Wavelets

Overview

Introduction Wavelet analysis is a signal-processing and multiresolution modeling framework that represents data using localized basis functions called wavelets, rather than global sinusoids alone. A wavelet is a short-duration oscillatory function with finite energy, and wavelet transforms decompose a signal into components that are simultaneously localized in scale (frequency-like behavior) and position (time or space). This locality is the core advantage over classical Fourier-only views: abrupt changes, transients, edges, and nonstationary behavior remain visible instead of being smeared across the entire domain. A practical reference for background is the Wikipedia entry on wavelets and wavelet transforms: https://en.wikipedia.org/wiki/Wavelet.

In business and engineering settings, this matters because many real datasets are not stationary. Demand spikes, sensor glitches, market shocks, mechanical defects, and image boundaries are localized events. Wavelets provide a disciplined way to separate coarse trends from fine details while preserving the timing/location of each feature. Boardflare’s wavelet tools are built on PyWavelets, the standard Python wavelet library, with NumPy array semantics behind the scenes. That combination gives users production-grade numerical routines while keeping an Excel-friendly interface.

Conceptually, wavelets support two major transform families. The continuous wavelet transform (CWT) probes a signal at many scales and translations, producing a scaleogram-like coefficient map for exploration. The discrete wavelet transform (DWT) uses dyadic filter banks for compact decomposition, ideal for denoising, compression, feature extraction, and hierarchical reconstruction. In this category, CWT_PYWT covers continuous analysis; DWT, WAVEDEC_PYWT, DWT2, IDWT, WAVEREC, DOWNCOEF, UPCOEF, and THRESHOLD_PYWT cover the discrete workflow from decomposition through selective reconstruction and denoising.

From a modeling perspective, wavelets are best viewed as a structured pipeline rather than isolated formulas. First, decompose the signal into approximation and detail coefficients. Second, decide which scales or orientations carry meaningful information versus noise. Third, manipulate coefficients (for example, by thresholding). Fourth, reconstruct either the full signal or selected components. This pipeline aligns naturally with board-level analytics goals: explainability (which scales matter), robustness (noise suppression), and scenario testing (what changes when high-frequency content is removed).

When to Use It Use wavelets when the core job is to understand or transform data that changes behavior over time/space, especially when short-lived events are important.

A common business case is operations and condition monitoring. Suppose a manufacturing team tracks vibration from rotating equipment and needs early fault detection before catastrophic failure. Fourier spectra identify dominant frequencies but often miss when and where impulsive faults emerge. A wavelet workflow can use CWT_PYWT to identify transient energy bursts by scale and time, WAVEDEC_PYWT to isolate detail levels associated with bearing defects, and THRESHOLD_PYWT plus WAVEREC to denoise while preserving diagnostically relevant impulses. The result is earlier, more actionable maintenance signals and fewer false alarms.

A second scenario is financial or demand-series analysis where regimes shift rapidly. Retail demand, intraday traffic, and market microstructure series all contain trend, seasonal structure, and high-frequency irregularities. A team can apply DWT or multilevel WAVEDEC_PYWT to separate slow-moving demand baseline from short-term shocks, then reconstruct smoothed forecasts with IDWT or WAVEREC. If users need only one branch (approximation for trend or detail for volatility), DOWNCOEF and UPCOEF provide efficient targeted extraction and reconstruction without handling the full decomposition tree.

A third scenario is image and matrix-like data in quality control or geospatial analysis. In 2D, directional details are often more informative than raw intensity. DWT2 decomposes a matrix into approximation plus horizontal/vertical/diagonal detail subbands, which helps distinguish edge orientation, texture changes, or structural defects. This is useful for automated inspection pipelines where horizontal streaks, vertical scratches, or diagonal artifacts may correspond to different root causes.

Wavelets are also appropriate when teams need robust denoising without losing edge structure. Moving averages and low-pass filters can overly blur transitions. Coefficient-domain shrinkage with THRESHOLD_PYWT typically preserves sharp events better by suppressing small noisy coefficients while keeping significant structures. In quality dashboards, this often improves both visual interpretability and downstream model stability.

Finally, wavelets are valuable in model feature engineering. Detail coefficients at specific scales can become features for anomaly detection, classification, or forecasting models. Coarse approximations capture baseline dynamics; finer details capture rapid deviations. This multiscale feature set is often more expressive than single-resolution statistics.

How It Works Wavelet transforms can be described with two related but distinct frameworks.

For continuous analysis, the CWT of signal x(t) with mother wavelet \psi is:

W_x(a,b)=\frac{1}{\sqrt{|a|}}\int_{-\infty}^{\infty} x(t)\,\psi^*\!\left(\frac{t-b}{a}\right) dt

where a is scale and b is translation. Large a captures coarse structure (lower pseudo-frequency), small a captures fine structure (higher pseudo-frequency). CWT_PYWT returns coefficients across user-specified scales and associated pseudo-frequencies, enabling a time-scale map of activity.

For discrete analysis, DWT is implemented via analysis filter banks. At each level, the signal is passed through low-pass and high-pass filters and downsampled by 2:

