> For the complete documentation index, see [llms.txt](https://johannesliu.gitbook.io/data-science-python-implemented/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://johannesliu.gitbook.io/data-science-python-implemented/10.0-foundation_signal_processing/10.6-dwt_idwt_swt.md).

# 10.6 多级DWT,IDWT和SWT

### 10.6.1 多级离散小波变换分解

\[]:import pywt

x = \[3, 7, 1, 1, -2, 5, 4, 6]

db1 = pywt.Wavelet('db1')

cA3, cD3, cD2, cD1 = pywt.wavedec(x, db1)

print(cA3)

print(cD3)

print(cD2)

print(cD1)

### 10.6.2 多级离散小波变换重构

\[]:coeffs = pywt.wavedec(x, db1)

print(pywt.waverec(coeffs, db1))

\[]:\[ 3. 7. 1. 1. -2. 5. 4. 6.]

### 10.6.3 多级离散小波变换分解

\[]:x = \[3, 7, 1, 3, -2, 6, 4, 6]

(cA2, cD2), (cA1, cD1) = pywt.swt(x, db1, level=2)

print(cA1)

print(cD1)

print(cA2)

print(cD2)

\[]:\[7.07106781 5.65685425 2.82842712 0.70710678 2.82842712 7.07106781

7.07106781 6.36396103]

\[-2.82842712 4.24264069 -1.41421356 3.53553391 -5.65685425 1.41421356

-1.41421356 2.12132034]

\[ 7. 4.5 4. 5.5 7. 9.5 10. 8.5]

\[ 3. 3.5 0. -4.5 -3. 0.5 0. 0.5]

\[]:\[(cA2, cD2)] = pywt.swt(cA1, db1, level=1, start\_level=1)

print(cA2)

print(cD2)

\[]:\[ 7. 4.5 4. 5.5 7. 9.5 10. 8.5]

\[ 3. 3.5 0. -4.5 -3. 0.5 0. 0.5]

\[]:coeffs = pywt.swt(x, db1)

len(coeffs), pywt.swt\_max\_level(len(x))

\[]:(3, 3)
