# Circular Convolution Using Matlab Program (DSP)

## What is Circular Convolution?

Circular Convolution

Circular convolution also know as cyclic convolution to two functions which are aperiodic in nature occurs when one of them is convolved in the normal way with a periodic summation of other function.

A similar situation can be observed can be expressed in terms of a periodic summation of both functions, if the infinite integration interval is reduced to just one period. This situation arises in Discrete Time Fourier Transform(DTFT) and is called as periodic convolution.

Let us consider x to be a function with a defined periodic summation, xT, where:

If h is any other function for which the convolution xT * (Multiply) exists, then the convolution xT ∗ h is periodic and equal to:

where to is an arbitrary parameter and hT is a periodic summation of h.

The second integral is called the periodic convolution of functions xT and hT & is normalized by 1/T.

When xT is expressed as the periodic summation of another function, x, the same operation may also be referred to as a circular convolution of functions h and x.

## Matlab Code for Circular Convolution

Here is the code
```clc;
close all;
clear all;
x1=input('Enter the first sequence :
');
x2=input('Enter the second sequence
: ');
N1=length(x1);
N2=length(x2);
N=max(N1,N2);

if(N2>N1)
x4=[x1,zeros(1,N-N1)];
x5=x2;
elseif(N2==N1)
x4=x1;
x5=x2;
else
x4=x1;
x5=[x2,zeros(1,N-N2)];
end

x3=zeros(1,N);
for m=0:N-1
x3(m+1)=0;
for n=0:N-1
j=mod(m-n,N);
x3(m+1)=x3(m+1)+x4(n+1).*x5(j+1);
end
end

subplot(4,1,1)
stem(x1);
title('First Input Sequence');
xlabel('Samples');
ylabel('Amplitude');
subplot(4,1,2)
stem(x2);
title('Second Input Sequence');
xlabel('Samples');
ylabel('Amplitude');
subplot(4,1,3)
stem(x3);
title('Circular Convolution Using
Modulo Operator');
xlabel('Samples');
ylabel('Amplitude');

%In built function
y=cconv(x1,x2,N);
subplot(4,1,4)
stem(y);
title('Circular Convolution using
Inbuilt Function');
xlabel('Samples');
ylabel('Amplitude');

```

you can directly execute the code in matlab

Here is the Output

If you could not understand the code do comment below I will post a detailed guide regarding the explanation of Matlab Code for Circular Convolution