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