5
$\begingroup$

I search to display a time-frequency signal with an original discrete temporal signal (sampling step = 0.001sec). I use Python and the library Scipy.signal. I use the function cwt(data, wavelet, widths) to do a continuous wavelet transform, with the complex morlet wavelet (or gabor wavelet).

First step: Obtain a scale-translation signal. In doubt, I associate directly the array “widths” with the array of the possible different scales. Because, I don’t understand what is parameter width if it’s not scale. Perhaps, you will tell me “it’s the width of your current wavelet”! But, even if it is, I don’t know how linked width with scale…

My second problem is to find and display 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? Maybe the solution to my first problem is here also (scaling factor and scale..?)..?

Thank you

$\endgroup$
  • $\begingroup$ Instinctively, morlet wavelet should be effective with cwt function. In fact, the morlet is even in the same script that cwt function! And yet, my first test don't... I'm (really) not an expert, but I changed myself the cwt function and for me, the problem came from the initialization of the matrix of return (see script of cwt). I believe that I skirt the problem just in adding dtype=complex as parameter in the zeros() function. Thank for the link. I will try :) But I would know link between width/scale if there is... $\endgroup$ – ArnoNoo Apr 4 '14 at 14:14
  • $\begingroup$ Well the cwt docstring says that ricker is meant to be used with it, so try that first? "The first argument is the number of points that the returned vector will have (len(wavelet(width,length)) == length). The second is a width parameter, defining the size of the wavelet" morlet has separate parameters for both frequency and scale, while ricker's second parameter is "width". I don't know if morlet's "frequency" or "scale" is compatible with "width", but I'd guess that "scale" is the one, which means morlet is not compatible with cwt. $\endgroup$ – endolith Apr 4 '14 at 14:56
  • $\begingroup$ I have already used ricker, but I need a complex wavelet (and morlet was the only available on Scipy) because I need to use complex result to find local phase. Like I said, I'm not an expert, but yet, I think it's not really difficult to do a CWT with morlet, because the convolution product is always efficient. I think I'm not far to understand the issue (I'm not so far on the visual result from the example on MATLAB which I cited in my post). Just, I must to learn a little more on mathematical formula of CWT method & morlet function, to control all the process. I will be back! ^^ $\endgroup$ – ArnoNoo Apr 4 '14 at 15:45
  • $\begingroup$ Width in this function is very bad defined. It is actually not width at all. I would assume it is scale, but still can not find any well documented informaiton $\endgroup$ – Guosong Zhang Jul 2 '18 at 8:48
3
$\begingroup$

There's no indication that cwt is meant to be compatible with morlet. As cwt docstring says:

Wavelet function, which should take 2 arguments. ... second is a width parameter, defining the size of the wavelet (e.g. standard deviation of a gaussian).

The morlet function takes 4 arguments, the second of which is not a width parameter, it's a frequency parameter, so I don't think it is meant to be used with cwt. Using ricker as a template, you are supposed to define your own functions to use with cwt. In addition, cwt cannot handle complex wavelets (as of v0.18).

I'd suggest you try a different implementation that has this done for you:

  • Pyscellania has a Wavelets module (now mirrored at github) which implements real/complex Morlet, MexicanHat, Paul order 2, Paul order 4, 1st Derivative Of Gaussian, 4th Derivative Of Gaussian, Unnormalised version of continuous Haar transform, Normalised Haar
  • aaren/wavelets supports Morlet, Paul, DOG, Ricker
  • Machine Learning PYthon (mlpy) has mlpy.wavelet.cwt that supports Morlet, Paul, and Derivative Of Gaussian wavelets
  • Dapid/fast-pycwt supports Morlet and Ricker
  • ObsPy (seismological observatories) has a cwt module and "for now only 'morlet' is implemented"
  • pyCWT has Morlet wavelet
$\endgroup$
  • 1
    $\begingroup$ As of v0.18, the second parameter w is a ratio parameter that determines how many oscillation there are in the gaussian envelope of the wavelet. It can be varied depending on your application, but it should be constant regardless of the scane/frequency of each of your transforms. The s (for scale) parameter is the width you are looking for. You could use a lambda function that sets w and interfaces with cwt(), that's what I usually do when working with it. When w = 1, the central frequency of the wavelet has the same scale-frequency relation as a Fourier transform. $\endgroup$ – PhilMacKay Sep 26 '16 at 19:14
0
$\begingroup$

I tried to study directly the morlet wavelet function in testing different values for width and scale parameters. The results are that it's not (for me) intuituve :

  • width corresponds to the numbers of peaks of the wavelet
  • scale varies the "width" of the wavelet form (worth: more s increases, more this width decreases... It's in opposition to this method)

In fact, this method says:

Scaling, as a mathematical operation, either dilates or compresses a signal. Larger scales correspond to dilated (or stretched out) signals and small scales correspond to compressed signals.

I will search another methods to try to see where is the problem. Unless someone knows already the response. Thanks.


In fact, the problem seems to come from the number of cycles of the wavelets: more the frequency increases, more the number of cycles must follow. And the number of cycles is really linked with parameter "w" in morlet wavelet. It is really important if you do a study over a large band of frequency. Hope that it will help others.

$\endgroup$
  • $\begingroup$ In fact, the function of the morlet wavelet is: morlet(w,x) = pi**-0.25 * exp(1jwx) * exp(-0.5*(x**2)), where x is scaled on [-s*2*pi ; +s*2*pi] and corresponding to time, and w, called width (because it's the place of the parameter width for the current wavelet when used by cwt()), it's for me omega (angular frequency). In consequence, indeed, it can be perhaps more complicated that I thought to use morlet with cwt. But if I understand well, the fundamental frequency of the wavelet is just: Fc=w/2*pi. But it's surely possible, the function convolve() can do that... $\endgroup$ – ArnoNoo Apr 9 '14 at 9:36
  • 1
    $\begingroup$ I found an interesting link here. On the slide 4, the formula of the wavelet transform shows the correct scale. I try to use this formula in building my own convolution function. $\endgroup$ – ArnoNoo Apr 9 '14 at 10:08
  • $\begingroup$ Moreover, this formula is for continuous signal and I have a discrete signal. The functions of Scipy seem to enable to use discrete signal like a continuous signal (depending maybe of the importance of points). I read the description of Discrete Wavelet Transform (DWT), and it seems really more difficult to apply... $\endgroup$ – ArnoNoo Apr 9 '14 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.