Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

UNIVERSITY OF ENGINEERING AND TECHNOLOGY

TAXILA

FACULTY OF TELECOMMUNICATION AND


INFORMATION ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

Digital Signal Processing

DSP Lab Manual no.4


Convolution Sum in MATLAB

Submitted by:
19-CP-01
Anam Arshad

Submitted to:
Sir Amir Arslan
Lab Tasks:
Task 01 :
Code:
function y=my_convolution(x,h)
C=[];
for i=1:length(x)
z=h.*x(i);
C=[C;z];
end
[row,col]=size(C);
k=row+col;
t=2;
y=[];
cd=0;
while(t<=k)
for i=1:row
for j=1:col
if ((i+j)==t)
cd=cd+C(i,j);
end
end
end
t=t+1;
y=[y cd];
cd=0;
end
disp(y)
stem(y)
end

Output:
When input is given in form of signal x[n] and h[n] . The output is convolution of both signals
in time domain y[n]=x[n]*h[n]. In coding there are loops if condition and while loop also. The
matrix C is defined initially to 0.Then after it checks the condition and run the loop, each value
that is calculated is stored in cd matrix modification of C matrix.

When x[n] is [1 2 3 4 5] and h[n] is [1 1 1 1] then y[n] is equal to:

Y[n]=x[n]*h[n]
Task 02:
Output:

Both have same answer and value of y[n].

Task 03:
Output:
Commutative:
x[n]*h[n]=h[n]*x[n]

The commutative property of convolution sum is proved:


Associative:
(x[n]*h1[n])*h2[n]=x[n]*(h1[n]*h2[n])
The assosiative property is proved:
Distributive:
x[n]*h1[n]+x[n]*h2[n]=x[n]*(h1[n]+h2[n])
The distributive property is proved:

You might also like