findpeaks_knn: Peak Detection using K-nearest neighbors

View source: R/signal2.R

findpeaks_knnR Documentation

Peak Detection using K-nearest neighbors

Description

Find peaks in a signal based on its local maxima, as determined by K-nearest neighbors.

Usage

# 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)

Arguments

x

A numeric vector or array.

index

A matrix or list of domain vectors giving the sampling locations of x if it is a multidimensional signal. May be omitted if x is an array.

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 arrayInd.

...

Arguments passed to the noise estimation function.

Details

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.

Value

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.

Author(s)

Kylie A. Bemis

See Also

findpeaks, estnoise_quant, estnoise_sd, estnoise_mad, estnoise_diff, estnoise_filt

Examples

# 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)

kuwisdelu/matter documentation built on Dec. 8, 2024, 8:09 p.m.