DSP Lab Report # 04
DSP Lab Report # 04
Class BEE-6A
Lab Assessment
Post Lab Total
Pre-Lab In-Lab Data
Data Analysis Writing Style
Presentation
Matlab using FFT command, and perform periodic convolution on Matlab, in-addition students
Pre-Lab
1. DFT
For a periodic signal x[n] with a period N, discrete Fourier transform (DFT) is computed as
Where w0 = 2π/N is the fundamental frequency of the signal. Following two conditions must satisfied
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
2. DTFT
DFT is the computable version of discrete time Fourier transform. Despite being the Fourier transform
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
The DTFT is a transformation that maps Discrete-time (DT) signal x[n] into a complex valued function
2.1 Periodicity
2.2 Implication
2.3 Symmetry
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)
2.4 Implication:
We need only half period of X(ejw) i.e. w [0, ]
Shifting in periodic sequences is referred to as circular shift, x[n-l] is depicted in the figure
below,
In-Lab
FFT command is used to compute Discrete Fourier Transform (DFT), it uses one-dimensional fast
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.
The fft function employs a radix-2 fast Fourier transform algorithm if the length of the sequence is a
power of two.
Example:
Abs
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
array Z. The angles lie between . For complex Z, the magnitude R and phase angle theta are
given by:
5.1.Linearity property
(Pseudo-code)
c. Take the DFT of the sum computed in last step using FFT command
b. Multiply the constants α and β with DFTs of x1[n] and x2[n] respectively.
MATLAB Code
5.2.Parsevals theorem
(Pseudo-code)
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
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.
1 1]
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)
K= length (n);
P= 3;
z = circshift(y, [K,P]);
subplot(2,1,2);
stem (n,z,'r','LineWidth',2)
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.
Code:
n = 1:5;
x = [1 2 3 4 5];
subplot (4,1,1)
stem (n,x)
m = 2;
N = length (x)
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:
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:
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:
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
Code:
%Task 5
x=[1 2 3 4 5 6];
n=0:3;
y=[3 2 1 0 1 2];
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)
X=fft(x,N);
Y=fft(y,N);
M=Y.*X;
subplot(2,1,2)
stem(w,M,'r','LineWidth',2)
Figure:
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)
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:
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.