-
-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
swt normalization and option to trim the approximation coefficients #476
Conversation
Looks like a very interesting enhancement.
If you have an example lying around already, that would be useful to add I think (perhaps as a demo instead of docstring example). |
7bf0544
to
5150c22
Compare
If trim_approx is set to True, we will retain approximation coefficients only for the final level of decomposition as is currently done for the DWT functions. add trim_approx option to all SWT transforms
TST: verify perfect round trip transform when norm=True as well
1.) energy preservation 2.) variance partition
allow output formats of 'swt', 'swt2' and 'swtn' (equivalent to 'wavedec', 'wavedec2', 'wavedecn')
5150c22
to
e2d7faa
Compare
fix links to Modes documentation
I rebased this and added a commit fixing up the docstrings as requested. If there are no further comments, I will plan to merge in a few days. |
Somehow the demo shown above got dropped from this PR at some point. I found it here and will make a separate PR to add it back in. |
Is trim_approx available in swt ? |
On Thu, Sep 26, 2019 at 3:24 PM mohammadAbdolhosseiniMoghaddam < ***@***.***> wrote:
Is trim_approx available in swt ?
I am using 1.0.3 version. The following is thrown error?
TypeError: swt() got an unexpected keyword argument 'trim_approx'
Any gelp is apperciated.
It is available only in the development version of the library. At the
moment you would need to build from source to have that feature.
However, I think it is probably about time to make a new release (1.1).
Once 1.1 is released you will be able to install the feature via pip or
conda.
Note that the documentation at https://pywavelets.readthedocs.io/ defaults
to the development branch and describe features not yet in an official
release. You can see documentation for a specific release instead via a
button near the lower right hand corner of the page.
|
This PR adds two optional arguments to
swt
,swt2
andswtn
that change the scaling of the coefficients and control which coefficients are retained.Option to discard unecessary approximation coefficients
The first option,
trim_approx
can be set true in order to keep only the approximation coefficients from the final level of decomposition. These are the only ones used by the inverse transform, so discarding the rest reduces memory use. There are also a couple of additional benefits:1.) when
trim_approx=True
the format of the coefficients returned is exactly the same as forwavedec
,wavedec2
andwavedecn
2.) Because of 1.), it becomes possible to also use the existing
pywt.ravel_coeffs
andpywt.unravel_coeffs
on the output of the SWT transforms.Option to use energy-preserving normalization
If we rescale the wavelet analysis filterbank by 1/sqrt(2), then the set of forward transform coefficients has the same energy as the original input. Additionally the sum of the variances of the individual coefficient arrays equals the variance of the input signal.
This makes the behavior very similar to the multiple-overlap DWT (MODWT) proposed by Percival and Walden in their book on time-series analysis. With
norm=True
andtrim_approx=True
swt can be used to recreate the type of things done with matlab's modwt and in the R package waveslim.Each commit here is well separated, so it might be easiest to review them sequentially.