请教各位前辈,我在用2407a做fft运算实验,使用ti的库函数。但程序计算出来的结果和matlab计算出来的结果不一样(峰值频率对得上,但幅值不对)。 源程序如下: #include "math.h"
#include "fft.h"
#define N 128 /* FFT Length */
#pragma DATA_SECTION(ipcb, "FFTipcb"); #pragma DATA_SECTION(mag, "FFTmag"); #pragma DATA_SECTION(win, "FFTwin");
FFT128C fft=FFT128C_DEFAULTS;
int ipcb[2*N]; /* In place computation buffer */ int mag[N]; /* Magnitude buffer */ int win[N/2]=HAMMING128; /* Window coefficient array */
int src[N];
#define PI (3.141592654)
main() { int i; int peak,freq;
disable(); lf2407a_init();
/* FFT initialization */ fft.ipcbptr=ipcb; /* FFT computation buffer */ fft.magptr=mag; /* Store mag. square in separate buff */ fft.winptr=win; /* Window coefficient array */ fft.init(); /* Copy Twiddle factor */ /* Acquire samples in bit reversed order or Bit-reverse the in-order data using bit-rev utility */
for(i=0;i<N;i++) { src = 32768 * cos(2*PI*i/N); } FFTC_brev1(src, ipcb, N);
/* FFT Computation */ fft.win(&fft); /* Window the input data */ fft.izero(&fft); /* Zero the imaginary part */ fft.calc(&fft); /* Compute the FFT */ fft.mag(&fft); /* Obtain the magnitude square */
peak=fft.peakmag; freq=fft.peakfrq;
while(1); }
结果分析请看下楼 |