1

Interpolate MEG data to standard sensor array

This Matlab script will interpolate data to a standard sensor array

Maxfilter options:

maxfilter -f %s -o %s -trans %s -v -frame head -origin 0 0 45 -force -ctc /neuro/databases/ctc/ct_sparse.fif -cal /neuro/databases/sss/sss_cal.dat

Note: Run the script in Matlab R2006b rather than R2009a! The script might crash if running in R2009a.


% For files specified in cell array "files{}", apply maxfilter with -trans
% option in order to interpolate data to sensor array specified in "trans_file"
% originall file names will be appended by "_t", or by whatever is specified in "t_ext"
% for each transed file, a log-file with maxfilter output will be created ("*.log")
% OH, March 2009
% you can pre-specify a list of files here
fiff_files = {'/fullpath/file4subj1.fif', ...
         '/fullpath/file4subj2.fif', ...
         '/fullpath/file4subj3.fif'};
% Fiff-file with standard sensor geometry to which the others will be interpolated
trans_file = '/fullpath/fiff4trans.fif';
t_ext = '_t';   % suffix for filenames of transed files
if ~exist(trans_file, 'file'),
    fprintf(1, 'Cannot proceed without trans_file %s\n', trans_file);
    return;
end;
trans_data = fiff_read_evoked( trans_file );     % read fiff-file with standard sensor geometry
nr_files = length(fiff_files);
for ff = 1:nr_files,     % for each input file, apply maxfilter -trans, then reinsert digitiser points
    in_file = fiff_files{ff};
    [thispath,thisfile,thisext,thisversn] = fileparts(in_file);
    out_file = fullfile(thispath, [thisfile t_ext thisext]);
    log_file = fullfile(thispath, [thisfile t_ext '.log']);
    % maxfilter -trans...
    eval(sprintf('!/neuro/bin/util/maxfilter -f %s -o %s -trans %s -v -frame head -origin 0 0 45 -force -ctc /neuro/databases/ctc/ct_sparse.fif -cal /neuro/databases/sss/sss_cal.dat | tee %s', in_file, out_file, trans_file, log_file));

    % reinsert digitiser points...
    data = fiff_read_evoked( out_file );        % read invidual data file with data interpolated to standard sensor geometry
    data.info.dig = trans_data.info.dig;        % insert digitised points from standard geometry to interpolated data set
    fiff_write_evoked( out_file, data );    % write interpolated data back to fiff-file
end;