Learn R Programming

alkahest (version 1.3.0)

peaks_find: Find Peaks

Description

Finds local maxima in sequential data.

Usage

peaks_find(x, y, ...)

# S4 method for numeric,numeric peaks_find(x, y, method = "MAD", SNR = 2, m = NULL, ...)

# S4 method for ANY,missing peaks_find(x, method = "MAD", SNR = 2, m = NULL, ...)

Value

Returns a list with two components x and y.

Arguments

x, y

A numeric vector. If y is missing, an attempt is made to interpret x in a suitable way (see grDevices::xy.coords()).

...

Extra parameters to be passed to internal methods.

method

A character string specifying the method to be used for background noise estimation (see below).

SNR

An integer giving the signal-to-noise-ratio for peak detection (see below).

m

An odd integer giving the window size (i.e. the number of adjacent points to be used). If NULL, 5% of the data points is used as the half window size.

Author

N. Frerebeau

Details

A local maximum has to be the highest one in the given window and has to be higher than \(SNR \times noise\) to be recognized as peak.

The following methods are available for noise estimation:

MAD

Median Absolute Deviation.

Note that to improve peak detection, it may be helpful to smooth the data and remove the baseline beforehand.

See Also

Other peaks detection methods: peaks_fwhm()

Examples

Run this code
## X-ray diffraction
data("XRD")

## 4S Peak Filling baseline
baseline <- baseline_peakfilling(XRD, n = 10, m = 5, by = 10, sparse = TRUE)

plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
lines(baseline, type = "l", col = "red")

## Correct baseline
XRD <- signal_drift(XRD, lag = baseline, subtract = TRUE)

## Find peaks
peaks <- peaks_find(XRD, SNR = 3, m = 11)

plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
lines(peaks, type = "p", pch = 16, col = "red")
abline(h = attr(peaks, "noise"), lty = 2) # noise threshold

## Half-Width at Half-Maximum
x <- seq(-4, 4, length = 1000)
y <- dnorm(x)

peaks_fwhm(x, y, center = 0) # Expected: 2 * sqrt(2 * log(2))

Run the code above in your browser using DataLab