Home > vbmeg > functions > device > active_check > vb_load_active_trial_data.m

vb_load_active_trial_data

PURPOSE ^

load meg/eeg data from multiple files and concatenate them

SYNOPSIS ^

function [data, channel_info, cond_id] = vb_load_active_trial_data(fileinfo)

DESCRIPTION ^

 load meg/eeg data from multiple files and concatenate them
 [Usage]
   [data, channel_info, cond_id] = vb_load_active_trial_data(fileinfo)

 [Input]
 fileinfo : structure with file information for multiple files
 fileinfo.filename{n}  : n-th session data file names [n=1:Nsession]
 fileinfo.Nchannel     : # of total channels
 fileinfo.Nsample      : # of samples in one trial
 fileinfo.Ntotal       : # of all trials 
 fileinfo.Ntrial       : # of trials for each session [1 x Nsession]
 fileinfo.session_id   : session index for each trial [1 x Ntotal]
 fileinfo.cond_id      : condition number for each trials [1 x Ntotal]
 fileinfo.ActiveChannel: Active channel list (boolean array) [Nchannel x 1]
 fileinfo.ActiveTrial  : Active trial list   (boolean array) [Ntotal x 1]

 [Output]
         data : concatenated data data [Nch x Nsample x Nactive]
 channel_info : <<struct>> channel information of loaded data
              :  .Active [Nchannel x 1]
              :  .Name   [Nchannel x 1]
              :  .Type   [Nchannel x 1]
              :  .ID     [Nchannel x 1]
      cond_id : condition number for each trials [1 x Nactive]

 Masa-aki Sato 2009-8-4
   2010-11-15 (Sako) modified loading data of each file MEG --> ALL
   2011-03-01 (Sako) supported empty channel_id (return empty data)
   2011-08-26 (Sako) modified for minimum format file
   2018-08-22 (Takeda) Neuromag is supported
   2022-06-03 (k_suzuki) QZFM is supported
   2022-06-03 (k_suzuki) To load multi-run from .info.mat with specified ActiveTrial, loadspec.ActiveTrial is set to false (line 107)

 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 [data, channel_info, cond_id] = vb_load_active_trial_data(fileinfo)
