首页 > 解决方案 > How to define my own continuous wavelet by using Python?

问题描述

As the title shows, I want to define my own continuous wavelet by Python. However, I don't know how to achieve this exactly.

The formula of my wavelet mother function is below

enter image description here

It looks something like the Mexican hat wavelet, but they are different.

So how can I define such a custom wavelet by Python, then CWT can be performed using this wavelet?

标签: pythonscipywaveletwavelet-transformpywavelets

解决方案


根据这个,您需要一个函数,该函数需要多个点和一个比例作为wavelet参数提供

所以我们这样定义:

import math
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt

mother_wavelet = lambda z : np.exp(-z*z/4)*(2-z*z)/(4*math.sqrt(math.pi))

def mexican_hat_like(n,scale):
    x = np.linspace(-n/2,n/2,n)
    return mother_wavelet(x/scale)

让我们测试一下。我们注意到,实际上可以使用与您的非常相似的东西。不同之处在于缩放比例a,并且常数是正面看起来略有不同。注意math.sqrt(2)Ricker 小波的缩放

points = 100
a = 4.0
vec_ours = mexican_hat_like(points, a)
vec_theirs = signal.ricker(points, a*math.sqrt(2))
plt.plot(vec_ours, label = 'ours')
plt.plot(vec_theirs, label = 'ricker')
plt.legend(loc = 'best')
plt.show()

这是图表:

小波


推荐阅读