impemented FFT with numpy and recursion

This commit is contained in:
2025-10-08 16:24:04 +03:00
parent 9a8f75de19
commit db305dbfda

7
FFT.py
View File

@ -20,12 +20,15 @@ def FFT_real(inp):
def FFT(inp): def FFT(inp):
return FFT_np(inp)
def FFT_np(inp):
inp = np.array(inp) inp = np.array(inp)
N = inp.shape[0] N = inp.shape[0]
if N == 1: if N == 1:
return inp return inp
X_even = FFT(inp[::2]) X_even = FFT_np(inp[::2])
X_odd = FFT(inp[1::2]) X_odd = FFT_np(inp[1::2])
k = np.arange(N // 2) k = np.arange(N // 2)
tw = np.exp(-2j * np.pi * k / N) * X_odd tw = np.exp(-2j * np.pi * k / N) * X_odd
return np.concatenate((X_even + tw, X_even - tw)) return np.concatenate((X_even + tw, X_even - tw))