Signal processing and analysis of human brain potentials (EEG) [Exercise 4]
Cleaning Data
We will re-use the dataset we used in the first exercise.
Task: Go through the dataset using the MNE explorer and clean it. You can use raw.plot()
for this.
If you are working from a jupyter notebook, try to use %matplotlib qt
for better support of the cleaning window. To get an understanding how the tool works, press help
or type ?
in the window. (Hint: You first have to add a new annotation by pressing a
)
Marking electrodes
Task: While going through the dataset, mark what you observe as bad electrodes. Those are saved in raw.info['bads']
.
The channels can later be interpolated with raw.interpolate_bads()
or epoch.interpolate_bads()
. Compare the channel + neighbours before and after. Did the interpolation succeed?
You need channel locations to run the interpolation which you can get by using the default-standardized channel locations raw.set_montage('standard_1020',match_case=False)
If you are interested in the mathematical details of spline interpolation, checkout this link
Task: Save the annotations to a file. Best practice is to use a csv file of sorts e.g. using raw.annotations.save(filename)
. Try to subsetting for BAD_
first. Bonus: Save it in a BIDS derivate folder according to the BIDS guidelines.
In the semester project you will use mne-bids-pipeline, which will automatically save many results - you might nevertheless come to a point where saving your own logs might be a good idea
Remove bad trials
In MNE, if annotations with BAD_
exist, the epoching function automatically removes them. We are now ready to compare ERP results with and without removal of bad segments. Epoch the data, the respective bad segments will be removed automatically.
Task: Compare the two ERPs for the channel Cz
Automatic rejection
In the epoching step, we can also specify rejection criterion for a peak-to-peak rejection method
= dict(eeg=100e-6, # 100 ยตV
reject_criteria =200e-6) # 200 ยตV
eog= mne.Epochs(raw, events, reject=reject_criteria,reject_by_annotation=False) epochs
Task: Compare these epochs with your manual rejection and with the ERPs without rejection. Plot a single channel Cz
overlaying all three โsolutionsโ.
Bonus: We are going to add to our comparison by using autoreject in MNE python. Have a look at https://autoreject.github.io/ for installation and usage examples. Hint: You need channel locations to run autoreject which you can get by using the default-standardized channel locations raw.set_montage('standard_1020',match_case=False)
Bonus: We can also try to circumvent cleaning by using trimmed / winsorized means. For this, the epochs.average(method=X)
function can be exchanged with a averaging callback. Scipy has comparable functions that you can try out and compare.