downsample | R Documentation |
Downsamples a signal for the purposes of visualization. A subset of the original samples are used to represent the signal. The downsampled signal is intended to resemble the original when visualized and should not typically be used for downstream processing.
downsample(x, n = length(x) / 10L, domain = NULL,
method = c("lttb", "ltob", "dynamic"))
x |
A numeric vector. |
n |
The length of the downsampled signal. |
domain |
The domain variable of the signal. |
method |
The downsampling method to be used. Must be one of |
This function implements the downsampling methods from Sveinn Steinarsson's 2013 MSc thesis Downsampling Time Series for Visual Representation, including largest-triangle-three-buckets (LTTB), largest-triangle-one-bucket (LTOB), and dynamic binning.
A vector of length n
, giving the downsampled signal.
Kylie A. Bemis
S. Steinarsson. “Downsampling Time Series for Visual Representation.” MSc, School of Engineering and Natural Sciences, University of Iceland, Reykjavik, Iceland, June 2013.
approx1
set.seed(1)
t <- seq(from=0, to=6 * pi, length.out=2000)
x <- sin(t) + 0.6 * sin(2.6 * t)
x <- x + runif(length(x))
xs <- downsample(x, n=200)
s <- attr(xs, "sample")
plot(x, type="l")
points(s, xs, col="red", type="b")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.