What is an IIR Filter: Explanation, Example, and Uses
IIR filter (Infinite Impulse Response filter) is a type of digital filter that uses both current and past input values as well as past output values to produce its output. It can create complex filtering effects with fewer calculations compared to other filters because it feeds back part of its output into itself.How It Works
An IIR filter works like a smart echo machine. Imagine you shout into a canyon and hear your voice bounce back multiple times, each echo mixing with the next. Similarly, an IIR filter uses past outputs (echoes) combined with current and past inputs to shape the signal.
This feedback loop means the filter's output depends on an infinite number of past inputs and outputs, which is why itβs called "infinite impulse response." This makes IIR filters efficient because they can achieve sharp filtering effects with fewer calculations than filters that only use past inputs.
Example
This example shows a simple IIR filter applied to a signal using Python's scipy library. It filters out high-frequency noise from a noisy sine wave.
import numpy as np import matplotlib.pyplot as plt from scipy.signal import lfilter, butter # Create a noisy sine wave signal t = np.linspace(0, 1, 200) signal = np.sin(2 * np.pi * 5 * t) + 0.5 * np.random.randn(t.size) # Design a low-pass IIR Butterworth filter b, a = butter(N=3, Wn=0.1, btype='low') # Apply the IIR filter y = lfilter(b, a, signal) # Plot original and filtered signals plt.plot(t, signal, label='Noisy signal') plt.plot(t, y, label='Filtered signal') plt.legend() plt.xlabel('Time [seconds]') plt.ylabel('Amplitude') plt.title('IIR Filter Example') plt.show()
When to Use
Use IIR filters when you need efficient filtering with fewer calculations, especially in real-time systems like audio processing, communications, and control systems. They are great for removing noise or shaping signals where sharp cutoffs are needed but computational resources are limited.
However, because of feedback, IIR filters can be less stable and harder to design than other filters, so they are best when you need fast, efficient filtering and can carefully manage their design.
Key Points
- IIR filters use past outputs and inputs to create their output.
- They are efficient and can achieve sharp filtering with fewer calculations.
- They have an infinite impulse response due to feedback loops.
- Commonly used in audio, communications, and control systems.
- Require careful design to ensure stability.