GNU Radio C++ API Reference: gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type > Class Template Reference

| GNU Radio C++ API Reference 3.10.12.0 The Free & Open Software Radio Ecosystem |

Loading...
Searching...
No Matches
gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type > Class Template Reference

Base class template for Infinite Impulse Response filter (IIR). More...

`#include <gnuradio/filter/iir_filter.h>`

## Public Member Functions
| 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.
| iir_filter ()
o_type | filter (const i_type input)
| compute a single output value.
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.
unsigned | ntaps_ff () const
unsigned | ntaps_fb () const
void | set_taps (const std::vector< tap_type > &fftaps, const std::vector< tap_type > &fbtaps)
| install new taps.
gr_complex | filter (const gr_complex input)
gr_complex | filter (const gr_complex input)
gr_complex | filter (const gr_complex input)

## Protected Attributes
bool | d_oldstyle
std::vector< tap_type > | d_fftaps
std::vector< tap_type > | d_fbtaps
int | d_latest_n
int | d_latest_m
std::vector< acc_type > | d_prev_output
std::vector< i_type > | d_prev_input

## Detailed Description

template<class i_type, class o_type, class tap_type, class acc_type>
class gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >

Base class template for Infinite Impulse Response filter (IIR).

This class provides a templated kernel for IIR filters. These iir_filters can be instantiated with a set of feed-forward and feed-back taps in the constructor. We then call the iir_filter::filter function to add a new sample to the filter, or iir_filter::filter_n to add a vector of samples to be filtered.

Instantiating a filter means defining the templates for the data types being processed by the filter. There are four templates:

- i_type the data type of the input data (i.e., float).
- o_type the data type of the output data (i.e., float).
- tap_type the data type of the filter taps (i.e., double).
- acc_type the data type of the internal accumulator (i.e., double).

The acc_type is specified to control how data is handled internally in the filter. This should always be the highest precision data type of any of the first three. Often, IIR filters require double-precision values in the taps for stability, and so the internal accumulator should also be double precision.

Example:

gr::filter::kernel::iir_filter<float,float,double,double> iir_filt(fftaps, fbtaps);
...
float y = iir_filt.filter(x);
<or>
iir_filt.filter(y, x, N); // y and x are float arrays
gr::filter::kernel::iir_filter
Base class template for Infinite Impulse Response filter (IIR).
Definition iir_filter.h:71

Another example for handling complex samples with double-precision taps (see filter::iir_filter_ccz):

gr:;filter::kernel::iir_filter<gr_complex, gr_complex, gr_complexd, gr_complexd>
iir_filt(fftaps, fbtaps);
gr
GNU Radio logging wrapper.
Definition basic_block.h:29

## Constructor & Destructor Documentation

## ◆ iir_filter() [1/2]

template<class i_type, class o_type, class tap_type, class acc_type>

gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::iir_filter | ( | const std::vector< tap_type > & | fftaps,
|  | const std::vector< tap_type > & | fbtaps,
|  | bool | oldstyle = true )
| inline

Construct an IIR with the given taps.

This filter uses the Direct Form I implementation, where `fftaps` contains the feed-forward taps, and `fbtaps` the feedback ones.

`oldstyle:` The old style of the IIR filter uses feedback taps that are negative of what most definitions use (scipy and Matlab among them). This parameter keeps using the old GNU Radio style and is set to TRUE by default. When taps generated from scipy, Matlab, or gr_filter_design, use the new style by setting this to FALSE.

When `oldstyle` is set FALSE, the input and output satisfy a difference equation of the form

\[y[n] + \sum_{k=1}^{M} a_k y[n-k] = \sum_{k=0}^{N} b_k x[n-k] \]

with the corresponding rational system function

\[H(z) = \frac{\sum_{k=0}^{N} b_k z^{-k}}{1 + \sum_{k=1}^{M} a_k z^{-k}} \]

where: \(x\) - input signal, \(y\) - output signal, \(a_k\) - k-th feedback tap, \(b_k\) - k-th feed-forward tap, \(M\) - `len(fbtaps)-1`, \(N\) - `len(fftaps)-1`.

