Initial commit

This commit is contained in:
2026-02-18 21:32:22 +01:00
commit ea3a39f550
15 changed files with 903 additions and 0 deletions

31
fft/fft.py Normal file
View File

@@ -0,0 +1,31 @@
import numpy as np
def fft(x: np.array) -> np.array:
N = len(x)
if N == 1:
return x
else:
even_fft = fft(x[::2])
odd_fft = fft(x[1::2])
factors = np.exp(-2j * np.pi * np.arange(N) / N)
result = np.concatenate([even_fft + factors[:N // 2] * odd_fft,
even_fft + factors[N // 2:] * odd_fft])
return result
def main():
x = np.arange(8)
fft(x)
# # x = np.random.normal(size=4)
# x = np.array([1, 0, 1, 0, 0, 0, 0, 0])
# print(f"own:\t{fft(x)}")
# print(f"numpy:\t{np.fft.fft(x)}")
if __name__ == "__main__":
main()