Introduction
Butterworth filters with order other than 1 have an overshoot phenomenon that can be problematic in some cases. For example, if smoothing is used on an estimate of kinetic energy, overshoots might yield negative values that are nonphysical. This post simply illustrates this with madeup data that the reader can experiment with.
Methods
First, create and plot some fake data, a tophat function. (Note the use of par
to tighten the margins.)

library(signal)
n < 100
x < 1:n
y < ifelse(0.3*n < x & x < 0.7*n, 1, 0)
par(mar=c(3, 3, 1, 1), mgp=c(2, 0.7, 0))
plot(x, y, type='o', pch=20, ylim=c(0.1, 1.1))

Next, decide on the cutoff frequency for a lowpass filter. Setting W
to 0.1 means a cutoff at 1/10th of the Nyquist frequency.

W < 0.1

Finally, filter with orders 1, 2 and 3, and add coloured lines indicating the results

b1 < butter(1, W)
y1 < filtfilt(b1, y)
points(x, y1, type='o', pch=20, col='red')
b2 < butter(2, W)
y2 < filtfilt(b2, y)
points(x, y2, type='o', pch=20, col='blue')
b3 < butter(3, W)
y3 < filtfilt(b3, y)
points(x, y3, type='o', pch=20, col='forestgreen')
legend("topright", lwd=2, pch=20,
col=c("black", "red", "blue", "forestgreen"),
legend=c("Signal", "Order 1", "Order 2", "Order 3"))

Results
Conclusions
Be careful in using butterworth filters of order 2 and higher, at least in applications that are sensitive to overshoot (e.g. kineticenergy timeseries).
Rbloggers.com offers daily email updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...