Professional Documents
Culture Documents
Lab 5 Introduction To Convulution
Lab 5 Introduction To Convulution
Lab Report
LAB 05
Submitted by:
Name: Muhammad Usman Jadoon
Reg# B20F0447EE031
Submitted to:
Name: Rafi Ullah
Designation: LAB Engineer
Date:
March 24, 2022
Introduction to Convolution using MATLAB
OBJECTIVE:
The objective of this lab is to study basics of continuous time convolution and discrete time
convolution of signals Software:
MATLAB
Introduction:
Convolution is a mathematical operation used to express the relation between input and output
of an LTI system. It relates input, output and impulse response of an LTI system as: 𝑦(𝑛) = 𝑥(𝑛) ∗
ℎ(𝑛)
Where 𝒚 (𝒏) = output of LTI, 𝒙 (𝒏) = input of LTI and 𝒉 (𝒏) = impulse response of LTI.
OTHER COMMANDS:
By installing spfirst from the internet and then put in the toolbox folder in MATLAB we can
use further commands for our ease.
Con2dis
Dconvdemo (for discrete signal)
Cconvdemo (for continuous signal)
Lab 05 Tasks :
TASK 1:
a) Make the flowchart or pseudo code for convolution.
b) Implement convolution in MATLAB. (Hint: Make a function using the format: function result =
myconv (a,b) Where a and b are input matrix and result is convolution answer.)
ANSWER:
CODE:
(a). Pseudo Code:
• Store the input signal as a 1xN vector a
• Store the impulse response of the system as a 1xM vector b
• Transpose the impulse response or the input signal
• Multiply them to construct an NxM or MxN matrix P
• add P(i,(i-j)
• represent in a vector form c
(b). function c =
myconv(a,b) a=[1 3 -2 4
-1] b=[-2 3 4 -3 6]
N=0:(length(a)-1);
stem(a,b); disp(c)
end
(c).
x=[1 3 -2 4 -1]; h=[-2 3 4 -3 6];
Y=conv(x,h); N=0:(length(h)-1);
stem(x,h); grid; xlabel('n'); ylabel('y(n)');
title('Output of system via Convulution');
OUTPUT:
EXPLANATION:
In this task we convolve functions using function and write pseudo code of convolution.
TASK 2:
Let input signal x be [1, 3, –2, 4, -1] and the system h be [-2, 3, 4, –3, 6]. Find the output of the
system y using the conv command.
ANSWER:
CODE:
x=[1 3 -2 4 -1];
h=[-2 3 4 -3 6];
Y=conv(x,h);
N=0:(length(h)-1);
stem(x,h); grid;
xlabel('n');
ylabel('y(n)');
title('Output of system via Convulution');
OUTPUT:
EXPLANATION:
In this task we convolve the signals by conv command.
TASK 3:
Now suppose we add another system j = [3, –1, 2, 4, 1] in series with the above system. Now find
the overall response and output y of the above system using the conv command. Hint: The
systems h and j should be convolved first and then the resultant should be convolved with x to
get the overall response.
ANSWER:
CODE:
x1 = [1 3 -2 4 -1]
h1 = [-2 3 4 -3 6]
j1 = [3 -1 2 4 1] y =
conv(j1,h1) q =
0:(length(y)-1);
subplot(2,2,1);
stem(q,y); grid;
xlabel('n1');
ylabel('y[n] 1');
title('Output of System via Convolution between j1 and h1');
z = conv (x1,y) n =
0:(length(z)-1)
subplot(2,2,3);
stem(n,z) grid;
xlabel('n');
ylabel('y[n]');
title('Output of System via Convolution between x1 and h1,j1');
OUTPUT:
TASK 4:
Again, suppose now j is attached in parallel to h. Now find the impulse response y for the
system.
ANSWER:
CODE:
x=[1, 3, -2, 4, -1];
h=[-2, 3, 4, -3, 6];
j = [3, -1, 2, 4, 1];
h2=h+j; y=conv(x,h2);
n=0:(length(y)-1);
stem(n,y);
grid;
OUTPUT:
EXPLANATION:
In this task h and j is parallel and y impulse response has been found.
TASK 5:
Now suppose the two systems h and j are again in series and a third system k = [2, 3, 4, 5, 6] has
also been attached with them in parallel. Find the impulse response of the overall system and
hence the output y. Hint: You will have to make sure that the size of the system k be made
equal to the resultant of the size of the system obtained by convolving the systems h and k that
are attached in series.
ANSWER:
CODE:
x=[1, 3, -2, 4, -1];
h=[-2, 3, 4, -3, 6]; j
= [3, -1, 2, 4, 1];
k=[ 2 3 4 5 6 0 0 0
0] y=conv(h,j);
n=0:(length(y)-1);
subplot(2,2,1);
stem(n,y); grid;
xlabel('x');
ylabel('y');
title('series h and j');
ANSWER:
CODE:
n=0:4; x =[1, 3, -
2, 4, -1];
subplot(3,2,1);
stem(n,x); title('x
system'); n = 0 :
4;
j= 6* heaviside(n) -14.*heaviside(n-1)+20.*heaviside(n-2)-16.*heaviside(n-3)+10.*heaviside(n-
4); subplot(3,2,2);
stem(n, j) title('j
system'); %j = [3,
–1, 2, 4, 1] axis([-
15 15 -1 8]) n = -
2:2;
h= -4.*heaviside(n+2)+14.*heaviside(n+1)-12.*heaviside(n)-2.*heaviside(n-1)+20.*heaviside(n-
2); subplot(3,2,3);
stem(n, h)
title('h system');
%[-2, 3, 4, –3, 6]
%k = [2, 3, 4, 5, 6] n
= 3:7;
k= 4.*heaviside(n-3)-2.*heaviside(n-4)+4.*heaviside(n-5)-2.*heaviside(n-6)+4.*heaviside(n-7);
%-12.*heaviside(n+5)-2.*heaviside(n+6)+20.*heaviside(n+7);
subplot(3,2,4); stem(n, k) title('k system');
OUTPUT:
Code:
y=conv(h,j);
n=0:(length(y)-1);
subplot(3,2,1);
stem(n,y); grid;
xlabel('x');
ylabel('y');
title('series h and j');
z=k+y;
n=0:(length(z)-1);
subplot(3,2,2);
stem(n,z); grid;
xlabel('x');
ylabel('y');
title('parallel of k with series of h and j');
OUTPUT:
EXPLANATION:
First by Heaviside commands made the signals and then convolve them by
putting in series and parallel, and found the overall response of the system.
TASK 7:
You should perform the following steps with the 𝑑𝑐𝑜𝑛𝑣𝑑𝑒𝑚𝑜 GUI.
ANSWER:
OUTPUT:
CONCLUSION:
In this lab we learnt time reversal, flipping, time scaling and even and odd signals. Made
and plotted signals in Matlab and expand, compressed the signals and explored various
commands. Learnt the behaviour of signals.