pyntbci.eeg.generate_pink_noise

pyntbci.eeg.generate_pink_noise(n_trials: int, n_channels: int, n_samples: int, amplitude: float = 1.0, exponent: float = 1.0, random_state: int | Generator = None, dtype: str | dtype = 'float32') NDArray[source]

Generate 1/f (pink) noise per channel, approximating the aperiodic background spectrum of EEG. Each channel is generated independently by shaping the amplitude spectrum of independent white noise.

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.

  • amplitude (float (default: 1.0)) – The standard deviation of the noise.

  • exponent (float (default: 1.0)) – The spectral exponent, such that the power spectral density scales with 1 / (freq ** exponent). A value of 1.0 gives classical pink noise, 0.0 gives white noise, and 2.0 gives brown noise.

  • 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. Computation (including the FFT) is always done in float64/complex128 internally; this only controls the precision of the final result.

Returns:

noise – The pink noise of shape (n_trials, n_channels, n_samples).

Return type:

NDArray