Concatenate MEG data sets. Data sets must have the same number of channels and be recorded with the same sampling frequency. --- Syntax vb_concat_megfile(concat_parm) --- Input concat_parm.megfile : New MEG data is saved with this file name. concat_parm.ix_info : Recording information (active flag, sensor position, etc.) of the new MEG data is set to that of (ix_info)-th MEG data. concat_parm.data{n} : Information of n-th MEG data. data{n}.megfile: .meg.mat file concatenated. data{n}.twin : Time window in sample number, not actual time. data{n}.trial : Sequence of trial numbers. --- Input (optional) concat_parm.pretrigger: Pretrigger period of the new MEG data --- Example The following is an example to concatenates MEG data of 1-40 trials in 'meg1.meg.mat' and 41-80 trials in 'meg2.meg.mat'. The concatenated MEG data has the recording information of 'meg2.meg.mat'. >> concat_parm.megfile = 'new_data.meg.mat'; >> concat_parm.ix_info = 2; >> concat_parm.Pretrigger = 300; >> concat_parm.data{1}.megfile = 'meg1.meg.mat'; >> concat_parm.data{1}.twin = [1 300]; >> concat_parm.data{1}.trial = 1:40; >> concat_parm.data{2}.megfile = 'meg2.meg.mat'; >> concat_parm.data{2}.twin = [1001 2000]; >> concat_parm.data{2}.trial = 41:80; >> vb_concat_megfile(concat_parm); --- History 2008-06-12 Taku Yoshioka 2008-06-27 Taku Yoshioka (pretrigger) 2009-09-01 (Sako) substituted vb_load_measurement_info for vb_load_meg_info Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function vb_concat_megfile(concat_parm) 0002 % Concatenate MEG data sets. 0003 % Data sets must have the same number of channels and be recorded with 0004 % the same sampling frequency. 0005 % 0006 % --- Syntax 0007 % vb_concat_megfile(concat_parm) 0008 % 0009 % --- Input 0010 % concat_parm.megfile : New MEG data is saved with this file name. 0011 % concat_parm.ix_info : Recording information (active flag, sensor 0012 % position, etc.) of the new MEG data is set to 0013 % that of (ix_info)-th MEG data. 0014 % concat_parm.data{n} : Information of n-th MEG data. 0015 % data{n}.megfile: .meg.mat file concatenated. 0016 % data{n}.twin : Time window in sample number, not actual time. 0017 % data{n}.trial : Sequence of trial numbers. 0018 % 0019 % --- Input (optional) 0020 % concat_parm.pretrigger: Pretrigger period of the new MEG data 0021 % 0022 % --- Example 0023 % The following is an example to concatenates MEG data of 1-40 trials in 0024 % 'meg1.meg.mat' and 41-80 trials in 'meg2.meg.mat'. The concatenated MEG 0025 % data has the recording information of 'meg2.meg.mat'. 0026 % 0027 % >> concat_parm.megfile = 'new_data.meg.mat'; 0028 % >> concat_parm.ix_info = 2; 0029 % >> concat_parm.Pretrigger = 300; 0030 % >> concat_parm.data{1}.megfile = 'meg1.meg.mat'; 0031 % >> concat_parm.data{1}.twin = [1 300]; 0032 % >> concat_parm.data{1}.trial = 1:40; 0033 % >> concat_parm.data{2}.megfile = 'meg2.meg.mat'; 0034 % >> concat_parm.data{2}.twin = [1001 2000]; 0035 % >> concat_parm.data{2}.trial = 41:80; 0036 % >> vb_concat_megfile(concat_parm); 0037 % 0038 % --- History 0039 % 2008-06-12 Taku Yoshioka 0040 % 2008-06-27 Taku Yoshioka (pretrigger) 0041 % 2009-09-01 (Sako) substituted vb_load_measurement_info for vb_load_meg_info 0042 % 0043 % Copyright (C) 2011, ATR All Rights Reserved. 0044 % License : New BSD License(see VBMEG_LICENSE.txt) 0045 0046 vb_struct2vars(concat_parm,{'data','ix_info','megfile'}); 0047 const = vb_define_const; 0048 0049 % Check consistency of data 0050 Ndata = length(data); 0051 MEGinfo = vb_load_measurement_info(data{1}.megfile); 0052 Nrepeat = length(data{1}.trial); 0053 Nchannel = MEGinfo.Nchannel; 0054 SampleFreq = MEGinfo.SampleFreq; 0055 0056 for i=2:length(concat_parm.data) 0057 if length(data{i}.trial)~=Nrepeat, 0058 error('Number of trials must be same.'); 0059 end 0060 0061 MEGinfo = vb_load_measurement_info(data{i}.megfile); 0062 if MEGinfo.SampleFreq~=SampleFreq, 0063 error('Sampling frequency must be same.'); 0064 end 0065 0066 if MEGinfo.Nchannel~=Nchannel, 0067 error('Channel number must be same.'); 0068 end 0069 end 0070 0071 % Sampling frame 0072 ixx = (data{1}.twin(1)):(data{1}.twin(2)); 0073 ix_sample0{1} = 1:length(ixx); 0074 ix_sample{1} = ix_sample0{1}; 0075 for i=2:Ndata 0076 ixx = (data{i}.twin(1)):(data{i}.twin(2)); 0077 ix_sample0{i} = 1:length(ixx); 0078 ix_sample{i} = ix_sample0{i}+ix_sample{i-1}(end); 0079 end 0080 0081 % Create concatenated data 0082 for i=1:Ndata 0083 load_spec = []; 0084 load_spec.TrialNumber = data{i}.trial; 0085 load_spec.ActiveChannel = false; 0086 load_spec.ActiveTrial = false; 0087 0088 % MEG channel 0089 load_spec.ChannelType = const.DATA_TYPE_MAIN; 0090 tmp = vb_load_meg_data(data{i}.megfile,load_spec); 0091 bexp(:,ix_sample{i},:) = tmp(:,ix_sample0{i},:); 0092 clear tmp; 0093 0094 % External channel 0095 load_spec.ChannelType = const.DATA_TYPE_EXTRA; 0096 tmp = vb_load_meg_data(data{i}.megfile,load_spec); 0097 bexp_ext(:,ix_sample{i},:) = tmp(:,ix_sample0{i},:); 0098 0099 % Reference channel 0100 load_spec.ChannelType = const.DATA_TYPE_REFERENCE; 0101 tmp = vb_load_meg_data(data{i}.megfile,load_spec); 0102 refmg(:,ix_sample{i},:) = tmp(:,ix_sample0{i},:); 0103 clear tmp; 0104 end 0105 0106 % Trial information 0107 for i=1:Nrepeat 0108 Trial(i).number = i; 0109 Trial(i).Sample = 1:size(bexp,2); 0110 Trial(i).Active = 1; 0111 end 0112 0113 % Update MEGinfo 0114 MEGinfo = vb_load_measurement_info(data{ix_info}.megfile); 0115 MEGinfo.Nsample = size(bexp,2); 0116 MEGinfo.Nrepeat = Nrepeat; 0117 MEGinfo.Trial = Trial; 0118 MEGinfo = vb_info_adjust_trial(MEGinfo); 0119 if isfield(concat_parm,'Pretrigger'), 0120 MEGinfo.Pretrigger = concat_parm.Pretrigger; 0121 end 0122 0123 % Save data 0124 load(data{ix_info}.megfile,'pick','Qpick','ref_pick','ref_Qpick', ... 0125 'CoordType','PositionFile','Measurement'); 0126 vb_fsave(megfile,'pick','Qpick','ref_pick','ref_Qpick', ... 0127 'CoordType','bexp','bexp_ext','refmg','PositionFile', ... 0128 'MEGinfo','Measurement');