pythonmatlabpywavelets

Non-supported wavelets in PyWavelets cwt()


I'm am refreshing my knowledge of wavelets by working through some of the examples in Fugal's book, "Conceptual Wavelets in Digital Signal Processing" (2006) using PyWavelets rather than Matlab. I have run into a problem in the very first introductory chapter. Mr. Fugal presents two examples of using the continuous wavelet transform (CWT) to solve a couple of problems. The first localizes a chirp in frequency and the second localizes a discontinuity in time. However, for the first Fugal uses the Db20 as the basis, and in the second he uses the Db4. The Db family is not one of the support wavelets that can be used by cwt().

I made a couple of substitutions (Complex Morlet for the chirp and Complex Shannon for the discontinuity) that seemed to work well. I was just wondering if there is some way to repeat Fugal's use of the Db family in PyWavelets with the cwt() function?


Solution

  • There is actually a workaround for this issue as mentioned here.
    You should first extend the DiscreteContinuousWavelet class to include complex_cwt:

    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
    

    After that, you can simply instantiate and use the wavelet like this:

    wavelet = DiscreteContinuousWaveletEx('db4')
    pywt.cwt(signal, scales, wavelet)