Stationary Wavelet Transform¶
Stationary Wavelet Transform (SWT), also known as Undecimated wavelet transform or Algorithme à trous is a translation-invariance modification of the Discrete Wavelet Transform that does not decimate coefficients at every transformation level.
Multilevel 1D swt
¶
-
pywt.
swt
(data, wavelet, level=None, start_level=0, axis=-1)¶ Multilevel 1D stationary wavelet transform.
Parameters: - data :
Input signal
- wavelet :
Wavelet to use (Wavelet object or name)
- level : int, optional
The number of decomposition steps to perform.
- start_level : int, optional
The level at which the decomposition will begin (it allows one to skip a given number of transform steps and compute coefficients starting from start_level) (default: 0)
- axis: int, optional
Axis over which to compute the SWT. If not given, the last axis is used.
Returns: - coeffs : list
List of approximation and details coefficients pairs in order similar to wavedec function:
[(cAn, cDn), ..., (cA2, cD2), (cA1, cD1)]
where n equals input parameter
level
.If
start_level = m
is given, then the beginning m steps are skipped:[(cAm+n, cDm+n), ..., (cAm+1, cDm+1), (cAm, cDm)]
Notes
The implementation here follows the “algorithm a-trous” and requires that the signal length along the transformed axis be a multiple of
2**level
. If this is not the case, the user should pad up to an appropriate size using a function such asnumpy.pad
.
Multilevel 2D swt2
¶
-
pywt.
swt2
(data, wavelet, level, start_level=0, axes=(-2, -1))¶ Multilevel 2D stationary wavelet transform.
Parameters: - data : array_like
2D array with input data
- wavelet : Wavelet object or name string, or 2-tuple of wavelets
Wavelet to use. This can also be a tuple of wavelets to apply per axis in
axes
.- level : int
The number of decomposition steps to perform.
- start_level : int, optional
The level at which the decomposition will start (default: 0)
- axes : 2-tuple of ints, optional
Axes over which to compute the SWT. Repeated elements are not allowed.
Returns: - coeffs : list
Approximation and details coefficients (for
start_level = m
):[ (cA_m+level, (cH_m+level, cV_m+level, cD_m+level) ), ..., (cA_m+1, (cH_m+1, cV_m+1, cD_m+1) ), (cA_m, (cH_m, cV_m, cD_m) ) ]
where cA is approximation, cH is horizontal details, cV is vertical details, cD is diagonal details and m is
start_level
.
Notes
The implementation here follows the “algorithm a-trous” and requires that the signal length along the transformed axes be a multiple of
2**level
. If this is not the case, the user should pad up to an appropriate size using a function such asnumpy.pad
.
Multilevel n-dimensional swtn
¶
-
pywt.
swtn
(data, wavelet, level, start_level=0, axes=None)¶ n-dimensional stationary wavelet transform.
Parameters: - data : array_like
n-dimensional array with input data.
- wavelet : Wavelet object or name string, or tuple of wavelets
Wavelet to use. This can also be a tuple of wavelets to apply per axis in
axes
.- level : int
The number of decomposition steps to perform.
- start_level : int, optional
The level at which the decomposition will start (default: 0)
- axes : sequence of ints, optional
Axes over which to compute the SWT. A value of
None
(the default) selects all axes. Axes may not be repeated.
Returns: - [{coeffs_level_n}, …, {coeffs_level_1}]: list of dict
Results for each level are arranged in a dictionary, where the key specifies the transform type on each dimension and value is a n-dimensional coefficients array.
For example, for a 2D case the result at a given level will look something like this:
{'aa': <coeffs> # A(LL) - approx. on 1st dim, approx. on 2nd dim 'ad': <coeffs> # V(LH) - approx. on 1st dim, det. on 2nd dim 'da': <coeffs> # H(HL) - det. on 1st dim, approx. on 2nd dim 'dd': <coeffs> # D(HH) - det. on 1st dim, det. on 2nd dim }
For user-specified
axes
, the order of the characters in the dictionary keys map to the specifiedaxes
.
Notes
The implementation here follows the “algorithm a-trous” and requires that the signal length along the transformed axes be a multiple of
2**level
. If this is not the case, the user should pad up to an appropriate size using a function such asnumpy.pad
.
Maximum decomposition level - swt_max_level
¶
-
pywt.
swt_max_level
(input_len)¶ Calculates the maximum level of Stationary Wavelet Transform for data of given length.
Parameters: - input_len : int
Input data length.
Returns: - max_level : int
Maximum level of Stationary Wavelet Transform for data of given length.
Notes
For the current implementation of the stationary wavelet transform, this corresponds to the number of times
input_len
is evenly divisible by two. In other words, for an n-level transform, the signal length must be a multiple of2**n
.numpy.pad
can be used to pad a signal up to an appropriate length as needed.