Learn R Programming

ir (version 0.4.1)

ir_bc: Performs baseline correction on infrared spectra

Description

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

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.

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.

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

Examples

Run this code
library(dplyr)

# 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)

Run the code above in your browser using DataLab