time <- seq(0, 3, 0.005)
s <- sin(120 * pi * time) + rnorm(length(time))
# Welch periodogram shows a peak at 60Hz
pwelch(s, 200, plot = 1, log = "y")
# notch filter to remove 60Hz
s1 <- notch_filter(s, 200, lb = 59, ub = 61)
pwelch(s1, 200, plot = 2, log = "y", col = "red")
Run the code above in your browser using DataLab