Diff for "maxdiagnost" - Meg Wiki
location: Diff for "maxdiagnost"
Differences between revisions 5 and 7 (spanning 2 versions)
Revision 5 as of 2009-07-08 10:53:19
Size: 5960
Editor: YaaraErez
Comment:
Revision 7 as of 2009-07-08 10:55:18
Size: 5926
Editor: YaaraErez
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
The output of maxfilter can be written to a text file (e.g. using the "tee" command in unix). For example, if you use movement compensation (-movecomp), this file will contain movement and HPI-fit parameters for each time step (usually every 200ms). We recommend you look at this output carefully, since it may help detect fundamental problems with HPI positioning, or whether your participant moved during a session.
A possible Matlab script for reading the maxfilter output is shown below, together with a shorter script that reads the output and displays it in separate figures for each input file.
= Maxfilter Diagnostics =
The output of maxfilter can be written to a text file (e.g. using the "tee" command in unix). For example, if you use movement compensation (-movecomp), this file will contain movement and HPI-fit parameters for each time step (usually every 200ms). We recommend you look at this output carefully, since it may help detect fundamental problems with HPI positioning, or whether your participant moved during a session.  A possible Matlab script for reading the maxfilter output is shown below, together with a shorter script that reads the output and displays it in separate figures for each input file.
Line 5: Line 5:
Line 6: Line 7:
% uses check_movecomp to read and display maxfilter -movecomp output
Line 10: Line 12:
nr_files = length(movecompfiles);
for ff = 1:nr_files,
Line 11: Line 15:
nr_files = length(movecompfiles);

for ff = 1:nr_files,
    
Line 21: Line 21:
Line 24: Line 23:
Line 31: Line 29:
Line 33: Line 30:
Line 35: Line 31:
Line 37: Line 32:
Line 39: Line 33:
Line 42: Line 35:
while feof(fid_in) == 0,      while feof(fid_in) == 0,
Line 53: Line 46:
Line 56: Line 48:
Line 59: Line 50:
Line 65: Line 55:
    
Line 71: Line 61:
        while ~isempty(deblank(restof)),                     while ~isempty(deblank(restof)),
Line 75: Line 65:
            end;                        end;
Line 79: Line 69:
    
Line 82: Line 72:
        
Line 87: Line 77:
        
Line 93: Line 83:
        
Line 99: Line 89:
        
Line 105: Line 95:
        
Line 111: Line 101:
        
Line 117: Line 107:
        
Line 119: Line 109:
    
Line 121: Line 111:
Line 127: Line 116:
Line 139: Line 127:
Line 141: Line 128:

Maxfilter Diagnostics

The output of maxfilter can be written to a text file (e.g. using the "tee" command in unix). For example, if you use movement compensation (-movecomp), this file will contain movement and HPI-fit parameters for each time step (usually every 200ms). We recommend you look at this output carefully, since it may help detect fundamental problems with HPI positioning, or whether your participant moved during a session. A possible Matlab script for reading the maxfilter output is shown below, together with a shorter script that reads the output and displays it in separate figures for each input file.

This script reads and displays info from maxfilter output file (if -movecomp was used):

% uses check_movecomp to read and display maxfilter -movecomp output
% Files with maxfilter outputs, e.g. for different subjects and conditions
movecompfiles = {'outputfile1.log', ...
                 'outputfile2.log', ...
                 'outputfile3.log');
nr_files = length(movecompfiles);
for ff = 1:nr_files,

    [mv_fig, linet, linee, lineg, linev, liner, lined] = check_movecomp(movecompfiles{ff}); % read info from log-file
    [a,b,c,d] = fileparts( movecompfiles{ff} );
    tittxt = [a(end-17:end) '/' b]; % just one way to keep the figure title short
    figure( mv_fig );
    % check_movecomp only creates the figure, but without the title, so you can do this separately
    ht = title(tittxt); set(ht, 'interpreter', 'none'); % add title to figure
end;

The previous script uses the following Matlab function (also in /imaging/olaf/MEG/maxfilter):

function [mv_fig, linet, linee, lineg, linev, liner, lined] = check_movecomp(mvcomp_file);
% read and plot maxfilter output from log-file
% [mv_fig, linet, linee, lineg, linev, liner, lined] = check_movecomp(mvcomp_file);
colours = {'b', 'g', 'r', 'm', 'c', 'k', 'y'};
fprintf(1, 'Input file: %s.\n', mvcomp_file);
fid_in = fopen(mvcomp_file);    % open movecomp log-file
now_line = fgetl(fid_in);
cc = 0;
fprintf(1, 'Reading line ');
while feof(fid_in) == 0,
    if ~isempty(deblank(now_line)),
        cc = cc + 1;
        alllines{cc} = now_line;
        if ~mod(cc,100), fprintf(1, '%d ', cc); end;
        if ~mod(cc,1000), fprintf(1, '\n', cc); end;
    end;
    now_line = fgetl(fid_in);
