Use scipy.signal.argrelmax You can get the index of the peak value.
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
x = np.linspace(0,10,100)
yorg = np.sin(x)
y = yorg + np.random.randn(100)*0.2
#Get index of peak value
maxid = signal.argrelmax(y, order=1) #Maximum value
minid = signal.argrelmin(y, order=1) #minimum value
plt.plot(x,yorg,'r',label='Original sin')
plt.plot(x,y,'k-',label='Original series')
plt.plot(x[maxid],y[maxid],'ro',label='Peak value')
plt.plot(x[minid],y[minid],'bo',label='Peak value (minimum)')
plt.legend()
If you change the value of order, the extraction interval will change.
Recommended Posts