0002 % load meg/eeg data from multiple files and concatenate them
0003 % [Usage]
0004 %   [data, channel_info, cond_id] = vb_load_active_trial_data(fileinfo)
0005 %
0006 % [Input]
0007 % fileinfo : structure with file information for multiple files
0008 % fileinfo.filename{n}  : n-th session data file names [n=1:Nsession]
0009 % fileinfo.Nchannel     : # of total channels
0010 % fileinfo.Nsample      : # of samples in one trial
0011 % fileinfo.Ntotal       : # of all trials
0012 % fileinfo.Ntrial       : # of trials for each session [1 x Nsession]
0013 % fileinfo.session_id   : session index for each trial [1 x Ntotal]
0014 % fileinfo.cond_id      : condition number for each trials [1 x Ntotal]
0015 % fileinfo.ActiveChannel: Active channel list (boolean array) [Nchannel x 1]
0016 % fileinfo.ActiveTrial  : Active trial list   (boolean array) [Ntotal x 1]
0017 %
0018 % [Output]
0019 %         data : concatenated data data [Nch x Nsample x Nactive]
0020 % channel_info : <<struct>> channel information of loaded data
0021 %              :  .Active [Nchannel x 1]
0022 %              :  .Name   [Nchannel x 1]
0023 %              :  .Type   [Nchannel x 1]
0024 %              :  .ID     [Nchannel x 1]
0025 %      cond_id : condition number for each trials [1 x Nactive]
0026 %
0027 % Masa-aki Sato 2009-8-4
0028 %   2010-11-15 (Sako) modified loading data of each file MEG --> ALL
0029 %   2011-03-01 (Sako) supported empty channel_id (return empty data)
0030 %   2011-08-26 (Sako) modified for minimum format file
0031 %   2018-08-22 (Takeda) Neuromag is supported
0032 %   2022-06-03 (k_suzuki) QZFM is supported
0033 %   2022-06-03 (k_suzuki) To load multi-run from .info.mat with specified ActiveTrial, loadspec.ActiveTrial is set to false (line 107)
0034 %
0035 % Copyright (C) 2011, ATR All Rights Reserved.
0036 % License : New BSD License(see VBMEG_LICENSE.txt)
0037 
0038 filename  = fileinfo.filename  ;
0039 
0040 Nsample  = fileinfo.Nsample;
0041 Nchannel = fileinfo.Nchannel;
0042 Ntotal   = fileinfo.Ntotal;
0043 
0044 % Number of files
0045 Nfile = length(filename);
0046 
0047 % active channel & trials
0048 if isfield(fileinfo, 'act_trial')
0049     act_trial = fileinfo.act_trial;
0050 elseif isfield(fileinfo, 'ActiveTrial');
0051     act_trial = find(fileinfo.ActiveTrial ~= 0);
0052 end
0053 
0054 if isfield(fileinfo, 'channel_id');
0055     channel_id = fileinfo.channel_id;
0056 elseif isfield(fileinfo, 'ActiveChannel')
0057     ch_info = vb_load_channel_info(filename{1});
0058     channel_id = ch_info.ID(fileinfo.ActiveChannel ~= 0);
0059 end
0060 
0061 if isempty(channel_id)
0062   warning('(%s) channel_id is empty\n', mfilename);
0063   data = [];
0064   channel_info = [];
0065   cond_id = [];
0066   return;
0067 end
0068 
0069 % --- get the name list of target channel
0070 ch_info = vb_load_channel_info(filename{1}, 'USER', channel_id);
0071 ch_names = ch_info.Name;
0072 
0073 % Number of active channel & trials
0074 Nch  = length(channel_id);
0075 Nall = length(act_trial);
0076 
0077 fprintf('Number of files to read: %d\n',Nfile)
0078 fprintf('Number of all trials: %d\n',Ntotal)
0079 fprintf('Number of all channels: %d\n',Nchannel)
0080 fprintf('Number of trials to read: %d\n',Nall)
0081 fprintf('Number of channels to read: %d\n',Nch)
0082 
0083 data = zeros(Nch,Nsample,Ntotal);
0084 Nst = 0;
0085 
0086 channel_info = [];
0087 
0088 % Merge multiple data files
0089 for n=1:Nfile
0090   [measurement, device] = vb_load_device(filename{n});
0091 
0092   Measurement = upper(measurement);
0093   Device      = upper(device);
0094 
0095   % Load MEG/EEG data
0096   if (strcmp(Measurement, 'MEG') ...
0097     && (~strcmp(Device, 'YOKOGAWA') && ~strcmp(Device, 'BASIC') && ~strcmp(Device, 'NEUROMAG') && ~strcmp(Device, 'QZFM')))...
0098     || (strcmp(Measurement, 'EEG') ...
0099       && (~strcmp(Device, 'BIOSEMI') && ~strcmp(Device, 'BRAINAMP') ...
0100       && ~strcmp(Device, 'BASIC')))
0101       [tmp_data] = vb_load_meg_data(filename{n});
0102 
0103   else
0104     
0105     loadspec.ChannelName = ch_names;
0106     loadspec.ActiveChannel = false;
0107     loadspec.ActiveTrial   = false;
0108     
0109     if n == 1
0110       % one channel_info is enough
0111         [tmp_data, channel_info] = vb_load_meg_data(filename{n}, loadspec);
0112     else
0113         [tmp_data] = vb_load_meg_data(filename{n}, loadspec);
0114     end
0115   end
0116   
0117   Nc = size(tmp_data,1);
0118   Nt = size(tmp_data,3);
0119   ix = (1:Nt) + Nst; % consecutive index for concatenated data
0120     
0121      data(:,:,ix)  = tmp_data(:,:,:);
0122     
0123   Nst = Nt + Nst;
0124 end
0125 
0126 data = data(:,:,act_trial);
0127 return
0128

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