mne.preprocessing.create_ecg_epochs(raw, ch_name=None, event_id=999, picks=None, tmin=- 0.5, tmax=0.5, l_freq=8, h_freq=16, reject=None, flat=None, baseline=None, preload=True, keep_ecg=False, reject_by_annotation=True, decim=1, verbose=None)[source]

Conveniently generate epochs around ECG artifact events.

rawinstance of Raw

The raw data.

ch_nameNone | str

The name of the channel to use for ECG peak detection. If None (default), ECG channel is used if present. If None and no ECG channel is present, a synthetic ECG channel is created from cross channel average. Synthetic channel can only be created from MEG channels.


The index to assign to found events.

picksstr | list | slice | None

Channels to include. Slices and lists of integers will be interpreted as channel indices. In lists, channel type strings (e.g., ['meg', 'eeg']) will pick channels of those types, channel name strings (e.g., ['MEG0111', 'MEG2623'] will pick the given channels. Can also be the string values “all” to pick all channels, or “data” to pick data channels. None (default) will pick all channels.


Start time before event.


End time after event.


Low pass frequency to apply to the ECG channel while finding events.


High pass frequency to apply to the ECG channel while finding events.

rejectdict | None

Rejection parameters based on peak-to-peak amplitude. Valid keys are ‘grad’ | ‘mag’ | ‘eeg’ | ‘eog’ | ‘ecg’. If reject is None then no rejection is done. Example:

reject = dict(grad=4000e-13, # T / m (gradiometers)
              mag=4e-12, # T (magnetometers)
              eeg=40e-6, # V (EEG channels)
              eog=250e-6 # V (EOG channels)
flatdict | None

Rejection parameters based on flatness of signal. Valid keys are ‘grad’ | ‘mag’ | ‘eeg’ | ‘eog’ | ‘ecg’, and values are floats that set the minimum acceptable peak-to-peak amplitude. If flat is None then no rejection is done.

baselinetuple | list of length 2 | None

The time interval to apply rescaling / baseline correction. If None do not apply it. If baseline is (a, b) the interval is between “a (s)” and “b (s)”. If a is None the beginning of the data is used and if b is None then b is set to the end of the interval. If baseline is equal to (None, None) all the time interval is used. If None, no correction is applied.


Preload epochs or not (default True). Must be True if keep_ecg is True.


When ECG is synthetically created (after picking), should it be added to the epochs? Must be False when synthetic channel is not used. Defaults to False.


Whether to reject based on annotations. If True (default), epochs overlapping with segments whose description begins with 'bad' are rejected. If False, no rejection based on annotations is performed.

New in version 0.14.0.


Factor by which to subsample the data.


Low-pass filtering is not performed, this simply selects every Nth sample (where N is the value passed to decim), i.e., it compresses the signal (see Notes). If the data are not properly filtered, aliasing artifacts may occur.

New in version 0.21.0.

verbosebool, str, int, or None

If not None, override default verbose level (see mne.verbose() and Logging documentation for more). If used, it should be passed as a keyword-argument only.

ecg_epochsinstance of Epochs

Data epoched around ECG r-peaks.


Filtering is only applied to the ECG channel while finding events. The resulting ecg_epochs will have no filtering applied (i.e., have the same filter properties as the input raw instance).