wsd: Windowed Scalogram Difference

View source: R/wsd.R

wsdR Documentation

Windowed Scalogram Difference

Description

This function computes the Windowed Scalogram Difference of two signals. The definition and details can be found in (Bolós et al. 2017).

Usage

wsd(signal1,
           signal2,
           dt = 1,
           scaleparam = NULL,
           windowrad = NULL,
           rdist = NULL,
           delta_t = NULL,
           normalize = c("NO", "ENERGY", "MAX", "SCALE"),
           refscale = NULL,
           wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"),
           wparam = NULL,
           waverad = NULL,
           border_effects = c("BE", "INNER", "PER", "SYM"),
           mc_nrand = 0,
           commutative = TRUE,
           wscnoise = 0.02,
           compensation = 0,
           energy_density = TRUE,
           parallel = FALSE,
           makefigure = TRUE,
           time_values = NULL,
           figureperiod = TRUE,
           xlab = "Time",
           ylab = NULL,
           main = "-log2(WSD)",
           zlim = NULL)

Arguments

signal1

A vector containing the first signal.

signal2

A vector containing the second signal (its length should be equal to that of signal1).

dt

Numeric. The time step of the signals.

scaleparam

A vector of three elements with the minimum scale, the maximum scale and the number of suboctaves per octave for constructing power 2 scales (following Torrence and Compo 1998). If NULL, they are automatically constructed.

windowrad

Integer. Time radius for the windows, measured in dt. By default, it is set to ceiling(length(signal1) / 20).

rdist

Integer. Log-scale radius for the windows measured in suboctaves. By default, it is set to ceiling(length(scales) / 20).

delta_t

Integer. Increment of time for the construction of windows central times, measured in dt. By default, it is set to ceiling(length(signal1) / 256).

normalize

String, equal to "NO", "ENERGY", "MAX" or "SCALE". If "ENERGY", signals are divided by their respective energies. If "MAX", each signal is divided by the maximum value attained by its scalogram. In these two cases, energy_density must be TRUE. Finally, if "SCALE", each signal is divided by their scalogram value at scale refscale.

refscale

Numeric. The reference scale for normalize.

wname

A string, equal to "MORLET", "DOG", "PAUL", "HAAR" or "HAAR2". The difference between "HAAR" and "HAAR2" is that "HAAR2" is more accurate but slower.

wparam

The corresponding nondimensional parameter for the wavelet function (Morlet, DoG or Paul).

waverad

Numeric. The radius of the wavelet used in the computations for the cone of influence. If it is not specified, it is asumed to be √{2} for Morlet and DoG, 1/√{2} for Paul and 0.5 for Haar.

border_effects

String, equal to "BE", "INNER", "PER" or "SYM", which indicates how to manage the border effects which arise usually when a convolution is performed on finite-lenght signals.

  • "BE": With border effects, padding time series with zeroes.

  • "INNER": Normalized inner scalogram with security margin adapted for each different scale.

  • "PER": With border effects, using boundary wavelets (periodization of the original time series).

  • "SYM": With border effects, using a symmetric catenation of the original time series.

mc_nrand

Integer. Number of Montecarlo simulations to be performed in order to determine the 95% and 5% significance contours.

commutative

Logical. If TRUE (default) the commutative windowed scalogram difference. Otherwise a non-commutative (but simpler) version is computed (see Bolós et al. 2017).

wscnoise

Numeric in [0,1]. If a (windowed) scalogram takes values close to zero, some problems may appear because we are considering relative differences. Specifically, we can get high relative differences that in fact are not relevant, or even divisions by zero.

If we consider absolute differences this would not happen but, on the other hand, using absolute differences is not appropriate for scalogram values not close to zero.

So, the parameter wscnoise stablishes a threshold for the scalogram values above which a relative difference is computed, and below which a difference proportional to the absolute difference is computed (the proportionality factor is determined by requiring continuity).

Finally, wscnoise can be interpreted as the relative amplitude of the noise in the scalograms and is chosen in order to make a relative (= 0), absolute (= 1) or mix (in (0,1)) difference between scalograms. Default value is set to 0.02.

compensation

Numeric. It is an alternative to wscnoise for preventing numerical errors or non-relevant high relative differences when scalogram values are close to zero (see Bolós et al. 2017). It should be a non-negative relatively small value.

energy_density

Logical. If TRUE (default), divide the scalograms by the square root of the scales for convert them into energy density. Note that it does not affect the results if wscnoise = 0.

parallel

Logical. If TRUE, it uses function parApply from package parallel for the Montecarlo simulations. When FALSE (default) it uses the normal apply function.

makefigure

Logical. If TRUE (default), a figure with the WSD is plotted.

time_values

A numerical vector of length length(signal) containing custom time values for the figure. If NULL (default), it will be computed starting at 0.

figureperiod

Logical. If TRUE (default), periods are used in the figure instead of scales.

xlab

A string giving a custom X axis label.

ylab

A string giving a custom Y axis label. If NULL (default) the Y label is either "Scale" or "Period" depending on the value of figureperiod.

main

A string giving a custom main title for the figure.

zlim

A vector of length 2 with the limits for the z-axis (the color bar).

Value

A list with the following fields:

  • wsd: A matrix of size length(tcentral) x length(scales) containing the values of the windowed scalogram differences at each scale and at each time window.

  • tcentral: The vector of central times used in the computations of the windowed scalograms.

  • scales: The vector of scales.

  • windowrad: Radius for the time windows of the windowed scalograms, measured in dt.

  • rdist: The log-scale radius for the windows measured in suboctaves.

  • signif95: A logical matrix of size length(tcentral) x length(scales). If TRUE, the corresponding point of the wsd matrix is in the 95% significance.

  • signif05: A logical matrix of size length(tcentral) x length(scales). If TRUE, the corresponding point of the wsd matrix is in the 5% significance.

  • fourierfactor: A factor for converting scales into periods.

  • coi_maxscale: A vector of length length(tcentral) containing the values of the maximum scale from which there are border effects for the respective central time.

References

C. Torrence, G. P. Compo. A practical guide to wavelet analysis. B. Am. Meteorol. Soc. 79 (1998), 61–78.

V. J. Bolós, R. Benítez, R. Ferrer, R. Jammazi. The windowed scalogram difference: a novel wavelet tool for comparing time series. Appl. Math. Comput., 312 (2017), 49-65.

Examples


nt <- 1500
time <- 1:nt
sd_noise <-  0.2 #% In Bolós et al. 2017 Figure 1, sd_noise = 1.
signal1 <- rnorm(n = nt, mean = 0, sd = sd_noise) + sin(time / 10)
signal2 <- rnorm(n = nt, mean = 0, sd = sd_noise) + sin(time / 10)
signal2[500:1000] = signal2[500:1000] + sin((500:1000) / 2)
## Not run: 
wsd <- wsd(signal1 = signal1, signal2 = signal2)

## End(Not run)


wavScalogram documentation built on Dec. 28, 2022, 2:06 a.m.