PyWavelets / pywt

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

How is CWT cmor wavelet defined? #735

Closed cyschneck closed 2 months ago

cyschneck commented 2 months ago

I am working on replicating behavior from Torrence and Compo in PyWavelets using the Complex Morlet function. The Morlet function in the Torrence and Compo is not a Morlet function, but a Complex Morlet function, so it should be similar to the cmor function in PyWavelets.

Previously, a cmor1.5-1.0 was recommended. While this is close, the wavelets do not match. Untitled

I think essentially the issue that I've encountered is that the definition of the Complex Morlet function in Torrence and Compo (Table 1) is: image

Whereas the PyWavelets Complex Morlet Wavelet is defined as: image

While this seems to match the equation for a Complex Morlet Wavelet that is in Matlab, the equation does not match the Torrence/Compo paper that is referenced at the top of the CWT page.

There does not doesn't appear to be any definitions of bandwidth and center frequency that can be used in cmor that will make the behaviors match since Torrence and Compo is using $\pi$^ (-0.25) and PyWavelets is using $\pi$ ^ (-0.5)

The wiki definition and SciPy's Morlet function (before it was deprecated) also appear to match the equation described in Torrence/Compo. Where does PyWavelet's definition of a Complex Morlet come from?

rgommers commented 2 months ago

Great question @cyschneck. Unfortunately I really don't know the answer. I think it's been like this since it was first written (before 2010).

cyschneck commented 2 months ago

Thanks, I'll have to keep digging

For future reference, based on some research I believe this originated from the same equation used for the Complex Morlet in Matlab from Computational Signal Processing with Wavelets

Teolis, Anthony. Computational Signal Processing with Wavelets. Boston, MA: Birkhäuser Boston, 1998. https://doi.org/10.1007/978-1-4612-4142-3. 

On page 65-66, the Morlet wavelet is referred to as: image image image Specifically, the (mother) Morlet wavelet is defined as: image Which seems to match PyWavelets: 321322221-f42a0cc8-5db3-414e-bad6-a9b0188aa073 I'll need to keep looking to see why it is defined differently in this one reference location compared to the more common definition I see elsewhere since both the Teolis book and the Torrence/Compo paper came out in the same year, but thanks!

cyschneck commented 2 months ago

While the amplitude is different, the closest match I've found is a bandwidth of sqrt(pi) and a center frequency of 6/2*pi (so it is close to the default Morlet of 6). The amplitude difference is the result of some constant that is missing that Torrence/Compo is using. I'll see if I can find where they derive their equation with the $\pi$^(-1/4) from Untitled

cyschneck commented 2 months ago

So, for future reference, using B=sqrt(pi) and C=6/2pi produces the graph above, with the same intersects along 0.0, but a smaller amplitude.

To generate a matching wavelet, B needs to somehow be both 2 and sqrt(pi) to match the Torrence and Compo formula:

image

To match, setting B=2 and multiplying the entire wavelet by a constant value sqrt(2)*pi^(1/4)

Untitled

rgommers commented 1 month ago

Thank you for all the details @cyschneck! I am sure this will help the next person who looks into this definition.