EEE324 Digital Signal Processing Lab Reports # 04
EEE324 Digital Signal Processing
Lab # 04: Discrete Fourier Transform and its
Properties
Name Abdul basit
Registration Number FA18-BEE-002
Class BEE-6A
Instructor’s Name Ma’am Nida Zamir
Lab Assessment
Post Lab Total
Pre-Lab In-Lab Data
Data Analysis Writing Style
Presentation
Details of Group Members
Abdul Basit FA18-BEE-002
Hareem Safdar FA18-BEE-048
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
Lab # 04: Discrete Fourier Transform and its
Properties
Objective
By the end of this lab students will be able to compute and plot the DFT of a discrete signal on
Matlab using FFT command, and perform periodic convolution on Matlab, in-addition students
will verify the properties of DFT.
Pre-Lab
1. DFT
For a periodic signal x[n] with a period N, discrete Fourier transform (DFT) is computed as
X (k) = ∑ x (n) e-j(2π/N)kn
Where w0 = 2π/N is the fundamental frequency of the signal. Following two conditions must satisfied
for its DFT to be computed
i. x[n] should be of finite length of length N.
ii. x[n] should be made periodic by repeating the system infinite times
Since x[n] is periodic the FT of its one period will completely characterize the system, hence the
summation will go from 0 to N-1.
2. DTFT
DFT is the computable version of discrete time Fourier transform. Despite being the Fourier transform
of a discrete signal x[n], DTFT X(ejw) is function of a continuous variable w, given by
X (k) = ∑ x (n) e-jwn
In order to compute DTFT, infinite summations are required, which is not possible, hence DFT is
computed for the knowledge of frequency response. Figure below presents DFT as the discretized
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
version of discrete time Fourier transform (DTFT) in frequency domain.
The DTFT is a transformation that maps Discrete-time (DT) signal x[n] into a complex valued function
of the real variable, if x (n) is absolutely sum able i.e.
Then, discrete-time Fourier transforms (DTFT):
Inverse discrete-time Fourier transform (IDTFT) of X(ejwn):
2.1 Periodicity
The DTFT X(ejw) is periodic in w with period 2 :
2.2 Implication
We need only one period of X(ejw)
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
2.3 Symmetry
For real-valued x(n), X(ejw) is conjugate symmetric
X(ejw) = X*(ejw) or
Re[X(e-jw)] = Re[X(ejw)]
(even symmetry)
Im[X(e-jw)] = Im[X(ejw)]
(odd symmetry)
|X(e-jw)| = |X(ejw)|
(even symmetry)
phase(X(e-jw)) = phase(X(ejw)) (odd symmetry)
2.4 Implication:
We need only half period of X(ejw) i.e. w [0, ]
3. Shifting and convolving periodic signals
3.1 Periodic or circular Shift
Shifting in periodic sequences is referred to as circular shift, x[n-l] is depicted in the figure
below,
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
In-Lab
1. FFT Command in Matlab
FFT command is used to compute Discrete Fourier Transform (DFT), it uses one-dimensional fast
algorithm namely Fast Fourier transform to compute DFT.
Y = fft(X)
Y = fft(X, n)
The functions X = fft(x) implement the transform for vectors of length N by:
Y = fft(X) returns the discrete Fourier transform of vector X, computed with a fast Fourier transform
(FFT) algorithm.
If X is a matrix, fft returns the Fourier transform of each column of the matrix.
πIf the length of X is less than n, X is padded with trailing zeros to length n.
If the length of X is greater than n, the sequence X is truncated.
The fft function employs a radix-2 fast Fourier transform algorithm if the length of the sequence is a
power of two.
The frequency axis w, in case of discrete signals goes from w = –π → π.
Example:
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
However normalized frequency w/π goes from -1 to 1, defined as follows in Matlab.
Abs
Absolute value and complex magnitude Y = abs(X)
Abs(X) returns an array Y such that each element of Y is the absolute value of the corresponding
element of X.
Angle:
Phase angle P = angle (Z) returns the phase angles, in radians, for each element of complex
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
array Z. The angles lie between . For complex Z, the magnitude R and phase angle theta are
given by:
5. Verifying the DFT Properties on Matlab
5.1.Linearity property
(Pseudo-code)
i. Take two signals x1[n] and x2[n].
ii. Compute the LHS as
a. Multiply x1[n] with constant α and x2[n] with a constants β
b. Add αx1[n] and βx2[n] using sigadd function
c. Take the DFT of the sum computed in last step using FFT command
iii. Compute the RHS as
a. Take the DFT of x1[n] and x2[n] using FFT command
b. Multiply the constants α and β with DFTs of x1[n] and x2[n] respectively.
c. Add the αDFT{x1[n]} and βDFT{x2[n]} using sigadd function
iv. Subplot both LHS and RHS to compare both sides
MATLAB Code
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
5.2.Parsevals theorem
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
(Pseudo-code)
i. Take a signals x[n].
ii. Compute the LHS as
a. Compute the mod of x[n] using abs() command
b. Take the square of the mod of x[n] (calculated in last step)
c. Compute the sum of squared mod of x[n] (calculated in last step) to obtain the energy of x[n],
use sum() command for computing sum.
If we consider only one period of this sequence then this shifting can be considered as circular
shift, depicted below.
3.2 Periodic Convolution
Convolution of two periodic sequences is referred to as periodic convolution. As the same
sequence is repeating after a N samples, it is sufficient to calculate the convolution for only the
one period and repeat the resulted sequence infinite times to yield the convolved sequence.
Figure below depicts the circular convolution of y[n] = [1 1 1 1 0 0 0 1] and h[n] = [0 0 0 0 1 1
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
1 1]
iii. Compute the RHS as
a. Compute the DFT of x[n] using fft command
b. Compute the mod of DFT{x[n]} using abs() command
c. Take the square of the mod of DFT{x[n]} (calculated in last step)
d. Compute the sum of squared mod of DFT{x[n]} (calculated in last step)
iv. Compare the result of both LHS and RHS
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
>> LHS_Energy = 1.0000
>> RHS_Energy = 1.0000
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
In-Lab Tasks
Lab Tasks
Task 01:
Write Matlab function for circular shift by first writing its pseudo-code of the procedure explained
in the In-Lab section and then writing its code.
Code:
% Task 01
clear all
close all
clc
n = 1:7;
y = [1 2 3 4 5 6 7];
subplot (2,1,1);
stem (n,y,'r','LineWidth',2)
title 'original graph'
xlabel 'Time --->';
ylabel 'Amplitude --->';
K= length (n);
P= 3;
z = circshift(y, [K,P]);
subplot(2,1,2);
stem (n,z,'r','LineWidth',2)
title 'circular shifted graph'
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
xlabel 'Time --->';
ylabel 'Amplitude --->';
Figure:
Task 02:
Verify the time shifting property of DFT by first writing a pseudo code of the RHS
and LHS followed by the MATLAB code. Use the circular shift function designed above for
shifting in time domain. Compare the result by sub-plotting LHS and RHS of the following
equation.
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
Code:
n = 1:5;
x = [1 2 3 4 5];
subplot (4,1,1)
stem (n,x)
m = 2;
N = length (x)
Y = circshift (x, [N m]);
subplot (4,1,2)
stem (n,Y)
z = fft (Y,N);
w = linspace (-3.14,3.14,N);
subplot (4,1,3)
stem (w,z)
for k = 1:N
wn = exp(-1j*2*k*m*3.14/N);
end
x = fft (x,N);
c = x.*wn;
subplot (4,1,4)
stem (w,c)
Output:
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
Task 03:
Verify the duality property of DFT by first writing a pseudo code of the RHS and LHS
followed by the MATLAB code. Compare the result by sub-plotting LHS and RHS of the
following equation.
Code:
n = 1:5;
x = [1 2 3 4 5];
subplot (3,1,1)
stem (n,x,'r','LineWidth',2)
N = length (x)
y = N.*x;
y = fft (y);
w = linspace (0,6,N);
subplot (3,1,2)
stem (w,y,'r','LineWidth',2)
X = fft (x);
subplot (3,1,3)
stem (w,X,'r','LineWidth',2)
Output:
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
Task 04:
Write Matlab function for circular convolution by first writing its pseudo-code of the procedure
explained in the In-Lab section and then writing its code.
Code:
function z=t4(n,x,y)
z=cconv(x,y,4);
stem(n,z,'r','LineWidth',2)
end
Output:
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
Task 05:
Verify the convolution property of DFT by first writing a pseudo code of the RHS
and LHS followed by the MATLAB code. Use the circular convolution function developed in
task-4 to compute convolution in time domain. Compare the result by sub-plotting LHS and
RHS of the following equation.
Code:
%Task 5
x=[1 2 3 4 5 6];
n=0:3;
y=[3 2 1 0 1 2];
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
%Left hand side
N=length(x);
z=cconv(x,y,N);
w=linspace(0,3,N);
Z=fft(z);
subplot(2,1,1)
stem(w,Z,'r','LineWidth',2)
%Right hand side
X=fft(x,N);
Y=fft(y,N);
M=Y.*X;
subplot(2,1,2)
stem(w,M,'r','LineWidth',2)
Figure:
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
Task 06:
Verify the duality property of DFT by first writing a pseudo code of the RHS and LHS
followed by the MATLAB code. Compare the result by sub-plotting LHS and RHS of the
following equation.
Code:
%Task 6
n = 1:3;
x= [1 2 3];
subplot (3,1,1)
stem (n,x,'r','LineWidth',2)
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
N = length (x);
y = N.*x;
Y = fft(y);
w = linspace (0,6,N);
subplot (3,1,2)
stem (w,Y,'r','LineWidth',2)
X = fft(x);
subplot (3,1,3)
stem (w,X,'r','LineWidth',2)
Figure:
COMSATS Institute of Information Technology
EEE324 Digital Signal Processing Lab Reports # 04
Critical Analysis / Conclusion
In this lab we had learnt that the Discrete Fourier Transform and its Properties. We
performed periodic and circular shifts (in circular shifts only one period is considered), and
periodic convolution. To find DFT, a MATLAB command FFT which stands for Fast
Fourier transform, is used. After calculating DTFT, resulting signal was a complex
exponential which is a continuous function. But to apply DSP, we require a discrete signal
so DFT can be used to obtain a transform which is discrete.
COMSATS Institute of Information Technology