Python scipy 信号 find_peaks_cwt 没有准确找到峰值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25571260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
scipy signal find_peaks_cwt not finding the peaks accurately?
提问by cjm2671
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().
下面是一个带有红点的图表,它显示了由 找到的峰值的位置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
更新:数据在这里: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.
对于某些背景,我想要做的是定位图像中手指之间的空间。绘制的是手周围轮廓的 x 坐标。青色斑点 = 峰。如果有更可靠/更强大的方法,请发表评论。


采纳答案by cjm2671
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.
然后根据rapelpy的回答使用angrelextrema。
Result:
结果:


回答by rapelpy
Edited after getting the raw data.
获取原始数据后进行编辑。
argelmax and arglextrma are out of the race.
argelmax 和 arglextrma 不在比赛中。
The curve is very noisy, so you have to play with small peak width (as pv. mentioned) and the noise.
曲线非常嘈杂,因此您必须使用小峰宽(如 pv. 所述)和噪声。
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]


回答by sweetdream
There is a much easier solution using this function: https://gist.github.com/endolith/250860which is an adaptation of http://billauer.co.il/peakdet.html
使用此功能有一个更简单的解决方案:https: //gist.github.com/endolith/250860,这是对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 :-)
享受 :-)



