PyWavelets / pywt

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

generalized morse wavelets #544

Open apatlpo opened 4 years ago

apatlpo commented 4 years ago

I'd like to use generalized Morse wavelets for an analysis and am under the impression that it is not implemented in pywt. These wavelets are defined by in the frequency domain: image where U(\omega) is the unit step function.

Do you believe we could add this to pywt ? If yes, what would be the roadmap to do this?

grlee77 commented 4 years ago

Do you believe we could add this to pywt ?

Yes, I think it would be a good addition.

If yes, what would be the roadmap to do this?

We only have a handful of contributors working in their spare time, and I don't personally have a lot of experience with the continuous wavelet transform or these wavelets. I am happy to help with reviewing and getting things merged if you or others come up with an implementation. We can provide some guidance on how to get started if you are interested in working on it.

Sometimes it is possible to port an existing implementation from another open source software package. However, before going this route, please make sure the underlying code is based on a permissive license like MIT or BSD, otherwise we will not be able to include it.

apatlpo commented 4 years ago

Do you think the spectral definition of the wavelet may be a problem?

I came across the following library otherwise [ninwavelets(https://github.com/uesseu/ninwavelets). I have the feeling I could also try a scipy implementation.

mattbit commented 4 years ago

Hi, I’m also interested in implementing Morse wavelets. The Generalized Morse Wavelets proposed in [1] were implemented by the authors in the jLab Matlab toolbox which can be used as a reference. There's also a partial Python translation available here. I'm not familiar with PyWavelets internals, where shoud we start?

[1]: Lilly, Jonathan M., and Sofia C. Olhede. "Generalized Morse wavelets as a superfamily of analytic wavelets." IEEE Transactions on Signal Processing 60.11 (2012): 6036-6041.

grlee77 commented 4 years ago

Hi @mattbit. In terms of implementation, the wavelets themselves are defined in C and Cython code. Specifically for the CWT, the primary files that would need to be modified are:

pywt/_extensions/c/_cwt.template.h
pywt/_extensions/c/_cwt.template.c
pywt/_extensions/_cwt.pyx
pywt/_extensions/wavelets_list.pxi

and possibly the ContinuousWavelet class in pywt/_extensions/_cwt.pyx They would need to be implemented in a way that is consistent with the other continuous wavelets in those files.

grlee77 commented 4 years ago

Also, I am not a licensing expert, but I don't know that it is okay to work from that jLab Matlab toolbox code unless you were to get specific permission from the authors. While open source, their license terms specifically forbid commercial applications, so it is a more restrictive license than the one used by PyWavelets.

mattbit commented 4 years ago

Hi @grlee77, thanks for your response. I had a look at the PyWavelet code and I understand that the wavelet functions are defined in pywt/_extensions/c/_cwt.templace.c. The problem—as already pointed out by @apatlpo—is that Morse wavelets are naturally defined in the frequency space, so the calculation of the wave function would require an inverse FFT in the Cython/C code, if we want to keep consistency with the existing structure. I will have a look to understand how this can be implemented, but I’m open to suggestions. Of course, the best thing would be to compute the CWT convolution directly in frequency space, but that would mean changing quite a lot of code (as far as I understand, the current implementation does not allow for wavelet defined in the frequency domain and the code in pywt/_cwt only deals with the time-domain case). What's your opinion?

P.S: about the jLab code, I checked it and I think that it's not necessary, all what we need is described in the published that I article mentioned above. On the other hand, I guess that we can use Matlab to generate some test data and benchmark our implementation.

apatlpo commented 4 years ago

my last thoughts on this was to first give a try at scipy cwt implementation before considering an implementation in pywt. The implementation in spectral space seemed easier there. Did you try that @mattbit ?

mattbit commented 4 years ago

Did you try that @mattbit ?

Not yet, I will have a look, thanks :)

OverLordGoldDragon commented 3 years ago

p.s., I'll likely have it ported from jLab within a few weeks at ssqueezepy.