You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to implement a matrix form of the DWT (for MCMC sampling reasons) and am comparing to pywt.dwt and wavedec (v 1.3.0) to confirm that I have constructed my matrix correctly. I am encountering a shift in the coefficients from dwt that I did not expect.
nsamp = 64
wavelet = "db4"
level = 1.
signal = np.zeros(nsamp)
signal[0] = 1.
cA_pywt, cD_pywt = pywt.dwt(signal, wavelet, mode="per")
# compute matrix W
# w_k = W @ signal
# cA_matrix = w_k[: nsamp // (2 ** (level + 1))]
# cD_matrix = w_k[nsamp // (2 ** (level + 1)) : nsamp // (2 ** level)]
# plot cA and cD
I would have thought that for a delta function, the peak would be at cA_pywt[0], not cA_pywt[1]. Are the filters not aligned so that at k=0, wavelet.dec_lo[0] is aligned with signal[0]? Also, during decimation, is every even or every odd sample selected?
I've dug through the C code and done some tests to attempt to answer my own question. Please correct me if I'm wrong. Using mode="periodization", the signal is shifted so that the center of the filter is aligned with the first sample. So in my example above, for "db4", wavelet.dec_lo[0] is aligned with signal[4]. So I'll modify my question: Why is this the convention?
As for the decimation, with mode="periodization" if the filter is of even length then the even samples are kept and if the filter is of odd length the odd samples are kept.
Activity
tycohen commentedon Mar 31, 2025
I've dug through the C code and done some tests to attempt to answer my own question. Please correct me if I'm wrong. Using
mode="periodization", the signal is shifted so that the center of the filter is aligned with the first sample. So in my example above, for "db4",wavelet.dec_lo[0]is aligned withsignal[4]. So I'll modify my question: Why is this the convention?As for the decimation, with
mode="periodization"if the filter is of even length then the even samples are kept and if the filter is of odd length the odd samples are kept.