EE342.01: MATLAB M-FILE FOR PLOTTING DISCRETE-TIME PULSE MAGNITUDE SPECTRA

MATLAB M-File example11.m:
%
% Filename: example11.m
%
% Description: m-file to plot magnitude spectrum of p5[n]
%

clear; clf;

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

Xa = 1 + 2*cos(W) + 2*cos(2*W); % plot |X(W)| from cosines
subplot(2,1,1);
plot(W,abs(Xa));
xlabel('W '); ylabel('|X(W)|');
title('DTFT of p5[n] (from sum of cosines)');

Xb = sin(2.5*W)./sin(W/2);      % plot |X(W)| sinc-like function
subplot(2,1,2);
plot(W,abs(Xb));
xlabel('W '); ylabel('|X(W)|');
title('DTFT of p5[n] (from sinc-like function)');
MATLAB Plot Generated: