# NOT RUN {
lx <- 60
tx <- seq(0, 360, length.out = lx)
x <- sin(2 * pi * tx / 120)
# upsample
p <- 3; q <- 2
ty <- seq(0, 360, length.out = lx * p / q)
y <- resample(x, p, q)
# downsample
p <- 2; q <- 3
tz <- seq(0, 360, length.out = lx * p / q)
z <- resample(x, p, q)
# plot
plot(tx, x, type = "b", col = 1, pch = 1,
xlab = "", ylab = "")
points(ty, y, col = 2, pch = 2)
points(tz, z, col = 3, pch = 3)
legend("bottomleft", legend = c("original", "upsampled", "downsampled"),
lty = 1, pch = 1:3, col = 1:3)
# }
Run the code above in your browser using DataLab