#NEWLINE# def peakdet( v , delta , x = None ) : #NEWLINE# #INDENT# '\n    Converted from MATLAB script at http://billauer.co.il/peakdet.html\n    \n    Returns two arrays\n    \n    function [maxtab, mintab]=peakdet(v, delta, x)\n    %PEAKDET Detect peaks in a vector\n    %        [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local\n    %        maxima and minima ("peaks") in the vector V.\n    %        MAXTAB and MINTAB consists of two columns. Column 1\n    %        contains indices in V, and column 2 the found values.\n    %      \n    %        With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices\n    %        in MAXTAB and MINTAB are replaced with the corresponding\n    %        X-values.\n    %\n    %        A point is considered a maximum peak if it has the maximal\n    %        value, and was preceded (to the left) by a value lower by\n    %        DELTA.\n    \n    % Eli Billauer, 3.4.05\n    % This function is released to the public domain; Any use is allowed.\n    \n    ' #NEWLINE# maxtab = [ ] #NEWLINE# mintab = [ ] #NEWLINE# if ( x is None ) : #NEWLINE# #INDENT# x = numpy . arange ( len ( v ) ) #NEWLINE# #UNINDENT# v = numpy . asarray ( v ) #NEWLINE# if ( len ( v ) != len ( x ) ) : #NEWLINE# #INDENT# sys . exit ( 'Input vectors v and x must have same length' ) #NEWLINE# #UNINDENT# if ( not numpy . isscalar ( delta ) ) : #NEWLINE# #INDENT# sys . exit ( 'Input argument delta must be a scalar' ) #NEWLINE# #UNINDENT# if ( delta <= 0 ) : #NEWLINE# #INDENT# sys . exit ( 'Input argument delta must be positive' ) #NEWLINE# #UNINDENT# ( mn , mx ) = ( numpy . Inf , ( - numpy . Inf ) ) #NEWLINE# ( mnpos , mxpos ) = ( numpy . NaN , numpy . NaN ) #NEWLINE# lookformax = True #NEWLINE# for i in numpy . arange ( len ( v ) ) : #NEWLINE# #INDENT# this = v [ i ] #NEWLINE# if ( this > mx ) : #NEWLINE# #INDENT# mx = this #NEWLINE# mxpos = x [ i ] #NEWLINE# #UNINDENT# if ( this < mn ) : #NEWLINE# #INDENT# mn = mxpos #NEWLINE# mnpos = x [ i ] #NEWLINE# #UNINDENT# if lookformax : #NEWLINE# #INDENT# if ( this < ( mx - delta ) ) : #NEWLINE# #INDENT# maxtab . append ( mxpos ) #NEWLINE# mn = this #NEWLINE# mnpos = x [ i ] #NEWLINE# lookformax = False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( this > ( mn + delta ) ) : #NEWLINE# #INDENT# mintab . append ( mnpos ) #NEWLINE# mx = this #NEWLINE# mxpos = x [ i ] #NEWLINE# lookformax = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( numpy . array ( maxtab ) , numpy . array ( mintab ) )