cA[k]=\sum_n x[n]h[2k-n], \qquad cD[k]=\sum_n x[n]g[2k-n]

with h and g derived from the selected wavelet family (for example Daubechies or Symlets). The approximation cA contains coarse content; detail cD captures local variations. DWT performs this for one level, while WAVEDEC_PYWT recursively decomposes the approximation to produce

[cA_n, cD_n, cD_{n-1},\ldots,cD_1].

Reconstruction uses synthesis filters \tilde h, \tilde g and upsampling:

x[n]=\sum_k cA[k]\tilde h[n-2k] + \sum_k cD[k]\tilde g[n-2k].

IDWT handles one-level inverse reconstruction, and WAVEREC reconstructs from multilevel coefficients. If only a single branch is required, DOWNCOEF extracts one decomposition branch directly and UPCOEF reconstructs one branch contribution at a chosen level.

In 2D, separable transforms apply the same filter-bank logic along rows and columns. DWT2 outputs one approximation subband and three directional detail subbands (cH,cV,cD) corresponding to horizontal, vertical, and diagonal structures. This orientation-awareness is why 2D wavelets are widely used in image compression and defect detection.

Thresholding is typically applied to detail coefficients to suppress noise. Soft-threshold shrinkage is:

\hat w = \operatorname{sign}(w)\max(|w|-\lambda,0),

while hard thresholding is:

\hat w = w\,\mathbf{1}_{|w|\ge\lambda}.

THRESHOLD_PYWT implements these and additional modes (garrote, greater, less) from PyWavelets’ thresholding utilities.

There are several assumptions and implementation choices users should understand:

  1. Boundary extension mode matters. Options such as symmetric, periodization, and periodic change how edges are handled and can materially affect coefficients near boundaries.
  2. Wavelet family selection is a bias-variance tradeoff. Short-support wavelets preserve localization; smoother wavelets may represent smooth trends with fewer coefficients.
  3. Level selection controls resolution depth. Too few levels miss coarse structure; too many can over-fragment short signals.
  4. Coefficient interpretation is scale-dependent, not directly “frequency bins” in the Fourier sense.
  5. Denoising quality depends on threshold strategy and whether thresholds are level-specific.

From an implementation standpoint, Boardflare exposes stable PyWavelets operations in spreadsheet-compatible forms. Users can prototype in Excel-style workflows and still rely on the same mathematical operators used in Python pipelines. Official docs for transform APIs are in PyWavelets documentation, including CWT, DWT/IDWT, multilevel decomposition, and thresholding sections.

Practical Example Consider a predictive-maintenance team monitoring a pump with a 1 kHz vibration signal sampled every second in rolling windows. The team’s job is to detect emerging faults while reducing false positives from random noise.

Step 1 is exploratory localization. Analysts begin with CWT_PYWT on selected windows using a real-valued mother wavelet and a scale range tuned to expected mechanical frequencies. They inspect coefficient intensity by scale and time to identify intermittent bursts that align with potential impact events. This does not yet produce the final metric, but it reveals when anomalies appear and which scales are informative.

Step 2 is compact decomposition for production features. They switch to WAVEDEC_PYWT with a fixed wavelet and level chosen from validation windows. The resulting cA_n captures slow baseline behavior (machine operating regime), while detail bands capture fast impulses and harmonics. They compute per-level energy metrics:

E_j = \sum_k |cD_j[k]|^2

and track these as health indicators over time.

Step 3 is denoising prior to threshold-based alarms. On each detail band, the team applies THRESHOLD_PYWT with soft thresholding. A common approach is to set threshold per level with robust noise scale estimates, then shrink coefficients before reconstruction. This suppresses low-magnitude random fluctuations while retaining impulsive structures likely tied to real faults.

Step 4 is reconstruction and comparison. For full denoised signal reconstruction, they use WAVEREC. For explainability, they also reconstruct isolated contributions using UPCOEF from specific detail levels that historically correlate with known failure modes. This helps communicate to operations teams that alerts are driven by defined frequency-scale behavior, not a black-box score.

Step 5 is operational deployment and triage. In streaming mode, they run one-level DWT for fast incremental checks and escalate to deeper WAVEDEC_PYWT only when indicators cross preliminary thresholds. If a diagnostic notebook needs direct branch extraction, DOWNCOEF retrieves only approximation or detail coefficients to reduce processing and simplify visual checks. For matrix snapshots from multi-sensor arrays, DWT2 highlights directional structures that can reveal sensor-alignment or mounting issues.

Step 6 is inverse validation. During incident review, analysts verify reconstruction consistency with IDWT for one-level experiments and WAVEREC for multilevel pipelines. Reproducible inverse results are important for auditability and trust: teams can show exactly which coefficient manipulations produced the final denoised signal.

Compared with traditional Excel-only smoothing, this workflow gives clearer localization, better edge preservation, and scale-by-scale interpretability. Instead of one global smoothing knob, analysts control decomposition level, wavelet family, boundary mode, threshold strategy, and reconstruction path. That flexibility is the practical reason wavelets are a durable choice for noisy, nonstationary operational data.

