mne.simulation.add_ecg#

mne.simulation.add_ecg(raw, head_pos=None, interp='cos2', n_jobs=None, verbose=None, *, rng=None, random_state=None)[source]#

Add ECG noise to raw data.

Parameters:
rawinstance of Raw

The raw instance to modify.

head_posNone | path-like | dict | tuple | array

Path to the position estimates file. Should be in the format of the files produced by MaxFilter. If dict, keys should be the time points and entries should be 4x4 dev_head_t matrices. If None, the original head position (from info['dev_head_t']) will be used. If tuple, should have the same format as data returned by head_pos_to_trans_rot_t. If array, should be of the form returned by mne.chpi.read_head_pos().

interpstr

Either 'hann', 'cos2' (default), 'linear', or 'zero', the type of forward-solution interpolation to use between forward solutions at different head positions.

n_jobsint | None

The number of jobs to run in parallel. If -1, it is set to the number of CPU cores. Requires the joblib package. None (default) is a marker for ‘unset’ that will be interpreted as n_jobs=1 (sequential execution) unless the call is performed under a joblib.parallel_config context manager that sets another value for n_jobs.

verbosebool | str | int | None

Control verbosity of the logging output. If None, use the default verbosity level. See the logging documentation and mne.verbose() for details. Should only be passed as a keyword argument.

rngNone | int | instance of Generator | RandomState

The random number generator (RNG). If None (default), a new numpy.random.Generator seeded from entropy is used. Pass an int or a numpy.random.Generator for reproducible results, or a legacy RandomState to control the random-number stream or for interoperability with third-party code such as scikit-learn that does not accept generators. An integer seed uses numpy.random.default_rng() and therefore produces a different stream than the same integer passed to a legacy random_state or seed parameter.

New in v1.13.

random_stateNone | int | instance of RandomState

Supported for compatibility. New code should use rng. If None, NumPy’s global RandomState is used. The random generator state used for blink, ECG, and sensor noise randomization.

Returns:
rawinstance of Raw

The instance, modified in place.

Notes

The ECG artifacts are generated by:

  1. Random inter-beat intervals are drawn from a uniform distribution of times corresponding to 40 and 80 beats per minute.

  2. The activation function is the sum of three Hanning windows with varying durations and scales to make a more complex waveform.

  3. The activated dipole is located one (estimated) head radius to the left (-x) of head center and three head radii below (+z) head center; this dipole is oriented in the +x direction.

  4. Activations only affect MEG channels.

The scale-factor of the activation function was chosen based on visual inspection to yield amplitudes generally consistent with those seen in experimental data. Noisy versions of the activation will be stored in the first EOG channel in the raw instance, if it exists.

New in v0.18.

Examples using mne.simulation.add_ecg#

Generate simulated raw data

Generate simulated raw data

Simulate raw data using subject anatomy

Simulate raw data using subject anatomy