feat(cwt): add icwt for cmor wavelets via Torrence & Compo (1998)#135
Open
MilaGolomozin wants to merge 1 commit into
Open
feat(cwt): add icwt for cmor wavelets via Torrence & Compo (1998)#135MilaGolomozin wants to merge 1 commit into
MilaGolomozin wants to merge 1 commit into
Conversation
Implements the inverse continuous wavelet transform (icwt) for complex Morlet (cmor) wavelets using the reconstruction formula from: Torrence, C. and Compo, G.P. (1998). A Practical Guide to Wavelet Analysis. BAMS 79(1), pp. 61-78. Eq. 11-13. Changes: - Add _cdelta_cmor() to compute the wavelet-dependent reconstruction constant C_delta (T&C Eq. 13) via numerical integration - Add icwt() accepting ContinuousWavelet | str, torch.Tensor input, and returning a torch.Tensor; GPU/autograd compatible - Export icwt from ptwt.__init__ Tests added to tests/test_continuous_transform.py: - test_cwt_cmor: forward CWT correctness for cmor wavelets (gap in existing test coverage; cmor requires parametrised B-C values unlike fixed-name wavelets such as mexh or cgau) - test_icwt: finiteness and valid C_delta across three cmor wavelets and two scale densities - test_icwt_cdelta_valid: C_delta is finite and positive for a range of cmor B/C parameter combinations - test_icwt_rejects_non_cmor: ValueError is raised for unsupported wavelet families (mexh, morl, cgau1, gaus1) - test_icwt_accepts_wavelet_object: icwt accepts both str and pywt.ContinuousWavelet, consistent with the cwt interface - test_icwt_cuda: output tensor lives on the same device as the input coefficients (CPU and CUDA) Related to v0lta#134
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements an inverse continuous wavelet transform (
icwt) for complex Morlet (cmor) wavelets. The reconstruction follows Torrence & Compo (1998), Eq. 11–13:where$C_\delta$ is a wavelet-dependent reconstruction constant computed numerically from the cmor Fourier transfer function (T&C Eq. 13).
Changes:
Tests added to tests/test_continuous_transform.py:
Reconstruction quality
Evaluated on a mono voice recording (22050 Hz) using dynamic scales spanning
$B \in {0.5, 1.0, 1.5, 2.0, 2.5, 3.0}$ and $C \in {0.5, 1.0, 1.5, 2.0, 2.5, 3.0}$ .
20 Hz to Nyquist at 48 voices per octave, across all 36 combinations of
Metrics explained:
reconstruction
$|x - \alpha\hat{x}|2$, computed as
$\alpha = \langle x, \hat{x}\rangle / \langle \hat{x}, \hat{x}\rangle$.
A value far from 1.0 indicates a residual amplitude offset in $C\delta$
for that wavelet/scale configuration.
shape fidelity from amplitude error
Top 5 wavelets by alpha-calibrated RMSE:
Limitations / future work
require separate derivations of
future PRs.
for extreme
B/Cvalues this grid may need tuning.suggesting a systematic amplitude factor in
convention that warrants further investigation.
The reconstruction quality is comparable to MATLAB's icwt implementation and captures the frequency content of the original signal well.
The method is not perfect, but to my knowledge no open-source PyTorch alternative currently exists, making this a useful stepping stone for the community.
Additional evaluation material (spectrograms, extended comparisons) is available on request.
Related to #134