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.
find_spikes(
x,
x.is.delta = FALSE,
z.threshold = 9,
max.spike.width = 8,
na.rm = FALSE
)
A logical vector of the same length as x
. Values that are TRUE
correspond to local spikes in the data.
numeric vector containing spectral data.
logical Flag indicating if x contains already differences.
numeric Modified Z values larger than z.threshold
are considered to be spikes.
integer Wider regions with high Z values are not detected as spikes.
logical indicating whether NA
values should be stripped
before searching for spikes.
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.
Whitaker, D. A.; Hayes, K. (2018) A simple algorithm for despiking Raman spectra. Chemometrics and Intelligent Laboratory Systems, 179, 82-84.
Other peaks and valleys functions:
find_peaks()
,
get_peaks()
,
peaks()
,
replace_bad_pixs()
,
spikes()
,
valleys()
,
wls_at_target()
with(white_led.raw_spct,
which(find_spikes(counts_3, z.threshold = 30)))
Run the code above in your browser using DataLab