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