= Tutorial XX: Detecting artifacts = ''Authors: Francois Tadel, Elizabeth Bock, John C Mosher, Sylvain Baillet'' <> = From Auditory = Restore view: 3s, CTF LT == Heartbeats and eye blinks == * Select the two AEF runs in the Process1 box. * Select successively the following processes, then click on [Run]: * '''Events > Detect heartbeats:''' Select channel '''ECG''', check "All file", event name "cardiac". * '''Events > Detect eye blinks:''' Select channel '''VEOG''', check "All file", event name "blink". * '''Events > Remove simultaneous''': Remove "'''cardiac'''", too close to "'''blink'''", delay '''250ms'''. = From continuous = == Identify the artifacts == The first step is to identify several repetitions of the artifact (the vectors '''b'''<)>>''1''<)>>...'''b'''<)>>''m''<)>>). We need to set markers in the recordings that indicate when the events that we want to correct for occur. To help with this task, it is recommended to always record with bipolar electrodes the activity of the eyes (electro-oculogram or EOG, vertical and horizontal), the heart (electro-cardiogram or ECG), and possibly other sources of muscular contaminations (electromyogram or EMG). In this example, we are going to use the ECG and vertical EOG traces to mark the cardiac activity and the eye blinks. Two methods can be used, manual or automatic. === EOG/ECG channels === * Select the protocol '''TutorialRaw''' created in the previous tutorial, and select the "Functional data" view (second button in the toolbar on top of the database explorer). * Double-click on the '''clean''' continuous recordings ("'''Raw | notch(60Hz 120Hz 180Hz)'''") to open the MEG recordings. * Set the length of the reviewed time window to '''3 seconds''' (in the Record tab, text box "Duration") * Right-click on the continuous recordings again > '''Misc > Display time series'''. . {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawSsp?action=AttachFile&do=get&target=tsMisc.gif|tsMisc.gif|height="148",width="577",class="attachment"}} * In this file the channel type "'''Misc'''" groups the two channels '''EEG057 '''('''ECG''', in green) and '''EEG058 '''('''vertical EOG''', in red). This configuration depends on the acquisition setup, and can be redefined afterwards in Brainstorm (right-click on the channel file > Edit channel file, and then change manually the string in the column Type for any channel). * Use the shortcuts introduced in the previous tutorial to adjust the vertical scale of this display: Shift+mouse wheel, +/- keys, or the buttons on the right side of the figure. * Then go further in time to see what is happening on those channels over the time: use the "'''>>>'''" buttons, or the associated shortcuts (read the tooltips of the button) * '''ECG''': On the green trace, you can recognize the very typical shape of the electric activity of the heart (P, QRS and T waves). This is a very good example, the signal is not always that clean. * '''EOG''': On the red trace, there is not much happening for most of the recordings except for a few bumps, typical of eye blinks, eg. at 33.590s. This subject is sitting very still and not blinking much. We can expect MEG recordings of a very good quality. * You can observe the contamination from a blink on the left-frontal sensors: move to '''33.590s''' (you can use the text boxes in the time panel, the Record tab, or the scrollbar in the figure), and select a subset of sensors (Shift+B, or right-click on the figure > Display setup > CTF LF) . {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawSsp?action=AttachFile&do=get&target=megEog.gif|megEog.gif|height="265",width="475",class="attachment"}} === Manual marking === Create a new category of markers "'''blink_manual'''", using the menu Events > Add group. Select this new group. Review the file, and mark the peaks you observe on the vertical EOG trace, using the '''Ctrl+E''' keyboard shortcut. Do that for a few eye blinks. {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawSsp?action=AttachFile&do=get&target=markEog.gif|markEog.gif|height="174",width="496",class="attachment"}} You could repeat the same operation for all the blinks, then for all the ECG peaks and jump to the next chapter of the tutorial and compute the SSP. It would be uselessly time consuming, as there is a process that does it for you automatically. However, it is good to remember how to do it manually because you may face some cases where you don't have clean ECG/EOG, or if you want to correct for another type of artifact. === Automatic detection: EOG === In the Record tab, select the menu: '''SSP > Detect eye blinks'''. It opens automatically the pipeline editor, with the process "Detect eye blinks" selected: * '''Channel name''': Name of the channel that is used to perform the detection. Select or type "'''EEG058'''" as it is the name of the EOG channel * '''Time window''': Time range that the algorithm should scan for the selected artifact. Leave the default values to process the entire file. * '''Event name''': Name of the event group that is created for saving all the detected events. Leave the default "blink". {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawSsp?action=AttachFile&do=get&target=sspMenu.gif|sspMenu.gif|class="attachment"}} {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawSsp?action=AttachFile&do=get&target=detectEog.gif|detectEog.gif|height="232",width="334",class="attachment"}} Click on Run. After the process stops, you can see two new event categories "'''blink'''" and "'''blink2'''" in the Record tab. You can review a few of them, to make sure that they really indicate the EOG events. In the Record tab, click on the "blink" event category, then on a time occurrence to jump to it in the MEG and Misc time series figures. Two types of events are created because this algorithm not only detects specific events in a signal, it also classifies them by shape. If you go through all the events that were detected in the two categories, you would see that the "blink" are all round bumps, typical of the '''eye blinks'''. In the category "blink2", the morphologies don't look as uniform; it mixes small blinks, and ramps or step functions followed by sharp drops that could indicate '''eye saccades'''. The saccades can be observed on the vertical EOG, but if you want a better characterization of them you should also record the horizontal EOG. The detection of the saccades should be performed with a different set of parameters, using the process "Detect custom events", introduced later in this chapter. {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawSsp?action=AttachFile&do=get&target=detectEogDone.gif|detectEogDone.gif|class="attachment"}} === Automatic detection: ECG === Now do the same thing for the heartbeats. In the Record tab, select the menu "'''SSP > Detect heartbeats'''". Configure the process to use the channel '''EEG057''' (name of the ECG channel), and leave the other options to the default values. {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawSsp?action=AttachFile&do=get&target=sspMenu1.gif|sspMenu1.gif|class="attachment"}} {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawSsp?action=AttachFile&do=get&target=detectEcg.gif|detectEcg.gif|height="228",width="330",class="attachment"}} Click on Run. After the process stops, you can see a new event category "'''cardiac'''" in the Record tab, with 346 occurrences. You can check a few of them, to make sure that the "cardiac" markers really indicate the ECG peaks, and that there are not too many peaks that are skipped. {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawSsp?action=AttachFile&do=get&target=detectEcgDone.gif|detectEcgDone.gif|class="attachment"}} === Automatic detection: Custom === Those two previous processes are shortcuts for a generic process "'''Detect custom events'''". We are not going to use it here, but it is interesting to introduce it to understand how the blinks and heartbeats detection work. The logic is the following: * The channel to analyze is read from the continuous file, for a given time window. * '''Frequency band''': The signal is filtered in a frequency band where the artifact is easy to detect. For EOG: 1.5-15Hz ; for ECG: 10-40Hz. * '''Threshold''': An event of interest is detected if the absolute value of the filtered signal value goes over a given number of times the standard deviation. For EOG: 2xStd, for ECG: 4xStd * '''Minimum duration between two events''': If the filtered signal crosses the threshold several times in relation with the same artifact (like it would be the case for muscular activity recordings on an EMG channel), we don't want to trigger several events but just one at the beginning of the activity. This parameter would indicate the algorithm to take only the maximum value over the given time window; it also prevents from detecting other events immediately after a successful detection. For the ECG, this value is set to 500ms, because it is very unlikely that the heart rate of the subject goes over 120 beats per minute. * '''Ignore the noisy segments''': If this option is selected, the detection is not performed on the segments that are much noisier than the rest of the recordings. * '''Enable classification''': If this option is selected, the events are classified by shape, based on correlation measure. In the end, only the categories that have more than 5 occurrences are kept, all the other successful detections are ignored. {{http://neuroimage.usc.edu/brainstorm/Tutorials/TutRawSsp?action=AttachFile&do=get&target=detectCustom.gif|detectCustom.gif|height="459",width="329",class="attachment"}} <> <>