使用scipy.signal.spectral.lombscargle进行句点发现

时间:2012-11-12 18:16:04

标签: python numpy scipy signal-processing scientific-computing

新的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的预期时段。有什么想法吗?

1 个答案:

答案 0 :(得分:7)

请注意spectral.lombscargle的最后一个参数是根据docstring的角频率:

Parameters
----------
x : array_like
Sample times.
y : array_like
Measurement values.
freqs : array_like
Angular frequencies for output periodogram.