Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

filter2

2-D digital filter


Description

Apply a 2-D digital filter to the data in x.

Usage

filter2(h, x, shape = c("same", "full", "valid"))

Arguments

h

transfer function, specified as a matrix.

x

numeric matrix containing the input signal to be filtered.

shape

Subsection of convolution, partially matched to:

"same"

Return the central part of the filtered data; same size as x (Default)

"full"

Return the full 2-D filtered data, with zero-padding on all sides before filtering

"valid"

Return only the parts which do not include zero-padded edges.

Details

The filter2 function filters data by taking the 2-D convolution of the input x and the coefficient matrix h rotated 180 degrees. More specifically, filter2(h, x, shape) is equivalent to conv2(x, rot90(h, 2), shape).

Value

The filtered signal, returned as a matrix

Author(s)

Paul Kienzle. Conversion to R by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com.

See Also

Examples

op <- par(mfcol = c(1, 2))
x <- seq(-10, 10, length.out = 30)
y <- x
f <- function(x, y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
z <- outer(x, y, f)
z[is.na(z)] <- 1
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
title( main = "Original")

h <- matrix(c(1, -2, 1, -2, 3, -2, 1, -2, 1), 3, 3)
zf <-filter2(h, z, 'same')
persp(x, y, zf, theta = 30, phi = 30, expand = 0.5, col = "lightgreen")
title( main = "Filtered")
par(op)

gsignal

Signal Processing

v0.3-1
GPL-3
Authors
Geert van Boxtel [aut, cre] (Maintainer), Tom Short [aut] (Author of 'signal' package), Paul Kienzle [aut] (Majority of the original sources), Ben Abbott [ctb], Juan Aguado [ctb], Muthiah Annamalai [ctb], Leonardo Araujo [ctb], William Asquith [ctb], David Bateman [ctb], David Billinghurst [ctb], Juan Pablo Carbajal [ctb], André Carezia [ctb], Vincent Cautaerts [ctb], Eric Chassande-Mottin [ctb], Luca Citi [ctb], Dave Cogdell [ctb], Carlo de Falco [ctb], Carne Draug [ctb], Pascal Dupuis [ctb], John W. Eaton [ctb], R.G.H Eschauzier [ctb], Andrew Fitting [ctb], Alan J. Greenberger [ctb], Mike Gross [ctb], Daniel Gunyan [ctb], Kai Habel [ctb], Kurt Hornik [ctb], Jake Janovetz [ctb], Alexander Klein [ctb], Peter V. Lanspeary [ctb], Bill Lash [ctb], Friedrich Leissh [ctb], Laurent S. Mazet [ctb], Mike Miller [ctb], Petr Mikulik [ctb], Paolo Neis [ctb], Georgios Ouzounis [ctb], Sylvain Pelissier [ctb], Francesco Potortì [ctb], Charles Praplan [ctb], Lukas F. Reichlin [ctb], Tony Richardson [ctb], Asbjorn Sabo [ctb], Thomas Sailer [ctb], Rolf Schirmacher [ctb], Rolf Schirmacher [ctb], Ivan Selesnick [ctb], Julius O. Smith III [ctb], Peter L. Soendergaard [ctb], Quentin Spencer [ctb], Doug Stewart [ctb], P. Sudeepam [ctb], Stefan van der Walt [ctb], Andreas Weber [ctb], P. Sudeepam [ctb], Andreas Weingessel [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.