50% off | Unlimited Data & AI Learning
Get 50% off unlimited learning

prospectr (version 0.2.0)

detrend: Detrend transformation

Description

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.

Usage

detrend(X, wav)

Arguments

X

a numeric data.frame, matrix or vector to process.

wav

the wavelengths/ band centers.

Value

a matrix or vector with detrend values

Details

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: xi=aλ2+bλ+c+ei were xi is the spectrum, λ is the wavelength vector, a, b, c are estimated by least square, and ei are the residuals of the least square fit. Then, a detrend spectrum corresponds to: xi=xi(aλ2+bλ+c=ei)

References

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.

See Also

standardNormalVariate, blockScale, blockNorm

Examples

Run this code
# 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