= Tutorial 8: Artifacts & Frequency filters = ''Authors: Francois Tadel, Elizabeth Bock, John C Mosher, Sylvain Baillet'' <> = From Auditory = == Detect and remove artifacts == === Spectral evaluation === * One of the typical pre-processing steps consist in getting rid of the contamination due to the power lines (50 Hz or 60Hz). Let's start with the spectral evaluation of this file. * Drag '''ALL''' the "Link to raw file" to the Process1 box, or easier, just drag the node "Subject01", it will select recursively all the files in it. * Run the process "'''Frequency > Power spectrum density (Welch)'''": * Time window: '''[All file]''', Window length: '''4s''', Overlap: '''50%''', Sensor types: '''MEG''' * Note that you need at least 8Gb of RAM to run the PSD on the entire file. If you don't or if you get "Out of memory" errors, you can try running the PSD on a shorter time window. * Click on '''[Edit]''' and select option "'''Save individual PSD values''' (for each trial)". {{http://neuroimage.usc.edu/brainstorm/Tutorials/Auditory?action=AttachFile&do=get&target=psd1.gif|psd1.gif|height="394",width="615",class="attachment"}} * Double-click on the new PSD files to display them. * Observations for '''Run''''''01''': {{http://neuroimage.usc.edu/brainstorm/Tutorials/Auditory?action=AttachFile&do=get&target=psd_eval01.gif|psd_eval01.gif|height="207",width="394",class="attachment"}} * Peaks related with the power lines: '''60Hz, 120Hz, 180Hz '''(240Hz and 300Hz could be observed as well depending on the window length used for the PSD) * The drop after '''600Hz''' corresponds to the low-pass filter applied at the acquisition time. * One channel indicates a higher noise than the others in high frequencies: '''MLO52''' (in red). We will probably mark it as bad later, when reviewing the recordings. * Observations for '''Run02''': {{http://neuroimage.usc.edu/brainstorm/Tutorials/Auditory?action=AttachFile&do=get&target=psd_eval02.gif|psd_eval02.gif|height="208",width="394",class="attachment"}} {{http://neuroimage.usc.edu/brainstorm/Tutorials/Auditory?action=AttachFile&do=get&target=psd_eval02_zoom.gif|psd_eval02_zoom.gif|height="208",width="595",class="attachment"}} * Same peaks related with the power lines: '''60Hz, 120Hz, 180Hz''' * Same drop after '''600Hz'''. * Same noisy channel: '''MLO52'''. * Additionally, we observe higher level of noise in frequencies in the range of 30Hz to 100Hz on '''many occipital sensors'''. This is probably due to some tension in the neck due to an uncomfortable position. We will see later whether those channels need to be tagged as bad. === Power line contamination === * Put '''ALL''' the "Link to raw file" into the Process1 box (or directly the Subject01 folder) * Run the process: '''Pre-process > Notch filter''' * Select the frequencies: '''60, 120, 180 Hz''' * Sensor types or names: '''MEG''' * The higher harmonics are too high to bother us in this analysis, plus they are not clearly visible in all the recordings. * In output, this process creates new .ds folders in the same folder as the original files, and links the new files to the database. {{http://neuroimage.usc.edu/brainstorm/Tutorials/Auditory?action=AttachFile&do=get&target=psd3.gif|psd3.gif|class="attachment"}} * Run again the PSD process "'''Frequency > Power spectrum density (Welch)'''" on those new files, with the same parameters, to evaluate the quality of the correction. * Double-click on the new PSD files to open them. {{http://neuroimage.usc.edu/brainstorm/Tutorials/Auditory?action=AttachFile&do=get&target=psd5.gif|psd5.gif|height="177",width="416",class="attachment"}} * Zoom in with the mouse wheel to observe what is happening around 60Hz (before / after). {{http://neuroimage.usc.edu/brainstorm/Tutorials/Auditory?action=AttachFile&do=get&target=psd6.gif|psd6.gif|height="143",width="453",class="attachment"}} * To avoid the confusion later, delete the links to the original files: Select the folders containing the original unfiltered files and press the Delete key (or right-click > File > Delete). {{http://neuroimage.usc.edu/brainstorm/Tutorials/Auditory?action=AttachFile&do=get&target=psd7.gif|psd7.gif|height="184",width="356",class="attachment"}} = From Continuous = It is common to have portions of recordings contaminated by events coming from the subject (eye blinks, movements, heartbeats, teeth clenching, implanted stimulators...) or from the environment (stimulation equipment, elevators, cars, trains, building vibrations...). Some occur at specific frequencies and can be removed using '''frequency filters''', as introduced in the first chapter of this tutorial. Some other artifacts have more complex frequency patterns but are well defined, reproducible and can be removed efficiently using '''Signal Space Projections''' ('''SSP'''). This tutorial shows how to apply this technique to correct for the cardiac and ocular artifacts. We are going to use the protocol '''TutorialRaw''' created in the previous tutorial [[Tutorials/TutRawViewer|Review continuous recordings and edit markers]]. If you have not followed this tutorial yet, please do it now. == Power line contamination == Notch filters are adapted to remove some well identified contaminations from oscillating systems, such as the power lines 50Hz or 60Hz. Here is an example of how to evaluate and correct fixed frequency artifacts. Important notes: 1. Usually you would prefer to apply the frequency filters '''before '''the SSP correction. 1. This approach is limited to CTF and Elekta-Neuromag recordings for now, other file formats will be developed on demand. An alternative approach for other file formats is described in the [[Tutorials/Epilepsy|EEG/Epilepsy tutorial]]. === Identify the unwanted frequencies === Drag and drop the "Link to raw file" in the Process1 tab, click on the button [Run] to open the Pipeline editor window and select the process "'''Frequency > Power spectrum density (Welch)'''". This will estimate the power spectrum of the signal using the Welch method. Set the time window to process to '''[0,50]s''', and the window length to '''4 sec''', with an overlap of '''50%''', this will be more than enough to get a good estimate of the spectrum (average of the Fourier transform of 24 windows of 4800 samples each). Leave the other options to the default values. {{attachment:psdRun.gif||height="290",width="463"}} Double click on the "Power (MEG)" file that was created under the "Link to raw file" in the database explorer. This shows the estimate of the power spectrum for the first 50 seconds of the continuous file, for all the sensors, with a logarithmic scale. You can identify four peaks at the following frequencies: 60Hz, 120Hz, 180Hz and 300Hz. The first three are related with the power lines (acquisition in Canada, where the electricity is delivered at 60Hz, plus the harmonics), and are expected to be coming from pure sinusoidal components in the signal. The last one is an artifact of the low-pass filter at 300Hz that was applied on the recordings at the acquisition time. We are going to ignore this one, as it is probably more complex and spanning over several frequency bins. {{attachment:psdBefore.gif||height="172",width="399"}} === Remove: 60Hz and harmonics === Leave the file "Link to raw file" in the Process1 list and now run "'''Pre-process > Notch filter'''".<
>Enter the frequencies to remove ('''60Hz, 120Hz '''and '''180Hz''') and leave the other options to the default values. {{attachment:sinRemoval.gif||height="272",width="333"}} The operation creates a new "Link to raw file" entry in the database, pointing to a new CTF dataset in the same folder as the original continuous file. To check where this file was created: right-click on the file "'''Raw | notch(60Hz 120Hz 180Hz)'''" > '''File '''> '''Show in file explorer'''. This file has the exact same properties as the original file, including the SSP projectors, only the values of the MEG sensors were updated. {{attachment:sinRemovalDb.gif||height="144",width="326"}} === Alternatives === If the notch filter is not giving satisfying result, you can use two other processes: * '''Sinusoid removal''': This process can do a better job at removing precise frequencies by identifying the sinusoidal components and then subtracting them from the signals in time domain (not a frequency filter). * '''Band-stop filter''': This process can be useful for removing larger segments of the spectrum, in case the power line peaks are spread over numerous frequency bins or for suppressing other types of artifacts. === Evaluate the results === Now run the same frequency analysis: process "'''Frequency > Power spectrum density (Welch)'''", time window = '''[0,50]s''', window length = '''4000ms''', overlap = '''50%'''. Double click on the new "Power (MEG)" file. As expected, the three first peaks due to the power lines are gone. {{attachment:psdAfter.gif||height="177",width="411"}} You can run a few other pre-processing operations directly on the continuous files, including a band-pass filter. Frequency filters and sinusoid removals are operations that you should apply at very early stages of the analysis, before epoching the recordings. Those operations do not perform well next to the beginning and the end of the signals, they may generate important artifacts. It is therefore much more accurate to filter the entire recordings from the original continuous file at once, rather than filtering small epochs after importing them in the database. From now on, we are only going to work on this clean file "Raw | notch(60Hz 120Hz 180Hz)". = From CTF = == Selecting files to process == First thing to do is to define the files you are going to process. This is done easily by picking files or folders in the database explorer and dropping them in the empty list of the Process1 tab. 1. Drag and drop the following nodes in the Process1 list: Right/ERF (recordings), Right (condition), and Subject01 (subject)<
><
> {{attachment:files1.gif}} * The number in the brackets next to each node represents the number of data files that where found in each of them. The node ERF "contains" only itself (1), Subject01/Right contains ERF and Std files (2), and Subject01 contains 2 conditions x 2 recordings (4). * The total number of files, ie. the sum of all those values, appears in the title of the panel "Files to process [7]". 1. The buttons on the left side allow you to select what type of file you want to process: Recordings, sources, time-frequency, other. Now select the second button "Sources". All the counts are updated and now reflect the number of sources files that are found for each node.<
><
> {{attachment:files2.gif}} 1. If you select the third button "Time-frequency", you would see "0" everywhere because there are no time-frequency decompositions in the database yet.<
><
> {{attachment:files3.gif}} 1. Now clear the list from all the files. You may either right-click on the list (popup menu ''Clear list''), or select all the nodes (holding ''Shift ''or ''Crtl ''key) and then press the ''Delete ''key. 1. Select both files Left/ERF and Right/ERF in the tree (holding ''Ctrl ''key), and put the in Process list. We are going to apply some functions on those two files. You cannot distinguish them after they are dropped in the list, because they are both referred as "ERP". If at some point you need to know what is in the list, just leave you mouse over a node for a few seconds, and a tooltip would give you information about it. Just like in the database explorer.<
><
> {{attachment:files4.gif}} <> <>