why is the output length of the inverse wavelet transform the double of my original signal?

I have an input signal of 30000 samples. I perform the Stationary wavelet transform in python to get the 4th level od decomposition. Then I perform an array mathematical operation over the decomposed level and convert it back into time. When I perform that conversion back in time, I get the exact double length (60000) of the original signal. Why is that and how can I correct it?

To help you reproduce the issue, I paste here an example code:

x_n_preprocessed = np.zeros(30000)
g_m = np.ones(30000)
y_m_2 = pywt.swt(x_n_preprocessed, 'sym4', level=4)[3]
y_m_corrected = np.multiply(y_m_2[0], g_m)
# combine the noise-free signal coefficients into a single array
s_n_hat = pywt.idwt(y_m_2, None, 'sym4', 'smooth')

import matplotlib.pylab as plt

plt.plot(x_n)
plt.plot(s_n_hat, 'red')
plt.show()

• What’s the point of y_m_corrected? It’s not being used in your code.
– Jdip
Mar 1, 2023 at 17:29
• I'm sorry, I just adapted the code for testing it for debugging here. That is the correct coefficients from the wavelet decomposition that I want to get back in time. I changed it to the origin y_m_2 for simplicity. Mar 1, 2023 at 21:58
• You need to read the documentation carefully, and probably spend some time understanding what the stationary wavelet transform is (and discrete wavelet transform, and how they differ). Your code does not make much sense. You're using y_m_2 as approximation coefficients in your call to idwt even though they're not...
– Jdip
Mar 1, 2023 at 23:56
• I do understand what the SWT but not the inverse reconstruction. This transformation comes from a scientific paper where, in their algorithm, they propose to perform linear algebra to the wavelet decomposed coefficients and finally, get them back in time to obtain the noise free signal. I am curious how they reconstruct the signal since it seems that in scipy, the three functions for inverse wavelet transform gives me the doblue size of my original signal. I provided approximation and detail coefficients Mar 2, 2023 at 7:51
• Not in the code you’ve pasted…
– Jdip
Mar 2, 2023 at 8:05