How to Perform Frequency Response Analysis of Iir Filters Using Matlab and Python

Frequency response analysis is a fundamental step in understanding the behavior of Infinite Impulse Response (IIR) filters. It helps engineers and students evaluate how filters process different frequencies, ensuring they meet desired specifications. This article guides you through performing frequency response analysis of IIR filters using two popular tools: MATLAB and Python.

Understanding IIR Filters

IIR filters are a class of digital filters characterized by feedback, which makes their response infinite in duration. They are widely used in signal processing due to their efficiency and sharp frequency selectivity. Analyzing their frequency response provides insight into their behavior across the spectrum.

Performing Frequency Response Analysis in MATLAB

MATLAB offers built-in functions to easily analyze the frequency response of IIR filters. The freqz function is commonly used for this purpose.

Suppose you have a digital IIR filter defined by its numerator and denominator coefficients:

b = [0.0675, 0.1349, 0.0675]

a = [1.0000, -1.1430, 0.4128]

You can analyze its frequency response as follows:

[b, a] = [0.0675, 0.1349, 0.0675], [1.0000, -1.1430, 0.4128]
freqz(b, a)

This command plots the magnitude and phase response, providing a clear view of how the filter behaves across frequencies.

Performing Frequency Response Analysis in Python

Python users can utilize the scipy.signal library to analyze IIR filters. The freqz function in this library performs a similar task as MATLAB’s.

Using the same filter coefficients as above, here’s how to perform the analysis in Python:

import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import freqz

b = [0.0675, 0.1349, 0.0675]
a = [1.0000, -1.1430, 0.4128]

w, h = freqz(b, a, worN=8000)

plt.figure()
plt.plot(w / np.pi, 20 * np.log10(abs(h)))
plt.title('Frequency Response')
plt.xlabel('Normalized Frequency (×π rad/sample)')
plt.ylabel('Magnitude (dB)')
plt.grid()
plt.show()

This script plots the magnitude response in decibels, allowing you to analyze how the filter attenuates or passes different frequencies.

Conclusion

Both MATLAB and Python provide powerful tools for frequency response analysis of IIR filters. MATLAB’s freqz function offers quick and straightforward visualization, while Python’s scipy.signal.freqz provides flexibility and integration with other Python libraries. Mastering these tools enables engineers and students to design and evaluate filters effectively in digital signal processing projects.