Created
April 3, 2014 18:42
-
-
Save halit/9960326 to your computer and use it in GitHub Desktop.
fast fourier transform with recursion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void _fft(double* buf, double* out, unsigned int n, unsigned int step){ | |
if(step<n){ | |
_fft(out, buf, n, step*2); | |
_fft(out+step, buf+step, n, step*2); | |
int i; | |
for(i=0;i<n;i += 2*step){ | |
double t = cexp(-I*PI*i/n)*out[i+step]; | |
buf[i/2] = out[i] + t; | |
buf[(i+n)/2] = out[i] - t; | |
} | |
} | |
} | |
void fft(double* buf, unsigned int n){ | |
double* out = (double*)malloc(sizeof(double)*n); | |
int i; | |
for(i=0;i<n;i++) out[i] = buf[i]; | |
_fft(buf, out, n, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment