cultivars.spectral.wavelets#

Wavelet analysis: the MODWT multiresolution decomposition and Morlet wavelet coherence.

A spectrum answers “at which frequencies” and a filter “what is the cycle”; a wavelet decomposition answers both at once, by frequency band and by date. The maximal-overlap discrete wavelet transform of Percival and Walden filters a series through a pyramid of upsampled wavelet and scaling filters,

\[ \begin{align}\begin{aligned}W_{j,t} = \sum_{l} \tilde h_l\, V_{j-1,\,t - 2^{j-1} l}, \qquad y_t = \sum_{j=1}^{J} D_{j,t} + S_{J,t},\\\qquad \hat\nu^2_j = \frac{1}{M_j}\sum_{t \ge L_j - 1} W_{j,t}^2,\end{aligned}\end{align} \]

into details at dyadic period bands \([2^j, 2^{j+1})\) plus a smooth, additively, aligned in time, and defined for any sample length; the wavelet variance \(\hat\nu^2_j\) over the boundary-free coefficients is an analysis of variance by scale with a chi-squared band, the usual way to ask which horizon carries a series’ variability. Wavelet coherence, on Torrence and Compo’s continuous Morlet transform, is the smoothed local squared coherence of two series

\[R^2(s, t) = \frac{|S(W_{xy}/s)|^2}{S(|W_x|^2/s)\, S(|W_y|^2/s)}\]

across scale \(s\) and date \(t\), with the phase of the cross-wavelet reading which series leads; it is the instrument behind “co-movement of output and inflation at business-cycle frequencies broke down after 1985” and its like.

Two commitments shape the surface. First, both objects are descriptive and say so: the cone of influence marks where the transform’s edge padding is felt, the AR(1) surrogate level says how much coherence two independent persistent series produce by chance, and the MODWT’s degrees of freedom shrink by half per level so the deepest scales declare themselves uninformative – the results state where the picture can be trusted, not that a model holds. Second, the discrete and continuous transforms are kept to the questions each answers: the MODWT is additive and orthogonal-by-scale, so it decomposes one series; Morlet coherence is redundant and smooth, so it compares two. Neither is offered for the other’s job.

Layout. MODWT takes a series through transform into MODWTResult; WaveletCoherence takes two through compute into WaveletCoherenceResult. The numerics live in _core: _modwt_filters holds the Haar, D4 and LA8 filters rescaled for the MODWT, _modwt and _modwt_inverse run the pyramid and its inverse, _modwt_details the multiresolution analysis and _modwt_variance the unbiased variance with Percival-Walden’s \(\eta_3\) degrees of freedom; _morlet_transform and _morlet_scales give the continuous transform on its dyadic grid, _wavelet_smooth the Torrence-Webster smoothing, _wavelet_coherence the coherence and phase, _cone_of_influence the edge mask, and _coherence_surrogates the AR(1) significance level; _MORLET_OMEGA0, _SCALES_PER_OCTAVE, _COHERENCE_SURROGATES and _MIN_SPECTRUM_OBS are the defaults. _SummaryMixin from _internals gives both results their printed form. The Fourier-domain counterparts – a spectrum without a date axis – are periodogram and density; the band-pass filters that isolate a stated band rather than octaves are in band_pass.

References

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

Torrence, C., & Compo, G. P. (1998). A practical guide to wavelet analysis. Bulletin of the American Meteorological Society, 79(1), 61-78.

Grinsted, A., Moore, J. C., & Jevrejeva, S. (2004). Application of the cross wavelet transform and wavelet coherence to geophysical time series. Nonlinear Processes in Geophysics, 11, 561-566.

Gencay, R., Selcuk, F., & Whitcher, B. (2002). An Introduction to Wavelets and Other Filtering Methods in Finance and Economics. Academic Press.

Example

A common period-24 cycle that switches off halfway through the sample: coherence is significant in that band almost everywhere in the first half and almost nowhere in the second, which is the time-frequency statement no spectrum can make, and the MODWT of one series puts the cycle’s variance in the level whose band holds it:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> t = np.arange(512.0)
>>> common = np.sin(2 * np.pi * t / 24) * (t < 256)
>>> x = common + 0.5 * rng.standard_normal(512)
>>> y = np.roll(common, 4) + 0.5 * rng.standard_normal(512)
>>> res = WaveletCoherence(per_octave=4, surrogates=100, seed=0).compute(x, y)
>>> hit = res.significant()[(res.periods > 18) & (res.periods < 32)]
>>> round(float(hit[:, 40:216].mean()), 1), round(float(hit[:, 296:472].mean()), 1)
(0.9, 0.1)
>>> modwt = MODWT(levels=5).transform(x)
>>> int(np.argmax(modwt.variance)) + 1, modwt.periods[3]
(4, (16.0, 32.0))

Classes#

MODWT

Maximal-overlap discrete wavelet transform and multiresolution analysis.

MODWTResult

A MODWT decomposition: coefficients, additive components, and variance by scale.

WaveletCoherence

Morlet wavelet coherence of two series, with cone of influence and surrogate significance.

WaveletCoherenceResult

Squared wavelet coherence and phase of two series over scale and time.