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>
121 const std::vector<tap_type>& fbtaps,
122 bool oldstyle =
true) noexcept(false)
124 d_oldstyle = oldstyle;
125 set_taps(fftaps, fbtaps);
136 o_type filter(
const i_type input);
142 void filter_n(o_type output[],
const i_type input[],
long n);
147 unsigned ntaps_ff()
const {
return d_fftaps.size(); }
148 unsigned ntaps_fb()
const {
return d_fbtaps.size(); }
154 const std::vector<tap_type>& fbtaps)
165 d_fbtaps.resize(fbtaps.size());
166 d_fbtaps[0] = fbtaps[0];
167 for (
size_t i = 1; i < fbtaps.size(); i++) {
168 d_fbtaps[i] = -fbtaps[i];
172 int n = fftaps.size();
173 int m = fbtaps.size();
174 d_prev_input.clear();
175 d_prev_output.clear();
176 d_prev_input.resize(2 * n, 0);
177 d_prev_output.resize(2 * m, 0);
193 template <
class i_type,
class o_type,
class tap_type,
class acc_type>
198 unsigned n = ntaps_ff();
199 unsigned m = ntaps_fb();
204 int latest_n = d_latest_n;
205 int latest_m = d_latest_m;
207 acc = d_fftaps[0] * input;
208 for (i = 1; i < n; i++)
209 acc += (d_fftaps[i] * d_prev_input[latest_n + i]);
210 for (i = 1; i < m; i++)
211 acc += (d_fbtaps[i] * d_prev_output[latest_m + i]);
214 d_prev_output[latest_m] = acc;
215 d_prev_output[latest_m + m] = acc;
216 d_prev_input[latest_n] = input;
217 d_prev_input[latest_n + n] = input;
226 d_latest_m = latest_m;
227 d_latest_n = latest_n;
231 template <
class i_type,
class o_type,
class tap_type,
class acc_type>
233 const i_type input[],
236 for (
int i = 0; i < n; i++)
237 output[i] = filter(input[i]);
std::vector< i_type > d_prev_input
Definition: iir_filter.h:187
std::vector< tap_type > d_fftaps
Definition: iir_filter.h:182
unsigned ntaps_ff() const
Definition: iir_filter.h:147
o_type filter(const i_type input)
compute a single output value.
Definition: iir_filter.h:194
iir_filter()
Definition: iir_filter.h:128
std::vector< acc_type > d_prev_output
Definition: iir_filter.h:186
Base class template for Infinite Impulse Response filter (IIR)
Definition: iir_filter.h:82
iir_filter(const std::vector< tap_type > &fftaps, const std::vector< tap_type > &fbtaps, bool oldstyle=true) noexcept(false)
Construct an IIR with the given taps.
Definition: iir_filter.h:120
void set_taps(const std::vector< tap_type > &fftaps, const std::vector< tap_type > &fbtaps)
install new taps.
Definition: iir_filter.h:153
std::complex< float > gr_complex
Definition: gr_complex.h:27
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
int d_latest_n
Definition: iir_filter.h:184
bool d_oldstyle
Definition: iir_filter.h:181
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:232
~iir_filter()
Definition: iir_filter.h:130
std::vector< tap_type > d_fbtaps
Definition: iir_filter.h:183
int d_latest_m
Definition: iir_filter.h:185
#define FILTER_API
Definition: gr-filter/include/gnuradio/filter/api.h:30
unsigned ntaps_fb() const
Definition: iir_filter.h:148