the cedar ledge

Discrete Haar Wavelet Transform

Date: March 27 2020

Summary: Introduction to discrete haar wavelet transform and use cases

Keywords: ##zettel #signalprocessing #wavelet #changes #python #archive

Bibliography

Not Available

Table of Contents

    1. Use Cases
    2. Example Implementation
    3. Example output
  1. How To Cite
  2. References
  3. Discussion:

The Discrete Haar Wavelet Transform computes the degree of relatedness of continuous points in the original discrete signal.

Use Cases

It is excellent for detecting edges in a signal and drastic changes in a signal

Example Implementation

# 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

Example output

> 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) ]]

How To Cite

Zelko, Jacob. Discrete Haar Wavelet Transform. https://jacobzelko.com/03272020050924-discrete-haar. March 27 2020.

References

Discussion:

CC BY-SA 4.0 Jacob Zelko. Last modified: November 24, 2023. Website built with Franklin.jl and the Julia programming language.