makeFilter {oce} | R Documentation |
make a digital filter
makeFilter(type=c("blackman-harris","rectangular", "hamming", "hann"), m, asKernel=TRUE)
type |
a string indicating the type of filter to use. (See Harris (1978) for a comparison of these and similar filters.)
|
m |
length of filter. This should be an odd number, for any non-rectangular filter. |
asKernel |
boolean, set to |
The filter is suitable for use by filter
,
convolve
or (for the asKernal=TRUE
case)
with kernapply
. Note that convolve
should
be faster than filter
, but it cannot be used if the time
series has missing values. For the Blackman-Harris filter,
the half-power frequency is at 1/m
cycles per time unit,
as shown in the “Examples” section. When using
filter
or kernapply
with these filters,
use circular=TRUE
.
If asKernel
is FALSE
, this returns a list of filter
coefficients, symmetric about the midpoint and summing to 1. These
may be used with filter
, which should be provided with
argument circular=TRUE
to avoid phase offsets. If
asKernel
is TRUE
, the return value is a smoothing
kernel, which can be applied to a timeseries with
kernapply
, whose bandwidth can be determined with
bandwidth.kernel
, and which has both print and plot
methods.
Dan Kelley
F. J. Harris, 1978. On the use of windows for harmonic analysis with the discrete Fourier Transform. Proceedings of the IEEE, 66(1), 51-83 (http://web.mit.edu/xiphmont/Public/windows.pdf.)
library(oce) y <- c(rep(1,10), rep(-1,10)) x <- seq_along(y) plot(x, y, type='o', ylim=c(-1.05, 1.05)) BH <- makeFilter("blackman-harris", 11, asKernel=FALSE) H <- makeFilter("hamming", 11, asKernel=FALSE) yBH <- stats::filter(y, BH) points(x, yBH, col=2, type='o') yH <- stats::filter(y, H) points(yH, col=3, type='o') legend("topright", col=1:3, cex=2/3, pch=1, legend=c("input", "Blackman Harris", "Hamming"))