Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Nekodigi
Last active December 17, 2020 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nekodigi/dc785025e602a20bb745a49e7d37e518 to your computer and use it in GitHub Desktop.
Save Nekodigi/dc785025e602a20bb745a49e7d37e518 to your computer and use it in GitHub Desktop.
void ditfft2(Complex[] x){//based on this site https://en.wikipedia.org/wiki/Cooley%E2%80%93Tukey_FFT_algorithm
int N = x.length;
if(N == 1){
return;
}else{//based on this site https://github.com/bubnicbf/Fast-Fourier-Transform-using-Cooley-Tukey-algorithm/blob/master/FFT.cpp
Complex[] even = new Complex[N/2];
Complex[] odd = new Complex[N/2];
int index = 0;
for(int i=0; i<N; i+=2)even[index++] = x[i];
index = 0;
for(int i=1; i<N; i+=2)odd[index++] = x[i];
ditfft2(even);//update even
ditfft2(odd);//update odd
for(int k = 0; k < N/2; k++){
Complex t = exp(c(-TWO_PI*k/N)).mult(odd[k]);
x[k] = even[k].add(t);
x[k+N/2] = even[k].sub(t);
}
}
}//result is updated x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment