Tuesday, July 24, 2012

One-Liner for Finding Peaks or Troughs in Data

To find the indices of the peaks or troughs in a data set x, using Python of MATLAB, we use
pks = find( diff( sign( diff( x ) ) ) < 0 ) + 1
trs = find( diff( sign( diff( x ) ) ) > 0 ) + 1 
 

1 comment: