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_resampler< T, Tc > Struct Template Reference

#include <dsp.h>

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

Public Member Functions

 fir_resampler (scheduler *sch, int _ncoeffs, Tc *_coeffs, pipebuf< T > &_in, pipebuf< T > &_out, int _interp=1, 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

unsigned int ncoeffs
 
Tc * coeffs
 
int interp
 
int decim
 
pipereader< T > in
 
pipewriter< T > out
 
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_resampler< T, Tc >

Definition at line 348 of file dsp.h.

Constructor & Destructor Documentation

◆ fir_resampler()

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

Definition at line 350 of file dsp.h.

References leansdr::fail().

353  : runnable(sch, "fir_resampler"),
354  ncoeffs(_ncoeffs), coeffs(_coeffs),
355  interp(_interp), decim(_decim),
356  in(_in), out(_out, interp),
357  freq_tap(NULL), tap_multiplier(1), freq_tol(0.1)
358  {
359  if (decim != 1)
360  fail("fir_resampler: decim not implemented"); // TBD
361  shifted_coeffs = new T[ncoeffs];
362  set_freq(0);
363  }
pipewriter< T > out
Definition: dsp.h:410
pipereader< T > in
Definition: dsp.h:409
runnable(scheduler *_sch, const char *name)
Definition: framework.h:193
void fail(const char *s)
Definition: framework.cpp:11
void set_freq(float f)
Definition: dsp.h:420
scheduler * sch
Definition: framework.h:199
float * freq_tap
Definition: dsp.h:413
float tap_multiplier
Definition: dsp.h:414
unsigned int ncoeffs
Definition: dsp.h:406
+ Here is the call graph for this function:

Member Function Documentation

◆ run()

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

Reimplemented from leansdr::runnable_common.

Definition at line 365 of file dsp.h.

References i, leansdr::cconverter< Tin, Zin, Tout, Zout, Gn, Gd >::in, leansdr::min(), leansdr::cconverter< Tin, Zin, Tout, Zout, Gn, Gd >::out, leansdr::runnable::sch, and leansdr::scheduler::verbose.

366  {
367  if (in.readable() < ncoeffs)
368  return;
369 
370  if (freq_tap)
371  {
372  float new_freq = *freq_tap * tap_multiplier;
373  if (fabs(current_freq - new_freq) > freq_tol)
374  {
375  if (sch->verbose)
376  fprintf(stderr, "Shifting filter %f -> %f\n",
377  current_freq, new_freq);
378  set_freq(new_freq);
379  }
380  }
381 
382  if (in.readable() * interp < ncoeffs)
383  return;
384  unsigned long count = min((in.readable() * interp - ncoeffs) / interp,
385  out.writable() / interp);
386  int latency = (ncoeffs + interp) / interp;
387  T *pin = in.rd() + latency, *pend = pin + count, *pout = out.wr();
388  // TBD use coeffs when current_freq=0 (fewer mults if float)
389  for (; pin < pend; ++pin)
390  {
391  for (int i = 0; i < interp; ++i, ++pout)
392  {
393  T *pi = pin;
394  T *pc = shifted_coeffs + i, *pcend = shifted_coeffs + ncoeffs;
395  T x = 0;
396  for (; pc < pcend; pc += interp, --pi)
397  x = x + (*pc) * (*pi);
398  *pout = x;
399  }
400  }
401  in.read(count);
402  out.written(count * interp);
403  }
pipewriter< T > out
Definition: dsp.h:410
pipereader< T > in
Definition: dsp.h:409
int32_t i
Definition: decimators.h:244
void set_freq(float f)
Definition: dsp.h:420
scheduler * sch
Definition: framework.h:199
float * freq_tap
Definition: dsp.h:413
float current_freq
Definition: dsp.h:419
float tap_multiplier
Definition: dsp.h:414
unsigned int ncoeffs
Definition: dsp.h:406
T min(const T &x, const T &y)
Definition: framework.h:440
+ Here is the call graph for this function:

◆ set_freq()

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

Definition at line 420 of file dsp.h.

References i, and M_PI.

421  {
422  for (int i = 0; i < ncoeffs; ++i)
423  {
424  float a = 2 * M_PI * f * i;
425  float c = cosf(a), s = sinf(a);
426  // TBD Support T=complex
427  shifted_coeffs[i].re = coeffs[i] * c;
428  shifted_coeffs[i].im = coeffs[i] * s;
429  }
430  current_freq = f;
431  }
#define M_PI
Definition: rdsdemod.cpp:27
int32_t i
Definition: decimators.h:244
float current_freq
Definition: dsp.h:419
unsigned int ncoeffs
Definition: dsp.h:406

Member Data Documentation

◆ coeffs

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

Definition at line 407 of file dsp.h.

◆ current_freq

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

Definition at line 419 of file dsp.h.

◆ decim

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

Definition at line 408 of file dsp.h.

◆ freq_tap

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

Definition at line 413 of file dsp.h.

◆ freq_tol

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

Definition at line 415 of file dsp.h.

◆ in

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

Definition at line 409 of file dsp.h.

◆ interp

template<typename T , typename Tc >
int leansdr::fir_resampler< T, Tc >::interp
private

Definition at line 408 of file dsp.h.

◆ ncoeffs

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

Definition at line 406 of file dsp.h.

◆ out

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

Definition at line 410 of file dsp.h.

◆ shifted_coeffs

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

Definition at line 418 of file dsp.h.

◆ tap_multiplier

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

Definition at line 414 of file dsp.h.


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