x0 <- rnorm(1000) / 5 + sin(1:1000 / 300)
# Simulates pulase signals
x <- x0
x[400:410] <- -100
x[420:430] <- 100
fitted <- interpolate_stimulation(x, 100, duration = 0.3, nknots = 10, nsd = 2)
oldpar <- par(mfrow = c(2, 1))
plot(fitted, type = 'l', col = 'blue', lwd = 2)
lines(x, col = 'red')
lines(x0, col = 'black')
legend("topleft", c("Interpolated", "Observed", "Underlying"),
lty = 1, col = c("blue", "red", "black"))
pwelch(x0, 100, 200, 100, plot = 1, col = 'black', ylim = c(-50, 50))
pwelch(x, 100, 200, 100, plot = 2, col = 'red')
pwelch(fitted, 100, 200, 100, plot = 2, col = 'blue')
par(oldpar)
Run the code above in your browser using DataLab