findpeaks_knn | R Documentation |
Find peaks in a signal based on its local maxima, as determined by K-nearest neighbors.
# Find peaks with KNN
findpeaks_knn(x, index, k = 5L,
snr = NULL, noise = "quant", relheight = 0.005,
arr.ind = is.array(x), useNames = TRUE, ...)
# Local maxima
knnmax(x, index, k = 5L)
# Local minima
knnmin(x, index, k = 5L)
x |
A numeric vector or array. |
index |
A matrix or list of domain vectors giving the sampling locations of |
k |
The number of nearest neighbors to consider when determining whether a sample is a local extremum. |
snr |
The minimum signal-to-noise ratio used for filtering the peaks. |
noise |
The method used to estimate the noise. See Details. |
relheight |
The minimum relative height (proportion of the maximum peak value) used for filtering the peaks. |
arr.ind |
Should array indices be returned? Otherwise, return linear indices. |
useNames |
Passed to |
... |
Arguments passed to the noise estimation function. |
For knnmax()
and knnmin()
, a local extremum is defined as an element greater (or less) than all of its nearest neighbors with a lesser index, and greater (or less) than or equal to all of its nearest neighbors with a greater or equal index. That is, ties are resolved such that the sample with the lowest index is considered the local extremum.
For findpeaks_knn()
, the peaks are simply the local maxima of the signal. The peaks are optionally filtered based on their relative heights.
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 knnmax()
and knnmin()
, an logical vector or array indicating whether each element is a local extremum.
For findpeaks_knn()
, an integer vector (or matrix if arr.ind=TRUE
) giving the indices of the peaks.
Kylie A. Bemis
findpeaks
,
estnoise_quant
,
estnoise_sd
,
estnoise_mad
,
estnoise_diff
,
estnoise_filt
# simple 2D signal
x <- c(
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0,
0, 0, 0, 2, 0, 0, 1, 4, 2, 0, 1, 1, 0, 0, 0,
0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 3, 2, 1, 0, 0,
0, 0, 0, 0, 1, 3, 3, 0, 0, 1, 4, 4, 3, 1, 0,
0, 0, 0, 0, 0, 3, 2, 0, 1, 0, 3, 2, 3, 0, 0,
0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 2, 2, 3, 0, 0)
x <- matrix(x, nrow=7, ncol=15, byrow=TRUE)
# find peaks in 2D using KNN
findpeaks_knn(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.