LAB5
Title: Discrete Fourier Transform:
Student Name:
Reg. No. :
Date :
Signature :
Objectives:
1) Implementing DFT and IDFT in Matlab.
2) Showing the meaning of frequency resolution and Time Resolution
3) Compare between Conventional DFT and FFT.
Preparation: (15 mins)
Numerical Computation of Frequency domain:
DTFT and Z-transform both provide frequency domain for discrete signals and are not numerically
computable transforms due to the following reasons:
1) They are defined for infinite length sequences
2) They are functions of continuous variables (w or z)
The evaluations of those transforms in Matlab or any DSP system are just approximations to the exact
calculations.
We need to avoid these issues and use a transform that is suitable for computer implementations.
DFS resolves the second issue by sampling the frequency domain variables, w or z, but in time domain,
it uses periodic sequences with infinite duration.
DFT avoids the two mentioned issues by sampling the frequency domain and used for finite duration
sequences.
DFT is numerically computable transform. Its computations for long sequences is time consuming,
therefor several algorithms has been developed to efficiently compute DFT. They are called FFT
algorithms
Frequency Sampling Theorem:
If x(n) is time-limited sequence in [0,N-1] interval, then finite N frequency samples evenly spaced
(2*pi/N) over the interval [0,2*pi] are sufficient to reconstruct the whole discrete time Fourier
transform, DTFT, of the sequence x(n).
The N equal-spaced coefficients are called DFT coefficients, X(k).
The DFT X(k) is expressed:
And IDFT is expressed:
Procedure:
Step1: Write down the following DFT and IDFT functions, open a new script (15 Minutes)
function [Xk] = dft(xn,N)
n = [Link]N-1]; % row vector for n
k = [Link]N-1]; % row vector for k
WN = exp(-j*2*pi/N); % WN factor
nk = n' * k; % Create N X N matrix of n*k values
WNnk = WN .^ nk; % N X N DFT Matrix
Xk = xn * WNnk; % row vector of DFT coefficients
Save it with dft.m name.
Then open a new script and write down:
function [xn] = idft(Xk,N)
n = [Link]N-1]; % row vector for n
k = [Link]N-1]; % row vector for k
WN = exp(-j*2*pi/N); % WN factor
nk = n' * k; % Create N X N matrix of n*k values
WNnk = WN .^ (-nk); % N X N IDFT Matrix
xn = (Xk * WNnk)/N; % row vector of IDFT values
Save it with idft.m name.
Try in command window:
x = [1 2 3 4 5]
N=5
X = dft(x,N)
x_idft = idft(X,N)
Q1) Write down the values of x, X, and x_idft, what do they represent?
Step2: Frequency Resolution of DFT versus Time resolution (15 Mins)
Calculate DFT for the following signal:
x(n) = cos(0.48*pi*n) + cos(0.52*pi*n)
N = 10;
n = (0:N-1);
k = (-N/2:N/2);
xn = cos(0.48*pi*n) + cos(0.52*pi*n);
X = dft(xn,N);
Xamp = abs([X(N/2+1:N) X(1:N/2+1)]);
w = (2*pi)/N * k;
subplot(2,1,1), stem(n,xn),grid on;
subplot(2,1,2), stem(w,Xamp),grid on
Q2) Try using N = 10, 20, 50, 80, and 100 samples, Write your note?
Step3: Comparing in time consuming between DFT and FFT
open a new script and write the following:
k = (1:11);
fft_time = zeros(1,11);
dft_time = zeros(1,11);
N = pow2(k)
for m=1:11
r = rand(1,N(m));
t = clock;fft(r);fft_time(m)= etime(clock,t);
t = clock;dft(r,N(m));dft_time(m)= etime(clock,t);
end
plot(N,fft_time,N,dft_time),legend('FFT TIme','DFT Time');
grid on;xlabel('N Samples');ylabel('Processing Time');
Q3) Draw the figure, what does it figure out?
Homework:
Using the above dft.m function, compute DFT for the following signal:
x(n) = [ 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0]
Plot its time and amplitude spectrum.