Circular Convolution Method 2 | Scigyan

Circular Convolution Method 2

Matlab program to find Circular Convolution by matrix multiplication using circshift command.
Two another methods of Circular Convolution:  Using fft and ifft predefined function and By using for loop function.

Matlab code

clc;close all; clear all;
x1=input('Enter the 1st sequence x[n] = ');
h1=input('Enter the 2nd sequence h[n] = ');
N1=length(x1);
N2=length(h1);

N=max(N1,N2);%Length of Circular convolved output sequence
if(N1>N2)
h1=[h1,zeros(1,N1-N2)]; %Modified second sequence if N1>N2
else
x1=[x1,zeros(1,N2-N1)]; %Modified first sequence if N1
end;

x=transpose(x1); h=transpose(h1); temp=h;
for i=1:N-1;
  temp=circshift(temp,1);
  h=horzcat(h,temp);
end;
h
x
y=h*x ;
disp('Circular convolved output y[n] = ');y %To view output in command window

%To display and plot circular convolution
subplot(3,1,1);
stem(x1); xlabel('N-->');
ylabel('Amplitude-->'); title('1st input sequence x[n] ');
subplot(3,1,2);
stem(h1); xlabel('N-->');
ylabel('Amplitude-->'); title('2nd input sequence h[n]');

subplot(3,1,3);
stem(y); xlabel('N-->');
ylabel('Amplitude-->');
title('Circular convolved output y[n]');

Command window

Enter the 1st sequence x[n] = [1 2 3 4]
Enter the 2nd sequence h[n] = [3 5 2 1]
h =
     3     1     2     5
     5     3     1     2
     2     5     3     1
     1     2     5     3
x =
     1
     2
     3
     4
Circular convolved output y[n] = 
y =
    31
    22
    25
    32

Figure window

Circular-Convolution-Method-2
No comments:
Post a Comment

Related Posts Plugin for WordPress, Blogger...