【问题标题】:Using scipy.signal.spectral.lombscargle for period discovery使用 scipy.signal.spectral.lombscargle 进行周期发现
【发布时间】:2012-11-01 04:47:11
【问题描述】:

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

【问题讨论】:

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


【解决方案1】:

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

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

【讨论】:

  • 是不是意味着结果要乘以2pi?
  • 是的,角频率以弧度/秒为单位。您可以在wikipedia 中阅读更多相关信息
  • @EarlBellinger 如果您对它感到满意,您也可以接受答案。
  • 确实;在接受之前,我只是确认它适用于我的重要示例。我现在已经确认它有效!非常感谢!
猜你喜欢
  • 2013-01-09
  • 1970-01-01
  • 1970-01-01
  • 2014-09-10
  • 2020-07-13
  • 2010-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多