Lab - 6

You might also like

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

Department of Electrical Engineering

Faculty Member: Dr Salman Ghafoor Dated: 10/24/2022

Section: BEE-12D Semester: 05

EE-232 : Signals and Systems


Lab 6 : Convolution of signals

PLO4 –CLO3 PLO5-CLO3 PLO8-CLO4 PLO9-CLO4


Name Reg. No Viva / Quiz / Analysis Modern Tool Ethics and Individual
Lab of data in Usage Safety and Team
Performance Lab Work
Report

5 Marks 5 Marks 5 Marks 5 Marks 5 Marks


Ahsan Bilal 341480

Hamza Ali 340543

M. Hamza Naeem 335797

EE-232 Signals and Systems Page 1


Lab 6 : Convolution

1.1.1Lab Exercise: Convolution of sequences


In this section, we will apply the above equation to calculate the convolution of two sequences and to
examine one of the important properties of convolution.

Given the following two sequences:

x[n]= {1,2,1,2} h[n]= {0,1,2,3,4,1,1} Where _ indicates the zero position.

a) Write a Matlab function ‘my_conv’ that will convolve the signal


x[n] with the system impulse response h[n] and produce the
output y[n]. Plot the output y[n] on a graph with correct axis.

%% User defined function to find linear convolution


%Xin =input function ,Hin=impulse response ,
%H_start=impulse h[n] zero location
%X_start=x[n] zero location
function cnv = my_conv(Xin,Hin,X_start,H_start)

L=(-X_start)+(-H_start):length(Hin)-(H_start+1)+length(Xin)-(X_start+1);
cnv =zeros(1,length(L));

for i=1:length(Xin)

temp=Xin(i).*[zeros(1,i-1) , Hin , zeros(1,length(Xin)-i)];

cnv=cnv+temp;

end

subplot(411);stem(Xin);title('x[n]')
subplot(412);stem(Hin);title('h[n]')
subplot(413);stem(cnv);title('y[n] user defined')

default=conv(Xin,Hin);
subplot(414);stem(cnv);title('y[n] default')

if(cnv)==default

EE-232 Signals and Systems Page 2


disp('USER DEFINED FUNCTION WORKING');
end

b) Compare your result with built in function of Matlab ‘conv’.

Matlab’s Function:

b) If x[n] starts from -1 and h[n] starts from -2 then what will be the result
of convolution using ‘my_conv’ and ‘conv’?

With my_conv:

EE-232 Signals and Systems Page 3


With built in conv we can see above.

Both have same results

d) Convolution of x[n]={-1 0 1} with h[n]={1 2 1} results in y[n] ={-1 -2 0 2 1}.


Verify this by using the function ‘my_conv’.

EE-232 Signals and Systems Page 4


Conclusion:
In this lab we learnt about convolution in detail and we were able to develop our own
convolution function in which we learnt it practically and in depth, it was an interesting
lab.

EE-232 Signals and Systems Page 5

You might also like