|
| 1 | +% create some data |
| 2 | +[S,time] = ni2_activation; |
| 3 | +sens = ni2_sensors('type','eeg','n',64); |
| 4 | + |
| 5 | +% in order to fool around with the reference of the leadfield, we need to |
| 6 | +% add an explicit 'tra', otherwise ft_compute_leadfield will subtract the |
| 7 | +% mean by default. By adding a tra as Identity matrix, the leadfields will |
| 8 | +% be returned 'without' reference. Here we add a reference on the left, 'eeg74' |
| 9 | +ref = 25; |
| 10 | +sens.tra = eye(numel(sens.label)); |
| 11 | +sens.tra(:,ref) = sens.tra(:,ref)-1; |
| 12 | + |
| 13 | +% create a volume conductor model |
| 14 | +headmodel = ni2_headmodel('type', 'spherical', 'nshell', 3); |
| 15 | + |
| 16 | +% create a 3D grid for the initial gridsearch |
| 17 | +sourcemodel = ni2_sourcemodel('type','grid','resolution',1); |
| 18 | + |
| 19 | +% simulate some sensor level data |
| 20 | +dippar = [-8./sqrt(2) 0.5 8./sqrt(2) [1 1 1].*(3^(-1/3))]; |
| 21 | +leadfield = ni2_leadfield(sens, headmodel, dippar); |
| 22 | +noise = sens.tra*randn(numel(sens.label),1000)*1e-3; |
| 23 | +sensordata = leadfield*S+noise; |
| 24 | +assert(all(sensordata(ref,:)==0)); |
| 25 | + |
| 26 | +% visualize it |
| 27 | +topo_observed = sensordata(:,500); |
| 28 | +ni2_topoplot(sens, topo_observed); |
| 29 | + |
| 30 | +data = []; |
| 31 | +data.avg = sensordata; |
| 32 | +data.time = time; |
| 33 | +data.label = sens.label; |
| 34 | +data.elec = sens; |
| 35 | +data.dimord ='chan_time'; |
| 36 | + |
| 37 | +% this is what I think Sarang means, i.e. data with an implicitref present, |
| 38 | +% and then svd'ed in order to remove the last component |
| 39 | +[u,s,v] = svd(data.avg, 'econ'); |
| 40 | +montage2.tra = u(:,1:end-1)'; |
| 41 | +montage2.labelold = data.label; |
| 42 | +for k = 1:size(montage2.tra,1) |
| 43 | + montage2.labelnew{k,1} = sprintf('comp%02d',k); |
| 44 | +end |
| 45 | +data_svd = ft_apply_montage(data, montage2); |
| 46 | +data_svd.elec = ft_apply_montage(data.elec, montage2); |
| 47 | + |
| 48 | +% this is the data with the reference channel removed |
| 49 | +cfg = []; |
| 50 | +cfg.channel = data.label; |
| 51 | +cfg.channel(ref) = []; |
| 52 | +data = ft_selectdata(cfg, data); |
| 53 | + |
| 54 | +% do some referencing by hand to obtain the average referenced data |
| 55 | +montage1.tra = eye(numel(data.label))- ones(numel(data.label))./numel(data.label); |
| 56 | +montage1.labelold = data.label; |
| 57 | +montage1.labelnew = data.label; |
| 58 | +data_avg = ft_apply_montage(data, montage1); |
| 59 | +data_avg.elec = ft_apply_montage(data.elec, montage1); |
| 60 | + |
| 61 | +cfg = []; |
| 62 | +cfg.gridsearch = 'yes'; |
| 63 | +cfg.model = 'regional'; |
| 64 | +cfg.headmodel = headmodel; |
| 65 | +cfg.sourcemodel = sourcemodel; |
| 66 | +cfg.latency = [0.49 0.51]; |
| 67 | +cfg.nonlinear = 'yes'; |
| 68 | +cfg.numdipoles = 1; |
| 69 | +dip = ft_dipolefitting(cfg, data); |
| 70 | +dip_avg = ft_dipolefitting(cfg, data_avg); |
| 71 | +dip_svd = ft_dipolefitting(cfg, data_svd); |
| 72 | + |
| 73 | +%ni2_topoplot(sens,dip.Vmodel(:,6)); |
| 74 | +%ni2_topoplot(sens,dip.Vdata(:,6)); |
| 75 | + |
| 76 | +sens_jittered = ni2_sensors('type', 'eeg', 'jitter', 0.1, 'n', 64); |
| 77 | + |
| 78 | +dataj = data; |
| 79 | +dataj_avg = data_avg; |
| 80 | +dataj_svd = data_svd; |
| 81 | + |
| 82 | +dataj.elec.elecpos = sens_jittered.chanpos; |
| 83 | +dipj = ft_dipolefitting(cfg, dataj); |
| 84 | +dataj_avg.elec.elecpos = sens_jittered.chanpos; |
| 85 | +dipj_avg = ft_dipolefitting(cfg, dataj_avg); |
| 86 | +dataj_svd.elec.elecpos = sens_jittered.chanpos; |
| 87 | +dipj_svd = ft_dipolefitting(cfg, dataj_svd); |
| 88 | + |
0 commit comments