我试图计算最大宽度,但当使用peak_widths时,它返回信号中的所有峰值宽度。
from scipy.signal import chirp, find_peaks, peak_widths
import matplotlib.pyplot as plt
x = np.linspace(0, 6 * np.pi, 1000)
y = np.sin(x) + 0.6 * np.sin(2.6 * x)
peaks, _ = find_peaks(y)
results_half = peak_widths(y, peaks, rel_height=0.5)
results_half[0]
plt.plot(y)
plt.plot(peaks, y[peaks], "x")
plt.hlines(*results_half[1:], color="C2")
plt.show()
这是来自https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.peak_widths.html的示例
我只想得到最大的宽度。
我想使用最大峰值位置的索引来找到最大峰值的fwhm。如何才能找到相应的最大宽度?
i_max_peak = peaks[np.argmax(y[peaks])]
y_max =y[i_max_peak]
我想得到最大峰值的宽度值。
发布于 2022-06-09 15:02:07
我想你已经走了一半了。
您已经用[np.argmax(y[peaks])]
获得了最大峰值的索引,剩下的是从results_half[0]
获取宽度
所以,我相信这会给你你想要的:
max_peak_loc = np.argmax(y[peaks])
widths = results_half[0]
widths[max_peak_loc]
https://stackoverflow.com/questions/72561977
复制相似问题