document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. -------------------------------------------------------------------------------------------------
  3.  ASSIGNMENT NO : 6
  4.  TITLE : WRITE A PROGRAM IN C TO FIND CIRCULAR CONVOLUTION OF TWO SEQUENCES.
  5. -------------------------------------------------------------------------------------------------
  6. */
  7.  
  8. #include<stdio.h>
  9. #include<conio.h>
  10.  
  11. int m,n,x[30],h[30],y[30],i,j, k,x2[30],a[30];
  12.  
  13. void main()
  14. {
  15.     clrscr();
  16.     printf("\\n Enter the length of the first sequence = ");
  17.     scanf("%d",&m);
  18.     printf("\\n Enter the length of the second sequence = ");
  19.     scanf("%d",&n);
  20.     printf("\\nEnter the first sequence = ");
  21.     for(i=0;i<m;i++)
  22.         scanf("%d",&x[i]);
  23.     printf("\\nEnter the second sequence = ");
  24.     for(j=0;j<n;j++)
  25.         scanf("%d",&h[j]);
  26.     if(m-n!=0)                                      /*If length of both sequences are not equal*/
  27.     {
  28.         if(m>n)                                 /* Pad the smaller sequence with zero*/
  29.         {
  30.             for(i=n;i<m;i++)
  31.                 h[i]=0;
  32.             n=m;
  33.         }
  34.         for(i=m;i<n;i++)
  35.             x[i]=0;
  36.         m=n;
  37.     }
  38.     y[0]=0;
  39.     a[0]=h[0];
  40.     for(j=1;j<n;j++)                            /*folding h(n) to h(-n)*/
  41.         a[j]=h[n-j];                        /*Circular convolution*/
  42.     for(i=0;i<n;i++)
  43.         y[0]+=x[i]*a[i];
  44.     for(k=1;k<n;k++)
  45.     {
  46.         y[k]=0;                         /*circular shift*/
  47.         for(j=1;j<n;j++)
  48.             x2[j]=a[j-1];
  49.         x2[0]=a[n-1];
  50.         for(i=0;i<n;i++)
  51.         {
  52.             a[i]=x2[i];
  53.             y[k]+=x[i]*x2[i];
  54.         }
  55.     }
  56.  
  57.     /*displaying the result*/
  58.     printf(" \\nThe circular convolution = ");
  59.     for(i=0;i<n;i++)
  60.     printf("%d \\t",y[i]);
  61.     getch();
  62. }
');