This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
430做fft 为什么采样点数是256可以运行程序 而512就不行了
#include <msp430f5529.h> #include "math.h" #include "IQmathLib.h" #define PI 3.1415926536 #define FFT_N 256 #define GLOBLA_IQ 15 volatile float res; struct compx {float real,imag;}; //����һ�������ṹ struct compx s[FFT_N]; //FFT�������� /******************************************************************* ����ԭ�ͣ�struct compx EE(struct compx b1,struct compx b2) �������ܣ��������������г˷����� *******************************************************************/ float MM(float m,float n) { _iq qA,qB,qC; qA = _IQ(m); qB = _IQ (n) ; qC = _IQmpy(qA,qB); res=_IQtoF(qC); return(res); } struct compx EE(struct compx a,struct compx b) { struct compx c; c.real = MM(a.real,b.real) - MM(a.imag,b.imag); c.imag = MM(a.real,b.imag) + MM(a.imag,b.real); return(c); } void delay(int count) { int i; for(i = 0; i < count; i++) { asm("nop"); } } /************************************************************ ������void Reverse(struct compx *xin) �������ܣ���ַ�任 ���������*xin�����ṹ�������ַָ�룬struct�� ************************************************************/ void Reverse(struct compx *xin) //�任˳����� { int nv2,nm1,i,k,j=0; struct compx t; nv2=FFT_N/2; //��ַ���㣬������Ȼ˳���ɵ�λ�� nm1=FFT_N-1; for(i=0;i<nm1;i++) { if(i<j) //���i<j,�����б�ַ { t=xin[j]; xin[j]=xin[i]; xin[i]=t; } k=nv2; //��j����һ����λ�� while(k<=j) //���k<=j,��ʾj�����λΪ1 { j=j-k; //�����λ���0 k=k/2; //k/2���Ƚϴθ�λ���������ƣ�����Ƚϣ�ֱ��ij��λΪ0 } j=j+k; //��0��Ϊ1 } } /***************************************************************** ����ԭ�ͣ�void FFT(struct compx *xin,int N) �������ܣ�������ĸ�������п��ٸ���Ҷ�任��FFT�� ���������*xin�����ṹ�������ַָ�룬struct�� *****************************************************************/ void FFT(struct compx *xin) { { int le,lei,ip,l,m,j,i,f; struct compx u,w,t; _iq qA, qB, qC; f=FFT_N; for(l=1;(f=f/2)!=1;l++) ; //����l��ֵ����������μ���; //l=8; for(m=1;m<=l;m++) // ���Ƶ��νἶ�� { //m��ʾ��m�����Σ�lΪ���μ�����l=log��2��N le=2<<(m-1); //le���ν���룬����m�����εĵ��ν����le�� lei=le/2; //ͬһ���ν��вμ����������ľ��� u.real=1.0; //uΪ���ν�����ϵ������ʼֵΪ1 u.imag=0.0; /***************************************************************** qA = _Q(PI/4.0); qB = _Q(0.5); qC = _IQsin(qA); res=_QtoF(qC); // 0.70710 = sin(PI/4) qC = _IQcos(qA); res=_QtoF(qC); // 0.70710 = cos(PI/4) qC = _Qatan(qB); res=_QtoF(qC); // 0.46365 = atan(0.5) *****************************************************************/ qA=_IQ(PI/lei); qB=_IQcos(qA); w.real=_IQtoF(qB); //wΪϵ���̣�����ǰϵ����ǰһ��ϵ������ qC=_IQsin(qA); w.imag=-(_IQtoF(qC)); //w.imag=-sin(PI/lei); for(j=0;j<=lei-1;j++) //���Ƽ��㲻ͬ�ֵ��νᣬ������ϵ����ͬ�ĵ��ν� { for(i=j;i<=FFT_N-1;i=i+le) //����ͬһ���ν����㣬������ϵ����ͬ���ν� { ip=i+lei; //i��ip�ֱ��ʾ�μӵ�������������ڵ� t=EE(xin[ip],u); //�������㣬�����ʽ xin[ip].real=xin[i].real-t.real; xin[ip].imag=xin[i].imag-t.imag; xin[i].real=xin[i].real+t.real; xin[i].imag=xin[i].imag+t.imag; } u=EE(u,w); //�ı�ϵ����������һ���������� } } } } /************************************************************ ������void main() ************************************************************/ void main() { WDTCTL = WDTPW + WDTHOLD; int i; int n=0; for(n=0;n<FFT_N;n++) //���ṹ�帳ֵ { s[n].real=sin(2*3.141592653589793*50*n/256); //ʵ��Ϊ���Ҳ�FFT_N���������ֵΪ1 //s[i].real=sin(2*3.141592653589793*i/FFT_N); //ʵ��Ϊ���Ҳ�FFT_N���������ֵΪ1 s[n].imag=0.0; //�鲿Ϊ0 } delay(1000); Reverse(s); FFT(s); //���п��ٸ���Ҷ�任 delay(1000); for(i=0;i<FFT_N;i++)//��任������ģֵ�����븴����ʵ���� { s[i].real=sqrt(s[i].real*s[i].real+s[i].imag*s[i].imag); } while(1); }