Skip to content

Instantly share code, notes, and snippets.

@halit
Created April 3, 2014 18:42
Show Gist options
  • Save halit/9960326 to your computer and use it in GitHub Desktop.
Save halit/9960326 to your computer and use it in GitHub Desktop.
fast fourier transform with recursion
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