MEG
Removing Artifacts With PCA And GRAPH
Preprocessing your data (PCA-based removal of ECG and EOG artifacts): (NOTE: this procedure will be included in MaxFilter soon!)
1/ Launch graph
Type graph in a console window and press enter to launch graph software
Deactivate the numlock key (VerrNum in French) of the num pad on your keyboard (you need it to be off to be able to use graph)
2/ Load Setup and display
Copy paste (using the middle button of your mouse) this line :
(load "/neurospin/meg/meg_rep/tools/graph_tools/graph_PCA/triplet-ecg.lsp")
This will load the triplet display.
Load the setup by "File/Load Settings" and selecting:
(load"/neurospin/meg/meg_rep/tools/graph_tools/graph_PCA/ecg-pca.setup")
or
(load"/neurospin/meg/meg_rep/tools/graph_tools/graph_PCA/PCA_ECG_EOG.setup")
The last one is for ECG and EOG PCA.
Look at your setup by going in Display and then Control Panel.Every box is called a Widget.You can see that you have 3 widget called triplet 1 to 3 which are for the main window display. Each widget controls a function or a display
Widgets are linked by lines that you can cut with the right button of your mouse.To connect two widgets click on the widget you want to connect to select it and then with the right button of your mouse, drag a line to the other widget you to connect it to.
3/ Load data
Load your Maxfiltered raw data by "File/Open diskfile"
4/ Check cardiac artifact
Check that the cardiac QRS complex is detected for most beats in the middle section of the main window. Adjust the threshold in the widget "ecg-threshold" if needed (double click on the widget and change the value). You should have a trigger in the form of a positive peak for each beat.
If the peaks are negative, you need to inverse the sign of your channel. To do that you can use the inverse widget on the bottom of control pannel or create it youself. Go in widget/math/unary called for instance inverse with fmul as function and (-1) as arguments.
Connect the widget Inverse to the widgets "ecg" and "ecg-filter".
5/ Average on the artifact
Average over the beats by command: (average 0 100) which uses the first 100 seconds of the file
The Xplotter display should now show the cardiac artefact.
6/ Perform the PCA and look at the components
Run PCA by: (pca-on-widget "to-pca" -0.2 0.4)
Open "Commands/SSP dialog" and choose "Actions/Add PCA fields/5 vectors"
Select the matrix in "Vector pool", select "Edit/Edit name" to rename to something like "PCA-ECG-grads", and select "Edit/Explode". You should have now 5 lines instead of 1 in the vector pool. These lines correspond to the 5 'strongest' principal components.
Select the topmost line and click on the arrow to copy it to the "SSP vectors" list. Right after the copying, the signals on the plotter display change to reflect the projected version of the data. Add more components until the artefact is no longer visible.
7/ Save the components you want to reject
Save the vector set you determined sufficient for removing the cardiac artefact: delete the unnecessary vectors from the pool (the left part of the window), select the vectors that are left (the ones that contain your artifac) and invoke "File/Save",and give a filename that ends with ".fif".
8/ Do the PCA for all type of channel
Disconnect the widget meg-grads of the widget to-pca and connect the one meg-mags or eeg depending on which sensor you want to perform the PCA on.
Redo all the steps from 6/. You can see that the vector of the PCA won't have the same dimension as for other type of sensors (it's written in the command line)
For PCA on the EEG,
->don't forget to load the good layout in the Data Ploter/ File menu.
->Check that you don't have any crappy sensors before doing the PCA. The reason is that each sensor will be a weighted sum of the other channels after the PCA and the noise of one could spread to the other. If you have one, ignore it by entering its name in the ignore window in the eeg widget. The ouptut vector won't have the dimension of all yours sensors then so you will have to take that into account while loading the PCA (matlab function does it right).
9/ DO EOG artifact removal with PCA
Repeat the procedure for EOG artefacts.
If you loaded the PCA_ECG_EOG setup, you just have to disconnect the ECG widget and connect the EOG widget instead.
Then (THIS IS IMPORTANT !!!!!!!!), go in the Parameters menu of the main window and then averager.Here change the average-trigger parameter to (eog-threshold 0).
This will make the averager widget take the eog widget as an input and not the ecg one.
If you loaded the ecg PCA setup, just change the name ECG in the ECG widget to EOG61 for EOG Horizontal and EOG62 for EOG V. Be careful if you didn't name your channel correctly, the EOG might be in EEG061 or another additionnal EEG channel. That's alright, just change the name to fit it to your data set.
Note that if your ECG or EOG electrodes are missing or too noisy, you can select one of the MEG sensor as the basis of your rejection procedure.
Note also that if the averaging returns no results, the detection threshold for detecting the blinks may be too high. You can change the threshold by editing the eog-threshold widget.
Check your EOG artifact and perform an average on the entire recording
(average 0 10000)
to be sure to have a good average (there are usually much less blinks than heart beats).
Run PCA by: (pca-on-widget "to-pca" -0.2 0.4)
Note that you may want to scale the time around the blink trigger (for instance, -0.1 0.3 may be sufficient to capture a blink)
10/ And then what ?
You may now use the SSP operators (the vector sets) on Matlab, MNE, Brainstorm and the Neuromag software. For these, the vector sets have to be combined into a single operator where the vectors are augmented to the full dimensionality of the data; for example, the 102-dimensional magnetometer vectors should be padded to 306-dimensional space (or even more if EEG is included) by inserting zeros at appropriate locations. The xfit program (Neuromag software) is able to do this; use it for Neuromag software, MNE and Brainstorm. For Matlab, Lucie has written a function that does a similar combination.
11/ Useful tips
Never keep a second vector without keeping the first one. That wouldn't make sense as the result of the PCA for the 2nd, 3d etc vectors does as if you had remove the other vector first. So you always have to remove every vector up to the last one you want to remove.
Examples
BLINK artefacts on gradiometers

BLINK artefacts on gradiometers removed (PCA-graph)

CARDIAC artefacts on magnetometers

CARDIAC artefacts on magnetometers removed (PCA-graph)
