|
97 | 97 | cfg.headmodel = headmodel;
|
98 | 98 | % cfg.normalize = 'yes';
|
99 | 99 | sourcemodel = ft_prepare_leadfield(cfg);
|
| 100 | + |
100 | 101 | L = cat(2,sourcemodel.leadfield{sourcemodel.inside});
|
101 | 102 |
|
102 | 103 | % compute the covariance
|
|
236 | 237 | cfg.funparameter = 'avg.pow';
|
237 | 238 | cfg.method = 'slice';
|
238 | 239 | cfg.nslices = 10;
|
239 |
| -cfg.funcolorlim=[0 0.2]; |
| 240 | +cfg.funcolorlim = [0 0.2]; |
240 | 241 | ft_sourceplot(cfg,source);
|
241 | 242 |
|
242 | 243 | %% contrast between 2 conditions
|
243 | 244 |
|
244 | 245 | % create the sensor data for the second condition
|
245 | 246 | sensordata2 = 1.25.*leadfield1*s1 + 0.8.*leadfield2*s2 + 0.8.*leadfield3*s3 + 1.25.*leadfield4*s4 + randn(301,1000)*0.04e-8;
|
246 | 247 |
|
247 |
| -% compute the covariance |
248 |
| -C2 = cov([sensordata sensordata2]'); |
249 |
| -iC2 = pinv(C2); % so that we compute it only once |
| 248 | +% compute the covariance and its inverse for both conditions combined |
| 249 | +C2 = cov([sensordata sensordata2]'); |
| 250 | +iC2 = inv(C2); |
250 | 251 | iCr2 = inv(C2+eye(301)*1e-19);
|
251 | 252 |
|
252 |
| -% compute the beamformer spatial filter |
| 253 | +% compute the beamformer spatial filter for condition 2 |
253 | 254 | for ii = 1:size(L,2)/3
|
254 | 255 | indx=(ii-1)*3+(1:3);
|
255 | 256 | Lr = L(:,indx); % Lr is the leadfield for source r
|
256 | 257 | wbfr2(indx,:)=pinv(Lr'*iCr2*Lr)*Lr'*iCr2;
|
257 | 258 | end
|
258 |
| -sbfr2 = wbfr2*sensordata2; |
259 |
| -pbfr2 = var(sbfr2,[],2); |
260 |
| -pbfr2 = sum(reshape(pbfr2,3,[])); |
| 259 | + |
261 | 260 | sbfr1 = wbfr2*sensordata;
|
262 | 261 | pbfr1 = var(sbfr1,[],2);
|
263 | 262 | pbfr1 = sum(reshape(pbfr1,3,[]));
|
| 263 | + |
| 264 | +sbfr2 = wbfr2*sensordata2; |
| 265 | +pbfr2 = var(sbfr2,[],2); |
| 266 | +pbfr2 = sum(reshape(pbfr2,3,[])); |
| 267 | + |
264 | 268 | source.avg.pow(source.inside)=(pbfr1-pbfr2)./(pbfr1+pbfr2);
|
265 | 269 |
|
266 | 270 | cfg = [];
|
267 | 271 | cfg.funparameter='avg.pow';
|
268 |
| -cfg.method='slice'; |
| 272 | +cfg.method='ortho'; |
269 | 273 | cfg.nslices = 10;
|
270 | 274 | cfg.funcolorlim=[-.2 .2];
|
271 | 275 | ft_sourceplot(cfg,source);
|
272 | 276 |
|
273 | 277 | %% correlated sources
|
| 278 | + |
274 | 279 | sens = ni2_sensors('type','meg');
|
275 | 280 | headmodel = ni2_headmodel('type','spherical','nshell',1);
|
276 | 281 |
|
|
295 | 300 | cfg.vol = headmodel;
|
296 | 301 | % cfg.normalize = 'yes';
|
297 | 302 | sourcemodel = ft_prepare_leadfield(cfg);
|
| 303 | + |
298 | 304 | L = cat(2,sourcemodel.leadfield{sourcemodel.inside});
|
299 | 305 |
|
300 | 306 | % compute the covariance
|
|
0 commit comments