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

read_sbi_meg_header

PURPOSE ^

Input: meg_dir % $MEG_DIR ex. /data1/toyama2/

SYNOPSIS ^

function [meg_info, pick1, pick2 ] = read_sbi_meg_header(meg_dir,sysid)

DESCRIPTION ^

 Input: meg_dir  % $MEG_DIR  ex. /data1/toyama2/
        sysid   % System ID  ex. 1000987
 Output: 
 meg_info : structure with following field
    .nch,       % number of active gardiometers
    .nch0          % number of gardiometers
    .nsamp,     % sampling number of measurement
    .nprsamp,   % sampling number for pre-trigger
    .sampf,     % sampling frequency
    .nrept,     % repeat number
    .active_ch  % Active channel index
    .ch_name    % Active channel name
    .ch_name0   % All channel name
    .ad_factor  % AD multiplicative factor to convert MEG data to [T]

 pick1(ch,:)         % position and direction of detection coils
                           on DICOM cord.  [m],[normal unit vector]
 pick2(ch,:)         % position and direction of compensation coils
                           on DICOM cord.  [m],[normal unit vector]

 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 [meg_info, pick1, pick2 ] = read_sbi_meg_header(meg_dir,sysid)
0002 % Input: meg_dir  % $MEG_DIR  ex. /data1/toyama2/
0003 %        sysid   % System ID  ex. 1000987
0004 % Output:
0005 % meg_info : structure with following field
0006 %    .nch,       % number of active gardiometers
0007 %    .nch0          % number of gardiometers
0008 %    .nsamp,     % sampling number of measurement
0009 %    .nprsamp,   % sampling number for pre-trigger
0010 %    .sampf,     % sampling frequency
0011 %    .nrept,     % repeat number
0012 %    .active_ch  % Active channel index
0013 %    .ch_name    % Active channel name
0014 %    .ch_name0   % All channel name
0015 %    .ad_factor  % AD multiplicative factor to convert MEG data to [T]
0016 %
0017 % pick1(ch,:)         % position and direction of detection coils
0018 %                           on DICOM cord.  [m],[normal unit vector]
0019 % pick2(ch,:)         % position and direction of compensation coils
0020 %                           on DICOM cord.  [m],[normal unit vector]
0021 %
0022 % Copyright (C) 2011, ATR All Rights Reserved.
0023 % License : New BSD License(see VBMEG_LICENSE.txt)
0024 
0025 % 2005-12-22 M. Sato
0026 
0027 global vbmeg_inst; 
0028 define = vbmeg_inst.const; 
0029 
0030 % MEGディレクトリからheaderディレクトリへの相対path
0031 head_dir = '../head/';    
0032 
0033 %
0034 % --- read SBI header
0035 %
0036 fname = sprintf('%s%s%s%s',meg_dir,head_dir,sysid,define.HEADER_EXTENSION);
0037 fid   = fopen(fname ,'r','l');
0038 if fid==-1, disp('XXX Error : Cannot open head file !!\n'); return; end
0039 
0040 % file info.
0041 H_file  = meg_hread('file',fid);
0042 
0043 % MEG data dimension
0044 H_meg   = meg_hread('meg',fid, H_file.i_meg_begin);
0045 nch0    = H_meg.i_nch;
0046 nsamp   = H_meg.i_nsample;      % sampling number of measurement
0047 nprsamp = H_meg.i_nprsample;      % sampling number for pre-trigger
0048 sampf   = H_meg.i_samp_freq;      % sampling frequency
0049 nrept   = H_meg.i_nwave;          % repeat number
0050 vbit    = H_meg.f_ad_weight;    % AD変換器1bitの重み[V/digit]
0051 
0052 % Sensor variable
0053 kind0  = zeros(nch0,1); 
0054 lock0  = zeros(nch0,1); 
0055 amp0   = zeros(nch0,1); 
0056 sens0  = zeros(nch0,1);
0057 
0058 chname0= cell(nch0,1);
0059 
0060 pick10 = zeros(nch0,6); 
0061 pick20 = zeros(nch0,6); 
0062 
0063 % Sensor position
0064 for i=1:nch0
0065     H_meg_ch = meg_hread('meg_ch',fid,...
0066                   H_file.i_meg_ch_begin + H_file.i_meg_ch_size*(i-1));
0067                   
0068     kind0(i) = H_meg_ch.i_pick_type;     % ピックアップコイルタイプ
0069     lock0(i) = H_meg_ch.i_meg_lock;        % MEG計測時のSQUIDロック状態
0070     amp0(i)  = H_meg_ch.f_amp_gain;     % 増幅器増幅度
0071     sens0(i) = H_meg_ch.f_phy_v_coef;    % 磁束−電圧変換係数[T/V]
0072     chname0{i} = H_meg_ch.c_ch_name;
0073     
0074     % sensor position
0075     pick10(i,1:3) = (H_meg_ch.st_dcp)'; 
0076     pick10(i,4:6) = (H_meg_ch.st_dca)';
0077     pick20(i,1:3) = (H_meg_ch.st_ccp)'; 
0078     pick20(i,4:6) = (H_meg_ch.st_cca)';
0079 end
0080 
0081 fclose(fid); 
0082 
0083 clear H_file H_meg
0084 
0085 %
0086 % ---  select active coils and data
0087 %
0088 %    kind0     ; ピックアップコイルタイプ
0089 %               0:マグネトメータ 1:グラジオメータ
0090 %    lock0    ; MEG計測時のSQUIDロック状態
0091 %               0:ロック 1:リセット 2:エラー
0092 
0093 % Index for active gardiometers
0094 okix=find(kind0==1 & lock0==0);
0095 % number of active gardiometers
0096 nch=length(okix);  
0097 
0098 % position and direction of detection coils on DEWAR cord. ([m],[rad,])
0099 pick1=pick10(okix,:);  
0100 % position and direction of compensation coils on DEWAR cord. ([m],[rad,])
0101 pick2=pick20(okix,:);  
0102 
0103 % AD multiplicative factor to convert MEG data to [T]
0104 % bexp = bexp0 .* (sens0) * vbit ./(amp0);
0105 amp  = vbit*sens0(okix)./amp0(okix);
0106 
0107 chname = cell(1,nch);
0108 
0109 for i=1:nch
0110     chname{i}=chname0{okix(i)};
0111 end
0112 
0113 meg_info = struct( ...
0114     'nch',nch, ...          % number of active gardiometers
0115     'nch0',nch0, ...          % number of gardiometers
0116     'nsamp',nsamp, ...      % sampling number of measurement
0117     'nprsamp',nprsamp, ...  % sampling number for pre-trigger
0118     'sampf',sampf, ...      % sampling frequency
0119     'nrept',nrept);         % repeat number
0120 
0121 meg_info.active_ch = okix;        % Active channel index
0122 meg_info.ch_name   = chname;    % Active channel name
0123 meg_info.ch_name0  = chname0;    % All channel name
0124 meg_info.ad_factor = amp;        % AD factor to convert MEG data to [T]

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