[SciPy-user] Finding local minima of greater than a given depth

Rob Clewley rob.clewley@gmail....
Thu Aug 14 15:01:19 CDT 2008

> Is there a function within scipy somewhere which will, given an array
> representing values of a function, find all the local minima having a
> depth greater than some specified minimum?  The following works great
> for smooth functions, but when the data has noise in it, it also
> returns all of the (very) local minima, which I don't want.

You could low-pass filter out the (presumably high frequency) noise,
which might introduce a slight phase change to your data. But you can
use the local minima of the filtered data as good starting points for
a better search in your original data. You might need to fit local
polynomials to your data near these to find the minimum without
introducing too much statistical bias (e.g. by just taking the
smallest data point, which might only be the smallest because of the

There isn't a scipy function to do this in one go, but there are
filter functions in scipy.signal and some polynomial fitting
functionality recently added by Anne Archibald which I use for this
kind of problem (search these archives for reference to that).

The depth of the minimum is better defined once you fit a function to
the region, but the appropriate size of that region is context
dependent. It could be meaningfully measured w.r.t. the next nearest
local maximum, or to a global average or maximum level derived from
the data. There's no one way to do it.


More information about the SciPy-user mailing list