end;    % while...
nr_lines = cc;
fprintf(1, '\n%d lines read\n', nr_lines);
HPIline = 'Hpi fit OK, movements [mm/s]';
lenH = length(HPIline);
Tline = '#t =';
lenT = length(Tline);
c_fit = 0;
t_fit = 0;
for cc = 1:nr_lines,
    thisline = alllines{cc};
    n = length(thisline);

    if n>=lenH && strcmp(thisline(1:lenH),HPIline),
        c_fit = c_fit+1;
        [tmp, restof] = strtok(thisline, '=');
        [tmp, restof] = strtok(restof(2:end), '/');
        cnt=0;
        while ~isempty(deblank(restof)),
            if length(find(findstr(tmp, '-')))==0,
                cnt=cnt+1;
                xyz(cnt,c_fit) = str2num(tmp);
            end;
            [tmp, restof] = strtok(restof(2:end), '/');
        end;
    end;

    if n>=lenT && strcmp(thisline(1:lenT),Tline),
        t_fit = t_fit+1;

        [tmp, restof] = strtok(thisline, 't');
        [tmp, restof] = strtok(restof, '=');
        [tmp, restof] = strtok(restof, ',');
        linet(t_fit) = str2num( tmp(2:end) );

        [tmp, restof] = strtok(thisline, 'e');
        [tmp, restof] = strtok(restof, '=');
        [tmp, restof] = strtok(restof);
        [tmp, restof] = strtok(restof);
        linee(t_fit) = str2num( tmp(2:end) );

        [tmp, restof] = strtok(thisline, 'g');
        [tmp, restof] = strtok(restof, '=');
        [tmp, restof] = strtok(restof);
        [tmp, restof] = strtok(restof, ',');
        lineg(t_fit) = str2num( tmp(2:end) );

        [tmp, restof] = strtok(thisline, 'v');
        [tmp, restof] = strtok(restof, '=');
        [tmp, restof] = strtok(restof);
        [tmp, restof] = strtok(restof);
        linev(t_fit) = str2num( tmp(2:end) );

        [tmp, restof] = strtok(thisline, 'r');
        [tmp, restof] = strtok(restof, '=');
        [tmp, restof] = strtok(restof);
        [tmp, restof] = strtok(restof);
        liner(t_fit) = str2num( tmp(2:end) );

        [tmp, restof] = strtok(thisline, 'd');
        [tmp, restof] = strtok(restof, '=');
        [tmp, restof] = strtok(restof);
        [tmp, restof] = strtok(restof);
        lined(t_fit) = str2num( tmp(2:end) );

    end;

end;
mv_fig(1) = figure;
subplot(2,1,1);
plot(linet, linee, colours{1}, linet, lineg, colours{2}, linet, linev, colours{3}, linet, liner, colours{4}, linet, lined, colours{5});
%legend( {'#e (cm)', '#g', '#v (cm/s)', '#r (rad/s)', '#d (cm)'} );
legend( {'fitting error (cm)', 'gof (0-1)', 'translation (cm/s)', 'rotation (rad/s)', 'drift (cm)'} );
if exist('xyz', 'var') && ~isempty(xyz),
    if size(xyz,2)~=length(linet),
        linet = 1:size(xyz,2);
        fprintf(1, '\n\nHPI problems!!! %s\n\n', mvcomp_file);
    end;
    subplot(2,1,2);
    plot(linet, xyz(1,:), colours{1}, linet, xyz(2,:), colours{2}, linet, xyz(3,:), colours{3});
    legend( {'x (mm/s)', 'y (mm/s)', 'z (mm/s)'} );
else,
    fprintf(1, '\n\nHPI problems!!! %s\n\n', mvcomp_file);
end;

Here's an example of how the output might look like:

attachment:fig_example.jpg

The upper panel is the more important one. The green line (goodness-of-fit, "gof") indicates how well the HPI coils could be detected, and should always be 1 (without accurate localisation of these coils, the rest would be meaningless). Translation (red), rotation (pink) and drift (light blue) indicate whether the subject moved their head. These values should be as low as possible, ideally below 0.3. As this example shows, this recording went rather well, with some sudden movements occurring at the beginning and around the middle of the scan.

CbuMeg: maxdiagnost (last edited 2013-03-08 10:02:46 by localhost)