1

I have the data and code below that creates a DWT wavelet, but I don't know how to inverse it so that it aligns with the original data. The code below works to create the coefficients but then I'm stuck on inversing it.

I don't want to use a package such as pywavelets but do it from scratch.

data = [56, 40, 8, 24, 48, 48, 40, 16]

def discreteHaarWaveletTransform(x):
    N = len(x)
    output = [0.0]*N

    length = N >> 1
    while True:
        for i in range(0,length):
            summ = x[i * 2] + x[i * 2 + 1]
            difference = x[i * 2] - x[i * 2 + 1]
            output[i] = summ/2
            output[length + i] = difference/2

        if length == 1:
            return output

        #Swap arrays to do next iteration
        x = output[:length << 1]
        length >>= 1

output: [35.0, -3.0, 16.0, 10.0, 8.0, -8.0, 0.0, 12.0]

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
tone
  • 47
  • 6

0 Answers0