spectral_connectivity.transforms.suggest_parameters#

suggest_parameters(sampling_frequency: float, signal_duration: float, frequency_resolution: float | None = None, desired_n_tapers: int | None = None, *, desired_freq_resolution: float | None = None) → MultitaperParameters[source]#

Suggest appropriate multitaper parameters for your analysis.

This helper function recommends parameters based on your data characteristics and analysis goals. It helps answer the common question: “What parameters should I use for my data?”

frequency_resolution (the target you pass) and the returned frequency_resolution (the resolution achieved) are both full DPSS concentration bandwidths in Hz, 2 * NW / time_window_duration, not FFT bin spacing.

Changed in version 3.0: The target resolution is named frequency_resolution, as in Multitaper and estimate_frequency_resolution(); it keeps its third position, so positional calls are unchanged. desired_freq_resolution= still works through 3.x with a DeprecationWarning and is removed in 4.0.

Parameters:
  • sampling_frequency (float) – Sampling rate in Hz of your data.

  • signal_duration (float) – Total duration in seconds of your signal.

  • frequency_resolution (float, optional) – Target frequency resolution in Hz. If specified, parameters will be chosen to achieve approximately this resolution. Given with desired_n_tapers, it takes precedence (see Warns).

  • desired_n_tapers (int, optional) – Target number of tapers for variance reduction. If specified, time_halfbandwidth_product will be chosen to achieve this. desired_n_tapers is a target; the returned n_tapers is what you get. Ignored, with a warning, when frequency_resolution is also given.

  • desired_freq_resolution (float, optional) – Deprecated name of frequency_resolution, by keyword only; removed in 4.0. Giving both raises ValueError.

Returns:

params – TypedDict containing suggested parameters with the following keys: - ‘sampling_frequency’: float - Input sampling frequency - ‘time_halfbandwidth_product’: float - Suggested NW - ‘time_window_duration’: float - Suggested window duration (seconds) - ‘n_tapers’: int - Number of tapers - ‘frequency_resolution’: float - Resulting frequency resolution (Hz) - ‘n_time_windows’: int - Approximate number of time windows - ‘nyquist_frequency’: float - Maximum frequency (Hz)

Return type:

MultitaperParameters

Raises:

ValueError – If desired frequency resolution is impossible to achieve with given signal duration.

Warns:
  • UserWarning – If both frequency_resolution and desired_n_tapers are specified. In this case, frequency_resolution takes precedence and desired_n_tapers is ignored.

  • UserWarning – If keeping frequency_resolution with at least 3 time windows leaves fewer than 2 tapers; use a longer signal or a coarser resolution.

Notes

Default behavior (no targets specified): - Uses NW=3 (balanced trade-off) - Sets window duration to capture ~5 time windows - Aims for reasonable frequency and time resolution

With frequency_resolution: - Calculates required window duration: T = 2*NW / Δf_target - Uses NW=3 by default unless this gives too few time windows - Ensures at least 3 time windows for temporal dynamics

With desired_n_tapers: - Calculates NW from: NW = (n_tapers + 1) / 2 - Uses reasonable window duration based on signal length

Examples

Get reasonable defaults for EEG data:

>>> params = suggest_parameters(
...     sampling_frequency=250,
...     signal_duration=60.0,
... )
>>> print(f"Suggested NW: {params['time_halfbandwidth_product']}")
Suggested NW: 3.0
>>> print(f"Window duration: {params['time_window_duration']:.2f}s")
Window duration: 12.00s
>>> print(f"Frequency resolution: {params['frequency_resolution']:.2f} Hz")
Frequency resolution: 0.50 Hz
>>> print(f"Number of tapers: {params['n_tapers']}")
Number of tapers: 5

Target specific frequency resolution:

>>> params = suggest_parameters(
...     sampling_frequency=1000,
...     signal_duration=10.0,
...     frequency_resolution=2.0,  # Want 2 Hz resolution
... )
>>> print(f"Achieved resolution: {params['frequency_resolution']:.2f} Hz")
Achieved resolution: 2.00 Hz

Target specific number of tapers:

>>> params = suggest_parameters(
...     sampling_frequency=1000,
...     signal_duration=5.0,
...     desired_n_tapers=9,  # Want strong averaging
... )
>>> print(f"Number of tapers: {params['n_tapers']}")
Number of tapers: 9

See also

estimate_frequency_resolution

Calculate frequency resolution

estimate_n_tapers

Calculate number of tapers

Multitaper.summarize_parameters

Display parameters for existing analysis