Question # 01: Write a function DFTsum(x) to compute DFT of signal x.
function z = DFTsum(x)
N=input('Enter the value of N');
z=zeros(1,N);
for k=1:N
y=0;
for n=1:N
y=y+x(n).*exp((-1j*2*pi*(k-1)*(n-1)/N));
end
z(k)=(y);
end
end
a) Compute DFT of x[n]=$[n] for N=10.
clc
clear all
close all
n=-4:4;
x=[1 zeros(1,9)]; % unit impulse
y=DFTsum(x); % calling DFTsum function and applying
stem(y)
title (‘DFT of x=delta(n)’);
b) Compute DFT for x[n]=1 for N=10.
𝟐𝝅𝒏
Compute DFT of 𝒙[𝒏] = 𝒄𝒐𝒔( ) for N=10.
𝟏𝟎
𝟐𝝅𝒏
Question # 02: Compute DFT of 𝒙[𝒏] = 𝒄𝒐𝒔( 𝟏𝟎 ) for N=512 and compare CPU time using
a) DFTsum function.
b) using built in function ‘fft’ of Matlab.
a) CPU time for application of self-made function DFTsum is 0.3906 seconds.
b) CPU time for commands fft and fftshift 0.0469 seconds.
Question # 03: x[n] = (0.5)n u[n]
a) Plot |X(w)| from –π < w< π
b) Compute 10 point DFT of x[n] & plot |X[k]| on same plot as part a.
c) Repeat b) for N=50 and N=100.
For N=50 samples
Repeating part a) and b) of question # 03 for 50 points DFT.
For N=100 samples:
Repeating part a) and b) of question # 03 for 100 points DFT.
Question # 04: Zero Padding x[n] = {1, 1, 1, 1} for n=0 to 3.
a) Plot |X (w)| for –π < w< π.
b) Compute 4 point DFT and plot |X (k)| on same plot as part a).
c) After zero padding N=32
Question # 05: Windowing Effect x[n] = Cos (wo n) + Cos (w1 n) + Cos (w2 n) for 0 < n < L-1.
a) For L=25
i) Plot |X(k)| for –π < w< π.
ii) Use Hanning window and plot |XN (k)| for –π < w< π.
b ) Repeat for L=50.
c ) Repeat for L=100.
Comments:
1. Zero Padding: Before zero padding the samples in frequency domain were less i.e. 4. We
couldn’t visualize the actual magnitude response correctly because the length of the signal was
too short. When the length was increased by adding zeros, and took DFT for N=32, the shape of
magnitude response was very close to the actual. The response become denser.
2. Computation time: The computation time for self-made DFT was larger that is 0.3 seconds and
for fft smaller because fft is “fast” Fourier transform built in MATLAB.
3. Windowing: By taking window length larger, we took more length of signal so it is more close to
delta and the identification of all frequency components is easier here. Because the longer a
signal is multiplied in time domain with a signal, the more close to delta function is convolved in
frequency domain and more close to the actual signal is obtained.