Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Morlet wavelet length in tfr_morlet #12073

Merged
merged 14 commits into from
Oct 6, 2023
2 changes: 1 addition & 1 deletion mne/time_frequency/multitaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def tfr_array_multitaper(

Notes
-----
%(temporal-window_tfr_notes)s
%(temporal-window_tfr_multitaper_notes)s
ruuskas marked this conversation as resolved.
Show resolved Hide resolved
%(time_bandwidth_tfr_notes)s

.. versionadded:: 0.14.0
Expand Down
7 changes: 3 additions & 4 deletions mne/time_frequency/tfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,7 @@ def tfr_morlet(
Notes
-----
%(morlet_notes)s
%(temporal-window_tfr_notes)s
%(fwhm_morlet_notes)s
%(temporal-window_tfr_morlet_notes)s

See :func:`mne.time_frequency.morlet` for more information about the
Morlet wavelet.
Expand Down Expand Up @@ -1040,7 +1039,7 @@ def tfr_array_morlet(
Notes
-----
%(morlet_notes)s
%(temporal-window_tfr_notes)s
%(temporal-window_tfr_morlet_notes)s
ruuskas marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: 0.14.0

Expand Down Expand Up @@ -1121,7 +1120,7 @@ def tfr_multitaper(

Notes
-----
%(temporal-window_tfr_notes)s
%(temporal-window_tfr_multitaper_notes)s
ruuskas marked this conversation as resolved.
Show resolved Hide resolved
%(time_bandwidth_tfr_notes)s

.. versionadded:: 0.9.0
Expand Down
37 changes: 30 additions & 7 deletions mne/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4411,9 +4411,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
the distribution.
"""

docdict[
"temporal-window_tfr_notes"
] = r"""
_temporal_window_tfr_base = """
In spectrotemporal analysis (as with traditional fourier methods),
the temporal and spectral resolution are interrelated: longer temporal windows
allow more precise frequency estimates; shorter temporal windows "smear"
Expand All @@ -4431,18 +4429,43 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
smoothing increases with frequency.*
Source: `FieldTrip tutorial: Time-frequency analysis using Hanning window,
multitapers and wavelets <https://www.fieldtriptoolbox.org/tutorial/timefrequencyanalysis>`_.
"""
ruuskas marked this conversation as resolved.
Show resolved Hide resolved

docdict["temporal-window_tfr_morlet_notes"] = (
_temporal_window_tfr_base
+ r"""
In MNE-Python, the length of the Morlet wavelet is affected by the arguments
``freqs`` and ``n_cycles``, which define the frequencies of interest
and the number of cycles, respectively. For the time-frequency representation,
the length of the wavelet is defined such that both tails of
the wavelet extend five standard deviations from the midpoint of its Gaussian
envelope and that there is a sample at time zero.

The length of the wavelet is thus :math:`10\times\mathtt{sfreq}\cdot\sigma-1`,
which is equal to :math:`\frac{5}{\pi} \cdot \frac{\mathtt{n\_cycles} \cdot
\mathtt{sfreq}}{\mathtt{freqs}} - 1`, where
:math:`\sigma = \frac{\texttt{n\_cycles}}{2\pi f}` corresponds to the standard
ruuskas marked this conversation as resolved.
Show resolved Hide resolved
deviation of the wavelet's Gaussian envelope. Note that the length of the
wavelet must not exceed the length of your signal.

For more information on the Morlet wavelet, see `mne.time_frequency.morlet`."""
ruuskas marked this conversation as resolved.
Show resolved Hide resolved
)

In MNE-Python, the temporal window length is defined by the arguments ``freqs``
and ``n_cycles``, respectively defining the frequencies of interest and the
number of cycles: :math:`T = \frac{\mathtt{n\_cycles}}{\mathtt{freqs}}`
docdict["temporal-window_tfr_multitaper_notes"] = (
_temporal_window_tfr_base
+ r"""
In MNE-Python, the multitaper temporal window length is defined by the arguments
``freqs`` and ``n_cycles``, respectively defining the frequencies of interest
and the number of cycles: :math:`T = \frac{\mathtt{n\_cycles}}{\mathtt{freqs}}`

A fixed number of cycles for all frequencies will yield a temporal window which
decreases with frequency. For example, ``freqs=np.arange(1, 6, 2)`` and
``n_cycles=2`` yields ``T=array([2., 0.7, 0.4])``.

To use a temporal window with fixed length, the number of cycles has to be
defined based on the frequency. For example, ``freqs=np.arange(1, 6, 2)`` and
``n_cycles=freqs / 2`` yields ``T=array([0.5, 0.5, 0.5])``.""" # noqa: E501
``n_cycles=freqs / 2`` yields ``T=array([0.5, 0.5, 0.5])``."""
) # noqa: E501

_theme = """\
theme : str | path-like
Expand Down
Loading