新的 Scipy v0.11 提供了一个光谱分析包。不幸的是,文档很少,可用的示例也不多。
作为一个小例子,我正在尝试对正弦波进行周期发现。不幸的是,它预测的是一个时期1
而不是预期的2pi
. 有任何想法吗?
# imports the numerical array and scientific computing packages
import numpy as np
import scipy as sp
from scipy.signal import spectral
# generates 100 evenly spaced points between 1 and 1000
time = np.linspace(1, 1000, 100)
# computes the sine value of each of those points
mags = np.sin(time)
# scales the sine values so that the mean is 0 and the variance is 1 (the documentation specifies that this must be done)
scaled_mags = (mags-mags.mean())/mags.std()
# generates 1000 frequencies between 0.01 and 1
freqs = np.linspace(0.01, 1, 1000)
# computes the Lomb Scargle Periodogram of the time and scaled magnitudes using each frequency as a guess
periodogram = spectral.lombscargle(time, scaled_mags, freqs)
# returns the inverse of the frequence (i.e. the period) of the largest periodogram value
1/freqs[np.argmax(periodogram)]
这将返回1
而不是预期的2pi ~= 1/0.6366
. 有任何想法吗?