Home > vbmeg > functions > estimation > bayes > vb_get_megdata.m

vb_get_megdata

PURPOSE ^

Get megdata for VB estimate;

SYNOPSIS ^

function [B,Ntrial,Nsensor,Tsample,Tmsec]= vb_get_megdata(megfile,twin_meg,temporal_filter,trial_average,ix_trial)

DESCRIPTION ^

 Get megdata for VB estimate;

 [B, Ntrial, Nsensor, Tsample] = vb_get_megdata(megfile, twin_meg,
 temporal_filter, trial_average)

 B{Nsession}   : MEG data concatenating all sessions
                 Sensor number/position for each session may be different
               : B{Nsession}(Nsensor, Tsample, Ntrial)

 Tsample : Total time sample of each trial for the analysis
 Ntrial  : # of trials in each session
 Nsensor : # of MEG sensors in each session 

 [history]
 2004-11-16 Taku Yoshioka
 Modified by M.Sato 2004/12/22
 rearranged by O. Yamashita
 2008-10-14 Taku Yoshioka
 2008-11-28 Taku Yoshioka
   Use vb_disp() for displaying message
 2011-05-11 taku-y
  [minor] New output variable 'Tmsec' was added. This is a vector of
  actual time of row of B{n}. 
 2012-01-27 taku-y
  [minor] Messages have been modified.

 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 [B,Ntrial,Nsensor,Tsample,Tmsec] ...
0002     = vb_get_megdata(megfile,twin_meg,temporal_filter,trial_average,ix_trial)
0003 % Get megdata for VB estimate;
0004 %
0005 % [B, Ntrial, Nsensor, Tsample] = vb_get_megdata(megfile, twin_meg,
0006 % temporal_filter, trial_average)
0007 %
0008 % B{Nsession}   : MEG data concatenating all sessions
0009 %                 Sensor number/position for each session may be different
0010 %               : B{Nsession}(Nsensor, Tsample, Ntrial)
0011 %
0012 % Tsample : Total time sample of each trial for the analysis
0013 % Ntrial  : # of trials in each session
0014 % Nsensor : # of MEG sensors in each session
0015 %
0016 % [history]
0017 % 2004-11-16 Taku Yoshioka
0018 % Modified by M.Sato 2004/12/22
0019 % rearranged by O. Yamashita
0020 % 2008-10-14 Taku Yoshioka
0021 % 2008-11-28 Taku Yoshioka
0022 %   Use vb_disp() for displaying message
0023 % 2011-05-11 taku-y
0024 %  [minor] New output variable 'Tmsec' was added. This is a vector of
0025 %  actual time of row of B{n}.
0026 % 2012-01-27 taku-y
0027 %  [minor] Messages have been modified.
0028 %
0029 % Copyright (C) 2011, ATR All Rights Reserved.
0030 % License : New BSD License(see VBMEG_LICENSE.txt)
0031 
0032 const = vb_define_verbose;
0033 VERBOSE_LEVEL_NOTICE = const.VERBOSE_LEVEL_NOTICE;
0034 VERBOSE_LEVEL_EMERGENCY = const.VERBOSE_LEVEL_EMERGENCY;
0035 
0036 if nargin<5, ix_trial = []; end
0037 if nargin<4 | isempty(trial_average), trial_average = false; end
0038 if nargin<3 | isempty(temporal_filter), temporal_filter = false; end
0039 
0040 % MEG data file names given as a cell array
0041 if iscell(megfile),
0042   Nfile = length(megfile);
0043 else
0044   tmp = megfile;
0045   megfile = {tmp};
0046   Nfile = 1;
0047 end
0048 
0049 MEGinfo = vb_load_meg_info(megfile{1});
0050 Tstart = vb_index_to_time(twin_meg(1), MEGinfo);
0051 Tend   = vb_index_to_time(twin_meg(2), MEGinfo);
0052 vb_disp(['  Number of sessions          : ' num2str(Nfile)], ...
0053         VERBOSE_LEVEL_NOTICE);
0054 vb_disp(['  Time window                 : ' num2str(Tstart,'%4.1f') ...
0055          ' - ' num2str(Tend,'%4.1f') ' [ms]'],VERBOSE_LEVEL_NOTICE);
0056 
0057 % Time window for analysis
0058 Tfilt    = twin_meg(1):twin_meg(2);
0059 % Total sample for each trial
0060 Tsample = twin_meg(2) - twin_meg(1) + 1;
0061 
0062 B       = cell(Nfile,1); % MEG data
0063 Ntrial  = zeros(Nfile,1);
0064 Nsensor = zeros(Nfile,1);
0065 
0066 for n = 1:Nfile
0067   % Load MEG data
0068   bexp = vb_load_meg_data(megfile{n});
0069   %  load(megfile{n},'bexp');
0070   if ~isempty(ix_trial), bexp = bexp(:,:,ix_trial); end
0071   
0072   % MEG trial averaging
0073   if trial_average, 
0074     bexp = mean(bexp,3); 
0075   end
0076   
0077   % Variable preparation
0078   Ntrial(n)  = size(bexp,3);
0079   Ndata      = size(bexp,2);
0080   Nsensor(n) = size(bexp,1);
0081   
0082   if Ndata < twin_meg(2), 
0083     vb_disp(['Error: Load MEG file ' megfile{n}], ...
0084             VERBOSE_LEVEL_EMERGENCY);
0085     error(['# of sample is smaller than given period' ])
0086   end
0087 
0088   vb_disp(sprintf('  MEG data file (session %2d)  : %s',n,megfile{n}), ...
0089           VERBOSE_LEVEL_NOTICE);
0090   vb_disp(['  Number of sensors           : ' num2str(Nsensor(n))], ...
0091           VERBOSE_LEVEL_NOTICE);
0092   vb_disp(['  Number of trials            : ' num2str(Ntrial(n))], ...
0093           VERBOSE_LEVEL_NOTICE);
0094 
0095   % MEG data
0096   Bn = bexp(:,Tfilt,:);
0097 
0098   % MEG temporal smoothing
0099   if temporal_filter
0100     for s = 1:Ntrial(n)
0101       Bn(:,:,s) = vb_temporal_smooth( Bn(:,:,s) );
0102     end
0103   end
0104 
0105   B{n} = Bn;
0106 end
0107 
0108 % actual time (all sessions assumed to have the same length, pretrigger)
0109 MEGinfo = vb_load_meg_info(megfile{1});
0110 Tmsec   = vb_index_to_time(Tfilt, MEGinfo);
0111 
0112 return;

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