maxbugs - Meg Wiki

You are not allowed to do login on this page. Login and try again.

Clear message
location: maxbugs

Avoid MaxFilter Bugs!

CBU researchers have encountered problems using some options in Neuromag's Max Filter program (version 2.0), and in discussing these issues with the Neuromag software engineers, we have learned of a few other bugs too (hopefully these will be fixed in version 2.1, though we have not received this yet). These are briefly summarised below and will be expanded upon as we gain more info. To know more, please see this technical note from Neuromag: Maxfilter_Bugs.pdf , and also the "neuromeg" mailing list archives for the full discussion http://www.jiscmail.ac.uk/archives/neuromeg.html (and if you haven't done it already, join the list!)

Don't use '-trans default' without setting '-frame' and '-origin'

If you attempt to transform the subject's head position to the 'default' position corresponding to the origin of the device coordinate frame (see p. 33 of Max Filter User's Guide) without specifying the -frame and -origin options, the transformed data will contain large-amplitude noise at the vertex. This bug is known to Neuromag and they are working on a solution. Apparently Max Move works ok when the target position is defined in another file, or with the default option when -frame and -origin are specified, e.g.: '-trans other_file_sss.fif' or '-trans default -frame head -origin 0 0 40' where the last three numbers are the xyz coordinates of the sphere origin. "0 0 40" is an approximation of the centre of a typical head/brain, relative to the fiducial origin, and in most cases should be adequate. However it may be better to specify the centre of a sphere fit to the digitized head points (or a point relative to this). One reason is that the centre of the brain may be more stable across subjects relative to the centre of the head rather than relative to the fiducial origin (e.g. if a subject has a crooked nose?) Another reason is that this should make the realignment robust to errors, or differences, in the definition of the fiducial points across subjects or sessions (e.g. preauricular vs. periauricular). maxfilter automatically defines the origin in a similar way if neither "-trans default" nor "-origin" are specified. However, if you are specifying the origin manually, here is a matlab example of how you might extract the coordinates of a best-fitting head sphere and pass this to maxfilter:

[co ki]=hpipoints(fiffile); % fiffaccess command to return digitised points in head coordinates
headpoints=co(:,~mod(ki,2))'; % don't include the fiducial points or EEG electrodes
save(regexprep(fiffile,'\.fif$','_headpoints.txt'),'-ASCII','headpoints')
cmd_fit=['/neuro/bin/util/fit_sphere_to_points ' regexprep(fiffile,'\.fif$','_headpoints.txt')];
[status spherefit]=unix(cmd_fit);
fit=str2num(spherefit)*1000; % m to mm;
cmd=sprintf('%s -trans default -frame head -origin %g %g %g', maxfiltercommand, fit(1), fit(2)-5, fit(3));

Don't use '-trans' with head-movement compensation '-movecomp'

According to Neuromag, -movecomp always returns the head position to the initial position in the recording.

Don't use '-autobad' with head-position estimation '-headpos' or movement compensation '-movecomp'

Just don't. Apparently '-autobad' is fine alone, and '-headpos' and '-movecomp' are fine without '-autobad'. Note (as above) that you do not have to use '-autobad'; you can instead inspect your raw data, note any noisy or otherwise 'bad' sensors, and use the -bad <sensor number(s)>, e.g.: '-bad 521 1421 2413'

Don't use '-autobad' with '-st' option

Apparently, autobad is automatically disabled when the -st option is selected.

Don't use '-lpfilt' to low-pass filter data

According to Neuromag, -lpfilt uses an IIR filter which introduces a delay in the output signal. Note that downsampling, option -ds, also necessarily low-pass filters data but it does not cause the same delay because it uses an FIR filter.

Head origin 0 0 0 problem and solution

Neuromag have discovered a bug in the current release of maxfilter which could impact on anyone who recorded MEG data at the CBU in early 2008. The problem occurs for sessions in which the positions of the HPI coils were re-digitised as extra points to check their location as part of the MEG prep. This seems to have been common practice in late Feb, March, April, and early May, but has since been re-placed with the check HPI option.

The bug is such that maxfilter will set the sphere origin to 0,0,0 instead of the more normal 0,0,40 during SSS which results in much more noisy data coming out. NB maxfilter will not crash and no error will be given, you have to check the log files to spot this. The solution at present is to manually input your own sphere origin during the call to max filter. An example of how to do this, using fit sphere to points, and calling it from within Matlab is given below. If you are not in a rush the new release of maxfilter (MaxFilter 2.1) will contain a fix. From looking at data with and without the fix applied it is strongly recommended that you re-analyse your data if your files do encounter this bug.

[co ki]=hpipoints(infile);                       % infile is your raw .fif filename (with .fif)
tmppoints=co(:,ki>1)';                                  % don't include the fiducial points
nloc = find(~(tmppoints(:,3)<0 & tmppoints(:,2)>0));    % Remove the nose points if you have any
headpoints = tmppoints(nloc,:);                   
save(headpfname,'-ASCII','headpoints')
cmd_fit=['/neuro/bin/util/fit_sphere_to_points ' headpfname];
[status spherefit]=unix(cmd_fit);
if length(spherefit)<1;
    error('Spherefit failed!')
end
fit=str2num(spherefit)*1000; % m to mm;

%% Finally the call to max filter. The key part is the inclusion of -origin tag and the fit values

eval(sprintf('!/neuro/bin/util/maxfilter -f %s -o %s -ctc /neuro/databases/ctc/ct_sparse.fif -cal /neuro/databases/sss/sss_cal.dat -autobad off -frame head -origin %g %g %g -v | tee %s', infile, outfile, fit(1), fit(2), fit(3), logfile)) . 

Downsampling by a factor of 5

On at least one dataset (acquired at 1kHz sampling rate; ie standard in this and all respects), downsampling by a factor of 4 ('-ds 4') works fine, but downsampling by a factor of 5 ('-ds 5') causes a core dump...

Telegraphing

There have been some spurious (i.e. in one study roughly 1 in 6 runs) cases of maxfilter creating telegraph artifacts in data. These effects are minimized by using -st; however, they are still present.