import numpy import math import matplotlib.pyplot as plt #creating a three-component vector matrix of length 2^12: #v = numpy.zeros(shape=(4096)) v = numpy.zeros(4096) #insert 1 in the 5th and 30th place a = numpy.insert(v,4,1) b = numpy.insert(v,29,1) c = a + b #Calculate the wavelet transform. #"4 equations in 4 unknowns..." -NMM: numer = math.sqrt(3) denom = 4 * math.sqrt(2) #Forward transform lo/smooth coefficients: c0 = (1 + num)/denom c1 = (3 + num)/denom c2 = (3 - num)/denom c3 = (1 - num)/denom #Forward transform hi/wavelet coefficients: w0 = c3 w1 = -c2 w2 = c1 w3 = -c0 #Inverse transform lo/smooth values: i_c0 = c2 i_c1 = w2 i_c2 = c0 i_c3 = w0 #Inverse transform hi/wavelet values: i_w0 = c3 i_w1 = w3 i_w2 = c1 i_w3 = w1 def invTransform(a, n): a = [] if (n >= 4): i,j half = n >> 1 halfPls1 = half + 1 tmp[0] = a[half-1]*i_c0 + a[n-1]*i_c1 + a[0]*i_c2 + a[half]*i_c3 tmp[1] = a[half-1]*i_w0 + a[n-1]*i_w1 + a[0]*i_w2 + a[half]*i_w3 j = 2 counter = 0 while counter < half-1: counter += 1 a[i] = tmp[i] #Inverse Daubechies Transform: plt.show()