Home > bioelectromagnetism > eeg_load_scan4_cnt_data.m

eeg_load_scan4_cnt_data

PURPOSE ^

eeg_load_scan4_cnt_data - Read Neuroscan 4.x Continuous EEG Data

SYNOPSIS ^

function [data,srate,numSamples,labels,events] = eeg_load_scan4_cnt_data(fid,varargin)

DESCRIPTION ^

 eeg_load_scan4_cnt_data - Read Neuroscan 4.x Continuous EEG Data
 
 [data,srate,numSamples,labels,events] = eeg_load_scan4_cnt_data(fid,channels,range)
 
   ------------- IN ------------------------------------------------------------                      
   fid                     ->  file identifier
   channels (optional)     ->  vector of channel numbers to load or string 'all'.
                               [default = 'all']                   
   range (optional)        ->  2-element vector containing start and stop points
                               (inclusive) or string 'all' [default = 'all']

   ------------- OUT ------------------------------------------------------------
   data                    <-  matrix of electrodes in columns 
                               (ascending order, no repeats)
   srate (optional)        <-  sample rate of data
   numSamples (optional)   <-  total samples in CNT file
   labels (optional)       <-  cell array of channel labels
   events (optional)       <-  matrix of event info:
                                   column 1 = event stim type
                                   column 2 = offset in points

   Note: Works only with Scan 4.1+ data files

   See also: eeg_load_scan4_cnt_event

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [data,srate,numSamples,labels,events] = eeg_load_scan4_cnt_data(fid,varargin)
0002 
0003 % eeg_load_scan4_cnt_data - Read Neuroscan 4.x Continuous EEG Data
0004 %
0005 % [data,srate,numSamples,labels,events] = eeg_load_scan4_cnt_data(fid,channels,range)
0006 %
0007 %   ------------- IN ------------------------------------------------------------
0008 %   fid                     ->  file identifier
0009 %   channels (optional)     ->  vector of channel numbers to load or string 'all'.
0010 %                               [default = 'all']
0011 %   range (optional)        ->  2-element vector containing start and stop points
0012 %                               (inclusive) or string 'all' [default = 'all']
0013 %
0014 %   ------------- OUT ------------------------------------------------------------
0015 %   data                    <-  matrix of electrodes in columns
0016 %                               (ascending order, no repeats)
0017 %   srate (optional)        <-  sample rate of data
0018 %   numSamples (optional)   <-  total samples in CNT file
0019 %   labels (optional)       <-  cell array of channel labels
0020 %   events (optional)       <-  matrix of event info:
0021 %                                   column 1 = event stim type
0022 %                                   column 2 = offset in points
0023 %
0024 %   Note: Works only with Scan 4.1+ data files
0025 %
0026 %   See also: eeg_load_scan4_cnt_event
0027 %
0028 
0029 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0030 
0031 % Licence:  GNU GPL, no express or implied warranties
0032 % History:  2002, Sean.Fitzgibbon@flinders.edu.au
0033 %           06/2002, Darren.Weber_at_radiology.ucsf.edu
0034 %                    adapted to eeg_toolbox
0035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0036 
0037 
0038 
0039 % --------------- Load Parameters -----------------------------
0040 fseek(fid,370,'bof');
0041 numChan = fread(fid,1,'ushort');
0042 
0043 fseek(fid,376,'bof');
0044 srate = fread(fid,1,'ushort');
0045 
0046 fseek(fid,886,'bof');
0047 eventPos = fread(fid,1,'long');
0048 
0049 dataPos = 900+(75*numChan);
0050 numSamples = ((eventPos - dataPos)/numChan)/2;
0051 
0052 fseek(fid,900,'bof');
0053 labels = cellstr(deblank(char(fread(fid,[10,numChan],'10*char',75-10)')));
0054 
0055 fseek(fid,947,'bof');
0056 baseline = fread(fid,numChan,'short',75-2)';
0057 
0058 fseek(fid,959,'bof');
0059 sensitivity = fread(fid,numChan,'float',75-4)';
0060 
0061 fseek(fid,971,'bof');
0062 calibration = fread(fid,numChan,'float',75-4)';
0063 
0064 % --------------- Set Channels & Ranges -----------------
0065 
0066 if (nargin == 1)
0067     channels = 'all';
0068     range = 'all';
0069 elseif (nargin == 2)
0070     channels = varargin{1};
0071     range = 'all';
0072 elseif  (nargin == 3)
0073     channels = varargin{1};
0074     range = varargin{2};
0075 end
0076 
0077 if isa(range,'char') & (range == 'all')
0078     start = 0;
0079     numPoints = numSamples;
0080     range = [1 numSamples];
0081 else
0082     start = (range(1)-1)*numChan*2;
0083     numPoints = range(2)-range(1)+1;
0084 end
0085 
0086 
0087 
0088 
0089 
0090 % Must check than range is within numSamples!
0091 
0092 
0093 
0094 
0095 
0096 
0097 if isa(channels,'char') & (channels == 'all')
0098     channels = [1:numChan];
0099 else
0100     channels = sort(channels);
0101     index = [];
0102     for i = 1:length(channels)-1
0103         if (channels(i) == channels(i+1))
0104             index = [index i+1];
0105         end
0106     end
0107     channels(index) = [];
0108 end
0109 
0110 
0111 % --------------- Read Events ---------------------------
0112 
0113 
0114 fseek(fid,eventPos+1,'bof');
0115 eventSize   = fread(fid,1,'long');
0116 eventOffset = fread(fid,1,'long');
0117 
0118 fseek(fid,eventPos + 9 + eventOffset,'bof');
0119 stimType = fread(fid,eventSize/19,'short',19-2);
0120 
0121 fseek(fid,eventPos + 9 + eventOffset + 4,'bof');
0122 stimOffset = fread(fid,eventSize/19,'long',19-4);
0123 
0124 stimOffset = stimOffset - (900 + (75 * numChan));
0125 stimOffset = stimOffset ./ (2 * numChan);
0126 
0127 events = [stimType stimOffset];
0128 
0129 
0130 % --------------- Read Data -----------------------------
0131 
0132 if (length(channels) < numChan)
0133     data = zeros(numPoints,length(channels));
0134     for i = 1:length(channels)
0135         fseek(fid,dataPos+start,'bof');
0136         fseek(fid,(channels(i)-1)*2,'cof');
0137         data(:,i) = fread(fid,numPoints,'short',(numChan-1)*2);
0138     end
0139 elseif (length(channels) == numChan)
0140     fseek(fid,dataPos+start,'bof');
0141     data = zeros(numChan,numPoints);
0142     data = fread(fid,[numChan,numPoints],'short');
0143     data = data';
0144 end
0145 
0146 
0147 % --------------- scale to microvolts -----------------------------
0148 
0149 scaleFactor = ((sensitivity .* calibration)./204.8);
0150 scaleFactor = scaleFactor(ones(size(data,1),1),channels);
0151 
0152 baseline = baseline(ones(size(data,1),1),channels);
0153 
0154 data = (data - baseline) .* scaleFactor;
0155 
0156 frewind(fid);
0157 
0158 return

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