-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask01.m
More file actions
639 lines (542 loc) · 23.4 KB
/
task01.m
File metadata and controls
639 lines (542 loc) · 23.4 KB
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
function task01( logpars, PTB, EThndl, LPT )
rng('shuffle');
% Test task
ver = '2.0';
fprintf('Associative learning task version %s\n', ver);
fprintf('\n\n');
%% init experiment structure
EXP = {};
EXP.stimduration = 6;
EXP.targetduration = .200;
EXP.trunc_unif_dur = .500;
EXP.stimsdir = fullfile('textures-03');
EXP.assetsdir = fullfile('assets');
EXP.baseImg = [0 0 800 600];
EXP.baseImg_afc = [0 0 800 600];
EXP.framePix = 4;
EXP.time2resp = 6;
EXP.RespFeedSec = .5;
EXP.triangle_side = 100;
EXP.triangle_center = [PTB.xCenter PTB.yCenter];
EXP.triangle_alpha = .6;
EXP.triangle_col = [0.2 0.2 0.2 EXP.triangle_alpha];
EXP.triangle_col_t = [1 1 1];
EXP.triangle_col_c = [0 1 0];
EXP.triangle_col_w = [1 0 0];
EXP.triangle_orient = {'LeftArrow', 'DownArrow', 'UpArrow', 'RightArrow'};
EXP.keyCodeLeft = KbName('LeftArrow');
EXP.keyCodeCenter = KbName('DownArrow');
EXP.keyCodeRight = KbName('RightArrow');
EXP.afcInstructionT = 'Wählen Sie eine zufällige Farbe durch Drücken der Pfeiltasten (links / unten / rechts).';
EXP.afcInstruction = 'Was wäre jetzt am wahrscheinlichsten gewesen?';
EXP.afcInst_yaxis = PTB.yCenter - 200;
EXP.fixCrossDimPix = 80;
EXP.fixCrossWidth = 4;
EXP.xCoords = [-EXP.fixCrossDimPix EXP.fixCrossDimPix 0 0];
EXP.yCoords = [0 0 -EXP.fixCrossDimPix EXP.fixCrossDimPix];
EXP.allCoords = [EXP.xCoords; EXP.yCoords];
EXP.dotColor = [0 1; 0 1; 0 1];
EXP.dotSize = [20 14];
% markers
EXP.target = 90;
EXP.mrk_afc = 92;
EXP.markerStartTask = 110;
EXP.markerEndTask = 116;
EXP.pauseOn = 112;
EXP.pauseOff = 114;
%% load assets
% subject randomization
if str2double(logpars.subjid) == 1000
EXP.id = 1;
else
EXP.id = str2double(logpars.subjid);
EXP.id = EXP.id - 1000;
end
SI = load(fullfile(EXP.assetsdir, 'imgs_randomization.mat'));
EXP.imgs = SI.XX(EXP.id, :);
imgs_filename = fullfile(logpars.subjdir, 'imgs.mat');
save(imgs_filename, '-struct', 'EXP', 'imgs');
% copy imgs name for the purpose of 3-AFC task
EXP.imgs_afc = EXP.imgs;
S = load(fullfile(EXP.assetsdir, 'associative_randomization.mat'));
EXP.X = S.XX(EXP.id).X1;
EXP.T = S.XX(EXP.id).T;
EXP.Q = S.XX(EXP.id).Q;
EXP.ITI = S.XX(EXP.id).ITI;
if logpars.debugging
indxSize = 2;
pauses_indx = find(EXP.X==8);
pauses_indx = pauses_indx([15, 30]);
else
indxSize = size(EXP.X,1);
pauses_indx = find(EXP.X==999);
end
% scale single images to screensize
if logpars.smallscreen == 1
EXP.baseImg = round(EXP.baseImg*.66);
EXP.triangle_side = round(EXP.triangle_side * .66);
elseif logpars.smallscreen == 2
EXP.baseImg = round(EXP.baseImg*.33);
EXP.triangle_side = round(EXP.triangle_side * .33);
end
% load single images into textures
EXP.textures = cell(length(EXP.imgs), 1);
for i=1:length(EXP.imgs)+1
if i == 8
img = imread(fullfile(EXP.assetsdir, 'fixation_cross.png'));
else
img = imread(fullfile(EXP.stimsdir, EXP.imgs{i}));
end
img = imresize(img, flip(EXP.baseImg(3:4)));
EXP.textures{i} = Screen('MakeTexture', PTB.window, img);
% Show init screen
text = sprintf('%s %d%%', 'Loading resources...', round(i/length(EXP.imgs)*100));
drawInstructions(PTB.window, text);
Screen('Flip', PTB.window);
end
clear img;
% prepare size of images shown in the AFC
if logpars.smallscreen == 1
EXP.baseImg_afc = round(EXP.baseImg_afc*.3);
elseif logpars.smallscreen == 2
EXP.baseImg_afc = round(EXP.baseImg_afc*.1);
else
EXP.baseImg_afc = round(EXP.baseImg_afc*.5);
end
% load images and rescale them
EXP.textures_afc = cell(length(EXP.imgs_afc), 1);
for i=1:length(EXP.imgs_afc)+1
if i == 8
img = imread(fullfile(EXP.assetsdir, 'fixation_cross.png'));
else
img = imread(fullfile(EXP.stimsdir, EXP.imgs_afc{i}));
end
img = imresize(img, flip(EXP.baseImg_afc(3:4)));
EXP.textures_afc{i} = Screen('MakeTexture', PTB.window, img);
% Show init screen
text = sprintf('%s %d%%', 'Loading resources...', round(i/length(EXP.imgs_afc)*100));
drawInstructions(PTB.window, text);
Screen('Flip', PTB.window);
end
clear img;
centeredImgLeft = CenterRectOnPointd(EXP.baseImg_afc, PTB.xCenter*.5, PTB.yCenter);
centeredImgCenter = CenterRectOnPointd(EXP.baseImg_afc, PTB.xCenter, PTB.yCenter);
centeredImgRight = CenterRectOnPointd(EXP.baseImg_afc, PTB.xCenter*1.5, PTB.yCenter);
% target polygon (equilateral triangle)
EXP.triangle_R = EXP.triangle_side / sqrt(3);
EXP.triangle_h = sqrt(3) / 2 * EXP.triangle_side;
% change to not equilateral
EXP.triangle_h = 1.5 * EXP.triangle_side;
%% Kb responses
kblog = Keylogger();
%% init logfile
fprintf('\n\n');
fprintf('Initialising log files...\n')
logfile = fopen(logpars.logfilename,'w+');
fprintf(logfile, '%s', ...
strcat(...
'event,', ...
'texture,', ...
'timestamp,', ...
'target_timestamp,', ...
'target_orientation,', ...
'q_option_left,', ...
'q_option_center,', ...
'q_option_right,', ...
'q_response' ...
));
fprintf(logfile, '\n');
fclose(logfile);
%% Instructions: triangle orientation
text = {'In dieser Aufgabe werden Sie gebeten, die Orientierung eines Dreiecks anzugeben,\n'
'das kurz auf dem Bildschirm erscheint.\n'
'Um die Richtung des Dreiecks anzugeben, verwenden Sie die Tastaturpfeile.\n'
'Diese Pfeile entsprechen den vier Richtungen:\n'
'links unten oben rechts\n\n'
'Um sich die Tastaturpfeile und Richtungen einzuprägen, machen Sie jetzt eine Übungsrunde.\n\n'
'Legen Sie Ihre rechte Hand (drei Finger) auf die Tastaturpfeile\n'
'und drücken Sie den Pfeil nach links, um weitere Anweisungen zu erhalten...'};
drawInstructions(PTB.window, strjoin(text));
Screen('Flip', PTB.window);
RestrictKeysForKbCheck(KbName('LeftArrow'));
KbStrokeWait;
Screen('Flip', PTB.window);
RestrictKeysForKbCheck([]);
text = {'In der Mitte des Bildschirms sehen Sie ein Dreieck.\n'
'Geben Sie mit den Pfeilen an, in welche Richtung das Dreieck zeigt.\n\n'
'Wenn Ihre Antwort richtig ist, wird das Dreieck grün.\n'
'Wenn Ihre Antwort falsch ist, wird das Dreieck rot\n'
'und die richtige Orientierung wird unten angezeigt.\n\n'
'Seien Sie so schnell wie möglich! Die Zeit ist begrenzt.\n\n'
'Sobald Sie eine bestimmte Anzahl von richtigen Antworten erreicht haben,\n'
'erhalten Sie weitere Anweisungen.\n\n'
'Drücken Sie den Pfeil nach links, um die Übung zu starten...'};
drawInstructions(PTB.window, strjoin(text));
Screen('Flip', PTB.window);
RestrictKeysForKbCheck(KbName('LeftArrow'));
KbStrokeWait;
Screen('Flip', PTB.window);
RestrictKeysForKbCheck([]);
%% Training responses with respect to triangle orientation
Screen('DrawDots', PTB.window, [PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], EXP.dotSize, EXP.dotColor, [], 2);
vbl = Screen('Flip', PTB.window);
ncorrect = [0 0 0 0];
% training orientation must be pseudorandomized
% such that every orientation is correct at least x times
if logpars.debugging
thrld = 1;
else
thrld = 4;
end
while ~all(ncorrect >= thrld)
Screen('DrawDots', PTB.window, [PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], EXP.dotSize, EXP.dotColor, [], 2);
vbl = Screen('Flip', PTB.window, vbl + PTB.ifi/2);
% add weights to make it more pseudo-randomised
rsample = randsample(1:4, 1, true, 1./(ncorrect+1));
t_orient = EXP.triangle_orient{rsample};
pointList = getTriangle(PTB.xCenter, PTB.yCenter, EXP.triangle_side, EXP.triangle_h, t_orient);
Screen('FillPoly', PTB.window, EXP.triangle_col_t , pointList, 1);
vbl = Screen('Flip', PTB.window, vbl + 1);
kblog.startRecording(vbl);
% wait max 1 sec
KbStrokeWait([], vbl + 1);
keypress = kblog.dumpLog();
response = 0;
Screen('DrawDots', PTB.window, [PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], EXP.dotSize, EXP.dotColor, [], 2);
for p=1:length(keypress)
if keypress(p).pressed
keyCode = keypress(p).keyCode;
if keyCode == KbName(t_orient)
response = 1;
Screen('FillPoly', PTB.window, EXP.triangle_col_c , pointList, 1);
else
response = 0;
Screen('FillPoly', PTB.window, EXP.triangle_col_w , pointList, 1);
switch t_orient
case 'LeftArrow'
txt = 'links';
case 'DownArrow'
txt = 'unten';
case 'UpArrow'
txt = 'oben';
case 'RightArrow'
txt = 'rechts';
end
DrawFormattedText(PTB.window, txt, 'center', PTB.yCenter + 100, 0, 100, [], [], 1.5);
end
break;
end
end
vbl = Screen('Flip', PTB.window);
% clear
Screen('DrawDots', PTB.window, [PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], EXP.dotSize, EXP.dotColor, [], 2);
vbl = Screen('Flip', PTB.window, vbl + .500 + PTB.ifi/2);
ncorrect(rsample) = ncorrect(rsample) + response;
end
% clear the screen
Screen('Flip', PTB.window);
WaitSecs(1);
Screen('Flip', PTB.window);
%% Instructions: AFC task
text ={
'Jetzt wissen Sie, wie Sie die Orientierung eines Dreiecks angeben können.\n\n'
'In der Hauptaufgabe wird ein Dreieck auf einem farbigen Bild erscheinen (aber nicht immer).\n'
'Es gibt 7 verschiedene Farben, und meistens wird nur eine davon auf dem Bildschirm angezeigt.\n'
'Manchmal werden aber auch drei Farben angezeigt, und Sie müssen sich für eine davon entscheiden.\n\n'
'Um eine Farbe auszuwählen, benutzen Sie die Pfeiltasten.\n'
'Die Pfeile links / unten / rechts entsprechen der Farbe \n'
'auf der linken Seite, in der Mitte und auf der rechten Seite.\n\n'
'Für die Übungsrunde können Sie immer eine zufällige Farbe wählen.\n\n'
'Drücken Sie den Pfeil nach links, um die Übungsrunde zu starten.\n'
};
drawInstructions(PTB.window, strjoin(text));
Screen('Flip', PTB.window);
RestrictKeysForKbCheck(KbName('LeftArrow'));
KbStrokeWait;
Screen('Flip', PTB.window);
RestrictKeysForKbCheck([]);
%% Training: AFC task
items = [1234, 2345, 3456, 4567, 5671, 6712];
items = num2cell(items);
items = cellfun(@(i) sprintf('%i', i), items, 'UniformOutput', false);
% training orientation must be pseudorandomized
% such that every orientation is correct at least x times
if logpars.debugging
thrld = 1;
else
thrld = 7;
end
nresponses = zeros(length(items),1);
while ~(sum(nresponses) > thrld)
rsample = randsample(1:length(items), 1, true, 1./(nresponses+1));
item = items{rsample};
source = item(1);
q_optionLeft = item(2);
q_optionCenter = item(3);
q_optionRight = item(4);
sourceDuration = 3;
itiduration = 2;
Screen('DrawLines', PTB.window, EXP.allCoords, ...
EXP.fixCrossWidth, 0, [PTB.xCenter PTB.yCenter], 2);
Screen('DrawDots', PTB.window, ...
[PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], ...
EXP.dotSize, EXP.dotColor, [], 2);
onset = Screen('Flip', PTB.window);
Screen('DrawTexture', PTB.window, EXP.textures{str2double(source)});
onset = Screen('Flip', PTB.window, onset + itiduration + PTB.ifi/2);
DrawFormattedText(PTB.window, EXP.afcInstructionT, 'center', EXP.afcInst_yaxis, 0, 120, [], [], 1.5);
Screen('DrawTexture', PTB.window, EXP.textures_afc{str2double(q_optionLeft)}, [], centeredImgLeft);
Screen('DrawTexture', PTB.window, EXP.textures_afc{str2double(q_optionCenter)}, [], centeredImgCenter);
Screen('DrawTexture', PTB.window, EXP.textures_afc{str2double(q_optionRight)}, [], centeredImgRight);
onset = Screen('Flip', PTB.window, onset + sourceDuration + PTB.ifi/2, 1);
[vbl, keyCode] = KbStrokeWait([], onset + EXP.time2resp - PTB.ifi/2);
keyCode = find(keyCode);
response = 1;
if keyCode == EXP.keyCodeLeft
Screen('FrameRect', PTB.window, 1, centeredImgLeft, EXP.framePix);
elseif keyCode == EXP.keyCodeCenter
Screen('FrameRect', PTB.window, 1, centeredImgCenter, EXP.framePix);
elseif keyCode == EXP.keyCodeRight
Screen('FrameRect', PTB.window, 1, centeredImgRight, EXP.framePix);
else
response = 0;
end
if (EXP.time2resp - EXP.RespFeedSec) > (vbl - onset)
Screen('Flip', PTB.window);
WaitSecs(EXP.RespFeedSec);
Screen('Flip', PTB.window);
else
Screen('Flip', PTB.window);
end
nresponses(rsample) = nresponses(rsample) + response;
end
%% Instructions: main
text = {
'In der Hauptaufgabe werden die Farben in einer Reihenfolge präsentiert\n'
'und die Reihenfolge wird entsprechend einer Regel bestimmt.\n'
'Achten Sie auf die Reihenfolge der Farben\n'
'und lernen Sie diese Regel (also, welche Bilder jeweils aufeinander folgen).\n'
'Ihr Wissen über die Regel wird von Zeit zu Zeit getestet.\n'
'Das bedeutet, dass Sie manchmal drei Farben sehen und eine davon auswählen müssen.\n\n'
'Wenn Sie die Reihenfolge der Farben betrachten,\n'
'kann manchmal ein Dreieck auf dem farbigen Bild erscheinen.\n'
'Wenn das Dreieck erscheint, geben Sie seine Richtung mit einem Tastendruck an.\n'
'Seien Sie so genau und so schnell wie möglich!\n\n'
'Die Aufgabe dauert etwa 45 Minuten, und es gibt Pausen währenddessen.\n\n'
'Versuchen Sie, während der Aufgabe Ihren Kopf still zu halten.\n'
'Versuchen Sie, Ihren Blick nahe der Mitte des Bildschirms zu halten,\n'
'die durch einen kleinen weißen Kreis gekennzeichnet ist.\n\n'
'Legen Sie nun die Hand auf die Tastaturpfeile\n'
'und drücken Sie den Pfeil nach links, um die Kalibrierung des Eyetrackers zu starten...'};
drawInstructions(PTB.window, strjoin(text));
Screen('Flip', PTB.window);
RestrictKeysForKbCheck(KbName('LeftArrow'));
KbStrokeWait;
Screen('Flip', PTB.window);
RestrictKeysForKbCheck([]);
%% Trial structure
LPT.sendMarker(EXP.markerStartTask);
block = 0;
onset = 0;
delay = 0;
for indx =1:indxSize
if ismember(indx, [1; pauses_indx])
vbl = Screen('Flip', PTB.window, onset + delay + PTB.ifi/2);
if ismember(indx, pauses_indx)
% PAUSE
LPT.sendMarker(EXP.pauseOn);
text = {
'PAUSE\n\n'
'Um fortzufahren, drücken Sie den Pfeil nach links ...'
};
drawInstructions(PTB.window, strjoin(text));
Screen('Flip', PTB.window, vbl + PTB.ifi/2);
RestrictKeysForKbCheck(KbName('LeftArrow'));
KbStrokeWait;
Screen('Flip', PTB.window);
RestrictKeysForKbCheck([]);
LPT.sendMarker(EXP.pauseOff);
end
block = block + 1;
if block ~= 1
% PLACE THE HAND ON THE KEYBOARD
text = {'Legen Sie nun die Hand (drei Finger) auf die Tastaturpfeile\n'
'und drücken Sie Pfeil links, um die Kalibrierung des Eyetrackers zu starten...'};
drawInstructions(PTB.window, strjoin(text));
Screen('Flip', PTB.window);
RestrictKeysForKbCheck(KbName('LeftArrow'));
KbStrokeWait;
Screen('Flip', PTB.window);
RestrictKeysForKbCheck([]);
end
% EYE TRACKER CALIBRATION
fprintf('\n\n');
fprintf('Running calibration...\n')
calValInfo = EThndl.calibrate(PTB.window,true);
% save calibration data
[ filepath , name, ~] = fileparts(logpars.calibfilename);
calibname = fullfile(filepath, sprintf('%s_block%02d.mat', name, block));
save(calibname, getname(calValInfo));
text = {
'Achten Sie auf die Reihenfolge der Farben und lernen Sie die Regel.\n\n'
'Die Aufgabe wird in wenigen Sekunden automatisch fortfahren...'
};
drawInstructions(PTB.window, strjoin(text));
fprintf('\n\n');
fprintf('Continue data collection...\n')
EThndl.startRecording(true);
EThndl.startBuffer();
WaitSecs(1);
EThndl.setBegazeTrialImage('grey.png');
% init buffer data
bufferdata = EThndl.consumeBufferData();
% reshape to rowise
bufferdata = reshapeBufferData(bufferdata);
% init eyetracker event data
eteventdata = {};
eteventdata.timestamp = [];
eteventdata.event = {};
vbl = Screen('Flip', PTB.window);
kblog.startRecording(vbl);
delay = 8;
onset = Screen('Flip', PTB.window, vbl + delay + PTB.ifi/2);
end
% TRIAL STRUCTURE
state_indx = EXP.X(indx);
if state_indx < 8
texture = EXP.imgs{state_indx};
else
texture = 'N/A';
end
mrk = state_indx*10;
t_onset = 'N/A';
t_orient = 'N/A';
q_optionLeft = 'N/A';
q_optionCenter = 'N/A';
q_optionRight = 'N/A';
response = 'N/A';
if state_indx == 8
Screen('DrawLines', PTB.window, EXP.allCoords, ...
EXP.fixCrossWidth, 0, [PTB.xCenter PTB.yCenter], 2);
Screen('DrawDots', PTB.window, ...
[PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], ...
EXP.dotSize, EXP.dotColor, [], 2);
onset = Screen('Flip', PTB.window, onset + delay + PTB.ifi/2);
eteventdata = updateETeventData(eteventdata, EThndl, string(mrk));
EThndl.setBegazeTrialImage('interval.png');
LPT.sendMarker(mrk);
delay = EXP.ITI(indx);
elseif ismember(state_indx, 1:7)
Screen('DrawTexture', PTB.window, EXP.textures{state_indx});
Screen('DrawDots', PTB.window, ...
[PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], ...
EXP.dotSize, EXP.dotColor, [], 2);
onset = Screen('Flip', PTB.window, onset + delay + PTB.ifi/2);
eteventdata = updateETeventData(eteventdata, EThndl, string(mrk));
EThndl.setBegazeTrialImage(EXP.imgs{state_indx});
LPT.sendMarker(mrk);
% check if target is present
if EXP.T(indx)
t_orient = EXP.triangle_orient{EXP.T(indx)};
pointList = getTriangle(PTB.xCenter, PTB.yCenter, EXP.triangle_side, EXP.triangle_h, t_orient);
Screen('DrawTexture', PTB.window, EXP.textures{state_indx});
Screen('DrawDots', PTB.window, ...
[PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], ...
EXP.dotSize, EXP.dotColor, [], 2);
Screen('FillPoly', PTB.window, EXP.triangle_col , pointList, 1);
t_onset = onset + unifrnd(EXP.trunc_unif_dur, EXP.stimduration - EXP.trunc_unif_dur);
vbl = Screen('Flip', PTB.window, t_onset + PTB.ifi/2);
eteventdata = updateETeventData(eteventdata, EThndl, string(EXP.target));
EThndl.sendMessage('target');
LPT.sendMarker(EXP.target);
Screen('DrawTexture', PTB.window, EXP.textures{state_indx});
Screen('DrawDots', PTB.window, ...
[PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], ...
EXP.dotSize, EXP.dotColor, [], 2);
Screen('Flip', PTB.window, vbl + EXP.targetduration + PTB.ifi/2);
end
delay = EXP.stimduration;
% AFC task
elseif state_indx > 999
q_options = EXP.Q{indx};
q_options = q_options(2:end);
% shuffle options
q_options = q_options(randperm(3));
q_optionLeft = q_options(1);
q_optionCenter = q_options(2);
q_optionRight = q_options(3);
DrawFormattedText(PTB.window, EXP.afcInstruction, 'center', EXP.afcInst_yaxis, 0, 120, [], [], 1.5);
Screen('DrawTexture', PTB.window, EXP.textures_afc{str2double(q_options(1))}, [], centeredImgLeft);
Screen('DrawTexture', PTB.window, EXP.textures_afc{str2double(q_options(2))}, [], centeredImgCenter);
Screen('DrawTexture', PTB.window, EXP.textures_afc{str2double(q_options(3))}, [], centeredImgRight);
onset = Screen('Flip', PTB.window, onset + delay + PTB.ifi/2, 1);
eteventdata = updateETeventData(eteventdata, EThndl, string(EXP.mrk_afc));
EThndl.sendMessage('afc');
LPT.sendMarker(EXP.mrk_afc);
[vbl, keyCode] = KbStrokeWait([], onset + EXP.time2resp - PTB.ifi/2);
keyCode = find(keyCode);
if keyCode == EXP.keyCodeLeft
response = 'left';
Screen('FrameRect', PTB.window, 1, centeredImgLeft, EXP.framePix);
elseif keyCode == EXP.keyCodeCenter
response = 'center';
Screen('FrameRect', PTB.window, 1, centeredImgCenter, EXP.framePix);
elseif keyCode == EXP.keyCodeRight
response = 'right';
Screen('FrameRect', PTB.window, 1, centeredImgRight, EXP.framePix);
end
if (EXP.time2resp - EXP.RespFeedSec) > (vbl - onset)
Screen('Flip', PTB.window);
WaitSecs(EXP.RespFeedSec);
%Screen('Flip', PTB.window, onset + EXP.time2resp - PTB.ifi/2);
Screen('Flip', PTB.window);
delay = 0;
else
%Screen('Flip', PTB.window, onset + EXP.time2resp - PTB.ifi/2);
Screen('Flip', PTB.window);
delay = 0;
end
end
bufferdata = catBufferData(bufferdata, EThndl);
% save buffer data
fname = [logpars.bufferfilename(1:end-4) sprintf('_block%02d.mat', block)];
save(fname, getname(bufferdata));
% save event data
fname = [logpars.eteventfilename(1:end-4) sprintf('_block%02d.mat', block)];
save(fname, getname(eteventdata));
% save logfile
logfile = fopen(logpars.logfilename,'a+');
fprintf(logfile, '%s', ...
string(state_indx), ',', ...
texture, ',', ...
string(onset), ',', ...
string(t_onset), ',', ...
string(t_orient), ',', ...
string(q_optionLeft), ',', ...
string(q_optionCenter), ',', ...
string(q_optionRight), ',', ...
string(response) ...
);
fprintf(logfile, '\n');
fclose(logfile);
% save data blockwise
if ismember(indx, [pauses_indx-1; size(EXP.X,1)])
Screen('Flip', PTB.window, onset + delay + PTB.ifi/2);
EThndl.stopBuffer(true);
EThndl.stopRecording();
EThndl.saveData(fullfile(cd, sprintf('%s_block%02d', logpars.idffilename, block)), ...
logpars.subjid, sprintf('%s_block%02d', logpars.taskname, block), true);
% save responses keyboard
keypress = kblog.dumpLog();
filename = fullfile(logpars.subjdir, ...
sprintf('%s_responses_block%02d.csv', logpars.taskname, block));
writetable(struct2table(keypress), filename);
end
end
% clear the screen
Screen('Flip', PTB.window, onset + delay + PTB.ifi/2);
text = {'Saving data...'};
drawInstructions(PTB.window, strjoin(text));
Screen('Flip', PTB.window);
WaitSecs(6);
LPT.sendMarker(EXP.markerEndTask);