⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fft256c.c

📁 这是本人在TI DSP C6713DSK开发板上开发的256点FFT实现程序
💻 C
字号:
//FFT256c.c FFT implementation calling a C-coded FFT function 

#include "dsk6713_aic23.h"
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;

#include <math.h>                          
#define PTS 256			    //# of points for FFT 
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n);	    //FFT prototype
float iobuffer[PTS];   		    //as input and output buffer
float x1[PTS];         		    //intermediate buffer 
short i;               		    //general purpose index variable                  
short buffercount = 0;     	    //number of new samples in iobuffer         
short flag = 0;        		    //set to 1 by ISR when iobuffer full   
COMPLEX w[PTS];       		    //twiddle constants stored in w 
COMPLEX samples[PTS];  		    //primary working buffer                                              

main()
{
 for (i = 0 ; i<PTS ; i++)	    // set up twiddle constants in w 
  {
   w[i].real = cos(2*PI*i/512.0); //Re component of twiddle constants
   w[i].imag =-sin(2*PI*i/512.0); //Im component of twiddle constants
  }
 comm_intr();			    //init DSK, codec, McBSP 
 
 while(1)				    //infinite loop   
  {
   while (flag == 0) ;            //wait until iobuffer is full 
   flag = 0;                      //reset flag
   for (i = 0 ; i < PTS ; i++)    //swap buffers
    {
     samples[i].real=iobuffer[i]; //buffer with new data
     iobuffer[i] = x1[i];         //processed frame to iobuffer
    } 
   for (i = 0 ; i < PTS ; i++)
     samples[i].imag = 0.0;	    //imag components = 0

   FFT(samples,PTS);              //call function FFT.c

   for (i = 0 ; i < PTS ; i++)    //compute magnitude
    {
     x1[i] = sqrt(samples[i].real*samples[i].real 
	     + samples[i].imag*samples[i].imag)/16;
    }
   x1[0] = 32000.0;               //negative spike for reference
  }                               //end of infinite loop
} 					    //end of main

interrupt void c_int11()	    //ISR
 {
  output_sample((short)(iobuffer[buffercount]));     //out from iobuffer
  iobuffer[buffercount++]=(float)((short)input_sample()); //input to iobuffer
  if (buffercount >= PTS)				   //if iobuffer full
  {
	buffercount = 0;					   //reinit buffercount
	flag = 1;						   //set flag
  }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -