CBU-specific SPM5 parameters for MEG/EEG
Some further details for CBU MEG/EEG data...
Extracting data values from SPM5
SPM5 stores the data with two files: yourfile.mat and yourfile.dat. The first "mat" (Matlab) file is a small "header" file, which contains information about the data (e.g, channel names and types, sampling rate, etc). If you just load yourfile.mat into Matlab, there will be a structure D in your workspace that contains fields and subfields with this information (e.g, D.channels.name). Go on, have a look. The second *.dat file is a bigger file that contains the datavalues themselves (but you cannot load this directly; see below).
- For computational efficiency, whenever you read or write data (to manipulate them), the data are "memory-mapped". This uses a compiled C function. So to examine the data directly in Matlab, you need to first memory map it as follows:
D = spm_eeg_ldata('yourfile')
The structure D will now be in memory, but one of its fields (D.data) will now "point" to the data file. It is normally a 3D array with dimensions Channels X Samples X Trials (though for time-frequency data, it is a 4D array with dimensions Channels X Frequencies X Samples X Trials). For unaveraged data, the Trial is simply that; for averaged data the Trial corresponds to the Condition; for averaged data that has been contrasted (ie, contrasts are just linear combinations of conditions, like the average or difference between conditions), then Trial corresponds to the contrast number. So if you want to know the magnetic (or electrical) signal on the first channel at the second sample (timepoint) for the third Trial, you simply then need to type:
d = D.data(1,2,3)
- Or for example if you want a Channels X Conditions matrix, having averaged across all samples in a timewindow (to be repeated for each subject and then entered into an ANOVA with factors Channels and Conditions for example), then:
twin = [100 200]; % Time window between 100ms and 200ms post-stimulus; swin = round(twin*D.Radc/1000); % Convert from ms to samples (D.Radc = sampling rate) swin = swin + D.events.start + 1; % Adjust for any prestimulus baseline (D.events.start) d = mean(D.data(:,swin(1):swin(2),:),2); % Average across 2nd dimension, ie samples
Note that the first three lines of the above can be reduced to
swin = meg_t2s([100 200],D);
by using one of the common "meg_misc" functions that we have added (see http://imaging.mrc-cbu.cam.ac.uk/meg/MeegCodeCbuSvn). Conversely, meg_s2t(swin,D) will convert back from samples to peristimulus time. Finally note that the Matlab function repanova.m written by RikHenson (http://www.mrc-cbu.cam.ac.uk/people/rik.henson/personal/analysis.html) can do any NxMxOXP... repeated-measures ANOVA like that mentioned above in Matlab (using Greenhouse-Geisser correction).
A note on downsampling
- The data are acquired at 1000Hz. There is no real need to downsample, other than to reduce the filesize. Unfortunately, file size can be a problem for some SPM functions, and will slow down preprocessing. So if you are not interested in frequencies above Y Hz (eg 100Hz), you don't really need to sample more than 2Y Hz (200Hz).
You can downsample by factors of 2 (eg 500Hz), 3 (eg 333Hz) and 4 (eg 250Hz) during Maxfiltering (and in theory by a factor of 5, but this has caused Maxfilter crashes on some files for some reason). This downsampling applies to all channels, including the trigger channel (eg STI101). So be careful that downsampling does not 1) miss a trigger (so make the triggers more than a few ms in duration), 2) interpolate a trigger rising slope, affecting the trigger profile and hence trigger value (depending how it is read). Therefore if your files are not too large, it is probably better NOT to downsample during Maxfiltering, but to downsample after the data have been read into SPM (ie after spm_eeg_rdata_FIF) using spm_eeg_downsample. This is because once the data is in SPM, the trigger channel is no longer represented explicitly; the triggers themselves are simply represented by their onset time () and their value ()
SPM5 stores the sampling rate in the field D.Radc (see above section about the structure D)
- Note that downsampling is not necessarily a good idea if you are interested in exact latencies: eg a sampling rate of 100Hz only means one sample every 10ms.
MEG/EEG montages (layout or CTF files)
- SPM needs a "layout" or "CTF" file that simply tells it how to display the channels in the Graphics window when displaying EEG or MEG data (and when writing space-time sensor images). This file is stored in D.channels.ctf. The file is selected when you read the raw data using spm_eeg_rdata_FIF.m.
There is a standard one for our Neuromag MEG channels in /imaging/local/spm/spm5/EEGtemplates/FIF306_setup.mat, which you should probably use.
However, there have been several changes to our EEG montages in the MEG laboratory. For our old caps, you can try these montages in that directory: cbu_meg_70eeg_montage_old.mat and cbu_meg_124eeg_montage_old.mat (depending on your number of channels.
- A final alternative offered by spm_eeg_rdata_FIF.m is for it to create a new CTF file for each dataset read (to be stored in a local directory of yours). It creates them simply be guessing Cz as the channel with maximal Z, and then projecting onto a flat 2D surface using a spherical projection. This will be fine for displaying data (though there may not be optimal coverage of your Graphics window), but you should double-check these if you plan to do space-time sensor SPMs across subjects).
In the EEGtemplates directory, you will also see some EEG montages for the CBU's EEG Neuroscan lab, ie cnt74_cbu.mat and cnt128.mat.
For more help, please contact RikHenson.