Home > eeg > egis > meg_code > getbtiraw.m

getbtiraw

PURPOSE ^

GETBTIRAW get MEG data from Bti raw data files

SYNOPSIS ^

function [B, channel, npts, dt] = getbtiraw(topdir,datfile,hdrfile)

DESCRIPTION ^

 GETBTIRAW get MEG data from Bti raw data files

 Open file topdir/datfile, using hdrfile to translate the rawfile format.
 Return magnetic field data B (zero-meaned), channel names (both suitably
 reordered), number of points npts, and time step dt.
 At present doesn't return n_epochs or initial time.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [B, channel, npts, dt] = getbtiraw(topdir,datfile,hdrfile)
0002 % GETBTIRAW get MEG data from Bti raw data files
0003 %
0004 % Open file topdir/datfile, using hdrfile to translate the rawfile format.
0005 % Return magnetic field data B (zero-meaned), channel names (both suitably
0006 % reordered), number of points npts, and time step dt.
0007 % At present doesn't return n_epochs or initial time.
0008 
0009 % Example: datfile = '3047.4/2Mx3-6s254/GV8RH9BO/1/c,rfhp1.0Hz'
0010 
0011 % Get format information from header file
0012 if ~exist('hdrfile') hdrfile = []; end
0013 [channel bfactors npts dt] = parseheader(topdir, hdrfile);
0014 
0015 fid = fopen(fullfile(topdir,datfile), 'r', 'ieee-be');
0016 % use integer*2 format if reading raw digitized data (short int)
0017 if ~exist('rformat'), rformat = 'integer*2'; end
0018 
0019 % else data may be in float format if filtered or DC offset
0020 
0021 nchans = size(channel,1);
0022 [B num] = fread(fid,[nchans npts],rformat);
0023 if num ~= (npts*nchans)
0024   error('Number of data points read doesnt match number requested')
0025 end
0026 
0027 fclose(fid);
0028 
0029 sortarray = [];                % sort channels into good order
0030 for i=1:nchans
0031   if channel(i,1) == 'A'        % good MEG channels first
0032     sortarray(i) = str2num(channel(i,2:end));
0033   elseif channel(i,1:3) == 'TRI'    % Trigger next
0034     sortarray(i) = 500;
0035   elseif channel(i,1:3) == 'RES'    % then Response channel
0036     sortarray(i) = 501;
0037   elseif channel(i,1) == 'X'        % finally external channels
0038     sortarray(i) = 1000 + str2num(channel(i,2:end));
0039   else
0040     sortarray(i) = 2000 + i;
0041   end
0042 end
0043 
0044 [channum sortindex] = sort(sortarray);
0045 sortindex = sortindex(channum<2000);    % discard extraneous channels
0046 B = B(sortindex,:)';
0047 channel = channel(sortindex,:);
0048 bfactors = bfactors(sortindex);
0049 bmeans = mean(B);
0050 nbchans = find(strcmp(cellstr(channel),'TRIGGER')) - 1; % # of Bfield channels
0051 bmeans(nbchans+1:end) = 0*bmeans(nbchans+1:end); % only zeromean B channels
0052 
0053 if rformat == 'integer*2'        % apply channel factors to ints
0054   for i=1:size(B,2)
0055     B(:,i) = bfactors(i)*(B(:,i)-bmeans(i));
0056   end
0057 end
0058

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003