Skip to content

Commit d84c83e

Browse files
small updates
1 parent 18c0b25 commit d84c83e

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

exercises_code/ni2_inverse5_scanning.m

+15-9
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
cfg.headmodel = headmodel;
9898
% cfg.normalize = 'yes';
9999
sourcemodel = ft_prepare_leadfield(cfg);
100+
100101
L = cat(2,sourcemodel.leadfield{sourcemodel.inside});
101102

102103
% compute the covariance
@@ -236,41 +237,45 @@
236237
cfg.funparameter = 'avg.pow';
237238
cfg.method = 'slice';
238239
cfg.nslices = 10;
239-
cfg.funcolorlim=[0 0.2];
240+
cfg.funcolorlim = [0 0.2];
240241
ft_sourceplot(cfg,source);
241242

242243
%% contrast between 2 conditions
243244

244245
% create the sensor data for the second condition
245246
sensordata2 = 1.25.*leadfield1*s1 + 0.8.*leadfield2*s2 + 0.8.*leadfield3*s3 + 1.25.*leadfield4*s4 + randn(301,1000)*0.04e-8;
246247

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);
250251
iCr2 = inv(C2+eye(301)*1e-19);
251252

252-
% compute the beamformer spatial filter
253+
% compute the beamformer spatial filter for condition 2
253254
for ii = 1:size(L,2)/3
254255
indx=(ii-1)*3+(1:3);
255256
Lr = L(:,indx); % Lr is the leadfield for source r
256257
wbfr2(indx,:)=pinv(Lr'*iCr2*Lr)*Lr'*iCr2;
257258
end
258-
sbfr2 = wbfr2*sensordata2;
259-
pbfr2 = var(sbfr2,[],2);
260-
pbfr2 = sum(reshape(pbfr2,3,[]));
259+
261260
sbfr1 = wbfr2*sensordata;
262261
pbfr1 = var(sbfr1,[],2);
263262
pbfr1 = sum(reshape(pbfr1,3,[]));
263+
264+
sbfr2 = wbfr2*sensordata2;
265+
pbfr2 = var(sbfr2,[],2);
266+
pbfr2 = sum(reshape(pbfr2,3,[]));
267+
264268
source.avg.pow(source.inside)=(pbfr1-pbfr2)./(pbfr1+pbfr2);
265269

266270
cfg = [];
267271
cfg.funparameter='avg.pow';
268-
cfg.method='slice';
272+
cfg.method='ortho';
269273
cfg.nslices = 10;
270274
cfg.funcolorlim=[-.2 .2];
271275
ft_sourceplot(cfg,source);
272276

273277
%% correlated sources
278+
274279
sens = ni2_sensors('type','meg');
275280
headmodel = ni2_headmodel('type','spherical','nshell',1);
276281

@@ -295,6 +300,7 @@
295300
cfg.vol = headmodel;
296301
% cfg.normalize = 'yes';
297302
sourcemodel = ft_prepare_leadfield(cfg);
303+
298304
L = cat(2,sourcemodel.leadfield{sourcemodel.inside});
299305

300306
% compute the covariance

exercises_text/ni2_inverse5_scanning.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ We will use the variables `sensordata`, `sourcemodel` and `L` that we also used
304304

305305
Now we will simulate data from a 'second’ condition (compared to the original variable sensordata), where the sources have the exact same locations and time courses, but the amplitude of two sources is decreased, and the amplitude of the other sources is increased, relative to the 'first’ condition.
306306

307-
sensordata2 = 1.25.*leadfield1_s1 + ...
308-
0.80.*leadfield2_s2 + ...
309-
0.80.*leadfield3_s3 + ...
310-
1.25.*leadfield4_s4 + ...
307+
sensordata2 = 1.25 .* leadfield1*s1 + ...
308+
0.80 .* leadfield2*s2 + ...
309+
0.80 .* leadfield3*s3 + ...
310+
1.25 .* leadfield4*s4 + ...
311311
randn(301, 1000)*0.04e-8;
312312

313313
We will now compute the spatial filters using the covariance estimated from the data combined across the two conditions. In this way we will end up with a single set of spatial filters, and thus, in comparing across the two conditions, we ensure that the depth bias is the same for condition 1 and 2. The covariance of the data combined across the 2 conditions can be computed in several ways, e.g. by averaging the single condition covariances. Here, we first concatenate the data and subsequently compute the covariance. Now we will use the MATLAB `cov` function, rather than computing the covariance 'by hand’ (i.e. by first computing the mean across time etc.).

0 commit comments

Comments
 (0)