0001 function [bexp0,bexp,J,Iextract] = vb_gen_megdata(parm,MEGinfo)
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 MEGinfo.nprsamp = MEGinfo.nprsamp;
0033 Noise = MEGinfo.Noise;
0034 Noise_file = MEGinfo.Noise_file;
0035 ix = MEGinfo.ix;
0036 ix0 = MEGinfo.ix;
0037 Source = MEGinfo.pattern;
0038 Rfilt = MEGinfo.Rfilt;
0039 Rmax = Rfilt*2;
0040
0041
0042 load([parm.dir.brain parm.file.brain],'nextDD','nextIX');
0043
0044
0045 Iextract = [];
0046 for i = 1:length(ix)
0047 Iextract = [Iextract; ix{i}];
0048 end
0049 Iextract = unique(Iextract);
0050
0051 tmp = [];
0052 for i = 1:length(Iextract)
0053 tmp_ix = find(nextDD{Iextract(i)}<=Rmax);
0054 tmp = [tmp; nextIX{Iextract(i)}(tmp_ix)];
0055 end
0056 Iextract = unique(tmp);
0057 I = length(Iextract);
0058
0059
0060 Itrans = zeros(length(nextIX),1);
0061 Itrans(Iextract) = 1:length(Iextract);
0062
0063
0064 CW = vb_smooth_filter_norm(parm,Rfilt,Rmax,Iextract);
0065
0066
0067 load([parm.dir.basis parm.file.basis],'basis');
0068 basis = basis(Iextract,:);
0069
0070
0071 J = zeros(I,MEGinfo.T);
0072
0073 for i = 1:length(ix)
0074 si = Source{i};
0075 for j = 1:size(si,1)
0076 t1 = si(j,1);
0077 t2 = si(j,2);
0078 dt = t2-t1;
0079 JJ = si(j,3) * sin(pi*((0:dt)./dt)).^2;
0080 J(Itrans(ix{i}),t1:t2) = J(Itrans(ix{i}),t1:t2) + ...
0081 repmat(JJ,[length(ix{i}) 1]);
0082 end
0083 end
0084
0085
0086 J = CW * J;
0087 bexp0 = basis' * J;
0088
0089
0090 tmp = bexp0(:,MEGinfo.nprsamp+1:size(bexp0,2));
0091 tmp = mean(abs(tmp'));
0092 nlevel = MEGinfo.SN * max(tmp);
0093
0094 bexp = bexp0;
0095 switch MEGinfo.Noise
0096 case 1,
0097 bexp = bexp + nlevel * randn(size(bexp));
0098 case {2,3},
0099 load(MEGinfo.Noise_file,'cv0');
0100 N = size(cv0,1);
0101 cv0 = cv0 ./ (sum(diag(cv0)) / N);
0102 if MEGinfo.Noise == 2
0103 cv0 = diag(diag(cv0));
0104 end
0105 R = chol(cv0);
0106 bexp = bexp + nlevel * R * randn(size(bexp));
0107 end
0108