Skip to content

Instantly share code, notes, and snippets.

@Chlumsky
Last active April 28, 2022 11:41
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 Chlumsky/d939d0c1f76a215a6bf4f0c276efb768 to your computer and use it in GitHub Desktop.
Save Chlumsky/d939d0c1f76a215a6bf4f0c276efb768 to your computer and use it in GitHub Desktop.
Fast Fourier Transform
#include <artery-math.h>
using namespace artery;
// Fast Fourier Transform implementation by Viktor Chlumsky
template <typename T, typename U>
void fft(Complex<T> *dst, const U *src, int length, int stride = 1) {
if (!(length >>= 1)) {
*dst = *src;
return;
}
fft(dst, src, length, stride<<1);
fft(dst+length, src+stride, length, stride<<1);
Complex<T> w = exp(-PI/length*Complex<T>::I);
for (Complex<T> q = 1, *mid = dst+length; length--; q *= w) {
Complex<T> k = q**mid;
*mid++ = *dst-k;
*dst++ += k;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment