36 #define SWAP(a, b) {typeof(a) t; t = a; a = b; b = t;}
48 void _fft(std::complex<double> buf[], std::complex<double> out[],
int n,
int step)
50 std::complex<double> zI(0.0, 1.0);
53 _fft(out, buf, n, step*2);
54 _fft(out + step, buf + step, n, step*2);
55 for (
int i=0; i<n; i+=2*step)
57 std::complex<double> t=std::exp(-zI*M_PI*
double(i)/
double(n))*out[i + step];
58 buf[i / 2] = out[i] + t;
59 buf[(i + n)/2] = out[i] - t;
63 void fft(std::complex<double> buf[],
int n)
65 std::complex<double> out[n];
66 for (
int i=0; i<n; i++)
82 void fft(
double *x,
double *y,
int n,
int dir)
84 int m, i1, j, k, i2, l1, l2;
85 double c1, c2, tx, ty, t1, t2, u1, u2, z;
88 while (1<<m<n && m<32)
93 std::cerr <<
"FFT: number of points, " << n <<
", is not a power of 2.\n";
100 for (
int i=0; i<n-1; i++)
123 for (
int l=0; l<m; l++)
131 for (
int i=j; i<n; i+=l2)
134 t1 = u1*x[i1] - u2*y[i1];
135 t2 = u1*y[i1] + u2*x[i1];
145 c2 = sqrt((1.0 - c1)/2.0);
148 c1 = sqrt((1.0 + c1)/2.0);
153 for (
int i=0; i<n; i++)
void _fft(std::complex< double > buf[], std::complex< double > out[], int n, int step)
void fft(std::complex< double > buf[], int n)