PyWavelets / pywt

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

wraparound in pywt.swt #277

Closed JoostJM closed 7 years ago

JoostJM commented 7 years ago

When performing swt using a Haar wavelet, the last index in the L-filter is calculated as 1/sqrt(2) * (index[-1] + index[0]), i.e. it seems as if the function wraps around. Is this intentional? I'm certainly no expert on wavelet transforms. Here is the output from some simple tests I did in jupyter:

Test1, length = 8 In: [5 4 3 0 0 0 0 0] Out-H: [ 6.364 4.9497 2.1213 0. 0. 0. 0. 3.5355] Out-L: [ 0.7071 0.7071 2.1213 0. 0. 0. 0. -3.5355]

Test2, length = 6 In: [5 4 3 0 0 0] Out-H: [ 6.364 4.9497 2.1213 0. 0. 3.5355] Out-L: [ 0.7071 0.7071 2.1213 0. 0. -3.5355]

Test3, reverse In: [0 0 0 0 0 3 4 5] Out-H: [ 0. 0. 0. 0. 2.1213 4.9497 6.364 3.5355] Out-L: [ 0. 0. 0. 0. -2.1213 -0.7071 -0.7071 3.5355]

Test4, reverse with extra padding In: [0 0 0 0 0 3 4 5 0 0] Out-H: [ 0. 0. 0. 0. 2.1213 4.9497 6.364 3.5355 0. 0. ] Out-L: [ 0. 0. 0. 0. -2.1213 -0.7071 -0.7071 3.5355 0. 0. ]

Test5, discreet instead of stationary wavelet transform In: [5 4 3 0 0 0 0 0] Out-H: [ 6.364 2.1213 0. 0. ] Out-L: [ 0.7071 2.1213 0. 0. ]

3.5355 is equal to 1/sqrt(2) * 5

grlee77 commented 7 years ago

Yes, the edge mode is periodization for the SWT transforms. This is basically like periodic, but handles odd-sized inputs a bit differently. (IIRC, for odd input the last sample is duplicated to make an even sized signal and then the even sized signal is filtered using periodic boundary conditions).

The DWT routines have a variety of other edge modes implemented, but the SWT routines do not.

JoostJM commented 7 years ago

@grlee77 Thanks for the comment!