23 #ifndef INCLUDED_IIR_FILTER_H
24 #define INCLUDED_IIR_FILTER_H
81 template<
class i_type,
class o_type,
class tap_type,
class acc_type>
113 const std::vector<tap_type>& fbtaps,
115 throw (
std::invalid_argument)
117 d_oldstyle = oldstyle;
118 set_taps(fftaps, fbtaps);
129 o_type filter(
const i_type input);
135 void filter_n(o_type output[],
const i_type input[],
long n);
140 unsigned ntaps_ff()
const {
return d_fftaps.size(); }
141 unsigned ntaps_fb()
const {
return d_fbtaps.size(); }
147 const std::vector<tap_type> &fbtaps)
148 throw (std::invalid_argument)
160 d_fbtaps.resize(fbtaps.size());
161 d_fbtaps[0] = fbtaps[0];
162 for(
size_t i = 1; i < fbtaps.size(); i++) {
163 d_fbtaps[i] = -fbtaps[i];
167 int n = fftaps.size();
168 int m = fbtaps.size();
169 d_prev_input.clear();
170 d_prev_output.clear();
171 d_prev_input.resize(2 * n, 0);
172 d_prev_output.resize(2 * m, 0);
188 template<
class i_type,
class o_type,
class tap_type,
class acc_type>
194 unsigned n = ntaps_ff();
195 unsigned m = ntaps_fb();
200 int latest_n = d_latest_n;
201 int latest_m = d_latest_m;
203 acc = d_fftaps[0] * input;
204 for(i = 1; i < n; i ++)
205 acc += (d_fftaps[i] * d_prev_input[latest_n + i]);
206 for(i = 1; i < m; i ++)
207 acc += (d_fbtaps[i] * d_prev_output[latest_m + i]);
210 d_prev_output[latest_m] = acc;
211 d_prev_output[latest_m+m] = acc;
212 d_prev_input[latest_n] = input;
213 d_prev_input[latest_n+n] = input;
222 d_latest_m = latest_m;
223 d_latest_n = latest_n;
227 template<
class i_type,
class o_type,
class tap_type,
class acc_type>
230 const i_type input[],
233 for(
int i = 0; i < n; i++)
234 output[i] = filter(input[i]);
std::vector< i_type > d_prev_input
Definition: iir_filter.h:182
std::vector< tap_type > d_fftaps
Definition: iir_filter.h:177
o_type filter(const i_type input)
compute a single output value.
Definition: iir_filter.h:190
iir_filter()
Definition: iir_filter.h:121
std::vector< acc_type > d_prev_output
Definition: iir_filter.h:181
Base class template for Infinite Impulse Response filter (IIR)
Definition: iir_filter.h:82
void set_taps(const std::vector< tap_type > &fftaps, const std::vector< tap_type > &fbtaps)
install new taps.
Definition: iir_filter.h:146
unsigned ntaps_ff() const
Definition: iir_filter.h:140
std::complex< float > gr_complex
Definition: gr_complex.h:27
Include this header to use the message passing features.
Definition: logger.h:131
int d_latest_n
Definition: iir_filter.h:179
unsigned ntaps_fb() const
Definition: iir_filter.h:141
bool d_oldstyle
Definition: iir_filter.h:176
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:112
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:229
~iir_filter()
Definition: iir_filter.h:123
std::vector< tap_type > d_fbtaps
Definition: iir_filter.h:178
int d_latest_m
Definition: iir_filter.h:180
#define FILTER_API
Definition: gr-filter/include/gnuradio/filter/api.h:30