天天看點

Python簡單FFT變換實作

def fft_(signal, fs):
    if not fs:
        raise ValueError("The sampling frequency must be given !")
    L = len(signal)
    PL = abs(np.fft.fft(signal / L))[: int(L / 2)]
    PL[0] = 0
    f = np.fft.fftfreq(L, 1 / fs)[: int(L / 2)]
    return f,