Scipy/Numpy FFT Frequency Analysis

后端 未结 4 876
再見小時候
再見小時候 2020-12-04 08:15

I\'m looking for how to turn the frequency axis in a fft (taken via scipy.fftpack.fftfreq) into a frequency in Hertz, rather than bins or fractional bins.

I tried to

4条回答
  •  臣服心动
    2020-12-04 08:57

    I think you don't need to do fftshift(), and you can pass sampling period to fftfreq():

    import scipy
    import scipy.fftpack
    import pylab
    from scipy import pi
    t = scipy.linspace(0,120,4000)
    acc = lambda t: 10*scipy.sin(2*pi*2.0*t) + 5*scipy.sin(2*pi*8.0*t) + 2*scipy.random.random(len(t))
    
    signal = acc(t)
    
    FFT = abs(scipy.fft(signal))
    freqs = scipy.fftpack.fftfreq(signal.size, t[1]-t[0])
    
    pylab.subplot(211)
    pylab.plot(t, signal)
    pylab.subplot(212)
    pylab.plot(freqs,20*scipy.log10(FFT),'x')
    pylab.show()
    

    from the graph you can see there are two peak at 2Hz and 8Hz.

    enter image description here

提交回复
热议问题