时间序列的极值点提取

在这里插入图片描述
什么叫极值点提取,大家看看图就知道了吧!

代码也很简单,只需要调用 scipy 中 signal 模块的 find_peaks 函数即可

from scipy import signal 

peaks, _ = signal.find_peaks(y, distance=5) #distance表示极大值点两两之间的距离至少大于等于5个水平单位

print(peaks)
'''
[   6   39   71  103  125  146  170  198  233  253  272  291  309  329
  349  370  394  423  463  483  503  524  545  569  600  646  669  694
  724  768  790  814  841  874  897  921  949  985 1004 1023 1042 1060
 1080 1100 1121 1145 1174 1213 1234 1253 1273 1294 1317 1344 1377 1399
 1424 1453 1489 1509 1528 1546 1565 1585 1605 1627 1653 1685 1725 1746
 1767 1788 1812 1842 1883 1904 1925 1947 1973]
'''
print(len(peaks))  # the number of peaks
'''
79
'''

plt.figure(figsize=(20,5))
plt.plot(y)
for i in range(len(peaks)):
    plt.plot(peaks[i], y[peaks[i]],'*',markersize=10)
plt.show()

猜你喜欢

转载自blog.csdn.net/itnerd/article/details/108362607