%Circular Array
clc;clear;
x1=[1 4 3 2];
x2=[1 2 3 1];
N=length(x1);
for n=0:N-1
y(n+1)=sum(x1.*circshift(flip(x2),n+1));
end
disp(y);
disp(cconv(x1,x2,N));
%DFT IDFT Stock Hom's Method
clc;clear;
x1=[1 4 3 2];
x2=[1 2 3 1];
X1=fft(x1);
X2=fft(x2);
Y=X1.*X2;
y=ifft(Y);
disp(y);
%Linear Convolution using Circular Convolution
clc;clear;
x1=[1 2 -1 3 5];
x2=[1 -1];
L=length(x1);
M=length(x2);
N=L+M-1;
x1=[x1 zeros(1,N-L)];
x2=[x2 zeros(1,N-M)];
for n=0:N-1
y(n+1)=sum(x1.*circshift(flip(x2),n+1));
end
disp(y)
disp(conv(x1,x2));
%Convolution Summation
clc;clear;
x1=[1 2 -1 3 5]; x2=[1 -1];
L=length(x1);
M=length(x2);
N=L+M-1;
for n=1:N
y(n)=0
for k=1:L
if n-k+1>=L && n-k+1 <=M
y(n)=y(n)+x1(k)*2*(n-k+1);
end
end
end
disp(y)
disp(conv(x1,x2));