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

vb_eeginfo_make_channel_info

PURPOSE ^

make ChannelInfo from channel label

SYNOPSIS ^

function channel_info = vb_eeginfo_make_channel_info(eeginfo, ch_labels, ch_type)

DESCRIPTION ^

 make ChannelInfo from channel label
 [usage]
   channel_info = vb_eeginfo_make_channel_info(eeginfo, ch_labels, ch_type)
 [input]
        eeginfo : <required> <<struct>> EEGinfo
                :  - This must have the next fields.
                :     .ChannelName
                :     .ChannelID
                :     .ActiveChannel
                :     .ExtraChannelInfo
      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]
   @see vb_megfile_make_channel_info.m
 [history]
   2009-07-16 (Sako) initial version

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

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