find_spikes: Find spikes

View source: R/spct.spikes.R

find_spikesR Documentation

Find spikes

Description

This function finds spikes in a numeric vector using the algorithm of Whitaker and Hayes (2018). Spikes are values in spectra that are unusually high or low compared to neighbors. They are usually individual values or very short runs of similar "unusual" values. Spikes caused by cosmic radiation are a frequent problem in Raman spectra. Another source of spikes are "hot pixels" in CCD and diode arrays. Other kinds of accidental "outlayers" will be also detected.

Usage

find_spikes(
  x,
  x.is.delta = FALSE,
  z.threshold = 9,
  max.spike.width = 8,
  na.rm = FALSE
)

Arguments

x

numeric vector containing spectral data.

x.is.delta

logical Flag indicating if x contains already differences.

z.threshold

numeric Modified Z values larger than z.threshold are considered to be spikes.

max.spike.width

integer Wider regions with high Z values are not detected as spikes.

na.rm

logical indicating whether NA values should be stripped before searching for spikes.

Details

Spikes are detected based on a modified Z score calculated from the differenced spectrum. The Z threshold used should be adjusted to the characteristics of the input and desired sensitivity. The lower the threshold the more stringent the test becomes, resulting in most cases in more spikes being detected. A modified version of the algorithm is used if a value different from NULL is passed as argument to max.spike.width. In such a case, an additional step filters out broader spikes (or falsely detected steep slopes) from the returned values.

Value

A logical vector of the same length as x. Values that are TRUE correspond to local spikes in the data.

References

Whitaker, D. A.; Hayes, K. (2018) A simple algorithm for despiking Raman spectra. Chemometrics and Intelligent Laboratory Systems, 179, 82-84.

See Also

Other peaks and valleys functions: find_peaks(), get_peaks(), peaks(), replace_bad_pixs(), spikes(), valleys(), wls_at_target()

Examples


with(white_led.raw_spct,
     which(find_spikes(counts_3, z.threshold = 30)))


photobiology documentation built on Oct. 21, 2023, 1:06 a.m.