|
一个网上下载的C51的FFT程序,有些不懂,好象没有处理输入数据
[复制链接]
程序内容如下 #include <reg52.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <absacc.h>
#define uchar unsigned char #define uint unsigned int #define size 1024 const float pi=3.1416; float xdata xreal[size]; float xdata ximag[size]; float xdata outputreal[size]; float xdata input[size]; float xdata largest=0;
uint f0; uchar t1h,t1l; uchar i=20; uchar j=0,k=0;
uint ibitr(uint j,uint nu) { int b,j1,i,j2; j1=j; b=0; for(i=1;i<=nu;i++) { j2=j1/2; b=b*2+(j1-2*j2); j1=j2; } return(b); }
void fft( uint n , uint nu) { float treal,timag,arg,c,s; uint p,n2,nu1,l,i,j,k,kn2;
n2=n; nu1=nu;
for (l=0;l<nu;l++) { nu1=nu1-1; n2=n2/2; k=0; while(k+n2<n) { for(i=0;i<n2;i++) { j=k>>nu1; p=ibitr(j,nu); arg=6.28315*p/n; c=cos(arg); s=sin(arg); kn2=k+n2; treal=xreal[kn2]*c-ximag[kn2]*s; timag=ximag[kn2]*c+xreal[kn2]*s; xreal[kn2]=xreal[k]-treal; ximag[kn2]=ximag[k]-timag; xreal[k]=xreal[k]+treal; ximag[k]=ximag[k]+timag; k=k+1; } k=k+n2; } } for(k=0;k<n;k++) { i=ibitr(k,nu); if(i>k) { treal=xreal[k]; timag=ximag[k]; xreal[k]=xreal; ximag[k]=ximag; xreal=treal; ximag=timag; } } } void Fill(void) //数组清零 { uint i; for(i=0;i<size;i++) { xreal=0; ximag=0; outputreal=0; } }
void inputdata(void) { int i; for(i=0;i<size;i++) { input=XBYTE[0x0000+i]; } }
void main(void) { uint i,j;
inputdata();
fft(size,(uint)(log(size)/log(2)));
for (i=0;i<size;i++) { outputreal = sqrt (xreal* xreal+ximag*ximag); if (outputreal>largest) largest=outputreal; }
while(1); { }
}
怎么看也觉得void fft( uint n , uint nu)这个函数没有处理需要处理的数据(inputdata());那位大侠能解释一下啊,如果是正确的我还要移植到STM32上,搞不懂为什么不用STM32的DSP库,非得让我们移植!
|
|