Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scipy signal find_peaks_cwt not finding the peaks accurately?

Tags:

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

like image 751
cjm2671 Avatar asked Aug 29 '14 15:08

cjm2671


1 Answers

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

like image 63
cjm2671 Avatar answered Oct 15 '22 19:10

cjm2671