EE342: MATLAB M-FILE FOR PLOTTING DISCRETE-TIME RECTANGLE MAGNITUDE SPECTRA

MATLAB M-File example8.m:
%
% Filename: example8.m
%
% Description: m-file to plot magnitude spectrum of
%              f[k]=u[k+2]-u[k-3].
%

clear; clf;

W = -3*pi:0.01:3*pi;            % define DT frequencies

Fa = 1 + 2*cos(W) + 2*cos(2*W); % plot |F(W)| from cosines
subplot(2,1,1);
plot(W,abs(Fa));
xlabel('\Omega '); ylabel('|F(\Omega)|');
title('DTFT of f[k]=u[k+2]-u[k-3] (from sum of cosines)');

Fb = sin(2.5*W)./sin(W/2);      % plot |F(W)| sinc-like function
subplot(2,1,2);
plot(W,abs(Fb));
xlabel('\Omega '); ylabel('|F(\Omega)|');
title('DTFT of f[k]=u[k+2]-u[k-3] (from sinc-like function)');
MATLAB Plot Generated: