spectral_connectivity.simulate.simulate_lagged_broadband#
- simulate_lagged_broadband(lags_samples: ArrayLike, noise_levels: ArrayLike, n_time_samples: int, n_trials: int | None = 1, random_state: int | Generator | None = None) NDArray[floating][source]#
Noisy copies of one white-noise source, each delayed by whole samples.
Signal
kissource[t - lags_samples[k]] + noise_levels[k] * N(0, 1), so a signal with a smaller lag leads one with a larger lag by their difference in samples. The source is broadband on purpose: a sinusoid delayed by a whole number of cycles is indistinguishable from the original and carries no lag information for group delay or the phase slope index.- Parameters:
lags_samples (array_like of int, shape (n_signals,)) – Delay of each signal behind the source, in whole samples (not seconds). Must be non-negative integers; express a lead as a smaller lag on the leading signal, e.g.
lags_samples=(0, 3)for signal 0 leading signal 1 by 3 samples. Convert a delay in seconds withround(delay * sampling_frequency), as in the second example. Python’sroundsends an exact half to the even neighbour (10.5 samples become 10, 11.5 become 12), and a delay of half a sample or less becomes 0, so the signals are simultaneous: check the simulated delay,lags_samples[k] / sampling_frequencyseconds, or simulate at a higher rate.noise_levels (float or array_like of float, shape (n_signals,)) – Standard deviation of the independent Gaussian noise added to each signal. A scalar applies to every signal; 0 gives the pure delayed source.
n_time_samples (int) – Number of time samples per signal.
n_trials (int or None, default=1) – Number of independent trials. None draws the default single trial and returns it without its trial axis, as a 2-D array.
random_state (int, np.random.Generator, or None, optional) – Seed or generator for reproducible results.
- Returns:
time_series – The delayed noisy copies,
(time, trial, signal)likesimulate_MVAR;(time, signal)whenn_trialsis None.- Return type:
NDArray[floating], shape (n_time_samples, n_trials, n_signals) or (n_time_samples, n_signals)
- Raises:
ValueError – If any lag is negative or not an integer, if
noise_levelsis neither a scalar nor one value per signal, or ifn_time_samplesorn_trials(unless None) is not a positive integer.
Notes
The source has
n_time_samples + max(lags_samples)samples and signalkis its slice starting atmax(lags_samples) - lags_samples[k], so no sample wraps around. The source is drawn first, then all of the noise in one draw of shapetime_series.shape.Examples
>>> import numpy as np >>> time_series = simulate_lagged_broadband( ... lags_samples=(0, 3), noise_levels=0.0, n_time_samples=100, random_state=0 ... ) >>> time_series.shape (100, 1, 2) >>> # Signal 1 repeats signal 0 three samples later: signal 0 leads. >>> bool(np.array_equal(time_series[3:, :, 1], time_series[:-3, :, 0])) True
For a delay given in seconds, round it to whole samples at the sampling rate, pass that count as
lags_samples=(0, lag_samples), and check the delay it simulates:>>> sampling_frequency = 1500.0 # Hz >>> delay = 0.0102 # seconds: signal 0 should lead signal 1 by 10.2 ms >>> lag_samples = round(delay * sampling_frequency) # 15.3 samples, rounded >>> lag_samples 15 >>> lag_samples / sampling_frequency # the delay actually simulated, in seconds 0.01