Program code
%linear convolution using
circular convolution
clc;
clear all;
close all;
x=input('Please enter
the first sequence x[n] = ');
h=input('Please enter
the second sequence h[n] = ');
len_x=length(x);
len_h=length(h);
h=[h zeros(1,len_x-1)];
x=[x zeros(1,len_h-1)];
L=len_x+len_h-1;
for i=0:L-1
for j=1:L-i;
a(j+i,i+1)=x(j);
end
end
for m=1:L-1
for n=m+1:L
a(m,n)=x(L-n+m+1);
end
end
b=transpose(h);
y=a*b;
y=transpose(y);
subplot(311);
stem(x);
disp('The sequence
obtained after linear convolution of x[n] with h[n], is given below. ');
disp(y);
grid on;
title('First
sequence x[n] ');
subplot(312);
stem(h);
grid on;
title('Second
sequence h[n] ');
subplot(313);
stem(y);
Example of output
Please enter the first sequence x[n] = [1 2 3 4 5 6]
Please enter the second sequence h[n] = [1 2 3 4 5
6]
The sequence obtained after linear convolution of
x[n] with h[n], is given below.
1 4
10 20 35
56 70 76
73 60 36
________________________________________