prospectr (version 0.1.3)

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
numeric data.frame, matrix or vector to process
wav
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: $$x_i = a\lambda^2 + b\lambda + c + e_i$$ were $x_i$ is the spectrum, $\lambda$ is the wavelength vector, a, b, c are estimated by least square, and $e_i$ are the residuals of the least square fit. Then, a detrend spectrum corresponds to: $$x\ast_i = x_i - (a\lambda^2 + b\lambda + c = e_i)$$

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
data(NIRsoil)
wav <- as.numeric(colnames(NIRsoil$spc))
spc <- 1/10^NIRsoil$spc # conversion to reflectance
opar <- par(no.readonly = TRUE)
par(mfrow=c(2,1),mar=c(4,4,2,2))
matplot(wav,t(spc[1:10,]),type='l',xlab='',ylab='Reflectance') # plot of the 10 first spectra
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