Home > bioelectromagnetism > eeg_load_scan_coh_asc.m

eeg_load_scan_coh_asc

PURPOSE ^

eeg_load_scan_coh_asc - Read a Scan coherence ascii file (*.dat)

SYNOPSIS ^

function coh = eeg_load_scan_coh_asc(filename)

DESCRIPTION ^

 eeg_load_scan_coh_asc - Read a Scan coherence ascii file (*.dat)
 
 Usage: coh = eeg_load_scan_coh_asc(filename)
 
 This script extracts all the coherence values from a Scan 
 coherence ascii file.
 
 An example of the coh struct returned:
 
       subject: ''
          date: '19-Jul-2002'
          time: '14:01:47'
      channels: 64
          rate: 500
          type: 'PairedChannels'
        points: 82
        domain: 'Frequency'
         pairs: 2016
      freqbins: [1x82 double]
     pairnames: {2016x2 cell}
          data: [2016x82 double]
         phase: [2016x82 double]

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function coh = eeg_load_scan_coh_asc(filename)
0002 
0003 % eeg_load_scan_coh_asc - Read a Scan coherence ascii file (*.dat)
0004 %
0005 % Usage: coh = eeg_load_scan_coh_asc(filename)
0006 %
0007 % This script extracts all the coherence values from a Scan
0008 % coherence ascii file.
0009 %
0010 % An example of the coh struct returned:
0011 %
0012 %       subject: ''
0013 %          date: '19-Jul-2002'
0014 %          time: '14:01:47'
0015 %      channels: 64
0016 %          rate: 500
0017 %          type: 'PairedChannels'
0018 %        points: 82
0019 %        domain: 'Frequency'
0020 %         pairs: 2016
0021 %      freqbins: [1x82 double]
0022 %     pairnames: {2016x2 cell}
0023 %          data: [2016x82 double]
0024 %         phase: [2016x82 double]
0025 %
0026 %
0027 
0028 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0029 
0030 % Licence:  GNU GPL, no express or implied warranties
0031 % History:  11/2002, Darren.Weber_at_radiology.ucsf.edu
0032 %
0033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0034 
0035 [path,name,ext] = fileparts(filename);
0036 file = fullfile(path,[name ext]);
0037 
0038 [fid,msg] = fopen(file,'r');
0039 if ~isempty(msg), error(msg); end
0040 
0041 tic
0042 
0043 fprintf('\nEEG_LOAD_SCAN_COH_ASC...\n');
0044 fprintf('...reading data file:\n\t%s\n',file);
0045 
0046 coh = read_coh(fid);
0047 
0048 t = toc; fprintf('...done (%6.2f sec).\n\n',t);
0049 
0050 return
0051 
0052 
0053 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0055 function [coh] = read_coh(fid)
0056     
0057     coh = [];
0058     
0059     % Read the header, eg:
0060     %
0061     % [Subject]
0062     % [Date]    07/19/2002
0063     % [Time]    14:01:47
0064     % [Channels]    64
0065     % [Rate]    500.000000
0066     % [Type]    PairedChannels
0067     % [Points]    82
0068     % [Domain]    Frequency
0069     % [Pairs]    2016
0070     % [Paired Channels Data Matrix: Magnitude Squared (Pairs by Points)]
0071     
0072     fprintf('...reading header\n');
0073     
0074     while 1,
0075         tmp = fgetl(fid);
0076         if strmatch(lower('[Subject]'),lower(tmp)),
0077             coh.subject = strrep(tmp,sprintf('[Subject]\t'),'');
0078             tmp = fgetl(fid);
0079         end
0080         if strmatch(lower('[Date]'),lower(tmp)),
0081             tmp = strrep(tmp,sprintf('[Date]\t'),'');
0082             coh.date = datestr(datenum(tmp));
0083             tmp = fgetl(fid);
0084         end
0085         if strmatch(lower('[Time]'),lower(tmp)),
0086             coh.time = strrep(tmp,sprintf('[Time]\t'),'');
0087             tmp = fgetl(fid);
0088         end
0089         if strmatch(lower('[Channels]'),lower(tmp)),
0090             tmp = strrep(tmp,sprintf('[Channels]\t'),'');
0091             coh.channels = str2num(tmp);
0092             tmp = fgetl(fid);
0093         end
0094         if strmatch(lower('[Rate]'),lower(tmp)),
0095             tmp = strrep(tmp,sprintf('[Rate]\t'),'');
0096             coh.rate = str2num(tmp);
0097             tmp = fgetl(fid);
0098         end
0099         if strmatch(lower('[Type]'),lower(tmp)),
0100             coh.type = strrep(tmp,sprintf('[Type]\t'),'');
0101             tmp = fgetl(fid);
0102         end
0103         if strmatch(lower('[Points]'),lower(tmp)),
0104             tmp = strrep(tmp,sprintf('[Points]\t'),'');
0105             coh.points = str2num(tmp);
0106             tmp = fgetl(fid);
0107         end
0108         if strmatch(lower('[Domain]'),lower(tmp)),
0109             coh.domain = strrep(tmp,sprintf('[Domain]\t'),'');
0110             tmp = fgetl(fid);
0111         end
0112         if strmatch(lower('[Pairs]'),lower(tmp)),
0113             tmp = strrep(tmp,sprintf('[Pairs]\t'),'');
0114             coh.pairs = str2num(tmp);
0115             tmp = fgetl(fid);
0116         end
0117         if findstr(lower(tmp),lower('Data')),
0118             datamatrix = tmp;
0119             tmp = fgetl(fid);
0120             tmp = strrep(tmp,'[' ,'');
0121             tmp = strrep(tmp,']' ,'');
0122             tmp = strrep(tmp,'Hz','');
0123             coh.freqbins = str2num(tmp);
0124         end
0125         break;
0126     end
0127     
0128     coh.pairnames = cell(coh.pairs,2);
0129     
0130     if findstr(datamatrix,'Pairs by Points'),
0131         coh.data = zeros(coh.pairs,coh.points);
0132         row = coh.pairs;
0133     elseif findstr(datamatrix,'Points by Pairs'),
0134         % not sure this is an option, but just in case
0135         fprintf('..cannot read data matrix for points by pairs\n');
0136         return
0137         %coh.data = zeros(coh.points,coh.pairs);
0138         %row = coh.points;
0139     end
0140     
0141     % Now read in the data matrix
0142     fprintf('...reading coherence\n');
0143     for r = 1:row,
0144         tmp = fgetl(fid);
0145         a = findstr(tmp,'[') + 1;
0146         b = findstr(tmp,']') - 1;
0147         c = findstr(tmp,'-');
0148         c = c(1);
0149         coh.pairnames{r,1} = tmp(a:c-1);
0150         coh.pairnames{r,2} = tmp(c+1:b);
0151         coh.data(r,:) = str2num(tmp(b+2:end));
0152     end
0153     
0154     % Phase Degrees
0155     tmp = fgetl(fid);
0156     if findstr(tmp,'Phase'),
0157         fprintf('...reading phase (degrees)\n');
0158         tmp = fgetl(fid); % this line contains freqbins
0159         coh.phase = zeros(size(coh.data));
0160         for r = 1:row,
0161             tmp = fgetl(fid);
0162             b = findstr(tmp,']') - 1;
0163             coh.phase(r,:) = str2num(tmp(b+2:end));
0164         end
0165     end
0166     
0167     fclose(fid);
0168     
0169 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003