Learn R Programming

rchemo (version 0.1-3)

dderiv: Derivation by finite difference

Description

Calculation of the first derivatives, by finite differences, of the row observations (e.g. spectra) of a dataset.

Usage

dderiv(X, n = 5, ts = 1)

Value

A matrix of the transformed data.

Arguments

X

X-data (\(n, p\)).

n

The number of points (i.e. columns of X) defining the window over wich is calculate each finite difference. The derivation is calculated for the point at the center of the window. Therefore, n must be an odd integer, and be higher or equal to 3.

ts

A scaling factor for the finite differences (by default, ts = 1.)

Examples

Run this code

data(cassav)

X <- cassav$Xtest

n <- 15
Xp_derivate1 <- dderiv(X, n = n)
Xp_derivate2 <- dderiv(dderiv(X, n), n)

oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 2))
plotsp(X, main = "Signal")
plotsp(Xp_derivate1, main = "Corrected signal")
abline(h = 0, lty = 2, col = "grey")
par(oldpar)

Run the code above in your browser using DataLab