write a program to compute the magnitude response at frequencies π*[-1:0.01:1] radians/sample. plot the results. in matlab

Here is a sample program to compute and plot the magnitude response:

main.m
% Create FIR filter
b = fir1(50, 0.5, 'low');

% Compute frequency response
w = -pi:0.01:pi;
h = freqz(b,1,w);

% Plot magnitude response
plot(w/pi, 20*log10(abs(h)))
grid on
xlabel('Normalized frequency (\times\pi rad/sample)')
ylabel('Magnitude (dB)')
title('Magnitude Response')
282 chars
14 lines

This program creates a lowpass FIR filter with 51 taps and a cutoff frequency of 0.5pi. It then computes the frequency response of the filter over the range of frequencies from -pi to pi, in increments of 0.01pi. Finally, it plots the magnitude response in dB, with frequency normalized to the range of -1 to 1.

Note that the freqz function returns the complex frequency response of a filter, but we take only the magnitude of this response in order to plot the frequency response.

related categories

gistlibby LogSnag