The detection of peaks using the min_dist parameter does not always produce correct results

Issue #1 resolved
marcos_duarte created an issue

Hi Lucas

First of all, very nice functions. There is a problem with the peak.indexes function: the detection of peaks using the min_dist parameter does not always produce correct results. For instance:

y = np.array([0, 1, 0, 2, 0, 3, 0, 2, 0, 1, 0])
peakutils.indexes(y, thres=0, min_dist=2)

Returns:

array([5, 9], dtype=int64)

But the correct is:

array([3, 5, 9], dtype=int64)

The problem is the comparison (of peak at 3) with a larger peak (at 5) which later will be removed after a comparison with an even larger peak (at 9). I solved this problem inspired on the matlab findpeaks function, see Detection of peaks in data

I hope this helps. Marcos

Comments (6)

  1. Lucas Hermann Negri repo owner

    Hello Marcos,

    Thanks for the report and for the proposed solution! I will study your implementation and think about the problem a little more. By the way, thanks for publishing your implementation, it served as inspiration for the indexes function.

    Thanks,

    Lucas.

  2. marcos_duarte reporter

    Great. And good that the function detects 1, 5, and 9 and not 3, 5, and 9! (unintentional mistake).

  3. Log in to comment