\(a_0\), that is `fbtaps`[0], is ignored.

References d_oldstyle, and set_taps().

## ◆ iir_filter() [2/2]

template<class i_type, class o_type, class tap_type, class acc_type>

gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::iir_filter | ( |  | ) |
| inline

References d_latest_m, and d_latest_n.

## Member Function Documentation

## ◆ filter() [1/4]

gr_complex gr::filter::kernel::iir_filter< gr_complex, gr_complex, gr_complexd, gr_complexd >::filter | ( | const gr_complex | input | ) |

## ◆ filter() [2/4]

gr_complex gr::filter::kernel::iir_filter< gr_complex, gr_complex, double, gr_complexd >::filter | ( | const gr_complex | input | ) |

## ◆ filter() [3/4]

gr_complex gr::filter::kernel::iir_filter< gr_complex, gr_complex, float, gr_complex >::filter | ( | const gr_complex | input | ) |

## ◆ filter() [4/4]

template<class i_type, class o_type, class tap_type, class acc_type>

o_type gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::filter | ( | const i_type | input | ) |

compute a single output value.

Returns
  the filtered input value.

References d_fbtaps, d_fftaps, d_latest_m, d_latest_n, d_prev_input, d_prev_output, ntaps_fb(), and ntaps_ff().

Referenced by filter_n().

## ◆ filter_n()

template<class i_type, class o_type, class tap_type, class acc_type>

void gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::filter_n | ( | o_type | output[],
|  | const i_type | input[],
|  | long | n )

compute an array of N output values. `input` must have N valid entries.

References filter().

## ◆ ntaps_fb()

template<class i_type, class o_type, class tap_type, class acc_type>

unsigned gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::ntaps_fb | ( |  | ) | const
| inline

References d_fbtaps.

Referenced by filter().

## ◆ ntaps_ff()

template<class i_type, class o_type, class tap_type, class acc_type>

unsigned gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::ntaps_ff | ( |  | ) | const
| inline

Returns
  number of taps in filter.

References d_fftaps.

Referenced by filter().

## ◆ set_taps()

template<class i_type, class o_type, class tap_type, class acc_type>

void gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::set_taps | ( | const std::vector< tap_type > & | fftaps,
|  | const std::vector< tap_type > & | fbtaps )
| inline

install new taps.

References d_fbtaps, d_fftaps, d_latest_m, d_latest_n, d_oldstyle, d_prev_input, and d_prev_output.

Referenced by iir_filter().

## Member Data Documentation

## ◆ d_fbtaps

template<class i_type, class o_type, class tap_type, class acc_type>

std::vector<tap_type> gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::d_fbtaps
| protected

Referenced by filter(), ntaps_fb(), and set_taps().

## ◆ d_fftaps

template<class i_type, class o_type, class tap_type, class acc_type>

std::vector<tap_type> gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::d_fftaps
| protected

Referenced by filter(), ntaps_ff(), and set_taps().

## ◆ d_latest_m

template<class i_type, class o_type, class tap_type, class acc_type>

int gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::d_latest_m
| protected

Referenced by filter(), iir_filter(), and set_taps().

## ◆ d_latest_n

template<class i_type, class o_type, class tap_type, class acc_type>

int gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::d_latest_n
| protected

Referenced by filter(), iir_filter(), and set_taps().

## ◆ d_oldstyle

template<class i_type, class o_type, class tap_type, class acc_type>

bool gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::d_oldstyle
| protected

Referenced by iir_filter(), and set_taps().

## ◆ d_prev_input

template<class i_type, class o_type, class tap_type, class acc_type>

std::vector<i_type> gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::d_prev_input
| protected

Referenced by filter(), and set_taps().

## ◆ d_prev_output

template<class i_type, class o_type, class tap_type, class acc_type>

std::vector<acc_type> gr::filter::kernel::iir_filter< i_type, o_type, tap_type, acc_type >::d_prev_output
| protected

Referenced by filter(), and set_taps().

The documentation for this class was generated from the following file:

- iir_filter.h