respace {DecomposeR} | R Documentation |
Interpolate with even spacing
Description
Interpolate with even spacing. Can determine on its own the most conservative sampling interval (using the Greatest Common Rational Divisor)
Usage
respace(
dt,
xy = NULL,
delta = NULL,
tolerance = 8,
relative = TRUE,
n.warn = 100
)
Arguments
dt |
depth/time (same length than length/rows of xy) |
xy |
signal (vector or matrix) |
delta |
the new sampling interval. If NULL, uses the Greatest Common Rational Divisor |
tolerance , relative |
parameters for the |
n.warn |
the amount of interpolated points in between the largest interval above which a warning is provided. This warning can be useful to avoid needlessly long outputs, which might make any subsequent computation take too much time. |
Value
a list of interpolated xy and dt values ($xy and $dt), plus a vector of logicals indicating whether each point was part of the initial input or was added by interpolation
Examples
set.seed(42)
n <- 50
t <- seq_len(n)
xy <- (1 + 0.6 * sin(t*0.025)) * sin(t*0.2) + 2 * sin(t*0.025) +
rnorm(n, sd = 0.5)
inter_dt <- round(runif(length(xy), min = 0.5, max = 1.5), 1)
dt <- cumsum(inter_dt)
res <- respace(xy = xy, dt = dt)
opar <- par("mfrow")
par(mfrow = c(1,1))
plot(res$xy, res$dt, type = "l")
points(res$xy[res$initial], res$dt[res$initial], pch = 19, col = "green")
points(res$xy[!res$initial], res$dt[!res$initial],
pch = 19, col = "red", cex = 0.5)
par(mfrow = opar)