Circular Convolution DSP program in C - Computer Programming

# Computer Programming

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

## Thursday, November 10, 2011

Circular Convolution

AIM

To verify Circular Convolution.

EQUIPMENTS

SANDS TEXAS 5416 Kit.

RS232 Serial Cable

Power Cord

THEORY

Circular convolution is another way of finding the convolution sum of two input signals. It resembles the linear convolution, except that the sample values of one of the input signals is folded and right shifted before the convolution sum is found. Also note that circular convolution could also be found by taking the DFT of the two input signals and finding the product of the two frequency domain signals. The Inverse DFT of the product would give the output of the signal in the time domain which is the circular convolution output. The two input signals could have been of varying sample lengths. But we take the DFT of higher point, which ever signals levels to. For eg. If one of the signal is of length 256 and the other spans 51 samples, then we could only take 256 point DFT. So the output of IDFT would be containing 256 samples instead of 306 samples, which follows N1+N2 – 1 where N1 & N2 are the lengths 256 and 51 respectively of the two inputs. Thus the output which should have been 306 samples long is fitted into 256 samples. The

256 points end up being a distorted version of the correct signal. This process is called circular convolution.

PROGRAM:

/* prg to implement circular convolution */

#include<stdio.h>

int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];

void main()

{

printf("  enter the length of the first sequence\n");

scanf("%d",&m);

printf("  enter the length of the second sequence\n");

scanf("%d",&n);

printf("  enter the first sequence\n");

for(i=0;i<m;i++)

scanf("%d",&x[i]);

printf("  enter the second sequence\n");

for(j=0;j<n;j++)

scanf("%d",&h[j]);

if(m-n!=0)                                         /*If length of both sequences are not equal*/

{

if(m>n)                                                        /* Pad the smaller sequence with zero*/

{

for(i=n;i<m;i++)

h[i]=0;

n=m;

}

for(i=m;i<n;i++)

x[i]=0;

m=n;

}

y[0]=0;

a[0]=h[0];

for(j=1;j<n;j++)                                                    /*folding h(n) to h(-n)*/

a[j]=h[n-j];

/*Circular convolution*/

for(i=0;i<n;i++)

y[0]+=x[i]*a[i];

for(k=1;k<n;k++)

{

y[k]=0;

/*circular shift*/

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];

}

}

/*displaying the result*/

printf("  the circular convolution is\n");

for(i=0;i<n;i++)

printf("%d \t",y[i]);

}

OUTPUT:-

Enter the first sequence

5

6

7

Enter the second sequence

7

8

5

4

OUTPUT   ;-      the circular convolution is

94        110      122      106

MODEL GRAPH: