max_swt_level

Function max_swt_level 

Source
pub fn max_swt_level(signal_length: usize, filter_length: usize) -> usize
Expand description

Calculate maximum decomposition level for SWT

The maximum level J is constrained by: 2^J * (L-1) < N where:

  • J is the decomposition level
  • L is the filter length (number of wavelet coefficients)
  • N is the signal length

This constraint is identical to MODWT because SWT also uses filter dilation (the à trous algorithm) without downsampling. At level J, the filter is upsampled by inserting 2^J - 1 zeros between coefficients.

§Why this constraint exists:

The à trous (“with holes”) algorithm inserts zeros between filter coefficients at each level. At level J:

  • The dilated filter spans (2^J * (L-1) + 1) samples
  • This span must fit within the signal length N for valid convolution

§Examples

  • Signal length 1024, Haar wavelet (L=2): max level = 9

    • At level 9: filter has 2^9 = 512 zeros between coefficients
  • Signal length 100, DB2 wavelet (L=4): max level = 5

    • At level 5: effective filter length = 2^5 * 3 + 1 = 97 < 100 ✓
    • At level 6: effective filter length = 2^6 * 3 + 1 = 193 > 100 ✗

§Comparison with DWT

DWT can typically go deeper because it downsamples at each level, halving the data size. SWT and MODWT maintain all coefficients, limiting the maximum decomposition depth by the filter dilation constraint.