-
Notifications
You must be signed in to change notification settings - Fork 3
/
simulate_data_randomly.m
44 lines (43 loc) · 1.05 KB
/
simulate_data_randomly.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function [w,x,s,yrec,p0] = simulate_data_randomly(J,K,T,draw,chanlocs)
% forward model
% load('/home/frans/documents/Microstates/EEG_faces/SPMgainmatrix_aceMdspm8_faces_run1_1_c.mat')
w=rand(J,K);
w=bsxfun(@rdivide,bsxfun(@minus,w,mean(w,1)),std(w,[],1)); % normalize
if draw
chan_idx = 1:(128/J):128;
dims = factor(K);
if size(dims,2)==4
nrow = dims(1)*dims(2);
ncol = dims(3)*dims(4);
elseif size(dims,2)==3
nrow = dims(1)*dims(2);
ncol = dims(3);
elseif size(dims,2)==2
nrow = dims(1);
ncol = dims(2);
else
nrow = 1;
ncol = dims(1);
end
figure;
for i=1:K
subplot(nrow,ncol,i)
topoplot(w(:,i),chanlocs(chan_idx),'electrodes','off','style','map');
end
end
x = rand(K,T);
s = zeros(K,T);
for k=1:K
s(k,:) = abs(sin(0.005*(1:T)))>(k-1)/K;
s(k,abs(sin(0.005*(1:T)))>k/K) = 0;
end
if draw
subplot(2,1,1)
imagesc(s)
subplot(2,1,2)
plot(repmat(1:T,K,1)',(x.*s)')
end
[~,I] = max(s);
p0 = 1-sum(abs(diff(I)))/T;
yrec = w*(x.*s);
end