繁体   English   中英

fft功率谱困难

[英]fft power spectrum woes

我无法从傅里叶变换中获取频谱......我有一些数据: 数据

我以中心为中心,似乎没有太多的趋势......

我绘制了它的傅立叶变换:

傅里叶变换

而且我得到的东西并不好......

这是我的代码:

def fourier_spectrum(X, sample_freq=1):
    ps = np.abs(np.fft.fft(X))**2
    freqs = np.fft.fftfreq(X.size, sample_freq)
    idx = np.argsort(freqs)

    plt.plot(freqs[idx], ps[idx])

改编自此处的代码。

它似乎适用于一些天真的sin波数据:

fourier_spectrum(np.sin(2*np.pi*np.linspace(-10,10,400)), 20./400)

sin谱

所以我的问题是:我期待一个非零几乎无处不在的频谱,我做错了什么? 如果我没有做错什么,我的数据的哪些功能导致了这个? 另外,如果我没有做错任何事情,并且由于某种原因fft不适合我的数据,我该怎么做才能从我的数据中提取重要的频率?

事实证明,我只是不理解频谱中x轴的单位,即Hz。 因为我的样本间距大约为一秒,而我的周期大约是一天,所以在我的频谱上真正可见的唯一单位是~1 / s(在边缘处)到大约1 / m(近中间的),任何时间长于此的东西都与0无法区分。我的误解源于教程中的图形,它们进行转换以使x轴单位及时,而不是反时间。 我重写了我的frequency_spectrum绘图功能,对结果图进行了适当的“缩放”...

def fourier_spectrum(X, sample_spacing_in_s=1, min_period_in_s=5):
    '''
        X: is our data
        sample_spacing_in_s: is the time spacing between samples
        min_period_in_s: is the minimum period we want to show up in our
            graph... this is handy because if our sample spacing is
            small compared to the periods in our data, then our spikes
            will all cluster near 0 (the infinite period) and we can't
            see them.  E.g. if you want to see periods on the order of
            days, set min_period_in_s=5*60*60 #5 hours
    '''
    ps = np.abs(np.fft.fft(X))**2
    freqs = np.fft.fftfreq(X.size, sample_spacing_in_s)
    idx = np.argsort(freqs)
    plt.plot(freqs[idx], ps[idx])
    plt.xlim(-1./min_period_in_s,1./min_period_in_s) # the x-axis is in Hz

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM