An IIR filter uses past outputs to shape the current output. This feedback loop helps create filters that can be very efficient and effective.
IIR filter structure (feedback loops) in Signal Processing
y[n] = (b0 * x[n]) + (b1 * x[n-1]) + ... + (bM * x[n-M]) - (a1 * y[n-1]) - ... - (aN * y[n-N])
x[n] is the current input sample.
y[n] is the current output sample.
The b coefficients multiply input samples, and the a coefficients multiply past output samples (feedback).
y[n] = 0.5 * x[n] + 0.5 * x[n-1] - 0.3 * y[n-1]
y[n] = 0.2 * x[n] + 0.1 * x[n-1] + 0.1 * x[n-2] - 0.4 * y[n-1] - 0.1 * y[n-2]
This code creates a step input signal and applies a simple IIR filter using the difference equation with feedback loops. It then plots both the input and filtered output to show how the filter smooths the step.
import numpy as np import matplotlib.pyplot as plt # Define input signal: a step signal x = np.zeros(50) x[10:] = 1 # Step starts at sample 10 # Coefficients for a simple IIR filter b = [0.5, 0.5] # feedforward coefficients a = [1.0, -0.3] # feedback coefficients (a[0] is always 1) # Initialize output array y = np.zeros_like(x) # Apply IIR filter using difference equation for n in range(len(x)): # Feedforward part ff = 0 for i in range(len(b)): if n - i >= 0: ff += b[i] * x[n - i] # Feedback part fb = 0 for j in range(1, len(a)): if n - j >= 0: fb += a[j] * y[n - j] y[n] = ff - fb # Plot input and output plt.plot(x, label='Input x[n]') plt.plot(y, label='Output y[n]') plt.title('Simple IIR Filter with Feedback Loop') plt.xlabel('Sample n') plt.ylabel('Amplitude') plt.legend() plt.grid(True) plt.show()
The feedback loop means the output depends on past outputs, so the filter can 'remember' past inputs.
Make sure the first feedback coefficient a[0] is 1 for the standard form.
Improper coefficients can make the filter unstable, causing outputs to grow without bound.
An IIR filter uses both past inputs and past outputs to calculate the current output.
Feedback loops allow the filter to be efficient and have sharp responses.
Understanding the difference equation helps you design and implement these filters.