Learn R Programming

oce (version 0.1-76)

make.filter: Make a digital filter

Description

make a digital filter

Usage

make.filter(type=c("blackman-harris"), m)

Arguments

type
a string indicating the type of filter. Only one type is provided so far, the Blackman-Harris filter, a modified raised-cosine filter. For a discussion of this and other filters, see Harris (1978).
m
sugggested length of filter. If m is an even number, the filter length is set to m+1.

Value

  • A list of filter coefficients, symmetric about the midpoint and summing to 1.

Details

The filter is suitable for use by filter or convolve. Note that convolve should be faster than filter, but it cannot be used if the time series has missing values.

References

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.)

Examples

Run this code
library(oce)
x <- c(rep(0,30),rep(1,30),rep(0,30))
plot.ts(x)
x1 <- filter(x, make.filter("blackman-harris", 5))
lines(x1, col='red')
x2 <- filter(x, make.filter("blackman-harris", 10))
lines(x2, col='blue')
legend("topright", lwd=1, col=c("red", "blue"), legend=c("m=5", "m=10"))

Run the code above in your browser using DataLab