IIR Filters 101
I will try to keep the math side of things as light as possible but we cannot avoid it completely, so I will use the hand waving proof technique. If you have any doubts or questions about the statements made here without any proof, please use the comments and I will try to address them there.
The first thing we will need is the z transform, the discrete version of the Laplace transform. For a sequence of discrete samples x(n), its z transform is defined as:
where
and
Here T is the sample period, fs
is the sample rate and f is the frequency at which z and X(z) are being evaluated. The other important thing to know is that if we delay the time sequence x(n) by one clock, in the z domain this is equivalent to multiplying X(z) by z-1. So the transfer function of a register delay is z-1.
In general an IIR of order N is defined by the time domain finite difference equation:
that is the next output sample y(n) is a linear function of the previous N-1 output samples and N input samples. FIRs are just particular forms of IIRs when all ak=0. Trying to derive the IIR filter impulse response and frequency transfer function from the a and b coefficients is no longer obvious and that's where the z transform helps. In the z domain the time domain difference equation becomes:
With a bit of rearranging this gives us the z domain IIR filter transfer function H(z):
For N=2 we get the famous biquads, with 5 non-trivial coefficients. Any even order N IIR can be decomposed into a cascade of N/2 biquads, each one with 5 coefficients, with an extra first order section with 3 coefficients if N is odd.
H(z) can now be evaluated for any frequency f using , which gives us H(f), the IIR filter frequency domain transfer function. H(f) is always a complex function, even when all coefficients are real, and if represented in polar coordinates
are the filter's attenuation and phase as a function of frequency, while
is the filter's group delay (the one which is a constant for linear phase FIRs). So with a bit of trigonometry and complex algebra the attenuation, phase and group delays of any IIR of any order N can be evaluated for any frequency f.
As mentioned earlier, large order IIRs are never implemented directly due to coefficient sensitivity problems, cascades of second order biquad sections are always used, things like this:
or its dual form:
While this might make sense from a mathematical point of view, we will see in the next blog post that especially for FPGA hardware implementations, there are much better ways to build IIR filters.
Back to the top: The Art of FPGA Design Season 2