bin_spectra: Binning of Adjacent Channels

View source: R/bin_spectra.R

bin_spectraR Documentation

Binning of Adjacent Channels

Description

Reduces the number of channels of spectra by replacing each group of width adjacent channels by their mean.

Usage

bin_spectra(x, width = 3, segments = TRUE)

Arguments

x

A numeric matrix or data frame of spectra, one per row, or a numeric vector (one spectrum). Their names are the wavelengths.

width

The number of adjacent channels averaged, a positive integer. Default is 3; width = 1 returns the spectra unchanged.

segments

A logical: bin the segments between gaps of the wavelength axis separately (TRUE, default). Needs wavelengths as names.

Details

Averaging keeps the intensities on their scale and divides the noise of independent channels by about sqrt(width), at the cost of spectral resolution: keep width smaller than the width of the emission lines (a few channels in LIBS spectra) to keep them resolved. Fewer channels also make the models faster to fit.

The channels are grouped from the first one; when their number is not a multiple of width, the last group is smaller. When segments = TRUE, the spectrum is split between the detectors of a multi-spectrometer system (where the wavelengths step back, or jump by more than 5 times the median spacing), and each detector is binned on its own, so that no group straddles two detectors. The binned channels are named by their mean wavelength (to 10 significant digits), or, when the names are not wavelengths, by the name of their first channel; a channel left alone in its group keeps its name.

Value

The binned spectra, of the same type as x (a tibble for a data frame), with ceiling(n / width) channels for each detector segment of n channels.

Author(s)

Christian L. Goueguel

References

  • Vrábel, J., Képeš, E., Duponchel, L., et al. (2020). Classification of challenging laser-induced breakdown spectroscopy soil sample data - EMSLIBS contest. Spectrochimica Acta Part B, 169:105872.

See Also

step_bin_spectra(), gap_derivative(), average()

Examples

data(forageLIBS)
spectra <- forageLIBS[1:3, -(1:14)]
binned <- bin_spectra(spectra, width = 3)
ncol(spectra)
ncol(binned)
names(binned)[1:3]

specProc documentation built on Nov. 20, 2026, 5:11 p.m.