-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm_spatial_training_witheye.m
322 lines (271 loc) · 12.4 KB
/
wm_spatial_training_witheye.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
% Working Memory PFC columnar imaging with spatial task
% Samples at different directions are shown at the same time with different
% colors
% By Yuan @ 20230426
% By Yinghua @ 20230518
% By Yuan @ 20230905
% By Yuan @ 20231223
% By Xin @ 20231229
% By Yuan @ 20231229
% By Yuan @ 20240719
%%
resDir = [CurrDir '\Results\training\' SubjID '\'];
if ~isdir(resDir)
mkdir(resDir);
end
if exist([resDir SubjID '_Sess' num2str(SessID) '_spatialTask_color_run' num2str(RunID) '.mat'],'file')
ShowCursor;
Screen('CloseAll');
reset_test_gamma;
warning on;
error('This run number has been tested, please enter a new run num!');
end
results = zeros(Param.DisBehav.TrialNum,8);
timePoints = zeros(Param.DisBehav.TrialNum,8);
trial_index = randperm(Param.DisBehav.TrialNum);
trial_index = mod(trial_index,Param.Discri.DirectionNum)+1;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% Results Matrix %%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1- trial number 2- visual field location
% 3- sample baseline 4- task_diff
% 5- test angle 6- response, 1 = left, 2 = right
% 7- acc, 1 = right, 0 = wrong
% 8- sample actual
% 9- ITI time (s)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%% TimePoint Matrix %%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1- trial onset 2- fix onset delay
% 3- ITI duration 4- Sample duration
% 5- Delay duration 6- Test duration
% 7- RT 8- trail dur
%% Main experiment
%% initialize eye tracker
mainfilename = [SubjID '_' num2str(SessID) '_' num2str(RunID)];
dummymode = 0;
el=EyelinkInitDefaults(wnd);
if ~EyelinkInit(dummymode, 1)
fprintf('Eyelink Init aborted.\n');
cleanup; % cleanup function
return;
end
[v vs]=Eyelink('GetTrackerVersion');
fprintf('Running experiment on a ''%s'' tracker.\n', vs);
% make sure that we get event data from the Eyelink
Eyelink('Command', 'link_sample_data = LEFT,RIGHT,GAZE,AREA');
Eyelink('command', 'link_event_data = GAZE,GAZERES,HREF,AREA,VELOCITY');
Eyelink('command', 'link_event_filter = LEFT,RIGHT,FIXATION,BLINK,SACCADE,BUTTON');
% open file to record data to
edfFile=[mainfilename '.edf'];
Eyelink('Openfile', edfFile);
% STEP 4
% Calibrate the eye tracker
EyelinkDoTrackerSetup(el);
% STEP 6
% do a final check of calibration using driftcorrection
success=EyelinkDoDriftCorrection(el);
if success~=1
cleanup;
return;
end
eye_used = Eyelink('EyeAvailable'); % get eye that's tracked
if eye_used == el.BINOCULAR; % if both eyes are tracked
eye_used = el.LEFT_EYE; % use left eye
end
% draw_box
Eyelink('command', 'draw_box %d %d %d %d 15',round(Param.Settings.ScrnResolution(3)/2-2*Param.SpatialDot.InnerRadius),round(Param.Settings.ScrnResolution(4)/2-2*Param.SpatialDot.InnerRadius),round(Param.Settings.ScrnResolution(3)/2+2*Param.SpatialDot.InnerRadius),round(Param.Settings.ScrnResolution(4)/2+2*Param.SpatialDot.InnerRadius));
% open file to record data to
edfFile=[mainfilename '.edf'];
Eyelink('Openfile', edfFile);
%% Staircase settings
if SessID == 1 && RunID == 1
Param.Staircase.AngleDelta = Curr_AngleDelta;
elseif SessID == 1 && RunID ~= 1
previou_results = load([CurrDir '\Results\training\' SubjID '\' SubjID '_Sess' num2str(SessID) '_spatialTask_color_run' num2str(RunID-1) '.mat']);
Param.Staircase.AngleDelta = previou_results.threshold_value;
elseif SessID ~= 1 && RunID == 1
previou_results = load([CurrDir '\Results\training\' SubjID '\' SubjID '_Sess' num2str(SessID-1) '_spatialTask_color_run' num2str(10) '.mat']);
Param.Staircase.AngleDelta = previou_results.threshold_value;
elseif SessID ~= 1 && RunID ~= 1
previou_results = load([CurrDir '\Results\training\' SubjID '\' SubjID '_Sess' num2str(SessID) '_spatialTask_color_run' num2str(RunID-1) '.mat']);
Param.Staircase.AngleDelta = previou_results.threshold_value;
end
% stop by trials
UD = PAL_AMUD_setupUD('up',Param.Staircase.Up,'down',Param.Staircase.Down);
UD = PAL_AMUD_setupUD(UD,'StepSizeDown',Param.Staircase.StepSizeDown,'StepSizeUp',Param.Staircase.StepSizeUp, ...
'stopcriterion', Param.Staircase.StopCriterion1,'xMax',Param.Staircase.xMax,'xMin',Param.Staircase.xMin,'truncate','yes');
UD = PAL_AMUD_setupUD(UD,'startvalue', Param.Staircase.AngleDelta,'stoprule',Param.Staircase.StopRule1);
%% Spatial task
for trial_i = 1:Param.DisBehav.TrialNum
if mod(trial_i,Param.DisBehav.minirun)==1
if trial_i == 1
DrawFormattedText(wnd,'Press space to start!','center','center', white);
else
DrawFormattedText(wnd,'Take a rest! Press space to start!','center','center', white);
end
Screen('Flip',wnd);
is_true = 0;
while (is_true == 0)
[ifkey,RT_time,keyCode] = KbCheck;
if keyCode(Param.Keys.Space)
is_true = 1;
elseif keyCode(Param.Keys.EscPress)
abort;
end
end
end
results(trial_i,1) = trial_i;
results(trial_i,2) = Param.Stimuli.LocationUsed;
% task diff
results(trial_i,4) = UD.xCurrent;
jitter_temp = sign(rand-0.5);
if jitter_temp == 0
jitter_temp = 1;
end
curr_jitter = jitter_temp * results(trial_i,4);
% determine location
results(trial_i,3) = Param.Discri.Directions(trial_index(trial_i)); % target location = first sample
temp_loc = randi(Param.Discri.DirectionNum-1);
% task start time
trial_onset = GetSecs;
timePoints(trial_i,1) = trial_onset;
% start recoding
Eyelink('startrecording');
Eyelink('Message','Trial %d Begin',trial_i);
% % draw prefixation
% Screen('FillOval', wnd, Param.Fixation.OvalColor, Param.Fixation.OvalLoc);
% Screen('DrawLines', wnd, Param.Fixation.CrossLoc2, Param.Fixation.CrossWidth, Param.Fixation.CrossColor, [], 1);
% vbl = Screen('Flip',wnd);
% timePoints(trial_i,2) = vbl - timePoints(trial_i,1);
%
%% base location
curr_loc = zeros(2,2);
results(trial_i,8) = results(trial_i,3) + (rand - 0.5) * 2 *Param.SpatialDot.AngleJitter;
results(trial_i,5) = results(trial_i,8) + curr_jitter;
curr_loc(1,1) = Param.SpatialDot.OuterRadius * cos(results(trial_i,8)/180*pi)+Param.Stimuli.Locations(3,1);
curr_loc(1,2) = Param.SpatialDot.OuterRadius * sin(results(trial_i,8)/180*pi)+Param.Stimuli.Locations(3,2);
curr_loc(2,1) = Param.SpatialDot.OuterRadius * cos(results(trial_i,5)/180*pi)+Param.Stimuli.Locations(3,1);
curr_loc(2,2) = Param.SpatialDot.OuterRadius * sin(results(trial_i,5)/180*pi)+Param.Stimuli.Locations(3,2);
%% dot color
curr_color_temp = randperm(Param.Discri.DirectionNum,1);
curr_color(1,:) = Param.SpatialDot.DiskColor;
%% Go!
%% ITI
Screen('FillOval',wnd,Param.Fixation.OvalColor,Param.Fixation.OvalLoc);
vbl = Screen('Flip',wnd);
timePoints(trial_i,2) = vbl-timePoints(trial_i,1);
%% Sample
Screen('FillOval',wnd,curr_color(1,:),[curr_loc(1,1)-Param.SpatialDot.DotSize, curr_loc(1,2)-Param.SpatialDot.DotSize,curr_loc(1,1)+Param.SpatialDot.DotSize,curr_loc(1,2)+Param.SpatialDot.DotSize]);
Screen('FillOval',wnd,Param.Fixation.OvalColor,Param.Fixation.OvalLoc);
Screen('DrawLines',wnd,Param.Fixation.CrossLoc,Param.Fixation.CrossWidth,Param.Fixation.CrossColor,[],1);
vbl = Screen('Flip',wnd,vbl + Param.trainTrial.ITI);
timePoints(trial_i,3) = vbl - sum(timePoints(trial_i,1:2));
%% Delay
Screen('FillOval',wnd,Param.Fixation.OvalColor,Param.Fixation.OvalLoc);
Screen('DrawLines',wnd,Param.Fixation.CrossLoc,Param.Fixation.CrossWidth,Param.Fixation.CrossColor,[],1);
vbl = Screen('Flip',wnd,vbl + Param.trainTrial.durColor);
timePoints(trial_i,4) = vbl - sum(timePoints(trial_i,1:3));
%% test
Screen('FillOval',wnd,curr_color(1,:),[curr_loc(2,1)-Param.SpatialDot.DotSize, curr_loc(2,2)-Param.SpatialDot.DotSize,curr_loc(2,1)+Param.SpatialDot.DotSize,curr_loc(2,2)+Param.SpatialDot.DotSize]);
Screen('FillOval',wnd,Param.Fixation.OvalColor,Param.Fixation.OvalLoc);
Screen('DrawLines',wnd,Param.Fixation.CrossLoc,Param.Fixation.CrossWidth,Param.Fixation.CrossColor,[],1);
vbl = Screen('Flip',wnd,vbl+Param.trainTrial.Delay);
stimulus_onset = vbl;
timePoints(trial_i,5) = vbl - sum(timePoints(trial_i,1:4));
%% response
Screen('FillOval',wnd,Param.Fixation.OvalColor,Param.Fixation.OvalLoc);
Screen('DrawLines',wnd,Param.Fixation.CrossLoc,Param.Fixation.CrossWidth,Param.Fixation.CrossColor,[],1);
vbl = Screen('Flip',wnd,vbl+Param.trainTrial.testColor);
timePoints(trial_i,6) = vbl - sum(timePoints(trial_i,1:5));
is_true = 0;
while (is_true == 0 && GetSecs - vbl < Param.trainTrial.MaxRT)
[keyIsDown_1, RT_time, keyCode] = KbCheck;
if keyCode(Param.Keys.Right) || keyCode(Param.Keys.two1) || keyCode(Param.Keys.two2)
results(trial_i,6) = 2; % response
if jitter_temp == 1
results(trial_i,7) = 1; % acc
end
timePoints(trial_i,7) = RT_time - vbl; % reation time
is_true = 1;
elseif keyCode(Param.Keys.Left) || keyCode(Param.Keys.one1) || keyCode(Param.Keys.one2)
results(trial_i,6) = 1;
if jitter_temp == -1
results(trial_i,7) = 1;
end
timePoints(trial_i,7) = RT_time - vbl;
is_true = 1;
elseif keyCode(Param.Keys.EscPress)
abort;
end
end
UD = PAL_AMUD_updateUD(UD, results(trial_i,7)); % update UD structure
%% Feedback
% test
Screen('FillOval',wnd,curr_color(1,:),[curr_loc(2,1)-Param.SpatialDot.DotSize, curr_loc(2,2)-Param.SpatialDot.DotSize,curr_loc(2,1)+Param.SpatialDot.DotSize,curr_loc(2,2)+Param.SpatialDot.DotSize]);
% sample
Screen('FrameOval',wnd,curr_color(1,:),[curr_loc(1,1)-Param.SpatialDot.DotSize, curr_loc(1,2)-Param.SpatialDot.DotSize,curr_loc(1,1)+Param.SpatialDot.DotSize,curr_loc(1,2)+Param.SpatialDot.DotSize]);
if results(trial_i,7) == 1
DrawFormattedText(wnd,'Correct','center','center', white);
elseif results(trial_i,7) == 0
DrawFormattedText(wnd,'Wrong','center','center', white);
beep;
end
Screen('Flip',wnd);
while (GetSecs - timePoints(trial_i,1) < Param.trainTrial.Duration_Beh)
timePoints(trial_i,8) = GetSecs - timePoints(trial_i,1);
end
% stop recoding
Eyelink('Message','Trial %d End',trial_i);
Eyelink('stoprecording');
end
% Eyelink close;
Eyelink('CloseFile');
% download data file
try
fprintf('Receiving data file ''%s''\n', edfFile);
status=Eyelink('ReceiveFile');
if status > 0
fprintf('ReceiveFile status %d\n', status);
end
if 2==exist(edfFile, 'file')
fprintf('Data file ''%s'' can be found in ''%s''\n', edfFile, pwd);
end
figure(1);
% mainfilename = [num2str(1) '_' num2str(4)];%??????8???
edf_used=Edf2Mat([mainfilename '.edf'],1);
fix_num = size(edf_used.Events.Efix.start,2);
scatter(edf_used.Events.Efix.posX,edf_used.Events.Efix.posY);
catch rdf
fprintf('Problem receiving data file ''%s''\n', edfFile );
rdf;
end
%% compute accuracy
threshold_value = PAL_AMUD_analyzeUD(UD, 'trials', Param.Staircase.StopRule1);
Accu = sum(results(:,7))./Param.DisBehav.TrialNum;
disp(' ');
disp(['Accuracy: ' num2str(Accu)]);
disp(' ');
%% save data
cd(resDir);
resName = [SubjID '_Sess' num2str(SessID) '_spatialTask_color_run' num2str(RunID) '.mat'];
save(resName,'results','timePoints','UD','threshold_value','Accu','Param');
cd(CurrDir);
figure(1);
edf_used=Edf2Mat([mainfilename '.edf'],1);
fix_num = size(edf_used.Events.Efix.start,2);
scatter(edf_used.Events.Efix.posX,edf_used.Events.Efix.posY);
hold on;
%% plot
figure(2);
end_trial = size(UD.x,2);
task_diff_temp = UD.x;
plot(1:end_trial,task_diff_temp(1:end_trial));
axis([0 Param.Staircase.MaxTrial 0 15]);
%%
warning on;
reset_test_gamma;
ShowCursor;
Screen('CloseAll');
delete *.asv