DOWNCOEF

This function computes one branch of a one-dimensional wavelet decomposition: either approximation or detail coefficients.

It applies analysis filtering and downsampling iteratively up to the requested level, returning only the selected branch.

The part selector chooses approximation (a) or detail (d) output.

This is useful when only one coefficient type is required instead of a full decomposition.

Excel Usage

=DOWNCOEF(part, data, wavelet, wavelet_mode, level)
  • part (str, required): Coefficient type to compute.
  • data (list[list], required): Input signal values as an Excel range.
  • wavelet (str, required): Wavelet name.
  • wavelet_mode (str, optional, default: “symmetric”): Signal extension mode.
  • level (int, optional, default: 1): Decomposition level.

Returns (list[list]): One-row coefficient values for the selected branch.

Example 1: Approximation coefficients at level one

Inputs:

part data wavelet wavelet_mode level
a 1 2 3 4 db1 symmetric 1

Excel formula:

=DOWNCOEF("a", {1,2,3,4}, "db1", "symmetric", 1)

Expected output:

Result
2.12132 4.94975
Example 2: Detail coefficients at level two

Inputs:

part data wavelet wavelet_mode level
d 1 2 3 4 5 6 7 8 db2 periodic 2

Excel formula:

=DOWNCOEF("d", {1,2,3,4,5,6,7,8}, "db2", "periodic", 2)

Expected output:

Result
4 -1.36603 1.09808 -4.09808
Example 3: Scalar input is normalized to one-point signal

Inputs:

part data wavelet wavelet_mode level
a 5 db1 symmetric 1

Excel formula:

=DOWNCOEF("a", 5, "db1", "symmetric", 1)

Expected output:

7.07107

Example 4: Matrix input is flattened before decomposition

Inputs:

part data wavelet wavelet_mode level
d 1 2 sym2 periodization 1
3 4

Excel formula:

=DOWNCOEF("d", {1,2;3,4}, "sym2", "periodization", 1)

Expected output:

Result
-0.517638 1.93185

Python Code

import numpy as np
import pywt

def downcoef(part, data, wavelet, wavelet_mode='symmetric', level=1):
    """
    Compute approximation or detail coefficients at a specified decomposition level.

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

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

    Args:
        part (str): Coefficient type to compute. Valid options: Approximation, Detail.
        data (list[list]): Input signal values as an Excel range.
        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'.
        level (int, optional): Decomposition level. Default is 1.

    Returns:
        list[list]: One-row coefficient values for the selected branch.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

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

        values = []
        for row in matrix:
            for item in row:
                try:
                    values.append(float(item))
                except (TypeError, ValueError):
                    continue

        if len(values) == 0:
            return "Error: Input must contain at least one numeric value"

        coeff = pywt.downcoef(part=part, data=np.asarray(values, dtype=float), wavelet=wavelet, mode=wavelet_mode, level=int(level))
        return [np.asarray(coeff, dtype=float).tolist()]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Coefficient type to compute.
Input signal values as an Excel range.
Wavelet name.
Signal extension mode.
Decomposition level.