Home > vbmeg > functions > device > eeg > vb_eegfile_make_channel_info.m

vb_eegfile_make_channel_info

PURPOSE ^

make ChannelInfo from channel label

SYNOPSIS ^

function channel_info = vb_eegfile_make_channel_info(eegfile, ch_labels, ch_type)

DESCRIPTION ^

 make ChannelInfo from channel label
 [usage]
   channel_info = vb_eegfile_make_channel_info(eegfile, ch_labels, ch_type)
 [input]
        eegfile : <required> <<file>> EEG-MAT file
      ch_labels : <optional> specified channel label list {Nchannel x 1}
        ch_type : <optional> [0] | 1 channel type of channel_info
                :  0) all (sensor channels and external channel(s)
                :  1) only sensor channels
                :  2) only external channel(s)
 [output]
   channel_info : <<struct>>
                :  .Active [Nchannel x 1]
                :  .Name   {Nchannel x 1}
                :  .Type   [Nchannel x 1]
                :  .ID     [Nchannel x 1]
                : - Nchannel = Nchannel_eeg + Nchannel_ext
 [note]
   for now, main channels and extra channels are managed separately
 [history]
   2008-06-06 (Sako) initial version
   2009-07-16 (Sako) added ch_type as the argument

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function channel_info = vb_eegfile_make_channel_info(eegfile, ch_labels, ch_type)
0002 % make ChannelInfo from channel label
0003 % [usage]
0004 %   channel_info = vb_eegfile_make_channel_info(eegfile, ch_labels, ch_type)
0005 % [input]
0006 %        eegfile : <required> <<file>> EEG-MAT file
0007 %      ch_labels : <optional> specified channel label list {Nchannel x 1}
0008 %        ch_type : <optional> [0] | 1 channel type of channel_info
0009 %                :  0) all (sensor channels and external channel(s)
0010 %                :  1) only sensor channels
0011 %                :  2) only external channel(s)
0012 % [output]
0013 %   channel_info : <<struct>>
0014 %                :  .Active [Nchannel x 1]
0015 %                :  .Name   {Nchannel x 1}
0016 %                :  .Type   [Nchannel x 1]
0017 %                :  .ID     [Nchannel x 1]
0018 %                : - Nchannel = Nchannel_eeg + Nchannel_ext
0019 % [note]
0020 %   for now, main channels and extra channels are managed separately
0021 % [history]
0022 %   2008-06-06 (Sako) initial version
0023 %   2009-07-16 (Sako) added ch_type as the argument
0024 %
0025 % Copyright (C) 2011, ATR All Rights Reserved.
0026 % License : New BSD License(see VBMEG_LICENSE.txt)
0027 
0028 % --- CHECK ARGUMENTS --- %
0029 if ~exist('eegfile', 'var'), eegfile = ''; end
0030 if ~exist('ch_labels', 'var'), ch_labels = []; end
0031 if ~exist('ch_type', 'var'), ch_type = []; end
0032 [eegfile, ch_labels, ch_type] = ...
0033   inner_check_arguments(eegfile, ch_labels, ch_type);
0034 
0035 % --- MAIN PROCEDURE --------------------------------------------------------- %
0036 %
0037 eeginfo = vb_eegfile_load_eeginfo(eegfile);
0038 org_eeg_label = vb_eeginfo_get_channel_label(eeginfo);
0039 org_ext_label = vb_eeginfo_get_channel_label_extra(eeginfo, false);
0040 
0041 % ----- EEG CHANNELS
0042 target_eeg_labels = [];
0043 if ch_type ~= 2 && ~isempty(org_eeg_label) && ~isempty(ch_labels)
0044   [eeg_idx] = vb_util_get_index(org_eeg_label, ch_labels);
0045   if ~isempty(eeg_idx)
0046     target_eeg_labels = org_eeg_label(eeg_idx);
0047   end
0048 else
0049   eeg_idx = [];
0050 end
0051 
0052 % ----- EXTRA CHANNELS
0053 target_ext_labels = [];
0054 if ch_type ~= 1 && ~isempty(org_ext_label) && ~isempty(ch_labels)
0055   [ext_idx] = vb_util_get_index(org_ext_label, ch_labels);
0056   if ~isempty(ext_idx)
0057     target_ext_labels = org_ext_label(ext_idx);
0058   end
0059 else
0060   ext_idx = [];
0061 end
0062 
0063 extra_info = eeginfo.ExtraChannelInfo;
0064 
0065 % ----- Active
0066 if vb_info_active_channel_is_valid(eeginfo)
0067   active_ch = vb_info_get_active_channel(eeginfo);
0068   eeg_active = active_ch(eeg_idx);
0069   
0070   if ~isempty(extra_info.Channel_active)
0071     ext_active = extra_info.Channel_active(ext_idx);
0072   else
0073     % temporary
0074     Nch = length(ext_idx);
0075     ext_active = ones(Nch,1);
0076   end
0077   channel_info.Active = [eeg_active;ext_active];
0078 else
0079   Nch = length(target_eeg_labels)+length(target_ext_labels);
0080   channel_info.Active = ones(Nch,1);
0081 end
0082 
0083 % ----- Name
0084 channel_info.Name = [target_eeg_labels;target_ext_labels];
0085 
0086 % ----- Type
0087 % ----- all types are set '1' for now
0088 len_eeg_ch = length(target_eeg_labels);
0089 eeg_type = ones(len_eeg_ch, 1);
0090 
0091 if ~isempty(extra_info.Channel_type)
0092   ext_type = extra_info.Channel_type(ext_idx);
0093 else
0094 %   Nch = length(ext_idx);
0095 %   ext_type = ones(Nch,1);
0096   % ----- undefined yet
0097   ext_type = [];
0098 end
0099 channel_info.Type = [eeg_type;ext_type];
0100 
0101 % ----- ID
0102 ext_idx = extra_info.Channel_id(ext_idx);
0103 channel_info.ID = [eeg_idx;ext_idx];
0104 return;
0105 %
0106 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0107 
0108 % --- INNER FUNCTIONS -------------------------------------------------------- %
0109 %
0110 % --- inner_check_arguments()
0111 %
0112 % function [eegfile, eeg_labels, ext_labels, ref_labels] = ...
0113 %   inner_check_arguments(eegfile, eeg_labels, ext_labels, ref_labels)
0114 function [eegfile, ch_labels, ch_type] = ...
0115   inner_check_arguments(eegfile, ch_labels, ch_type)
0116 
0117 func_ = mfilename;
0118 if isempty(eegfile)
0119   error('(%s)eegfile is a required parameter', func_);
0120 end
0121 
0122 if exist(eegfile, 'file') ~= 2
0123   error('(%s)cannot find eegfile : %s', func_, eegfile);
0124 end
0125 
0126 if isempty(ch_type)
0127   ch_type = 0; % all channels
0128 end
0129 return;
0130 %
0131 % --- end of inner_check_arguments()
0132 %
0133 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0134 
0135 %%% END OF FILE %%%

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