%% FIR Lowpass Filter
% Design a 30th-order lowpass filter with a normalized cutoff frequency of 0.6\pi rad/sample. Plot the ideal frequency response overlaid with the actual frequency response.

f = [0 0.6 0.6 1];
m = [1 1 0 0];

b1 = fir2(30,f,m);
[h1,w] = freqz(b1,1);

plot(f,m,w/pi,abs(h1))
xlabel('\omega / \pi')
lgs = {'Ideal','fir2 default'};
legend(lgs)

%
% Redesign the filter using a 64-point interpolation grid.

b2 = fir2(30,f,m,64);
h2 = freqz(b2,1);

hold on
plot(w/pi,abs(h2))
lgs{3} = 'npt = 64';
legend(lgs)

%
% Redesign the filter using the 64-point interpolation grid and a 13-point interval around the cutoff frequency.

b3 = fir2(30,f,m,64,13);
h3 = freqz(b3,1);

plot(w/pi,abs(h3))
lgs{4} = 'lap = 13';
legend(lgs)

% Copyright 2012 The MathWorks, Inc.