Learn R Programming

soundgen (version 2.7.2)

findPeaks: Find peaks

Description

A bare-bones, very fast function to find local maxima (peaks) in a numeric vector.

Usage

findPeaks(x, wl = 3, thres = NULL)

Value

Returns a vector with indices of local maxima

Arguments

x

numeric vector

wl

rolling window over which we look for maxima: central value ± floor(wl/2), eg ±1 if wl=3

thres

required absolute value of each peak

See Also

findInflections

Examples

Run this code
x = rnorm(100)
findPeaks(x, wl = 3)
findPeaks(x, wl = 3, thres = 1)
findPeaks(x, wl = 5)
idx = findPeaks(x, wl = 5, thres = 1)
plot(x, type = 'b'); abline(h = 1, lty = 3)
points(idx, x[idx], col = 'blue', pch = 8)

Run the code above in your browser using DataLab