You are on page 1of 2

clear all;

% clear all the variables used


before
clc;
%clear the screen
x=rand(1,10000);
h=[.5 .2];
x1=length(x);
x2=length(h);
a=0:1:x1-1;
%range of a is given
b=0:1:x2-1;
%Multiplication
for i=1:x1
for j=1:x2
c(j,i)=x(1,i)*h(1,j);
end
end
%Shifting
for i=1:x2
for j=1:i-1
d(i,j)=0;
end
for k=i:i+x1-1
d(i,k)=c(i,k-i+1);
end
for m=i+x1:x1+x2-1
d(i,m)=0;
end
end
%Addition
for i=1:x1+x2-1
con(i)=0;
for j=1:x2
con(i)=con(i)+d(j,i);
end
end
subplot(3,1,1)

stem(a,x)
title('Input signal');
subplot(3,1,2)
stem(b,h)
title('Impulse signal');
subplot(3,1,3)
stem(con)
disp(con)
title('Convoluted signal')

Input signal
1
0.5
0

1000

2000

3000

4000

5000

6000

7000

8000

0.7

0.8

9000 10000

Impulse signal
0.5

0.1

0.2

0.3

0.4

0.5

0.6

0.9

Convoluted signal
1
0.5
0

2000

4000

6000

8000

10000

12000

You might also like