# How to achieve a periodized Mexican hat wavelet with period L by using Python?

Now I have a scaled Mexican hat wavelet, i.e. $$\psi(a,x)=\frac{1}{\sqrt{a}}…\left(1-\frac{x^2}{a^2}\right)e^{-x^2/(2a^2)},$$ which decays quickly along the x-axis. Here I want to define a periodized wavelet in the following way $$\psi^P(a,x)=\sum_{m\in\mathbb{Z}}\psi(a,x-mL),$$ where $$L$$ is the period of $$\psi^P(a,x)$$. However, I have no idea how to achieve it by using programs, e.g. Python. Can you help me?

• What is the context? Note, "periodization" could mean something else. Apr 26, 2022 at 21:41

This is quite straight forward, if you use Python's numpy library. It is capable of array operations and thus, this task is just a few lines.

import numpy as np
import matplotlib.pyplot as plt

#parameters
a = 0.5
L = 512
length = 2**15
samplingPeriod = .01

nbrOfWavelets = int(length/L)

#calculate single wavelet for x=-length to x=length
xArray = (np.arange(2*length)-length)*samplingPeriod
singleWavelet = (1/np.sqrt(a)) * (1-((xArray**2)/(a**2))) * np.exp((-1*xArray**2)/(a**2))

#define initial wavelet beginning at zero time, cut in half
periodicWavelet = np.zeros(length) + singleWavelet[length:]

#iteratively add following wavelets hopping in steps of L
for m in range(1,nbrOfWavelets):
periodicWavelet += singleWavelet[length-m*L:-m*L]

fig = plt.plot(periodicWavelet)
plt.show()