如何改变pywt中的膨胀和平移系数

how to change dilation and translation coefficient in pywt

我是 pywt 和小波分析的新手。 我现在面临几个问题,希望有人能帮我解决。

首先,我想改变my_wavelet中的膨胀(D)和平移(x),但我不知道具体怎么做。如果有人提供示例,我将不胜感激。

其次,我可以在数组s的边缘添加零吗?由于值 cA 和 cD 的输出大小为 7,而输入 s 大小为 13。或者有什么方法可以避免大小减小?

三、上面公式中的C_P,D和pywt.dwt函数输出的cA一样吗?我仍然不明白为什么在公式中只有一个输出但 pywt.dwt 给出了两个?

s = [1,2,3,7,8,9,5,1,1,0,1]
my_filter_bank = ( [1,1], [-1,1], [1,1], [-1,1] )
my_wavelet = pywt.Wavelet('haar', filter_bank = my_filter_bank)
cA, cD = pywt.dwt(s, my_wavelet)

提前致谢。

我认为您在连续小波变换和离散小波变换之间得到了mixed-up。您提供的公式是 CWT 的公式,但您尝试在 Python 中计算的是 DWT。

First, I would like to change dilation (D) and translation (x) in my_wavelet, but I do not know how to do it exactly. I will be very grateful if anyone provides an example(s).

您不必这样做,至少如果您打算将 DWT 应用于信号 s 则不必这样做。 DWT 将使用单个级别(使用 dwt)或多个级别(使用 wavedec)分解您的信号。将每个级别视为与小波的尺度相关,它的膨胀程度。所以你的小波的扩张和平移已经被“处理”了。

Second, can I add zeros at the edge of array s? Since the output of value cA and cD are in size 7 while input s is size 13. Or is there any method to avoid the reduction of size?

cA 和 cD 的大小定义 here:

Length of coefficients arrays depends on the selected mode. For all modes except periodization:

len(cA) == len(cD) == floor((len(data) + wavelet.dec_len - 1) / 2)

For periodization mode (“per”):

len(cA) == len(cD) == ceil(len(data) / 2)

cA 和 cD 的大小与您的输入信号 s 不同这一事实不应该打扰您。当然,您可以在信号边缘添加零,但这只会导致您从 zero-padded 信号计算系数。

Third, is C_P,D in the formula above the same as cA output from pywt.dwt function? I still don't understand why in the formula there's only one output but pywt.dwt gave two?

不,它们不是一回事。 C_P,你公式中的D是给定尺度和位置的小波系数,而cA和cD对应的是详细系数和近似系数。

最后一个提示:我个人觉得很难用像你这样的小阵列来理解小波变换。我建议分析示例数据,例如 scipy 的心电图:

import pywt
import matplotlib.pyplot as plt
from scipy.misc import electrocardiogram

s = electrocardiogram()
plt.plot(s)
plt.title('INPUT SIGNAL')

my_wavelet = pywt.Wavelet('db2')
cA, cD = pywt.dwt(s, my_wavelet) 
plt.plot(cD)
plt.title('DETAILED COEFF.')

plt.plot(cA)
plt.title('APPROXIMATION COEFF.')