How to Choose Choose tools by task stage: explore, decompose, manipulate, reconstruct.

graph TD
    A[Start with signal or matrix] --> B{Need time-scale map?}
    B -- Yes --> C[Use CWT_PYWT]
    B -- No --> D{1D or 2D data?}
    D -- 2D matrix --> E[Use DWT2]
    D -- 1D signal --> F{Single-level or multilevel?}
    F -- Single-level --> G[Use DWT]
    F -- Multilevel --> H[Use WAVEDEC_PYWT]
    H --> I{Need only one branch?}
    I -- Yes --> J[Use DOWNCOEF]
    I -- No --> K{Need denoising?}
    K -- Yes --> L[Use THRESHOLD_PYWT]
    L --> M[Use WAVEREC]
    K -- No --> M
    G --> N{Reconstruct one level?}
    N -- Yes --> O[Use IDWT]
    J --> P{Reconstruct branch contribution?}
    P -- Yes --> Q[Use UPCOEF]

Function Best for Key input decisions Strengths Limitations
CWT_PYWT Exploratory time-scale analysis scale grid, wavelet, method (conv/fft) Excellent localization of transients; intuitive scaleogram workflows Higher computational load; coefficient volume can be large
DWT Fast one-level 1D decomposition wavelet, boundary mode Simple, fast split into approximation/detail Only one resolution level
WAVEDEC_PYWT Full multilevel 1D decomposition wavelet, level, mode Hierarchical structure for denoising and features Requires level-selection discipline
DWT2 2D matrix/image decomposition wavelet, mode Directional details (H/V/D) for texture/edge analysis Single-level output in this interface
DOWNCOEF Direct access to one branch part (a/d), level Efficient when only one branch is needed Less context than full decomposition
THRESHOLD_PYWT Coefficient shrinkage and denoising threshold value, mode, substitute Flexible denoising behavior; easy to tune Poor thresholds can remove signal
IDWT One-level inverse reconstruction cA/cD arrays, wavelet, mode Ideal for controlled local experiments Not for full multilevel trees
WAVEREC Full multilevel reconstruction ordered coefficient rows, mode End-to-end reconstruction from multilevel coefficients Requires correct coefficient ordering
UPCOEF Reconstruct only approximation/detail contribution part, level, optional take Strong explainability for scale contributions Not a full generic inverse substitute

A practical decision policy is:

  • Use CWT_PYWT first when the timing of events is unknown and diagnostic exploration is primary.
  • Use DWT for lightweight pipelines or single-step filtering.
  • Use WAVEDEC_PYWT when denoising, multiscale feature extraction, or scale-wise interpretability is required.
  • Use DWT2 for spatial data where orientation-specific details matter.
  • Use THRESHOLD_PYWT after decomposition, not on raw data if the goal is wavelet denoising.
  • Use IDWT for one-level reconstructions and WAVEREC for multilevel inverse workflows.
  • Use DOWNCOEF and UPCOEF when teams need targeted branch analysis for diagnostics or report-friendly decomposition narratives.

If multiple options appear viable, default to the simplest pipeline that satisfies the business objective: one-level DWT and IDWT for quick smoothing tasks, multilevel WAVEDEC_PYWT and WAVEREC for production-grade denoising/feature workflows, and CWT_PYWT for forensic exploration of nonstationary events.

CWT_PYWT

This function computes the continuous wavelet transform (CWT) of a one-dimensional signal for a set of scales using a selected mother wavelet.

The transform measures similarity between the signal and scaled/shifted wavelets, producing coefficients indexed by scale and position. It also returns pseudo-frequencies corresponding to each scale.

For signal x(t) and wavelet \psi, the CWT at scale a and shift b is:

W_x(a,b)=\frac{1}{\sqrt{|a|}}\int_{-\infty}^{\infty}x(t)\,\psi^*\left(\frac{t-b}{a}\right)dt

Coefficients are returned as rows with frequencies included as the first row.

Excel Usage

=CWT_PYWT(data, scales, wavelet, sampling_period, method, axis)
  • data (list[list], required): Input signal values as an Excel range.
  • scales (list[list], required): Positive scales used for analysis.
  • wavelet (str, optional, default: “mexh”): Wavelet name.
  • sampling_period (float, optional, default: 1): Sampling period of the input signal (seconds).
  • method (str, optional, default: “conv”): Algorithm used for CWT computation.
  • axis (int, optional, default: -1): Axis index of the signal.

Returns (list[list]): A rectangular 2D range where the first row contains pseudo-frequencies and subsequent rows contain transform coefficients by scale.

Example 1: Mexican hat CWT with three scales

Inputs:

data scales wavelet sampling_period method axis
1 2 3 2 1 1 2 3 mexh 1 conv -1

Excel formula:

=CWT_PYWT({1,2,3,2,1}, {1,2,3}, "mexh", 1, "conv", -1)

Expected output:

Result
0.25 0.125 0.0833333
-0.730298 0.263894 1.54896 1.54896 0.263894
-0.223961 1.67159 3.16782 3.16782 1.67159
1.08292 2.54236 3.45789 3.45789 2.54236
Example 2: Morlet CWT using FFT method

