impemented FFT with numpy and recursion

This commit is contained in:
2025-10-08 16:23:27 +03:00
parent 601817e2b3
commit 9a8f75de19
3 changed files with 23 additions and 3 deletions

22
FFT.py
View File

@ -3,10 +3,30 @@ import numpy as np
def FFT(inp):
def FFT_backup(inp):
inp = np.array(inp)
out = np.fft.fft(inp)
out = [val for val in np.abs(out)]
print(out)
return out
def FFT_real(inp):
inp = np.array(inp)
out = FFT(inp)
out = [val for val in np.abs(out)]
print(out)
return out
def FFT(inp):
inp = np.array(inp)
N = inp.shape[0]
if N == 1:
return inp
X_even = FFT(inp[::2])
X_odd = FFT(inp[1::2])
k = np.arange(N // 2)
tw = np.exp(-2j * np.pi * k / N) * X_odd
return np.concatenate((X_even + tw, X_even - tw))