0001 function eeg = read_sbi_eeg_data(sys_dir, sys_id, eeg_info, param)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 Nchannel = eeg_info.nch ;
0016 Nsample = eeg_info.nsamp;
0017 Nrepeat = eeg_info.nrept;
0018 SampleFreq = eeg_info.sampf;
0019
0020 if exist('param','var')&& isfield(param,'time_win')&& ~isempty(param.time_win)
0021 Tstart = fix(param.time_win(1)*SampleFreq*0.001)+1;
0022 Tend = fix(param.time_win(2)*SampleFreq*0.001)+1;
0023 Tstart = max(Tstart,1);
0024 Tend = min(Tend,Nsample);
0025 else
0026 Tstart = 1;
0027 Tend = Nsample;
0028 end
0029
0030 Nbyte = 2;
0031
0032 Tsample = Tend - Tstart + 1;
0033 Nblock = Nchannel*Tsample;
0034 Nskip = Nchannel*Nsample*Nbyte;
0035 start_id = ( Nchannel*(Tstart-1) )*Nbyte;
0036
0037
0038
0039
0040 fname = sprintf('%seeg/%s.eeg',sys_dir,sys_id);
0041 fid = fopen(fname, 'r','l');
0042
0043 if fid==-1, disp('XXX Error : Cannot open EEG file !!\n'); return; end
0044
0045
0046
0047 eeg = zeros(Nblock,Nrepeat);
0048
0049 for n=1:Nrepeat
0050 fseek(fid, start_id ,'bof');
0051 eeg(:,n) = fread(fid, Nblock, 'short');
0052 start_id = start_id + Nskip;
0053 end
0054
0055 fclose(fid);
0056
0057 eeg = reshape(eeg, [Nchannel Tsample Nrepeat]);
0058
0059
0060 if exist('param','var') && isfield(param,'trials') && ~isempty(param.trials)
0061 eeg = eeg(:,:, param.trials);
0062 end
0063