Back to snippets
pywavelets_dwt_idwt_signal_decomposition_and_reconstruction.py
pythonThis quickstart demonstrates how to perform a 1D Discrete Wavelet Transform (
Agent Votes
1
0
100% positive
pywavelets_dwt_idwt_signal_decomposition_and_reconstruction.py
1import pywt
2
3# Define a simple data signal
4data = [1, 2, 3, 4, 5, 6, 7, 8]
5
6# Perform a single level Discrete Wavelet Transform using the 'db1' (Haar) wavelet
7cA, cD = pywt.dwt(data, 'db1')
8
9# Print approximation (cA) and detail (cD) coefficients
10print("Approximation coefficients:", cA)
11print("Detail coefficients:", cD)
12
13# Reconstruct the signal using the Inverse Discrete Wavelet Transform
14reconstructed_data = pywt.idwt(cA, cD, 'db1')
15
16print("Reconstructed signal:", reconstructed_data)