python - 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
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?
解决方案
根据这个,您需要一个函数,该函数需要多个点和一个比例作为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()
这是图表:
推荐阅读
- c++ - 使用 C++ 进行文字游戏倒计时
- c# - EF Core:如何避免重复条目?
- python - discord.py 块广告不起作用
- python - 提取特定的 JSON 键并在 Python 中转换为 CSV
- google-cloud-platform - 使用 Python 对来自 Google Cloud Logging 的日志进行分页
- swift - 在 SwiftUI 中使用 ForEach 枚举
- python - 通过围绕枢轴旋转一个 3d 点来创建一个圆
- mysql - 来自 SSH 的 MySQL 查询
- javascript - 仅在页面 100% 加载时执行功能的问题
- java - 关于 Codility 的 MinMaxDivision 解决方案的问题,它使用二进制搜索来解决它