MATLAB program to perform linear convolution using circular convolution

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

________________________________________

If you find this program code useful, then please deposit 5 Indian Rupees in my bank account, as my fee. (Citizens of Pakistan cannot do this.).
I am the woman who wrote this program code.
My name: Anju K.
My bank account number: 30221619108
Bank: State Bank of India, Chakkarakkal branch, India.
IFSC code: SBIN0070728
SWIFT code: SBININBB
BIC code: SBININBB
My email: tc9749@gmail.com .


No comments:

Post a Comment

Please write your opinion about this MATLAB program here, only in English.