<jupyter_start><jupyter_text>Find ECG artifactsLocate QRS component of ECG.<jupyter_code># Authors: <NAME> <<EMAIL>>
#
# License: BSD (3-clause)


import numpy as np
import matplotlib.pyplot as plt

import mne
from mne import io
from mne.datasets import sample

print(__doc__)

data_path = sample.data_path()<jupyter_output><empty_output><jupyter_text>Set parameters<jupyter_code>raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'

# Setup for reading the raw data
raw = io.read_raw_fif(raw_fname)

event_id = 999
ecg_events, _, _ = mne.preprocessing.find_ecg_events(raw, event_id,
                                                     ch_name='MEG 1531')

# Read epochs
picks = mne.pick_types(raw.info, meg=False, eeg=False, stim=False, eog=False,
                       include=['MEG 1531'], exclude='bads')
tmin, tmax = -0.1, 0.1
epochs = mne.Epochs(raw, ecg_events, event_id, tmin, tmax, picks=picks,
                    proj=False)
data = epochs.get_data()

print("Number of detected ECG artifacts : %d" % len(data))<jupyter_output><empty_output><jupyter_text>Plot ECG artifacts<jupyter_code>plt.plot(1e3 * epochs.times, np.squeeze(data).T)
plt.xlabel('Times (ms)')
plt.ylabel('ECG')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12530315278900567, 'fraction_numerical': 0.014551333872271624, 'mean_word_length': 4.115702479338843, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '41562', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 486, 'n_tokens_neox': 458, 'n_words': 92, 'path': '0.13/_downloads/plot_find_ecg_artifacts.ipynb', 'repo_name': 'drammock/mne-tools.github.io', 'size': '1281'}