25 oct. 2013

Applying "SNV + Detrend" to the spectra with R

Normally Detrend is used together with SNV as a Math treatment to remove the scatter. We have seen in the last post, how to apply Detrend to the spectra using the R package "pracma".
There are other posts in this blog about SNV (standard normal variate), and we can combine them to get the SNV + Detrend math treatment.
First let´s apply the SNV:
yarn_snv<-scale(t(yarn$NIR),center=TRUE,scale=TRUE)
wavelengths1<-seq(1,268,by=1)  #para "yarn"
matplot(wavelengths1,yarn_snv,type="l",main="Yarn spectra with +SNV",xlab="Wavelength (nm)",ylab="1/R (log 1/R)",lty=1,col=1)

 

and now the Detrend:
library(pracma)
yarndt_NIR<-detrend(t(yarn$NIR),tt="linear")
matplot(wavelengths1,yarndt_NIR,type="l",lty=1,xlab="Wavelength

+(nm)",ylab="1/R")


 

 


23 oct. 2013

Applying "Detrend" to the spectra with R

There is a nice math treatment I use to apply to the spectra in NIR. It is the Detrend.
Normally goes together with the SNV, but this time I´m going to apply it alone.
I´m going to use the Yarn data, with this raw spectra:
 

 
Now we load the R package "pracma":
 
library(pracma)
yarndt_NIR<-detrend(t(yarn$NIR),tt="linear")
wavelengths1<-seq(1,268,by=1)  #para "yarn"
matplot(wavelengths1,yarndt_NIR,type="l",lty=1,
+xlab="Wavelength(nm)",ylab="1/R")
 
The spectra change to this one:
 
We can see hou the "trend" effect ( a shift in the baseline) is corrected and the baseline adjusted.

: