You are on page 1of 12

Digital Signal Processing Lab Manual

DEPARTMENT OF ELECTRICAL ENGINEERING


GCU LAHORE
Experiment # 9
Title: Discrete Time Transform (DFT)

Equipment Required: Personal computer (PC) with windows operating system


and MATLAB software
Theory:-
In Lab Experiment 7, we have discussed in detail the Discrete Time Fourier Transform
(DTFT) for the analysis of signals given by:

(DTFT): X (e j )   x(n)e jn

n 
(1)  
 
1 
(IDTFT): x(n)  j
 X (e )e
jn (2)
2 

While DTFT is very useful analytically, it usually cannot be exactly evaluated on a


computer because equation (1) requires an infinite sum and equation (2) requires the
evaluation of an integral.

The discrete Fourier transform (DFT) is a sampled version of the DTFT, hence it is better
suited to numerical evaluation on computers
N 1
Analysis Equation (DFT): X (k )   x(n)e  j 2kn / N (3)
n0

1 N 1 j 2kn / N
Synthesis Equation (lDFT): x(n)  X (k )e (4)
N k 0
Digital Signal Processing Lab Manual
Using the matrix vector multiplication technique used to compute the DTFT and DTFS in
previous laboratory experiments, we can calculate the DFT using:

WNnk e  j 2kn / N


Equation (3) and (4) can be written as: X (k )  N 1 nk (6)

 x(n)WN
n0
1 N 1
Analysis Equation (DFT): x(n)  X (k )W nk (7)

 N
N k 0

Or equivalently,

X(k) = WNx(n)

x(n) =1/N WN*X(k)

WN is a square matrix. The following MATLAB function implements the above


procedure.
DFT Function

function [Xk] =dft (xn,N)


%ComputeDiscreteFourierTransform
n=[0:1:N-1];
k= [0:1:N-1];
WN = exp (-j * 2 * pi / N);
nk = n' * k;
WNnk = WN.^ nk;
Xk = xn * WNnk;

The following idft function implements the synthesis equation.


IDFT Function

function [xn] =idft (Xk, N)


%Compute Inverse Discrete Transform
n= [0:1:N-1];
61

k = [0:1:N-1];
WN = exp (-j * 2 * pi / N);
Page

nk = n' * k;
Digital Signal Processing Lab Manual

WNnk = WN .^ (-nk) ;
xn = (Xk * WNnk)/N;

Zero-Padding:-
It is an operation in which more zeros are appended to the original sequence. The
resulting longer DFT provides closely spaced samples of the discrete time Fourier
transform of the original sequence. In MATLAB zero padding is implemented using the
zeros function. The zero padding gives high-density spectrum and provides a better
displayed version for plotting. But it does not give a high resolution spectrum because no
new information is added to the signal: only additional zeros are added in the data.

Procedure:-
Execute following examples in MATLAB

EXAMPLE

To illustrate the difference between high-density spectrum and the high-resolution


spectrum consider the sequence

x(n) =cos(0.48πn) + cos(0.52πn)

a) High resolution spectrum based on 100 samples of the signal x(n)

subplot( 1,1,1)
n=[0:1:99];
x=cos(0.48 *pi *n)+cos(0.52 *pi *n);
subplot(2,1, 1);stem(n,x);
title('signal x(n), 0 <= n <= 99');xlabel('n')
axis([0, 100,-2.5,2.5])
X=fft(x);magX=abs(X(1: 1:51));
k=0:1:50;w=2*pi/100*k;
subplot(2,1 ,2);plot(w/pi,magX);title('DTFT
Magnitude');xlabel('frequency in pi units')
axis([0,1,0,60])
62
Page
Digital Signal Processing Lab Manual

MATLAB:

b)Spectrum based on the first 10 samples of x(n)

n1=[0: 1:9];y1 =x( 1: 1: 10);


subplot(2,1, 1);stem(n1,y1);
title('signal x(n), 0 <= n <= 9');xlabel('n')
axis([0,10,-2.5,2.5])
Y1 =fft(y1);magY1
=abs(Y1( 1:1:6)); k1
=0:1:5;w1 =2*pi/10*k1;
subplot(2,1
,2);stem(w1/pi,magY1 );
title('Samples of DTFT
Magnitude');
xlabel('frequency in pi
units') axis([0,1 ,0,
10])
disp('Press RETURN to continue');pause;
63
Page
Digital Signal Processing Lab Manual

MATLAB:

C) High density Spectrum (50 samples) based on the first 10 samples of x(n)

n2=[0:1:49];y2=[x(1: 1:10) zeros(1,40)];


subplot(2,1, 1);stem(n2,y2);
title('signal x(n), 0 <= n <= 9 + 40
zeros');xlabel('n') axis([0,50, -2.5,2.5])
Y2=fft(y2);magY2=abs(Y2(
1:1:26)); k2=0:
1:25;w2=2*pi/50*k2;
subplot(2,1
,2);plot(w2/pi,magY2);
title('DTFT Magnitude');xlabel('frequency in
pi units') axis([0,1,0,10])
MATLAB:

64
Page
Digital Signal Processing Lab Manual

D)High density spectrum (100 samples) based on the first 10 samples of x(n)

n3=[0: 1:99];y3=[ x(1: 1:10) zeros( 1,90)];


subplot(2,1, 1);stem(n3,y3);
title('signal x(n), 0 <= n <= 9 + 90
zeros');xlabel('n') axis([0,100,-2.5,2.5])
Y3=fft(y3);magY3=abs(Y3(
1: 1:51));
k3=0:1:50;w3=2*pi/100*k3
; subplot(2,1
,2);plot(w3/pi,magY3);
title('DTFT Magnitude');xlabel('frequency in
pi units') axis([0, 1,0, 10])
MATLAB:

65
Page
Digital Signal Processing Lab Manual

PROBLEMS .
1) Determine the DFT of the following periodic sequences using the
DFT definition, and verify by using MATLAB.
a. x1(n)={2,0,2,0},N=4

b. x2(n) = {0,0, 1,0, 0}, N = 5


Digital Signal Processing Lab Manual

c. X3(n) = {3, -3,3, -3}, N = 4

d. x4(n) = {j,j, -j, -j}, N = 4


Digital Signal Processing Lab Manual

e. x5(n) = {1,j,j, 1}, N = 4

2)Determine the x(n), First use the IDFS definition and then verify' using MATLAB.
a. X1(k) = {5, -2j, 3, 2j}, N = 4
Digital Signal Processing Lab Manual

b. X2(k)={4,-5,3,-5},N=4

c. X3(k)={I,2,3,4,5},N=5
Digital Signal Processing Lab Manual

d. X4(k)={0,0,2,0},N=4

e. X5 (k) = {0,j, -2j, -j}, N = 4


Digital Signal Processing Lab Manual

CONCLUSION:
I have learned about Zero-Padding. It is an operation in which more zeros are appended to the
original sequence. The resulting longer DFT provides closely spaced samples of the discrete
time Fourier transform of the original sequence. In MATLAB zero padding is implemented
using the zeros function. The zero padding gives high-density spectrum and provides a better
displayed version for plotting. But it does not give a high-resolution spectrum because no new
information is added to the signal: only additional zeros are added in the data.

You might also like