我正在尝试比较两个频谱,但我对许多观点感到困惑。
一台设备以40赫兹的频率采样,另一台以100赫兹的频率采样,因此我不确定是否需要考虑这一点。无论如何,我已经从两个设备产生了频谱,现在我想比较这些。如何在每个点进行相关,以便在每个点获得pearson相关性。我知道如何做一个整体当然但我想看到强相关点和那些不太强的点?
答案 0 :(得分:1)
如果计算功率谱密度P(f),那么原始信号x(t)的采样方式无关紧要。您可以直接和定量地比较两种光谱。为了确保您已经计算了谱密度,您可以明确地检查Parsevals定理:
$ \ int P(f)df = \ int x(t)^ 2 dt $
当然你必须考虑实际评估的频率请记住,fft会给你f = 1 / T的频率,直到或低于奈奎斯特频率f_ny = 1 /(2 dt),具体取决于x中的样本数量(t)是偶数还是奇数。
这是psd
的python示例代码def psd(x,dt=1.):
"""Computes one-sided power spectral density of x.
PSD estimated via abs**2 of Fourier transform of x
Takes care of even or odd number of elements in x:
- if x is even both f=0 and Nyquist freq. appear once
- if x is odd f=0 appears once and Nyquist freq. does not appear
Note that there are no tapers applied: This may lead to leakage!
Parseval's theorem (Variance of time series equal to integral over PSD) holds and can be checked via
print ( np.var(x), sum(Px*f[1]) )
Accordingly, the etsimated PSD is independent of time series length
Author/date: M. von Papen / 16.03.2017
"""
N = np.size(x)
xf = np.fft.fft(x)
Px = abs(xf)**2./N*dt
f = np.arange(N/2+1)/(N*dt)
if np.mod(N,2) == 0:
Px[1:N/2] = 2.*Px[1:N/2]
else:
Px[1:N/2+1] = 2.*Px[1:N/2+1]
# Take one-sided spectrum
Px = Px[0:N/2+1]
return Px, f