Skip to content

Instantly share code, notes, and snippets.

@RodrigoPrior
Created November 5, 2017 16:21
Show Gist options
  • Save RodrigoPrior/d8199eaf2fda244560d5376514dbd6ae to your computer and use it in GitHub Desktop.
Save RodrigoPrior/d8199eaf2fda244560d5376514dbd6ae to your computer and use it in GitHub Desktop.
Example of Haar Mother Wavelet in python using np.piecewise interval definition.
"""
Haar Mother Wavelet.
Example of Haar Mother Wavelet in python using np.piecewise interval definition.
"""
# Ref.:
# https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.piecewise.html
# https://sfalsharif.wordpress.com/2009/12/18/piecwise-function-definitions-in-numpy/
import numpy as np
import matplotlib.pyplot as plt
t = 1
x = np.arange(-2, 2, 0.1)
y = np.piecewise(x,
[(x>=0) & (x < t/2), (x>= t/2) & (x < t)],
[lambda x: 1, lambda x: -1, lambda x:0])
plt.stem(x,y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment