1 #ifndef INCLUDE_BANDPASS_H 2 #define INCLUDE_BANDPASS_H 4 #define _USE_MATH_DEFINES 9 #define M_PI 3.14159265358979323846 15 void create(
int nTaps,
double sampleRate,
double lowCutoff,
double highCutoff)
17 std::vector<Real> taps_lp;
18 std::vector<Real> taps_hp;
19 double wcl = 2.0 *
M_PI * lowCutoff;
20 double Wcl = wcl / sampleRate;
21 double wch = 2.0 *
M_PI * highCutoff;
22 double Wch = wch / sampleRate;
27 qDebug(
"Bandpass filter has to have an odd number of taps");
33 for(
int i = 0; i < nTaps; i++)
36 m_taps.resize(nTaps / 2 + 1);
37 taps_lp.resize(nTaps / 2 + 1);
38 taps_hp.resize(nTaps / 2 + 1);
41 for(i = 0; i < nTaps / 2 + 1; i++) {
42 if(i == (nTaps - 1) / 2) {
43 taps_lp[
i] = Wch /
M_PI;
44 taps_hp[
i] = -(Wcl /
M_PI);
47 taps_lp[
i] =
sin(((
double)i - ((
double)nTaps - 1.0) / 2.0) * Wch) / (((double)i - ((
double)nTaps - 1.0) / 2.0) *
M_PI);
48 taps_hp[
i] = -
sin(((
double)i - ((
double)nTaps - 1.0) / 2.0) * Wcl) / (((double)i - ((
double)nTaps - 1.0) / 2.0) *
M_PI);
52 taps_hp[(nTaps - 1) / 2] += 1;
55 for(i = 0; i < nTaps / 2 + 1; i++) {
56 taps_lp[
i] *= 0.54 + 0.46 *
cos((2.0 *
M_PI * ((
double)i - ((
double)nTaps - 1.0) / 2.0)) / (
double)nTaps);
57 taps_hp[
i] *= 0.54 + 0.46 *
cos((2.0 *
M_PI * ((
double)i - ((
double)nTaps - 1.0) / 2.0)) / (
double)nTaps);
61 m_taps[(nTaps - 1) / 2] += 1;
66 for(i = 0; i < (int)
m_taps.size() - 1; i++) {
72 for(i = 0; i < (int)
m_taps.size(); i++) {
92 n_taps =
m_taps.size() - 1;
94 for(i = 0; i < n_taps; i++)
116 while (
m_ptr >= size)
130 #endif // INCLUDE_BANDPASS_H
std::vector< Real > m_taps
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
void create(int nTaps, double sampleRate, double lowCutoff, double highCutoff)
Fixed< IntType, IntBits > sin(Fixed< IntType, IntBits > const &x)
std::vector< Type > m_samples