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.- 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).- ...
Further arguments passed to
ir_bc_polynomial(),ir_bc_rubberband()orir_bc_sg().
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
if(!requireNamespace("ChemoSpec", quietly = TRUE)) {
x2 <-
ir::ir_sample_data |>
dplyr::slice(1:10) |>
ir::ir_bc(method = "polynomial", degree = 2)
}
# Savitzky-Golay baseline correction
if(!requireNamespace("signal", quietly = TRUE)) {
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)