There was a Reddit ELI5 post asking about the FFT a while ago that I had commented on and supplied python code for (see below). I ended up copying my response into a blog post.
from cmath import exp,pi
def FFT(X):
n = len(X)
w = exp(-2*pi*1j/n)
if n > 1:
X = FFT(X[::2]) + FFT(X[1::2])
for k in xrange(n/2):
xk = X[k]
X[k] = xk + w**k*X[k+n/2]
X[k+n/2] = xk - w**k*X[k+n/2]
return X
EDIT woops forgot first two lines of code EDIT didn't know about cmath exp
4
u/minnoI <3 duck typing less than I used to, interfaces are niceAug 29 '13
Why the e = exp(1)? Just use exp to do the exponentiation.
6
u/Antagonist360 Aug 29 '13 edited Aug 29 '13
There was a Reddit ELI5 post asking about the FFT a while ago that I had commented on and supplied python code for (see below). I ended up copying my response into a blog post.
EDIT woops forgot first two lines of code
EDIT didn't know about cmath exp