Inputs:

data scales wavelet sampling_period method axis
0 1 0 -1 0 1 1 2 morl 0.5 fft -1

Excel formula:

=CWT_PYWT({0,1,0,-1,0,1}, {1,2}, "morl", 0.5, "fft", -1)

Expected output:

Result
1.625 0.8125
0.120407 -0.129497 -0.243535 0.248083 0.248083 -0.243535
-0.26446 -0.0684351 0.449466 -0.281727 -0.281727 0.449466
Example 3: Scalar signal is normalized to one-point input

Inputs:

data scales wavelet sampling_period method axis
5 1 2 gaus1 1 conv -1

Excel formula:

=CWT_PYWT(5, {1,2}, "gaus1", 1, "conv", -1)

Expected output:

Result
0.2 0.1
-2.81359
-1.38996
Example 4: Matrix data is flattened before transform

Inputs:

data scales wavelet sampling_period method axis
1 2 1 2 4 gaus2 1 conv -1
3 4

Excel formula:

=CWT_PYWT({1,2;3,4}, {1,2,4}, "gaus2", 1, "conv", -1)

Expected output:

Result
0.3 0.15 0.075
-0.418199 -0.0357481 0.186334 1.94042
-1.12753 0.393749 2.69092 3.60706
0.869678 2.72246 4.01056 4.14076

Python Code

Show Code
import numpy as np
import pywt

def cwt_pywt(data, scales, wavelet='mexh', sampling_period=1, method='conv', axis=-1):
    """
    Compute the continuous wavelet transform and associated pseudo-frequencies.

    See: https://pywavelets.readthedocs.io/en/latest/ref/cwt.html

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

    Args:
        data (list[list]): Input signal values as an Excel range.
        scales (list[list]): Positive scales used for analysis.
        wavelet (str, optional): Wavelet name. Valid options: Mexican Hat, Morlet, Gaussian1, Gaussian2. Default is 'mexh'.
        sampling_period (float, optional): Sampling period of the input signal (seconds). Default is 1.
        method (str, optional): Algorithm used for CWT computation. Valid options: Convolution, FFT. Default is 'conv'.
        axis (int, optional): Axis index of the signal. Default is -1.

    Returns:
        list[list]: A rectangular 2D range where the first row contains pseudo-frequencies and subsequent rows contain transform coefficients by scale.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        def flatten_numeric(matrix):
            flat = []
            for row in matrix:
                if not isinstance(row, list):
                    return None
                for item in row:
                    try:
                        flat.append(float(item))
                    except (TypeError, ValueError):
                        continue
            return flat

        data_vals = flatten_numeric(to2d(data))
        scale_vals = flatten_numeric(to2d(scales))

        if data_vals is None or scale_vals is None:
            return "Error: Invalid input - data and scales must be 2D lists"
        if len(data_vals) == 0:
            return "Error: Input must contain at least one numeric data value"
        if len(scale_vals) == 0:
            return "Error: Input must contain at least one numeric scale"

        coeffs, freqs = pywt.cwt(
            np.asarray(data_vals, dtype=float),
            np.asarray(scale_vals, dtype=float),
            wavelet=wavelet,
            sampling_period=float(sampling_period),
            method=method,
            axis=int(axis),
        )

        coeff_matrix = np.asarray(coeffs)
        if np.iscomplexobj(coeff_matrix):
            coeff_rows = np.abs(coeff_matrix).tolist()
        else:
            coeff_rows = coeff_matrix.tolist()

        rows = [np.asarray(freqs, dtype=float).tolist()] + [list(row) for row in coeff_rows]
        max_len = max(len(row) for row in rows)
        return [row + [""] * (max_len - len(row)) for row in rows]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input signal values as an Excel range.
Positive scales used for analysis.
Wavelet name.
Sampling period of the input signal (seconds).
Algorithm used for CWT computation.
Axis index of the signal.

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

Show 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.

DWT

This function computes a one-dimensional single-level discrete wavelet transform and returns approximation and detail coefficients.

The approximation coefficients capture low-frequency content and the detail coefficients capture high-frequency content. Both are produced by filtering and downsampling the input signal.

For filters h and g and signal x[n]:

cA[k]=\sum_n x[n]h[2k-n], \quad cD[k]=\sum_n x[n]g[2k-n]

Results are returned as two rows in a 2D range.

Excel Usage

=DWT(data, wavelet, wavelet_mode, axis)
  • 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.
  • axis (int, optional, default: -1): Axis index for decomposition.

Returns (list[list]): Two rows containing approximation and detail coefficients.

Example 1: Db1 transform on even-length signal

Inputs:

data wavelet wavelet_mode axis
1 2 3 4 db1 symmetric -1

Excel formula:

=DWT({1,2,3,4}, "db1", "symmetric", -1)

Expected output:

Result
2.12132 4.94975
-0.707107 -0.707107
Example 2: Db2 transform with periodic mode

Inputs:

data wavelet wavelet_mode axis
2 4 6 8 10 12 db2 periodic -1

Excel formula:

=DWT({2,4,6,8,10,12}, "db2", "periodic", -1)

Expected output:

Result
14.7985 4.62158 10.2784 14.7985
-4.24264 3.33067e-16 6.66134e-16 -4.24264
Example 3: Scalar input is normalized to one-point signal

Inputs:

data wavelet wavelet_mode axis
7 db1 symmetric -1

Excel formula:

=DWT(7, "db1", "symmetric", -1)

Expected output:

Result
9.89949
0
Example 4: Matrix input is flattened before transform

Inputs:

data wavelet wavelet_mode axis
1 2 sym2 periodization -1
3 4

Excel formula:

=DWT({1,2;3,4}, "sym2", "periodization", -1)

Expected output:

Result
2.82843 4.24264
-0.517638 1.93185

Python Code

Show Code
import numpy as np
import pywt

def dwt(data, wavelet, wavelet_mode='symmetric', axis=-1):
    """
    Perform a single-level one-dimensional discrete wavelet transform.

    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:
        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'.
        axis (int, optional): Axis index for decomposition. Default is -1.

    Returns:
        list[list]: Two rows containing approximation and detail coefficients.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        def flatten_numeric(matrix):
            values = []
            for row in matrix:
                if not isinstance(row, list):
                    return None
                for item in row:
                    try:
                        values.append(float(item))
                    except (TypeError, ValueError):
                        continue
            return values

        signal = flatten_numeric(to2d(data))
        if signal is None:
            return "Error: Invalid input - data must be a 2D list"
        if len(signal) == 0:
            return "Error: Input must contain at least one numeric value"

        c_a, c_d = pywt.dwt(np.asarray(signal, dtype=float), wavelet=wavelet, mode=wavelet_mode, axis=int(axis))
        row_a = np.asarray(c_a).tolist()
        row_d = np.asarray(c_d).tolist()
        max_len = max(len(row_a), len(row_d))
        return [row_a + [""] * (max_len - len(row_a)), row_d + [""] * (max_len - len(row_d))]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input signal values as an Excel range.
