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
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)}"