Date: March 27 2020
Summary: Introduction to discrete haar wavelet transform and use cases
Keywords: ##zettel #signalprocessing #wavelet #changes #python #archive
Not Available
The Discrete Haar Wavelet Transform computes the degree of relatedness of continuous points in the original discrete signal.
It is excellent for detecting edges in a signal and drastic changes in a signal
# Declaring imports
import numpy as np
def gen_haar_matrix(n, normalized=None):
#Source:
# 0. https://en.wikipedia.org/wiki/Haar_wavelet
# 1. http://fourier.eng.hmc.edu/e161/lectures/Haar/index.html
# 2. https://docs.scipy.org/doc/numpy/reference/generated/numpy.kron.html
# 3. https://www.wikiwand.com/en/Kronecker_delta
# Allow only size n of power 2
n = 2**np.ceil(np.log2(n))
if n > 2:
h = gen_haar_matrix(n / 2)
else:
return np.array([[1, 1], [1, -1]])
# calculate upper haar part
h_n = np.kron(h, [1, 1])
# calculate lower haar part
if normalized:
h_i = np.sqrt(n/2)*np.kron(np.eye(len(h)), [1, -1])
else:
h_i = np.kron(np.eye(len(h)), [1, -1])
# combine parts
h = np.vstack((h_n, h_i))
return h
> gen_haar_matrix(n = 4, normalized = False)
[[ 1. 1. 1. 1.]
[ 1. 1. -1. -1.]
[ 1. -1. 0. -0.]
[ 0. -0. 1. -1.]]
> gen_haar_matrix(n = 4, normalized = True)
[[ 1. 1. 1. 1. ]
[ 1. 1. -1. -1. ]
[ sqrt(2) -sqrt(2) 0. -0. ]
[ 0. -0. sqrt(2) -sqrt(2) ]]
Zelko, Jacob. Discrete Haar Wavelet Transform. https://jacobzelko.com/03272020050924-discrete-haar. March 27 2020.