%Linear Convolution
#include<stdio.h>
int x[15],h[15],y[15];
int i,j,m,n;
void main(){
printf("\n Enter the value of m:");
scanf("%d",&m);
printf("\n Enter the value of n:");
scanf("%d",&n);
printf("Enter the values for i/p x(n):\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter the values for i/p h(n):\n");
for(i=0;i<n;i++)
scanf("%d",&h[i]);
for(i=m;i<m+n-1;i++)
x[i]=0;
for(i=n;i<m+n-1;i++)
h[i]=0;
for(i=0;i<m+n-1;i++){
y[i]=0;
for(j=0;j<=1;j++)
y[i]=y[i]+(x[j]*h[i-j]);
}
for(i=0;i<m+n-1;i++)
printf("\n the value of output y[%d]=%d",i,y[i]);
}
%Circular Convolution
#include<stdio.h>
int x[30],h[30],y[30],x2[30],a[30];
int i,j,m,n,k;
void main(){
printf("\n Enter the length of the 1st sequence:");
scanf("%d",&m);
printf("\n Enter the length of the 2nd seq:");
scanf("%d",&n);
printf("Enter the 1st sequence:\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter the 2nd sequence:\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++) {
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++){
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf("The circular convolution is:\n");
for(i=0;i<n;i++)
printf("%d\t",y[i]);
}
%DFT
#include<stdio.h>
#include<math.h>
int N,K,n,i;
float pi=3.1416,sumre=0,sumim=0,out_real[8]={0.0},out_imag[8]={0.0};
int x[32];
void main(void)
{
printf("Enter the length of the sequence:");
scanf("%d",&N);
printf("Enter the sequence:");
for(i=0;i<N;i++)
scanf("%d",&x[i]);
for(K=0;K<N;K++)
{
sumre=0;
sumim=0;
for(n=0;n<N;n++)
{
sumre=sumre+x[n]*cos(2*pi*K*n/N);
sumim=sumim-x[n]*sin(2*pi*K*n/N);
}
out_real[K]=sumre;
out_imag[K]=sumim;
printf("x([%d])=\t %f\t+\t%fi\n",K,out_real[K],out_imag[K]);
}
}