0% found this document useful (0 votes)
110 views

Lab Report 4 ZARYAB RAUF FA17-ECE-046

This lab report discusses digital signal processing concepts like the discrete Fourier transform and its properties. The report details 5 tasks completed in MATLAB: 1) writing a circular shift function, 2) verifying the time shifting property of the DFT, 3) verifying the duality property of the DFT, 4) writing a circular convolution function, and 5) verifying the convolution property of the DFT. For each task, pseudo-code and MATLAB code are provided along with analysis of results showing properties held for both the left and right sides of relevant equations.

Uploaded by

HAMZA ALI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

Lab Report 4 ZARYAB RAUF FA17-ECE-046

This lab report discusses digital signal processing concepts like the discrete Fourier transform and its properties. The report details 5 tasks completed in MATLAB: 1) writing a circular shift function, 2) verifying the time shifting property of the DFT, 3) verifying the duality property of the DFT, 4) writing a circular convolution function, and 5) verifying the convolution property of the DFT. For each task, pseudo-code and MATLAB code are provided along with analysis of results showing properties held for both the left and right sides of relevant equations.

Uploaded by

HAMZA ALI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

LAB REPORT # 4

DIGITAL SIGNALS PROCESSING


INSTRUCTOR: SIR MUBEEN SABIR
DATED: 11/11/2020

SUBMITTED BY: ZARYAB RAUF


CIIT/FA17-ECE-046/ISB | EEE-5B
Lab # 04 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=0:4 showing the limit of signal x.
iii. cricshift is the command used for circular shifting of the signal used to circularly shift
the original function.
iv. Plot the discrete graph using stem command for both original function and circularly.

MATLAB CODE:
function [x,y]= circ (x,n)

n=0:4
x=[1 2 3 4 5]
subplot(2,1,1)
stem(n,x);

y=circshift(x,[1 -1]);
subplot(2,1,2)
stem(n,y);
end

OUTPUT:
>> task1

n=
0 1 2 3 4

x=

1 2 3 4 5

ans =

1 2 3 4 5

>>

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 )
PSEUDO-CODE:

LHS:

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


ii. Save the length of n in w2.
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 y2.


ii. Multiply y2 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:
clc

close all

clear all

x=[1 2 3 4]

n=[-2 -1 0 1]

w2=length(n)

b=circshift(x,n)

LHS =abs(fft(b))

n1=linspace(-pi,pi,length(LHS))
subplot(2,1,1)

stem(n1,LHS)

title('LHS') ;

y2=fft(x)

RHS=y2.*exp(-1i .*(2.*pi./w2).*2)

w1=linspace(-pi,pi,length(y2))

subplot(2,1,2)

stem(w1,abs(RHS))

title('RHS') ;

OUTPUT:

x=

1 2 3 4

n=

-2 -1 0 1

w2 =

4
b=

2 3 4 1

LHS =

10.0000 2.8284 2.0000 2.8284

n1 =

-3.1416 -1.0472 1.0472 3.1416

y2 =

10.0000 + 0.0000i -2.0000 + 2.0000i -2.0000 + 0.0000i -2.0000 - 2.0000i

RHS =

-10.0000 - 0.0000i 2.0000 - 2.0000i 2.0000 + 0.0000i 2.0000 + 2.0000i


w1 =

-3.1416 -1.0472 1.0472 3.1416

>>

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.
DFT [ Nx (−n )]= X (k )
PSEUDO-CODE:
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.
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)

OUTPUT:
x=

1 2 3 4 5

n=

1 2 3 4 5

x1 =

5 4 3 2 1

LHS =

15.0000 4.2533 2.6287 2.6287 4.2533

w1 =

-3.1416 -1.5708 0 1.5708 3.1416

w2 =

-3.1416 -1.5708 0 1.5708 3.1416

>>
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:

i. Design a function with single output and two inputs 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. Plot its graph to show linear convolution.
vi. Use circular conv command to circularly convolve the original signal.
vii. Use subplot command to show difference between original and circularly shifted signal.

MATLAB CODE:
function [y]= circonv (x,h,n)

x=[1 2 3 4]
h=[2 3 4 5]
n=-1:2
subplot(2,1,1)
stem(n,x)
y=cconv(x,h,length(x))
subplot(2,1,2)
stem(n,y)
end

OUTPUT:

x=

1 2 3 4 5

n=

1 2 3 4 5

x1 =

5 4 3 2 1

LHS =

15.0000 4.2533 2.6287 2.6287 4.2533


w1 =

-3.1416 -1.5708 0 1.5708 3.1416

w2 =

-3.1416 -1.5708 0 1.5708 3.1416

>> task4

x=

1 2 3 4

h=

2 3 4 5

n=
-1 0 1 2

y=

36 38 36 30

ans =

36 38 36 30

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’.
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=cconv(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)

OUTPUT:

x1 =

1 2 3

n1 =

-1 0 1

x2 =

0 1 2

n2 =

0 1 2

c =

7 7 4

y =

18 3 3

w1 =

-3.1416 0 3.1416
a =

6.0000 1.7321 1.7321

b =

3.0000 1.7321 1.7321

w2 =

-3.1416 0 3.1416

>>

CONCLUSION/CRITICAL ANALYSIS:
In this lab the following things were learned:

1. The computation and plotting of Discrete Fourier Transform using the MATLAB
command FFT.
2. Time shifting property using the circular shift function was verified on both LHS and RHS.
3. Circular shift was performed and plotted.
4. Duality property on both LHS and RHS of the signals was verified of the given function.
5. As seen in task 5, on the LHS both signals were convolved, and their FOURIER
TRANSFORM was taken, then on the RHS the FOURIER TRANSFORM of both of the
signals was taken separately and then convolved, both had same results i.e. plots,
means LHS=RHS.

You might also like