This function is used to low pass filter (smooth) a regularly-sampled time series.

smooth(x, n)

Arguments

x

The signal to be filtered. It can be multi-channel with a signal in each column, e.g., an acceleration matrix. The number of samples (i.e., the number of rows in x) must be larger than the filter length, n.

n

The smoothing parameter - use a larger number to smooth more. n must be greater than 1. Signal components above 1/n of the Nyquist frequency are filtered out.

Value

The input signal has the first and fifth harmonic. Applying the low-pass filter removes most of the fifth harmonic so the output appears as a sinewave except for the first few samples which are affected by the filter startup transient. Smooth uses fir_nodelay to perform the filtering and so introduces no delay.

Examples

if (FALSE) {
# noisy stuff
y1 <- sin((2 * pi * 0.05) %*% t(c(1:100))) + cos((2 * pi * 0.25) %*% t(c(1:100)))
plot(x = c(1:length(y1)), y = y1)
# smooth it out
y2 <- smooth(x, n = 4)
plot(x = c(1:length(y2)), y = y2)
}