Inverse Discrete Wavelet Transform (IDWT)¶
Single level idwt
¶
- pywt.idwt(cA, cD, wavelet, mode='symmetric', axis=-1)¶
Single level Inverse Discrete Wavelet Transform.
- Parameters
- cAarray_like or None
Approximation coefficients. If None, will be set to array of zeros with same shape as
cD
.- cDarray_like or None
Detail coefficients. If None, will be set to array of zeros with same shape as
cA
.- waveletWavelet object or name
Wavelet to use
- modestr, 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 zero-filled 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
- coeffsarray_like
Coefficients list [cAn, cDn, cDn-1, …, cD2, cD1]
- waveletWavelet object or name string
Wavelet to use
- modestr, 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
- partstr
Coefficients type: * ‘a’ - approximations reconstruction is performed * ‘d’ - details reconstruction is performed
- coeffsarray_like
Coefficients array to reconstruct
- waveletWavelet object or name
Wavelet to use
- levelint, optional
Multilevel reconstruction level. Default is 1.
- takeint, optional
Take central part of length equal to ‘take’ from the result. Default is 0.
- Returns
- recndarray
1-D 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.])