Wavelet name.
Signal extension mode.
Axis index for decomposition.

DWT2

This function computes a single-level two-dimensional discrete wavelet transform of a numeric matrix.

The transform separates the matrix into one approximation component and three directional detail components: horizontal, vertical, and diagonal. These components summarize structure at different orientations and scales.

For separable 2D analysis, filtering and downsampling are applied along both axes to produce:

(cA, cH, cV, cD)

where cA is approximation and cH,cV,cD are detail subbands.

Excel Usage

=DWT2(data, wavelet, wavelet_mode)
  • data (list[list], required): Input 2D numeric matrix as an Excel range.
  • wavelet (str, required): Wavelet name.
  • wavelet_mode (str, optional, default: “symmetric”): Signal extension mode.

Returns (list[list]): Four rows containing flattened cA, cH, cV, and cD coefficient arrays, padded to a rectangular range.

Example 1: Db1 transform on 2x2 matrix

Inputs:

data wavelet wavelet_mode
1 2 db1 symmetric
3 4

Excel formula:

=DWT2({1,2;3,4}, "db1", "symmetric")

Expected output:

Result
5
-2
-1
0
Example 2: Db2 transform on 4x4 matrix

Inputs:

data wavelet wavelet_mode
1 2 3 4 db2 periodic
5 6 7 8
9 10 11 12
13 14 15 16

Excel formula:

=DWT2({1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16}, "db2", "periodic")

Expected output:

Result
25.6603 22.1962 25.6603 11.8038 8.33975 11.8038 25.6603 22.1962 25.6603
-8 -8 -8 6.28037e-16 9.42055e-16 6.28037e-16 -8 -8 -8
-2 -2.22045e-16 -2 -2 -9.99201e-16 -2 -2 -2.22045e-16 -2
6.66134e-16 4.44089e-16 6.66134e-16 -7.42976e-16 -1.9908e-16 -7.42976e-16 6.66134e-16 4.44089e-16 6.66134e-16
Example 3: Transform using periodization mode

Inputs:

data wavelet wavelet_mode
2 0 2 0 sym2 periodization
1 3 1 3
4 2 4 2
3 1 3 1

Excel formula:

=DWT2({2,0,2,0;1,3,1,3;4,2,4,2;3,1,3,1}, "sym2", "periodization")

Expected output:

Result
2.63397 2.63397 5.36603 5.36603
-0.366025 -0.366025 0.366025 0.366025
-1.36603 -1.36603 -0.633975 -0.633975
2.36603 2.36603 -0.366025 -0.366025
Example 4: Scalar input is promoted to 1x1 matrix

Inputs:

data wavelet wavelet_mode
5 db1 symmetric

Excel formula:

=DWT2(5, "db1", "symmetric")

Expected output:

Result
10
0
0
0

Python Code

Show Code
import numpy as np
import pywt

