Learn R Programming

wmtsa (version 2.0-3)

wavCWT: Continuous wavelet transform

Description

The continuous wavelet transform (CWT) is a highly redundant transformation of a real-valued or complex-valued function \(f(x)\), mapping it from the time domain to the so-called time-scale domain. Loosely, speaking the CWT coefficients are proportional to the variability of a function at a given time and scale.

The CWT is defined by a complex correlation of a scaled and time-shifted mother wavelet with a function \(f(x)\). Let \(\psi(x)\) be a real- or complex-valued function representing a mother wavelet, i.e. a function which meets the standard mathematical criteria for a wavelet and one that can be used to generate all other wavelets within the same family. Let \(\psi^*(\cdot)\) be the complex conjugate of \(\psi(\cdot)\). The CWT of \(f(x)\) is defined as

$$ W_f(a,b) \equiv \frac{1}{\sqrt{a}} \int_{-\infty}^\infty f(x) \psi^* \Bigl(\frac{x-b}{a} \Bigr) \; dx, $$ for \((a,b) \in {\mathcal{R}}\) and \(a > 0\), where \(a\) is the scale of the wavelet and \(b\) is the shift of the wavelet in time. It can be shown that the above complex correlation maintains a duality with the Fourier transform defined by the relation

$$ W_f(a,b) \equiv \frac{1}{\sqrt{a}} \int_{-\infty}^\infty f(x) \psi^* \Bigl(\frac{x-b}{a} \Bigr) \; dx \longleftrightarrow \sqrt{a} \, F(\omega) \,\Psi^*(a\omega) $$

where \(F(\cdot)\) is the Fourier transform of \(f(x)\) and \(\omega\) is the frequency in radians. This function calculates the CWT in the Fourier domain followed by an inverse Fourier transform.

Usage

wavCWT(x, scale.range=deltat(x) * c(1, length(x)), n.scale=100,
    wavelet="gaussian2", shift=5, variance=1)

Arguments

x

a vector containing a uniformly-sampled real-valued time series. The time series may be of class class rts, ts, cts, or signalSeries, or be a numeric vector.

n.scale

the number of scales to evaluate over the scale.range. Default: 100.

scale.range

a two-element vector containing the range of scales over which to evaluate the CWT. The smallest specified scale must be greater than or equal to the sampling.interval of the time series. Default: deltat(x) * c(1, length(x)).

shift

numeric value representing the frequency shift to use for the Morlet wavelet filter. Default: 5.

variance

if the wavelet filter is of type "gaussian1" or "gaussian2" then this parameter represents the variance of the Gaussian PDF used to scale the corresponding filters. Default: 1.

wavelet

a character string denoting the wavelet filter to use in calculating the CWT. Choices are "haar", "gaussian1", "gaussian2", and "morlet", where gaussian1 and gaussian2 represent the first and second derivatives of a Gaussian PDF. Default: "gaussian2".

Value

an object of class wavCWT.

S3 METHODS

as.matrix

returns the CWT coefficients as a complex matrix with rows and columns representing times and scales, respectively.

plot

plots the CWT. By default, the modulus of the CWT coefficients are plotted in the time-scale plane. The plot method also supports the following optional arguments:

phase

Logical flag. If TRUE, the phase of the CWT is plotted. Default: FALSE.

xlab

A character string used for the label on the x-axis. Default: "time".

ylab

A character string used for the label on the y-axis. Default: "log2(units)" where units are the units of the time series if available. If units are not available, "log2(scale)" is used.

power.stretch

A numeric value used to scale the magnitude of the CWT coefficients for display purposes only. If power.stretch=0, then image is transformed with log(abs(x)+1). Otherwise, the image is transformed with (abs(x))\(\mbox{\textasciicircum}\)power.stretch. Default: 0.5.

type

A character string denoting the type of plot to produce. Choices are "image" and "persp" which plot the CWT as an image or as a meshed perspective plot, respectively. The perspective plot resamples the data to contain a maximum of grid.size rows and columns.

zoom

A four-element vector containing the ranges to zoom into the data in c(xmin, xmax, ymin, ymax) format. Default: NULL (no zoom).

grid.size

An integer specifying the maximum number of lines to use for each dimension in creating meshed perspective plots. Default: 100.

new

A logical flag. If TRUE, a new plot is forced with the frame() command.

print

prints a qualitiative summary of the CWT and its components.

References

D. B. Percival and A. T. Walden, Wavelet Methods for Time Series Analysis, Cambridge University Press, 2000.

See Also

wavCWTFilters.

Examples

Run this code
# NOT RUN {
## calculate the CWT of the sunspots series using 
## a Mexican hat wavelet (gaussian2) 
sunspots.cwt <- wavCWT(sunspots)

## print the result 
print(sunspots.cwt)

## plot an image of the modulus of the CWT and the 
## time series 
plot(sunspots.cwt, series=TRUE)

## plot a coarse-scale wire-frame perspective of 
## the CWT 
plot(sunspots.cwt, type="persp")
# }

Run the code above in your browser using DataLab