Infinite Impulse Response Filter (iirfilt)
API Keywords: iirfilt infinite impulse response IIR filter
The iirfilt_crcf object and family implement the infinite impulse response (IIR) filters. Also known as recursive filters, IIR filters allow a portion of the output to be fed back into the input, thus creating an impulse response which is non-zero for an infinite amount of time. Formally, the output signal may be written in terms of the input signal as
where are the feed-forward parameters and are the feed-back parameters of length and , respectively. The -transform of the transfer function is therefore
Typically the coefficients in are normalized such that .
For larger order filters (even as small as ) the filter can become unstable due to finite machine precision. It is often therefore useful to express in terms of second-order sections. For a filter of order , these sections are denoted by the two matrices and where (0 for odd , 1 for even ) and .
Notice that is now a series of cascaded second-order IIR filters. The sos form is practical when filters are designed from analog prototypes where the poles and zeros are known. liquid implements second-order sections efficiently with the internal iirfiltsos_crcf family of objects. For a cascaded second-order section IIR filter, use iirfilt_crcf_create_sos(B,A,n) . See also : iirdes (IIR filter design) in[ref:section-filter-iirdes] .
Listed below is the full interface to the iirfilt family of objects. The interface to the iirfilt object follows the convention of other liquid signal processing objects; while each method is listed for iirfilt_crcf , the same functionality applies to iirfilt_rrrf and iirfilt_cccf .
- iirfilt_crcf_create(*b,Nb,*a,Nb) creates a new iirfilt object with feed-forward coefficients and feed-back coefficients .
- iirfilt_crcf_create_sos(*B,*A,Nsos) creates a new iirfilt object using second-order sections. The feed-forward coefficient matrix is specified by and the feed-back coefficient matrix is specified by .
- iirfilt_crcf_create_prototype(ftype,btype,format,order,fc,f0,Ap,As) creates a new IIR filter object using the prototype interface described in [ref:section-filter-iirdes-iirdes] . This is the simplest method for designing an IIR filter with Butterworth, Chebyshev-I, Chebyshev-II, elliptic/Cauer, or Bessel coefficients.
- iirfilt_crcf_destroy(q) destroys an iirfilt object, freeing all internally-allocated memory arrays and buffers.
- iirfilt_crcf_print(q) prints the internals of an iirfilt object.
- iirfilt_crcf_clear(q) clears the filter's internal state.
- iirfilt_crcf_execute(q,x,*y) executes one iteration of the filter with an input , storing the result in , and updating its internal state.
- iirfilt_crcf_get_length(q) returns the order of the filter.
- iirfilt_crcf_freqresponse(q,fc,*H) computes the complex response of the filter at the normalized frequency .
- iirfilt_crcf_groupdelay(q,fc) returns the group delay of the filter at the normalized frequency .
Listed below is a basic example of the interface. For more detailed and extensive examples, refer to examples/iirfilt_crcf_example.c in the main liquid project source directory.
#include <liquid/liquid.h>
int main() {
// options
unsigned int order=4; // filter order
unsigned int n = order+1;
float b[n], a[n];
// ... initialize filter coefficients ...
// create filter object
iirfilt_crcf q = iirfilt_crcf_create(b,n,a,n);
float complex x; // input sample
float complex y; // output sample
// execute filter (repeat as necessary)
iirfilt_crcf_execute(q,x,&y);
// destroy filter object
iirfilt_crcf_destroy(q);
}
An example of the iirfilt can be seen in[ref:fig-filter-iirfilt_crcf] in which a low-pass filter is applied to a signal to remove a high-frequency component.