SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Classes | Public Member Functions | Public Attributes | Private Attributes | List of all members
leansdr::auto_notch< T > Struct Template Reference

#include <sdr.h>

+ Inheritance diagram for leansdr::auto_notch< T >:
+ Collaboration diagram for leansdr::auto_notch< T >:

Classes

struct  slot
 

Public Member Functions

 auto_notch (scheduler *sch, pipebuf< complex< T >> &_in, pipebuf< complex< T >> &_out, int _nslots, T _agc_rms_setpoint)
 
 ~auto_notch ()
 
void run ()
 
void detect ()
 
void process ()
 
- Public Member Functions inherited from leansdr::runnable
 runnable (scheduler *_sch, const char *name)
 
- Public Member Functions inherited from leansdr::runnable_common
 runnable_common (const char *_name)
 
virtual ~runnable_common ()
 
virtual void shutdown ()
 

Public Attributes

int decimation
 
float k
 
- Public Attributes inherited from leansdr::runnable_common
const char * name
 

Private Attributes

cfft_engine< float > fft
 
pipereader< complex< T > > in
 
pipewriter< complex< T > > out
 
int nslots
 
slot__slots
 
int phase
 
float gain
 
agc_rms_setpoint
 

Additional Inherited Members

- Protected Attributes inherited from leansdr::runnable
schedulersch
 

Detailed Description

template<typename T>
struct leansdr::auto_notch< T >

Definition at line 46 of file sdr.h.

Constructor & Destructor Documentation

◆ auto_notch()

template<typename T>
leansdr::auto_notch< T >::auto_notch ( scheduler sch,
pipebuf< complex< T >> &  _in,
pipebuf< complex< T >> &  _out,
int  _nslots,
_agc_rms_setpoint 
)
inline

Definition at line 51 of file sdr.h.

55  : runnable(sch, "auto_notch"),
56  decimation(1024 * 4096),
57  k(0.002), // k(0.01)
58  fft(4096),
59  in(_in),
60  out(_out, fft.n),
61  nslots(_nslots),
62  phase(0),
63  gain(1),
64  agc_rms_setpoint(_agc_rms_setpoint)
65  {
66  __slots = new slot[nslots];
67 
68  for (int s = 0; s < nslots; ++s)
69  {
70  __slots[s].i = -1;
71  __slots[s].expj = new complex<float>[fft.n];
72  }
73  }
int decimation
Definition: sdr.h:48
slot * __slots
Definition: sdr.h:213
pipereader< complex< T > > in
Definition: sdr.h:201
runnable(scheduler *_sch, const char *name)
Definition: framework.h:193
pipewriter< complex< T > > out
Definition: sdr.h:202
complex< float > * expj
Definition: sdr.h:209
scheduler * sch
Definition: framework.h:199
cfft_engine< float > fft
Definition: sdr.h:200
const int n
Definition: dsp.h:64

◆ ~auto_notch()

template<typename T>
leansdr::auto_notch< T >::~auto_notch ( )
inline

Definition at line 75 of file sdr.h.

76  {
77  delete[] __slots;
78  }
slot * __slots
Definition: sdr.h:213

Member Function Documentation

◆ detect()

template<typename T>
void leansdr::auto_notch< T >::detect ( )
inline

Definition at line 98 of file sdr.h.

Referenced by leansdr::auto_notch< leansdr::f32 >::run().

99  {
100  complex<T> *pin = in.rd();
101  complex<float> *data = new complex<float>[fft.n];
102  float m0 = 0, m2 = 0;
103 
104  for (int i = 0; i < fft.n; ++i)
105  {
106  data[i].re = pin[i].re;
107  data[i].im = pin[i].im;
108  m2 += (float)pin[i].re * pin[i].re + (float)pin[i].im * pin[i].im;
109  if (gen_abs(pin[i].re) > m0)
110  m0 = gen_abs(pin[i].re);
111  if (gen_abs(pin[i].im) > m0)
112  m0 = gen_abs(pin[i].im);
113  }
114 
115  if (agc_rms_setpoint && m2)
116  {
117  float rms = gen_sqrt(m2 / fft.n);
118  if (sch->debug)
119  fprintf(stderr, "(pow %f max %f)", rms, m0);
120  float new_gain = agc_rms_setpoint / rms;
121  gain = gain * 0.9 + new_gain * 0.1;
122  }
123 
124  fft.inplace(data, true);
125  float *amp = new float[fft.n];
126 
127  for (int i = 0; i < fft.n; ++i)
128  amp[i] = hypotf(data[i].re, data[i].im);
129 
130  for (slot *s = __slots; s < __slots + nslots; ++s)
131  {
132  int iamax = 0;
133 
134  for (int i = 0; i < fft.n; ++i)
135  if (amp[i] > amp[iamax])
136  iamax = i;
137 
138  if (iamax != s->i)
139  {
140  if (sch->debug)
141  fprintf(stderr, "%s: slot %d new peak %d -> %d\n", name, (int)(s - __slots), s->i, iamax);
142 
143  s->i = iamax;
144  s->estim.re = 0;
145  s->estim.im = 0;
146  s->estt = 0;
147 
148  for (int i = 0; i < fft.n; ++i)
149  {
150  float a = 2 * M_PI * s->i * i / fft.n;
151  s->expj[i].re = cosf(a);
152  s->expj[i].im = sinf(a);
153  }
154  }
155 
156  amp[iamax] = 0;
157 
158  if (iamax - 1 >= 0)
159  amp[iamax - 1] = 0;
160 
161  if (iamax + 1 < fft.n)
162  amp[iamax + 1] = 0;
163  }
164 
165  delete[] amp;
166  delete[] data;
167  }
slot * __slots
Definition: sdr.h:213
pipereader< complex< T > > in
Definition: sdr.h:201
#define M_PI
Definition: rdsdemod.cpp:27
T gen_abs(T x)
int32_t i
Definition: decimators.h:244
T gen_sqrt(T x)
scheduler * sch
Definition: framework.h:199
cfft_engine< float > fft
Definition: sdr.h:200
const int n
Definition: dsp.h:64
void inplace(complex< T > *data, bool reverse=false)
Definition: dsp.h:89
+ Here is the caller graph for this function:

