36 lines
577 B
Python
36 lines
577 B
Python
import numpy as np
|
|
|
|
|
|
|
|
|
|
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):
|
|
return FFT_np(inp)
|
|
|
|
def FFT_np(inp):
|
|
inp = np.array(inp)
|
|
N = inp.shape[0]
|
|
if N == 1:
|
|
return inp
|
|
X_even = FFT_np(inp[::2])
|
|
X_odd = FFT_np(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))
|
|
|