17 #ifndef LEANSDR_FILTERGEN_H 18 #define LEANSDR_FILTERGEN_H 33 for (
int i = 0;
i < n; ++
i)
34 s2 = s2 + coeffs[
i] * coeffs[
i];
37 for (
int i = 0;
i < n; ++
i)
38 coeffs[
i] = coeffs[
i] * gain;
45 for (
int i = 0;
i < n; ++
i)
49 for (
int i = 0;
i < n; ++
i)
50 coeffs[
i] = coeffs[
i] * gain;
57 for (
int i = 0;
i < n; ++
i)
59 for (
int i = 0;
i < n; ++
i)
67 int lowpass(
int order,
float Fcut, T **coeffs,
float gain = 1)
69 int ncoeffs = order + 1;
70 *coeffs =
new T[ncoeffs];
71 for (
int i = 0;
i < ncoeffs; ++
i)
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);
76 float alpha = 25.0/46, beta = 21.0/46;
77 float window = alpha - beta*
cos(2*
M_PI*
i/order);
81 (*coeffs)[
i] = sinc * window;
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)
98 int t =
i - ncoeffs / 2;
101 c =
sqrt(Fs) * (1 - B + 4 * B / pi);
105 float den = pi * tT * (1 - (4 * B * tT) * (4 * B * tT));
107 c = B *
sqrt(Fs / 2) * ((1 + 2 / pi) *
sin(pi / (4 * B)) + (1 - 2 / pi) *
cos(pi / (4 * B)));
109 c =
sqrt(Fs) * (
sin(pi * tT * (1 - B)) + 4 * B * tT *
cos(pi * tT * (1 + B))) / den;
118 void dump_filter(
const char *name,
int ncoeffs,
float *coeffs);
123 #endif // LEANSDR_FILTERGEN_H
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
void normalize_dcgain(int n, T *coeffs, float gain=1)
int lowpass(int order, float Fcut, T **coeffs, float gain=1)
void normalize_power(int n, T *coeffs, float gain=1)
void dump_filter(const char *name, int ncoeffs, float *coeffs)
Fixed< IntType, IntBits > sin(Fixed< IntType, IntBits > const &x)
Fixed< IntType, IntBits > sqrt(Fixed< IntType, IntBits > const &x)
int root_raised_cosine(int order, float Fs, float rolloff, T **coeffs)
void cancel_dcgain(int n, T *coeffs)