C++实现FFT算法
#include "iostream.h"
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
#include "malloc.h"
#define PI (float)3.1415926//复数结构体
typedef struct{ float re; float im;}complex;//定义旋转因子
complex W(int N,int n){
complex out; out.re=(float)cos(2*PI*((float)n/(float)N));
out.im=-(float)sin(2*PI*((float)n/(float)N)); return out;
}
//复数加法,out=a+b
complex add(complex a,complex b){
complex out;
out.re=a.re+b.re;
out.im=a.im+b.im;
return out;}
//复数减法,out=a-b
complex sub(complex a,complex b){
complex out;
out.re=a.re-b.re;
out.im=a.im-b.im;
return out;}
//复数乘法,out=a*b
complex mul(complex a,complex b){
complex out;
out.re=a.re*b.re-a.im*b.im;
out.im=a.re*b.im+a.im*b.re;
return out;
}
//复数赋值
complex comcpy(complex a){
complex out;
out.re=a.re;
out.im=a.im;
return out;
}
bool DOFFT(complex *x,complex *F,int N){
int K=(int)(log(N+1)/log(2));// cout<
}
// cout<
}
return true;
}
int reverse(int n,int j){
int i,k,power;
power=(int)(log(n+1)/log(2));
k=0;
for(i=0;i
return k;
}
void main(){
int m,i,j; for(i=0;i cout< DOFFT(x,F,N); cout< }
int N=4;
complex *x,*F;
x=new complex[N];
F=new complex[N];
for(i=0;i
x[i].im=0;
cout<<"x["< }
for(i=N/2;i
x[i].im=0;
cout<<"x["< }
cout<
}
for(i=0;i
}
for(i=0;i
for(i=0;i
cout<<"("<