from circular convolution of two one dimensional sequences by antonynycil
help to find the circular convolution

circularconv.m
% inputting the sequences
x1=input('Enter the 1st sequence :');
n1=length(x1);
x2=input('Enter the 2nd sequence :');
n2=length(x2);

% for circular pading add zeros to maximum of lengths
if n1>n2
for i=n2+1:n1
x2(i)=0;
end
else
for i=n1+1:n2
x1(i)=0;
end
end

% calculation of new length
n=length(x1)

% calculation of circular convolution
z=0;
for u=0:n-1
z(u+1)=0;
for p=0:n-1
z(u+1)= z(u+1)+((x1(p+1))*(x2(mod(u-p,n)+1)));
end
end

% calculation in freq domain for comparison
e=0;
 e=z
xx1=fft(x1);
xx2=fft(x2);

% out is circular covolution in frequency domain
out=(xx1.*xx2);

% w1 is circular convolution in time domain
w1=round(ifft(out))

%  plotting of the result
subplot(2,2,1);
stem(abs(x1));
title('x1');
xlabel('frequency component');
ylabel('absolute value');

subplot(2,2,2);
stem(abs(x2));
title('x2');
xlabel('frequency component');
ylabel('absolute value');

subplot(2,2,3);
stem(abs(e));
title('DFT[x1(n)@x2(n)]');
xlabel('frequency component');
ylabel('absolute value');

subplot(2,2,4);
stem(abs(out));
title('X1(k)*X2(k)');
xlabel('frequency component');
ylabel('absolute value');

Contact us