0001 function megmat_file = neuromag_to_megmat(data_fiffile, mri_fiffile, ...
0002 output_prefix, face_file)
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 if ~exist('data_fiffile', 'var')
0029 error('data_fiffile is a required parameter.');
0030 end
0031 if ~exist('mri_fiffile', 'var')
0032 error('mri_fiffile is a required parameter.');
0033 end
0034 if ~exist('output_prefix', 'var')
0035 error('output_prefix is a required parameter.');
0036 end
0037 if ~exist('face_file', 'var')
0038 face_file = [];
0039 end
0040 if exist(data_fiffile, 'file') ~= 2
0041 error('data_fiffile:%s is not found.', data_fiffile);
0042 end
0043 if exist(mri_fiffile, 'file') ~= 2
0044 error('mri_fiffile:%s is not found.', mri_fiffile);
0045 end
0046
0047 [f_path] = vb_get_file_parts(output_prefix);
0048 if exist(f_path, 'dir') ~= 7
0049 error('output_prefix directory:%s is invalid.', f_path);
0050 end
0051 if ~exist('sensor_mode','var'), sensor_mode = 'All'; end
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 fprintf('--- now loading neuromag header.\n');
0062 [MEGinfo_list, sensor_info] = neuromag_load_meg_header(data_fiffile, ...
0063 mri_fiffile);
0064
0065
0066
0067
0068
0069 [extra_info] = neuromag_load_extra_info(data_fiffile);
0070
0071
0072
0073
0074 if ~isempty(face_file)
0075
0076 if exist(face_file,'file') ~= 2
0077 warning('face_file:%s is not found.\n', face_file);
0078
0079 end
0080
0081 [state, guide_def] = ...
0082 vb_util_check_variable_in_matfile(face_file, 'spherical_head');
0083
0084 if state == guide_def.VALID
0085 load(face_file, 'spherical_head');
0086 Vcenter = spherical_head.Vcenter;
0087 Vradius = spherical_head.Vradius;
0088 else
0089 [state, guide_def] = ...
0090 vb_util_check_variable_in_matfile(face_file, 'surf_face');
0091 if state == guide_def.VALID
0092
0093
0094
0095 h = 0.4;
0096 load(face_file, 'surf_face')
0097
0098 V = surf_face.V_reduce;
0099 Zmax = max(V(:,3));
0100 Zmin = min(V(:,3));
0101 ix = find(V(:,3) > (h * Zmax + (1-h) * Zmin));
0102
0103
0104 [Vcenter,Vradius] = vb_center_sphere(V(ix,:));
0105 else
0106 Vcenter = [];
0107 Vradius = [];
0108 end
0109 end
0110
0111 else
0112 Vcenter = [];
0113 Vradius = [];
0114 end
0115
0116 pick = sensor_info.pick;
0117 Qpick = sensor_info.Qpick;
0118 weight = sensor_info.Weight;
0119
0120 Ninfo = length(MEGinfo_list);
0121
0122
0123
0124
0125 fprintf('--- now loading neuromag data.\n');
0126 for k=1:Ninfo
0127
0128 if Ninfo == 1
0129 megmat_file{1} = [output_prefix, '.meg.mat'];
0130 else
0131 megmat_file{k} = [output_prefix, '_', num2str(k), '.meg.mat'];
0132 end
0133
0134
0135 MEGinfo = MEGinfo_list{k};
0136
0137 session_no = MEGinfo.device_info.index_in_fiffile;
0138
0139
0140 [bexp, ch_info, sfreq] = neuromag_load_meg_data_SSP(data_fiffile, session_no);
0141 [bexp_ext, extra_info] = neuromag_load_extra_data(data_fiffile, session_no);
0142
0143 if ~isempty(Vcenter)
0144 MEGinfo.Vcenter = Vcenter;
0145 MEGinfo.Vradius = Vradius;
0146 end
0147
0148 MEGinfo.Nsample = size(bexp, 2);
0149 MEGinfo.SampleFreq = sfreq;
0150
0151
0152 Trial(1).number = 1;
0153 Trial(1).sample = 1:MEGinfo.Nsample;
0154 Trial(1).Active = true;
0155 MEGinfo.Trial = Trial;
0156
0157 MEGinfo.sensor_weight = weight;
0158 MEGinfo.ExtraChannelInfo = extra_info;
0159
0160 MEGinfo.device = 'NEUROMAG';
0161 CoordType = 'SPM_Right_m';
0162
0163 Measurement = 'MEG';
0164
0165 MEGinfo.Measurement = Measurement;
0166 MEGinfo.ActiveChannel = MEGinfo.ChannelInfo.Active;
0167 MEGinfo.ActiveTrial = MEGinfo.Trial.Active;
0168
0169
0170
0171
0172 vb_fsave(megmat_file{k}, 'MEGinfo', 'Measurement', 'CoordType', ...
0173 'pick', 'Qpick', 'bexp', 'bexp_ext');
0174 fprintf('%s was created.\n', megmat_file{k});
0175 end
0176 fprintf('--- conversion were finished.\n');