Description Usage Arguments Details Value Note Author(s) References Examples
Turn a signal of length N
into a signal of length n
via linear interpolation.
1 | eegresample(x, n)
|
x |
Vector or matrix (time by channel) of EEG data with |
n |
Number of time points for the resampled data. |
Data are resampled using the "Linear Length Normalization" approach described in Helwig et al. (2011). Let \mathbf{x} = (x_1, …, x_N)' denote the input vector of length N, and define a vector \mathbf{t} = (t_1, …, t_n) with entries
t_i = 1 + (i - 1) δ
for i = 1, …, n where δ = (N - 1) / (n - 1). The resampled vector is calculated as
y_i = x_{\lfloor t_i \rfloor} + (x_{\lceil t_i \rceil} - x_{\lfloor t_i \rfloor}) ( t_i - \lfloor t_i \rfloor)
for i = 1, …, n where \lfloor \cdot \rfloor and \lceil \cdot \rceil denote the floor and ceiling functions.
Resampled version of input data with n
time points.
Typical usage is to down-sample (i.e., decrease the sampling rate of) a signal: n < N
.
Nathaniel E. Helwig <helwig@umn.edu>
Helwig, N. E., Hong, S., Hsiao-Wecksler E. T., & Polk, J. D. (2011). Methods to temporally align gait cycle data. Journal of Biomechanics, 44(3), 561-566.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | ########## EXAMPLE 1 ##########
# create vector with N = 200 time points
N <- 200
x <- sin(4 * pi * seq(0, 1, length.out = N))
# down-sample (i.e., decrease sampling rate) to n = 100
y <- eegresample(x, n = 100)
mean((y - sin(4 * pi * seq(0, 1, length.out = 100)))^2)
# up-sample (i.e., increase sampling rate) to n = 500
z <- eegresample(x, n = 500)
mean((z - sin(4 * pi * seq(0, 1, length.out = 500)))^2)
# plot results
par(mfrow = c(1,3))
plot(x, main = "Original (N = 200)")
plot(y, main = "Down-sampled (n = 100)")
plot(z, main = "Up-sampled (n = 500)")
########## EXAMPLE 2 ##########
# create matrix with N = 500 time points and 2 columns
N <- 500
x <- cbind(sin(2 * pi * seq(0, 1, length.out = N)),
sin(4 * pi * seq(0, 1, length.out = N)))
# down-sample (i.e., decrease sampling rate) to n = 250
y <- eegresample(x, n = 250)
ytrue <- cbind(sin(2 * pi * seq(0, 1, length.out = 250)),
sin(4 * pi * seq(0, 1, length.out = 250)))
mean((y - ytrue)^2)
# up-sample (i.e., increase sampling rate) to n = 1000
z <- eegresample(x, n = 1000)
ztrue <- cbind(sin(2 * pi * seq(0, 1, length.out = 1000)),
sin(4 * pi * seq(0, 1, length.out = 1000)))
mean((z - ztrue)^2)
# plot results
par(mfrow = c(1,3))
plot(x[,1], main = "Original (N = 500)", cex = 0.5)
points(x[,2], pch = 2, col = "blue", cex = 0.5)
plot(y[,1], main = "Down-sampled (n = 250)", cex = 0.5)
points(y[,2], pch = 2, col = "blue", cex = 0.5)
plot(z[,1], main = "Up-sampled (n = 1000)", cex = 0.5)
points(z[,2], pch = 2, col = "blue", cex = 0.5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.