Infinite Impulse Response (IIR) filters are such filters which include recursion, respectively feedback, in their implementation. Their impulse response does thus not drop to zero after a given time. They can become instable due to the feedback. However, IIR filters require less coefficients and thus less operations to get a filter with the desired effect than FIR filters. As FIR filters, IIR filters create an output sequence $y[n]$ for an input sequence $x[n]$. However, the recursion makes the simple convolution analogy impossible.
The Difference Equation¶
The difference equation known from FIR filters needs to be extended for IIR filters. Recursion is included with additional coefficients $a_n$, feeding back the output signal $y[n]$ with different delays. The following difference function represents a second order IIR filter. Also referred to as biquad filter, this is a basic component for many digital filter implementations:
$$ y[n] = b_0 x[n] + b_1 x[n-1]+ b_2 x[n-2] - a_1 y[n-1] - a_2 y[n-2] $$
The general form of the difference equation for IIR filters is the following sum equation, combining both the forward and recursive elements:
$$ y[n] = \sum\limits_{i=0}^{i=N} b_i x[n-i] - \sum\limits_{i=1}^{i=N} a_i y[n-i] $$
Implementation Structure¶
The above difference equation can be transferred into signal flow diagrams, with different implementation structures. These structures can be directly implemented in actual code. Although they all translate to the same difference equation, the implementation details can have an impact on the filter's properties. The following signal flow diagram shows the Direct Form 1:
An alternative is the Direct Form 2, which uses less delay units:
Exercise¶
The non-standard signal flow diagram below describes an IIR filter.
- 1: Determine the order and filter coefficients.
- 2: Write the difference equation for the filter.
- 3: Calculate the impulse response on paper up to 4 samples.
Solution¶
1: Get Filter Coefficients¶
For the feed-forward coefficients $b_i$ we start at the input node $x[n]$ and follow each path to the output node $y[n]$. We count the number of delays we have to determine the index of our coefficient:
- $b_0 = 0.1$
- $b_1 = 0.5$
- $b_2 = 0.1$
Or, as a vector:
$b = [0.1,0.5,0.1]$
For the feedback coefficients $a_i$ we start at the output node $y[n]$ and follow each feedback path, again counting the delays on each path. We have to flip the sign of the gain elements:
- $a_1 = 0.5$
- $a_2 = -0.25$
As a vecor:
$a = [0.5, -0.25]$
2: The Difference Equation¶
For the difference equation, can simply insert the coefficients into the following equation:
$$ y[n] = \sum\limits_{i=0}^{i=N} b_i x[n-i] - \sum\limits_{i=1}^{i=N} a_i y[n-i] $$
If we take the values from the coefficients listed above, we need to flip the sign again (which corresponds to the values in the signal flow diagram):
$$ y[n] = 0.1 x[n] + 0.5 x[n-1] + 0.1 x[n-2] -0.5y[n-1] +0.25y[n-2] $$
3: Impulse Response¶
We assume the following input vector to measure the impulse response:
$x[n] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]$
We can calculate the output $y[n]$ sample by sample:
Step 1: n=0
$y[0] = x[0] \cdot b[0] = 1 \cdot 0.1 = \mathbf{0.1}$
$y[n] = [\mathbf{0.1}]$
Step 2: n=1
$y[1] = x[n-1] \cdot b[1] - y[0] \cdot a[0] = 0.5 - 0.1 \cdot 0.5 = \mathbf{0.45}$
$y[n] = [0.1,\mathbf{0.45}]$
Step 3: n=2
$y[2] = x[n-2] \cdot b[2] - y[n-1] \cdot a[0] - y[n-2] \cdot a[1]$
$y[2] = 1 \cdot 0.1 - 0.45 \cdot 0.5 - 0.1 \cdot -0.25$
$y[2] = 0.1 - 0.225 + 0.025 = \mathbf{-0.1}$
$y[n] = [0.1,0.45,\mathbf{-0.1}]$
Step 4: n=3
At this step, we have no more input signal taken into the equation, since $x[3-2] = 0$:
$y[3] = - y[n-1] \cdot a[0] - y[n-2] \cdot a[1]$
$y[3] = - -0.1 \cdot 0.5 - 0.45 \cdot -0.25$
$y[3] = 0.05 + 0.1125 = \mathbf{0.1625}$
$y[n] = [0.1,0.45,-0.1,\mathbf{0.1625}]$
....
$\mathbf{y = [ 0.1, 0.45, -0.1, 0.1625, -0.10625, 0.09375, -0.0734375, 0.06015625, -0.0484375, 0.03925781]}$