N-Point algorithm using code composer studio

AIM:   To verify Linear Convolution using Code Composer Studio.

SOFTWARE REQUIREMENTS:

Operating System – Windows XP

Constructor - Simulator

Software – Code Composer 3.1v,6713DSK  Diagnostics 

 PROGRAM CODE:

#include <stdio.h>
#include <math.h>
void butterfly(double *,double *,double *,double *,double *,double *);
int main( )
{
int i;
double x[8]={1,2,3,4,4,3,2,1};        
//double x[8]={4,3,2,1,0,0,0,0};
 double XR[8];
 double XI[8]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
 double  WNR[4]={0.999969,  0.707092, 0.0,   -0.707092};
 double WNI[4]={0.0    , -0.707092,-0.999969,-0.707092};
 double spectrum[8];

   // store data in bit reversal order
    XR[0]=x[0];
    XR[1]=x[4];
    XR[2]=x[2];
    XR[3]=x[6];
    XR[4]=x[1];
    XR[5]=x[5];
    XR[6]=x[3];
    XR[7]=x[7];
  //  clrscr( );

// FIRST STAGE OF BUTTERFLY
   butterfly(&amp;amp;XR[0],&amp;amp;XI[0],&amp;amp;XR[1],&amp;amp;XI[1],&amp;amp;WNR[0],&amp;amp;WNI[0]);
   butterfly(&amp;amp;XR[2],&amp;amp;XI[2],&amp;amp;XR[3],&amp;amp;XI[3],&amp;amp;WNR[0],&amp;amp;WNI[0]);
   butterfly(&amp;amp;XR[4],&amp;amp;XI[4],&amp;amp;XR[5],&amp;amp;XI[5],&amp;amp;WNR[0],&amp;amp;WNI[0]);
   butterfly(&amp;amp;XR[6],&amp;amp;XI[6],&amp;amp;XR[7],&amp;amp;XI[7],&amp;amp;WNR[0],&amp;amp;WNI[0]);
   
  // SECOND STAGE OF BUTTERFLY

   butterfly(&amp;amp;XR[0],&amp;amp;XI[0],&amp;amp;XR[2],&amp;amp;XI[2],&amp;amp;WNR[0],&amp;amp;WNI[0]);
   butterfly(&amp;amp;XR[1],&amp;amp;XI[1],&amp;amp;XR[3],&amp;amp;XI[3],&amp;amp;WNR[2],&amp;amp;WNI[2]);
   butterfly(&amp;amp;XR[4],&amp;amp;XI[4],&amp;amp;XR[6],&amp;amp;XI[6],&amp;amp;WNR[0],&amp;amp;WNI[0]);
   butterfly(&amp;amp;XR[5],&amp;amp;XI[5],&amp;amp;XR[7],&amp;amp;XI[7],&amp;amp;WNR[2],&amp;amp;WNI[2]);
   
  // THIRD STAGE OF BUTTERFLY
   butterfly(&amp;amp;XR[0],&amp;amp;XI[0],&amp;amp;XR[4],&amp;amp;XI[4],&amp;amp;WNR[0],&amp;amp;WNI[0]);
   butterfly(&amp;amp;XR[1],&amp;amp;XI[1],&amp;amp;XR[5],&amp;amp;XI[5],&amp;amp;WNR[1],&amp;amp;WNI[1]);
   butterfly(&amp;amp;XR[2],&amp;amp;XI[2],&amp;amp;XR[6],&amp;amp;XI[6],&amp;amp;WNR[2],&amp;amp;WNI[2]);
   butterfly(&amp;amp;XR[3],&amp;amp;XI[3],&amp;amp;XR[7],&amp;amp;XI[7],&amp;amp;WNR[3],&amp;amp;WNI[3]);
         
    for(i=0;i<8;i++)
     {
       XR[i]*=64.0;
       XI[i]*=64.0;
      }
    for(i=0;i<8;i++)
    {
    printf("\n FFT XR[%d] = %lf XI[%d]=  %lf",i,XR[i],i,XI[i]);
    }
    return(0);
    }
void butterfly(double *ar,double *ai,double *br,double *bi,double *wr,double *wi)
    {
     double tr,ti;
     *ar/=4.0;
     *ai/=4.0;
      tr=*ar*2;
      ti=*ai*2;
     *br/=4.0;
     *bi/=4.0;
     *ar+=*br * *wr - *bi * *wi;
     *ai+=*br * *wi + *bi * *wr;
     *br= tr - *ar;  
     *bi= ti - *ai;  
      }

 

Expected Output:

 

XR[0]=19.9999070; XI[0]=0.000000;

XR[1]=-5.828134;    XI[1]=-2.414237;

XR[2]=0.000813;     XI[2]=-0.000093;

XR[3]=-0.171618;    XI[3]=-0.414175;

XR[4]=0.000248;     XI[4]=0.000000;