ir_bc
performs baseline correction for infrared spectra. Baseline
correction is either performed by using a polynomial with user defined
degree fitted to each spectrum (see ChemoSpec::baselineSpectra()
), or by
using a rubberband function that is fitted to each spectrum (see
hyperSpec::spc.rubberband()
), or using a Savitzky-Golay smoothed version of
the input spectra (see ir_bc_sg()
).
Arguments
- x
An object of class
ir
.- method
A character value indicating which method should be used for baseline correction. If
method = "polynomial"
, a polynomial is used for baseline correction. Ifmethod = "rubberband"
, a rubberband function is used for baseline correction. Ifmethod = "sg"
, a Savitzky-Golay smoothed version of the input spectra is used for baseline correction.- ...
Further arguments passed to
ir_bc_polynomial()
orir_bc_sg()
.- return_bl
A logical value indicating if for each spectrum the baseline should be returned instead of the corrected intensity values (
return_bl = TRUE
) or not (return_bl = FALSE
).
Value
An object of class ir
with the baseline corrected spectra, or if
return_bl = TRUE
, the baselines instead of the spectra in column spectra
.
Examples
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
# rubberband baseline correction
x1 <-
ir::ir_sample_data %>%
dplyr::slice(1:10) %>%
ir::ir_bc(method = "rubberband")
# polynomial baseline correction
x2 <-
ir::ir_sample_data %>%
dplyr::slice(1:10) %>%
ir::ir_bc(method = "polynomial", degree = 2)
#> Warning: Unknown or uninitialised column: `measurement_id`.
#> Warning: Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
#> Consider 'structure(list(), *)' instead.
# Savitzky-Golay baseline correction
x3 <-
ir::ir_sample_data %>%
dplyr::slice(1:10) %>%
ir::ir_bc(method = "sg", p = 3, n = 199, ts = 1, m = 0)
# return the baseline instead of the baseline corrected spectra
x1_bl <-
ir::ir_sample_data %>%
dplyr::slice(1:10) %>%
ir::ir_bc(method = "rubberband", return_bl = TRUE)