Diff for "Maxfilter" - Meg Wiki
location: Diff for "Maxfilter"
Differences between revisions 17 and 18
Revision 17 as of 2008-01-25 16:26:47
Size: 8897
Comment:
Revision 18 as of 2008-02-10 18:20:32
Size: 8542
Comment:
Deletions are marked like this. Additions are marked like this.
Line 10: Line 10:
Maxfilter will identify the bad channels you marked in the fiff file, and will not use them  in calculations. Maxfilter will identify the bad channels you marked in the fiff file, and will not use them in calculations.
Line 17: Line 17:
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 number 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: 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 number 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:
Line 19: Line 19:
[co ki]=hpipoints(fiffile); % fiffaccess command to return digitised points in head coordinates headpoints=co(:,ki>1)'; % don't include the fiducial points 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); spherefit=str2num(spherefit)*1000; % m to mm; cmd=sprintf('%s -trans default -frame head -origin %g %g  %g', restofmaxfiltercommand, spherefit(1),spherefit(2)-5,spherefit(3)); {{{
[co ki]=hpipoints(fiffile); % fiffaccess command to return digitised points in head coordinates
headpoints=co(:,ki>1)'; % don't include the fiducial points
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));
}}}
Line 27: Line 34:
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''''  ''' 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'''' '''
Line 41: Line 48:
''-version''               shows the version number of the program ''-version'' shows the version number of the program
Line 43: Line 50:
''-help                  ''shows information of all options -v                     switches on verbose logging ''-help ''shows information of all options -v switches on verbose logging
Line 45: Line 52:
''-f <infile.fif>        ''sets the name of the input file ''-f <infile.fif> ''sets the name of the input file
Line 47: Line 54:
''-o <outfile.fif>''        sets the name of the output file ''-o <outfile.fif>'' sets the name of the output file
Line 49: Line 56:
''-origin <x0 y0 z0>''      sets the origin of the inside expansion (x0,y0,z0 must be in [mm])'' '' ''-origin <x0 y0 z0>'' sets the origin of the inside expansion (x0,y0,z0 must be in [mm])'' ''
Line 51: Line 58:
''-frame <device/head>   ''sets the device/head coordinate frame ''-frame <device/head> ''sets the device/head coordinate frame
Line 53: Line 60:
''-in <order_in>''  sets the order of the inside expansion ''-in <order_in>'' sets the order of the inside expansion
Line 55: Line 62:
''-out <order_out>''       sets the order of the outside expansion ''-out <order_out>'' sets the order of the outside expansion
Line 57: Line 64:
''-bad <chnos>''           sets the list of static bad channels (logical chnos, e.g.: 0323 1042 2631) ''-bad <chnos>'' sets the list of static bad channels (logical chnos, e.g.: 0323 1042 2631)
Line 59: Line 66:
''-autobad <on/off/n>''    sets automated bad channel detection on or off ''-autobad <on/off/n>'' sets automated bad channel detection on or off
Line 62: Line 69:
''-badlimit <x>          ''threshold for bad channel detection (>ave+x*SD) ''-badlimit <x> ''threshold for bad channel detection (>ave+x*SD)
Line 64: Line 71:
'' -skip <intervals>''      skips raw data sequences ''-skip <intervals>'' skips raw data sequences
Line 69: Line 76:
''-force''                 ignores program warnings ''-force'' ignores program warnings
Line 71: Line 78:
''-def                   ''shows default settings ''-def ''shows default settings
Line 73: Line 80:
''-maint                 ''shows the options needed for maintenance ''-maint ''shows the options needed for maintenance
Line 77: Line 84:
''-st [<buflen>]         ''applies the time-domain MaxST extension, ''-st [<buflen>] ''applies the time-domain MaxST extension,
Line 80: Line 87:
''-corr <th>             ''sets subspace correlation limit (def=0.98) MaxMove ''-corr <th> ''sets subspace correlation limit (def=0.98) MaxMove
Line 84: Line 91:
''-trans <fiff_file> | default'' transforms the data into the coil definitions of <fiff_file>, or into the default                                 frame ''-trans <fiff_file> | default'' transforms the data into the coil definitions of <fiff_file>, or into the default frame
Line 87: Line 94:
''-movecomp [inter]      ''estimates and compensates head movements ''-movecomp [inter] ''estimates and compensates head movements
Line 90: Line 97:
''-headpos               ''estimates and stores head position parameters, ''-headpos ''estimates and stores head position parameters,
Line 93: Line 100:
''-hp <posfile>''          stores head position data in an ascii file ''-hp <posfile>'' stores head position data in an ascii file
Line 95: Line 102:
''-hpistep <n>''           sets head position update interval in ms ''-hpistep <n>'' sets head position update interval in ms
Line 100: Line 107:
''-hpicons''               check initial consistency isotrak vs hpifit -linefreq <f>          sets the basic line interference frequency ''-hpicons'' check initial consistency isotrak vs hpifit -linefreq <f> sets the basic line interference frequency
Line 103: Line 110:
''-lpfilt <corner>       ''applies low-pass IIR filtering ''-lpfilt <corner> ''applies low-pass IIR filtering
Line 108: Line 115:
''-site <name>''           loads sss_cal_<name>.dat and ct_sparse_<name>.fif ''-site <name>'' loads sss_cal_<name>.dat and ct_sparse_<name>.fif
Line 110: Line 117:
''-cal <calfile> | off''   uses the fine-calibration in <calfile>, ''-cal <calfile> | off'' uses the fine-calibration in <calfile>,
Line 113: Line 120:
''-ctc <ctcfile> | off   ''uses the cross-talk matrix in <ctcfile>, ''-ctc <ctcfile> | off ''uses the cross-talk matrix in <ctcfile>,
Line 116: Line 123:
''-magbad''                marks all magnetometers bad ''-magbad'' marks all magnetometers bad
Line 118: Line 125:
''-regularize on/off''     sets the component selection on or off ''-regularize on/off'' sets the component selection on or off
Line 120: Line 127:
''-iterate [n]''           uses iterative pseudo-inverse, n iteration loops ''-iterate [n]'' uses iterative pseudo-inverse, n iteration loops
Line 123: Line 130:
''-ds [f]''                applies downsampling with low-pass FIR filtering ''-ds [f]'' applies downsampling with low-pass FIR filtering

