WAVEREC

This function reconstructs a one-dimensional signal from multilevel discrete wavelet decomposition coefficients.

The coefficient input is interpreted as rows in the order produced by multilevel decomposition: approximation followed by detail levels. Each row may have different length and can be provided as a padded rectangular range.

Reconstruction applies synthesis filtering and upsampling repeatedly across levels to recover the signal estimate.

If the coefficient sequence is [cA_n, cD_n, \ldots, cD_1], inverse reconstruction combines all levels to produce the final signal.

Excel Usage

=WAVEREC(coeffs, wavelet, wavelet_mode, axis)
  • coeffs (list[list], required): Coefficient rows ordered as [cA_n, cD_n, …, cD1], with optional blank padding.
  • wavelet (str, required): Wavelet name.
  • wavelet_mode (str, optional, default: “symmetric”): Signal extension mode.
  • axis (int, optional, default: -1): Axis index for reconstruction.

Returns (list[list]): One-row reconstructed signal values.

Example 1: Reconstruct from two-level db1 coefficient rows

Inputs:

coeffs wavelet wavelet_mode axis
5 13 db1 symmetric -1
-2 -2
-0.70710678 -0.70710678

Excel formula:

=WAVEREC({5,13;-2,-2;-0.70710678,-0.70710678,-0.70710678,-0.70710678}, "db1", "symmetric", -1)

Expected output:

Result
1 2 3 4 5 6 7 8
Example 2: Reconstruct from single-level db1 coefficient rows

Inputs:

coeffs wavelet wavelet_mode axis
2.12132034 4.94974747 db1 symmetric -1
-0.70710678 -0.70710678

Excel formula:

=WAVEREC({2.12132034,4.94974747;-0.70710678,-0.70710678}, "db1", "symmetric", -1)

Expected output:

Result
1 2 3 4
Example 3: Padded coefficient rows ignore blanks

Inputs:

coeffs wavelet wavelet_mode axis
2.12132034 4.94974747 db1 symmetric -1
-0.70710678 -0.70710678

Excel formula:

=WAVEREC({2.12132034,4.94974747,"";-0.70710678,-0.70710678,""}, "db1", "symmetric", -1)

Expected output:

Result
1 2 3 4
Example 4: Reconstruct using periodization mode

Inputs:

coeffs wavelet wavelet_mode axis
2.12132034 4.94974747 db1 periodization -1
-0.70710678 -0.70710678

Excel formula:

=WAVEREC({2.12132034,4.94974747;-0.70710678,-0.70710678}, "db1", "periodization", -1)

Expected output:

Result
1 2 3 4

Python Code

import numpy as np
import pywt

def waverec(coeffs, wavelet, wavelet_mode='symmetric', axis=-1):
    """
    Reconstruct a one-dimensional signal from multilevel wavelet coefficients.

    See: https://pywavelets.readthedocs.io/en/latest/ref/idwt-inverse-discrete-wavelet-transform.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        coeffs (list[list]): Coefficient rows ordered as [cA_n, cD_n, ..., cD1], with optional blank padding.
        wavelet (str): Wavelet name.
        wavelet_mode (str, optional): Signal extension mode. Valid options: Symmetric, Periodization, Zero, Constant, Smooth, Periodic, Reflect, Antisymmetric, Antireflect. Default is 'symmetric'.
        axis (int, optional): Axis index for reconstruction. Default is -1.

    Returns:
        list[list]: One-row reconstructed signal values.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        rows_in = to2d(coeffs)
        if not isinstance(rows_in, list) or not all(isinstance(row, list) for row in rows_in):
            return "Error: Invalid input - coeffs must be a 2D list"

        coeff_list = []
        for row in rows_in:
            vals = []
            for item in row:
                try:
                    vals.append(float(item))
                except (TypeError, ValueError):
                    continue
            if len(vals) > 0:
                coeff_list.append(np.asarray(vals, dtype=float))

        if len(coeff_list) < 2:
            return "Error: Coeffs must contain at least approximation and one detail row"

        reconstructed = pywt.waverec(coeff_list, wavelet=wavelet, mode=wavelet_mode, axis=int(axis))
        return [np.asarray(reconstructed, dtype=float).tolist()]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Coefficient rows ordered as [cA_n, cD_n, ..., cD1], with optional blank padding.
Wavelet name.
Signal extension mode.
Axis index for reconstruction.