def dwt2(data, wavelet, wavelet_mode='symmetric'):
    """
    Perform a single-level two-dimensional discrete wavelet transform.

    See: https://pywavelets.readthedocs.io/en/latest/ref/2d-dwt-and-idwt.html

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

    Args:
        data (list[list]): Input 2D numeric matrix 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'.

    Returns:
        list[list]: Four rows containing flattened cA, cH, cV, and cD coefficient arrays, padded to a rectangular range.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

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

        matrix = []
        for row in matrix_in:
            if len(row) == 0:
                return "Error: Input rows must not be empty"
            out_row = []
            for item in row:
                try:
                    out_row.append(float(item))
                except (TypeError, ValueError):
                    return "Error: Input must contain only numeric values"
            matrix.append(out_row)

        arr = np.asarray(matrix, dtype=float)
        if arr.ndim != 2:
            return "Error: Input must be two-dimensional"

        c_a, details = pywt.dwt2(arr, wavelet=wavelet, mode=wavelet_mode)
        c_h, c_v, c_d = details

        rows = [
            np.asarray(c_a).ravel().tolist(),
            np.asarray(c_h).ravel().tolist(),
            np.asarray(c_v).ravel().tolist(),
            np.asarray(c_d).ravel().tolist(),
        ]
        max_len = max(len(row) for row in rows)
        return [row + [""] * (max_len - len(row)) for row in rows]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input 2D numeric matrix as an Excel range.
Wavelet name.
Signal extension mode.

IDWT

This function performs the inverse single-level discrete wavelet transform and reconstructs a signal from approximation and detail coefficients.

Reconstruction applies synthesis filters and upsampling to combine low-frequency and high-frequency components into the original-domain signal.

If cA[k] and cD[k] are coefficients, reconstruction has the form:

x[n]=\sum_k cA[k]\tilde{h}[n-2k] + \sum_k cD[k]\tilde{g}[n-2k]

where \tilde{h} and \tilde{g} are synthesis filters associated with the wavelet.

Excel Usage

=IDWT(c_a, c_d, wavelet, wavelet_mode, axis)
  • c_a (list[list], required): Approximation coefficients as an Excel range.
  • c_d (list[list], required): Detail coefficients as an Excel range.
  • 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 simple db1 coefficients

Inputs:

c_a c_d wavelet wavelet_mode axis
2.12132034 4.94974747 -0.70710678 -0.70710678 db1 symmetric -1

Excel formula:

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

Expected output:

Result
1 2 3 4
Example 2: Reconstruct using approximation only

Inputs:

c_a c_d wavelet wavelet_mode axis
1.5 2.5 3.5 0 0 0 db2 periodic -1

Excel formula:

=IDWT({1.5,2.5,3.5}, {0,0,0}, "db2", "periodic", -1)

Expected output:

Result
1.54362 1.89718 2.25073 2.60428
Example 3: Reconstruct using detail only

Inputs:

c_a c_d wavelet wavelet_mode axis
0 0 0 1 -1 1 db2 symmetric -1

Excel formula:

=IDWT({0,0,0}, {1,-1,1}, "db2", "symmetric", -1)

Expected output:

Result
0.965926 -0.258819 -0.965926 0.258819
Example 4: Scalar coefficients are normalized to one-point arrays

Inputs:

c_a c_d wavelet wavelet_mode axis
1 0 db1 symmetric -1

Excel formula:

=IDWT(1, 0, "db1", "symmetric", -1)

Expected output:

Result
0.707107 0.707107

Python Code

Show Code
import numpy as np
import pywt

def idwt(c_a, c_d, wavelet, wavelet_mode='symmetric', axis=-1):
    """
    Reconstruct a one-dimensional signal from approximation and detail 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:
        c_a (list[list]): Approximation coefficients as an Excel range.
        c_d (list[list]): Detail coefficients 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'.
        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

        def flatten_numeric(matrix):
            values = []
            for row in matrix:
                if not isinstance(row, list):
                    return None
                for item in row:
                    try:
                        values.append(float(item))
                    except (TypeError, ValueError):
                        continue
            return values

        a_vals = flatten_numeric(to2d(c_a))
        d_vals = flatten_numeric(to2d(c_d))

        if a_vals is None or d_vals is None:
            return "Error: Invalid input - coefficient inputs must be 2D lists"
        if len(a_vals) == 0 and len(d_vals) == 0:
            return "Error: At least one coefficient set must contain numeric values"

        approx = None if len(a_vals) == 0 else np.asarray(a_vals, dtype=float)
        detail = None if len(d_vals) == 0 else np.asarray(d_vals, dtype=float)

        reconstructed = pywt.idwt(approx, detail, 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

Approximation coefficients as an Excel range.
Detail coefficients as an Excel range.
Wavelet name.
Signal extension mode.
Axis index for reconstruction.

THRESHOLD_PYWT

This function applies wavelet thresholding to each value in an input range using a selected threshold rule.

Soft thresholding shrinks magnitudes toward zero, hard thresholding keeps large magnitudes unchanged while replacing smaller values, and other supported modes implement alternative denoising behaviors.

For soft thresholding with threshold \lambda:

\hat{x}=\operatorname{sign}(x)\max(|x|-\lambda,0)

The output preserves the input matrix shape.

Excel Usage

=THRESHOLD_PYWT(data, value, threshold_mode, substitute)
  • data (list[list], required): Input numeric values as an Excel range.
  • value (float, required): Threshold value.
  • threshold_mode (str, optional, default: “soft”): Thresholding mode.
  • substitute (float, optional, default: 0): Replacement value for thresholded entries.

Returns (list[list]): Thresholded values in a 2D range matching input shape.

Example 1: Soft threshold on a single row

Inputs:

data value threshold_mode substitute
1 1.5 2 2.5 3 2 soft 0

Excel formula:

=THRESHOLD_PYWT({1,1.5,2,2.5,3}, 2, "soft", 0)

Expected output:

Result
0 0 0 0.5 1
Example 2: Hard threshold on a 2x3 matrix

Inputs:

data value threshold_mode substitute
1 2 3 2 hard 0
4 0.5 2.5

Excel formula:

=THRESHOLD_PYWT({1,2,3;4,0.5,2.5}, 2, "hard", 0)

Expected output:

Result
0 2 3
4 0 2.5
Example 3: Greater mode replaces values below threshold

Inputs:

data value threshold_mode substitute
1 2 3 4 2.5 greater -1

Excel formula:

=THRESHOLD_PYWT({1,2,3,4}, 2.5, "greater", -1)

Expected output:

Result
-1 -1 3 4
Example 4: Less mode replaces values above threshold

Inputs:

data value threshold_mode substitute
1 2 3 4 2.5 less 9

Excel formula:

=THRESHOLD_PYWT({1,2,3,4}, 2.5, "less", 9)

Expected output:

Result
1 2 9 9

Python Code

Show Code
import numpy as np
import pywt

def threshold_pywt(data, value, threshold_mode='soft', substitute=0):
    """
    Apply elementwise wavelet thresholding to numeric data.

    See: https://pywavelets.readthedocs.io/en/latest/ref/thresholding-functions.html

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

    Args:
        data (list[list]): Input numeric values as an Excel range.
        value (float): Threshold value.
        threshold_mode (str, optional): Thresholding mode. Valid options: Soft, Hard, Garrote, Greater, Less. Default is 'soft'.
        substitute (float, optional): Replacement value for thresholded entries. Default is 0.

    Returns:
        list[list]: Thresholded values in a 2D range matching input shape.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

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

        matrix = []
        for row in matrix_in:
            out_row = []
            for item in row:
                try:
                    out_row.append(float(item))
                except (TypeError, ValueError):
                    return "Error: Input must contain only numeric values"
            matrix.append(out_row)

        arr = np.asarray(matrix, dtype=float)
        result = pywt.threshold(arr, value=float(value), mode=threshold_mode, substitute=float(substitute))
        return np.asarray(result).tolist()
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input numeric values as an Excel range.
Threshold value.
Thresholding mode.
Replacement value for thresholded entries.

UPCOEF

This function reconstructs either approximation or detail contributions directly from one-dimensional wavelet coefficients at a specified level.

It applies inverse filtering and upsampling iteratively according to the selected level and reconstruction part.

The part selector chooses whether approximation (a) or detail (d) synthesis is performed.

This can be used to isolate coarse or fine-scale signal contributions from a coefficient vector.

Excel Usage

=UPCOEF(part, coeffs, wavelet, level, take)
  • part (str, required): Coefficient type to reconstruct.
  • coeffs (list[list], required): Input coefficient values as an Excel range.
  • wavelet (str, required): Wavelet name.
  • level (int, optional, default: 1): Reconstruction level.
  • take (int, optional, default: 0): If positive, truncate output length to this value.

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

Example 1: Approximation reconstruction at level one

Inputs:

part coeffs wavelet level take
a 1 2 3 db1 1 0

Excel formula:

=UPCOEF("a", {1,2,3}, "db1", 1, 0)

Expected output:

Result
0.707107 0.707107 1.41421 1.41421 2.12132 2.12132
Example 2: Detail reconstruction at level two

Inputs:

part coeffs wavelet level take
d 1 -1 1 db2 2 0

Excel formula:

=UPCOEF("d", {1,-1,1}, "db2", 2, 0)

Expected output:

Result
-0.0625 -0.108253 -0.13726 -0.170753 0.416266 0.837019 0.0915064 -0.341506 -0.524519 -0.774519 -0.0915064 0.341506 0.462019 0.666266 -0.0457532 -0.51226 -0.108253 0.0625
Example 3: Reconstruction truncated with take parameter

Inputs:

part coeffs wavelet level take
a 1 2 3 4 db1 2 6

Excel formula:

=UPCOEF("a", {1,2,3,4}, "db1", 2, 6)

Expected output:

Result
1 1 1 1.5 1.5 1.5
Example 4: Scalar coefficient input is normalized

Inputs:

part coeffs wavelet level take
d 1 db1 1 0

Excel formula:

=UPCOEF("d", 1, "db1", 1, 0)

Expected output:

Result
0.707107 -0.707107

Python Code

Show Code
import numpy as np
import pywt

def upcoef(part, coeffs, wavelet, level=1, take=0):
    """
    Reconstruct approximation or detail contribution from one-dimensional 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:
        part (str): Coefficient type to reconstruct. Valid options: Approximation, Detail.
        coeffs (list[list]): Input coefficient values as an Excel range.
        wavelet (str): Wavelet name.
        level (int, optional): Reconstruction level. Default is 1.
        take (int, optional): If positive, truncate output length to this value. Default is 0.

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

        matrix = to2d(coeffs)
        if not isinstance(matrix, list) or not all(isinstance(row, list) for row in matrix):
            return "Error: Invalid input - coeffs 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: Coeffs must contain at least one numeric value"

        output = pywt.upcoef(part=part, coeffs=np.asarray(values, dtype=float), wavelet=wavelet, level=int(level), take=int(take))
        return [np.asarray(output, dtype=float).tolist()]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Coefficient type to reconstruct.
Input coefficient values as an Excel range.
Wavelet name.
Reconstruction level.
If positive, truncate output length to this value.

WAVEDEC_PYWT

This function performs a multilevel one-dimensional discrete wavelet transform and returns approximation and detail coefficient arrays by level.

Decomposition repeatedly applies low-pass and high-pass filtering followed by downsampling. The first coefficient row is the coarsest approximation, followed by detail rows from coarse to fine scales.

At level j, coefficients are computed as:

cA_j[k]=\sum_n x_j[n]h[2k-n], \quad cD_j[k]=\sum_n x_j[n]g[2k-n]

with the next-level signal defined by x_{j+1}=cA_j.

Excel Usage

=WAVEDEC_PYWT(data, wavelet, wavelet_mode, level, axis)
  • 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: null): Decomposition level (empty uses maximum valid level).
  • axis (int, optional, default: -1): Axis index for decomposition.

