# question about TF analysis

**URL:** <https://mne.discourse.group/t/question-about-tf-analysis/1678>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [December 8, 2018, 2:04pm UTC](https://mne.discourse.group/t/question-about-tf-analysis/1678 "2018-12-08T14:04:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [December 8, 2018, 2:04pm UTC](https://mne.discourse.group/t/question-about-tf-analysis/1678/1 "2018-12-08T14:04:30Z")

</div>

External Email - Use Caution

Hi~  
&nbsp;&nbsp;&nbsp;&nbsp;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  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20181208/db42d8ea/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20181208/db42d8ea/attachment.html)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [December 9, 2018, 12:00pm UTC](https://mne.discourse.group/t/question-about-tf-analysis/1678/2 "2018-12-09T12:00:26Z")

</div>

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: [Morlet wavelet - Wikipedia](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~

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;External Email - Use Caution
> 
> Hi~  
> &nbsp;&nbsp;&nbsp;&nbsp;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  
> [Mne\_analysis Info Page](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](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20181209/c787a13c/attachment-0001.bin)  
-------------- next part --------------  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20181209/c787a13c/attachment-0001.html)
