0001 function [data,srate,numSamples,labels,events] = eeg_load_scan4_cnt_data(fid,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
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
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
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
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
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
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