= Tutorial 6: Noise covariance matrix = The source reconstruction process requires an estimation of the noise level in the recordings. This tutorial shows how to compute the noise covariance matrix from the two averaged files we have in the database. <> == Compute from recordings == * Select protocol TutorialCTF, switch to the ''Functional data (sorted by subjects) ''view. * To estimate the noise covariance matrix, we need to use only the real recordings, and not the variance of the average (second recordings file of each condition). So select them at the same time (using the SHIFT or CTRL key) : Right/ERP and Left/ERP. Then right-click on one of them.<
><
> {{attachment:noiseCovMenu.gif}} * The Noise covariance menu includes: * '''Import from file''': Uses a matrix that was computed previously using the MNE software. * '''Import from Matlab''': Import from any [nChannels, nChannels] matrix in Matlab workspace. * '''Compute from recordings''': Use the selected recordings to estimate the noise covariance. * Select "Compute from recordings", the options window will appear:<
><
> {{attachment:noiseCovOptions.gif}} * The program is going to take the pre-stimulus values (= ''baseline'') for all the files that have been selected, which are supposed to be only noise, concatenate them, and then compute the covariance matrix for this big F matrix: <
>!NoiseCov = (F - mean(F)) * (F - mean(F))' * The top part of this window shows a summary of the files that have been selected: 2 files at 1250Hz. Total: 750 time samples. * In the bottom part, you can define some options: * '''Baseline''': You can specify what you consider as the pre-stimulus time window in your recordings. By default it takes all the time instants before 0ms, but you might need to redefine this depending on your experiment. * '''Output''': Compute either a full noise covariance, or just a diagonal matrix (only the variances of the channels). Keep the default selection unless you know exactly what you are doing. * Click on OK. Wait for a few seconds. Observe that two new files appeared in the database, one for each condition. Each of them contains the same [nChannels x nChannels] noise covariance matrix. Right-click on one of them: * {{attachment:noiseCovFiles.gif}} * '''Display as image''': Shows the noise covariance matrix as an indexed image. This can be useful to quickly check the quality of the recordings. The noisier channels are indicated by red points.<
><
> {{attachment:noiseCov.gif}} * '''Apply to all conditions''': Copy this noise covariance matrix to all the other conditions from the same subject. * '''Apply to all subjects''': Copy this noise covariance matrix to all the conditions of all the subjects in the database. * Note: The more time samples you have for the estimation of the noise covariance, the more accurate will be the source estimation. If you have many files available for the same subject / same run, always use ALL of them. Select all the files at the same time (or the subject, when you don't have garbage files like our "err" files here), and start the computation for all of them ''at the same time''. == Noise covariance from another dataset == The problem with this process is that to get a good estimation of the noise covariance, it usually requires much more time samples than what we have in an averaged file like the ones we have here. We cannot do anything more for this TutorialCTF protocol, but you will probably need this for your own recordings. You have several options available to get better results: * '''Use single trials''': If you have the single trials from which the average file was computed, * Create another condition in your subject, * Import the single trials in it, * Estimate the noise covariance on these single trials only (right-click on the new condition node > Noise covariance > Compute...)<
>Take only the pre-stimulus time windows (remember, you're trying to estimate the noise...) * Right-click again > Apply to all conditions / subjects, to copy the estimated noise covariance in the conditions that contain your averaged files. * '''Use a real baseline''': If you have recorded some rest periods during the experiment, or some empty room measurements, you can use them exactly as in the previous case. * Import the blocks of raw recordings in the database in a new condition. * Only difference when computing the noise covariance: You can take all the time instants because it is supposed to be noise everywhere. * Copy to other conditions * '''Import from another software''': If you have pre-processed your recordings with the MNE software, you might already have a nice noise covariance matrix available in a ''-cov.fif'' file. * Import it in the average condition (right-click on condition > Noise covariance > Import from file) * Divide by the number of trials used to compute this average. * '''Important note for averaged files''': If you import or compute a noise covariance matrix based on a set of RAW recordings, and then use it on averaged recordings, you may have to __set manually ____the number of trials__ that were used to compute the average. * This is usually done automatically, but in some case, we do not know the number of files that were used to compute the average. * This happens in case you import the average from a file format that do not save the number of trials averaged: * This is unfortunately the case for: 4D Neuroimaging, and all the EEG file formats * To check if this information is stored in the database: right click on the __averaged__ file for which you want to estimate sources. Menu File > View .mat file. If you see "nAvg = 1", the noise covariance matrix will not be used correctly on that file. * To fix, right-click on the averaged file > File > Set number of trials, and enter the number of trials from which the average was computed. == Next == Next tutorial: [[Tutorials/TutSourceEstimation|source estimation]].