scipy signal find_peaks_cwt not finding the peaks accurately?

cjm2671 picture cjm2671 · Aug 29, 2014 · Viewed 25.1k times · Source

I've got a 1-D signal in which I'm trying to find the peaks. I'm looking to find them perfectly.

I'm currently doing:

import scipy.signal as signal
peaks = signal.find_peaks_cwt(data, np.arange(100,200))

The following is a graph with red spots which show the location of the peaks as found by find_peaks_cwt().

Signal + Peaks

As you can see, the calculated peaks aren't accurate enough. The ones that are really important are the three on the right hand side.

My question: How do I make this more accurate?

UPDATE: Data is here: http://pastebin.com/KSBTRUmW

For some background, what I'm trying to do is locate the space in-between the fingers in an image. What is plotted is the x-coordinate of the contour around the hand. Cyan spots = peaks. If there is a more reliable/robust approach this, please leave a comment.

enter image description here

Answer

cjm2671 picture cjm2671 · Sep 4, 2014

Solved, solution:

Filter data first:

  window = signal.general_gaussian(51, p=0.5, sig=20)
  filtered = signal.fftconvolve(window, data)
  filtered = (np.average(data) / np.average(filtered)) * filtered
  filtered = np.roll(filtered, -25)

Then use angrelextrema as per rapelpy's answer.

Result:

enter image description here