Forward and reverse pass filter to correct phase shift introduced by one-pass filter. Uses stats::filter to do each filtering pass. Closely based on signal::filtfilt – see the documentation there for further discussion. Two main differences with the implementation in signal::filtfilt: (1) We pad the end of the time series with the last observed value instead of zeros. Based on very informal plotting, this seems to give better values at the end of the time series, which will be important for prediction (2) We call stats::filter to do the filtering instead of signal::filter. This is because signal::filter has an enforced call to na.omit, which clashes with our handling of NA values. On the other hand, I think we should do something like linear or quadratic interpolation of internal NAs. This would solve the problem with calling signal::filter, which is preferred since it is more flexible.
1 | two_pass_stats_filter(filter, x, method, sides, circular)
|
filter |
vector of filter coefficients for a FIR filter |
x |
vector of data to be filtered |
method |
method for a call to stats::filter – see the documentation at stats::filter |
sides |
sides for a call to stats::filter – see the documentation at stats::filter |
circular |
circular for a call to stats::filter – see the documentation at stats::filter |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.