GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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) throw (std::invalid_argument)
 Construct an IIR with the given taps. More...
 
 iir_filter ()
 
 ~iir_filter ()
 
o_type filter (const i_type input)
 compute a single output value. More...
 
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. More...
 
unsigned ntaps_ff () const
 
unsigned ntaps_fb () const
 
void set_taps (const std::vector< tap_type > &fftaps, const std::vector< tap_type > &fbtaps) throw (std::invalid_argument)
 install new taps. More...
 
template<>
gr_complex filter (const gr_complex input)
 
template<>
gr_complex filter (const gr_complex input)
 
template<>
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:

...
float y = iir_filt.filter(x);
<or>
iir_filt.filter(y, x, N); // y and x are float arrays

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);

Constructor & Destructor Documentation

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 
)
throw (std::invalid_argument
)
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.

fftaps and fbtaps must have equal numbers of taps

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.

The input and output satisfy a difference equation of the form

\[ y[n] \pm \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 \pm \sum_{k=1}^{M} a_k z^{-k}} \]

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
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

Member Function Documentation

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.
template<>
gr_complex gr::filter::kernel::iir_filter< gr_complex, gr_complex, float, gr_complex >::filter ( const gr_complex  input)
template<>
gr_complex gr::filter::kernel::iir_filter< gr_complex, gr_complex, double, gr_complexd >::filter ( const gr_complex  input)
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.

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
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.
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 
)
throw (std::invalid_argument
)
inline

install new taps.

Member Data Documentation

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
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
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
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
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
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
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

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