Home > vbmeg > demo > test_scripts > sbi > read_sbi_eeg_data.m

read_sbi_eeg_data

PURPOSE ^

--- Input

SYNOPSIS ^

function eeg = read_sbi_eeg_data(sys_dir, sys_id, eeg_info, param)

DESCRIPTION ^

 --- Input
 sys_dir  : MEG data dir
 sys_id   : MEG system ID
 eeg_info : MEG header info
 --- Optional Input
 param.time_win = [Tstart Tend]: [ms]
 param.trials   = trial index to extract
 --- Output
 eeg(Nchannel, Tsample, Nrepeat)  % measured fields  [V]

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    eeg = read_sbi_eeg_data(sys_dir, sys_id, eeg_info, param)
0002 % --- Input
0003 % sys_dir  : MEG data dir
0004 % sys_id   : MEG system ID
0005 % eeg_info : MEG header info
0006 % --- Optional Input
0007 % param.time_win = [Tstart Tend]: [ms]
0008 % param.trials   = trial index to extract
0009 % --- Output
0010 % eeg(Nchannel, Tsample, Nrepeat)  % measured fields  [V]
0011 %
0012 % Copyright (C) 2011, ATR All Rights Reserved.
0013 % License : New BSD License(see VBMEG_LICENSE.txt)
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; % Start time index
0022     Tend    = fix(param.time_win(2)*SampleFreq*0.001)+1; % End time index
0023     Tstart  = max(Tstart,1);
0024     Tend    = min(Tend,Nsample);
0025 else
0026     Tstart  = 1;
0027     Tend    = Nsample;
0028 end
0029 
0030 Nbyte = 2; % length for one sample (short-integer: 2 byte)
0031 
0032 Tsample  = Tend - Tstart + 1;        % # of sample to read in given time window
0033 Nblock   = Nchannel*Tsample;        % # of sample to read in one trial
0034 Nskip    = Nchannel*Nsample*Nbyte;    % # of byte for one trial
0035 start_id = ( Nchannel*(Tstart-1) )*Nbyte;    % # of sample before start time
0036 
0037 %
0038 % --- read SBI data
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 % Read EEG data
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 % Select trial index
0060 if exist('param','var') && isfield(param,'trials') && ~isempty(param.trials)
0061     eeg = eeg(:,:, param.trials);
0062 end
0063

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005