1 private static Complex[] FFT1(Complex[] f) 2 { 3 int N=f.length; 4 int power= (int) (Math.log10(N)/Math.log10(2)); 5 Complex[] F=new Complex[N]; 6 //按奇偶分组 7 for(int i=0;i<N;i++) 8 { 9 int p = 0; 10 for (int j = 0; j < power; j++) 11 if ((i & (1 << j)) != 0) 12 p += 1 << (power - j - 1); 13 14 F[p] = f[i]; 15 } 16 //蝶形因子 17 Complex[] wc = new Complex[N/ 2]; 18 for (int i = 0; i < N / 2; i++) 19 { 20 double angle = -i * Math.PI * 2 / N; 21 wc[i]=new Complex(Math.cos(angle),Math.sin(angle)); 22 } 23 //蝶形运算 24 for(int L=1;L<=power;L++)//第L层数 25 { 26 int bf=1<<(power-L);//蝶形数 27 for(int n=0;n<bf;n++)//第n+1个蝶形 28 { 29 int bfsize=1<<L;//蝶形大小 30 for(int k=0;k<bfsize/2;k++)//第k+1个蝶形因子 31 { 32 Complex temp,X1,X2;; 33 int i=n*bfsize+k, 34 j=i+bfsize/2; 35 temp=wc[k*bf].Mul(F[j]); 36 X1=F[i].Add(temp); 37 X2=F[i].Sub(temp); 38 F[i]=X1; 39 F[j]=X2; 40 } 41 } 42 } 43 return F; 44 }