CIRCULAR CONVOLUTION

//CIRCULAR CONVOLUTION
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,m,n,r;
cout<<“CIRCULAR CONVOLUTION”;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<“enter m,n”;
cin>>m>>n;

r=m+n-1;

int x1[10],x2[10],y[10];

for(i=0;i<=10;i++)
{
x1[i]=0;
x2[i]=0;
y[i]=0;
}

cout<<“enter input matrix”;
for(i=0;i<m;i++)
{
cin>>x1[i];
}
cout<<“enter impulse matrix”;
for(j=0;j<n;j++)
{
cin>>x2[j];
}

//PADDING LOGIC
if(m>n)
{for(i=n;i<m;i++)
{x2[i]=0;}
r=m;
}

if(n>m)
{for(i=m;i<n;i++)
{x1[i]=0;}
r=n;
}

cout<<“the input matrix is x[n]=”;
for(i=0;i<r;i++)
{
cout<<x1[i]<<“,”;
} cout<<endl;
cout<<“the impulse matrix is h[n]=”;
for(i=0;i<r;i++)
{
cout<<x2[i]<<“,”;
} cout<<endl;

//LOGIC OF THE CODE USING ANALYTICAL FORMULA
for(i=0;i<=r;i++)
{
for(j=0;j<=r-1;j++)
{
if(i-j<0)
{y[i]+=x1[j]*x2[r+i-j];}
else
{y[i]+=x1[j]*x2[i-j];}
}
}

//display op matrix
cout<<“the op matrix is y[n]=”;
for(i=0;i<r;i++)
{
cout<<y[i]<<“,”;
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s