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.
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
leansdr::fir_filter< T, Tc > Struct Template Reference

#include <dsp.h>

+ Inheritance diagram for leansdr::fir_filter< T, Tc >:
+ Collaboration diagram for leansdr::fir_filter< T, Tc >:

Public Member Functions

 fir_filter (scheduler *sch, int _ncoeffs, Tc *_coeffs, pipebuf< T > &_in, pipebuf< T > &_out, unsigned int _decim=1)
 
void run ()
 
- 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

float * freq_tap
 
float tap_multiplier
 
float freq_tol
 
- Public Attributes inherited from leansdr::runnable_common
const char * name
 

Private Member Functions

void set_freq (float f)
 

Private Attributes

int ncoeffs
 
Tc * coeffs
 
pipereader< T > in
 
pipewriter< T > out
 
int decim
 
T * shifted_coeffs
 
float current_freq
 

Additional Inherited Members

- Protected Attributes inherited from leansdr::runnable
schedulersch
 

Detailed Description

template<typename T, typename Tc>
struct leansdr::fir_filter< T, Tc >

Definition at line 268 of file dsp.h.

Constructor & Destructor Documentation

◆ fir_filter()

template<typename T, typename Tc>
leansdr::fir_filter< T, Tc >::fir_filter ( scheduler sch,
int  _ncoeffs,
Tc *  _coeffs,
pipebuf< T > &  _in,
pipebuf< T > &  _out,
unsigned int  _decim = 1 
)
inline

Definition at line 270 of file dsp.h.

273  : runnable(sch, "fir_filter"),
274  ncoeffs(_ncoeffs), coeffs(_coeffs),
275  in(_in), out(_out),
276  decim(_decim),
277  freq_tap(NULL), tap_multiplier(1), freq_tol(0.1)
278  {
279  shifted_coeffs = new T[ncoeffs];
280  set_freq(0);
281  }
float * freq_tap
Definition: dsp.h:340
T * shifted_coeffs
Definition: dsp.h:324
runnable(scheduler *_sch, const char *name)
Definition: framework.h:193
float tap_multiplier
Definition: dsp.h:341
void set_freq(float f)
Definition: dsp.h:326
pipewriter< T > out
Definition: dsp.h:321
float freq_tol
Definition: dsp.h:342
scheduler * sch
Definition: framework.h:199
pipereader< T > in
Definition: dsp.h:320

Member Function Documentation

◆ run()

template<typename T, typename Tc>
void leansdr::fir_filter< T, Tc >::run ( )
inlinevirtual

Reimplemented from leansdr::runnable_common.

Definition at line 283 of file dsp.h.

284  {
285  if (in.readable() < ncoeffs)
286  return;
287 
288  if (freq_tap)
289  {
290  float new_freq = *freq_tap * tap_multiplier;
291  if (fabs(current_freq - new_freq) > freq_tol)
292  {
293  if (sch->verbose)
294  fprintf(stderr, "Shifting filter %f -> %f\n",
295  current_freq, new_freq);
296  set_freq(new_freq);
297  }
298  }
299 
300  long count = min((in.readable() - ncoeffs) / decim,
301  out.writable());
302  T *pin = in.rd() + ncoeffs, *pend = pin + count * decim, *pout = out.wr();
303  // TBD use coeffs when current_freq=0 (fewer mults if float)
304  for (; pin < pend; pin += decim, ++pout)
305  {
306  T *pc = shifted_coeffs;
307  T *pi = pin;
308  T x = 0;
309  for (int i = ncoeffs; i--; ++pc, --pi)
310  x = x + (*pc) * (*pi);
311  *pout = x;
312  }
313  in.read(count * decim);
314  out.written(count);
315  }
float * freq_tap
Definition: dsp.h:340
T * shifted_coeffs
Definition: dsp.h:324
float tap_multiplier
Definition: dsp.h:341
void set_freq(float f)
Definition: dsp.h:326
float current_freq
Definition: dsp.h:325
int32_t i
Definition: decimators.h:244
pipewriter< T > out
Definition: dsp.h:321
float freq_tol
Definition: dsp.h:342
scheduler * sch
Definition: framework.h:199
pipereader< T > in
Definition: dsp.h:320
T min(const T &x, const T &y)
Definition: framework.h:440

◆ set_freq()

template<typename T, typename Tc>
void leansdr::fir_filter< T, Tc >::set_freq ( float  f)
inlineprivate

Definition at line 326 of file dsp.h.

327  {
328  for (int i = 0; i < ncoeffs; ++i)
329  {
330  float a = 2 * M_PI * f * (i - ncoeffs / 2.0);
331  float c = cosf(a), s = sinf(a);
332  // TBD Support T=complex
333  shifted_coeffs[i].re = coeffs[i] * c;
334  shifted_coeffs[i].im = coeffs[i] * s;
335  }
336  current_freq = f;
337  }
T * shifted_coeffs
Definition: dsp.h:324
#define M_PI
Definition: rdsdemod.cpp:27
float current_freq
Definition: dsp.h:325
int32_t i
Definition: decimators.h:244

Member Data Documentation

◆ coeffs

template<typename T, typename Tc>
Tc* leansdr::fir_filter< T, Tc >::coeffs
private

Definition at line 319 of file dsp.h.

◆ current_freq

template<typename T, typename Tc>
float leansdr::fir_filter< T, Tc >::current_freq
private

Definition at line 325 of file dsp.h.

◆ decim

template<typename T, typename Tc>
int leansdr::fir_filter< T, Tc >::decim
private

Definition at line 322 of file dsp.h.

◆ freq_tap

template<typename T, typename Tc>
float* leansdr::fir_filter< T, Tc >::freq_tap

Definition at line 340 of file dsp.h.

◆ freq_tol

template<typename T, typename Tc>
float leansdr::fir_filter< T, Tc >::freq_tol

Definition at line 342 of file dsp.h.

◆ in

template<typename T, typename Tc>
pipereader<T> leansdr::fir_filter< T, Tc >::in
private

Definition at line 320 of file dsp.h.

◆ ncoeffs

template<typename T, typename Tc>
int leansdr::fir_filter< T, Tc >::ncoeffs
private

Definition at line 318 of file dsp.h.

◆ out

template<typename T, typename Tc>
pipewriter<T> leansdr::fir_filter< T, Tc >::out
private

Definition at line 321 of file dsp.h.

◆ shifted_coeffs

template<typename T, typename Tc>
T* leansdr::fir_filter< T, Tc >::shifted_coeffs
private

Definition at line 324 of file dsp.h.

◆ tap_multiplier

template<typename T, typename Tc>
float leansdr::fir_filter< T, Tc >::tap_multiplier

Definition at line 341 of file dsp.h.


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