Sunday, 21 October 2012

Linear Convolution Assotiative Law (Prove) 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 x(n) signal : ');
h1=input('enter the h1(n) signal : ');
h2=input('enter the h2(n) signal : ');
s1=input('starting value of x(n) : ');
s2=input('starting value of h1(n) : ');
s4=input('starting value of h2(n) : ');
l1=length(x);
l2=length(h1);
l3=l1+l2-1;
l4=length(h2);
l5=l3+l4-1;
s3=s1+s2;
s5=s3+s4;

n1=s1:1:s1+l1-1;
n2=s2:1:s2+l2-1;
n3=s3:1:s3+l3-1;
n4=s4:1:s4+l4-1;
n5=s5:1:s5+l5-1;
c1=conv(x,h1);
y1=conv(c1,h2);
subplot(5,1,1);
stem(n1,x);
xlabel('time');
ylabel('amplitude');
title('original signal x(n)');
subplot(5,1,2);
stem(n2,h1);
xlabel('time');
ylabel('amplitude');
title('original signal h1(n)');
subplot(5,1,3);
stem(n4,h2);
xlabel('time');
ylabel('amplitude');
title('original signal h2(n)');
subplot(5,1,4);
stem(n5,y1);
xlabel('time');
ylabel('amplitude');
title('convoluted signal of [x(n)*h1(n)]*h2(n)');
l6=l2+l4-1;
s6=s2+s4;
n6=s6:1:s6+l6-1;
l7=l6+l1-1;
s7=s6+s1;
n7=s7:1:s7+l7-1;
c2=conv(h1,h2);
y2=conv(x,c2);
subplot(5,1,5);
stem(n7,y2);
xlabel('time');
ylabel('amplitude');
title('convoluted signal of x(n)*[h1(n)*h2(n)]');

No comments:

Post a Comment

Tech N Science © 2013