Last active
March 28, 2022 20:54
-
-
Save Eight1911/b7cc6b8cc9645822f0d340c3a4b056e1 to your computer and use it in GitHub Desktop.
Naive implementation of non-recursive radix-2 fast Fourier transform in Python.
This file contains hidden or 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
import math | |
# iterative cooley tukey fft for dyadics | |
def fft(v): | |
n, h = len(v), len(v) >> 1 | |
old, new = v[:], [0] * n | |
sublen, stride = 1, n | |
while sublen < n: | |
stride >>= 1 | |
for i in range(stride): | |
for k in range(0, n, 2*stride): | |
omega = math.exp(math.pi * k / n) | |
new[i+(k>>1)] = old[i+k] + omega * old[i+k+stride] | |
new[i+(k>>1)+h] = old[i+k] - omega * old[i+k+stride] | |
old, new = new, old | |
sublen <<= 1 | |
return old |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment