SensorStats - Meg Wiki

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment
Type the missing letters from: Lodon is th capial of nglnd

Revision 5 as of 2009-03-17 16:58:13

location: SensorStats

Statistics in sensor space

A standardised way or running sensor-level statistics on your MEG data is implemented in SPM5:

http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSpm

But nothing prevents you from finding your own way...

Converting Fiff-files to SPM images

This script has not been tested extensively, but it is based on the scripts at http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSPM.

% Modified from http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSPM
% takes a list of Fiff-files (cell array "fifflist{}") and converts MEG data to SPM image files,
% which can then be subjected to 2nd-level statistics, for example
% "rootdir" can contain the directory path common to all files
% the script will produce subdirectories with img-files in the directories of the input fiff-files
% so far only tested on one data set
% OH, March 2009
if exist('fifflist')~=1,   % you can specify a list of files here (e.g. on-line averages for all subjects in your study)
    fifflist = {'/fullpath/file4subj1.fif', ...
             '/fullpath/file4subj2.fif', ...
             '/fullpath/file4subj3.fif'};
end;
nr_fiffs = length(fifflist);
if exist('rootdir')~=1, % if not root directory specified, leave empty
    root_dir = '';
end;
% GET GOING...
clear S;
for ff = 1:nr_fiffs,    % for all Fiff-files...
% CONVERT FROM FIFF TO SPM FORMAT...
    S.Fchannels = fullfile(spm('dir'),'EEGtemplates','FIF306_setup.mat');
    S.veogchan  = [62];         % Channel 62 is (bipolar) VEOG, MAY NEED EDITING
    S.heogchan  = [61];         % Channel 61 is (bipolar) HEOG, MAY NEED EDITING
    S.veog_unipolar = 0;        % MAY NEED EDITING
    S.heog_unipolar = 0;        % MAY NEED EDITING
    S.conds = 1;                % conditions in fiff-file, MAY NEED EDITING
    S.grms = 1;    % so that the splitting outputs mags, grads and grad RMS (grms)

    [fiffpath,fiffname,fiffext,fiffversn] = fileparts(fifflist{ff});

    S.Fdata = fullfile(root_dir, fifflist{ff});   % Input Fiff-file before splitting
    fileSPMout = fullfile(root_dir, fiffpath, [fiffname '_SPM.mat']); % Output SPM file (if not specified, will be 'myexp.mat')
    S.Pout  = fileSPMout;   % output for conversion from Fiff to SPM format (before splitting)
    D0 = spm_eeg_rdata_FIF(S);  % convert fiff- to SPM-format

% SPLIT DATA INTO MAGS/GRADS/EEG...
    S.D = fileSPMout;       % structure for splitting

    D1 = spm_eeg_splitFIF(S);   % split SPM files

% WRITE TO IMAGE VOLUMES:
    % Select options (see help for spm_eeg_convertmat2ana3D):
    clear S
    S.interpolate_bad = 0;
    S.n = 32;
    S.pixsize = 3;
    % Select trial types:
    S.trialtypes = [1];
    img_outnames = '';
    % Mags:
    S.Fname = fullfile(root_dir, fiffpath, [fiffname '_SPM-mags.mat']);
    tmpname = spm_eeg_convertmat2ana3D(S);
    img_outnames(1,:) = fullfile(root_dir, fiffpath, [fiffname '_SPM-mags'], 'trialtype1', 'average.img');

    % Grad magnitude:
    S.Fname = fullfile(root_dir, fiffpath, [fiffname '_SPM-grds.mat']);
    tmpname = spm_eeg_convertmat2ana3D(S);
    img_outnames(2,:) = fullfile(root_dir, fiffpath, [fiffname '_SPM-grds'], 'trialtype1', 'average.img');

    % GradRMS magnitude:
    S.Fname = fullfile(root_dir, fiffpath, [fiffname '_SPM-grms.mat']);
    tmpname = spm_eeg_convertmat2ana3D(S);
    img_outnames(3,:) = fullfile(root_dir, fiffpath, [fiffname '_SPM-grms'], 'trialtype1', 'average.img');
% SMOOTH IMAGES
    P = img_outnames;

    SmoothKernel = [5 5 10]; % % Smoothness in x (mm), y (mm) and z (ms), MAY NEED EDITING
    for n=1:size(P,1);
               [pth,nam,ext] = fileparts(P(n,:));
               Pout{n}       = fullfile(pth,['s' nam ext]);
               spm_smooth(spm_vol(P(n,:)),Pout{n},SmoothKernel);
               Pin = strvcat(P(n,:),Pout{n});
               spm_imcalc_ui(Pin,Pout{n},'((i1+eps).*i2)./(i1+eps)',{[],[],'float32',0});
    end
    %The final imcalc step above is just to reinsert NaN's for voxels outside space-time volume into which data were smoothed

end;    %..ff