我真的对 pywt.cwt 函数感到困惑,因为我无法让它工作。该功能似乎是集成而不是微分。我想按如下方式工作:Example CWT ,但我的图表如下所示:My CWT 。这个想法是将原始信号 (av) 与 cumtrapz 积分,然后用高斯 CWT (=> S1) 微分,然后再次用高斯 CWT (=> S2) 微分。
正如你在图片中看到的,红线的底部山峰应该在山谷中对齐,但对我来说顶部山峰下方的土地,绿线应该向左移动 1/4 周期,但会移动到右边......这让我认为它出于某种原因集成。
我目前不知道是什么原因造成的...有人知道发生了什么事吗?
提前致谢!
#Get data from pandas
av = dfRange['y']
#remove gravity & turns av right way up
av = av - dfRange['y'].mean()
av = av * -1
#Filter
[b,a] = signal.butter(4, [0.9/(55.2/2), 20/(55.2/2)], 'bandpass')
av = signal.filtfilt(b,a, av)
#Integrate and differentiate av => S1
integrated_av = integrate.cumtrapz(av)
[CWT_av1, frequency1] = pywt.cwt(integrated_av, 8.8 , 'gaus1', 1/55.2)
CWT_av1 = CWT_av1[0]
CWT_av1 = CWT_av1 * 0.05
#differentiate S1 => S2
[CWT_av2, frequency2] = pywt.cwt(CWT_av1, 8.8 , 'gaus1', 1/55.2)
CWT_av2 = CWT_av2[0]
CWT_av2 = CWT_av2 * 0.8
#Find Peaks
inv_CWT_av1 = CWT_av1 * -1
av1_min, _ = signal.find_peaks(inv_CWT_av1)
av2_max, _ = signal.find_peaks(CWT_av2)
#Plot
plt.style.use('seaborn')
plt.figure(figsize=(25, 7), dpi = 300)
plt.plot_date(dfRange['recorded_naive'], av, linestyle = 'solid', marker = None, color = 'steelblue')
plt.plot_date(dfRange['recorded_naive'][:-1], CWT_av1[:], linestyle = 'solid', marker = None, color = 'red')
plt.plot(dfRange['recorded_naive'].iloc[av1_min], CWT_av1[av1_min], "ob", color = 'red')
plt.plot_date(dfRange['recorded_naive'][:-1], CWT_av2[:], linestyle = 'solid', marker = None, color = 'green')
plt.plot(dfRange['recorded_naive'].iloc[av2_max], CWT_av2[av2_max], "ob", color = 'green')
plt.gcf().autofmt_xdate()
plt.show()
最佳答案
我不确定这是否是您的答案,但这是通过使用 pywt
观察到的结果...
来自documentation小波基本上由高斯的微分给出,但存在一个依赖于阶数的归一化常数。
绘制高斯函数与小波的微分(通过放入脉冲响应提取)可得到以下结果:
有趣的观察是,阶数相关的归一化常数有时似乎包含“-1”。特别是,它适用于一阶 gaus1
。
所以,我的问题是,你真的可以像你期望的那样进行微分,而且还可以乘以 -1 吗?
图表代码:
import numpy as np
import matplotlib.pyplot as plt
import pywt
dt = 0.01
t = dt * np.arange(100)
# Calculate the differentials of a gaussian by quadrature:
# start with the gaussian y = exp(-(x - x_0) ^ 2 / dt)
ctr = t[len(t) // 2]
gaus = np.exp(-np.power(t - ctr, 2)/dt)
gaus_quad = [np.gradient(gaus, dt)]
for i in range(7):
gaus_quad.append(np.gradient(gaus_quad[-1], dt))
# Extract the wavelets using the impulse half way through the dataset
y = np.zeros(len(t))
y[len(t) // 2] = 1
gaus_cwt = list()
for i in range(1, 9):
cwt, cwt_f = pywt.cwt(y, 10, f'gaus{i}', dt)
gaus_cwt.append(cwt[0])
fig, axs = plt.subplots(4, 2)
for i, ax in enumerate(axs.flatten()):
ax.plot(t, gaus_cwt[i] / np.max(np.abs(gaus_cwt[i])))
ax.plot(t, gaus_quad[i] / np.max(np.abs(gaus_quad[i])))
ax.set_title(f'gaus {i+1}', x=0.2, y=1.0, pad=-14)
ax.axhline(0, c='k')
ax.set_xticks([])
ax.set_yticks([])
关于python - 为什么我的功能似乎是整合的而不是分化的? (pywt.cwt),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60507260/