[PYTHON] Extract peak values with scipy

Extract peak values with scipy

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()

peak.png

If you change the value of order, the extraction interval will change. peak2.png

Recommended Posts

Extract peak values with scipy
LPC with Scipy
CORDIC with Scipy
Create filter with scipy
Normarize data with Scipy
Extract EXIF with sips
How to extract null values and non-null values with pandas
Extract non-numeric elements with pandas.DataFrame
Extract Twitter data with CSV
Extract numbers with regular expressions
Harmonic mean with Python Harmonic mean (using SciPy)
Calculate sample distribution with Scipy (discrete distribution)
[Automation] Extract Outlook appointments with Python
Generate a normal distribution with SciPy
Scikit-learn DecisionTreeClassifier with datetime type values
[Beginner] Extract character strings with Python
Extract specific multiple columns with pandas
Extract multiple elements with Numpy array