CASCADE
The cascade algorithm (also known as the vector cascade algorithm) iteratively computes the values of the scaling function (phi) and the wavelet function (psi) at dyadic points starting from the filter coefficients.
The resulting functions are vital for constructing discrete wavelet transforms.
Excel Usage
=CASCADE(hk, J)
hk(list[list], required): Coefficients of the low-pass filter (Excel range).J(int, optional, default: 7): Number of iterations (level of resolution). Higher J means denser grid.
Returns (list[list]): A 2D array where the first row is the dyadic grid points, the second is phi(x), and the third is psi(x).
Example 1: Daubechies order 2 cascade
Inputs:
| hk | J | |||
|---|---|---|---|---|
| 0.48296291 | 0.8365163 | 0.22414387 | -0.12940952 | 2 |
Excel formula:
=CASCADE({0.48296291,0.8365163,0.22414387,-0.12940952}, 2)
Expected output:
| Result | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.25 | 0.5 | 0.75 | 1 | 1.25 | 1.5 | 1.75 | 2 | 2.25 | 2.5 | 2.75 |
| 0 | 0.63726 | 0.933013 | 1.10377 | 1.36603 | 0.341506 | 1.14347e-8 | -0.0915063 | -0.366025 | 0.0212341 | 0.0669873 | -0.0122595 |
| 0 | -0.170753 | -0.25 | -0.295753 | -0.366025 | 1.09151 | 1.73205 | -0.658494 | -1.36603 | 0.0792468 | 0.25 | -0.0457532 |
Python Code
Show Code
import numpy as np
from scipy.signal import cascade as scipy_cascade
def cascade(hk, J=7):
"""
Compute scaling and wavelet functions at dyadic points from filter coefficients.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.cascade.html
This example function is provided as-is without any representation of accuracy.
Args:
hk (list[list]): Coefficients of the low-pass filter (Excel range).
J (int, optional): Number of iterations (level of resolution). Higher J means denser grid. Default is 7.
Returns:
list[list]: A 2D array where the first row is the dyadic grid points, the second is phi(x), and the third is psi(x).
"""
try:
def to_1d(v):
if isinstance(v, list):
return np.array([float(x) for row in v for x in row])
return np.array([float(v)])
hk_arr = to_1d(hk)
x, phi, psi = scipy_cascade(hk_arr, J=int(J))
return [x.tolist(), phi.tolist(), psi.tolist()]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
Coefficients of the low-pass filter (Excel range).
Number of iterations (level of resolution). Higher J means denser grid.