%% L10_DFT %% ===================== %% Script to illustrate how to:- %% (i) calculate DFT and %% (ii)investigate relationship between DFT and DTFT. %% %% Created : 17 Aug 2005 %% Modified : 17 Aug 2005 %% %% Copyright (c) 2005 Salman Durrani. %% ------------------------------------------------------------ clc clear all close all n=[0 1 2 3]; x=[0 1 0 0]; %% ------------------------------------------------------------ %% Find FFT N=4; X = fft(x); %% Find DTFT num=[0 1]; den=1; w = [0:0.01:2*pi]; [H,W]=freqz(num,den,w); %% Plot Mags (without scaling x axis) subplot(2,2,1) stem(n,abs(X),'filled') hold on plot(W,abs(H),'k-') xlabel('Sample k') ylabel('|X[k]|') legend('DFT Magnitude','DTFT Magnitude') %% Plot Phases (without scaling x axis) subplot(2,2,3) stem(n,angle(X)*180/pi,'filled') hold on plot(W,angle(H)*180/pi,'k-') xlabel('Sample k') ylabel('< X[k] (degs)') legend('DFT Phase','DTFT Phase') %% Plot Mags (scaling x axis) subplot(2,2,2) stem(n,abs(X),'filled') hold on plot(W*N/(2*pi),abs(H),'k-') xlabel('Sample k') ylabel('|X[k]|') legend('DFT Magnitude','DTFT Magnitude') %% Plot Phases (scaling x axis) subplot(2,2,4) stem(n,angle(X)*180/pi,'filled') hold on plot(W*N/(2*pi),angle(H)*180/pi,'k-') xlabel('Sample k') ylabel('< X[k] (degs)') legend('DFT Phase','DTFT Phase')