1

This is an example similar to what my data looks like, there's a sharp peak, surrounded by some small noise, and mostly constant elsewhere with small noise.

Both find_peaks_cwt and peakutils don't perform as I would have hoped on this data.

enter image description here

find_peaks_cwt:

>>> x
[0.1, 0.1, 0.1, 0.11, 0.1, 0.09, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.0, 0.0, 0.4, 0.7, 0.7, 0.2, 0.0, 0.005, 0.1, 0.1]
>>> peaks = scipy.signal.find_peaks_cwt(x, np.arange(1,5))
>>> peaks
[1, 2, 3, 9, 12, 16, 17]

16 and 17 were correct peaks, but what's up with 1,2,3,9,12 being detected? Also, this routine lacks the ability to identify 16/17 as a single peak. That's somewhat problematic for me.

The findpeaks package seems more robust, and I've tried implementing it, but it has weird issues. It will throw exceptions for no reason that makes sense to me when I look at the data (there's a clear peak), and sometimes it'll even produce negative indexes for no obvious reason! I got the buggy heeby jeebies after working with it for a while.

Even on this example, peakutils doesn't seem to perform as hoped for:

>>> x
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.0, 0.0, 0.4, 0.7, 0.7, 0.2, 0.0, 0.005, 0.1, 0.1]
>>> peakutils.indexes(x, thres=0.0) # I tried many values of thres
array([], dtype=int64)

Any suggestions on identifying sharp peaks like this? I'm considering not using peak detection and just writing my own function to identify them.

David Parks
  • 30,789
  • 47
  • 185
  • 328
  • 1
    Performance of find_peaks_cwt depends on the wavelet widths you provide, e.g. try giving it some other than arange(1,5) eg linspace(1,5,100) --- you'll probably need to read the paper it's based on in order to use it properly. – pv. Nov 18 '16 at 19:52
  • I understand, and yes, I just tried `arange(1,100)`, and it picked up the peak correctly in this test example. I'll experiment with this more and look at the paper. You should post that as an answer. Thanks! – David Parks Nov 18 '16 at 20:01
  • I don't fully understand the algorithm myself --- it seems not always return the exact maximum index if the peak has a relatively flat top. Not sure if a bug, or whether this was intended behavior as a "best" estimate of peak center position. – pv. Nov 18 '16 at 20:09
  • I've now been through a lot of peak detection libraries, they all seem to have quirks, and getting really consistent results is not easy. Sharp peaks in particular are problematic, in this case I ended up doing a simple heuristic identifying the largest value and zeroing out data nearby. It works because the peak is so pronounced. I've used `findpeaks` in another case where the data is noisy and get ok results, but not what I would call truly consistent. – David Parks Jan 17 '17 at 19:25

0 Answers0