Title: | Pre-Processing XY Data from Experimental Methods |
Version: | 1.3.0 |
Maintainer: | Nicolas Frerebeau <nicolas.frerebeau@u-bordeaux-montaigne.fr> |
Description: | A lightweight, dependency-free toolbox for pre-processing XY data from experimental methods (i.e. any signal that can be measured along a continuous variable). This package provides methods for baseline estimation and correction, smoothing, normalization, integration and peaks detection. Baseline correction methods includes polynomial fitting as described in Lieber and Mahadevan-Jansen (2003) <doi:10.1366/000370203322554518>, Rolling Ball algorithm after Kneen and Annegarn (1996) <doi:10.1016/0168-583X(95)00908-6>, SNIP algorithm after Ryan et al. (1988) <doi:10.1016/0168-583X(88)90063-8>, 4S Peak Filling after Liland (2015) <doi:10.1016/j.mex.2015.02.009> and more. |
License: | GPL (≥ 3) |
URL: | https://codeberg.org/tesselle/alkahest, https://packages.tesselle.org/alkahest/ |
BugReports: | https://codeberg.org/tesselle/alkahest/issues |
Depends: | R (≥ 3.5.0) |
Imports: | grDevices, methods, stats, utils |
Suggests: | knitr, markdown, Matrix, tinytest |
VignetteBuilder: | knitr |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
X-schema.org-isPartOf: | https://www.tesselle.org |
X-schema.org-keywords: | spectroscopy, archaeometry, r-package |
Collate: | 'AllGenerics.R' 'alkahest-internal.R' 'alkahest-package.R' 'baseline.R' 'data.R' 'integrate.R' 'peaks.R' 'replace.R' 'resample.R' 'rescale.R' 'signal.R' 'smooth.R' 'windows.R' 'xrd.R' |
NeedsCompilation: | no |
Packaged: | 2025-02-25 21:35:08 UTC; nicolas |
Author: | Nicolas Frerebeau |
Repository: | CRAN |
Date/Publication: | 2025-02-25 22:00:02 UTC |
alkahest: Pre-Processing XY Data from Experimental Methods
Description
A lightweight, dependency-free toolbox for pre-processing XY data from experimental methods (i.e. any signal that can be measured along a continuous variable). This package provides methods for baseline estimation and correction, smoothing, normalization, integration and peaks detection. Baseline correction methods includes polynomial fitting as described in Lieber and Mahadevan-Jansen (2003) doi:10.1366/000370203322554518, Rolling Ball algorithm after Kneen and Annegarn (1996) doi:10.1016/0168-583X(95)00908-6, SNIP algorithm after Ryan et al. (1988) doi:10.1016/0168-583X(88)90063-8, 4S Peak Filling after Liland (2015) doi:10.1016/j.mex.2015.02.009 and more.
Details
Package: | alkahest |
Type: | Package |
Version: | 1.3.0 |
License: | GPL-3 |
Zenodo: | doi:10.5281/zenodo.7081524 |
Author(s)
Full list of authors and contributors (alphabetic order)
Nicolas Frerebeau | Université Bordeaux Montaigne, France |
Brice Lebrun | Université Bordeaux Montaigne, France |
Package maintainer
Nicolas Frerebeau
nicolas.frerebeau@u-bordeaux-montaigne.fr
Archéosciences Bordeaux (UMR 6034)
Maison de l'Archéologie
Université Bordeaux Montaigne
33607 Pessac cedex
France
See Also
Useful links:
Report bugs at https://codeberg.org/tesselle/alkahest/issues
Gamma-Ray Spectrometry
Description
Gamma-Ray Spectrometry
Usage
BEGe
Format
A data.frame
with 8192 rows (channels) and 2 variables.
- energy
(keV)
- count
See Also
Other datasets:
LaBr
,
Raman
,
XRD
Examples
data("BEGe")
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
Gamma-Ray Spectrometry
Description
Gamma-Ray Spectrometry
Usage
LaBr
Format
A data.frame
with 1024 rows (channels) and 2 variables.
- energy
(keV)
- count
See Also
Other datasets:
BEGe
,
Raman
,
XRD
Examples
data("LaBr")
plot(LaBr, type = "l", xlab = "Energy (keV)", ylab = "Count")
Raman Spectroscopy
Description
Raman Spectroscopy
Usage
Raman
Format
A data.frame
with 1182 rows and 2 variables.
- shift
Raman shift.
- intensity
See Also
Other datasets:
BEGe
,
LaBr
,
XRD
Examples
data("Raman")
plot(Raman, type = "l", xlab = "Shift", ylab = "Intensity")
Powder X-ray Diffraction
Description
Powder X-ray Diffraction
Usage
XRD
Format
A data.frame
with 2989 rows and 2 variables.
- theta
- count
See Also
Other datasets:
BEGe
,
LaBr
,
Raman
Examples
data("XRD")
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
Asymmetric Least Squares Smoothing
Description
Baseline estimation with asymmetric least squares smoothing.
Usage
baseline_asls(x, y, ...)
## S4 method for signature 'numeric,numeric'
baseline_asls(x, y, p = 0.01, lambda = 10^4, stop = 100)
## S4 method for signature 'ANY,missing'
baseline_asls(x, p = 0.01, lambda = 10^4, stop = 100)
Arguments
x , y |
A |
... |
Currently not used. |
p |
A length-one |
lambda |
A length-one |
stop |
An |
Value
Returns a list
with two components x
and y
.
Author(s)
P. H. C. Eilers and H. F. M. Boelens (original Matlab code)
References
Eilers, P. H. C. & Boelens, H. F. M. (2005). Baseline Correction with Asymmetric Least Squares Smoothing.
See Also
Other baseline estimation methods:
baseline_linear()
,
baseline_peakfilling()
,
baseline_polynomial()
,
baseline_rollingball()
,
baseline_rubberband()
,
baseline_snip()
Examples
## X-ray diffraction
data("XRD")
## Subset from 20 to 70 degrees
XRD <- signal_select(XRD, from = 20, to = 70)
## Plot spectrum
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
## Polynomial baseline
baseline <- baseline_asls(XRD, p = 0.005, lambda = 10^7)
lines(baseline, type = "l", col = "red")
Linear Baseline Estimation
Description
Linear Baseline Estimation
Usage
baseline_linear(x, y, ...)
## S4 method for signature 'numeric,numeric'
baseline_linear(x, y, points = range(x))
## S4 method for signature 'ANY,missing'
baseline_linear(x, points = range(x))
Arguments
x , y |
A |
... |
Currently not used. |
points |
A |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other baseline estimation methods:
baseline_asls()
,
baseline_peakfilling()
,
baseline_polynomial()
,
baseline_rollingball()
,
baseline_rubberband()
,
baseline_snip()
Examples
## X-ray diffraction
data("XRD")
## Plot spectrum
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
## Linear baseline
baseline <- baseline_linear(XRD, points = c(25, 34))
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
lines(baseline, type = "l", col = "red")
## Correct baseline
XRD$count <- XRD$count - baseline$y
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
4S Peak Filling
Description
Baseline estimation by iterative mean suppression.
Usage
baseline_peakfilling(x, y, ...)
## S4 method for signature 'numeric,numeric'
baseline_peakfilling(x, y, n, m, by = 10, lambda = 1600, d = 2, sparse = FALSE)
## S4 method for signature 'ANY,missing'
baseline_peakfilling(x, n, m, by = 10, lambda = 1600, d = 2, sparse = FALSE)
Arguments
x , y |
A |
... |
Currently not used. |
n |
An |
m |
An odd |
by |
A length-one |
lambda |
An |
d |
An |
sparse |
A |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
References
Liland, K. H. (2015). 4S Peak Filling - baseline estimation by iterative mean suppression. MethodsX, 2, 135-140. doi:10.1016/j.mex.2015.02.009.
See Also
signal_correct()
, smooth_whittaker()
Other baseline estimation methods:
baseline_asls()
,
baseline_linear()
,
baseline_polynomial()
,
baseline_rollingball()
,
baseline_rubberband()
,
baseline_snip()
Examples
## 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")
Polynomial Baseline Estimation
Description
Polynomial Baseline Estimation
Usage
baseline_polynomial(x, y, ...)
## S4 method for signature 'numeric,numeric'
baseline_polynomial(x, y, d = 3, tolerance = 0.001, stop = 100)
## S4 method for signature 'ANY,missing'
baseline_polynomial(x, d = 3, tolerance = 0.001, stop = 100)
Arguments
x , y |
A |
... |
Currently not used. |
d |
An |
tolerance |
A |
stop |
An |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
References
Lieber, C. A. and Mahadevan-Jansen, A. (2003). Automated Method for Subtraction of Fluorescence from Biological Raman Spectra. Applied Spectroscopy, 57(11): 1363-67. doi:10.1366/000370203322554518.
See Also
Other baseline estimation methods:
baseline_asls()
,
baseline_linear()
,
baseline_peakfilling()
,
baseline_rollingball()
,
baseline_rubberband()
,
baseline_snip()
Examples
## X-ray diffraction
data("XRD")
## Subset from 20 to 70 degrees
XRD <- signal_select(XRD, from = 20, to = 70)
## Plot spectrum
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
## Polynomial baseline
baseline <- baseline_polynomial(XRD, d = 4, tolerance = 0.02, stop = 1000)
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
lines(baseline, type = "l", col = "red")
Rolling Ball Baseline Estimation
Description
Rolling Ball Baseline Estimation
Usage
baseline_rollingball(x, y, ...)
## S4 method for signature 'numeric,numeric'
baseline_rollingball(x, y, m, s)
## S4 method for signature 'ANY,missing'
baseline_rollingball(x, m, s)
Arguments
x , y |
A |
... |
Currently not used. |
m |
An odd |
s |
An odd |
Value
Returns a list
with two components x
and y
.
Note
There will be (m - 1) / 2
points both at the beginning and at the end
of the data series for which a complete m
-width window cannot be
obtained. To prevent data loss, progressively wider/narrower windows are
used at both ends of the data series.
Author(s)
N. Frerebeau
References
Kneen, M. A. and Annegarn, H. J. (1996). Algorithm for Fitting XRF, SEM and PIXE X-Ray Spectra Backgrounds. Nuclear Instruments and Methods in Physics Research Section B: Beam Interactions with Materials and Atoms, 109/110: 209-213. doi:10.1016/0168-583X(95)00908-6.
See Also
Other baseline estimation methods:
baseline_asls()
,
baseline_linear()
,
baseline_peakfilling()
,
baseline_polynomial()
,
baseline_rubberband()
,
baseline_snip()
Examples
## X-ray diffraction
data("XRD")
## Subset from 20 to 70 degrees
XRD <- signal_select(XRD, from = 20, to = 70)
## Plot spectrum
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
## Rolling Ball baseline
baseline <- baseline_rollingball(XRD, m = 201, s = 151)
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
lines(baseline, type = "l", col = "red")
Rubberband Baseline Estimation
Description
Rubberband Baseline Estimation
Usage
baseline_rubberband(x, y, ...)
## S4 method for signature 'numeric,numeric'
baseline_rubberband(x, y, noise = 0, spline = TRUE, ...)
## S4 method for signature 'ANY,missing'
baseline_rubberband(x, noise = 0, spline = TRUE, ...)
Arguments
x , y |
A |
... |
Extra arguments to be passed to |
noise |
A length-one |
spline |
A |
Details
A convex envelope of the spectrum is determined and the baseline is estimated as the part of the convex envelope lying below the spectrum. Note that the rubber band does not enter the concave regions (if any) of the spectrum.
Value
Returns a list
with two components x
and y
.
Note
baseline_rubberband()
is slightly modified from C. Beleites'
hyperSpec::spc.rubberband()
.
Author(s)
N. Frerebeau
See Also
Other baseline estimation methods:
baseline_asls()
,
baseline_linear()
,
baseline_peakfilling()
,
baseline_polynomial()
,
baseline_rollingball()
,
baseline_snip()
Examples
## gamma-ray spectrometry
data("BEGe")
## Subset from 2.75 to 200 keV
BEGe <- signal_select(BEGe, from = 3, to = 200)
## Plot spectrum
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
## Rubberband baseline
baseline <- baseline_rubberband(BEGe)
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
lines(baseline, type = "l", col = "red")
SNIP Baseline Estimation
Description
Sensitive Nonlinear Iterative Peak clipping algorithm.
Usage
baseline_snip(x, y, ...)
## S4 method for signature 'numeric,numeric'
baseline_snip(x, y, LLS = FALSE, decreasing = FALSE, n = 100)
## S4 method for signature 'ANY,missing'
baseline_snip(x, LLS = FALSE, decreasing = FALSE, n = 100)
Arguments
x , y |
A |
... |
Currently not used. |
LLS |
A |
decreasing |
A |
n |
An |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
References
Morháč, M., Kliman, J., Matoušek, V., Veselský, M. & Turzo, I. (1997). Background elimination methods for multidimensional gamma-ray spectra. Nuclear Instruments and Methods in Physics Research Section A: Accelerators, Spectrometers, Detectors and Associated Equipment, 401(1), p. 113-132. doi:10.1016/S0168-9002(97)01023-1
Morháč, M. & Matoušek, V. (2008). Peak Clipping Algorithms for Background Estimation in Spectroscopic Data. Applied Spectroscopy, 62(1), p. 91-106. doi:10.1366/000370208783412762
Ryan, C. G., Clayton, E., Griffin, W. L., Sie, S. H. & Cousens, D. R. (1988). SNIP, a statistics-sensitive background treatment for the quantitative analysis of PIXE spectra in geoscience applications. Nuclear Instruments and Methods in Physics Research Section B: Beam Interactions with Materials and Atoms, 34(3), p. 396-402. doi:10.1016/0168-583X(88)90063-8
See Also
Other baseline estimation methods:
baseline_asls()
,
baseline_linear()
,
baseline_peakfilling()
,
baseline_polynomial()
,
baseline_rollingball()
,
baseline_rubberband()
Examples
## gamma-ray spectrometry
data("BEGe")
## Subset from 2.75 to 200 keV
BEGe <- signal_select(BEGe, from = 3, to = 200)
## Plot spectrum
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
## SNIP baseline
baseline <- baseline_snip(BEGe, LLS = FALSE, decreasing = FALSE, n = 100)
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
lines(baseline, type = "l", col = "red")
Rectangle Rule
Description
Approximates the definite integral by using the rectangle rule.
Usage
integrate_rectangle(x, y, ...)
## S4 method for signature 'numeric,numeric'
integrate_rectangle(x, y, right = FALSE)
## S4 method for signature 'ANY,missing'
integrate_rectangle(x, right = FALSE)
Arguments
x , y |
A |
... |
Currently not used. |
right |
A |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other integration methods:
integrate_trapezoid()
Examples
## Calculate the area under the sine curve from 0 to pi
# integrate(f = function(x) x^3, lower = 0, upper = 2)
x <- seq(0, 2, len = 101)
y <- x^3
plot(x, y, type = "l")
integrate_rectangle(x, y, right = FALSE) # 3.9204
integrate_rectangle(x, y, right = TRUE) # 4.0804
integrate_trapezoid(x, y) # 4.0004
Trapezoidal Rule
Description
Approximates the definite integral by using the trapezoidal rule.
Usage
integrate_trapezoid(x, y, ...)
## S4 method for signature 'numeric,numeric'
integrate_trapezoid(x, y)
## S4 method for signature 'ANY,missing'
integrate_trapezoid(x)
Arguments
x , y |
A |
... |
Currently not used. |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other integration methods:
integrate_rectangle()
Examples
## Calculate the area under the sine curve from 0 to pi
# integrate(f = function(x) x^3, lower = 0, upper = 2)
x <- seq(0, 2, len = 101)
y <- x^3
plot(x, y, type = "l")
integrate_rectangle(x, y, right = FALSE) # 3.9204
integrate_rectangle(x, y, right = TRUE) # 4.0804
integrate_trapezoid(x, y) # 4.0004
Strip XRD ka2
Description
Strip XRD ka2
Usage
ka2_strip_penalized(x, y, ...)
## S4 method for signature 'numeric,numeric'
ka2_strip_penalized(
x,
y,
lambda,
wave = c(1.5406, 1.54443),
tau = 0.5,
nseg = 1,
progress = interactive()
)
## S4 method for signature 'ANY,missing'
ka2_strip_penalized(
x,
lambda,
wave = c(1.5406, 1.54443),
tau = 0.5,
nseg = 1,
progress = interactive()
)
Arguments
x , y |
A |
... |
Currently not used. |
lambda |
An |
wave |
A length-two |
tau |
A length-one |
nseg |
A length-one |
progress |
A |
Value
Returns a list
with two components x
and y
.
Note
Matrix is required.
Author(s)
J. J. de Rooi et al. (original R code).
References
de Rooi, J. J., van der Pers, N. M., Hendrikx, R. W. A., Delhez, R., Böttger A. J. and Eilers, P. H. C. (2014). Smoothing of X-ray diffraction data and Ka2 elimination using penalized likelihood and the composite link model. Journal of Applied Crystallography, 47: 852-860. doi:10.1107/S1600576714005809
Examples
## Not run:
## X-ray diffraction
data("XRD")
## Subset from 20 to 40 degrees
XRD <- signal_select(XRD, from = 20, to = 40)
## Plot diffractogram
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
## Penalized likelihood smoothing
lambda <- seq(from = 1, to = 8, length.out = 40)
lambda <- 10^lambda
likelihood <- smooth_likelihood(XRD, lambda = lambda, d = 3)
lines(likelihood, col = "red")
## Strip ka2
ka2 <- ka2_strip_penalized(XRD, lambda = lambda, tau = 0.5, nseg = 1)
lines(ka2, col = "blue")
## End(Not run)
Find Peaks
Description
Finds local maxima in sequential data.
Usage
peaks_find(x, y, ...)
## S4 method for signature 'numeric,numeric'
peaks_find(x, y, method = "MAD", SNR = 2, m = NULL, ...)
## S4 method for signature 'ANY,missing'
peaks_find(x, method = "MAD", SNR = 2, m = NULL, ...)
Arguments
x , y |
A |
... |
Extra parameters to be passed to internal methods. |
method |
A |
SNR |
An |
m |
An odd |
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.
Value
Returns a list
with two components x
and y
.
Note
There will be (m - 1) / 2
points both at the beginning and at the end
of the data series for which a complete m
-width window cannot be
obtained. To prevent data loss, progressively wider/narrower windows are
used at both ends of the data series.
Adapted from Stasia Grinberg's
findPeaks
function.
Author(s)
N. Frerebeau
See Also
Other peaks detection methods:
peaks_fwhm()
Examples
## 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))
Half-Width at Half-Maximum
Description
Estimates the Half-Width at Half-Maximum (FWHM) for a given peak.
Usage
peaks_fwhm(x, y, ...)
## S4 method for signature 'numeric,numeric'
peaks_fwhm(x, y, center)
## S4 method for signature 'ANY,missing'
peaks_fwhm(x, center)
Arguments
x , y |
A |
... |
Currently not used. |
center |
A |
Details
It tries to get the smallest possible estimate.
Value
A numeric
value.
Author(s)
N. Frerebeau
See Also
Other peaks detection methods:
peaks_find()
Examples
## 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))
Replace Negative Values
Description
Replace Negative Values
Usage
replace_negative(x, y, ...)
## S4 method for signature 'numeric,numeric'
replace_negative(x, y, value = 0)
## S4 method for signature 'ANY,missing'
replace_negative(x, value = 0)
Arguments
x , y |
A |
... |
Extra parameters to be passed to |
value |
A |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other replacement methods:
replace_threshold()
Replace Values Below a Given Threshold
Description
Replace Values Below a Given Threshold
Usage
replace_threshold(x, y, threshold, ...)
## S4 method for signature 'numeric,numeric,function'
replace_threshold(x, y, threshold, value = 0, ...)
## S4 method for signature 'ANY,missing,function'
replace_threshold(x, threshold, value = 0, ...)
## S4 method for signature 'numeric,numeric,numeric'
replace_threshold(x, y, threshold, value = 0, ...)
## S4 method for signature 'ANY,missing,numeric'
replace_threshold(x, threshold, value = 0, ...)
Arguments
x , y |
A |
threshold |
A |
... |
Extra parameters to be passed to |
value |
A |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other replacement methods:
replace_negative()
Bin
Description
Averages x
values and applies a function to the corresponding y
values.
Usage
resample_bin(x, y, ...)
## S4 method for signature 'numeric,numeric'
resample_bin(x, y, by, f = mean, ...)
## S4 method for signature 'ANY,missing'
resample_bin(x, y, by, f = sum)
Arguments
x , y |
A |
... |
Extra parameters to be passed to |
by |
An |
f |
A |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other resampling methods:
resample_down()
,
resample_interpolate()
Examples
## X-ray diffraction
data("XRD")
## Plot spectrum
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
## Bin by 3
XRD_bin_mean <- resample_bin(XRD, by = 3, f = mean)
XRD_bin_min <- resample_bin(XRD, by = 3, f = min)
plot(XRD, type = "l", xlim = c(25, 35),
xlab = expression(2*theta), ylab = "Count")
lines(XRD_bin_mean, type = "l", col = "red")
lines(XRD_bin_min, type = "l", col = "green")
## Downsample by 10
XRD_down <- resample_down(XRD, by = 10)
plot(XRD, type = "l", xlim = c(20, 40),
xlab = expression(2*theta), ylab = "Count")
lines(XRD_down, type = "l", col = "red")
## Linearly interpolate
XRD_approx <- resample_interpolate(XRD, from = 20, to = 40, by = 0.02)
plot(XRD, type = "l", xlim = c(20, 40),
xlab = expression(2*theta), ylab = "Count")
lines(XRD_approx, type = "l", col = "red")
Downsample
Description
Downsample
Usage
resample_down(x, y, ...)
## S4 method for signature 'numeric,numeric'
resample_down(x, y, by)
## S4 method for signature 'ANY,missing'
resample_down(x, y, by)
Arguments
x , y |
A |
... |
Currently not used. |
by |
An |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other resampling methods:
resample_bin()
,
resample_interpolate()
Examples
## X-ray diffraction
data("XRD")
## Plot spectrum
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
## Bin by 3
XRD_bin_mean <- resample_bin(XRD, by = 3, f = mean)
XRD_bin_min <- resample_bin(XRD, by = 3, f = min)
plot(XRD, type = "l", xlim = c(25, 35),
xlab = expression(2*theta), ylab = "Count")
lines(XRD_bin_mean, type = "l", col = "red")
lines(XRD_bin_min, type = "l", col = "green")
## Downsample by 10
XRD_down <- resample_down(XRD, by = 10)
plot(XRD, type = "l", xlim = c(20, 40),
xlab = expression(2*theta), ylab = "Count")
lines(XRD_down, type = "l", col = "red")
## Linearly interpolate
XRD_approx <- resample_interpolate(XRD, from = 20, to = 40, by = 0.02)
plot(XRD, type = "l", xlim = c(20, 40),
xlab = expression(2*theta), ylab = "Count")
lines(XRD_approx, type = "l", col = "red")
Linearly Interpolate
Description
Linearly Interpolate
Usage
resample_interpolate(x, y, ...)
## S4 method for signature 'numeric,numeric'
resample_interpolate(x, y, from, to, by, ...)
## S4 method for signature 'ANY,missing'
resample_interpolate(x, y, from, to, by, ...)
Arguments
x , y |
A |
... |
Extra arguments to be passed to |
from |
A length-one |
to |
A length-one |
by |
A length-one |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other resampling methods:
resample_bin()
,
resample_down()
Examples
## X-ray diffraction
data("XRD")
## Plot spectrum
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
## Bin by 3
XRD_bin_mean <- resample_bin(XRD, by = 3, f = mean)
XRD_bin_min <- resample_bin(XRD, by = 3, f = min)
plot(XRD, type = "l", xlim = c(25, 35),
xlab = expression(2*theta), ylab = "Count")
lines(XRD_bin_mean, type = "l", col = "red")
lines(XRD_bin_min, type = "l", col = "green")
## Downsample by 10
XRD_down <- resample_down(XRD, by = 10)
plot(XRD, type = "l", xlim = c(20, 40),
xlab = expression(2*theta), ylab = "Count")
lines(XRD_down, type = "l", col = "red")
## Linearly interpolate
XRD_approx <- resample_interpolate(XRD, from = 20, to = 40, by = 0.02)
plot(XRD, type = "l", xlim = c(20, 40),
xlab = expression(2*theta), ylab = "Count")
lines(XRD_approx, type = "l", col = "red")
Normalize intensities by AUC
Description
Rescales intensities so that the area under the curve (AUC) is equal to 1.
Usage
rescale_area(x, y, ...)
## S4 method for signature 'numeric,numeric'
rescale_area(x, y, method = c("rectangle", "trapezoid"), ...)
## S4 method for signature 'ANY,missing'
rescale_area(x, method = c("rectangle", "trapezoid"), ...)
Arguments
x , y |
A |
... |
Currently not used. |
method |
A |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other normalization methods:
rescale_range()
,
rescale_snv()
,
rescale_total()
,
rescale_transform()
Examples
## gamma-ray spectrometry
data("BEGe")
## Subset from 2.75 to 200 keV
BEGe <- signal_select(BEGe, from = 3, to = 200)
## Plot spectrum
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
## Normalize by area under the curve
BEGe_area <- rescale_area(BEGe)
plot(BEGe_area, type = "l", xlab = "Energy (keV)", ylab = "Count")
integrate_rectangle(BEGe)
integrate_rectangle(BEGe_area)
## Rescale so that intensities sum to 1
BEGe_total <- rescale_total(BEGe, total = 1)
plot(BEGe_total, type = "l", xlab = "Energy (keV)", ylab = "Count")
## Rescale intensities to 0-1
BEGe_range <- rescale_range(BEGe, min = 0, max = 1)
plot(BEGe_range, type = "l", xlab = "Energy (keV)", ylab = "Count")
Rescales intensities to have specified minimum and maximum
Description
Rescales intensities to have specified minimum and maximum.
Usage
rescale_range(x, y, ...)
rescale_min(x, y, ...)
rescale_max(x, y, ...)
## S4 method for signature 'numeric,numeric'
rescale_range(x, y, min = 0, max = 1)
## S4 method for signature 'ANY,missing'
rescale_range(x, min = 0, max = 1)
## S4 method for signature 'numeric,numeric'
rescale_min(x, y, min = 0)
## S4 method for signature 'ANY,missing'
rescale_min(x, min = 0)
## S4 method for signature 'numeric,numeric'
rescale_max(x, y, max = 1)
## S4 method for signature 'ANY,missing'
rescale_max(x, max = 1)
Arguments
x , y |
A |
... |
Currently not used. |
min |
A legnth-one |
max |
A legnth-one |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other normalization methods:
rescale_area()
,
rescale_snv()
,
rescale_total()
,
rescale_transform()
Examples
## gamma-ray spectrometry
data("BEGe")
## Subset from 2.75 to 200 keV
BEGe <- signal_select(BEGe, from = 3, to = 200)
## Plot spectrum
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
## Normalize by area under the curve
BEGe_area <- rescale_area(BEGe)
plot(BEGe_area, type = "l", xlab = "Energy (keV)", ylab = "Count")
integrate_rectangle(BEGe)
integrate_rectangle(BEGe_area)
## Rescale so that intensities sum to 1
BEGe_total <- rescale_total(BEGe, total = 1)
plot(BEGe_total, type = "l", xlab = "Energy (keV)", ylab = "Count")
## Rescale intensities to 0-1
BEGe_range <- rescale_range(BEGe, min = 0, max = 1)
plot(BEGe_range, type = "l", xlab = "Energy (keV)", ylab = "Count")
Standard Normal Variate (SNV) Transformation
Description
Subtracts the mean and scales to unit variance.
Usage
rescale_snv(x, y, ...)
## S4 method for signature 'numeric,numeric'
rescale_snv(x, y, ...)
## S4 method for signature 'ANY,missing'
rescale_snv(x, y, ...)
Arguments
x , y |
A |
... |
Currently not used. |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
References
Barnes, R. J., Dhanoa, M. S. & Lister, S. J. (1989). Standard Normal Variate Transformation and De-Trending of Near-Infrared Diffuse Reflectance Spectra. Applied Spectroscopy, 43(5): 772-777. doi:10.1366/0003702894202201.
See Also
Other normalization methods:
rescale_area()
,
rescale_range()
,
rescale_total()
,
rescale_transform()
Examples
## Raman spectrometry
data("Raman")
## Subset from 200 to 800 1/cm
Raman <- signal_select(Raman, from = 200, to = 800)
## Plot spectrum
plot(Raman, type = "l", xlab = "Raman shift", ylab = "Intensity")
## Normalize SNV
Raman_snv <- rescale_snv(Raman)
plot(Raman_snv, type = "l", xlab = "Raman shift", ylab = "Intensity")
Rescale intensities to sum to a specified value
Description
Rescales intensities to sum to a specified value.
Usage
rescale_total(x, y, ...)
## S4 method for signature 'numeric,numeric'
rescale_total(x, y, total = 1)
## S4 method for signature 'ANY,missing'
rescale_total(x, total = 1)
Arguments
x , y |
A |
... |
Currently not used. |
total |
A legnth-one |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other normalization methods:
rescale_area()
,
rescale_range()
,
rescale_snv()
,
rescale_transform()
Examples
## gamma-ray spectrometry
data("BEGe")
## Subset from 2.75 to 200 keV
BEGe <- signal_select(BEGe, from = 3, to = 200)
## Plot spectrum
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
## Normalize by area under the curve
BEGe_area <- rescale_area(BEGe)
plot(BEGe_area, type = "l", xlab = "Energy (keV)", ylab = "Count")
integrate_rectangle(BEGe)
integrate_rectangle(BEGe_area)
## Rescale so that intensities sum to 1
BEGe_total <- rescale_total(BEGe, total = 1)
plot(BEGe_total, type = "l", xlab = "Energy (keV)", ylab = "Count")
## Rescale intensities to 0-1
BEGe_range <- rescale_range(BEGe, min = 0, max = 1)
plot(BEGe_range, type = "l", xlab = "Energy (keV)", ylab = "Count")
Transform Intensities
Description
Transform Intensities
Usage
rescale_transform(x, y, ...)
## S4 method for signature 'numeric,numeric'
rescale_transform(x, y, f, ...)
## S4 method for signature 'ANY,missing'
rescale_transform(x, f, ...)
Arguments
x , y |
A |
... |
Extra arguments to be passed to |
f |
A |
Details
Transformation of intensities can be used to improve the identification of peaks with a low signal-to-noise ratio.
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other normalization methods:
rescale_area()
,
rescale_range()
,
rescale_snv()
,
rescale_total()
Examples
## gamma-ray spectrometry
data("BEGe")
## Subset from 2.75 to 200 keV
BEGe <- signal_select(BEGe, from = 3, to = 200)
## Plot spectrum
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
## Transform intensities
BEGe_trans <- rescale_transform(BEGe, f = sqrt)
plot(BEGe_trans, type = "l", xlab = "Energy (keV)", ylab = "sqrt(Count)")
Bind
Description
Combines XY objects.
Usage
signal_bind(...)
## S4 method for signature 'ANY'
signal_bind(...)
Arguments
... |
Any object that can be interpreted in a suitable way
(see |
Value
Returns a matrix
of intensities.
Author(s)
N. Frerebeau
See Also
Other signal processing methods:
signal_correct()
,
signal_drift()
,
signal_mean()
,
signal_shift()
,
subset()
Examples
## X-ray diffraction
data("XRD")
XRD1 <- signal_drift(XRD, lag = 1500)
## Bind
XRD_bind <- signal_bind(XRD, XRD1)
XRD_bind[, 1:10]
## Mean
XRD_mean <- signal_mean(XRD, XRD1)
plot(NULL, type = "l", xlim = c(10, 70) , ylim = c(3000, 36000),
xlab = expression(2*theta), ylab = "Count")
lines(XRD, type = "l")
lines(XRD1, type = "l")
lines(XRD_mean, type = "l", col = "red")
Baseline Correction
Description
Baseline Correction
Usage
signal_correct(x, y, ...)
## S4 method for signature 'numeric,numeric'
signal_correct(
x,
y,
method = c("linear", "polynomial", "asls", "rollingball", "rubberband", "SNIP", "4S"),
...
)
## S4 method for signature 'ANY,missing'
signal_correct(
x,
method = c("linear", "polynomial", "asls", "rollingball", "rubberband", "SNIP", "4S"),
...
)
Arguments
x , y |
A |
... |
Extra arguments to be passed to |
method |
A |
Details
Available methods for baseline estimation:
asls
Asymmetric Least Squares Smoothing (see
baseline_asls()
).linear
Linear baseline estimation (see
baseline_linear()
).polynomial
Polynomial baseline estimation (see
baseline_polynomial()
).rollingball
Rolling ball baseline estimation (see
baseline_rollingball()
).rubberband
Rubberband baseline estimation (see
baseline_rubberband()
).SNIP
Sensitive Nonlinear Iterative Peak clipping algorithm (see
baseline_snip()
).4S
4S Peak Filling (see
baseline_peakfilling()
).
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other signal processing methods:
signal_bind()
,
signal_drift()
,
signal_mean()
,
signal_shift()
,
subset()
Examples
## gamma-ray spectrometry
data("BEGe")
## Subset from 2.75 to 200 keV
BEGe <- signal_select(BEGe, from = 3, to = 200)
## Drift
baseline <- baseline_snip(BEGe)
BEGe_drif <- signal_drift(BEGe, lag = baseline, subtract = TRUE)
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
lines(BEGe_drif, type = "l", col = "red")
## Correct
BEGe_corr <- signal_correct(BEGe, method = "SNIP")
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
lines(BEGe_corr, type = "l", col = "red")
Drift Intensities
Description
Drift Intensities
Usage
signal_drift(x, y, lag, ...)
## S4 method for signature 'numeric,numeric,numeric'
signal_drift(x, y, lag)
## S4 method for signature 'ANY,missing,ANY'
signal_drift(x, lag, subtract = FALSE)
Arguments
x , y |
A |
lag |
A |
... |
Currently not used. |
subtract |
A |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other signal processing methods:
signal_bind()
,
signal_correct()
,
signal_mean()
,
signal_shift()
,
subset()
Examples
## gamma-ray spectrometry
data("BEGe")
## Subset from 2.75 to 200 keV
BEGe <- signal_select(BEGe, from = 3, to = 200)
## Drift
BEGe_plus <- signal_drift(BEGe, lag = 250)
BEGe_minus <- signal_drift(BEGe, lag = 250, subtract = TRUE)
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
lines(BEGe_plus, type = "l", col = "red")
lines(BEGe_minus, type = "l", col = "green")
Mean Intensities
Description
Mean Intensities
Usage
signal_mean(...)
## S4 method for signature 'ANY'
signal_mean(...)
Arguments
... |
Any object that can be interpreted in a suitable way
(see |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other signal processing methods:
signal_bind()
,
signal_correct()
,
signal_drift()
,
signal_shift()
,
subset()
Examples
## X-ray diffraction
data("XRD")
XRD1 <- signal_drift(XRD, lag = 1500)
## Bind
XRD_bind <- signal_bind(XRD, XRD1)
XRD_bind[, 1:10]
## Mean
XRD_mean <- signal_mean(XRD, XRD1)
plot(NULL, type = "l", xlim = c(10, 70) , ylim = c(3000, 36000),
xlab = expression(2*theta), ylab = "Count")
lines(XRD, type = "l")
lines(XRD1, type = "l")
lines(XRD_mean, type = "l", col = "red")
Shift the X Scale
Description
Shifts the x
scale by a given value.
Usage
signal_shift(x, y, lag, ...)
## S4 method for signature 'numeric,numeric'
signal_shift(x, y, lag)
## S4 method for signature 'ANY,missing'
signal_shift(x, lag)
Arguments
x , y |
A |
lag |
A |
... |
Currently not used. |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other signal processing methods:
signal_bind()
,
signal_correct()
,
signal_drift()
,
signal_mean()
,
subset()
Examples
## X-ray diffraction
data("XRD")
## Plot spectrum
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
## Shift by one degree
XRD_offset <- signal_shift(XRD, lag = 1)
lines(XRD_offset, type = "l", col = "red")
Penalized Likelihood Smoothing
Description
Penalized Likelihood Smoothing
Usage
smooth_likelihood(x, y, ...)
## S4 method for signature 'numeric,numeric'
smooth_likelihood(x, y, lambda, d = 2, SE = FALSE, progress = interactive())
## S4 method for signature 'ANY,missing'
smooth_likelihood(x, lambda, d = 2, SE = FALSE, progress = interactive())
Arguments
x , y |
A |
... |
Currently not used. |
lambda |
An |
d |
An |
SE |
A |
progress |
A |
Value
Returns a list
with two components x
and y
.
Note
Matrix is required.
Author(s)
J. J. de Rooi et al. (original R code).
References
de Rooi, J. J., van der Pers, N. M., Hendrikx, R. W. A., Delhez, R., Böttger A. J. and Eilers, P. H. C. (2014). Smoothing of X-ray diffraction data and Ka2 elimination using penalized likelihood and the composite link model. Journal of Applied Crystallography, 47: 852-860. doi:10.1107/S1600576714005809
See Also
Other smoothing methods:
smooth_loess()
,
smooth_rectangular()
,
smooth_savitzky()
,
smooth_triangular()
,
smooth_whittaker()
Examples
## Not run:
## X-ray diffraction
data("XRD")
## Subset from 20 to 40 degrees
XRD <- signal_select(XRD, from = 20, to = 40)
## Plot diffractogram
plot(XRD, type = "l", xlab = expression(2*theta), ylab = "Count")
## Penalized likelihood smoothing
lambda <- seq(from = 1, to = 8, length.out = 40)
lambda <- 10^lambda
likelihood <- smooth_likelihood(XRD, lambda = lambda, d = 3)
lines(likelihood, col = "red")
## Strip ka2
ka2 <- ka2_strip_penalized(XRD, lambda = lambda, tau = 0.5, nseg = 1)
lines(ka2, col = "blue")
## End(Not run)
Loess Smoothing
Description
Smoothes intensities by loess fitting.
Usage
smooth_loess(x, y, ...)
## S4 method for signature 'numeric,numeric'
smooth_loess(x, y, span = 0.75, ...)
## S4 method for signature 'ANY,missing'
smooth_loess(x, span = 0.75, ...)
Arguments
x , y |
A |
... |
Extra arguments to be passed to |
span |
An |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other smoothing methods:
smooth_likelihood()
,
smooth_rectangular()
,
smooth_savitzky()
,
smooth_triangular()
,
smooth_whittaker()
Examples
## Simulate data with some noise
x <- seq(-4, 4, length = 100)
y <- dnorm(x) + rnorm(100, mean = 0, sd = 0.01)
## Plot spectrum
plot(x, y, type = "l", xlab = "", ylab = "")
## Rectangular smoothing
unweighted <- smooth_rectangular(x, y, m = 3)
plot(unweighted, type = "l", xlab = "", ylab = "")
## Triangular smoothing
weighted <- smooth_triangular(x, y, m = 5)
plot(weighted, type = "l", xlab = "", ylab = "")
## Loess smoothing
loess <- smooth_loess(x, y, span = 0.75)
plot(loess, type = "l", xlab = "", ylab = "")
## Savitzky–Golay filter
savitzky <- smooth_savitzky(x, y, m = 21, p = 2)
plot(savitzky, type = "l", xlab = "", ylab = "")
## Whittaker smoothing
whittaker <- smooth_whittaker(x, y, lambda = 1600, d = 2)
plot(whittaker, type = "l", xlab = "", ylab = "")
Rectangular Smoothing
Description
Unweighted sliding-average or rectangular Smoothing.
Usage
smooth_rectangular(x, y, ...)
## S4 method for signature 'numeric,numeric'
smooth_rectangular(x, y, m = 3)
## S4 method for signature 'ANY,missing'
smooth_rectangular(x, m)
Arguments
x , y |
A |
... |
Currently not used. |
m |
An odd |
Details
It replaces each point in the signal with the average of m
adjacent
points.
Value
Returns a list
with two components x
and y
.
Note
There will be (m - 1) / 2
points both at the beginning and at the end
of the data series for which a complete m
-width window cannot be
obtained. To prevent data loss, progressively wider/narrower windows are
used at both ends of the data series.
Author(s)
N. Frerebeau
See Also
Other smoothing methods:
smooth_likelihood()
,
smooth_loess()
,
smooth_savitzky()
,
smooth_triangular()
,
smooth_whittaker()
Examples
## Simulate data with some noise
x <- seq(-4, 4, length = 100)
y <- dnorm(x) + rnorm(100, mean = 0, sd = 0.01)
## Plot spectrum
plot(x, y, type = "l", xlab = "", ylab = "")
## Rectangular smoothing
unweighted <- smooth_rectangular(x, y, m = 3)
plot(unweighted, type = "l", xlab = "", ylab = "")
## Triangular smoothing
weighted <- smooth_triangular(x, y, m = 5)
plot(weighted, type = "l", xlab = "", ylab = "")
## Loess smoothing
loess <- smooth_loess(x, y, span = 0.75)
plot(loess, type = "l", xlab = "", ylab = "")
## Savitzky–Golay filter
savitzky <- smooth_savitzky(x, y, m = 21, p = 2)
plot(savitzky, type = "l", xlab = "", ylab = "")
## Whittaker smoothing
whittaker <- smooth_whittaker(x, y, lambda = 1600, d = 2)
plot(whittaker, type = "l", xlab = "", ylab = "")
Savitzky-Golay Filter
Description
Savitzky-Golay Filter
Usage
smooth_savitzky(x, y, ...)
## S4 method for signature 'numeric,numeric'
smooth_savitzky(x, y, m = 3, p = 2)
## S4 method for signature 'ANY,missing'
smooth_savitzky(x, m, p)
Arguments
x , y |
A |
... |
Currently not used. |
m |
An odd |
p |
An |
Details
This method is based on the least-squares fitting of polynomials to
segments of m
adjacent points.
Value
Returns a list
with two components x
and y
.
Note
There will be (m - 1) / 2
points both at the beginning and at the end
of the data series for which a complete m
-width window cannot be
obtained. To prevent data loss, the original (m - 1) / 2
points at
both ends of the data series are preserved.
Author(s)
N. Frerebeau
References
Gorry, P. A. (1990). General Least-Squares Smoothing and Differentiation by the Convolution (Savitzky-Golay) Method. Analytical Chemistry, 62(6), p. 570-573. doi:10.1021/ac00205a007.
Savitzky, A. & Golay, M. J. E. (1964). Smoothing and Differentiation of Data by Simplified Least Squares Procedures. Analytical Chemistry, 36(8), p. 1627-1639. doi:10.1021/ac60214a047.
See Also
Other smoothing methods:
smooth_likelihood()
,
smooth_loess()
,
smooth_rectangular()
,
smooth_triangular()
,
smooth_whittaker()
Examples
## Simulate data with some noise
x <- seq(-4, 4, length = 100)
y <- dnorm(x) + rnorm(100, mean = 0, sd = 0.01)
## Plot spectrum
plot(x, y, type = "l", xlab = "", ylab = "")
## Rectangular smoothing
unweighted <- smooth_rectangular(x, y, m = 3)
plot(unweighted, type = "l", xlab = "", ylab = "")
## Triangular smoothing
weighted <- smooth_triangular(x, y, m = 5)
plot(weighted, type = "l", xlab = "", ylab = "")
## Loess smoothing
loess <- smooth_loess(x, y, span = 0.75)
plot(loess, type = "l", xlab = "", ylab = "")
## Savitzky–Golay filter
savitzky <- smooth_savitzky(x, y, m = 21, p = 2)
plot(savitzky, type = "l", xlab = "", ylab = "")
## Whittaker smoothing
whittaker <- smooth_whittaker(x, y, lambda = 1600, d = 2)
plot(whittaker, type = "l", xlab = "", ylab = "")
Triangular Smoothing
Description
Weighted sliding-average or triangular smoothing.
Usage
smooth_triangular(x, y, ...)
## S4 method for signature 'numeric,numeric'
smooth_triangular(x, y, m = 3)
## S4 method for signature 'ANY,missing'
smooth_triangular(x, m)
Arguments
x , y |
A |
... |
Currently not used. |
m |
An odd |
Details
It replaces each point in the signal with the weighted mean of m
adjacent points.
Value
Returns a list
with two components x
and y
.
Note
There will be (m - 1) / 2
points both at the beginning and at the end
of the data series for which a complete m
-width window cannot be
obtained. To prevent data loss, progressively wider/narrower windows are
used at both ends of the data series.
Author(s)
N. Frerebeau
See Also
Other smoothing methods:
smooth_likelihood()
,
smooth_loess()
,
smooth_rectangular()
,
smooth_savitzky()
,
smooth_whittaker()
Examples
## Simulate data with some noise
x <- seq(-4, 4, length = 100)
y <- dnorm(x) + rnorm(100, mean = 0, sd = 0.01)
## Plot spectrum
plot(x, y, type = "l", xlab = "", ylab = "")
## Rectangular smoothing
unweighted <- smooth_rectangular(x, y, m = 3)
plot(unweighted, type = "l", xlab = "", ylab = "")
## Triangular smoothing
weighted <- smooth_triangular(x, y, m = 5)
plot(weighted, type = "l", xlab = "", ylab = "")
## Loess smoothing
loess <- smooth_loess(x, y, span = 0.75)
plot(loess, type = "l", xlab = "", ylab = "")
## Savitzky–Golay filter
savitzky <- smooth_savitzky(x, y, m = 21, p = 2)
plot(savitzky, type = "l", xlab = "", ylab = "")
## Whittaker smoothing
whittaker <- smooth_whittaker(x, y, lambda = 1600, d = 2)
plot(whittaker, type = "l", xlab = "", ylab = "")
Whittaker Smoothing
Description
Whittaker Smoothing
Usage
smooth_whittaker(x, y, ...)
## S4 method for signature 'numeric,numeric'
smooth_whittaker(x, y, lambda = 1600, d = 2, sparse = FALSE)
## S4 method for signature 'ANY,missing'
smooth_whittaker(x, lambda = 1600, d = 2, sparse = FALSE)
Arguments
x , y |
A |
... |
Currently not used. |
lambda |
An |
d |
An |
sparse |
A |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
References
Eilers, P. H. C. (2003). A Perfect Smoother. Analytical Chemistry, 75(14): 3631-36. doi:10.1021/ac034173t.
See Also
Other smoothing methods:
smooth_likelihood()
,
smooth_loess()
,
smooth_rectangular()
,
smooth_savitzky()
,
smooth_triangular()
Examples
## Simulate data with some noise
x <- seq(-4, 4, length = 100)
y <- dnorm(x) + rnorm(100, mean = 0, sd = 0.01)
## Plot spectrum
plot(x, y, type = "l", xlab = "", ylab = "")
## Rectangular smoothing
unweighted <- smooth_rectangular(x, y, m = 3)
plot(unweighted, type = "l", xlab = "", ylab = "")
## Triangular smoothing
weighted <- smooth_triangular(x, y, m = 5)
plot(weighted, type = "l", xlab = "", ylab = "")
## Loess smoothing
loess <- smooth_loess(x, y, span = 0.75)
plot(loess, type = "l", xlab = "", ylab = "")
## Savitzky–Golay filter
savitzky <- smooth_savitzky(x, y, m = 21, p = 2)
plot(savitzky, type = "l", xlab = "", ylab = "")
## Whittaker smoothing
whittaker <- smooth_whittaker(x, y, lambda = 1600, d = 2)
plot(whittaker, type = "l", xlab = "", ylab = "")
Subset
Description
-
signal_select()
allows to subset by values ofx
. -
signal_slice()
allows to subset by position alongx
.
Usage
signal_select(x, y, ...)
signal_slice(x, y, ...)
## S4 method for signature 'numeric,numeric'
signal_select(x, y, from, to)
## S4 method for signature 'ANY,missing'
signal_select(x, from, to)
## S4 method for signature 'numeric,numeric'
signal_slice(x, y, subset)
## S4 method for signature 'ANY,missing'
signal_slice(x, subset)
Arguments
x , y |
A |
... |
Currently not used. |
from , to |
A |
subset |
An |
Value
Returns a list
with two components x
and y
.
Author(s)
N. Frerebeau
See Also
Other signal processing methods:
signal_bind()
,
signal_correct()
,
signal_drift()
,
signal_mean()
,
signal_shift()
Examples
## gamma-ray spectrometry
data("BEGe")
## Plot spectrum
plot(BEGe, type = "l", xlab = "Energy (keV)", ylab = "Count")
## Subset from 2.75 keV to 200 keV
BEGe_1 <- signal_select(BEGe, from = 3, to = 200)
## Plot spectrum
plot(BEGe_1, type = "l", xlab = "Energy (keV)", ylab = "Count")
## Subset from the 20th to the 1250th value
BEGe_2 <- signal_slice(BEGe, subset = 20:1250)
## Plot spectrum
plot(BEGe_2, type = "l", xlab = "Energy (keV)", ylab = "Count")
Sliding Windows
Description
There will be (m - 1) / 2
points both at the beginning and at the end
of the data series for which a complete m
-width window cannot be
obtained. To prevent data loss, progressively wider/narrower windows are
evaluated at both ends of the data series.
Usage
window_sliding(n, m, ...)
## S4 method for signature 'integer,integer'
window_sliding(n, m, i = NULL)
## S4 method for signature 'numeric,numeric'
window_sliding(n, m, i = NULL)
Arguments
n |
An |
m |
An odd |
... |
Currently not used. |
i |
A vector |
Value
Returns a length-n
list
of integer
vectors (indices of the
data points in each window).
Author(s)
N. Frerebeau
See Also
Other moving windows:
window_tumbling()
Examples
## Length of the data series
n <- 10
## Progressive sliding windows
sliding <- window_sliding(n = n, m = 5)
plot(NULL, xlim = c(1, n), ylim = c(1, 10.5), xlab = "Index", ylab = "Window")
for (i in seq_along(sliding)) {
w <- sliding[[i]]
text(x = w, y = rep(i, length(w)), labels = w, pos = 3)
lines(w, rep(i, length(w)), type = "l", lwd = 2)
}
## Tumbling windows
## (compare with drop = TRUE)
tumbling <- window_tumbling(n = n, m = 3, drop = FALSE)
plot(NULL, xlim = c(1, n), ylim = c(1, 5.5), xlab = "Index", ylab = "Window")
for (i in seq_along(tumbling)) {
w <- tumbling[[i]]
text(x = w, y = rep(i, length(w)), labels = w, pos = 3)
lines(w, rep(i, length(w)), type = "l", lwd = 2)
}
Tumbling Windows
Description
Tumbling Windows
Usage
window_tumbling(n, m, ...)
## S4 method for signature 'integer,integer'
window_tumbling(n, m, drop = FALSE)
## S4 method for signature 'numeric,numeric'
window_tumbling(n, m, drop = FALSE)
Arguments
n |
An |
m |
An |
... |
Currently not used. |
drop |
A |
Value
Returns a list
of integer
vectors (indices of the data points in
each window).
Author(s)
N. Frerebeau
See Also
Other moving windows:
window_sliding()
Examples
## Length of the data series
n <- 10
## Progressive sliding windows
sliding <- window_sliding(n = n, m = 5)
plot(NULL, xlim = c(1, n), ylim = c(1, 10.5), xlab = "Index", ylab = "Window")
for (i in seq_along(sliding)) {
w <- sliding[[i]]
text(x = w, y = rep(i, length(w)), labels = w, pos = 3)
lines(w, rep(i, length(w)), type = "l", lwd = 2)
}
## Tumbling windows
## (compare with drop = TRUE)
tumbling <- window_tumbling(n = n, m = 3, drop = FALSE)
plot(NULL, xlim = c(1, n), ylim = c(1, 5.5), xlab = "Index", ylab = "Window")
for (i in seq_along(tumbling)) {
w <- tumbling[[i]]
text(x = w, y = rep(i, length(w)), labels = w, pos = 3)
lines(w, rep(i, length(w)), type = "l", lwd = 2)
}