impemented FFT with numpy and recursion
This commit is contained in:
22
FFT.py
22
FFT.py
@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user