Algorithm to locate local maxima

后端 未结 9 1883
有刺的猬
有刺的猬 2020-12-24 03:24

I have data that always looks something like this:

alt text http://michaelfogleman.com/static/images/chart.png

I need an algorithm to locate the three peaks.

相关标签:
9条回答
  • 2020-12-24 03:32

    You could try to fit a spline to the data and then find the extrema of the spline. Since the spline is piecewise polynomial, the exact locations of the extrema can be found with relatively simple formulas.

    0 讨论(0)
  • 2020-12-24 03:32

    Do you know the derivative of the data? If yes and you can symbolically solve the system then you can find the points where the derivative is equal to zero.

    If you don't have the formula (which seems to be the case from your OP) then you might want to try filter out some noise then do the following:

    If you can't solve symbolically then you can use something like Newton–Raphson method to get to the local maxima and choose the starting points randomly from the range to try to capture all the maxima.

    If you don't have the derivative data then you might want to try a hill climbing algorithm that doesn't require the derivative and start it at multiple different randomly chosen points. You could then keep track of the points that you find when the iterative hill climbing part of the algorithm terminates. This will only probabilistically find all the local maxima but it may be good enough for your purposes.

    EDIT: given that the 3 peaks will be roughly in the same places you should try guarantee that the starting point for these algorithms is near those points for at least some of the times you run the iterative algorithm.

    0 讨论(0)
  • 2020-12-24 03:36

    Another method is to create what i call a walking slope average. I dont know if there is a name for it but it goes like this, your data set is for example 1000 numbers, you take x[n] +x[n..1234567] numbers say 7 numbers ahaed, take average of first 3 and last 3 use them to find if a line put over them would go up or down.

    When it goes down you passed a mountain peek number, after one such sample keep waiting till it raises again. So only after upwards you track the first moment of going down. And repeat that.

    It will detect tops, and depending on slope line length (7) .. 15 ..33 etc, you also remove noise.

    0 讨论(0)
  • 2020-12-24 03:43

    The local maxima would be any x point which has a higher y value than either of its left and right neighbors. To eliminate noise, you could put in some kind of tolerance threshold (ex. x point must have higher y value than n of its neighbors).

    To avoid scanning every point, you could use the same approach but go 5 or 10 points at a time to get a rough sense of where the maximum lie. Then come back to those areas for a more detailed scan.

    0 讨论(0)
  • 2020-12-24 03:43

    You could try a band-pass filter to reject the noise and make it easier to reliably select those maxima.

    The point of a band-pass (rather than low-pass) is to pull nearly-constant down to zero. That way, the highest values you find in the filtered result will probably be the clearest peaks.

    Certainly if you can define a narrow frequency-range for your signal and apply a very selective filter, it should make a fairly unsophisticated maxima-finding algorithm practical - e.g. a simple sample-thats-higher-than-either-neighbour scan.

    A sophisticated filter might not be necessary - you could get away with a mexican hat wavelet at a single well-chosen scale. One scale probably means it's not really a wavelet any more - just a band-pass FIR filter.

    EDIT

    There's an asymmetric wavelet (I forget the name) which, if the mexican hat is analogous to a cosine, takes the role of the sine. I mention it as it combines band-pass filtering with a kind of derivative - the zero-crossings in the result are the stationary-points of a band-pass filtered version of the original signal.

    A "debounced" scan could then identify reliable maxima by looking for crossing points in this "derivative" signal.

    0 讨论(0)
  • 2020-12-24 03:47

    Couldn't you move along the graph, regularly calculating the derivative and if it switches from positive to negative you've found a peak?

    0 讨论(0)
提交回复
热议问题