PyWavelets / pywt

PyWavelets - Wavelet Transforms in Python
http://pywavelets.readthedocs.org
MIT License
1.97k stars 460 forks source link

allow calling CWT with discrete wavelets? #365

Open grlee77 opened 6 years ago

grlee77 commented 6 years ago

A user on the mailing list asked why Haar and Daubechies wavelets are not allowed for cwt. In Matlab R2012b, the cwt does allow using 'haar', 'db4', etc as the wavelet name. However, in R2016b Matlab apparently replaced their cwt with a new implementation that operates differently. Apparently the old cwt is still available as well.

I can verify that our existing code does actually already give the same coefficients as R2012b Matlab for the Daubechies wavelets if we change the following line:

https://github.com/PyWavelets/pywt/blob/bf7be1f4293b44a85a34dbce24b4f4573137775d/pywt/_cwt.py#L72

to

if hasattr(wavelet, 'complex_cwt') and wavelet.complex_cwt

so that an AttributeError is avoided.

I am not an expert in CWT analysis, so I don't know if there are strong use cases for these wavelets in a CWT analysis in practice.

arian-nik commented 3 years ago

One of the cases where CWT is useful is when derivative of a noisy signal is to be calculated. In this case, 'db' and 'sym' wavelets are useful depending on their vanishing moments. So modifying CWT to support these two popular wavelet families would broaden the applications of CWT in Python.

GraLu1992 commented 3 years ago

Facing the same issue that I want to use Daubechies wavelets for cwt. Are there any concerns about the theory behind it, or why hasn't this functionality been implemented yet? I've only done a cursory reading of wavelet transform theory so far, but as far as I understand the difference between dwt and cwt should really only be in the way the scaling and shifting parameters are discretized.

eqsols commented 2 years ago

Has there been any update to supporting Daubechies wavelet (e.g. db4) with CWT?

Yecaergi commented 3 weeks ago

Hello everyone! In the version of Matlab R2016a I did some work implementing the daubechies wavelet in the continuous wavelet transform, CWT. I need to replicate these results in Python. Searching different libraries, I notice that none of them have implemented cwt for this type of wavelets. I don't understand the theoretical reason behind it. Is there any progress on this? Could they be implemented in the CWT? I tried to implement @grlee77 's recommendation (put: if hasattr(wavelet, 'complex_cwt') and wavelet.complex_cwt, in line 72) but the code did not work.

eqsols commented 3 weeks ago

Hello, We found a workaround for this issue, which you can find below:

Yecaergi commented 3 weeks ago

Thank you so much @eqsols! The trick you gave me works perfectly. I compared some results with Matlab, using this type of wavelets from daubechies and others, and they are equivalent to those obtained in the pywt library. I would like to take this opportunity to ask you if we have any inverse continuous wavelet transform algorithm that allows us to reconstruct the signal with these incorporated wavelets. I did a fairly exhaustive search and this leads me to the icwt algorithm based on the paper by Torrence and compo (1998), which is not implemented for the wavelets we are talking about. Thank you very much for your contributions!

eqsols commented 3 weeks ago

For our use case, we only needed CWT with the db4 wavelet. So, unfortunately, we don't have an implementation of the inverse continuous wavelet transform algorithm.