Skip to contents

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()).

Usage

ir_bc(x, method = "rubberband", ..., return_bl = FALSE)

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. If method = "rubberband", a rubberband function is used for baseline correction. If method = "sg", a Savitzky-Golay smoothed version of the input spectra is used for baseline correction.

...

Further arguments passed to ir_bc_polynomial() or ir_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)