
Last chance! 50% off unlimited learning
Sale ends in
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
.
makeFilter(type = c("blackman-harris", "rectangular", "hamming", "hann"), m, asKernel = TRUE)
"blackman-harris"
yields a modified raised-cosine filter designated
as "4-Term (-92 dB) Blackman-Harris" by Harris (1978; coefficients given in
the table on page 65). This is also called "minimum 4-sample Blackman
Harris" by that author, in his Table 1, which lists figures of merit as
follows: highest side lobe level -92dB; side lobe fall off -6 db/octave;
coherent gain 0.36; equivalent noise bandwidth 2.00 bins; 3.0-dB bandwidth
1.90 bins; scallop loss 0.83 dB; worst case process loss 3.85 dB; 6.0-db
bandwidth 2.72 bins; overlap correlation 46 percent for 75% overlap and 3.8
for 50% overlap. Note that the equivalent noise bandwidth is the width of
a spectral peak, so that a value of 2 indicates a cutoff frequency of
1/m
, where m
is as given below. "rectangular"
for a flat filter. (This is just for convenience. Note that
kernel("daniell",....)
gives the same result, in kernel form.)
"hamming"
for a Hamming filter (a raised-cosine that does not taper
to zero at the ends) "hann"
(a raised cosine that tapers to
zero at the ends). TRUE
to get a smoothing kernel for
the return value.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.
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"))
Run the code above in your browser using DataLab