“宽度"单位scipy.signal.cwt() 函数的参数 [英] Units of "widths" argument to scipy.signal.cwt() function

查看:179
本文介绍了“宽度"单位scipy.signal.cwt() 函数的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对传递给 scipy.signal.cwt() 和通过扩展传递给 scipy.signal.find_peaks_cwt() 的 widths 参数感到困惑.以前非常有用的堆栈溢出问题(以及其中的指针)解释了我的大部分困惑.widths 是一个尺度数组,在与数据卷积之前拉伸小波.

I am confused about the widths parameter that gets passed to scipy.signal.cwt() and by extension to scipy.signal.find_peaks_cwt(). A previous and very helpful Stack Overflow question (and pointers therein) explained away most of my confusion. The widths is an array of scales by which to stretch the wavelet before convolution with your data.

仍然让我困惑的一点是,widths 元素的单位是什么?宽度为 1 是否意味着小波被拉伸到一个索引"宽,其中索引是 data 元素之间的距离?起初我认为是这种情况,但是 (a) 宽度可以采用非整数值,并且 (b) cwt() 结果可能因宽度而异.

The point which confused me still is, what are the units of the elements of widths? Does a width of 1 mean the wavelet is stretched to be one "index" wide, where index is the distance between elements of data? At first I assumed this was the case, but (a) the widths can take non-integer values, and (b) cwt() results can vary depending on the widths.

这里有一些代码说明了我的困惑.为什么最后两行给出不同的结果?

Here is some code which illustrates my confusion. Why do the last two lines give different results?

#generating an arbitrary signal with overlapping gaussian peaks with various 
npeaks = 6
support = np.arange(0,1.01,0.01)
pkx = np.array([0.2, 0.3, 0.38, 0.55, 0.65]) #peak locations
pkfun = sum(stats.norm.pdf(support, loc=pkx[i], scale=0.03) for i in range(0,npeaks-1))

#finding peaks for two different setting of widths
pkindsOne = sig.find_peaks_cwt(pkfun, widths = np.arange(4,6), wavelet = sig.ricker)
pkindsTwo = sig.find_peaks_cwt(pkfun, widths = np.arange(4,6.4), wavelet = sig.ricker)

#printing to show difference between calls
for ind, el in enumerate(pkindsTwo):
    print el, pkindsOne[ind]
20 20
36 36
38 38
55 55
63 66
66 91
91

结果很接近,但第二次调用在输入数据的元素 63 处发现了一个假峰.因此我不相信宽度单位是数据向量的索引.但它们还能是什么?如果不是,widths 的单位是什么?cwt()find_peaks_cwt() 从不知道或看到任何 x 轴单位(例如,我在代码中定义的 support 向量),那我错过了什么?实际上,何时使用非整数宽度有意义?

The results are close, but the second call finds one spurious peak at element 63 of the input data. Thus I'm not convinced that the units of widths are indices of the data vector. But what else could they be? If not, what are the units of the widths? cwt() and find_peaks_cwt() never know about or see any x-axis units (e.g. the support vector I define in my code), so what am I missing? When, practically speaking, does it ever make sense to use non-integer widths?

推荐答案

我自己也有同样的问题.查看源代码,我最好的客人是单位在样本数"中.scipy.signal.wavelets.cwt 中的关键代码行是:

I had the same question myself. Looking at the source code, my best guest is that the units are in "number of samples". The key code line within scipy.signal.wavelets.cwt is:

wavelet_data = wavelet(min(10 * width, len(data)), width)

这里,小波"是一个函数(母小波的构建器),它以样本数接收参数length_of_wavelet"和width_of_wavelet".宽度仍然可以是非整数值的原因是(如果我没记错的话)它代表缩放因子,它可以采用任何实数正数,因为它只是影响形状的公式的一个因子小波.

Here, "wavelet" is a function (builder of the mother wavelet) which receives parameters "length_of_wavelet" and "width_of_wavelet" in number of samples. The reason why widths can still be a non-integer value is that (if I'm not wrong) it represents the scaling factor, which can take any real positive number as it is just a factor of the formulation that affects the shape of the wavelet.

这篇关于“宽度"单位scipy.signal.cwt() 函数的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