-
Notifications
You must be signed in to change notification settings - Fork 1
/
MultifocalSequenceDemo.m
135 lines (97 loc) · 2.41 KB
/
MultifocalSequenceDemo.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
% MultifocalSequenceDemo.m
nAng = 24; %number of segments in each ring
nEcc = 8; %number of eccecentric rings of segments
nT = 200; %number of 'blocks' (time steps) needs to be even
stimSeq = generateMultifocalSequence(nAng,nEcc,nT);
%%
% Visualize the sequence matrix
figure(1)
clf
imagesc(1-stimSeq);
colormap(gray)
axis equal;
axis tight
xlabel('Time');
ylabel('Segment number');
%%
% Correlations of time-courses between segments
%
% The constraint that neighboring segments are never on at the same time
% induces negative correlations between neighboring segments and positive
% correlations between segments within 'even' and 'odd' subsets. This is
% not ideal. This issue exists in the sequence that Omar and Geoff Aguirre
% sent us.
c = corrcoef(stimSeq);
% set the diagonals to NaN;
c(find(eye(size(c)))) =NaN;
figure(2)
clf
imagesc(c);
colorbar
colormap(gray);
%%
% autocorrelations
clear r
s = stimSeq(1,:);
shiftS = stimSeq(1,:); % stimSeq(1,:) is the autocorrelation. Other numbers give correlations between segments
for i=1:length(s)
tmp = corrcoef(s,shiftS);
r(i) = tmp(1,2);
shiftS = [shiftS(2:end),shiftS(1)];
end
figure(3)
clf
plot(r,'.-');
xlabel('shift')
%%
% Visualize the segments
[ecc,ang] = meshgrid(1:nEcc,1:nAng);
nSegments = nAng*nEcc;
segA = mod(ecc+mod(ang,2),2); %checkerboard
segA = logical(segA(:));
[x,y] = meshgrid(linspace(-1,1,501));
ang = atan2(y,x);
ecc = sqrt(x.^2+y.^2);
angList = linspace(-pi,pi,nAng+1);
eccList = linspace(.1,1,nEcc+1);
%h= image(zeros(size(x)));
img = zeros(size(x));
count= 1;
clear wedgeId
for i = 1:nEcc
for j=1:nAng
count = count+1;
img(ecc>eccList(i) &ecc<=eccList(i+1) & ang>angList(j) & ang<=angList(j+1)) = count;
end
end
figure(4)
clf
h= image(x(1,:),y(:,1),img);
axis equal
axis tight
axis off
cmap= hsv(nSegments+1);
cmap(1,:) = [0,0,0];
colormap(cmap);
colorbar
%%
% Show a movie of the sequence
frameRate = 4; %Hz
colorbar off
tic
for i=1:nT
img = zeros(size(x));
cmap = zeros(nSegments+2,3);
cmap(1,:) = [.5,.5,.5];
for j=1:(nAng*nEcc)
if stimSeq(j,i)
%if segA(j);
cmap(j+1,:) = [1,1,1];
end
end
colormap(cmap);
title(num2str(i));
drawnow
while(toc<i/frameRate)
end
end