I am having trouble understanding some discrete wavelet transform code. I found this snippet which is supposed to yield the dwt up to level 3 for a signal of length 8 and calculate the approximation and detail coefficients in place.
import numpy as np
def Haar(x):
x = x / np.sqrt(2)
a, b = x[0] + x[1], x[0] - x[1]
x[0], x[1] = a, b
for k in range(2,len(x) - 1,2):
a, b = x[k] + x[k+1], x[k] - x[k+1]
x[k], x[k+1] = a, b
x = [4, 6, 10, 12, 8, 6, 5, 5]
print('data', x)
m = int(np.log2(len(x)))
def dwt(x, f):
for i in range(m):
f(x[0::2 ** i])
print('output', x)
dwt(x, Haar)
However, the output with Python 3.8 is the same than the input and imo the operations performed in Haar are not passed back to the call site which results in always working on the original data. The code was written for Python 2 so I tested also with python 2.7 but to the same result.
What am I missing here?