Inverse Discrete Wavelet Transform (IDWT)¶
Single level idwt
¶

pywt.
idwt
(cA, cD, wavelet, mode='symmetric', axis=1)¶ Single level Inverse Discrete Wavelet Transform.
Parameters:  cA : array_like or None
Approximation coefficients. If None, will be set to array of zeros with same shape as
cD
. cD : array_like or None
Detail coefficients. If None, will be set to array of zeros with same shape as
cA
. wavelet : Wavelet object or name
Wavelet to use
 mode : str, optional (default: ‘symmetric’)
Signal extension mode, see Modes.
 axis: int, optional
Axis over which to compute the inverse DWT. If not given, the last axis is used.
Returns:  rec: array_like
Single level reconstruction of signal from given coefficients.
Examples
>>> import pywt >>> (cA, cD) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth') >>> pywt.idwt(cA, cD, 'db2', 'smooth') array([ 1., 2., 3., 4., 5., 6.])
One of the neat features of
idwt
is that one of thecA
andcD
arguments can be set to None. In that situation the reconstruction will be performed using only the other one. Mathematically speaking, this is equivalent to passing a zerofilled array as one of the arguments.>>> (cA, cD) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth') >>> A = pywt.idwt(cA, None, 'db2', 'smooth') >>> D = pywt.idwt(None, cD, 'db2', 'smooth') >>> A + D array([ 1., 2., 3., 4., 5., 6.])
Multilevel reconstruction using waverec
¶

pywt.
waverec
(coeffs, wavelet, mode='symmetric', axis=1)¶ Multilevel 1D Inverse Discrete Wavelet Transform.
Parameters:  coeffs : array_like
Coefficients list [cAn, cDn, cDn1, …, cD2, cD1]
 wavelet : Wavelet object or name string
Wavelet to use
 mode : str, optional
Signal extension mode, see Modes.
 axis: int, optional
Axis over which to compute the inverse DWT. If not given, the last axis is used.
Notes
It may sometimes be desired to run
waverec
with some sets of coefficients omitted. This can best be done by setting the corresponding arrays to zero arrays of matching shape and dtype. Explicitly removing list entries or setting them to None is not supported.Specifically, to ignore detail coefficients at level 2, one could do:
coeffs[2] == np.zeros_like(coeffs[2])
Examples
>>> import pywt >>> coeffs = pywt.wavedec([1,2,3,4,5,6,7,8], 'db1', level=2) >>> pywt.waverec(coeffs, 'db1') array([ 1., 2., 3., 4., 5., 6., 7., 8.])
Direct reconstruction with upcoef
¶

pywt.
upcoef
(part, coeffs, wavelet, level=1, take=0)¶ Direct reconstruction from coefficients.
Parameters:  part : str
Coefficients type: * ‘a’  approximations reconstruction is performed * ‘d’  details reconstruction is performed
 coeffs : array_like
Coefficients array to recontruct
 wavelet : Wavelet object or name
Wavelet to use
 level : int, optional
Multilevel reconstruction level. Default is 1.
 take : int, optional
Take central part of length equal to ‘take’ from the result. Default is 0.
Returns:  rec : ndarray
1D array with reconstructed data from coefficients.
See also
Examples
>>> import pywt >>> data = [1,2,3,4,5,6] >>> (cA, cD) = pywt.dwt(data, 'db2', 'smooth') >>> pywt.upcoef('a', cA, 'db2') + pywt.upcoef('d', cD, 'db2') array([0.25 , 0.4330127 , 1. , 2. , 3. , 4. , 5. , 6. , 1.78589838, 1.03108891]) >>> n = len(data) >>> pywt.upcoef('a', cA, 'db2', take=n) + pywt.upcoef('d', cD, 'db2', take=n) array([ 1., 2., 3., 4., 5., 6.])