Lab Report 4 ZARYAB RAUF FA17-ECE-046
Lab Report 4 ZARYAB RAUF FA17-ECE-046
LAB TASKS
PSEUDO-CODE:
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
>>
DFT [ Nx (−n ) ]= X ( k )
PSEUDO-CODE:
LHS:
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 =
n1 =
y2 =
RHS =
>>
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 =
w1 =
w2 =
>>
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 =
w2 =
>> 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
PSEUDO-CODE:
LHS:
RHS:
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 =
b =
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.