MaxFilter

A common first step in analysing your data is to pre-processing them using the Maxfilter program. This Neuromag sofware implements "Signal-Space Separation" (SSS), which is a clever mathematical way to separate magnetic signals coming from within the brain (or more precisely, a sphere within the sensors) from those coming from outside the brain (or more precisely, from outside a sphere outside the sensors). Some PDFs that describe the SSS mathematics are here: attachment:Taulu_IEEE_05.pdf , attachment:Taulu_JAP_05.pdf , attachment:Taulu_PMB_06.pdf .

Maxfilter is essential if you have acquired your data using Maxshield (to remove the shielding effects). It is also helpful for 1) removing noise, particularly using its "temporal extension", 2) detecting bad channels, 3) realigning (interpolated) data after movement (provided you have used continuous HPI) and 4) moving the data to a standard space (e.g, across subjects).

Before you apply SSS, it is a very good idea to mark bad channels. These can be detected with the "autobad" feature of Maxfilter (though this does not work for timeperiods in which continuous HPI is active, which is why we often only start cHPI after about 20s, and see below for bugs associated with this option). Alternatively, they can be detected with software like BESA, or by eye during acquisition or afterwards using a browser like mne_browse_raw. You can then tell maxfilter these channels are bad when you call maxfilter (see below), or you can mark them in the actual FIFfile using a commandline utility mark_bad_fiff under /neuro/bin/util/. Eg:

/neuro/bin/util/mark_bad_fiff 632 741 2211 <filename.fif>

Maxfilter will identify the bad channels you marked in the fiff file, and will not use them in calculations.

Avoid MaxFilter Bugs!

CBU researchers have encountered problems using some options in Neuromag's Max Filter program, and in discussing these issues with the Neuromag software engineers, we have learned of a few other bugs too. These are briefly summarised below and will be expanded upon as we gain more info. See the "neuromeg" mailing list archives for the full discussion (and if you haven't done it already, join the list!): http://www.jiscmail.ac.uk/archives/neuromeg.html

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 number 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(:,ki>1)'; % don't include the fiducial points
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 '-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.

Usage of MaxFitler from command line'

GUI interface to maxfilter is limited, but can be helpful to discover the options the program has to offer. For the full power and scriptability, use the command line utility.

usage: /opt/neuromag/bin/util/i686-pc-linux-gnu/maxfilter -f <infile> [options]

General options:

-version shows the version number of the program

-help shows information of all options -v switches on verbose logging

-f <infile.fif> sets the name of the input file

-o <outfile.fif> sets the name of the output file

-origin <x0 y0 z0> sets the origin of the inside expansion (x0,y0,z0 must be in [mm])

-frame <device/head> sets the device/head coordinate frame

-in <order_in> sets the order of the inside expansion

-out <order_out> sets the order of the outside expansion

-bad <chnos> sets the list of static bad channels (logical chnos, e.g.: 0323 1042 2631)

-autobad <on/off/n> sets automated bad channel detection on or off

  • n: scan from first n raw data tags (def n = 20)

-badlimit <x> threshold for bad channel detection (>ave+x*SD)

-skip <intervals> skips raw data sequences

  • time intervals pairs in sec, e.g.: 0 30 120 150

-format <short/long/float> stores the output in 16-bit short, 32-bit integer or float format

-force ignores program warnings

-def shows default settings

-maint shows the options needed for maintenance

MaxST options:

-st [<buflen>] applies the time-domain MaxST extension,

  • optionally set data buffer length (def 4 sec)

-corr <th> sets subspace correlation limit (def=0.98) MaxMove

MaxMove options:

-trans <fiff_file> | default transforms the data into the coil definitions of <fiff_file>, or into the default frame

-movecomp [inter] estimates and compensates head movements

  • in continuous raw data (optionally for intermittent HPI)

-headpos estimates and stores head position parameters,

  • but does not compensate movements

-hp <posfile> stores head position data in an ascii file

-hpistep <n> sets head position update interval in ms

-hpisubt <amp/base/off> subtracts hpi signals: sine amplitudes,

  • amp + baseline, or switch off (def = amp)

-hpicons check initial consistency isotrak vs hpifit -linefreq <f> sets the basic line interference frequency

  • (50 or 60 Hz)

-lpfilt <corner> applies low-pass IIR filtering

  • (def corner = 120 Hz)

Other options:

-site <name> loads sss_cal_<name>.dat and ct_sparse_<name>.fif

-cal <calfile> | off uses the fine-calibration in <calfile>,

  • or switch off

-ctc <ctcfile> | off uses the cross-talk matrix in <ctcfile>,

  • or switch off

-magbad marks all magnetometers bad

-regularize on/off sets the component selection on or off

-iterate [n] uses iterative pseudo-inverse, n iteration loops

  • default n=10; n=0 forces direct pseudo-inverse.

-ds [f] applies downsampling with low-pass FIR filtering

  • f is optional downsampling factor (def = 2; max=4)

CbuMeg: Maxfilter (last edited 2022-07-18 15:02:40 by OlafHauk)