0001 function [res] = mne_ex_compute_inverse(fname_data,setno,fname_inv,nave,lambda2,dSPM,sLORETA)
0002
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
0033
0034
0035
0036 me='MNE:mne_ex_compute_inverse';
0037
0038 global FIFF;
0039 if isempty(FIFF)
0040 FIFF = fiff_define_constants();
0041 end
0042
0043 if nargin ~= 6 && nargin ~= 7
0044 error(me,'Incorrect number of arguments');
0045 end
0046
0047 if nargin == 6
0048 sLORETA = false;
0049 end
0050
0051
0052
0053 data = fiff_read_evoked(fname_data,setno);
0054
0055
0056
0057 inv = mne_read_inverse_operator(fname_inv);
0058
0059
0060
0061 if nave < 0
0062 nave = data.evoked.nave;
0063 end
0064 inv = mne_prepare_inverse_operator(inv,nave,lambda2,dSPM,sLORETA);
0065
0066
0067
0068 data = fiff_pick_channels_evoked(data,inv.noise_cov.names);
0069 fprintf(1,'Picked %d channels from the data\n',data.info.nchan);
0070 fprintf(1,'Computing inverse...');
0071
0072
0073
0074
0075
0076
0077
0078 trans = diag(sparse(inv.reginv))*inv.eigen_fields.data*inv.whitener*inv.proj*double(data.evoked(1).epochs);
0079
0080
0081
0082
0083 if inv.eigen_leads_weighted
0084
0085
0086
0087 fprintf(1,'(eigenleads already weighted)...');
0088 sol = inv.eigen_leads.data*trans;
0089 else
0090
0091
0092
0093 fprintf(1,'(eigenleads need to be weighted)...');
0094 sol = diag(sparse(sqrt(inv.source_cov.data)))*inv.eigen_leads.data*trans;
0095 end
0096
0097 if inv.source_ori == FIFF.FIFFV_MNE_FREE_ORI
0098 fprintf(1,'combining the current components...');
0099 sol1 = zeros(size(sol,1)/3,size(sol,2));
0100 for k = 1:size(sol,2)
0101 sol1(:,k) = sqrt(mne_combine_xyz(sol(:,k)));
0102 end
0103 sol = sol1;
0104 end
0105 if dSPM
0106 fprintf(1,'(dSPM)...');
0107 sol = inv.noisenorm*sol;
0108 elseif sLORETA
0109 fprintf(1,'(sLORETA)...');
0110 sol = inv.noisenorm*sol;
0111 end
0112 res.inv = inv;
0113 res.sol = sol;
0114 res.tmin = double(data.evoked(1).first)/data.info.sfreq;
0115 res.tstep = 1/data.info.sfreq;
0116 fprintf(1,'[done]\n');
0117
0118 return;
0119 end
0120