Skip to content

Instantly share code, notes, and snippets.

@kidpixo
Created June 22, 2015 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidpixo/ad2e958e7de4d386fa05 to your computer and use it in GitHub Desktop.
Save kidpixo/ad2e958e7de4d386fa05 to your computer and use it in GitHub Desktop.
# see http://stackoverflow.com/a/20642478/1435167
import numpy as np
from scipy.signal import argrelextrema
x = np.random.random(100)
# for local maxima
argrelextrema(x, np.greater)
# for local minima
argrelextrema(x, np.less)
ind = np.arange(0,len(x))
# see http://wiki.scipy.org/Cookbook/SavitzkyGolay
smo = savitzky_golay(savitzky_golay(x,21,3),21,3)
plt.plot(ind,x,'--')
#plt.plot(ind[argrelextrema(x, np.greater)],x[argrelextrema(x, np.greater)],'bo')
plt.plot(ind,smo,'r',lw=3)
# maxima
plt.plot(ind[argrelextrema(smo, np.greater)],smo[argrelextrema(smo, np.greater)],'ro')
# minima
plt.plot(ind[argrelextrema(smo, np.less)],smo[argrelextrema(smo, np.less)],'bo')
plt.ylim([-.5,1.5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment