binning: Signal binning

View source: R/binning.R

binningR Documentation

Signal binning

Description

Compute average values of a signal in pre-determined bins (col-wise subsets). The bin size can be determined either directly or by specifying the number of bins. Sometimes called boxcar transformation in signal processing

Usage

binning(X, bins, bin.size)

Arguments

X

a numeric matrix or vector to process (optionally a data frame that can be coerced to a numerical matrix).

bins

the number of bins.

bin.size

the desired size of the bins.

Value

a matrix or vector with average values per bin.

Author(s)

Antoine Stevens & Leonardo Ramirez-Lopez

See Also

savitzkyGolay, movav, gapDer, continuumRemoval

Examples

data(NIRsoil)
wav <- as.numeric(colnames(NIRsoil$spc))

# 5 first spectra
matplot(wav, t(NIRsoil$spc[1:5, ]),
  type = "l",
  xlab = "Wavelength /nm",
  ylab = "Absorbance"
)

NIRsoil$spc_binned <- binning(NIRsoil$spc, bin.size = 20)

# bin means
matpoints(as.numeric(colnames(NIRsoil$spc_binned)),
  t(NIRsoil$spc_binned[1:5, ]),
  pch = 1:5
)

NIRsoil$spc_binned <- binning(NIRsoil$spc, bins = 20)
dim(NIRsoil$spc_binned) # 20 bins

# 5 first spectra
matplot(wav,
  t(NIRsoil$spc[1:5, ]),
  type = "l",
  xlab = "Wavelength /nm",
  ylab = "Absorbance"
)

# bin means
matpoints(as.numeric(colnames(NIRsoil$spc_binned)),
  t(NIRsoil$spc_binned[1:5, ]),
  pch = 1:5
)

prospectr documentation built on Aug. 31, 2022, 5:05 p.m.