情节的寻找时期

问题描述 投票:-1回答:1

我构建了一个包含3个不同图的图,这些图代表在某个时间范围内3个不同质量的位置。我想找到每个时期。我不熟悉在寻找在线查找周期时遇到的FFT函数。我该怎么办?下面是绘图和图形的内核;我不会包括用于构建所有这些变量的代码,因为它会涉及面很广。

我知道我的代码只是开始制作垂直线,然后通过肉眼进行估算,但是我宁愿通过编码而不是使用该方法来进行编码。

#using the times in days
T9 = 500
dt9 = 0.5
num9 = T9/dt9
times9 = np.linspace(0, T9, num9)
xpos_q9_m1_AU_new = xpos_q9_m1_AU[:-1]
xpos_q9_m2_AU_new = xpos_q9_m2_AU[:-1]
xpos_q9_m3_AU_new = xpos_q9_m3_AU[:-1]
plt.plot(times9, xpos_q9_m1_AU_new)
plt.plot(times9, xpos_q9_m2_AU_new)
plt.plot(times9, xpos_q9_m3_AU_new)
plt.xlabel('Time (days)')
plt.ylabel('X Positions (AU)')
plt.title('X Position of the Kepler 16 System over Time')
plt.legend(['Body 1', 'Body 2', 'Body 3'])
plt.savefig('q9_plot.png');

X Position of Masses over Time

python math plot figure period
1个回答
0
投票

您正在寻找的是Fourier Transform。此功能确定什么频率组成一个波。 Scipy有一个可以很好地为您完成此任务的模块:

from scipy.fft import fft
# Number of sample points
N = 600
# sample spacing
T = 1.0 / 800.0
x = np.linspace(0.0, N * T, N)
y = np.sin(50.0 * 2.0 * np.pi * x)
yf = fft(y)
xf = np.linspace(0.0, 1.0 / (2.0 * T), N // 2)
import matplotlib.pyplot as plt
plt.plot(xf, 2.0 / N * np.abs(yf[0:N // 2]))
plt.grid()
plt.show()

Frequency distribution of np.sin(50.0 * 2.0 * np.pi * x) showing spike at 50

这为您提供了显示预测频率的图表。

© www.soinside.com 2019 - 2024. All rights reserved.