Maxfilter Version 2.2
Look here for a brief introduction and literature about Maxfilter and its main feature, the Signal Space Separation method.
Example
Version 2.2. is currently the default on our 64-bit machines (see below for more details).
This command will apply Maxfilter including Signal Space Separation (SSS), its temporal extension (ST), and movement compensation.
maxfilter -f input_file.fif -o output_file.fif -st -origin 0 0 45 -frame head -autobad on -movecomp -format short -force
For more information on these and other options, see the Maxfilter 2.2 Manual.
Known problems and bugs
Maxfilter 2.2. cannot do downsampling and filtering at the same time as movement compensation. You will therefore have to run those in a separate step, e.g.
maxfilter -f input_file.fif -o output_file.fif -ds 4 -lpfilt 40
Diagnostics
You can get information about movement parameters using these scripts to analyse maxfilter output.
How to run Maxfilter at the CBSU
Via the CBU load balancing scripts
maxfilter - defaults to running version 2.2 on l43-l59
maxfilter-2.0 - runs version 2.0 on l24-l42
maxfilter-2.1 - runs v 2.1 on l43-l59
maxfilter-2.2 - runs v 2.2 on l43-l59
maxfilter_gui – runs using maxfilter-2.2 on l43-l59
To run without loadbalancing (i.e. on the current machine)
/neuro/bin/util/maxfilter – will run the default version of maxfilter for that machine (v2.0 on l24-42, v2.2 on l43-59)
The higher numbered machines also have the commands:
/neuro/bin/util/maxfilter-2.1
/neuro/bin/util/maxfilter-2.2
Running maxfilter this way does have the potential pitfall that the command /neuro/bin/util/maxfilter will run different versions depending on which machine you’re on.
By calling the actual binary files
/neuro/bin/util/<machine architecture>/maxfilter
/neuro/bin/util/<machine architecture>/maxfilter-2.1
/neuro/bin/util/<machine architecture>/maxfilter-2.2
Example Matlab Script
Courtesy of Rik Henson
% Maxfilter 2.2 Matlab script for Lisa's Experiment (R Henson May 2012) % Note matlab needs to be started on a 64bit machine (eg "spm eeg 8 highmemory") dat_wd = '/megdata/cbu/cat_mci/'; bas_wd = '/home/rh01/Collaborations/Lisa/NewData/imaging_data'; % a symbolic link to /imaging... YOU NEED TO CHANGE THIS TO YOUR DIECTORY!!! basestr = ' -ctc /neuro/databases/ctc/ct_sparse.fif -cal /neuro/databases/sss/sss_cal.dat'; basestr = [basestr ' -linefreq 50 -hpisubt amp']; basestr = [basestr ' -force']; % care!!! %basestr = [basestr ' -ds 4']; maxfstr = '!/neuro/bin/util/x86_64-pc-linux-gnu/maxfilter-2.2 ' addpath /imaging/local/meg_misc addpath /neuro/meg_pd_1.2/ for s = 1:length(cbu_codes{g}) sub_wd = fullfile(bas_wd,groups{g},sprintf('Sub%02d_%s',s,cbu_codes{g}{s})); try eval(sprintf('!mkdir %s',sub_wd)); end raw_wd = dir(fullfile(dat_wd,cbu_codes{g}{s},'1*')); raw_files = dir(fullfile(dat_wd,cbu_codes{g}{s},raw_wd.name,'*raw*')); midrun = ceil(length(raw_files)/2); % middle run for trans "across runs within subject" below cd(sub_wd) movfile = 'trans_move.txt'; eval(sprintf('!touch %s',movfile)); success=0; inc=0; incEEG = 1; for run = 1:length(raw_files) rawfile = fullfile(dat_wd,cbu_codes{g}{s},raw_wd.name,raw_files(run).name); while ~success % fit sphere doesn't change with run, but some files cause hpipoints error! fitfile = fullfile(dat_wd,cbu_codes{g}{s},raw_wd.name,raw_files(run+inc).name); try delete(fullfile(sub_wd,'fittmp.txt')); delete(fullfile(wd,sprintf('run_%02d_hpi.txt',run+inc))); end try [orig(s,:),rad,fit] = meg_fit_sphere(fitfile,sub_wd,sprintf('ses_%02d_hpi.txt',run+inc),incEEG); success=1; catch inc=inc+1; end delete(fullfile(sub_wd,'fittmp.txt')); end origstr = sprintf(' -origin %d %d %d -frame head',orig(s,1),orig(s,2),orig(s,3)); %% 1. Bad channel detection outfile = fullfile(sub_wd,sprintf('run_%02d_bad',run)); filestr = sprintf(' -f %s -o %s.fif',rawfile,outfile); finstr = [maxfstr filestr origstr basestr sprintf(' -autobad 2000 -v | tee %s.log',outfile)] % 2000s should be 33mins - ie all data! eval(finstr); delete(sprintf('%s.fif',outfile)); % Pull out bad channels from logfile: badfile = sprintf('%s.txt',outfile); eval(sprintf('!cat %s.log | sed -n -e ''/Detected/p'' -e ''/Static/p'' | cut -f 5- -d '' '' > %s',outfile,badfile)); tmp=dlmread(badfile,' '); tmp=reshape(tmp,1,prod(size(tmp))); tmp=tmp(tmp>0); % Omit zeros (padded by dlmread): % Get frequencies (number of buffers in which chan was bad): [frq,allbad] = hist(tmp,unique(tmp)); % Mark bad based on threshold (currently ~5% of buffers (assuming 500 buffers)): badchans = allbad(frq>0.05*500); if isempty(badchans) badstr = ''; else badstr = sprintf(' -bad %s',num2str(badchans)) end %% 2-step SSS then trans % %% 2. tSSS and trans across runs within subject outfile = fullfile(sub_wd,sprintf('run_%02d_tsss',run)); tSSSstr = ' -st 10 -corr 0.98'; posfile = fullfile(sub_wd,sprintf('run_%02d_headpos.txt',run)); compstr = sprintf(' -movecomp inter -hpistep 10 -hp %s',posfile); if run == midrun % Middle run - no need to trans anywhere transtr = ''; else transtr = sprintf(' -trans %s',fullfile(dat_wd,cbu_codes{g}{s},raw_wd.name,raw_files(midrun).name)); end filestr = sprintf(' -f %s -o %s.fif',rawfile,outfile); finstr = [maxfstr filestr basestr badstr tSSSstr compstr origstr transtr sprintf(' -v | tee %s.log',outfile)] eval(finstr); if run == midrun % Middle run - no need to trans anywhere eval(sprintf('!echo ''0 mm'' >> %s',movfile)); else eval(sprintf('!cat %s.log | sed -n ''/Position change/p'' | cut -f 7- -d '' '' >> %s',outfile,movfile)); end %% 3. trans to default helmet position (for across-subject) infile = outfile; outfile = fullfile(sub_wd,sprintf('run_%02d_tsss_transdef',run)); transtr = sprintf(' -trans default -origin %d %d %d -frame head -force',orig(s,:)+[0 -13 6]); filestr = sprintf(' -f %s.fif -o %s.fif',infile,outfile); finstr = [maxfstr filestr transtr sprintf(' -v | tee %s.log',outfile)] eval(finstr); if run == length(raw_files) eval(sprintf('!echo ''Transd...'' >> %s',movfile)); eval(sprintf('!cat %s.log | sed -n ''/Position change/p'' | cut -f 7- -d '' '' >> %s',outfile,movfile)); end end