11 #ifndef INCLUDED_IIR_FILTER_H
12 #define INCLUDED_IIR_FILTER_H
69 template <
class i_type,
class o_type,
class tap_type,
class acc_type>
109 const std::vector<tap_type>& fbtaps,
110 bool oldstyle =
true) noexcept(false)
112 d_oldstyle = oldstyle;
113 set_taps(fftaps, fbtaps);
122 o_type filter(
const i_type input);
128 void filter_n(o_type output[],
const i_type input[],
long n);
133 unsigned ntaps_ff()
const {
return d_fftaps.size(); }
134 unsigned ntaps_fb()
const {
return d_fbtaps.size(); }
140 const std::vector<tap_type>& fbtaps)
151 d_fbtaps.resize(fbtaps.size());
152 d_fbtaps[0] = fbtaps[0];
153 for (
size_t i = 1; i < fbtaps.size(); i++) {
154 d_fbtaps[i] = -fbtaps[i];
158 int n = fftaps.size();
159 int m = fbtaps.size();
160 d_prev_input.clear();
161 d_prev_output.clear();
162 d_prev_input.resize(2 * n, 0);
163 d_prev_output.resize(2 * m, 0);
179 template <
class i_type,
class o_type,
class tap_type,
class acc_type>
184 unsigned n = ntaps_ff();
185 unsigned m = ntaps_fb();
190 int latest_n = d_latest_n;
191 int latest_m = d_latest_m;
193 acc = d_fftaps[0] * input;
194 for (i = 1; i < n; i++)
195 acc += (d_fftaps[i] * d_prev_input[latest_n + i]);
196 for (i = 1; i < m; i++)
197 acc += (d_fbtaps[i] * d_prev_output[latest_m + i]);
200 d_prev_output[latest_m] = acc;
201 d_prev_output[latest_m + m] = acc;
202 d_prev_input[latest_n] = input;
203 d_prev_input[latest_n + n] = input;
212 d_latest_m = latest_m;
213 d_latest_n = latest_n;
217 template <
class i_type,
class o_type,
class tap_type,
class acc_type>
219 const i_type input[],
222 for (
int i = 0; i < n; i++)
223 output[i] = filter(input[i]);
Base class template for Infinite Impulse Response filter (IIR)
Definition: iir_filter.h:71
unsigned ntaps_ff() const
Definition: iir_filter.h:133
o_type filter(const i_type input)
compute a single output value.
Definition: iir_filter.h:180
std::vector< i_type > d_prev_input
Definition: iir_filter.h:173
std::vector< tap_type > d_fbtaps
Definition: iir_filter.h:169
unsigned ntaps_fb() const
Definition: iir_filter.h:134
std::vector< acc_type > d_prev_output
Definition: iir_filter.h:172
int d_latest_n
Definition: iir_filter.h:170
iir_filter()
Definition: iir_filter.h:116
void set_taps(const std::vector< tap_type > &fftaps, const std::vector< tap_type > &fbtaps)
install new taps.
Definition: iir_filter.h:139
std::vector< tap_type > d_fftaps
Definition: iir_filter.h:168
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:108
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:218
int d_latest_m
Definition: iir_filter.h:171
bool d_oldstyle
Definition: iir_filter.h:167
#define FILTER_API
Definition: gr-filter/include/gnuradio/filter/api.h:18
std::complex< float > gr_complex
Definition: gr_complex.h:15
GNU Radio logging wrapper.
Definition: basic_block.h:29