Skip to content

Commit aa1b315

Browse files
authored
Create fft.py
1 parent 02087e3 commit aa1b315

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

fft.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Author Dario Clavijo 2023
2+
# based on https://en.wikipedia.org/wiki/Cooley%E2%80%93Tukey_FFT_algorithm
3+
from gmpy2 import *
4+
pi_i = (-2j) * complex(gmpy2.const_pi())
5+
6+
def fft(X):
7+
if (N:=len(X)) == 1:
8+
return X
9+
else:
10+
N2 = N >> 1
11+
E = fft(X[::2])
12+
O = fft(X[1::2])
13+
for k in range(0, N2):
14+
q = exp((pi_i * k) / N ) * O[k]
15+
X[k] = E[k] + q
16+
X[k + N2] = E[k] - q
17+
return X

0 commit comments

Comments
 (0)