FIR Filter Frequency Response Matlab Program

 A Finite Impulse Response (FIR) filter is a type of digital filter that uses a finite number of past input samples to produce a filtered output. FIR filters are characterized by their impulse response, which is finite in length, and therefore, the filter is always stable. FIR filters can be designed to have linear phase response, which means that the phase shift introduced by the filter is proportional to the frequency.

The transfer function equation of a general digital filter is given by the following equation:

\( H(z)=\frac{\sum_{k=0}^{M-1}b_{k}z^{-k}}{\sum_{k=0}^{N-1}a_{k}z^{-k}} \) ---->(1)

or, \( H(z) = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2} + ... + b_n z^{-n}}{a_0 + a_1 z^{-1} + a_2 z^{-2} + ... + a_n z^{-n}}\)

The frequency response of an FIR filter can be obtained by taking the discrete Fourier transform of its impulse response. The frequency response of an FIR filter is a function of the normalized frequency and can be visualized as a plot of magnitude and phase response. The magnitude response of an FIR filter can be used to determine the frequency selectivity of the filter, while the phase response is important for preserving the shape of the signal waveform.

The following MATLAB program calculates the magnitude and phase response of a Finite Impulse Response (FIR) filter.

% Matlab program for FIR Filter Magnitude and Phase Response

b=[1.0 0.8 0.6 0.4 0.6 0.8 1.0];
[h,w]=freqz(b,1,256,'whole');
H=abs(h);
ph=angle(h);
plot(w,H);grid
title('Magnitude of the FIR filter')
ylabel('Magnitude')
xlabel('Normalized frequency from 0 to 2*pi')
figure
plot(w,ph);
grid
title('Phase response of the FIR filter')
ylabel('Phase angle in radians')
xlabel('Normalized frequency')

The coefficients of the filter(see how to calculate IIR filter coefficients in Matlab) are specified in the variable b. The freqz function is used to calculate the frequency response of the filter. The function takes in the filter coefficients, 1 as the denominator, and 256 as the number of frequency points. The 'whole' option specifies that the frequency response should be calculated for frequencies from 0 to 2Ï€. The magnitude and phase response are then calculated using the abs and angle functions respectively. Finally, the plot function is used to plot the magnitude and phase response of the filter versus normalized frequency. The grid function is used to show a grid in the plot. The magnitude response plot shows the gain of the filter at different frequencies, while the phase response plot shows the phase shift introduced by the filter at different frequencies.

Below are the frequency response graph showing magnitude response and phase response graphs.

FIR filter phase response

FIR filter frequency response

 References

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

[2] IIR Filter Frequency Response Matlab Code

[3] Impulse Invariant Transformation Filter Design Example Work

[2] DFT in Matlab without built-in function

Post a Comment

Previous Post Next Post