Normalizes each row of an input data.frame
or matrix
by applying a SNV transformation
followed by fitting a second order linear model and returning the fitted residuals.
detrend(X, wav)
a numeric data.frame
, matrix
or vector
to process.
the wavelengths/ band centers.
a matrix
or vector
with detrend values
The detrend is a row-wise transformation that allows to correct for wavelength-dependent
scattering effects (variations in curvilinearity). A second-degree polynomial is fit through each spectrum:
Barnes RJ, Dhanoa MS, Lister SJ. 1989. Standard normal variate transformation and de-trending of near-infrared diffuse reflectance spectra. Applied spectroscopy, 43(5): 772-777.
# NOT RUN {
data(NIRsoil)
wav <- as.numeric(colnames(NIRsoil$spc))
# conversion to reflectance
spc <- 1/10^NIRsoil$spc
opar <- par(no.readonly = TRUE)
par(mfrow = c(2,1), mar = c(4, 4, 2, 2))
#plot of the 10 first spectra
matplot(wav, t(spc[1:10,]),
type = 'l',
xlab = '',
ylab = 'Reflectance')
mtext('Raw spectra')
det <- detrend(spc, wav)
matplot(wav, t(det[1:10,]),
type = 'l',
xlab = 'Wavelength /nm',
ylab = 'Reflectance')
mtext('Detrend spectra')
par(opar)
# }
Run the code above in your browser using DataLab