code: def 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,
  ):
      """Conveniently generate epochs around ECG artifact events.
  
      %(create_ecg_epochs)s
  
      .. note:: 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).
  
      Parameters
      ----------
      raw : instance of Raw
          The raw data.
      %(ch_name_ecg)s
      %(event_id_ecg)s
      %(picks_all)s
      tmin : float
          Start time before event.
      tmax : float
          End time after event.
      %(l_freq_ecg_filter)s
      %(reject_epochs)s
      %(flat)s
      %(baseline_epochs)s
      preload : bool
          Preload epochs or not (default True). Must be True if
          keep_ecg is True.
      keep_ecg : bool
          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.
      %(reject_by_annotation_epochs)s
  
          .. versionadded:: 0.14.0
      %(decim)s
  
          .. versionadded:: 0.21.0
      %(verbose)s
  
      Returns
      -------
      ecg_epochs : instance of Epochs
          Data epoched around ECG R wave peaks.
  
      See Also
      --------
      find_ecg_events
      compute_proj_ecg
  
      Notes
      -----
      If you already have a list of R-peak times, or want to compute R-peaks
      outside MNE-Python using a different algorithm, the recommended approach is
      to call the :class:`~mne.Epochs` constructor directly, with your R-peaks
      formatted as an :term:`events` array (here we also demonstrate the relevant
      default values)::
  
          mne.Epochs(raw, r_peak_events_array, tmin=-0.5, tmax=0.5,
                     baseline=None, preload=True, proj=False)  # doctest: +SKIP
      """
      has_ecg = "ecg" in raw or ch_name is not None
      if keep_ecg and (has_ecg or not preload):
          raise ValueError(
              "keep_ecg can be True only if the ECG channel is "
              "created synthetically and preload=True."
          )
  
      events, _, _, ecg = find_ecg_events(
          raw,
          ch_name=ch_name,
          event_id=event_id,
          l_freq=l_freq,
          h_freq=h_freq,
          return_ecg=True,
          reject_by_annotation=reject_by_annotation,
      )
  
      picks = _picks_to_idx(raw.info, picks, "all", exclude=())
  
      # create epochs around ECG events and baseline (important)
      ecg_epochs = Epochs(
          raw,
          events=events,
          event_id=event_id,
          tmin=tmin,
          tmax=tmax,
          proj=False,
          flat=flat,
          picks=picks,
          reject=reject,
          baseline=baseline,
          reject_by_annotation=reject_by_annotation,
          preload=preload,
          decim=decim,
      )
  
      if keep_ecg:
          # We know we have created a synthetic channel and epochs are preloaded
          ecg_raw = RawArray(
              ecg,
              create_info(
                  ch_names=["ECG-SYN"],
                  sfreq=raw.info["sfreq"],
                  ch_types=["ecg"],
              ),
              first_samp=raw.first_samp,
          )
          with ecg_raw.info._unlock():
              ignore = ["ch_names", "chs", "nchan", "bads"]
              for k, v in raw.info.items():
                  if k not in ignore:
                      ecg_raw.info[k] = v
          syn_epochs = Epochs(
              ecg_raw,
              events=ecg_epochs.events,
              event_id=event_id,
              tmin=tmin,
              tmax=tmax,
              proj=False,
              picks=[0],
              baseline=baseline,
              decim=decim,
              preload=True,
          )
          ecg_epochs = ecg_epochs.add_channels([syn_epochs])
  
      return ecg_epochs
  
file_path: mne-python/mne/preprocessing/ecg.py
imports: import numpy
  from .._fiff.meas_info import create_info
  from .._fiff.pick import _picks_to_idx, pick_channels, pick_types
  from ..annotations import _annotations_starts_stops
  from ..epochs import BaseEpochs, Epochs
  from ..evoked import Evoked
  from ..filter import filter_data
  from ..io import BaseRaw, RawArray
  from ..utils import int_like, logger, sum_squared, verbose, warn
label_desc: Use image node_id 4 for calling a global function with example usage: create_ecg_epochs(raw, ch_name, event_id, picks, tmin, tmax, l_freq, h_freq, reject, flat, baseline, preload, keep_ecg, reject_by_annotation, decim, verbose) and returns: ecg_epochs