Circular Convolution of two sequences using DFT and IDFT
Compute the circular convolution of given two sequences using DFT and IDFT.
1: #include<graphics.h>
2: #include<iostream.h>
3: #include<conio.h>
4: #include<stdlib.h>
5: void main(void)
6: {
7: int sample,impulse,sam[10],imp[10],out[10][10],outp[10]={0},i;
8: int gd=DETECT,gm,maxx,maxy,j,k;
9: char str[5];
10: initgraph(&gd,&gm,"c:\\tc\\bgi");
11: maxx=getmaxx(); // Returns maximum x or y screen coordinate
12: maxy=getmaxy();
13: cout<<"\n\tEnter the number of element in sample sequence::";
14: cin>>sample;
15: cout<<"\n\tEnter the number of element in impulse sequence::";
16: cin>>impulse; //input impulse & sample sequence
17: cout<<"\n\tEnter the sample sequence";
18: for(i=0;i<sample;i++)
19: cin>>sam[i];
20: cout<<"\n\tEnter the impusle sequence";
21: for(i=0;i<impulse;i++)
22: cin>>imp[i];
23: if(sample<impulse)
24: for(i=sample;i<impulse;i++)
25: sam[i]=0;
26: else
27: for(i=impulse;i<sample;i++)
28: imp[i]=0;
29: if(sample<impulse)
30: sample=impulse;
31: int temp;
32: for(i=0;i<sample;i++)
33: for(j=0;j<sample;j++)
34: {
35: out[(j+i)%sample][i]=sam[j];
36: }
37: for(j=0;j<sample;j++)
38: for(k=0;k<sample;k++)
39: outp[j]=outp[j]+out[j][k]*imp[k];
40: int samp=sample;
41: setcolor(RED);
42: line(0,maxy/2,maxx,maxy/2);
43: line(maxx/2,0,maxx/2,maxy);
44: setcolor(GREEN);
45: for(i=0;i<samp;i++)
46: {
47: line(maxx/2+i*30,maxy/2,maxx/2+i*30,maxy/2-outp[i]*5);
48: moveto(maxx/2+i*30,maxy/2-outp[i]*5-10);
49: itoa(outp[i],str,10); //converts integer to string
50: outtext(str);
51: }
52: getch();
53: }