Title: | Wavelet Scalogram Tools for Time Series Analysis |
---|---|
Description: | Provides scalogram based wavelet tools for time series analysis: wavelet power spectrum, scalogram, windowed scalogram, windowed scalogram difference (see Bolos et al. (2017) <doi:10.1016/j.amc.2017.05.046>), scale index and windowed scale index (Benitez et al. (2010) <doi:10.1016/j.camwa.2010.05.010>). |
Authors: | Vicente J. Bolos and Rafael Benitez |
Maintainer: | Vicente J. Bolos <[email protected]> |
License: | GPL |
Version: | 1.1.3 |
Built: | 2024-10-30 06:49:40 UTC |
Source: | CRAN |
This function is an internal function which extracts from a vector x
,
the center of the vector of length n
. It emulates the Matlab(R) function wkeep
.
This function is used by the cwt_wst function when the HAAR wavelet is selected.
core(x,n)
core(x,n)
x |
A vector from wich the center is extracted. |
n |
Numeric. The length of the center of |
This function computes the continuous wavelet transform for some families of wavelet bases: "MORLET", "DOG", "PAUL" and "HAAR". It is a translation from the Matlab(R) function published by Torrence and Compo (Torrence & Compo, 1998).
The difference between cwt_wst
and cwt
from package Rwave
is that
cwt_wst
normalizes using and
cwt
uses .
cwt_wst(signal, dt = 1, scales = NULL, powerscales = TRUE, wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, waverad = NULL, border_effects = c("BE", "PER", "SYM"), makefigure = TRUE, time_values = NULL, energy_density = FALSE, figureperiod = TRUE, xlab = "Time", ylab = NULL, main = NULL, zlim = NULL)
cwt_wst(signal, dt = 1, scales = NULL, powerscales = TRUE, wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, waverad = NULL, border_effects = c("BE", "PER", "SYM"), makefigure = TRUE, time_values = NULL, energy_density = FALSE, figureperiod = TRUE, xlab = "Time", ylab = NULL, main = NULL, zlim = NULL)
signal |
A vector containing the signal whose wavelet transform is wanted. |
dt |
Numeric. The time step of the signal. |
scales |
A vector containing the wavelet scales at which the CWT
is computed. This can be either a vector with all the scales or, following Torrence
and Compo 1998, a vector of 3 elements with the minimum scale, the maximum scale and
the number of suboctaves per octave (in this case, |
powerscales |
Logical. It must be TRUE (default) in these cases:
|
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 |
border_effects |
String, equal to "BE", "PER" or "SYM", which indicates how to manage the border effects which arise usually when a convolution is performed on finite-length signals.
|
makefigure |
Logical. If TRUE (default), a figure with the wavelet power spectrum is plotted. |
time_values |
A numerical vector of length |
energy_density |
Logical. If TRUE (default), divide the wavelet power spectrum by the scales in the figure and so, values for different scales are comparable. |
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 |
main |
A string giving a custom main title for the figure. If NULL
(default) the main title is either "Wavelet Power Spectrum / Scales" or "Wavelet Power
Spectrum" depending on the value of |
zlim |
A vector of length 2 with the limits for the z-axis (the color bar). |
A list with the following fields:
coefs
: A matrix of size length(signal)
x length(scales)
,
containing the CWT coefficients of the signal.
scales
: The vector of scales.
fourierfactor
: A factor for converting scales into periods.
coi_maxscale
: A vector of length length(signal)
containing the
values of the maximum scale from which there are border effects at each time.
C. Torrence, G. P. Compo. A practical guide to wavelet analysis. B. Am. Meteorol. Soc. 79 (1998), 61–78.
dt <- 0.1 time <- seq(0, 50, dt) signal <- c(sin(pi * time), sin(pi * time / 2)) cwt <- cwt_wst(signal = signal, dt = dt, energy_density = TRUE)
dt <- 0.1 time <- seq(0, 50, dt) signal <- c(sin(pi * time), sin(pi * time / 2)) cwt <- cwt_wst(signal = signal, dt = dt, energy_density = TRUE)
This function computes the Fourier factor of a wavelet, according to Torrence and Compo (1998).
fourier_factor(wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL)
fourier_factor(wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL)
wname |
A string, equal to "MORLET", "DOG", "PAUL", "HAAR" or "HAAR2" that determines the wavelet function. |
wparam |
The corresponding nondimensional parameter for the wavelet function (Morlet, DoG or Paul). |
The numeric value of the Fourier factor.
C. Torrence, G. P. Compo. A practical guide to wavelet analysis. B. Am. Meteorol. Soc. 79 (1998), 61–78.
ff <- fourier_factor(wname = "DOG", wparam = 6)
ff <- fourier_factor(wname = "DOG", wparam = 6)
This function constructs power 2 scales (i.e. using a base 2 logarithmic scale) from a vector of three elements with the minimum scale, the maximum scale and the number of suboctaves per octave, following Torrence and Compo 1998.
pow2scales(scales)
pow2scales(scales)
scales |
A vector of three elements with the minimum scale, the maximum scale and the number ofsuboctaves per octave. |
A vector with all the scales.
C. Torrence, G. P. Compo. A practical guide to wavelet analysis. B. Am. Meteorol. Soc. 79 (1998), 61–78.
scales <- pow2scales(c(2,128,8))
scales <- pow2scales(c(2,128,8))
This function computes the scale index of a signal in the scale interval
, for a given set of scale parameters
and taking
as
the minimum scale (see Benítez et al. 2010).
The scale index of a signal in the scale interval is given by the
quotient
where is
the scalogram,
is the smallest scale such that
for all
, and
is the smallest scale such that
for all
.
scale_index(signal = NULL, scalog = NULL, dt = 1, scales = NULL, powerscales = TRUE, s1 = NULL, wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, waverad = NULL, border_effects = c("BE", "INNER", "PER", "SYM"), makefigure = TRUE, figureperiod = TRUE, plot_scalog = FALSE, xlab = NULL, ylab = "Scale index", main = "Scale Index")
scale_index(signal = NULL, scalog = NULL, dt = 1, scales = NULL, powerscales = TRUE, s1 = NULL, wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, waverad = NULL, border_effects = c("BE", "INNER", "PER", "SYM"), makefigure = TRUE, figureperiod = TRUE, plot_scalog = FALSE, xlab = NULL, ylab = "Scale index", main = "Scale Index")
signal |
A vector containing the signal whose scale indices are wanted. |
scalog |
A vector containing the scalogram from which the scale indices are going
to be computed. If |
dt |
Numeric. The time step of the signals. |
scales |
A vector containing the wavelet scales at wich the scalogram
is computed. This can be either a vector with all the scales or, following Torrence
and Compo 1998, a vector of 3 elements with the minimum scale, the maximum scale and
the number of suboctaves per octave (in this case, |
powerscales |
Logical. It must be TRUE (default) in these cases:
|
s1 |
A vector containing the scales |
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 |
border_effects |
A 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.
|
makefigure |
Logical. If TRUE (default), a figure with the scale indices is plotted. |
figureperiod |
Logical. If TRUE (default), periods are used in the figure instead of scales. |
plot_scalog |
Logical. If TRUE, it plots the scalogram from which the scale indices are computed. |
xlab |
A string giving a custom X axis label. If NULL (default) the X label is
either "s1" or "Period of s1" depending on the value of |
ylab |
A string giving a custom Y axis label. |
main |
A string giving a custom main title for the figure. |
A list with the following fields:
si
: A vector with the scale indices.
s0
: The scale .
s1
: A vector with the scales .
smax
: A vector with the scales .
smin
: A vector with the scales .
scalog
: A vector with the scalogram from which the scale indices are
computed.
scalog_smax
: A vector with the maximum scalogram values .
scalog_smin
: A vector with the minimum scalogram values .
fourierfactor
: A factor for converting scales into periods.
R. Benítez, V. J. Bolós, M. E. Ramírez. A wavelet-based tool for studying non-periodicity. Comput. Math. Appl. 60 (2010), no. 3, 634-641.
dt <- 0.1 time <- seq(0, 50, dt) signal <- c(sin(pi * time), sin(pi * time / 2)) si <- scale_index(signal = signal, dt = dt) # Another way, giving the scalogram instead of the signal: sc <- scalogram(signal = signal, dt = dt, energy_density = FALSE, makefigure = FALSE) si <- scale_index(scalog = sc$scalog, scales = sc$scales, dt = dt)
dt <- 0.1 time <- seq(0, 50, dt) signal <- c(sin(pi * time), sin(pi * time / 2)) si <- scale_index(signal = signal, dt = dt) # Another way, giving the scalogram instead of the signal: sc <- scalogram(signal = signal, dt = dt, energy_density = FALSE, makefigure = FALSE) si <- scale_index(scalog = sc$scalog, scales = sc$scales, dt = dt)
This function computes the normalized scalogram of a signal for the scales
given. It is important to note that the notion of scalogram here is analogous
to the spectrum of the Fourier transform. It gives the contribution of each scale to
the total energy of the signal. For each scale , it is defined as the square
root of the integral of the squared modulus of the wavelet transform w.r.t. the time
variable
, i.e.
"Normalized" means that the scalogram is divided by the square root of the number of
times, for comparison purposes between different values of the parameter
border_effects
.
scalogram(signal, dt = 1, scales = NULL, powerscales = TRUE, wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, waverad = NULL, border_effects = c("BE", "INNER", "PER", "SYM"), energy_density = TRUE, makefigure = TRUE, figureperiod = TRUE, xlab = NULL, ylab = "Scalogram", main = "Scalogram")
scalogram(signal, dt = 1, scales = NULL, powerscales = TRUE, wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, waverad = NULL, border_effects = c("BE", "INNER", "PER", "SYM"), energy_density = TRUE, makefigure = TRUE, figureperiod = TRUE, xlab = NULL, ylab = "Scalogram", main = "Scalogram")
signal |
A vector containing the signal whose scalogram is wanted. |
dt |
Numeric. The time step of the signal. |
scales |
A vector containing the wavelet scales at wich the scalogram
is computed. This can be either a vector with all the scales or, following Torrence
and Compo 1998, a vector of 3 elements with the minimum scale, the maximum scale and
the number of suboctaves per octave (in this case, |
powerscales |
Logical. It must be TRUE (default) in these cases:
|
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 |
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.
|
energy_density |
Logical. If TRUE (default), divide the scalogram by the square root of the scales for convert it into energy density. |
makefigure |
Logical. If TRUE (default), a figure with the scalogram is plotted. |
figureperiod |
Logical. If TRUE (default), periods are used in the figure instead of scales. |
xlab |
A string giving a custom X axis label. If NULL (default) the X label is
either "Scale" or "Period" depending on the value of |
ylab |
A string giving a custom Y axis label. |
main |
A string giving a custom main title for the figure. |
A list with the following fields:
scalog
: A vector of length length(scales)
, containing the values of
the scalogram at each scale.
scales
: The vector of scales.
energy
: If energy_density
is TRUE, it is the norm of
scalog
.
fourierfactor
: A factor for converting scales into periods.
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.
dt <- 0.1 time <- seq(0, 50, dt) signal <- c(sin(pi * time), sin(pi * time / 2)) scalog <- scalogram(signal = signal, dt = dt, border_effects = "INNER")
dt <- 0.1 time <- seq(0, 50, dt) signal <- c(sin(pi * time), sin(pi * time / 2)) scalog <- scalogram(signal = signal, dt = dt, border_effects = "INNER")
This function computes an approximation of the effective radius of a mother wavelet.
wavelet_radius(wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, perc = .0025, scale = 100, n = 1000, makefigure = FALSE)
wavelet_radius(wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, perc = .0025, scale = 100, n = 1000, makefigure = FALSE)
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). |
perc |
Numeric. The wavelet radius is computed so that the area covered is at
least the 100*(1- |
scale |
Numeric. Scale of the wavelet used in the computations. It only affects the accuracy. |
n |
Numeric. The computations use a time series of length |
makefigure |
Logical. Plots a figure with the real part of the mother wavelet and its modulus. |
A list with the following fields:
left
: The radius on the left.
right
: The radius on the right.
waverad <- wavelet_radius(wname = "MORLET", makefigure = TRUE)
waverad <- wavelet_radius(wname = "MORLET", makefigure = TRUE)
This function plots a function of two variables (usually times and scales). It is suitable for plotting windowed scalograms, windowed scalogram differences, wavelet coherences and windowed scale indices.
wavPlot(Z, X = NULL, Y = NULL, Ylog = FALSE, Yrev = TRUE, zlim = NULL, coi = NULL, rdist = NULL, sig95 = NULL, sig05 = NULL, Xname = "X", Yname = "Y", Zname = "Z")
wavPlot(Z, X = NULL, Y = NULL, Ylog = FALSE, Yrev = TRUE, zlim = NULL, coi = NULL, rdist = NULL, sig95 = NULL, sig05 = NULL, Xname = "X", Yname = "Y", Zname = "Z")
Z |
A matrix with the images of the function to be plotted. |
X |
A vector with x-coordinates (times). |
Y |
A vector with y-coordinates (scales). |
Ylog |
Logical. Considers logarithmic scale for the y-axis. |
Yrev |
Logical. Considers reverse the y-axis. |
zlim |
A vector of length 2 with the limits for the z-axis (the color bar). |
coi |
A vector of size |
rdist |
Numeric. Only for WSD plots, margin in the y-axis where appear border effects. |
sig95 |
Logical matrix with the same size as Z. TRUE if the corresponding point in Z is inside the significance at 95%. |
sig05 |
Logical matrix with the same size as Z. TRUE if the corresponding point in Z is inside the significance at 5%. |
Xname |
A string with the name of the x-axis. |
Yname |
A string with the name of the y-axis. |
Zname |
A string with the name of the function. |
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, mc_nrand = 10, makefigure = FALSE) wavPlot(Z = -log2(wsd$wsd), X = wsd$t, Y = wsd$scales, Ylog = TRUE, coi = wsd$coi, rdist = wsd$rdist, sig95 = wsd$signif95, sig05 = wsd$signif05, Xname = "Time", Yname = "Scale", Zname = "-log2(WSD)") ## End(Not run)
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, mc_nrand = 10, makefigure = FALSE) wavPlot(Z = -log2(wsd$wsd), X = wsd$t, Y = wsd$scales, Ylog = TRUE, coi = wsd$coi, rdist = wsd$rdist, sig95 = wsd$signif95, sig05 = wsd$signif05, Xname = "Time", Yname = "Scale", Zname = "-log2(WSD)") ## End(Not run)
This function computes the windowed scale indices of a signal in the scale
interval , for a given set of scale parameters
and taking
as the minimum scale (see Benítez et al. 2010).
The windowed scale index of a signal in the scale interval centered at
time
and with time windows radius
windowrad
is given by the quotient
where is the corresponding windowed scalogram with time windows
radius
windowrad
, is the smallest scale such that
for all
,
and
is the smallest scale such that
for all
.
windowed_scale_index(signal = NULL, wsc = NULL, wsc_coi = NULL, dt = 1, scales = NULL, powerscales = TRUE, s1 = NULL, windowrad = NULL, delta_t = NULL, wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, waverad = NULL, border_effects = c("BE", "INNER", "PER", "SYM"), makefigure = TRUE, time_values = NULL, figureperiod = TRUE, plot_wsc = FALSE, xlab = "Time", ylab = NULL, main = "Windowed Scale Index", zlim = NULL)
windowed_scale_index(signal = NULL, wsc = NULL, wsc_coi = NULL, dt = 1, scales = NULL, powerscales = TRUE, s1 = NULL, windowrad = NULL, delta_t = NULL, wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, waverad = NULL, border_effects = c("BE", "INNER", "PER", "SYM"), makefigure = TRUE, time_values = NULL, figureperiod = TRUE, plot_wsc = FALSE, xlab = "Time", ylab = NULL, main = "Windowed Scale Index", zlim = NULL)
signal |
A vector containing the signal whose windowed scale indices are wanted. |
wsc |
A matrix containing the windowed scalograms from which the windowed scale
indices are going to be computed (number of times x number of scales, as it is returned
by the |
wsc_coi |
A vector of length |
dt |
Numeric. The time step of the signal. |
scales |
A vector containing the wavelet scales at wich the windowed scalograms
are computed. This can be either a vector with all the scales or, following Torrence
and Compo 1998, a vector of 3 elements with the minimum scale, the maximum scale and
the number of suboctaves per octave. In the first case, |
powerscales |
Logical. It must be TRUE (default) only in these cases:
Otherwise, it must be |
s1 |
A vector containing the scales |
windowrad |
Integer. Time radius for the windows, measured in dt. By default,
it is set to |
delta_t |
Integer. Increment of time for the construction of windows central
times, measured in |
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 |
border_effects |
A 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.
|
makefigure |
Logical. If TRUE (default), a figure with the windowed scale indices is plotted. |
time_values |
A numerical vector of length |
figureperiod |
Logical. If TRUE (default), periods are used in the figure instead of scales. |
plot_wsc |
Logical. If TRUE, it plots the windowed scalograms from which the windowed scale indices are computed. |
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 "s1" or "Period of s1" depending on the value of |
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). |
A list with the following fields:
wsi
: A matrix of size length(tcentral)
x length(s1)
containing the values of the corresponding windowed scale indices.
s0
: The scale .
s1
: The vector of scales .
smax
: A matrix of size length(tcentral)
x length(s1)
containing the scales .
smin
: A matrix of size length(tcentral)
x length(s1)
containing the scales .
wsc
: A matrix of size length(tcentral)
x length(scales)
containing the windowed scalograms from which the windowed scale indices are computed.
scalog_smax
: A matrix of size length(tcentral)
x length(s1)
containing the values of the corresponding scalograms at scales .
scalog_smin
: A matrix of size length(tcentral)
x length(s1)
containing the values of the corresponding scalograms at scales .
tcentral
: The vector of central times used in the computation of
wsi
.
windowrad
: Radius for the time windows, measured in dt
.
fourierfactor
: A factor for converting scales into periods.
coi_maxscale
: A vector of length length(tcentral)
containing the
values of the maximum scale at each time from which there are border effects.
R. Benítez, V. J. Bolós, M. E. Ramírez. A wavelet-based tool for studying non-periodicity. Comput. Math. Appl. 60 (2010), no. 3, 634-641.
dt <- 0.1 time <- seq(0, 50, dt) signal <- c(sin(pi * time), sin(pi * time / 2)) # First, we try with default s1 scales (a vector with a wide range of values for s1). wsi_full <- windowed_scale_index(signal = signal, dt = dt, figureperiod = FALSE) # Next, we choose a meaningful s1 value, greater than all relevant scales. wsi <- windowed_scale_index(signal = signal, dt = dt, s1 = 4, figureperiod = FALSE) # Another way, giving the windowed scalograms instead of the signal: wsc <- windowed_scalogram(signal = signal, dt = dt, figureperiod = FALSE, energy_density = FALSE, makefigure = FALSE) wsi_full <- windowed_scale_index(wsc = wsc$wsc, wsc_coi = wsc$coi_maxscale, scales = wsc$scales, time_values = wsc$tcentral, figureperiod = FALSE) wsi <- windowed_scale_index(wsc = wsc$wsc, wsc_coi = wsc$coi_maxscale, scales = wsc$scales, s1 = 4, time_values = wsc$tcentral, figureperiod = FALSE)
dt <- 0.1 time <- seq(0, 50, dt) signal <- c(sin(pi * time), sin(pi * time / 2)) # First, we try with default s1 scales (a vector with a wide range of values for s1). wsi_full <- windowed_scale_index(signal = signal, dt = dt, figureperiod = FALSE) # Next, we choose a meaningful s1 value, greater than all relevant scales. wsi <- windowed_scale_index(signal = signal, dt = dt, s1 = 4, figureperiod = FALSE) # Another way, giving the windowed scalograms instead of the signal: wsc <- windowed_scalogram(signal = signal, dt = dt, figureperiod = FALSE, energy_density = FALSE, makefigure = FALSE) wsi_full <- windowed_scale_index(wsc = wsc$wsc, wsc_coi = wsc$coi_maxscale, scales = wsc$scales, time_values = wsc$tcentral, figureperiod = FALSE) wsi <- windowed_scale_index(wsc = wsc$wsc, wsc_coi = wsc$coi_maxscale, scales = wsc$scales, s1 = 4, time_values = wsc$tcentral, figureperiod = FALSE)
This function computes the normalized windowed scalograms of a signal for
the scales given. It is computed using time windows with radius windowrad
centered at a vector of central times with increment of time delta_t
. It is
important to note that the notion of scalogram here is analogous to the spectrum of the
Fourier transform. It gives the contribution of each scale to the total energy of the
signal. For each scale and central time
, it is defined as the square
root of the integral of the squared modulus of the wavelet transform w.r.t the time
variable
, i.e.
"Normalized" means that the windowed scalograms are divided by the square root of the length of the respective time windows in order to be comparable between them.
windowed_scalogram(signal, dt = 1, scales = NULL, powerscales = TRUE, windowrad = NULL, delta_t = NULL, wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, waverad = NULL, border_effects = c("BE", "INNER", "PER", "SYM"), energy_density = TRUE, makefigure = TRUE, time_values = NULL, figureperiod = TRUE, xlab = "Time", ylab = NULL, main = "Windowed Scalogram", zlim = NULL)
windowed_scalogram(signal, dt = 1, scales = NULL, powerscales = TRUE, windowrad = NULL, delta_t = NULL, wname = c("MORLET", "DOG", "PAUL", "HAAR", "HAAR2"), wparam = NULL, waverad = NULL, border_effects = c("BE", "INNER", "PER", "SYM"), energy_density = TRUE, makefigure = TRUE, time_values = NULL, figureperiod = TRUE, xlab = "Time", ylab = NULL, main = "Windowed Scalogram", zlim = NULL)
signal |
A vector containing the signal whose windowed scalogram is wanted. |
dt |
Numeric. The time step of the signal. |
scales |
A vector containing the wavelet scales at wich the windowed scalograms
are computed. This can be either a vector with all the scales or, following Torrence
and Compo 1998, a vector of 3 elements with the minimum scale, the maximum scale and
the number of suboctaves per octave. In the first case, |
powerscales |
Logical. It must be TRUE (default) only in these cases:
Otherwise, it must be |
windowrad |
Integer. Time radius for the windows, measured in |
delta_t |
Integer. Increment of time for the construction of windows central
times, measured in |
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 |
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.
|
energy_density |
Logical. If TRUE (default), divide the scalograms by the square root of the scales for convert them into energy density. |
makefigure |
Logical. If TRUE (default), a figure with the scalograms is plotted. |
time_values |
A numerical vector of length |
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 |
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). |
A list with the following fields:
wsc
: A matrix of size length(tcentral)
x length(scales)
containing the values of the windowed scalograms at each scale and at each time window.
tcentral
: The vector of central times at which the windows are centered.
scales
: The vector of the scales.
windowrad
: Radius for the time windows, measured in dt
.
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.
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.
R. Benítez, V. J. Bolós, M. E. Ramírez. A wavelet-based tool for studying non-periodicity. Comput. Math. Appl. 60 (2010), no. 3, 634-641.
dt <- 0.1 time <- seq(0, 50, dt) signal <- c(sin(pi * time), sin(pi * time / 2)) wscalog <- windowed_scalogram(signal = signal, dt = dt)
dt <- 0.1 time <- seq(0, 50, dt) signal <- c(sin(pi * time), sin(pi * time / 2)) wscalog <- windowed_scalogram(signal = signal, dt = dt)
This function computes the Windowed Scalogram Difference of two signals. The definition and details can be found in (Bolós et al. 2017).
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)
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)
signal1 |
A vector containing the first signal. |
signal2 |
A vector containing the second signal (its length should be equal to
that of |
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 |
rdist |
Integer. Log-scale radius for the windows measured in suboctaves. By
default, it is set to |
delta_t |
Integer. Increment of time for the construction of windows central
times, measured in |
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, |
refscale |
Numeric. The reference scale for |
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 |
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.
|
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 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 Finally, |
compensation |
Numeric. It is an alternative to |
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 |
parallel |
Logical. If TRUE, it uses function |
makefigure |
Logical. If TRUE (default), a figure with the WSD is plotted. |
time_values |
A numerical vector of length |
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 |
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). |
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.
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.
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)
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)