Sunday, 21 October 2012

Linear Convolution in MATLAB



Just create a new file with extension .m and paste the code below in that .m file. Then Run it.

clear all;
clc;
x=input('enter the sequence h(n) : ');
h=input('enter the sequence x(n) : ');
s1=input('enter the starting interval of x(n) : ');
s2=input('enter the starting interval of h(n) : ');
l1=length(x);
l2=length(h);
l3=l1+l2-1;
s3=s1+s2;
n1=s1:1:s1+l1-1;
n2=s2:1:s2+l2-1;
n3=s3:1:s3+l3-1;


y=conv(x,h);
subplot(3,1,1);
stem(n1,x);
xlabel('time');
ylabel('amlpitude');
title('original sequence x(n)');
subplot(3,1,2);
stem(n2,h);
xlabel('time');
ylabel('amlpitude');
title('original sequence h(n)');
subplot(3,1,3);
stem(n3,y);
xlabel('time');
ylabel('amlpitude');
title('Linear Convoluted Signal');

No comments:

Post a Comment

Tech N Science © 2013