Returns (list[list]): Coefficient rows ordered as [cA_n, cD_n, …, cD1], padded to a rectangular range.

Example 1: Two-level db1 decomposition

Inputs:

data wavelet wavelet_mode level axis
1 2 3 4 5 6 7 8 db1 symmetric 2 -1

Excel formula:

=WAVEDEC_PYWT({1,2,3,4,5,6,7,8}, "db1", "symmetric", 2, -1)

Expected output:

Result
5 13
-2 -2
-0.707107 -0.707107 -0.707107 -0.707107
Example 2: Db2 decomposition with automatic level

Inputs:

data wavelet wavelet_mode level axis
2 4 6 8 10 12 14 16 db2 symmetric -1

Excel formula:

=WAVEDEC_PYWT({2,4,6,8,10,12,14,16}, "db2", "symmetric", , -1)

Expected output:

Result
3.53553 4.62158 10.2784 15.9353 21.9203
-1.22474 3.33067e-16 6.66134e-16 4.44089e-16 1.22474
Example 3: Scalar input is normalized to one-point signal

Inputs:

data wavelet wavelet_mode level axis
5 db1 symmetric 1 -1

Excel formula:

=WAVEDEC_PYWT(5, "db1", "symmetric", 1, -1)

Expected output:

Result
7.07107
0
Example 4: Decomposition using periodization mode

