Linear Convolution using graphical methods & matrix multiplication methods

PROGRAM 1:
OBJECT: To write a program to compute Linear Convolution of any two sequences x(n) and h(n), using overlap add method. Sequences are as given below:
x(n) = { 1, 2, -1, 2, 3, -2, -3, -1, 1, 1, 2, -1} and h(n) = {1, 2, 3, -1}

SOURCE CODE:
x=input('Enter the sequence x(n) = ');
h=input('Enter the sequence h(n) = ');
n1=length(x);
n2=length(h);
N=n1+n2-1;
h1=[h zeros(1,n2-1)];
n3=length(h1);
y=zeros(1,N+n3-n2);
H=fft(h1);
for i=1:n2:n1
    if i<=(n1+n2-1)
        x1=[x(i:i+n3-n2) zeros(1,n3-n2)];
    else
        x1=[x(i:n1) zeros(1,n3-n2)];
    end
    x2=fft(x1);
    x3=x2.*H;
    x4=round(ifft(x3));
    if (i==1)
        y(1:n3)=x4(1:n3);
    else
        y(i:i+n3-1)=y(i:i+n3-1)+x4(1:n3);
    end
end
disp('The output sequence y(n)=');
disp(y(1:N));
stem(y(1:N));
title('Overlap Add Method');
xlabel('n');
ylabel('y(n)');

OUTPUT:
Enter the sequence x(n) = [1 2 -1 2 3 -2 -3 -1 1 1 2 -1]
Enter the sequence h(n) = [1 2 3 -1]
The output sequence y(n)=
     1     4     6     5     2    11     0   -16    -8     3     8     5     3    -5     1

Index of DSP Lab Manual.