对于间隔不均匀的样本,您可以
scipy.signal.lombscargle用来计算Lomb-
Scargle周期图。这是一个示例,其主频为2.5 rad / s。
from __future__ import divisionimport numpy as npfrom scipy.signal import lombscargleimport matplotlib.pyplot as pltnp.random.seed(12345)n = 100x = np.sort(10*np.random.rand(n))# Dominant periodic signaly = np.sin(2.5*x) # Add some smaller periodic componentsy += 0.15*np.cos(0.75*x) + 0.2*np.sin(4*x+.1)# Add some noisey += 0.2*np.random.randn(x.size)plt.figure(1)plt.plot(x, y, 'b')plt.xlabel('x')plt.ylabel('y')plt.grid()dxmin = np.diff(x).min()duration = x.ptp()freqs = np.linspace(1/duration, n/duration, 5*n)periodogram = lombscargle(x, y, freqs)kmax = periodogram.argmax()print("%8.3f" % (freqs[kmax],))plt.figure(2)plt.plot(freqs, np.sqrt(4*periodogram/(5*n)))plt.xlabel('Frequency (rad/s)')plt.grid()plt.axvline(freqs[kmax], color='r', alpha=0.25)plt.show()
该脚本将打印
2.497并生成以下图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)