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.
Functions
leansdr::filtergen Namespace Reference

Functions

void dump_filter (const char *name, int ncoeffs, float *coeffs)
 
template<typename T >
void normalize_power (int n, T *coeffs, float gain=1)
 
template<typename T >
void normalize_dcgain (int n, T *coeffs, float gain=1)
 
template<typename T >
void cancel_dcgain (int n, T *coeffs)
 
template<typename T >
int lowpass (int order, float Fcut, T **coeffs, float gain=1)
 
template<typename T >
int root_raised_cosine (int order, float Fs, float rolloff, T **coeffs)
 

Function Documentation

◆ cancel_dcgain()

template<typename T >
void leansdr::filtergen::cancel_dcgain ( int  n,
T *  coeffs 
)

Definition at line 54 of file filtergen.h.

References i.

55 {
56  float s = 0;
57  for (int i = 0; i < n; ++i)
58  s = s + coeffs[i];
59  for (int i = 0; i < n; ++i)
60  coeffs[i] -= s / n;
61 }
int32_t i
Definition: decimators.h:244

◆ dump_filter()

void leansdr::filtergen::dump_filter ( const char *  name,
int  ncoeffs,
float *  coeffs 
)

Definition at line 11 of file filtergen.cpp.

References i.

Referenced by root_raised_cosine().

12 {
13  fprintf(stderr, "%s = [", name);
14  for (int i = 0; i < ncoeffs; ++i)
15  fprintf(stderr, "%s %f", (i ? "," : ""), coeffs[i]);
16  fprintf(stderr, " ];\n");
17 }
int32_t i
Definition: decimators.h:244
+ Here is the caller graph for this function:

◆ lowpass()

template<typename T >
int leansdr::filtergen::lowpass ( int  order,
float  Fcut,
T **  coeffs,
float  gain = 1 
)

Definition at line 67 of file filtergen.h.

References cos(), i, M_PI, normalize_dcgain(), sin(), and sinc().

68 {
69  int ncoeffs = order + 1;
70  *coeffs = new T[ncoeffs];
71  for (int i = 0; i < ncoeffs; ++i)
72  {
73  float t = i - (ncoeffs - 1) * 0.5;
74  float sinc = 2 * Fcut * (t ? sin(2 * M_PI * Fcut * t) / (2 * M_PI * Fcut * t) : 1);
75 #if 0 // Hamming
76  float alpha = 25.0/46, beta = 21.0/46;
77  float window = alpha - beta*cos(2*M_PI*i/order);
78 #else
79  float window = 1;
80 #endif
81  (*coeffs)[i] = sinc * window;
82  }
83  normalize_dcgain(ncoeffs, *coeffs, gain);
84  return ncoeffs;
85 }
float sinc(float x)
Definition: misc.h:32
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2271
void normalize_dcgain(int n, T *coeffs, float gain=1)
Definition: filtergen.h:42
#define M_PI
Definition: rdsdemod.cpp:27
Fixed< IntType, IntBits > sin(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2265
int32_t i
Definition: decimators.h:244
+ Here is the call graph for this function:

◆ normalize_dcgain()

template<typename T >
void leansdr::filtergen::normalize_dcgain ( int  n,
T *  coeffs,
float  gain = 1 
)

Definition at line 42 of file filtergen.h.

References i.

Referenced by lowpass(), and root_raised_cosine().

43 {
44  float s = 0;
45  for (int i = 0; i < n; ++i)
46  s = s + coeffs[i];
47  if (s)
48  gain /= s;
49  for (int i = 0; i < n; ++i)
50  coeffs[i] = coeffs[i] * gain;
51 }
int32_t i
Definition: decimators.h:244
+ Here is the caller graph for this function:

◆ normalize_power()

template<typename T >
void leansdr::filtergen::normalize_power ( int  n,
T *  coeffs,
float  gain = 1 
)

Definition at line 30 of file filtergen.h.

References leansdr::gen_sqrt(), and i.

31 {
32  float s2 = 0;
33  for (int i = 0; i < n; ++i)
34  s2 = s2 + coeffs[i] * coeffs[i]; // TBD complex
35  if (s2)
36  gain /= gen_sqrt(s2);
37  for (int i = 0; i < n; ++i)
38  coeffs[i] = coeffs[i] * gain;
39 }
int32_t i
Definition: decimators.h:244
T gen_sqrt(T x)
+ Here is the call graph for this function:

◆ root_raised_cosine()

template<typename T >
int leansdr::filtergen::root_raised_cosine ( int  order,
float  Fs,
float  rolloff,
T **  coeffs 
)

Definition at line 91 of file filtergen.h.

References cos(), dump_filter(), i, M_PI, normalize_dcgain(), sin(), and sqrt().

Referenced by DATVDemod::InitDATVFramework(), and DATVDemod::InitDATVS2Framework().

92 {
93  float B = rolloff, pi = M_PI;
94  int ncoeffs = (order + 1) | 1;
95  *coeffs = new T[ncoeffs];
96  for (int i = 0; i < ncoeffs; ++i)
97  {
98  int t = i - ncoeffs / 2;
99  float c;
100  if (t == 0)
101  c = sqrt(Fs) * (1 - B + 4 * B / pi);
102  else
103  {
104  float tT = t * Fs;
105  float den = pi * tT * (1 - (4 * B * tT) * (4 * B * tT));
106  if (!den)
107  c = B * sqrt(Fs / 2) * ((1 + 2 / pi) * sin(pi / (4 * B)) + (1 - 2 / pi) * cos(pi / (4 * B)));
108  else
109  c = sqrt(Fs) * (sin(pi * tT * (1 - B)) + 4 * B * tT * cos(pi * tT * (1 + B))) / den;
110  }
111  (*coeffs)[i] = c;
112  }
113  normalize_dcgain(ncoeffs, *coeffs);
114  return ncoeffs;
115 }
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2271
void normalize_dcgain(int n, T *coeffs, float gain=1)
Definition: filtergen.h:42
#define M_PI
Definition: rdsdemod.cpp:27
Fixed< IntType, IntBits > sin(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2265
int32_t i
Definition: decimators.h:244
Fixed< IntType, IntBits > sqrt(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2283
+ Here is the call graph for this function:
+ Here is the caller graph for this function: