當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cusignal.spectral_analysis.spectral.lombscargle用法及代碼示例

用法:

cusignal.spectral_analysis.spectral.lombscargle(x, y, freqs)

計算Lomb-Scargle 周期圖。 Lomb-Scargle 周期圖由 Lomb [1] 開發,並由 Scargle [2] 進一步擴展,以發現和測試具有不均勻時間采樣的弱周期信號的重要性。當 normalize 為 False(默認)時,計算的周期圖未歸一化,對於具有足夠大 N 的振幅 A 的諧波信號,它采用值 (A**2) * N/4。當 normalize 為 True 時,計算的周期圖由殘差歸一化圍繞恒定參考模型(為零)的數據。輸入數組應該是一維的並且將被強製轉換為 float64。

參數

xarray_like

采樣時間。

yarray_like

測量值。

freqsarray_like

輸出周期圖的角頻率。

precenter布爾型,可選

通過減去平均值預中心振幅。

normalize布爾型,可選

計算歸一化周期圖。

返回

pgramarray_like

Lomb-Scargle 周期圖。

拋出

ValueError

如果輸入數組 xy 的形狀不同。

注意

由於 Townsend [3],此子例程使用稍微修改的算法計算周期圖,該算法允許僅使用每個頻率的輸入數組單次通過來計算周期圖。對於大量樣本和頻率,算法運行時間大致為 O(x * freqs) 或 O(N^2)。

參考

1

N.R. Lomb “Least-squares frequency analysis of unequally spaced data”, Astrophysics and Space Science, vol 39, pp. 447-462, 1976

2

J.D. Scargle “Studies in astronomical time series analysis. II - Statistical aspects of spectral analysis of unevenly spaced data”, The Astrophysical Journal, vol 263, pp. 835-853, 1982

3

R.H.D. Townsend, “Fast calculation of the Lomb-Scargle periodogram using graphics processing units.”, The Astrophysical Journal Supplement Series, vol 191, pp. 247-253, 2010

例子

>>> import cusignal
>>> import cupy as cp
>>> import matplotlib.pyplot as plt
First define some input parameters for the signal:
>>> A = 2.
>>> w = 1.
>>> phi = 0.5 * cp.pi
>>> nin = 1000
>>> nout = 100000
>>> frac_points = 0.9 # Fraction of points to select
Randomly select a fraction of an array with timesteps:
>>> r = cp.random.rand(nin)
>>> x = cp.linspace(0.01, 10*cp.pi, nin)
>>> x = x[r >= frac_points]
Plot a sine wave for the selected times:
>>> y = A * cp.sin(w*x+phi)
Define the array of frequencies for which to compute the periodogram:
>>> f = cp.linspace(0.01, 10, nout)
Calculate Lomb-Scargle periodogram:
>>> pgram = cusignal.lombscargle(x, y, f, normalize=True)
Now make a plot of the input data:
>>> plt.subplot(2, 1, 1)
>>> plt.plot(cp.asnumpy(x), cp.asnumpy(y), 'b+')
Then plot the normalized periodogram:
>>> plt.subplot(2, 1, 2)
>>> plt.plot(cp.asnumpy(f), cp.asnumpy(pgram))
>>> plt.show()

相關用法


注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cusignal.spectral_analysis.spectral.lombscargle。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。