23 #ifndef INCLUDED_IIR_FILTER_H
24 #define INCLUDED_IIR_FILTER_H
37 template<
class i_type,
class o_type,
class tap_type>
69 const std::vector<tap_type>& fbtaps,
71 throw (std::invalid_argument)
85 o_type
filter(
const i_type input);
91 void filter_n(o_type output[],
const i_type input[],
long n);
103 const std::vector<tap_type> &fbtaps)
104 throw (std::invalid_argument)
118 for(
size_t i = 1; i < fbtaps.size(); i++) {
123 int n = fftaps.size();
124 int m = fbtaps.size();
144 template<
class i_type,
class o_type,
class tap_type>
150 unsigned n = ntaps_ff();
151 unsigned m = ntaps_fb();
156 int latest_n = d_latest_n;
157 int latest_m = d_latest_m;
159 acc = d_fftaps[0] * input;
160 for(i = 1; i < n; i ++)
161 acc += (d_fftaps[i] * d_prev_input[latest_n + i]);
162 for(i = 1; i < m; i ++)
163 acc += (d_fbtaps[i] * d_prev_output[latest_m + i]);
166 d_prev_output[latest_m] = acc;
167 d_prev_output[latest_m+m] = acc;
168 d_prev_input[latest_n] = input;
169 d_prev_input[latest_n+n] = input;
178 d_latest_m = latest_m;
179 d_latest_n = latest_n;
183 template<
class i_type,
class o_type,
class tap_type>
186 const i_type input[],
189 for(
int i = 0; i < n; i++)
190 output[i] = filter(input[i]);
int d_latest_m
Definition: iir_filter.h:136
o_type filter(const i_type input)
compute a single output value.
Definition: iir_filter.h:146
std::vector< i_type > d_prev_input
Definition: iir_filter.h:138
bool d_oldstyle
Definition: iir_filter.h:132
base class template for Infinite Impulse Response filter (IIR)
Definition: iir_filter.h:38
iir_filter(const std::vector< tap_type > &fftaps, const std::vector< tap_type > &fbtaps, bool oldstyle=true)
Construct an IIR with the given taps.
Definition: iir_filter.h:68
std::vector< tap_type > d_fftaps
Definition: iir_filter.h:133
void set_taps(const std::vector< tap_type > &fftaps, const std::vector< tap_type > &fbtaps)
install new taps.
Definition: iir_filter.h:102
~iir_filter()
Definition: iir_filter.h:79
void filter_n(o_type output[], const i_type input[], long n)
compute an array of N output values. input must have N valid entries.
Definition: iir_filter.h:185
std::vector< tap_type > d_fbtaps
Definition: iir_filter.h:134
unsigned ntaps_ff() const
Definition: iir_filter.h:96
int d_latest_n
Definition: iir_filter.h:135
unsigned ntaps_fb() const
Definition: iir_filter.h:97
iir_filter()
Definition: iir_filter.h:77
std::vector< tap_type > d_prev_output
Definition: iir_filter.h:137