Adding noise to the spectra: This case can help to
develop tutorials about techniques to remove the noise, the package “prospectr”
one of this techniques could be the one called “Moving average”, or “Running mean”.
With this technique we trim the spectra a certain number of data points at the
extremes (but we will seeit in other post).
In this post let´s add some noise to the “NIRsoil” data,
library(prospectr)
data(NIRsoil)class(NIRsoil) # data.frame
names(NIRsoil) # "Nt" "Ciso" "CEC" "train" "spc"
head(NIRsoil$spc)# De 1100-2498 nm,every2nm
X<-as.matrix(NIRsoil$spc)
noise=rnorm(length(X),0,0.001) #(Generate noise)
#Constructing the Matrix:
noise<-matrix(noise,nrow=825,ncol=700)
plot(colnames(X),noise[1,],type="l",xlab="wavelength",
+ ylab="absorbance")
X.noisy<-X + noise
par(mfrow=c(2,1),ps=14)
plot(colnames(X),X[1,],type="l",xlab="wavelength",
+ ylab="absorbance",col="blue")
plot(colnames(X),X.noisy[1,],type="l",xlab="wavelength",
+ ylab="absorbance",col="red")
Up we can see the spectrum of the sample number in position 1, without noise added, and in the lower one the same spectrum with noise added.
No hay comentarios:
Publicar un comentario