Inputs:

data wavelet wavelet_mode level axis
3 1 0 4 8 6 5 2 sym2 periodization 2 -1

Excel formula:

=WAVEDEC_PYWT({3,1,0,4,8,6,5,2}, "sym2", "periodization", 2, -1)

Expected output:

Result
5.41418 9.08582
-5.96739 2.05232
-0.0947343 -0.647048 0.293494 -1.67303

Python Code

Show Code
import numpy as np
import pywt

def wavedec_pywt(data, wavelet, wavelet_mode='symmetric', level=None, axis=-1):
    """
    Compute a multilevel one-dimensional discrete wavelet decomposition.

    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:
        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 (empty uses maximum valid level). Default is None.
        axis (int, optional): Axis index for decomposition. Default is -1.

    Returns:
        list[list]: Coefficient rows ordered as [cA_n, cD_n, ..., cD1], padded to a rectangular range.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        def flatten_numeric(matrix):
            values = []
            for row in matrix:
                if not isinstance(row, list):
                    return None
                for item in row:
                    try:
                        values.append(float(item))
                    except (TypeError, ValueError):
                        continue
            return values

        signal = flatten_numeric(to2d(data))
        if signal is None:
            return "Error: Invalid input - data must be a 2D list"
        if len(signal) == 0:
            return "Error: Input must contain at least one numeric value"

        level_value = None if level is None else int(level)
        coeffs = pywt.wavedec(
            np.asarray(signal, dtype=float),
            wavelet=wavelet,
            mode=wavelet_mode,
            level=level_value,
            axis=int(axis),
        )

        rows = [np.asarray(coeff).tolist() for coeff in coeffs]
        max_len = max(len(row) for row in rows)
        return [row + [""] * (max_len - len(row)) for row in rows]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Input signal values as an Excel range.
Wavelet name.
Signal extension mode.
Decomposition level (empty uses maximum valid level).
Axis index for decomposition.

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

Show 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.