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
Author
Antoine Stevens & Leonardo Ramirez-Lopez
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
#> [1] 825 20
# 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
)
