python - 使用 scipy.signal.spectral.lombscargle 进行周期发现

标签 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 的预期周期。有什么想法吗?

最佳答案

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

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

关于python - 使用 scipy.signal.spectral.lombscargle 进行周期发现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13349181/

相关文章:

python - 无法在 AWS lambda 上使用 wget.download 下载文件并出现 Errno 97

python - pytest mysql 数据库 fixture : cannot create database

python - 在 nginx 上使用 Fabric 的 Python Flask Web 应用程序中出现上游超时错误

python - 多列(2D)numpy 数组到指示向量的稳定转换

python - 非线性回归中的标准误差

python - 使用 PySide 和 QTextEdit 半透明突出显示

python - 对统计处理的 R2 值使用 'groupby' - python

python - 在 matplotlib 动画中绘制不同颜色的点

python - 解析和计算 boolean 集定义

python - 数据帧行的快速笛卡尔求和