Units of the argument "widths" for the scipy.signal.cwt () function

I got confused by the widths parameter, which is passed to scipy.signal.cwt() and by extension to scipy.signal.find_peaks_cwt() . A previous and very useful question about stack overflow (and pointers in it) explained most of my confusion. widths is an array of scales with which you can stretch a wavelet to convolution with your data.

What confused me is - what are the units of widths elements ? Does width 1 mean that the wavelet is stretched to be one β€œindex” wide, where index is the distance between the data elements? At first I assumed that it was, but (a) the width can take non-integer values, and (b) the results of cwt () can vary depending on the width.

Here is some code that 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 

The results are close, but the second call finds one spurious peak in the input element 63. Thus, I am not sure if the units of width are the indices of the data vector. But what else can they be? If not, what are the units of widths ? cwt() and find_peaks_cwt() never know or do not see any units of the x axis (for example, the support vector, which I define in my code), so what am I missing? When, in practice, does it make sense to use a non-integer width?

+6
source share
1 answer

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

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

Here, the wavelet is a function (the builder of the mother wavelet) that receives the number of length_of_wavelet and width_of_wavelet in the number of samples. The reason the width can still be a non-integer value is because (if I'm not mistaken) it is a scaling factor that can take any real positive number, since this is just a formulation factor that affects the shape of the wavelet.

+5
source

Source: https://habr.com/ru/post/983241/


All Articles