MATLAB Codes DFT
MATLAB Codes DFT
function z = DFTsum(x)
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
𝟐𝝅𝒏
Question # 02: Compute DFT of 𝒙[𝒏] = 𝒄𝒐𝒔( 𝟏𝟎 ) for N=512 and compare CPU time using
a) DFTsum function.
a) For L=25
ii) Use Hanning window and plot |XN (k)| for –π < w< π.
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.