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

dwt

1-D Discrete Wavelet Transform


Description

Compute the single-level discrete wavelet transform of a signal

Usage

dwt(x, wname = "d8", lo = NULL, hi = NULL)

wfilters(wname)

Arguments

x

input data, specified as a numeric vector.

wname

analyzing wavelet, specified as a character string consisting of a class name followed by the wavelet length Only two classes of wavelets are supported; Daubechies (denoted by the prefix 'd' of even lengths 2 - 20, and Coiflet (denoted by the prefix ''c' of lengths 6, 12, 18, 24, and 30. The wavelet name 'haar' is the equivalent of 'd2'. Default: d8.

lo

scaling (low-pass) filter, specified as an even-length numeric vector. lo must be the same length as hi. Ignored when wname != NULL.

hi

wavelet (high-pass) filter, specified as an even-length numeric vector. hi must be the same length as lo, Ignored when wname != NULL.

Details

This function is only included because of compatibility with the 'Octave' 'signal' package. Specialized packages exist in R to perform the discrete wavelet transform, e.g., the wavelets package [1]. this function recognizes only a few wavelet names, namely those for which scale coefficients are available (Daubechies [2] and Coiflet [3]).

The wavelet and scaling coefficients are returned by the function wfilters, which returns the coefficients for reconstruction filters associated with the wavelet wname. Decomposition filters are the time reverse of the reconstruction filters (see examples).

Value

A list containing two numeric vectors:

a

approximation (average) coefficients, obtained from convolving x with the scaling (low-pass) filter lo, and then downsampled (keep the even-indexed elements).

d

detail (difference) coefficients, obtained from convolving x with the wavelet (high-pass) filter hi, and then downsampled (keep the even-indexed elements).

Note

The notations g and h are often used to denote low-pass (scaling) and high-pass (wavelet) coefficients, respectively, but inconsistently. Ref [4] uses it, as does the R wavelets package. 'Octave' uses the reverse notation. To avoid confusion, more neutral terms are used here.

There are two naming schemes for wavelet names in use. For instance for Daubechies wavelets (d), dN using the length or number of taps, and dbA referring to the number of vanishing moments. So d4 and db2 are the same wavelet transform. This function uses the formed (dN) notation; 'Matlab' uses the latter (dbA).

Author(s)

Lukas F. Reichlin.
Conversion to R by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com.

References

Examples

# get Coiflet 30 coefficients
wv <- wfilters('c30')
lo <- rev(wv$lo)
hi <- rev(wv$hi)

# general time-varying signal
time <- 1
fs <- 1000
x <- seq(0,time, length.out=time*fs)
y <- c(cos(2*pi*100*x)[1:300], cos(2*pi*50*x)[1:300],
       cos(2*pi*25*x)[1:200], cos(2*pi*10*x)[1:200])
op <- par(mfrow = c(3,1))
plot(x, y, type = "l", xlab = "Time", ylab = "Amplitude",
     main = "Original signal")
wt <- dwt(y, wname = NULL, lo, hi)

x2 <- seq(1, length(x) - length(hi) + 1, 2)
plot(x2, wt$a, type = "h", xlab = "Time", ylab = "",
    main = "Approximation coefficients")
plot(x2, wt$d, type = "h", xlab = "Time", ylab = "",
     main = "Detail coefficients")
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.