This is an extremely fast and simple local extrema finder. It computes both local maxima and minima at the same time, and returns indices to the the corresponding values in the input vector (handling constant regions by returning the index of the first point). This is not a replacement of Matlab's findpeaks function, which is much more powerful and has many more options. But it can be used for performance in routines that rely a lot on local extrema (eg the Hilbert-Huang transform).
FYI for an updated version: https://github.com/Sheljohn/Deck/blob/master/%2Bdk/%2Bmath/local_extrema.m
@François Sorry actually I realised this wasn't the right version :) The update should be able to deal with long plateaus. Again, if you are not happy with this behaviour, just replace loose inequalities with strict ones.
@François This is explicitly mentioned in the help text. If you want to change this behaviour, just replace `<= 0` with `< 0` on line 20.
if the data present stairs, it will take a minimum at each step even if not followed by a higher value
Handles long plateaus and inclusion of endpoints
The previous version offered a threshold parameter, but the associated code was incorrect (the correct way of dealing with thresholds uses topological prominence concepts), so I removed it.