Learn R Programming

specmine (version 4.0.0)

raman_sgolay_derivative: Compute Savitzky-Golay second derivative of Raman or SERS spectra

Description

Applies a Savitzky-Golay smoothing filter and computes the second derivative of Raman or surface-enhanced Raman spectroscopy (SERS) spectra.

Usage

raman_sgolay_derivative(dataset, window_size = 7, polynomial_order = 2)

Value

A dataset equivalent to dataset, with second derivative spectra stored in dataset$data. The original wavenumbers are stored in dataset$original_wavenumbers, when available. Information about the transform is stored in dataset$derivative.

Arguments

dataset

A dataset list containing a numeric matrix in dataset$data, with wavenumbers in rows and samples in columns. The dataset must also contain a numeric vector in dataset$wavenumbers, with one value per row of dataset$data.

window_size

Odd positive integer specifying the size of the moving window (number of points). Must be less than or equal to the number of wavenumbers.

polynomial_order

Positive integer specifying the order of the polynomial used for local fitting. Must be less than window_size.

Details

This function is a wrapper around savitzky_golay() specialized for Raman/SERS datasets. It fixes the differentiation order to 2 and provides argument names and validation tailored to spectroscopic workflows.

The dataset must contain wavenumbers in rows and samples in columns. Each sample spectrum is processed independently. The second derivative is computed using polynomial fitting within a moving window.

Examples

Run this code
wavenumbers = seq(400, 1000, length.out = 21)

dataset = list(
  data = cbind(
    sample1 = sin(seq(0, 2 * pi, length.out = 21)),
    sample2 = cos(seq(0, 2 * pi, length.out = 21))
  ),
  wavenumbers = wavenumbers
)

deriv2 = raman_sgolay_derivative(
  dataset,
  window_size = 7,
  polynomial_order = 2
)

dim(deriv2$data)

Run the code above in your browser using DataLab