Last active
April 28, 2022 11:41
-
-
Save Chlumsky/d939d0c1f76a215a6bf4f0c276efb768 to your computer and use it in GitHub Desktop.
Fast Fourier Transform
This file contains 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
#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