PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

516 Practical MATLAB® Applications for Engineers


over the ranges 0 ≤ k ≤ 32 and 0 ≤ k ≤ 64.

MATLAB Solution
% Script file: DTFT _ DFT
k = linspace(0,16,32);
fn32 = cos(3*pi*k/16);
kk = linspace(0,16,64);
fn64 = cos(3*pi*kk/16);
DFT _ fn32 = fft(fn32);
DFT _ fn64 = fft(fn64);
DFT _ fn = fft(fn32,256);
W = 0:1:255;

figure(1)
subplot (2,1,1)
plot (W,abs(DFT _ fn));
title (‘ Magnitudes of the DTFT and DFT’)
ylabel (‘Amplitude’)
axis ([0 259 0 20])
hold on
WW= linspace(0,255,32);
plot(WW,abs(DFT _ fn32),’*’,WW,abs(DFT _ fn32))
axis ([0 259 0 20])
subplot (2,1,2)
plot (W,abs(DFT _ fn));
ylabel (‘Amplitude’)
hold on
WWW= linspace(0,255,64);
plot (WWW,abs(DFT _ fn64),’o’,WWW,abs(DFT _ fn64));
xlabel (‘ Index k’);axis([0 259 0 29]);

figure(2)
subplot(2,1,1)
plot (W,angle(DFT _ fn));
title (‘ Phase of the DTFT and DFT’)
ylabel (‘Phase angle’)
axis ([0 259 -4 4])
hold on
plot (WW,angle(DFT _ fn32),’*’,WW,angle(DFT _ fn32))
subplot (2,1,2)
plot (W,angle(DFT _ fn))
axis ([0 259 -4 4])
hold on
plot (WWW,angle(DFT _ fn64),’o’,WWW,angle(DFT _ fn64));
axis([0 259 -4 4])
ylabel(‘Phase angle’)
xlabel(‘Index k’)

The script fi le DTFT_DFT is executed and the results are indicated in Figures 5.29
and 5.30.
Free download pdf