Sunday 24 November 2013

Cprogram to perform circular convolution

          I would like to write blogs which contains programs in C language or of MATLAB code.The reason is simple,I have a subject called Digital signal processing laboratory.It contains totally 24 programs and in exam we need to write just two,so some programs which I like out of the remaining ones I would like to write them in my blogs.
          C program :
#include<stdio.h>
int i,j,m,n,x[30],h[30],y[30],a[30],x2[30],temp[30];
main()
{
     printf("enter the length of the first sequence");
      scanf("%d",&m);
      printf("enter the length of the second sequence");
      scanf("%d",&n);
      printf("enter the first sequence");
      for(i=0;i<m;i++)
      scanf("%d",&x[i]);
      printf("enter the second sequence");
      for(j=0;j<n;j++)
       scanf("%d",&h[j]);
      if(m-n!=0)
{
    if(m>n)
   {
        for(i=n;i<m;i++)
        h[i]=0;
        m=n;
}
     for(i=m;i<n;i++)
      x[i]=0;
       m=n;
  }
      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[1-j];
          for(i=0;i<n;i++)
           {
                a[i]=x2[i];
               y[k]+=x[i]*x2[i];
         }
      }
          printf("circular convolution is ");
          for(i=0;i<n;i++)
          printf("%d\n",y[i]);

No comments:

Post a Comment