DWT decomposition level

537 views
Skip to first unread message

Nathaniel Smith

unread,
Sep 16, 2009, 5:42:11 AM9/16/09
to pywav...@googlegroups.com, fi...@wasilewski.it
The documentation states: "The dwt_max_level() function can be used to
compute the maximum useful level of decomposition for the given input
data length and wavelet filter length."

Can anyone explain what "useful" means in this context? Why is
dwt_max_level defined the way it is? Other references I have been
looking at seem to assume that one will decompose "all the way", which
wavedec by default does not. I'm not particularly attached to these
references and conversely I understand how to use the level= argument
to override if necessary, but I am curious if there is some particular
advantage to this default.

-- Nathaniel

Filip Wasilewski

unread,
Sep 22, 2009, 11:13:02 AM9/22/09
to PyWavelets
Hi Nathaniel,

On 16 Wrz, 11:42, Nathaniel Smith <n...@pobox.com> wrote:
> The documentation states: "The dwt_max_level() function can be used to
> compute the maximum useful level of decomposition for the given input
> data length and wavelet filter length."
>
> Can anyone explain what "useful" means in this context?

Thanks for pointing this out. I should explain this in the
documentation.

> Why is
> dwt_max_level defined the way it is?

It is defined this way mainly because of a design decision to maintain
compatibility with Matlab Wavelet Toolbox as the leading commercial
wavelet processing software. The corresponding WT function is
http://www.mathworks.com/access/helpdesk/help/toolbox/wavelet/wmaxlev.html,
but there's also no good explanation why such formula was chosen.

In general, a decomposition is "useful" when:

a) decimation of coefficients takes place, so the length of
coefficients on two subsequent levels is reduced by at least half of
the length of the filter (otherwise there is no point in decomposing a
signal because there is no real gain).

b) decomposition coefficients still maintain characteristic of the
original signal and are not dominated by border distortion values. As
an illustration of such situation, please take a look at these
examples:

Default maximum level=1, zero-padding and symmetric signal extension
modes. Please note similarities on 2nd and 3rd position of the
corresponding arrays:

>>> x = [1,4,3,2,1,9]
>>> pprint.pprint(pywt.wavedec(x, 'db2', 'zpd'))
[array([-0.29349422, 4.24264069, 2.18137951, 8.01160965]),
array([-1.09533535, 0.51763809, -4.34666622, -2.14670433])]
>>> pprint.pprint(pywt.wavedec(x, 'db2', 'sym'))
[array([ 2.47487373, 4.24264069, 2.18137951, 9.89949494]),
array([-1.83711731, 0.51763809, -4.34666622, 4.89897949])]


Level=2, values completely dominated by signal extension method
artifacts:

>>> pprint.pprint(pywt.wavedec(x, 'db2', 'zpd', level=2))
[array([-0.61482304, 2.85945554, 7.75536749]),
array([-2.29455081, -2.95753175, -2.07804446]),
array([-1.09533535, 0.51763809, -4.34666622, -2.14670433])]
>>> pprint.pprint(pywt.wavedec(x, 'db2', 'sym', level=2))
[array([ 4.125 , 3.95216426, 11.27123412]),
array([-1.08253175, -4.22756351, 4.72636114]),
array([-1.83711731, 0.51763809, -4.34666622, 4.89897949])]

> Other references I have been
> looking at seem to assume that one will decompose "all the way", which
> wavedec by default does not.

I think most of the references assume 2^x signal lengths and zero-
padding which is a very specific situation that unfortunately often
contrasts with real world applications.

Of course choosing a decomposition strategy depends strictly on the
problem, but in many situation a full decomposition is not even needed
and using smaller level values like 3 or 5 is just enough.

Filip

--
http://filipwasilewski.pl/

Nathaniel Smith

unread,
Sep 22, 2009, 8:22:36 PM9/22/09
to pywav...@googlegroups.com
On Tue, Sep 22, 2009 at 8:13 AM, Filip Wasilewski
<filipwa...@gmail.com> wrote:
> On 16 Wrz, 11:42, Nathaniel Smith <n...@pobox.com> wrote:
>> Why is
>> dwt_max_level defined the way it is?
>
> It is defined this way mainly because of a design decision to maintain
> compatibility with Matlab Wavelet Toolbox as the leading commercial
> wavelet processing software. The corresponding WT function is
> http://www.mathworks.com/access/helpdesk/help/toolbox/wavelet/wmaxlev.html,
> but there's also no good explanation why such formula was chosen.

Looking on that page, they might have an actual explanation buried in
the example:
% The rule is the last level for which at least
% one coefficient is correct.
Of course, it still isn't totally clear what this means, but I assume
it's something like "the last level for which at least one coefficient
is unaffected by edge effects". That seems consistent with your
explanation below, and makes a lot of sense.

> In general, a decomposition is "useful" when:
>
> a) decimation of coefficients takes place, so the length of
> coefficients on two subsequent levels is reduced by at least half of
> the length of the filter (otherwise there is no point in decomposing a
> signal because there is no real gain).
>
> b) decomposition coefficients still maintain characteristic of the
> original signal and are not dominated by border distortion values. As
> an illustration of such situation, please take a look at these
> examples:

[...]

Thanks, that makes things clearer.

>> Other references I have been
>> looking at seem to assume that one will decompose "all the way", which
>> wavedec by default does not.
>
> I think most of the references assume 2^x signal lengths and zero-
> padding which is a very specific situation that unfortunately often
> contrasts with real world applications.
>
> Of course choosing a decomposition strategy depends strictly on the
> problem, but in many situation a full decomposition is not even needed
> and using smaller level values like 3 or 5 is just enough.

Yeah -- my problem is a little different, in that I'm using the DWT as
a whitening transform for 1/f noise, so there actually are benefits to
pushing the decomposition rather far. (Detail coefficients are
decorrelated while approximation coefficients aren't, really, so the
more detail coefficients the better.) With signal length 256, db4,
mode="per", empirically the sweet spot seems to be level=6 rather than
level=5, in fact. But it's very nice to understand better what's going
on. The literature I've found is not very good at explaining practical
matters in clear ways. Thanks!

-- Nathaniel

Reply all
Reply to author
Forward
0 new messages