PyWavelets / pywt

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

inconsistent wavelet coefficients #327

Closed macelee closed 6 years ago

macelee commented 7 years ago

I find that the wavelet coefficients as shown in the Wavelet Browser website are not exactly the same as those in pywt module.

For example from http://wavelets.pybytes.com/, if I select "Coiflets 1", then click 'Copy' next to the decomposition low-pass filter link, I get the following values:

-0.01565572813546454 -0.0727326195128539 0.38486484686420286 0.8525720202122554 0.3378976624578092 -0.0727326195128539

If I inspect these values using Python, I have slightly different values:

import pywt print pywt.version 0.5.2 w=pywt.Wavelet('coif1') w.dec_lo [-0.015655728135791993, -0.07273261951252645, 0.3848648468648578, 0.8525720202116004, 0.3378976624574818, -0.07273261951252645]

As can be seen these values only roughly match to 11 or 12 digits.

In some other cases, the differences are much larger. For example, for the 30th coefficients of the low-pass filter for decomposition, we have -0.00021208083980379827 vs -0.000212081862067494 (different at the 6th non-zero digit).

The difference is very large. After the wavelet transform I sometimes get bigger differences that cannot be ignored.

I wonder which set of data is more accurate and why there is this discrepancy.

grlee77 commented 7 years ago

The values are indeed a bit inconsistent because the http://wavelets.pybytes.com site is outdated. It was created by the original author of this package and is no longer actively maintained. Debauchies and Coiflet coefficients with extended precision were added 1-2 years ago in PR #164. See specifically the discussion in that PR and the reference highlighted here: https://github.com/PyWavelets/pywt/blame/52b1808c2353f1b78433e03e36301b63d3037749/pywt/_extensions/c/wavelets_coeffs.template.h#L18-L32

macelee commented 7 years ago

Thanks for your information. I am processing the "wavelets_coeffs.template" file using a script. Line 2131 of that file contains one extra comma in the end. Is that a problem?

grlee77 commented 6 years ago

I am processing the "wavelets_coeffs.template" file using a script. Line 2131 of that file contains one extra comma in the end. Is that a problem?

C is okay with trailing commas, but we could perhaps remove it for stylistic consistency with the other cases.

rgommers commented 6 years ago

Fixed in gh-413 by adding a disclaimer to the docs.