0
0
RosComparisonBeginner · 4 min read

FIR vs IIR Filter Difference: Key Points and Usage

A FIR (Finite Impulse Response) filter has a finite duration impulse response and is always stable with linear phase, while an IIR (Infinite Impulse Response) filter has feedback, potentially infinite impulse response, and can be unstable but uses fewer coefficients. FIR filters are simpler and have no feedback, whereas IIR filters are more efficient but may distort phase.
⚖️

Quick Comparison

Here is a quick side-by-side comparison of FIR and IIR filters based on key factors.

FactorFIR FilterIIR Filter
Impulse ResponseFinite lengthInfinite length (due to feedback)
StabilityAlways stableMay be unstable
Phase ResponseLinear phase possibleUsually nonlinear phase
ComplexityHigher order neededLower order sufficient
FeedbackNo feedback (non-recursive)Uses feedback (recursive)
Computational EfficiencyLess efficientMore efficient
⚖️

Key Differences

FIR filters compute output using only current and past input values without feedback, making them inherently stable and capable of exact linear phase response. This means the shape of the signal's waveform is preserved, which is important in applications like audio processing.

IIR filters use feedback from past output values, which can cause the impulse response to last indefinitely. This feedback can make the filter unstable if not designed carefully. IIR filters are more computationally efficient because they achieve sharp frequency responses with fewer coefficients but usually introduce phase distortion.

In summary, FIR filters are preferred when phase linearity and stability are critical, while IIR filters are chosen for efficiency and sharper filtering with fewer resources.

⚖️

Code Comparison

Example of a simple low-pass FIR filter using Python and SciPy.

python
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import firwin, lfilter

# Design FIR filter
numtaps = 21  # Number of filter taps (coefficients)
cutoff = 0.3  # Normalized cutoff frequency (0 to 1)
fir_coeff = firwin(numtaps, cutoff)

# Create a sample signal: sum of two sine waves
fs = 100  # Sampling frequency
t = np.arange(0, 1.0, 1/fs)
signal = np.sin(2 * np.pi * 5 * t) + 0.5 * np.sin(2 * np.pi * 20 * t)

# Apply FIR filter
filtered_signal = lfilter(fir_coeff, 1.0, signal)

# Plot
plt.plot(t, signal, label='Original Signal')
plt.plot(t, filtered_signal, label='FIR Filtered Signal')
plt.legend()
plt.title('FIR Low-pass Filter')
plt.xlabel('Time [s]')
plt.show()
Output
A plot showing the original signal with two sine waves and the FIR filtered signal with high-frequency components reduced.
↔️

IIR Equivalent

Equivalent low-pass IIR filter example using Python and SciPy.

python
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import butter, lfilter

# Design IIR Butterworth filter
order = 4
cutoff = 0.3  # Normalized cutoff frequency
b, a = butter(order, cutoff, btype='low', analog=False)

# Create the same sample signal
fs = 100
t = np.arange(0, 1.0, 1/fs)
signal = np.sin(2 * np.pi * 5 * t) + 0.5 * np.sin(2 * np.pi * 20 * t)

# Apply IIR filter
filtered_signal = lfilter(b, a, signal)

# Plot
plt.plot(t, signal, label='Original Signal')
plt.plot(t, filtered_signal, label='IIR Filtered Signal')
plt.legend()
plt.title('IIR Low-pass Filter')
plt.xlabel('Time [s]')
plt.show()
Output
A plot showing the original signal with two sine waves and the IIR filtered signal with high-frequency components reduced, typically with some phase distortion.
🎯

When to Use Which

Choose FIR filters when you need guaranteed stability and linear phase response, such as in audio processing, data communications, or when phase distortion must be minimized.

Choose IIR filters when computational efficiency is important and some phase distortion is acceptable, like in real-time systems with limited resources or when sharp frequency cutoffs are needed with fewer coefficients.

Key Takeaways

FIR filters are always stable and can have linear phase, preserving signal shape.
IIR filters use feedback, are more efficient but can be unstable and distort phase.
Use FIR when phase linearity and stability are critical.
Use IIR when computational efficiency and sharp filtering are priorities.
FIR filters require more coefficients than IIR for similar frequency response.