.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/biosignal-erp/plot_ERP.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_biosignal-erp_plot_ERP.py: =============================================================================== Display ERP =============================================================================== Different ways to display a multichannel event-related potential (ERP). .. GENERATED FROM PYTHON SOURCE LINES 9-20 .. code-block:: Python # Authors: Quentin Barthélemy # # License: BSD (3-clause) from matplotlib import pyplot as plt import mne import numpy as np from pyriemann.utils.viz import plot_waveforms .. GENERATED FROM PYTHON SOURCE LINES 21-23 Load EEG data ------------- .. GENERATED FROM PYTHON SOURCE LINES 23-49 .. code-block:: Python # Set filenames data_path = str(mne.datasets.sample.data_path()) raw_fname = data_path + "/MEG/sample/sample_audvis_filt-0-40_raw.fif" event_fname = data_path + "/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif" # Read raw data, select occipital channels and high-pass filter signal raw = mne.io.Raw(raw_fname, preload=True, verbose=False) raw.pick_channels(["EEG 057", "EEG 058", "EEG 059"], ordered=True) raw.rename_channels({"EEG 057": "O1", "EEG 058": "Oz", "EEG 059": "O2"}) n_channels = len(raw.ch_names) raw.filter(1.0, None, method="iir") # Read epochs and get responses to left visual field stimulus tmin, tmax = -0.1, 0.8 epochs = mne.Epochs( raw, mne.read_events(event_fname), {"vis_l": 3}, tmin, tmax, proj=False, baseline=None, preload=True, verbose=False) X = 5e5 * epochs.get_data(copy=False) print("Number of trials:", X.shape[0]) times = np.linspace(tmin, tmax, num=X.shape[2]) plt.rcParams["figure.figsize"] = (7, 12) ylims = [] .. rst-class:: sphx-glr-script-out .. code-block:: none NOTE: pick_channels() is a legacy function. New code should use inst.pick(...). Filtering raw data in 1 contiguous segment Setting up high-pass filter at 1 Hz IIR filter parameters --------------------- Butterworth highpass zero-phase (two-pass forward and reverse) non-causal filter: - Filter order 8 (effective, after forward-backward) - Cutoff at 1.00 Hz: -6.02 dB Number of trials: 73 .. GENERATED FROM PYTHON SOURCE LINES 50-54 Plot all trials --------------- This kind of plot is a little bit messy. .. GENERATED FROM PYTHON SOURCE LINES 54-65 .. code-block:: Python fig = plot_waveforms(X, "all", times=times, alpha=0.3) fig.suptitle("Plot all trials", fontsize=16) for i_channel in range(n_channels): fig.axes[i_channel].set(ylabel=raw.ch_names[i_channel]) fig.axes[i_channel].set_xlim(tmin, tmax) ylims.append(fig.axes[i_channel].get_ylim()) fig.axes[n_channels - 1].set(xlabel="Time") plt.show() .. image-sg:: /auto_examples/biosignal-erp/images/sphx_glr_plot_ERP_001.png :alt: Plot all trials :srcset: /auto_examples/biosignal-erp/images/sphx_glr_plot_ERP_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 66-72 Plot central tendency and dispersion of trials ---------------------------------------------- This kind of plot is well-spread, but mean and standard deviation can be contaminated by artifacts, and they make a symmetric assumption on amplitude distribution. .. GENERATED FROM PYTHON SOURCE LINES 72-83 .. code-block:: Python fig = plot_waveforms(X, "mean+/-std", times=times) fig.suptitle("Plot mean+/-std of trials", fontsize=16) for i_channel in range(n_channels): fig.axes[i_channel].set(ylabel=raw.ch_names[i_channel]) fig.axes[i_channel].set_xlim(tmin, tmax) fig.axes[i_channel].set_ylim(ylims[i_channel]) fig.axes[n_channels - 1].set(xlabel="Time") plt.show() .. image-sg:: /auto_examples/biosignal-erp/images/sphx_glr_plot_ERP_002.png :alt: Plot mean+/-std of trials :srcset: /auto_examples/biosignal-erp/images/sphx_glr_plot_ERP_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 84-88 Plot histogram of trials ------------------------ This plot estimates a 2D histogram of trials [1]_. .. GENERATED FROM PYTHON SOURCE LINES 88-98 .. code-block:: Python fig = plot_waveforms(X, "hist", times=times, n_bins=25, cmap=plt.cm.Greys) fig.suptitle("Plot histogram of trials", fontsize=16) for i_channel in range(n_channels): fig.axes[i_channel].set(ylabel=raw.ch_names[i_channel]) fig.axes[i_channel].set_ylim(ylims[i_channel]) fig.axes[n_channels - 1].set(xlabel="Time") plt.show() .. image-sg:: /auto_examples/biosignal-erp/images/sphx_glr_plot_ERP_003.png :alt: Plot histogram of trials :srcset: /auto_examples/biosignal-erp/images/sphx_glr_plot_ERP_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 99-106 References ---------- .. [1] `Improved estimation of EEG evoked potentials by jitter compensation and enhancing spatial filters `_ A. Souloumiac and B. Rivet. 2013 IEEE International Conference on Acoustics, Speech and Signal Processing. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.569 seconds) .. _sphx_glr_download_auto_examples_biosignal-erp_plot_ERP.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_ERP.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_ERP.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_ERP.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_