0001 function [B,Ntrial,Nsensor,Tsample,Tmsec] ...
0002 = vb_get_megdata(megfile,twin_meg,temporal_filter,trial_average,ix_trial)
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
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
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
0058 Tfilt = twin_meg(1):twin_meg(2);
0059
0060 Tsample = twin_meg(2) - twin_meg(1) + 1;
0061
0062 B = cell(Nfile,1);
0063 Ntrial = zeros(Nfile,1);
0064 Nsensor = zeros(Nfile,1);
0065
0066 for n = 1:Nfile
0067
0068 bexp = vb_load_meg_data(megfile{n});
0069
0070 if ~isempty(ix_trial), bexp = bexp(:,:,ix_trial); end
0071
0072
0073 if trial_average,
0074 bexp = mean(bexp,3);
0075 end
0076
0077
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
0096 Bn = bexp(:,Tfilt,:);
0097
0098
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
0109 MEGinfo = vb_load_meg_info(megfile{1});
0110 Tmsec = vb_index_to_time(Tfilt, MEGinfo);
0111
0112 return;