IIR Filters ----------- **Infinite impulse response filters** are characterized with a difference equation like: .. math:: y[n] = \sum_{k=0}^M b_k x[n-k] - \sum_{k=1}^N a_k y[n-k] as discussed in the second chapter on LTI systems. There we have shown that for instance a simple system characterized with .. math:: y[n] = x[n] + \alpha y[n-1] corresponds with an LTI system with an infinite impulse response: .. math:: h[n] = (1\;\alpha\;\alpha^2\;\alpha^3\;\cdots) and we have established that it is a stable filter in case $|\alpha|<1$. In this section we will analyze these IIR filters in the Z-domain. Setting $a_0=1$ the difference equation at the top can be rewritten as: .. math:: \sum_{k=0}^N a_k y[n-k] = \sum_{k=0}^M b_k x[n-k] Applying the Z-transform to both sides (and using the shift property) we get .. math:: \left(\sum_{k=0}^N a_k z^{-k} \right) Y(z) = \left(\sum_{k=0}^M b_k z^{-k} \right) X(z) or .. math:: H(z) = \frac{Y(z)}{X(z)} = \frac{\sum_{k=0}^M b_k z^{-k}}{\sum_{k=0}^N a_k z^{-k}} In these notes we are going to restrict ourselves to the case $M\leq 2$ and $N\leq2$. In audio processing such a digital filter is called a **biquad filter**. .. math:: H(z) &= \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{a_0 + a_1 z^{-1} + a_2 z^{-2}}\\ &= \frac{b_0 z^2 + b_1 z + b_2}{a_0 z^2 + a_1 z + a_2} The first expression if the starting point to represent the filter as a block diagram. The second form is starting point for poles-zeros analysis of the filter. The analysis in the Z-domain is done through some examples of digital filters. Consider the filter defined with difference equation .. math:: y[n] = \alpha y[n-1] + b_0 x[n] Leading to the transfer function $H(z)$: .. math:: H(z) = \frac{Y(z)}{X(z)} &= \frac{b_0}{1-\alpha z^{-1}}\\ &=\frac{b_0 z}{z-\alpha} The pole of this filter is at $z=\alpha$ and thus the filter is stable for $\alpha<1$. The frequency response of the filter can be found by substituting $e^{j\W}$ for $z$ in the transfer function: .. math:: H(\W) = H(z)\bigg\rvert_{z=e^{j\W}} = \frac{b_0}{1-\alpha e^{-j\W}} .. exec_python:: lowpass IIRfilters :linenumbers: :code: shutter :Code_label: Show code for figure :results: hide import numpy as np import matplotlib.pyplot as plt from audiolazy import z Hlow = 1/(1-0.8*z**(-1)) Hlow.plot(freq_scale='log', rate=44100) plt.savefig('source/figures/lowpassresppnse.png') .. figure:: /figures/lowpassresppnse.png **Lowpass Response of Filter** with transfer function $H(z) = \frac{1}{1-0.8 z^{-1}}$