# NOT RUN {
bf <- butter(3, 0.1) # 10 Hz low-pass filter
t <- seq(0, 1, len = 100) # 1 second sample
x <- sin(2* pi * t * 2.3) + 0.25 * rnorm(length(t)) # 2.3 Hz sinusoid+noise
z <- filter(bf, x) # apply filter
plot(t, x, type = "l")
lines(t, z, col = "red")
zz <- filtfilt(bf, x)
lines(t, zz, col="blue")
legend("bottomleft", legend = c("original", "filter", "filtfilt"), lty = 1,
col = c("black", "red", "blue"))
# }
Run the code above in your browser using DataLab