%% Narrowband Section of Frequency Response
% Use czt to zoom in on a narrow-band section of a filter's frequency response.
% Design a 30th-order lowpass FIR filter using the window method. Specify a sample rate of 1 kHz and a cutoff frequency of 125 Hz. Use a rectangular window. Find the transfer function of the filter.

fs = 1000;
d = designfilt('lowpassfir','FilterOrder',30,'CutoffFrequency',125, ...
    'DesignMethod','window','Window',@rectwin,'SampleRate',fs);
h = tf(d);

%
% Compute the DFT and the CZT of the filter. Restrict the frequency range of the CZT to the band between 75 and 175 Hz. Generate 1024 samples in each case.

m = 1024;
y = fft(h,m);

f1 = 75;
f2 = 175;
w = exp(-j*2*pi*(f2-f1)/(m*fs));
a = exp(j*2*pi*f1/fs);
z = czt(h,m,w,a);

%
% Plot the transforms. Zoom in on the area of interest.

fn = (0:m-1)'/m;
fy = fs*fn;
fz = (f2-f1)*fn + f1;

plot(fy,abs(y),fz,abs(z))
xlim([50 200])
legend('FFT','CZT')
xlabel('Frequency (Hz)')

% Copyright 2015 The MathWorks, Inc.