You are on page 1of 8

LAB REPORT # 05

NAME: KHANSA MARYAM.

ROLL NO.: FA20-BEE-232.

SUBMITTED TO: SIR MOBEEN SABIR.

SUBJECT: DIGITAL SIGNAL PROCESSING.

DATED: 08-04-2023.

10
Lab # 05
Discrete Fourier Transform and its Properties
LAB TASKS:

TASK-1:

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.

PSEUDO-CODE:

i. Make a function circ for circular shift


ii. x[n] is a discrete function with n=1 showing the limit of signal x.
iii. Plot the discrete graph using stem command for both original function and circularly.

MATLAB CODE:

function [y] = circular(x,k)


for i=1:k
t1=x(1);
t2=x(end);
x(1)=[];
x(end)=[];
x=[t2 t1 x];
end
y=x;
end

TASK-2:

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.

DFT [ Nx (−n ) ]= X ( k )
10
PSEUDO-CODE:

LHS:

i. Two signals ‘x’ and ‘n’ are given


ii. Save the length of x in N.
iii. Use the circshift function designed in task 1.
iv. In a single command take discrete Fourier transform (of circularly shifted variable b)
using ‘fft’ command, then take its absolute value.
v. Limit the signal between pi and –pi using line space command.
vi. Plot its discrete graph with title “LHS”.

RHS:

i. Take Fourier transform of signal ‘x’ and save it in variable X.


ii. Multiply X with exponential function (e-j(2pi/N)2) as given in the RHS of the mentioned
equation.
iii. Limit the signal between pi and –pi using line space command.
iv. Plot its discrete graph with title “RHS”.

MATLAB CODE:

x = [2 4 6];
N=length(x)
n = [0 1 3];
l = 3;
x1=circular(x,l);
LHS=fft(x1)
n1=linspace(-pi,pi,length(LHS))
subplot(2,1,1)
stem(n1,abs(LHS))
X=fft(x);
RHS=X.*exp(-1j*((2*pi)/N)*n*l);
n2=linspace(-pi,pi,length(LHS))
subplot(2,1,2)
stem(n2,abs(RHS))

10
TASK-3:

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.

PSEUDO-CODE: DFT [ Nx (−n )]= X (k )

LHS:

i. An original signal ‘x’ is given with limit 1:5.


ii. Flip the signal ‘x’ using fliplr function, save it in ‘x1’.
iii. Multiply flipped signal with a scalar value, save it in variable ‘m’.
iv. Take fourier transform of the flipped signal using FFT command.
v. Limit is given using line space command.
vi. Plot its discrete graph.

RHS:

i. Take Fourier transform of signal ‘x’, then absolute of that Fourier transform all in a
single line.
ii. Limit the function using linespace command.
iii. Plot its discrete graph.

10
iv.

MATLAB CODE:

clc
close all
clear all

x=[1 2 3 4 5]
n=1:5

x1=fliplr(x)
m=-1.*x1 ;
LHS=abs(fft(m))
w1=linspace(-pi,pi,length(LHS))
subplot(2,1,1)
stem(w1,LHS)

RHS=abs(fft(x));
w2=linspace(-pi,pi,length(RHS))
subplot(2,1,2)
stem(w2,RHS)

TASK-4:

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.

PSEUDO-CODE:

10
i. Design a function with single output and input name it circonv ( circular convolution).
ii. Input one signal and save it in ‘x’.
iii. Input other signal and save it in ‘h’.
iv. Give limit ‘N’.
v. Perform convolution using for loop.

MATLAB CODE:

function [y,N] = circonv(x,h)


l1=length(x);
l2=length(h);
N=max(l1,l2);
x=[x zeros(1,N-l1)];
h=[h zeros(1,N-l2)];
y=zeros(1,N);
for q=1:N
for w=1:N
t=mod(q-w,N);
t=t+1;
y(q)=y(q)+x(w)*h(t);
end
end
end

TASK-5:

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.

DFT {x 1 (n )∗x 2 (n )}=X 1 (k ) X 2 (k )

PSEUDO-CODE:

LHS:

i. Take signal one and save it in ‘x1’.


ii. Take signal two and save it in ‘x2’.
iii. Circularly convolve both signals and save it variable ‘c’.

10
iv. Take fourier transform of ‘c’ and take its absolute value.
v. Plot its discrete graph.

RHS:

i. Take fourier transform of signal ‘x1’, then its absolute value.


ii. Save it in variable ‘a’.
iii. Take fourier transform of signal ‘x2’, then take its absolute value.
iv. Save it in variable ‘b’.
v. Convolve ‘a’ and ‘b’.
vi. Plot its discrete graph.

MATLAB CODE:

clc
clear all
close all

x1=[1 2 3]
n1=-1:1
x2=[0 1 2]
n2=[0:2]

c=circonv(x1,x2,length(x1))
y=abs(fft(c))
w1=linspace(-pi,pi,length(y))
subplot(2,1,1)
stem(w1,y)
title('LHS') ;

a=abs(fft(x1))
b=abs(fft(x2))
r=a.*b;
w2=linspace(-pi,pi,length(r))
subplot(2,1,2)
stem(w2,r)

10
CONCLUSION/CRITICAL ANALYSIS:
In this lab I learned:

 How to compute and plot Discrete Fourier Transform of a signal using MATLAB
command FFT.
 In task 1 I did circular shift of a signal and plotted its graph.
 In task 2 I verified the time shifting property on the LHS and RHS of the given function
using circular shift function designed in task 1.
 In task 3 I verified duality property on LHS and RHS of the given function.
 In task 4 I designed circular convolution function.
 In task 5 I took two signals on LHS I convolved both signals and took their fourier
transform and on right RHS I took fourier of both signals separately and convolved them,
the plots were same, hence proving LHS=RHS.

10

You might also like