使用Scipy.signal(Python)进行连续小波变换:cwt()函数中的参数"widths"是什么? (时间频率) [英] Continuous Wavelet Transform with Scipy.signal (Python): what is parameter “widths” in cwt() function? (time-frequency)

查看:1394
本文介绍了使用Scipy.signal(Python)进行连续小波变换:cwt()函数中的参数"widths"是什么? (时间频率)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索绘制带有离散时间信号的时频信号(采样步长= 0.001秒).我使用Python和Scipy.signal库.我使用函数cwt(data,wavelet,widths),该函数返回一个矩阵,以复杂的morlet小波(或gabor小波)进行连续小波变换.不幸的是,没有太多关于这种用法的文档.我发现的最好的是: -对于Matlab(我尝试找到相同的时标结果),但是我自然无法获得相同的功能, -而解释了什么是连续小波变换,而没有小波参数的细节

第一步:获取刻度转换信号.毫无疑问,我直接将数组宽度"与可能不同比例的数组相关联.因为,如果参数宽度不缩放,我不知道它是什么.也许,您会告诉我这是当前小波的宽度"!但是,即使现在,我仍不确定链接宽度与比例如何……在Scipy中的Morlet文档中,链接似乎可能是:"s:比例因子,从-s * 2 * pi到+ s * 2窗口化* pi,因此,我认为width = 4 * pi * scale(宽度=窗口的宽度).但是当我绘制小波时,比例会增加,小波的可视宽度也会减小...

我的第二个问题是找到并画出与频率相等的值.在文献中,我发现这个公式:Fa = Fc/(s * delta),其中Fa是最终频率,Fc是小波的中心频率,单位为Hz,s为比例,为采样周期.因此,可以选择比例尺(如果我找到了具有宽度的链接)和增量(= 0.001秒),但由于小波的中心频率而变得更加复杂.在scipy文档中,我发现:此小波[morlet小波]的基本频率以Hz为单位,由f = 2 * s * w * r/M给出,其中r是采样率[s在这里是缩放系数,加窗从-s * 2 * pi到+ s * 2 * pi.默认为1; w宽度;和M小波的长度]."我认为这是中心频率,对吗?

谢谢

这是我为cwt()保留的代码:

def MyCWT(data, wavelet, scales):

output = zeros([len(scales), len(data)], dtype=complex)

for ind, scale in enumerate(scales):

    window = scale*4*pi*10#Number of points to define correctly the wavelet
    waveletLength = min(window, len(data))#Number of points of the wavelet
    wavelet_data = wavelet(waveletLength, s=scale)#Need to precise w parameter???

    #To see the wavelets:
    plot(wavelet_data)
    xlabel('time (10^-3 sec)')
    ylabel('amplitude')
    title('Morlet Wavelet for scale='+str(scale)+'\nwidth='+str(window))
    show()

    #Concolution to calculate the current line for the current scale:
    z = convolve(data, wavelet_data, mode='same')

    i = 0
    for complexVal in z:
        output[ind][i] = complex(complexVal.real, complexVal.imag)         
        i+=1

return output

解决方案

widths参数是一个宽度大小的数组,在将小波与数据卷积之前,小波将被拉伸到该宽度.

您应该选择一个范围,该范围的起始值应比预期信号宽度稍小,但应稍大一些.您提供的值越多,计算速度越慢,但分辨率越高.

查看文档或参考论文生物信息学(2006)22(17):2059-2065. doi:10.1093/bioinformatics/btl355 了解更多信息.

I search to draw a time-frequency signal with a discrete temporal signal (sampling step = 0.001sec). I use Python and the library Scipy.signal. I use the function cwt(data, wavelet, widths), which returns a matrix, to do a continuous wavelet transform, with the complex morlet wavelet (or gabor wavelet). Unfortunately, there is not a lot of documentations of this use. The best which I found are: - this for Matlab (I try to find the same scale-time result) but I have naturally not access to the same fonctions, - And this which explain what is continuous wavelet transform, without details of wavelet parameters.

First step: Obtain a scale-translation signal. In doubt, I associated directly the array "widths" with the array of the possible different scales. Because, I don’t understood what is parameter width if it’s not scale. Perhaps, you would tell me "it’s the width of your current wavelet"! But, even now, I'm not sure how link width with scale… In the Morlet documentation in Scipy, it seems that the link could be: "s: Scaling factor, windowed from -s*2*pi to +s*2*pi", so, I thought that width = 4*pi*scale (width=width of the window). But when I draw the wavelets, more scale increases, more the visual width of the wavelet decreases...

My second problem is to find and draw the equivalent with frequency. In literature, I find this formula: Fa = Fc / (s*delta), where Fa is the final frequency, Fc the center frequency of a wavelet in Hz, s the scale and delta the sampling period. So, ok for scale (if I find the link with the width) and delta (=0.001sec), but it’s more complicated with center frequency of the wavelet. In scipy documentation, I find that: "The fundamental frequency of this wavelet [morlet wavelet] in Hz is given by f = 2*s*w*r / M, where r is the sampling rate [s is here Scaling factor, windowed from -s*2*pi to +s*2*pi. Default is 1; w the width; and M the length of the wavelet]." I think it’s the center frequency, is it?

Thank you

Here my remanied code for cwt():

def MyCWT(data, wavelet, scales):

output = zeros([len(scales), len(data)], dtype=complex)

for ind, scale in enumerate(scales):

    window = scale*4*pi*10#Number of points to define correctly the wavelet
    waveletLength = min(window, len(data))#Number of points of the wavelet
    wavelet_data = wavelet(waveletLength, s=scale)#Need to precise w parameter???

    #To see the wavelets:
    plot(wavelet_data)
    xlabel('time (10^-3 sec)')
    ylabel('amplitude')
    title('Morlet Wavelet for scale='+str(scale)+'\nwidth='+str(window))
    show()

    #Concolution to calculate the current line for the current scale:
    z = convolve(data, wavelet_data, mode='same')

    i = 0
    for complexVal in z:
        output[ind][i] = complex(complexVal.real, complexVal.imag)         
        i+=1

return output

解决方案

The widths parameter is an array of width sizes to which the wavelet is stretched to before convolving the wavelet with the data.

You should choose a range starting with a value slightly smaller than your expected signal width, up to slightly larger. The more values you supply, the slower the calculation but the higher the resolution.

Check out the documentation or the referenced paper Bioinformatics (2006) 22 (17): 2059-2065. doi: 10.1093/bioinformatics/btl355 for more information.

这篇关于使用Scipy.signal(Python)进行连续小波变换:cwt()函数中的参数"widths"是什么? (时间频率)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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