Open grlee77 opened 6 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.
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.
Has there been any update to supporting Daubechies wavelet (e.g. db4) with CWT?
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.
Hello, We found a workaround for this issue, which you can find below:
DiscreteContinuousWavelet
class to include complex_cwt
and set it to False
#Hacky way of setting `complex_cwt` to `False` for `pywt.DiscreteContinuousWavelet` since pywt would give an error otherwise
ex = pywt.DiscreteContinuousWavelet('db4')
class DiscreteContinuousWaveletEx(type(ex)):
def __init__(self, name=u'', filter_bank=None):
super(type(ex), self)
pywt.DiscreteContinuousWavelet.__init__(self, name, filter_bank)
self.complex_cwt = False
DiscreteContinuousWaveletEx
call CWT on it
wavelet = DiscreteContinuousWaveletEx('db4')
pywt.cwt(signal, scales, wavelet)
Hopefully this should solve the problem. While we have not tested it, this should work with other wavelets, not just db4.
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!
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.
A user on the mailing list asked why Haar and Daubechies wavelets are not allowed for
cwt
. In Matlab R2012b, thecwt
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
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.