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

read_sbi_meg_data

PURPOSE ^

--- Input

SYNOPSIS ^

function [bexp] = read_sbi_meg_data(meg_dir, meg_id, meg_info, param)

DESCRIPTION ^

 --- Input
 meg_dir  : MEG data dir
 meg_id   : MEG system ID
 meg_info : MEG header info
 --- Optional Input
 param.time_win = [Tstart Tend]: [ms]
 param.trials   = trial index to extract
 --- Output
 bexp(Nchannel, Tsample, Nrepeat)  % measured fields  [T]

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

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