{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "execution_count": null, "cell_type": "code", "source": [ "%matplotlib inline" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "\n\nIntroduction to artifacts and artifact detection\n================================================\n\nSince MNE supports the data of many different acquisition systems, the\nparticular artifacts in your data might behave very differently from the\nartifacts you can observe in our tutorials and examples.\n\nTherefore you should be aware of the different approaches and of\nthe variability of artifact rejection (automatic/manual) procedures described\nonwards. At the end consider always to visually inspect your data\nafter artifact rejection or correction.\n\nBackground: what is an artifact?\n--------------------------------\n\nArtifacts are signal interference that can be\nendogenous (biological) and exogenous (environmental).\nTypical biological artifacts are head movements, eye blinks\nor eye movements, heart beats. The most common environmental\nartifact is due to the power line, the so-called *line noise*.\n\nHow to handle artifacts?\n------------------------\n\nMNE deals with artifacts by first identifying them, and subsequently removing\nthem. Detection of artifacts can be done visually, or using automatic routines\n(or a combination of both). After you know what the artifacts are, you need\nremove them. This can be done by:\n\n - *ignoring* the piece of corrupted data\n - *fixing* the corrupted data\n\nFor the artifact detection the functions MNE provides depend on whether\nyour data is continuous (Raw) or epoch-based (Epochs) and depending on\nwhether your data is stored on disk or already in memory.\n\nDetecting the artifacts without reading the complete data into memory allows\nyou to work with datasets that are too large to fit in memory all at once.\nDetecting the artifacts in continuous data allows you to apply filters\n(e.g. a band-pass filter to zoom in on the muscle artifacts on the temporal\nchannels) without having to worry about edge effects due to the filter\n(i.e. filter ringing). Having the data in memory after segmenting/epoching is\nhowever a very efficient way of browsing through the data which helps\nin visualizing. So to conclude, there is not a single most optimal manner\nto detect the artifacts: it just depends on the data properties and your\nown preferences.\n\nIn this tutorial we show how to detect artifacts visually and automatically.\nFor how to correct artifacts by rejection see `tut_artifacts_reject`.\nTo discover how to correct certain artifacts by filtering see\n`tut_artifacts_filter` and to learn how to correct artifacts\nwith subspace methods like SSP and ICA see `tut_artifacts_correct_ssp`\nand `tut_artifacts_correct_ica`.\n\n\nArtifacts Detection\n-------------------\n\nThis tutorial discusses a couple of major artifacts that most analyses\nhave to deal with and demonstrates how to detect them.\n\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "import numpy as np\n\nimport mne\nfrom mne.datasets import sample\nfrom mne.preprocessing import create_ecg_epochs, create_eog_epochs\n\n# getting some data ready\ndata_path = sample.data_path()\nraw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'\n\nraw = mne.io.read_raw_fif(raw_fname, preload=True)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Low frequency drifts and line noise\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "(raw.copy().pick_types(meg='mag')\n .del_proj(0)\n .plot(duration=60, n_channels=100, remove_dc=False))" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "we see high amplitude undulations in low frequencies, spanning across tens of\nseconds\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "raw.plot_psd(tmax=np.inf, fmax=250)" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "On MEG sensors we see narrow frequency peaks at 60, 120, 180, 240 Hz,\nrelated to line noise.\nBut also some high amplitude signals between 25 and 32 Hz, hinting at other\nbiological artifacts such as ECG. These can be most easily detected in the\ntime domain using MNE helper functions\n\nSee `tut_artifacts_filter`.\n\n" ], "cell_type": "markdown", "metadata": {} }, { "source": [ "ECG\n---\n\nfinds ECG events, creates epochs, averages and plots\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "average_ecg = create_ecg_epochs(raw).average()\nprint('We found %i ECG events' % average_ecg.nave)\naverage_ecg.plot_joint()" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "we can see typical time courses and non dipolar topographies\nnot the order of magnitude of the average artifact related signal and\ncompare this to what you observe for brain signals\n\n" ], "cell_type": "markdown", "metadata": {} }, { "source": [ "EOG\n---\n\n" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "average_eog = create_eog_epochs(raw).average()\nprint('We found %i EOG events' % average_eog.nave)\naverage_eog.plot_joint()" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Knowing these artifact patterns is of paramount importance when\njudging about the quality of artifact removal techniques such as SSP or ICA.\nAs a rule of thumb you need artifact amplitudes orders of magnitude higher\nthan your signal of interest and you need a few of such events in order\nto find decompositions that allow you to estimate and remove patterns related\nto artifacts.\n\nConsider the following tutorials for correcting this class of artifacts:\n - `tut_artifacts_filter`\n - `tut_artifacts_correct_ica`\n - `tut_artifacts_correct_ssp`\n\n" ], "cell_type": "markdown", "metadata": {} } ], "metadata": { "kernelspec": { "display_name": "Python 2", "name": "python2", "language": "python" }, "language_info": { "mimetype": "text/x-python", "nbconvert_exporter": "python", "name": "python", "file_extension": ".py", "version": "2.7.13", "pygments_lexer": "ipython2", "codemirror_mode": { "version": 2, "name": "ipython" } } } }