Home > utils > physio > read_mate.m

read_mate

PURPOSE ^

[runinfo, params] = read_mate(flist,params)

SYNOPSIS ^

function [ri, p] = read_mate(flist,p)

DESCRIPTION ^

 [runinfo, params] = read_mate(flist,params)

 Reads physiological data monitoring files acquired using the Siemens 3T MATE
 system.

 Each variable is recorded to a different file, and these files are specified
 in flist.  There is a field in the params structure which identifies the filetypes

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ri, p] = read_mate(flist,p)
0002 % [runinfo, params] = read_mate(flist,params)
0003 %
0004 % Reads physiological data monitoring files acquired using the Siemens 3T MATE
0005 % system.
0006 %
0007 % Each variable is recorded to a different file, and these files are specified
0008 % in flist.  There is a field in the params structure which identifies the filetypes
0009 
0010 ri = struct('vol_onsets',[],'cardiac',[]);
0011 
0012 if nargin < 2
0013   error('read_mate: Too few input arguments')
0014 end
0015 
0016 % Determine how many files we are dealing with
0017 nfiles = length(flist);
0018 
0019 % Make sure we have a field specifying their types
0020 if ~isfield(p,'ftypes') || length(p.ftypes) ~= nfiles
0021   fprintf('read_mate: File type information incorrectly specified');
0022 end
0023 
0024 % One of the files must be the external trigger signal from the scanner, as
0025 % this will be used to determine start and stop times of a run, and for parsing
0026 % of the other files
0027 
0028 % Load in all of the files
0029 clear trig pulse resp
0030 for ifile = 1:nfiles
0031   fname = flist{ifile};
0032   
0033   if ~exist(fname,'file')
0034     fprintf('read_mate: Could not find file <%s> ... skipping ...\n', fname);
0035     continue
0036   end
0037   
0038   fprintf('Loading data from file: %s\n', fname);
0039   data = load(fname, '-ascii');
0040   
0041   switch p.ftypes{ifile}
0042     case {'scantrig', 'exttrig'}
0043       trig = data;
0044     case {'cardiac', 'pulse'}
0045       pulse = data;
0046     case {'respir'}
0047       resp = data;
0048     otherwise
0049       fprintf('read_mate: Unknown filetype: %s\n', p.ftypes{ifile});
0050   end
0051 end % for ifile=
0052 clear data
0053 
0054 if exist('trig')
0055   % Process the trigger data
0056   tp.thresh = p.trig_thresh;
0057   tp.dir = p.trig_dir;
0058 
0059   % Find the trigger pulse onsets
0060   trig_onset_samps = find_thresh_cross(trig,tp);
0061 
0062   % See how many trigger onsets we found, and make sure this number is reasonable
0063   ntrig = length(trig_onset_samps);
0064   if ~ntrig
0065     fprintf('read_mate: Found no scanner triggers ...\n')
0066     return
0067   end
0068 
0069   % Convert the onsets to time values
0070   trig_onset_sec = (trig_onset_samps-1)/p.Fs_trig;
0071 
0072   % Calculate some statistics about this pulse train that will be used to
0073   % determine run onsets and offsets.
0074 
0075   % Get the median inter-trigger interval and make sure it is within bounds
0076   itis = diff(trig_onset_sec);
0077   median_iti = median(itis);
0078 
0079   if p.trig_is_vol
0080     expect_median_iti = p.TR;
0081   else
0082     expect_median_iti = p.TR/p.nslice_per_vol;
0083   end
0084   min_iti = expect_median_iti-p.trig_slop_sec;
0085   max_iti = expect_median_iti+p.trig_slop_sec;
0086   if ~((median_iti > min_iti) & (median_iti < max_iti))
0087     warning(sprintf('read_mate: median iti (%1.4f s) is out of range (%1.4f, %1.4f)\n', median_iti, min_iti, max_iti))
0088     return
0089   end
0090 
0091   % Find the ITI that exceeds some integer multiple of the median ITI
0092   border_idxs = find(itis > 3*median_iti)+1;
0093   num_borders = length(border_idxs);
0094 
0095   % If we find none, then assume that all of the trigger events are part of the
0096   % same run
0097   if num_borders == 0
0098     trig_onset_idxs = 1:ntrig;
0099   elseif num_borders == 1;
0100     trig_onset_idxs = border_idxs:ntrig;
0101   else
0102     fprintf('Located %d run borders.  Too many to handle\n', num_borders);
0103     return
0104   end
0105 
0106   run_start_time = trig_onset_sec(trig_onset_idxs(1));
0107   run_stop_time = trig_onset_sec(trig_onset_idxs(end))+p.TR;
0108   ri.vol_onsets = trig_onset_sec(trig_onset_idxs)-run_start_time;
0109 else
0110   fprintf('Have no trigger information: Cannot process other information\n');
0111   return
0112 end % if exist('trig')
0113   
0114 for ifile = 1:nfiles
0115   switch p.ftypes{ifile}
0116     case {'cardiac', 'pulse'}
0117       tp.thresh = p.pulse_thresh;
0118       tp.dir = p.pulse_dir;
0119       
0120       % Get the pulse signal threshold crossings
0121       pulse_onset_samps = find_thresh_cross(pulse,tp);
0122       pulse_onset_sec = pulse_onset_samps/p.Fs_pulse;
0123       
0124       % Get the pulse events for the run
0125       pulse_idxs = find((pulse_onset_sec >= run_start_time) & (pulse_onset_sec ...
0126       <= run_stop_time));
0127       
0128       ri.cardiac = pulse_onset_sec(pulse_idxs)-run_start_time;
0129       
0130   end % switch p.ftypes{ifile}
0131 end % for ifile
0132 
0133 return
0134

Generated on Thu 23-May-2019 04:00:50 by m2html © 2003