PyWavelets / pywt

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

wave.wavefun does not return xs within proper support #313

Open carlosayam opened 7 years ago

carlosayam commented 7 years ago

As can be seen here, the values returned by wave.wavefun although correct in 𝜙 and ψ, have wrong values for xs as they are only valid for the scaling function, not the wavelet. As I see it, fixing this requires a breaking change in API

phi, psi, xs_phi, xs_psi = wave.wavefun(...)

and of course putting into place code for compactly supported wavelets, some sensible alternative for wavelets without compact support, and probably something for custom wavelets.

Happy to contribute with this or any alternative API change or addition that addresses this.

grlee77 commented 7 years ago

I think you are saying that the coordinates should be different for the wavelet by an integer shift? As a concrete example, for 'db2' the current xs is in the range [0, 3] while for the wavelet, xs_phi should be in the range [-1, 2]?

Additional contributors to the project are always welcome. The wavefun function is not one I have personally worked on. If you are interested in improving it, that would be appreciated. I would start by making a simple PR regarding just adding the xs_phi output to wavefun. Any new features can go in a separate PR.

probably something for custom wavelets

I think this already can be done? e.g. assuming you have a set of FIR filters defined:

w = pywt.Wavelet('my_wavelet', filterbank=(dec_lo, dec_hi, rec_lo, rec_hi))
w.orthogonal = True
phi, psi, xs_phi = w.wavefun()
carlosayam commented 7 years ago

Yes, that's what I meant. I will do a PR to have separate xs_phi and xs_psi in the output on wavefun.

I am using wavelets outside the context of filtering, as general approximation functions, and that information is critical for any algorithm working with them.

I will investigate is there is an easy way to infer support for father and mother wavelets from the filter definition; if I find something will use it.

Thanks for being open to this change :)

Also, keep in mind that this change will impact the "wavelet browser" site (is in this same repo, isn't it?)

grlee77 commented 7 years ago

I am using wavelets outside the context of filtering, as general approximation functions, and that information is critical for any algorithm working with them.

Great. If you have any simple demo along those lines that uses the new xs_phi, you could add a file to the demo subfolder of the repository to illustrate its use.

Also, keep in mind that this change will impact the "wavelet browser" site (is in this same repo, isn't it?)

Actually, that site was created long ago and I don't believe it is any longer actively maintained. For instance, there are additional Debauchies (up to db38) and Coiflet (up to coif17) wavelets available in PyWavelets that do not show up on that site. We should update the documentation to reflect that.

demo/plot_wavelets_pyqtgraph.py is a demo (requiring PyQtGraph) that serves a similar function and plots all of the current discrete wavelets. The older demo/plot_wavelets.py only requires Matplotlib, but does not plot every wavelet in each family. Those two functions would be very easy to update to use xs_phi in the plots for the wavelets.

carlosayam commented 7 years ago

Thanks Gregory for your guidance; I will get onto it.