MSP430 FFT算法
/*****************main programe********************/#include<msp430x14x.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "typedef.h "
float result;
struct compx s;
int Num=8;
const float pp=3.141592653589793;
extern void FFT(struct compx *s,int num);
double mpr,mpi,mfr,mfi;
int n,k,l,il;
extern void kbfft();
extern void FFT_dingdian();
main()
{
// ????
int i;
FILE *fin,*fout;
if((fin=fopen( "indata.txt ", "r "))==NULL)
{
printf( "can 't open infile ");
exit(0);
};
for(i=0;i <Num;i++)
{
//fscanf(fin, "%lf ",&s.real);
s.real=cos(2*3.1415926*(30)*(i)/80.0);//
s.imag=(double)0;
mpr=s.real;
mpi=0;
};
fclose(fin);
//////////////
//FFT(s,Num);
//n=8;k=3;l=0;il=0;
//kbfft(mpr,mpi,n,k,mfr,mfi,l,il);
FFT_dingdian();
//????
if((fout=fopen( "fftresult.txt ", "w "))==NULL)
{
printf( "can 't open outfile ");
exit(0);
};
for(i=0;i <Num;i++)
{
// result=sqrt(pow(s.real,2)+pow(s.imag,2));
fprintf(fout, "%lf+(%lf)i ",s.real,s.imag);
};
fclose(fout);
} //---定点---
#include<msp430x14x.h>
#include "math.h"
#define NN 8
//************************余弦表**********************************
constfloatCOS_tab=
{1.0000,0.9998,0.9993,0.9986,0.9975,0.9962,0.9945,0.9925,0.9903,
0.9877,0.9848,0.9816,0.9781,0.9744,0.9703,0.9659,0.9614,0.9563,
0.9511,0.9455,0.9397,0.9336,0.9272,0.9205,0.9135,0.9063,0.8988,
0.8910,0.8829,0.8746,0.8660,0.8572,0.8480,0.8387,0.8290,0.8192,
0.8090,0.7986,0.7880,0.7771,0.7760,0.7547,0.7431,0.7314,0.7193,
0.7071,0.6947,0.6820,0.6691,0.6561,0.6428,0.6293,0.6157,0.6018,
0.5878,0.5736,0.5592,0.5446,0.5299,0.5150,0.5000,0.4848,0.4695,
0.4540,0.4384,0.4226,0.4067,0.3907,0.3746,0.3584,0.3420,0.3256,
0.3090,0.2924,0.2757,0.2588,0.2419,0.2250,0.2079,0.1908,0.1736,
0.1564,0.1392,0.1219,0.1045,0.0872,0.0698,0.0523,0.0349,0.0174,
0.0000};
char Re(char M,char k)
{
char m=1;
int n;
while(M>0){m=m*2;M--;}//m==pow(2,M)
n=360 * k /m;
return n;
}
void FFT_dingdian( void )
{
signed char flag1=1,flag2=1;
chari,j,k,R,I;
char p,p1;
//float i5,i6,i7,i8;
char M,L;
int a,b,x=1,y=1,z=1;
int N1;
struct comp
{
float re;
float im;
}aa={{1,0},{0,0},{-1,0},{0,0},{1,0},{0,0},{-1,0},{0,0}};//,{9,0},{10,0},
//{11,0},{12,0},{13,0},{14,0},{15,0},{16,0}};//
struct comp bb,bb1,bb2;
L=0;
N1=NN;
while(N1>0)
{N1=N1/2;L++;}// L=log(NN)/log(2);
L=L-1;
//输入变址
for(i=0,j=0;i<NN;i++)
{
if(i>=j){k=NN/2;}
else
{
k=NN/2;
bb=aa;
aa=aa;
aa=bb;
}
while(k<=j){j=j-k;k=k/2;
if(k==j)break;}
j=j+k;
}
//变址结束
//由下开始FFT计算
for(M=1;M<=L;M++)
{
x=M-1;
a=1;
while(x>0){a=a*2;x--;}//a==2的M-1次方
for(k=0;k<a;k++)//a==2的M-1次方,即每一级有2的M-1次方个不同的旋转因子,步进值是1
//---同时也是蝶形结两结点间距
{
y=M;
b=1;
while(y>0){b=b*2;y--;}//b==2的M次方
//p=0;
for(p=k;p<NN-1;p=p+b)//b==2的M次方----相同旋转因子的蝶形结间距
{
p1=p+a;//a==2的M-1次方
R=Re(M,k);//----------------------=360*k/(2^M)--k最大为2^M-1
I=Re(M,k);//Re(M,k)==Im(M,k)
if(R>=0&&R<=90){flag1=1;}
else if(R>90&&R<=180){ R=180-R;flag1=-1;}
else if(R>180&&R<=270){ R=R-180;flag1=-1;}
else if(R>270&&R<=360){ R=360-R;flag1=1;}
if(I>=0&&I<=90){I=90-I;flag2=1;}
else if(I>90&&I<=180){I=I-90;flag2=1;}
else if(I>180&&I<=270){I=270-I;flag2=-1;}
else if(I>270&&I<=360){I=I-270;flag2=-1;}
bb.re=aa.re;
bb.im=aa.im;
bb1.re=aa.re*(flag1)*COS_tab;
bb1.im=aa.im*(flag2)*COS_tab;
bb2.re=aa.re*(flag2)*COS_tab;
bb2.im=aa.im*(flag1)*COS_tab;
aa.re=bb.re+bb1.re+ bb1.im;
aa.im=bb.im+bb2.im - bb2.re ;
aa.re=bb.re-bb1.re- bb1.im;
aa.im=bb.im-bb2.im + bb2.re ;
}
}
}
//FFT计算结束
return;
} 需要多长时间啊?? mark!!! mark mark mark 请问做一个FFT,430需要多长时间?
我现在在做一个水流量测速的玩意。
想用相位差法,但是不想用DSP这等高级玩意。这里看到楼主的帖子。很是兴奋!! mark !MSP430 FFT算法. mark mark 学习了 楼主浮点运算用float?应该double更准吧。。。 mark MARK 标记 fft算法以后留着有用 mark 记下,以后慢慢看 mark mark mark FFT
算法 学习。。。 马克一下 早看到这个就好了,实训的时候可以方便很多 mark 这可是好东西。MARK~~ 回复【12楼】lileistone 三块石头
-----------------------------------------------------------------------
430要避免DOUBLE运算,费时。8M的速度还是有点不快不慢的。。。 mark,看到很多程序都用这个,了解下 mark mark 收藏。记住了 MARK! 感觉用整形的比较快 记得以前大学编的FFT在486/66上计算 256x256矩阵要1s Mark 看看 mark一記,非常感謝,很有用的東西~~~ MARK,我想知道需要多少时间,我用430,8M的晶振,做一次FIR滤波 需要20ms,32位的,不知道这个需要多久? 有时间放到我板上跑跑看。谢了。 谢谢分享,请问楼主这个算法用来多少时间? 记号记号 MSP430 FFT算法. #include "typedef.h "????
这个是什么函数????{:sad:} mark{:lol:} 虽然 我还不知道FFT到底是什么 但是 感觉还是蛮有用的 所以感谢楼主咯 以后应该会用到~ 强 !! dianyuan 发表于 2010-12-23 16:37 static/image/common/back.gif
//---定点---
#include
#include "math.h"
mark !!! 标记,有用 {:smile:}{:smile:}{:smile:} mark!!先记下
mark 一下,做个记号啊,做个记号 留着以后看~~~ 额,楼主float最多7位有效数字... cool 楼主,你好!
我现在正在研究MSP430的FF算法,我可以向您请教一下吗?1790485810,这是我的QQ。谢谢 mark !MSP430 FFT算法. mark,mark, {:smile:}mark mark{:smile:} mark................... 不错,支持! 我现在正在研究MSP430的FF算法,我可以向您请教一下 路过,学习的 MARK,谢谢分享 真差劲,居然是浮点的,改成定点还差不多 看一下! fft算法以后留着有用 Mark!! 谢谢分享.正需要
页:
[1]