ad space

IIR Filter Frequency Response Matlab Code

IIR (Infinite Impulse Response) filters are a type of digital filter that use feedback to create a response. They are widely used in digital signal processing due to their simplicity, efficiency, and effectiveness in applications such as audio processing, image processing, and telecommunications. 

The frequency response of an IIR filter describes how the filter changes the amplitude and phase of a sinusoidal signal at different frequencies. This response can be visualized using a frequency response plot, which shows the magnitude and phase of the filter as a function of frequency. The shape of the frequency response depends on the filter design parameters, such as the filter coefficients and filter order. By analyzing the frequency response, it is possible to determine the filter's bandwidth, cutoff frequency, and resonance frequency, among other characteristics.

The following MATLAB code computes the magnitude and phase response of an IIR filter using the "freqz" and "grpdelay" functions. The coefficients of the filter are defined in the "b" and "a" arrays(see how to calculate IIR filter coefficients in Matlab).

%Matlab program for IIR Filter Magnitude and Phase Response

b=[0.0532 0.3725 1.1176 1.8626 1.8626 1.1176 0.3725 0.0532];
a=[1.0000 1.5473 2.1992 1.2240 0.8269 0.0347 0.0587 -0.0790];
[h,w] = freqz(b,a,256);
H=abs(h);
HdB=20*log10(H);
ph=angle(h);
Ph=unwrap(ph);
gd=grpdelay(b,a,256);
subplot(1,2,1)
plot(w,H);
grid
title('Magnitude of the frequency response')
ylabel('Magnitude')
xlabel('Normalized frequency')
subplot(1,2,2)
plot(w,HdB);
grid
title('Magnitude in dB of the frequency response')
ylabel('Magnitude in dB')
xlabel('Normalized frequency')
figure(2)
subplot(1,2,1)
plot(w,ph);grid
title('Phase response of the filter')
ylabel('Phase angle in radians')
xlabel('Normalized frequency')
subplot(1,2,2)
plot(w,Ph);grid
title('Unwrapped phase response filter')
ylabel('Phase angle in radians')
xlabel('Normalized frequency')

First, the code computes the frequency response "h" and the frequency vector "w" using the "freqz" function, with 256 frequency points. Then, it computes the magnitude response "H" and the magnitude in decibels "HdB" using the "abs" and "log10" functions.

The code also computes the phase response "ph" using the "angle" function, and then unwraps the phase using the "unwrap" function to obtain the phase response "Ph".

Finally, the group delay "gd" of the filter is computed using the "grpdelay" function. The magnitude and phase responses, as well as the unwrapped phase response, are plotted in separate subplots using the "plot" function, along with appropriate axis labels and titles.

 The following shows the resulting magnitude response, phase response and the phase angle plot.

IIR Filter Frequency Response graph

 
IIR filter phase response graph

 References

[1] FIR Filter Frequency Response Matlab Program

[2] Low-Pass Filter Design and Analysis in MATLAB 

[3] FIR filter design by frequency sampling

[4] Impulse Invariant Transformation Filter Design Example Work

[5] DFT in Matlab without built-in function

 

Post a Comment

Previous Post Next Post