In matlab conv() function is used for finding the linear convolution of sequences. The program is shown below.

**%Program to find the linear convolution of two sequences**

**x1=input('Enter the first sequence x1(n) = ');**

**t1=input('Enter the starting time of first sequence t1 = ');**

**x2=input('Enter the second sequence x2(n) = ');**

**t2=input('Enter the starting time of second sequence t2 = ');**

**l1=length(x1);**

**l2=length(x2);**

**ln=l1+l2-1;**

**yn=conv(x1,x2);**

**a=t1+l1-1;**

**t=t1:a;**

**subplot(311);**

**stem(t,x1);**

**grid on;**

**xlabel('time--->');**

**ylabel('amplitude--->');**

**TITLE('First sequence');**

**a=t2+l2-1;**

**t=t2:a;**

**subplot(312);**

**stem(t,x2);**

**grid on;**

**xlabel('time--->');**

**ylabel('amplitude--->');**

**TITLE('Second sequence');**

**tn=t1+t2;**

**a=tn+ln-1;**

**t=tn:a;**

**subplot(313);**

**stem(t,yn);**

**grid on;**

**xlabel('time--->');**

**ylabel('amplitude--->');**

**TITLE('Convolved output');**

%output

%Enter the first sequence x1(n) = [1 2 6 2 3 1 4]

%Enter the starting time of first sequence t1 = -3

%Enter the second sequence x2(n) = [3 1 4 5 2]

%Enter the starting time of second sequence t2 = -1

## 8 comments:

Its works perfect bingo!...

very nice program ....thanks alot

Nice that you have consider the origin.

this program really works........thanks a lot !!!!!!!!!!!!

thanks a lot (y)

what if the starting line is not the given instead the position in sequence x where n=0 is the given?

i want the convolution code for convolution x1=a1*sin(2*pi*f1*t) and x2=a2*sin(2*pi*f2*t) a1=1,a2=2,f1=100,f2=500,

i tryed your program but im getting only one diagram as output not all the three

## Post a Comment