Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/source/ref/wavelet-packets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ WaveletPacket and Node
from the reconstruction.


When initialized with data, the packet remembers the input shape and
trims the reconstruction to that shape. When initialized with
``data=None``, the coefficients can correspond to signals of different
lengths, so the reconstruction may have extra samples at the end. To
have the packet trim the reconstruction automatically, initialize it
with a zero array of the original shape before assigning coefficients.


WaveletPacket2D and Node2D
~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
28 changes: 28 additions & 0 deletions doc/source/regression/wp.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,34 @@ print([n.path for n in new_wp.get_leaf_nodes(False)])
print([n.path for n in new_wp.get_leaf_nodes(True)])
```

### Preserving the original length

A packet initialized with `data=None` relies on the coefficient lengths,
which can correspond to more than one input length. The five-sample signal
below reconstructs to six samples. The extension adds the extra sample at
the end.

```{code-cell}
import numpy as np

signal = np.arange(1.0, 6.0)
source = pywt.WaveletPacket(signal, 'haar', maxlevel=1)
from_coefficients = pywt.WaveletPacket(None, 'haar', maxlevel=1)
for path in ('a', 'd'):
from_coefficients[path] = source[path].data
print(format_array(from_coefficients.reconstruct()))
```

Initialize the packet with zeros of the original shape to trim the
reconstruction automatically.

```{code-cell}
with_shape = pywt.WaveletPacket(np.zeros_like(signal), 'haar', maxlevel=1)
for path in ('a', 'd'):
with_shape[path] = source[path].data
print(format_array(with_shape.reconstruct()))
```

## Removing nodes from Wavelet Packet tree

Let's create some sample data:
Expand Down