pwtools.signal.find_peaks¶
- pwtools.signal.find_peaks(y, x=None, k=3, spread=2, ymin=None)[source]¶
Simple peak finding algorithm.
Find all peaks where
y > ymin
. If x given, also extract peak maxima positions by fitting a spline of order k to each found peak. To find minima, just use-y
.- Parameters:
y (1d array_like) – data with peaks
x (1d array_like, optional, len(y)) – x axis
k (int) – order of spline
spread (int) – Use
2*spread+1
points around each peak to fit a spline. Note that we need2*spread+1 > k
.ymin (float, optional) – Find all peaks above that value.
- Returns:
idx0, pos0
idx0 (indices of peaks from finite diffs, each peak is at
x[idx0[i]]
)pos0 (refined x-positions of peaks if x given, else None)
Examples
>>> from pwtools.signal import gauss, find_peaks >>> from pwtools import num >>> x=linspace(0,10,300); y=0.2*gauss(x-0.5,.1) + gauss(x-2,.1) + 0.7*gauss(x-3,0.1) + gauss(x-6,1) >>> # ymin=0.4: ignore first peak at x=0.5 >>> find_peaks(y,x, ymin=0.4) ([60, 90, 179], [2.000231296097065, 3.0007122565950572, 5.999998055132549]) >>> idx0, pos0=find_peaks(y,x, ymin=0.4) >>> spl=num.Spline(x,y) >>> plot(x,y) >>> for x0 in pos0: ... plot([x0], [spl(x0)], 'ro')