findpeaks | R Documentation |
Find peaks in a signal based on its local maxima, as determined by a sliding window.
# Find peaks
findpeaks(x, width = 5L, prominence = NULL,
snr = NULL, noise = "quant", bounds = TRUE,
relheight = 0.005, ...)
# Local maxima
locmax(x, width = 5L)
# Local minima
locmin(x, width = 5L)
x |
A numeric vector. |
width |
The number of signal elements to consider when determining if the center of the sliding window is a local extremum. |
prominence |
The minimum peak prominence used for filtering the peaks. The prominence of a peak is the height that the peak rises above the higher of its bases (i.e., its lowest contour line). A peak's bases are found as the local minima between the peak and the next higher peaks on either side. |
snr |
The minimum signal-to-noise ratio used for filtering the peaks. |
noise |
The method used to estimate the noise. See Details. |
bounds |
Whether the boundaries of each peak should be calculated and returned. A peak's boundaries are found as the nearest local minima on either side. |
relheight |
The minimum relative height (proportion of the maximum peak value) used for filtering the peaks. |
... |
Arguments passed to the noise estimation function. |
For locmax()
and locmin()
, a local extremum is defined as an element greater (or less) than all of the elements within width / 2
elements to the left of it, and greater (or less) than or equal to all of the elements within width / 2
elements to the right of it. That is, ties are resolved such that only the leftmost sample is considered the local extremum.
For findpeaks()
, the peaks are simply the local maxima of the signal. The peak boundaries are found by descending a local maximum until a local minimum is found on either side, using the same criteria as above. The peaks are optionally filtered based on their prominences.
Optionally, the signal-to-noise ratio (SNR) can be estimated and used for filtering the peaks. These use the functions estnoise_quant
, estnoise_diff
, estnoise_filt
, etc., to estimate the noise in the signal.
For locmax()
and locmin()
, an logical vector indicating whether each element is a local extremum.
For findpeaks()
, an integer vector giving the indices of the peaks, with attributes 'left_bounds' and 'right_bounds' giving the left and right boundaries of the peak as determined using the rule above.
Kylie A. Bemis
findpeaks_cwt
,
findpeaks_knn
,
estnoise_quant
,
estnoise_sd
,
estnoise_mad
,
estnoise_diff
,
estnoise_filt
,
peakwidths
,
peakareas
,
peakheights
,
binpeaks
,
mergepeaks
# simple signal
x <- c(0, 1, 1, 2, 3, 2, 1, 4, 5, 1, 1, 0)
locmax(x)
findpeaks(x)
# simulated spectrum
set.seed(1)
x <- simspec(size=5000)
# find peaks with snr >= 3
p <- findpeaks(x, snr=3, noise="quant")
plot(x, type="l")
points(p, x[p], col="red")
# find peaks with derivative-based noise
p <- findpeaks(x, snr=3, noise="diff")
plot(x, type="l")
points(p, x[p], col="red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.