[Mne_analysis] question about TF analysis

Marijn van Vliet w.m.vanvliet at gmail.com
Sun Dec 9 07:00:26 EST 2018
Search archives:

Hi Tao Xia,

since you indicated this is your first time doing TF analysis, I’m including some background info on wavelet analysis in my answer.

The tfr_morlet function computes the frequency content of a signal by constructing “wavelets”, which are specially crafted wave-like signals. Take a look at the picture here to see what they look like: https://en.wikipedia.org/wiki/Morlet_wavelet. For each frequency you specify in the `freqs` parameter (you specified 1, 2, 3, …, 19, 20 Hz) a wavelet is created. Technically, a wavelet has infinite length, but for practical purposes we cut it off at some point because its signal becomes too small to matter. The `n_cycles` parameter controls where we cut it. You specified to cut off the wavelet after 5 cycles, which is a sane cutoff. A Morlet wavelet of 1Hz (your lowest frequency) needs 5 seconds to complete 5 cycles, so this wavelet is 5 seconds in length. A Morlet wavelet of 20 Hz (your highest frequency) needs 0.25 seconds to complete 5 cycles.

To analyse the frequency content, each wavelet is multiplied with your signal. The error arises when attempting to multiply the 1 Hz wavelet, which is 5 seconds in length, with your signal: your signal is shorter than 5 seconds! What to do? There are several options:

1) The best option is to give the function more signal (at least 5 seconds worth). If that is not an option (because you don’t have any more signal), you can 
2) Drop the lower frequencies and try a range like 5-20 Hz instead. If that is not an option (you really need some indication of 1Hz content) you can
3) Decrease the `n_cycles` parameter and obtain a result with reduced frequency accuracy. Note that you can specify `n_cycles` for each wavelet separately if you want. For example, if your signal is 2 seconds in length, you can use 2 cycles for 1Hz, 4 cycles for 2 Hz and 5 cycles for all other frequencies. You can do this by giving `n_cycles` a list with the number of cycles for each frequency ([2, 4, 5, 5, 5, 5, 5, …] in this case).

Hope that helps!

Best,
Marijn.


 that are multiplied with the signal for which you want to know the frequency content. When calling the function, you give a list of frequencies you are interested in (you specified 1-20 Hz). The lower the frequency, the longer the wavelet is in time. At 1 Hz, it s~

> On 8 Dec 2018, at 16:04, Xia, Tao <psytao18 at connect.hku.hk> wrote:
> 
>         External Email - Use Caution        
> 
> 
> Hi~
>     I want to know how to set the n_cycles and freqs with the command tfr_morlet. when I set the n_cycles=5, freqs=np.arange(1,21,1) , there is an error: ValueError: At least one of the wavelets is longer than the signal. Use a longer signal or shorter wavelets. This is my first experience doing TF analysis, wish you could give me some help. Thanks a lot.
> 
> 
> Tao Xia
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1386 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20181209/c787a13c/attachment-0001.bin 
-------------- next part --------------
        External Email - Use Caution        
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20181209/c787a13c/attachment-0001.html 


More information about the Mne_analysis mailing list