When I use the pywt.swt function for a level 1 transform I get different results than when doing a manual convolution with the low pass and high pass filters using wavelet.dec_lo and wavelet.dec_hi. I do not understand why. Here is an example:
import numpy as np
from scipy.signal import convolve
# Example signal
signal = np.array([1, 2, 3, 4, 5, 6, 7, 8])
# Perform Stationary Wavelet Transform (SWT)
wavelet = pywt.Wavelet('db2')
coeffs = pywt.swt(signal, wavelet, level=1)
# Print the coefficients for each level
for i, (cA, cD) in enumerate(coeffs, 1):
print(f"Level {i}:")
print(f" Approximation coefficients: {cA}")
print(f" Detail coefficients: {cD}")
# Obtain the decomposition filters
Lo_D = wavelet.dec_lo # Low-pass filter
Hi_D = wavelet.dec_hi # High-pass filter
# Convolve with level 1 filters
approx_level1 = convolve(signal, Lo_D, mode='same')
detail_level1 = convolve(signal, Hi_D, mode='same')
print("Level 1 Approximation:", approx_level1)
print("Level 1 Detail:", detail_level1)
With the approximation coefficients it just seems to be a problem at the edges which I could fix by padding the array but I do not understand what happens with the detail coefficients.
When I use the pywt.swt function for a level 1 transform I get different results than when doing a manual convolution with the low pass and high pass filters using wavelet.dec_lo and wavelet.dec_hi. I do not understand why. Here is an example:
Results:
I appreciate any help. Thank you.