EE342: MATLAB M-FILE FOR PLOTTING DTFT AND DFT SPECTRA

MATLAB M-File example10.m:
%
% Filename: example10.m
%
% Description: m-file that plots the DTFT and DFT spectra versus
%              discrete-time frequency
%

figure(1); clf;                     % open and clear figure 1
clear;                              % clear matlab memory

W = 0:0.001:2*pi;                   % define DT frequencies
F = sin(1.5*W).*exp(-j*W)./sin(W/2);% define DTFT F(W)

r=0:2;                              % define DFT frequency sample numbers
Wr=r*2*pi/3;                        % define DFT frequencies
Fr=[3 0 0];                         % define DFT Fr

subplot(2,1,1);                     % plot magnitude spectra
plot(W,abs(F)); hold on;
stem(Wr,abs(Fr),'filled'); hold off;
legend('|F(\Omega)|', '|F_r|');
xlabel('\Omega '); ylabel('|F|');
title('Magnitude Spectra of DTFT F(\Omega) and DFT F_r for f[k]=1,1,1');

subplot(2,1,2);                     % plot phase spectra
plot(W,angle(F)*180/pi); hold on;
stem(Wr,angle(Fr)*180/pi,'filled'); hold off;
legend('{\angle F(\Omega)}^o', '{\angle F_r}^o');
xlabel('\Omega '); ylabel('{\angle F}^o ');
title('Phase Spectra of DTFT F(\Omega) and DFT F_r for f[k]=1,1,1');
MATLAB Plot Generated: