Anonymous user
Fast Fourier transform: Difference between revisions
m
→{{header|C}}: Since we are using c99 anyway...
m (→{{header|C}}: Since we are using c99 anyway...) |
|||
Line 93:
#include <math.h>
#include <complex.h>
double PI;
typedef double complex cplx;
void _fft(cplx
{
_fft(out, buf, n, step * 2);
_fft(out + step, buf + step, n, step * 2);
▲ if (step < n) {
for (int i = 0; i < n; i += 2
cplx t = cexp(-I * PI * i / n) *
}
}
▲ buf[i / 2] = out[i] + t;
▲ buf[(i + n)/2] = out[i] - t;
}
void fft(cplx buf[], int n)
{▼
cplx out[n];
▲{
}
int main()
{
PI = atan2(1, 1) *
▲ cplx buf[] = {1, 1, 1, 1, 0, 0, 0, 0};
▲ for (i = 0; i < 8; i++)
printf("%g + %g i\n", creal(buf[i]), cimag(buf[i]));▼
fft(buf, 8);▼
for (i = 0; i < 8; i++)▼
printf("%g + %g i\n", creal(buf[i]), cimag(buf[i]));▼
void show(char * s) {
return 0;▼
printf(s);
}</lang>Output:<lang>1 + 0 i▼
if (!cimag(buf[i]))
else
}
show("Data: ");
show("\nFFT : ");
FFT : 4 (1, -2.41421) 0 (1, -0.414214) 0 (1, 0.414214) 0 (1, 2.41421)</lang>
=={{header|C++}}==
|