This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

调用库函数处理FFT出错



#include <stdio.h>

#include "math.h"

#include <DSPF_sp_cfftr2_dit.h>

#include <fastmath67x.h>

#define PI 3.14159265

#define f1 200

#define f2 1000

#define N 512

void gen_w_r2(float* w, int n);

void bit_rev(float *x, int n);

void divide(float* x, int n);

void DSPF_sp_cfftr2_dit(float     * x, float * w,  short n);

int i;

float *w;

float *x;

float input[N],Rot[N];

void main()

{

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

{

input[2*i]=(sin(2*PI*f1*i/N)+sin(2*PI*f2*i/N));

input[2*i+1]=0;

}

x=input;

w=Rot;

   gen_w_r2(w, N);      // Generate coefficient table  

   bit_rev(w, N>>1); // Bit reverse coefficient table      

   DSPF_sp_cfftr2_dit(x, w, N); // This is the radix 2 FFT benchmark from TI available input in normal order, output in  coefficient table in bit-reversed order

   while ( 1 );

}

void gen_w_r2(float* w, int n)                                      

   {                                                            

       int i;                                                      

       float pi = 4.0*atan(1.0);                                

       float e = pi*2.0/n;                                        

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

       {                                                        

            w[2*i]  = cos(i*e);                                

            w[2*i+1] = sin(i*e);                                

       }                                                        

   }                                          

//The follwoing C code is used to bit-reverse the output.    

void bit_rev(float *x, int n)                                  

{                                                          

  int i, j, k;                                              

  double rtemp, itemp;                                      

  j = 0;                                                    

  for(i=1; i < (n-1); i++)                                  

  {                                                        

    k = n >> 1;                                            

     while(k <= j)                                          

     {                                                      

        j -= k;                                            

        k >>= 1;                                            

     }                                                      

     j += k;                                                

     if(i < j)                                              

     {                                                      

        rtemp    = x[j*2];                                  

        x[j*2]   = x[i*2];                                  

        x[i*2]   = rtemp;                                  

        itemp    = x[j*2+1];                                

        x[j*2+1] = x[i*2+1];                                

        x[i*2+1] = itemp;                                  

     }                                                      

  }                                                        

}    

void divide(float* x, int n)              

{                                    

   int i;                          

   float inv = 1.0 / n;            

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

   {                                

       x[2*i]   = inv * x[2*i];    

       x[2*i+1] = inv * x[2*i+1];  

   }                                

}