寻找最接近P的最小值

2024-09-28 05:23:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用^{}查找峰值和最小值,使用:

import numpy as np
from scipy.signal import find_peaks

x=np.array([9.8,57.,53.,37.,24.,19.,16.,15.,13.,13.,12.,12.,11.,11.,11.,11.,11.,11.,10.,13.,13.,13.,15.,13.,12.,14.,15.,14.,51.,34.,24.,20.,24.,22.,18.,57.,63.,38.,27.,28.,31.,33.,94.,71.,48.,40.,43.,39.,31.,27.,22.,21.,20.,19.,18.,18.,19.,20.,20.,49.,62.,48.,43.,34.,33.,28.,26.,26.,24.,23.,23.,26.,27.,70.,97.,57.,46.,68.,82.,59.,49.,37.,40.,45.,36.,33.,28.,22.,23.,284.,524.,169.,111.,148.,98.,68.,50.,38.,30.,28.])
peaks, _ = find_peaks(x)
mins, _ =find_peaks(x*-1)

看起来像:

enter image description here

现在我有兴趣找到最接近每一个峰值的最小值。所以我可以把它们区别开来。你知道吗

在浏览了find_peaks文档之后,参数^{}似乎就是我要找的。你知道吗

prominences = peak_prominences(x, peaks)[0]
contour_heights = x[peaks] - prominences

然后看起来像:

enter image description here

经过检查,peak_prominences发现了峰值之前的最小值。对于我的应用程序,我需要最接近的峰值,不管它是在前面还是后面。你知道吗

如何使用minspeak_prominence计算定义参数wlen。?你知道吗

既然mins由极小值的指数组成,我如何用它来定义wlen?我基本上需要找到以min为单位的指数来限制每个峰值(即peaks[i])。你知道吗

仅仅使用minspeaks是否有更好的方法来实现这一点?你知道吗


Tags: fromimportnumpy参数定义asnpfind
1条回答
网友
1楼 · 发布于 2024-09-28 05:23:27

Now I am interested to find the closest minima to each peak. So I can take the difference between them.

以下是你要找的吗?你知道吗

closest_mins = [mins[np.argmin(np.abs(x-mins))] for x in peaks]
difference = x[peaks]-x[closest_mins]
print(difference)
[ 47.   3.   1.  37.   4.  45.  54.   3.  44.  51.  36.   8. 413.  37.]

下面是用虚线表示的peaksminspeaks最近的mins对的图。请注意,有mins最接近多个peaks。你知道吗

plt.plot(x)
plt.plot(peaks, x[peaks],'o', label = 'peaks')
plt.plot(mins, x[mins],'s', label = 'mins')
plt.plot(closest_mins, x[closest_mins],'*', label = 'closest mins')

for p, m in zip(peaks, closest_mins):
    plt.plot([p,m], [x[p], x[m]], 'k', dashes = (4,1))
plt.legend();

enter image description here

相关问题 更多 >

    热门问题