0
0
RosConceptBeginner Β· 3 min read

What is an IIR Filter: Explanation, Example, and Uses

An 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.

python
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()
Output
A plot showing two lines: a noisy sine wave and a smoother filtered sine wave after applying the IIR filter.
🎯

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.
βœ…

Key Takeaways

IIR filters use feedback from past outputs to efficiently shape signals.
They are ideal for real-time filtering when computational resources are limited.
Designing IIR filters requires care to maintain stability.
They are widely used in audio and communication systems for noise reduction.
IIR filters can achieve sharp cutoffs with fewer calculations than other filters.