pyntbci.eeg.generate_noise
- pyntbci.eeg.generate_noise(n_trials: int, n_channels: int, n_samples: int, fs: int, white_noise: float = 1.0, pink_noise: float = 0.0, pink_exponent: float = 1.0, line_noise: float = 0.0, line_freq: float = 50.0, line_harmonics: int = 1, random_state: int | Generator = None, dtype: str | dtype = 'float32') NDArray[source]
Generate multi-channel EEG background noise as the sum of white sensor noise, 1/f pink noise, and electrical line noise. White noise is always included with a strictly positive amplitude, which guarantees that channels are statistically independent and hence that any data this noise is added to is of full rank across channels (almost surely, given at least n_channels independent samples), preventing singular covariance matrices.
- Parameters:
n_trials (int) – The number of trials to generate.
n_channels (int) – The number of channels to generate.
n_samples (int) – The number of samples per trial.
fs (int) – The sampling frequency in Hz.
white_noise (float (default: 1.0)) – The standard deviation of the white sensor noise. Must be strictly positive to guarantee full-rank data.
pink_noise (float (default: 0.0)) – The standard deviation of the 1/f pink noise. If 0, no pink noise is added.
pink_exponent (float (default: 1.0)) – The spectral exponent of the pink noise, see generate_pink_noise. Only used if pink_noise > 0.
line_noise (float (default: 0.0)) – The amplitude of the electrical line noise. If 0, no line noise is added.
line_freq (float (default: 50.0)) – The line noise frequency in Hz. Only used if line_noise > 0.
line_harmonics (int (default: 1)) – The number of line noise harmonics to include. Only used if line_noise > 0.
random_state (int | np.random.Generator (default: None)) – A seed or numpy random number generator to draw the noise from. If None, a new one is used.
dtype (str | np.dtype (default: "float32")) – The dtype of the returned array. The individual noise sources are summed in float64 internally, regardless of dtype, to avoid compounding rounding error; this only controls the precision of the final result.
- Returns:
noise – The combined noise of shape (n_trials, n_channels, n_samples).
- Return type:
NDArray