scipy signal find_peaks_cwt not finding the peaks accurately?

有些话、适合烂在心里 提交于 2019-11-30 06:31:43

问题


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().

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.


回答1:


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:




回答2:


There is a much easier solution using this function: https://gist.github.com/endolith/250860 which is an adaptation of http://billauer.co.il/peakdet.html

I've just tried with the data you provided and I got the result below. No need for pre-filtering...

Enjoy :-)




回答3:


Edited after getting the raw data.

argelmax and arglextrma are out of the race.

The curve is very noisy, so you have to play with small peak width (as pv. mentioned) and the noise.

The best I found looks not very good.

import numpy as np
import scipy.signal as signal

peakidx = signal.find_peaks_cwt(y_array, np.arange(10,15), noise_perc=0.1)
print peakidx

[10, 100, 132, 187, 287, 351, 523, 597, 800, 1157, 1451, 1673, 1742, 1836]



来源:https://stackoverflow.com/questions/25571260/scipy-signal-find-peaks-cwt-not-finding-the-peaks-accurately

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!