Wavelet transform has recently become a very popular when it comes to analysis, de-noising and compression of signals and images. This section describes functions used to perform single- and multilevel Discrete Wavelet Transforms.
Single level Discrete Wavelet Transform.
Parameters: | data : array_like
wavelet : Wavelet object or name
mode : str, optional
axis: int, optional :
|
---|---|
Returns: | (cA, cD) : tuple
|
Notes
Length of coefficients arrays depends on the selected mode. For all modes except periodization:
len(cA) == len(cD) == floor((len(data) + wavelet.dec_len - 1) / 2)
For periodization mode (“per”):
len(cA) == len(cD) == ceil(len(data) / 2)
Examples
>>> import pywt
>>> (cA, cD) = pywt.dwt([1, 2, 3, 4, 5, 6], 'db1')
>>> cA
array([ 2.12132034, 4.94974747, 7.77817459])
>>> cD
array([-0.70710678, -0.70710678, -0.70710678])
See the signal extension modes section for the list of available options and the dwt_coeff_len() function for information on getting the expected result length.
The transform can be performed over one axis of multi-dimensional data. By default this is the last axis. For multi-dimensional transforms see the 2D transforms section.
Multilevel 1D Discrete Wavelet Transform of data.
Parameters: | data: array_like :
wavelet : Wavelet object or name string
mode : str, optional
level : int, optional
|
---|---|
Returns: | [cA_n, cD_n, cD_n-1, ..., cD2, cD1] : list
|
Examples
>>> from pywt import wavedec
>>> coeffs = wavedec([1,2,3,4,5,6,7,8], 'db1', level=2)
>>> cA2, cD2, cD1 = coeffs
>>> cD1
array([-0.70710678, -0.70710678, -0.70710678, -0.70710678])
>>> cD2
array([-2., -2.])
>>> cA2
array([ 5., 13.])
Partial Discrete Wavelet Transform data decomposition.
Similar to pywt.dwt, but computes only one set of coefficients. Useful when you need only approximation or only details at the given level.
Parameters: | part : str
data : array_like
wavelet : Wavelet object or name
mode : str, optional
level : int, optional
|
---|---|
Returns: | coeffs : ndarray
|
See also
Compute the maximum useful level of decomposition.
Parameters: | data_len : int
filter_len : int
|
---|---|
Returns: | max_level : int
|
Examples
>>> import pywt
>>> w = pywt.Wavelet('sym5')
>>> pywt.dwt_max_level(data_len=1000, filter_len=w.dec_len)
6
>>> pywt.dwt_max_level(1000, w)
6
Returns length of dwt output for given data length, filter length and mode
Parameters: | data_len : int
filter_len : int
mode : str, optional (default: ‘symmetric’)
|
---|---|
Returns: | len : int
|
Notes
For all modes except periodization:
len(cA) == len(cD) == floor((len(data) + wavelet.dec_len - 1) / 2)
for periodization mode (“per”):
len(cA) == len(cD) == ceil(len(data) / 2)
Based on the given input data length, Wavelet decomposition filter length and signal extension mode, the dwt_coeff_len() function calculates the length of the resulting coefficients arrays that would be created while performing dwt() transform.
filter_len can be either an int or Wavelet object for convenience.