◆ process()

template<typename T>
void leansdr::auto_notch< T >::process ( )
inline

Definition at line 169 of file sdr.h.

Referenced by leansdr::auto_notch< leansdr::f32 >::run().

170  {
171  complex<T> *pin = in.rd(), *pend = pin + fft.n, *pout = out.wr();
172 
173  for (slot *s = __slots; s < __slots + nslots; ++s)
174  s->ej = s->expj;
175 
176  for (; pin < pend; ++pin, ++pout)
177  {
178  complex<float> out = *pin;
179  // TODO Optimize for nslots==1 ?
180 
181  for (slot *s = __slots; s < __slots + nslots; ++s->ej, ++s)
182  {
183  complex<float> bb(pin->re * s->ej->re + pin->im * s->ej->im,
184  -pin->re * s->ej->im + pin->im * s->ej->re);
185  s->estim.re = bb.re * k + s->estim.re * (1 - k);
186  s->estim.im = bb.im * k + s->estim.im * (1 - k);
187  complex<float> sub(
188  s->estim.re * s->ej->re - s->estim.im * s->ej->im,
189  s->estim.re * s->ej->im + s->estim.im * s->ej->re);
190  out.re -= sub.re;
191  out.im -= sub.im;
192  }
193 
194  pout->re = gain * out.re;
195  pout->im = gain * out.im;
196  }
197  }
slot * __slots
Definition: sdr.h:213
pipereader< complex< T > > in
Definition: sdr.h:201
pipewriter< complex< T > > out
Definition: sdr.h:202
cfft_engine< float > fft
Definition: sdr.h:200
const int n
Definition: dsp.h:64
+ Here is the caller graph for this function:

◆ run()

template<typename T>
void leansdr::auto_notch< T >::run ( )
inlinevirtual

Reimplemented from leansdr::runnable_common.

Definition at line 80 of file sdr.h.

81  {
82  while (in.readable() >= fft.n && out.writable() >= fft.n)
83  {
84  phase += fft.n;
85 
86  if (phase >= decimation)
87  {
88  phase -= decimation;
89  detect();
90  }
91 
92  process();
93  in.read(fft.n);
94  out.written(fft.n);
95  }
96  }
int decimation
Definition: sdr.h:48
void detect()
Definition: sdr.h:98
pipereader< complex< T > > in
Definition: sdr.h:201
void process()
Definition: sdr.h:169
pipewriter< complex< T > > out
Definition: sdr.h:202
cfft_engine< float > fft
Definition: sdr.h:200
const int n
Definition: dsp.h:64

Member Data Documentation

◆ __slots

template<typename T>
slot* leansdr::auto_notch< T >::__slots
private

◆ agc_rms_setpoint

template<typename T>
T leansdr::auto_notch< T >::agc_rms_setpoint
private

Definition at line 216 of file sdr.h.

Referenced by leansdr::auto_notch< leansdr::f32 >::detect().

◆ decimation

template<typename T>
int leansdr::auto_notch< T >::decimation

◆ fft

template<typename T>
cfft_engine<float> leansdr::auto_notch< T >::fft
private

◆ gain

template<typename T>
float leansdr::auto_notch< T >::gain
private

◆ in

template<typename T>
pipereader<complex<T> > leansdr::auto_notch< T >::in
private

◆ k

template<typename T>
float leansdr::auto_notch< T >::k

Definition at line 49 of file sdr.h.

Referenced by leansdr::auto_notch< leansdr::f32 >::process().

◆ nslots

template<typename T>
int leansdr::auto_notch< T >::nslots
private

◆ out

template<typename T>
pipewriter<complex<T> > leansdr::auto_notch< T >::out
private

◆ phase

template<typename T>
int leansdr::auto_notch< T >::phase
private

The documentation for this struct was generated from the following file: