Created
June 22, 2015 13:22
-
-
Save kidpixo/ad2e958e7de4d386fa05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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