Learn R Programming

prospectr (version 0.2.8)

gapDer: Gap-Segment derivative

Description

Gap-Segment derivatives of a data matrix or vector

Usage

gapDer(X, m = 1, w = 1, s = 1, delta.wav)

Value

a matrix or vector with the filtered signal(s)

Arguments

X

a numeric matrix or vector` to transform (optionally a data frame that can be coerced to a numerical matrix).

m

an integer indicating the order of the derivative. Note that this function allows for high order derivatives (e.g. m = 6). If 0 is passed, the function will just smooth out the signal(s).

w

an integer indicating the gap size (must be odd and >=1), i.e. the spacing between points over which the derivative is computed.

s

an integer indicating the segment size (must be odd and >=1), i.e. the range over which the points are averaged (default = 1, i.e. no smoothing corresponding to Norris-Gap Derivative).

delta.wav

the sampling interval (or band spacing).

Author

Antoine Stevens and Leonardo Ramirez-Lopez

Details

In this type of derivatives, the gap size denotes the length of the x interval that separates the two segments that are averaged. A detailed explanation of gap segment derivatives can be found in Hopkins (2001).

The sampling interval specified with the delta.wav argument is used for scaling and get numerically correct derivatives.

The convolution function is written in C++/Rcpp for faster computations.

References

Hopkins, D. W. (2001). What is a Norris derivative?. NIR news, 12(3), 3-5.

See Also

savitzkyGolay, movav, binning, continuumRemoval

Examples

Run this code
data(NIRsoil)
opar <- par(no.readonly = TRUE)
par(mfrow = c(2, 2), mar = c(4, 4, 2, 2))
# plot of the 10 first spectra
matplot(as.numeric(colnames(NIRsoil$spc)),
  t(NIRsoil$spc[1:10, ]),
  type = "l",
  xlab = "",
  ylab = "Absorbance"
)
mtext("Raw spectra")

der <- gapDer(NIRsoil$spc, m = 1, w = 1, s = 1, delta.wav = 2)
matplot(as.numeric(colnames(der)),
  t(der[1:10, ]),
  type = "l",
  xlab = "Wavelength /nm",
  ylab = "gap derivative"
)

mtext("1st derivative spectra")
der <- gapDer(NIRsoil$spc, m = 1, w = 11, s = 1, delta.wav = 2)
matplot(as.numeric(colnames(der)), t(der[1:10, ]),
  type = "l",
  xlab = "Wavelength /nm",
  ylab = "gap derivative"
)

mtext("1st derivative spectra with a window size = 11 nm")
der <- gapDer(NIRsoil$spc, m = 1, w = 11, s = 5, delta.wav = 2)
matplot(as.numeric(colnames(der)), t(der[1:10, ]),
  type = "l",
  xlab = "Wavelength /nm",
  ylab = "gap derivative"
)
mtext("1st derivative spectra with: window size: 11 nm, smoothing: 5 nm")
par(opar)

Run the code above in your browser using DataLab