|
我在一个周期中采集了32个点!
在网络找了个程序,然后自己修改了一下,运行后的根据得到的数据看了波形,我都不知道对不对,把代码发上来,高手们多多拍砖?!
const float cos_tab[0x20]={
1,0.980785281,0.923879535,0.923879535,0.707106791,0.555570247,0.382683451,0.195090345,
0,-0.195090292,-0.382683401,-0.555570202,-0.707106753,-0.831469588,-0.923879515,-0.980785271,
-1,-0.980785292,-0.923879556,-0.831469648,-0.707106829,-0.555570292,-0.3826835,-0.195090398,
0,0.19509024,0.382683352,0.555570158,0.707106715,0.831469558,0.923879494,0.98078526};
const float sin_tab[0x20]={
0,0.195090319,0.382683426,0.555570225,0.707106772,0.831469603,0.923879525,0.980785276,
1,0.980785286,0.923879545,0.831469633,0.70710681,0.555570269,0.382683476,0.195090371,
0,-0.195090266,-0.382683377,-0.55557018,-0.707106734,-0.831469573,-0.923879504,-0.980785265,
-1,-0.980785297,-0.923879566,-0.831469663,-0.707106848,-0.555570314,-0.382683525,-0.195090424};
/* 采样来的数据放在dataR[ ]数组中,运算前dataI[ ]数组初始化为0 */
void FFT(float dataR[],float dataI[])
{
int x0,x1,x2,x3,x4,x5,xx;
int L,i,j,k,b,p;
float TR,TI,temp;
/********** following code invert sequence ************/
for(i=0;i<32;i++)
{
x0=x1=x2=x3=x4=x5=0;
x0=i&0x01;
x1=(i/2)&0x01;
x2=(i/4)&0x01;
x3=(i/8)&0x01;
x4=(i/16)&0x01;
x5=(i/32)&0x01;
xx=x0*32+x1*16+x2*8+x3*4+x4*2+x5;
dataI[xx]=dataR;
}
for(i=0;i<32;i++)
{
dataR=dataI;
dataI=0;
}
/************** following code FFT *******************/
for(L=1;L<=5;L++) /* for(1) */
{
b=1; i=L-1;
while(i>0)
{
b=b*2; /* b= 2^(L-1) */
i--;
}
for(j=0;j<=b-1;j++) /* for (2) */
{
p=1;
i=5-L;
while(i>0) /* p=pow(2,5-L)*j; */
{
p=p*2;
i--;
}
p=p*j;
for(k=j;k<32;k=k+2*b) /* for (3) */
{
TR=dataR[k];
TI=dataI[k];
temp=dataR[k+b];
dataR[k]=dataR[k]+dataR[k+b]*cos_tab[p]+dataI[k+b]*sin_tab[p];
dataI[k]=dataI[k]-dataR[k+b]*sin_tab[p]+dataI[k+b]*cos_tab[p];
dataR[k+b]=TR-dataR[k+b]*cos_tab[p]-dataI[k+b]*sin_tab[p];
dataI[k+b]=TI+temp*sin_tab[p]-dataI[k+b]*cos_tab[p];
} /* END for (3) */
} /* END for (2) */
} /* END for (1) */
} /* END FFT */
|
|