Plotting power spectrum in python

后端 未结 5 1993
情深已故
情深已故 2020-12-07 09:51

I have an array with 301 values, which were gathered from a movie clip with 301 frames. This means 1 value from 1 frame. The movie clip is running at 30 fps, so is in fact 1

5条回答
  •  一整个雨季
    2020-12-07 10:37

    if rate is the sampling rate(Hz), then np.linspace(0, rate/2, n) is the frequency array of every point in fft. You can use rfft to calculate the fft in your data is real values:

    import numpy as np
    import pylab as pl
    rate = 30.0
    t = np.arange(0, 10, 1/rate)
    x = np.sin(2*np.pi*4*t) + np.sin(2*np.pi*7*t) + np.random.randn(len(t))*0.2
    p = 20*np.log10(np.abs(np.fft.rfft(x)))
    f = np.linspace(0, rate/2, len(p))
    plot(f, p)
    

    enter image description here

    signal x contains 4Hz & 7Hz sin wave, so there are two peaks at 4Hz & 7Hz.

提交回复
热议问题