-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexp_fearadapt_main.m
1569 lines (1494 loc) · 75.1 KB
/
exp_fearadapt_main.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
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [p]=exp_fearadapt_main(subject,PainThreshold)
%[p]=exp_FearGen_ForAll(subject,phase,csp,PainThreshold)
%
%
% This code is based on the exp_FearAmy.m, adapted to run the initial FearGen
% experiment (Onat & Buechel, 2015).
%
% When the experiment starts as experimenter you will have to pass through
% few sanity checks (press (V)alidate to continue). Once these are
% passed, some text will be shown to the participant. You can also pass
% these stages by pressing V (normally the subject has to read them and
% press confirm key). These instructions for participants are shown using
% the ShowInstruction function, where you precise instructions by their
% id number. All instructions are stored in the GetText function by these
% ids. So if you would like to change instructions you will need to
% modify that function.
%
% The experiment starts with PHASE = 1. Here I set the shock intensity
% while the participant is in the scanner. The shock threshold is
% measured outside the scanner. This is here just to validate the shock
% intensity that will be used during the experiment, it is obtained by
% the PAINTHRESHOLD (given as input) times P.OUT.SHOCKFACTOR (defined
% below). PAINTHRESHOLD is only painful half of the time by definition,
% and we would like to give a shock which is more painful but still
% bearable by the participant. That is, I ask the participant to confirm
% the shock is PAINFUL and BEARABLE. If the shock is not bearable the
% program will propose a lower amplitude and the same question will be
% repeated until these two conditions are fulfilled. It is always good to
% stay in oral communication with the participant though. The phase = 1
% continues with a short presentation of faces, where I evaluate whether
% they 1/ follow the fixation cross as instructed and 2/ detect the
% oddball target. If they fail in any of these, phase 1 is repeated. This
% phase also helps people to familiarize with the faces if no other task
% has yet been carried out befo
%
% The phase 2 is baseline. All faces are shown, but non predicts the
% shock. Instead shocks are delivered after a shock symbol. This phase
% ends with ratings.
%
% Phase 3 is conditioning. Only CS+ and CS- are shown and CS+ is shocked
% at about 30% of the cases.
%
% Phase 4 is similar to baseline, all faces are shown, but shock follows
% the CS+ face to avoid extinction. Following this phase, there is the
% detection task.
%
%
% The current experiment can fully work with the Eyelink
% eye-tracker. This is however now disabled. If you intent to record
% eye-movements turn the EyelinkWanted flag to 1.
%
% The parallel communication currently relies on the cogent's OUTP
% function. It is used to deliver shocks and to send event pulses to the
% physio computer. If you intend to use a Windows systems you can install
% cogent and outp function, then you would be able to directly use this
% code. Or take the extra mile and code the outp equivalent in PTB (that
% would be nice).
%
% To do before you start:
% Set the baselocation for the experiment in SetParams around line 420:
% p.path.baselocation variable. this location will be used to save
% the experiment-related data for the current subject.
%
%
% Example usage:
% exp_FearGen_ForAll(12,3,4,1,8.43); runs the Conditioning paradigm (3) for
% participant 12, using the stimulus sequence 4 where the CS+ face is
% face number 1 for a participant who has a shock intensity of 8.43.
%
%
% Selim Onat
debug = 0;%debug mode => 1: transparent window enabling viewing the background.
trial_info = 0;
EyelinkWanted = 0;%is Eyelink wanted?
mrt = 0;
lab = '204';
%replace parallel port function with a dummy function
if ~IsWindows
%OUTP.m is used to communicate with the parallel port, mainly to send
%triggers to the physio-computer or Digitimer device (which is used to give
%shocks). OUTP is a cogent function, so it only works with Windows. In
%Unix the same functionality can also be obtained with PTB, but it is not
%coded in this program yet. So to communicate via the parallel port, there
%are two options: 1/install cogent + outp, or 2/ use equivalent of OUTP
%in PTB. This presentation will now replace the OUTP.m function with
%the following code, which simply does nothing but allows the program
%run.
%% outp = @(x,y) 1;
end
if nargin ~= 2
fprintf('Wrong number of inputs\n');
keyboard;
end
commandwindow;%focus on the command window, so that output is not written on the editor
%clear everything
clear mex global functions;%clear all before we start.
if IsWindows%clear cogent if we are in Windows and rely on Cogent for outp.
cgshut;
global cogent;
end
%%%%%%%%%%%load the GETSECS mex files so call them at least once
GetSecs;
WaitSecs(0.001);
%
el = [];%eye-tracker variable
p = [];%parameter structure that contains all info about the experiment.
s = [];
phase = 0; %for now
p.var.ExpPhase = 0;
trun = 6;
SetParams;%set parameters of the experiment
SetPTB;%set visualization parameters.
%
%init all the variables
t = [];
nTrial = 0;
ntTrial = 0;
%%
%Time Storage
TimeEndStim = [];
TimeStartShock = [];
TimeTrackerOff = [];
TimeCrossOn = [];
p.var.event_count = 0;
%%
InitEyeLink;
WaitSecs(2);
KbQueueStop(p.ptb.device);
KbQueueRelease(p.ptb.device);
%save again the parameter file
save(p.path.path_param,'p');
if EyelinkWanted
CalibrateEL;
ShowInstruction(299,0,5);
end
%% Instructions
p.var.ExpPhase = 1;%set this after the calibration;
for ninst = [1 2 3]
ShowInstruction(ninst,1);
end
% % ShowInstruction(5,1); %has been done in discr. task
% % ConfirmIntensity;
for ninst = [4 401:406]
ShowInstruction(ninst,1);
end
for phase = 1:trun
%%
press2shock = p.presentation(phase).press2shock(p.presentation(phase).world);
BlockInstruction(phase,press2shock,1)
PresentStimuli;
fprintf('Now saving p at end of block %d.\n',phase)
save(p.path.path_param,'p');
end
fprintf('Going into AskStimRating mode.\n');
AskStimRating;%make sure that scanner doesnt stop prematurely asa the stim offset
RateShockIntensity;
% AskStimRating;%make sure that scanner doesnt stop prematurely asa the stim offset
% if phase == 6
% if EyelinkWanted
% CalibrateEL;
% AskDetection;
% end
% fprintf('Going into AskStimRating mode.\n');
%get the eyelink file back to this computer
StopEyelink(p.path.edf);
%trim the log file and save
p.out.log = p.out.log(sum(isnan(p.out.log),2) ~= size(p.out.log,2),:);
%shift the time so that the first timestamp is equal to zero
p.out.log(:,1) = p.out.log(:,1) - p.out.log(1);
p.out.log = p.out.log;%copy it to the output variable.
save(p.path.path_param,'p');
%
%move the file to its final location.
movefile(p.path.subject,p.path.finalsubject);
%close everything down
cleanup;
function AskDetectionSelectable
%asks subjects to select the face that was associated with a shocks
positions = circshift(1:8,[1 Shuffle(1:8,1)]);%position of the marker
p.var.ExpPhase = 4;
ShowInstruction(8,1);
%%
increment([p.keys.increase p.keys.decrease]) = [1 -1];%key to increment mapping
%%
ok = 1;
while ok
DrawCircle;
Screen('FrameOval', p.ptb.w, [1 1 0], p.stim.circle_rect(positions(1),:), 2);%draw the marker circle somewhere random initially.
Screen('Flip',p.ptb.w);
[~, keyCode, ~] = KbStrokeWait(p.ptb.device);%observe key presses
keyCode = find(keyCode);
if length(keyCode) == 1%this loop avoids crashes to accidential presses of meta keys
if (keyCode == p.keys.increase) || (keyCode == p.keys.decrease)
positions = circshift(positions,[0 increment(keyCode)]);
elseif keyCode == p.keys.confirm
WaitSecs(0.1);
ok = 0;
end
end
end
%%
Screen('FillRect', p.ptb.w , p.stim.bg, p.ptb.imrect );
Screen('Flip',p.ptb.w);
ShowInstruction(14,0,10);
p.out.selectedface = p.stim.circle_order(positions(1));
end
function DrawCircle
for npos = 1:p.stim.tFace
Screen('DrawTexture', p.ptb.w, p.ptb.stim_sprites(p.stim.circle_file_id(npos)),[],p.stim.circle_rect(npos,:));
%Screen('DrawText', p.ptb.w, sprintf('%i_%i_%i',p.stim.circle_order(npos),p.stim.circle_file_id(npos),npos),mean(p.stim.circle_rect(npos,[1 3])) ,mean(p.stim.circle_rect(npos,[2 4])));
end
end
function [myrect]=angle2rect(A)
factor = 1.9;%factor resize the images
[x y] = pol2cart(A./180*pi,280);%randomly shift the circle
left = x+p.ptb.midpoint(1)-p.stim.width/2/factor;
top = y+p.ptb.midpoint(2)-p.stim.height/2/factor;
right = left+p.stim.width/factor;
bottom = top+p.stim.height/factor;
myrect = [left top right bottom];
end
function ConfirmIntensity
%Compute the intensity we want to deliver to the subject.
p.var.ShockIntensity = p.out.PainThreshold*p.out.ShockFactor;
%
ShowInstruction(9,1);
%
if strcmp(p.hostname,'blab0') && strcmp(lab,'204')
%
ShowInstruction(501,1);% Experimenter message.
WaitSecs(2);
ShowInstruction(10,0,1+rand(1));%shock is coming message...
t = GetSecs + p.duration.shock;
while GetSecs < t;
Buzz;
end
%
message = 'Bewege den "Zeiger" mit der rechten und linken Pfeiltaste\n und bestätige deine Einschätzung mit der mit der Leertaste.';
rect = [p.ptb.width*0.2 p.ptb.midpoint(2) p.ptb.width*0.6 100];
response = RatingSlider(rect,2,1,p.keys.increase,p.keys.decrease,p.keys.confirm,{ 'nicht\nerträglich' 'erträglich'},message,0);
if response == 2
ShowInstruction(502,1); % Stimulation OK.
fprintf('All is fine :)\n');
fprintf('Subject confirmed the shock intensity inside the scanner...\n');
fprintf('INTENSITY TO BE USED FOR THE MAIN EXPERIMENT: %g mA\n',p.var.ShockIntensity);
p.out.ShockIntensity = p.var.ShockIntensity;
return;
elseif response == 1
ShowInstruction(503,1); % Stimulation not OK.
fprintf('Shit... :(, %g is too much for the subject\n',p.var.ShockIntensity);
fprintf('We will try a little milder intensity.\n');
p.out.ShockFactor = p.out.ShockFactor - 0.05;
ConfirmIntensity;
end
else
%
fprintf([repmat('=',1,50) '\n']);
fprintf('TEST SHOCK:\n');
fprintf('!!! ADJUST THE SHOCK INTENSITY ON THE DIGITIMER !!!\n');
fprintf(' The intensity is now: %g mA\n',p.var.ShockIntensity);
fprintf(' Experimenter: Press any key to deliver a shock.\n');
fprintf([repmat('=',1,50) '\n']);
%
[secs, keyCode, deltaSecs] = KbStrokeWait(p.ptb.device);
ShowInstruction(10,0,1+rand(1));%shock is coming message...
t = GetSecs + p.duration.shock;
while GetSecs < t;
Buzz;
end
%
message = 'Bewege den "Zeiger" mit der rechten und linken Pfeiltaste\n und bestätige deine Einschätzung mit der mit der Leertaste.';
rect = [p.ptb.width*0.2 p.ptb.midpoint(2) p.ptb.width*0.6 100];
response = RatingSlider(rect,2,1,p.keys.increase,p.keys.decrease,p.keys.confirm,{ 'nicht\nerträglich' 'erträglich'},message,0);
if response == 2
fprintf('All is fine :)\n');
fprintf('Subject confirmed the shock intensity inside the scanner...\n');
fprintf('INTENSITY TO BE USED FOR THE MAIN EXPERIMENT: %g mA\n',p.var.ShockIntensity);
p.out.ShockIntensity = p.var.ShockIntensity;
return;
elseif response == 1
fprintf('Shit... :(, %g is too much for the subject\n',p.var.ShockIntensity);
fprintf('We will try a little milder intensity.\n');
p.out.ShockFactor = p.out.ShockFactor - 0.05;
ConfirmIntensity;
end
end
end
function PresentStimuli
%Enter the presentation loop and wait for the first pulse to
%arrive.
%wait for the dummy scans
if mrt
[secs] = WaitPulse(p.keys.pulse,p.mrt.dummy_scan);%will log it
else
secs = GetSecs;
end
KbQueueStop(p.ptb.device);
WaitSecs(.05);
KbQueueCreate(p.ptb.device);
KbQueueStart(p.ptb.device);%this means that from now on we are going to log pulses.
%If the scanner by mistake had been started prior to this point
%those pulses would have been not logged.
%log the pulse timings.
TimeEndStim = secs(end)- p.ptb.slack;%take the first valid pulse as the end of the last stimulus.
for nTrial = 1:p.presentation(phase).trialsperblock;
ntTrial = ntTrial+1;
%Get the variables that Trial function needs.
stim_id = p.presentation(phase).stim_id(nTrial);
ISI = p.presentation(phase).isi(nTrial);
ucs = p.presentation(phase).ucs(nTrial);
prestimdur = p.duration.prestim+rand(1)*.25;
%
OnsetTime = TimeEndStim + ISI - p.ptb.slack;
fprintf('Block %d: %03d of %03d (%02d of %02d total). S: %d, ISI: %d, UCS: %d, OnsetTime: %f secs.\n ',phase,nTrial,p.presentation(phase).trialsperblock,ntTrial,p.presentation(phase).tTrial,stim_id,ISI,ucs,OnsetTime);
%Start with the trial, here is time-wise sensitive must be
%optimal
[TimeEndStim] = Trial(nTrial,ntTrial,OnsetTime, prestimdur, stim_id , ucs);
%
%dump it
[keycode, secs] = KbQueueDump;%this contains both the pulses and keypresses.
%log everything but "pulse keys" as pulses, not as keypresses.
pulses = (keycode == p.keys.pulse);
if any(~pulses);%log keys presses if only there is one
Log(secs(~pulses),7,keycode(~pulses));
end
if any(pulses);%log pulses if only there is one
Log(secs(pulses),0,keycode(pulses));
end
%now we have to detect if the subject has pressed the CONFIRM
%key while the ODDBALL stimulus was on the screen.
% if any((keycode == p.keys.confirm) & (secs > OnsetTime) & (secs <= TimeEndStim))
% p.out.response(nTrial) = 1;
% fprintf('Subject Pressed the Hit Key!!\n');
% end
% if mod(nTrial,p.presentation(phase).trialsperblock)==0%LK change later.
% end
end
ShowInstruction(15,0,3)
DeliverCostShocks(ntTrial)
%wait 6 seconds for the BOLD signal to come back to the baseline...
KbQueueStop(p.ptb.device);
KbQueueRelease(p.ptb.device);
if mrt
if p.var.ExpPhase > 0
WaitPulse(p.keys.pulse,p.mrt.dummy_scan);%
fprintf('OK!! Stop the Scanner\n');
end
end
%dump the final events
[keycode, secs] = KbQueueDump;%this contains both the pulses and keypresses.
%log everything but "pulse keys" as pulses, not as keypresses.
pulses = (keycode == p.keys.pulse);
if any(~pulses);%log keys presses if only there is one
Log(secs(~pulses),7,keycode(~pulses));
end
if any(pulses);%log pulses if only there is one
Log(secs(pulses),0,keycode(pulses));
end
%stop the queue
KbQueueStop(p.ptb.device);
KbQueueRelease(p.ptb.device);
fprintf('Waiting 2 sec for a short break after block...\n')
WaitSecs(1);
end
function [TimeEndStim]=Trial(nTrial,ntTrial,TimeStimOnset , jitter, stim_id , ucs)
cond_id = p.presentation(phase).cond_id(nTrial);
if nTrial > 1
counter = p.out.counter(ntTrial-1);
fprintf('counter = %02d\n.',counter);
elseif nTrial == 1%mod(nTrial,p.presentation(phase).trialsperblock)==1
counter = 0;
fprintf('New block, counter set to zero.\n')
end
% fprintf('counter = %d\n',counter);
%plan all the times
TimeStimOnset = TimeStimOnset + jitter;
TimeBoxOnset = TimeStimOnset + p.duration.stim;
TimeOutcome = TimeStimOnset + p.duration.stim + p.duration.outcomedelay;
TimeEndStim = TimeStimOnset + p.duration.stim + p.duration.outcomedelay + p.duration.shock;
TimeTrackerOff = TimeStimOnset + p.duration.stim + p.duration.outcomedelay + p.duration.shock + p.duration.keep_recording;
% fprintf('\nPlanned timings: \nTimeStimOn: %f\nTimeBoxOn: %f\nTimeOutcome: %f\nTimeEndStim: %f\nTimeTrackerOff: %f\n',TimeStimOnset, TimeBoxOnset,TimeOutcome,TimeEndStim ,TimeTrackerOff)
fix = [p.ptb.CrossPosition_x p.ptb.CrossPosition_y];
if nTrial == 1
%% First fixation cross Onset
% FixCross = [fix(1)-1,fix(2)-p.ptb.fc_size,fix(1)+1,fix(2)+p.ptb.fc_size;fix(1)-p.ptb.fc_size,fix(2)-1,fix(1)+p.ptb.fc_size,fix(2)+1];
% Screen('FillRect', p.ptb.w, [0,0,0], FixCross');%draw the prestimus cross
DrawFormattedText(p.ptb.w, num2str(counter), 'center',p.ptb.midpoint(2)+p.stim.rectsize*p.stim.dist_counter,p.text.color);
DrawFormattedText(p.ptb.w, [num2str(press2shock) ' Knopfdrücke = 1 elektr. Reiz'], 'center',p.ptb.midpoint(2)+p.stim.rectsize*p.stim.dist_worldinfo,p.text.color);
Screen('DrawingFinished',p.ptb.w,0);
TimeCrossOn = Screen('Flip',p.ptb.w,0,0);
% fprintf('\nTimeCrossOn: %f\n',TimeCrossOn)
end
Log(TimeCrossOn,2,NaN);%cross onset.
%turn the eye tracker on
if EyelinkWanted
StartEyelinkRecording(ntTrial,stim_id,p.var.ExpPhase,stim_id,ucs,fix,mblock_id);%I would be cautious here, the first trial is never recorded in the EDF file, reason yet unknown.
end
%% Draw the stimulus to the buffer
Screen('DrawTexture', p.ptb.w, p.ptb.stim_sprites(stim_id),[],p.ptb.rect2draw);
DrawFormattedText(p.ptb.w, num2str(counter), 'center',p.ptb.midpoint(2)+p.stim.rectsize*p.stim.dist_counter,p.text.color);
DrawFormattedText(p.ptb.w, [num2str(press2shock) ' Knopfdrücke = 1 elektr. Reiz'], 'center',p.ptb.midpoint(2)+p.stim.rectsize*p.stim.dist_worldinfo,p.text.color);
if trial_info
DrawFormattedText(p.ptb.w, sprintf('Trial No %d, cond_id: %02d stim_id: %02d filename = %s.',stim_id,p.presentation(phase).cond_id(nTrial),p.stim.label{stim_id}), 'center',p.ptb.midpoint(2)-p.stim.rectsize-p.stim.dist_worldinfo,p.text.color);
end
% Screen('DrawDots', p.ptb.w, [p.ptb.midpoint(1) p.ptb.midpoint(2)], 10, [0 0 0], [], 2);
Screen('DrawingFinished',p.ptb.w,0);
%% STIMULUS ONSET
TimeStimOnset = Screen('Flip',p.ptb.w,TimeStimOnset,0);%asap and dont clear
% fprintf('Real TimeStimO: %f secs.\n',TimeStimOnset)
%send eyelink and ced a marker asap
if EyelinkWanted
Eyelink('Message', 'Stim Onset');
Eyelink('Message', 'SYNCTIME');
end
MarkCED( p.com.lpt.address, p.com.lpt.StimOnset );%this actually didn't really work nicely.
%the first stim onset pulse is always missing. This could be due to
%the fact that the state of the port was already 1 and thus CED
%didn't realize this command.
Log(TimeStimOnset,3,stim_id);%log the stimulus onset
kdown = 0;
timedout = false;
press_is_known = false;
while ~timedout %GetSecs < TimeBoxOnset%need sth like to so that we dont get x many key presses, once it's registered and counted
[kdown,keyT, keyC] = KbCheck(p.ptb.device);%observe key presses %different nomenklature to avoid confusion with KbQueueDump
if keyC ~= 0
Log(keyT,7,keyC) %store keypress to Log
end
keyC = find(keyC);
if length(keyC) == 1%this loop avoids crashes to accidential presses of meta keys
if keyC == p.keys.confirm
if ~press_is_known %so that we don't count perseverations
fprintf('Subject Pressed the Escape Key!\n');
%update counter display right away
counter = counter + 1;
Screen('DrawTexture', p.ptb.w, p.ptb.stim_sprites(stim_id),[],p.ptb.rect2draw);
DrawFormattedText(p.ptb.w, num2str(counter), 'center',p.ptb.midpoint(2)+p.stim.rectsize*p.stim.dist_counter,p.text.color);
DrawFormattedText(p.ptb.w, [num2str(press2shock) ' Knopfdrücke = 1 elektr. Reiz'], 'center',p.ptb.midpoint(2)+p.stim.rectsize*p.stim.dist_worldinfo,p.text.color);
Screen('DrawingFinished',p.ptb.w,0);
Screen('Flip',p.ptb.w,0,0);%asap and dont clear
p.out.response(ntTrial) = 1;
p.out.RT(ntTrial) = keyT - TimeStimOnset;
press_is_known = true;
end
end
end
if GetSecs >= TimeBoxOnset
timedout = true;
end
end
% fprintf('Done with KBcheck loop\n')
% fprintf('Now: %f secs.\n',GetSecs)
%% Draw Yellow Frame with Stimulus
Screen('DrawTexture', p.ptb.w, p.ptb.stim_sprites(stim_id),[],p.ptb.rect2draw);
DrawFormattedText(p.ptb.w, num2str(counter), 'center',p.ptb.midpoint(2)+p.stim.rectsize*p.stim.dist_counter,p.text.color);
DrawFormattedText(p.ptb.w, [num2str(press2shock) ' Knopfdrücke = 1 elektr. Reiz'], 'center',p.ptb.midpoint(2)+p.stim.rectsize*p.stim.dist_worldinfo,p.text.color); Screen('FrameRect',p.ptb.w, [255 255 0], p.ptb.rectbox, p.stim.rect_pix);
if trial_info
DrawFormattedText(p.ptb.w, sprintf('Trial No %d, cond_id: %02d stim_id: %02d filename = %s.',stim_id,cond_id,p.stim.label{stim_id}), 'center',p.ptb.midpoint(2)-p.stim.rectsize-p.stim.dist_worldinfo,p.text.color);
end
Screen('DrawingFinished',p.ptb.w,0);
TimeBoxOnset = Screen('Flip',p.ptb.w,[],0);
% fprintf('TimeBoxOn: %f\n',TimeBoxOnset)
Log(TimeBoxOnset,4,ntTrial);
TimeOutcome = WaitSecs('UntilTime',TimeOutcome);
%% shock if UCS
if ucs && ~p.out.response(ntTrial)==1
% MarkCED(p.com.lpt.address, p.com.lpt.ucs);
%Deliver shock and stim off immediately
fprintf('Buzz at %f.\n',GetSecs)
if EyelinkWanted
Eyelink('Message', 'UCS Onset');
end
Log(GetSecs,5,cond_id) %lets say cond_id is during the task, 99 is after it (punishment phase)
while GetSecs < TimeEndStim;
Buzz;%this is anyway sent to CED.
end
else
WaitSecs('UntilTime',TimeEndStim);
end
%% Stimulus Offset - switch to fixation cross
% FixCross = [fix(1)-1,fix(2)-p.ptb.fc_size,fix(1)+1,fix(2)+p.ptb.fc_size;fix(1)-p.ptb.fc_size,fix(2)-1,fix(1)+p.ptb.fc_size,fix(2)+1];
% Screen('FillRect', p.ptb.w, [0 0 0], FixCross');%draw the prestimus cross atop
DrawFormattedText(p.ptb.w, num2str(counter), 'center',p.ptb.midpoint(2)+p.stim.rectsize*p.stim.dist_counter,p.text.color);
DrawFormattedText(p.ptb.w, [num2str(press2shock) ' Knopfdrücke = 1 elektr. Reiz'], 'center',p.ptb.midpoint(2)+p.stim.rectsize*p.stim.dist_worldinfo,p.text.color);
Screen('DrawingFinished',p.ptb.w,0);
TimeCrossOn = Screen('Flip',p.ptb.w,0,0);
% fprintf('CrossOn: %f\n',TimeCrossOn)
Log(TimeCrossOn,6,ntTrial)
Log(TimeCrossOn,2,ntTrial)
%% record some more eye data after stimulus offset.
WaitSecs('UntilTime',TimeTrackerOff);
if EyelinkWanted
Eyelink('Message', 'Stim Offset');
Eyelink('Message', 'BLANK_SCREEN');
end
TimeTrackerOff = StopEyelinkRecording;
p.out.counter(ntTrial) = counter;%sum(p.out.response(1:nTrial));
end
function [TimeEndStim]=TrialRating(nTrial,TimeStimOnset , jitter, stim_id)
%plan all the times
TimeStimOnset = TimeStimOnset + jitter;
TimeEndStim = TimeStimOnset + p.duration.stim;
TimeTrackerOff = TimeStimOnset + p.duration.stim + p.duration.keep_recording;
% fprintf('\nPlanned timings: \nTimeStimOn: %f\nTimeEndStim: %f\nTimeTrackerOff: %f\n',TimeStimOnset, TimeEndStim ,TimeTrackerOff)
fix = [p.ptb.CrossPosition_x p.ptb.CrossPosition_y];
if nTrial == 1001
%% First fixation cross Onset
% FixCross = [fix(1)-1,fix(2)-p.ptb.fc_size,fix(1)+1,fix(2)+p.ptb.fc_size;fix(1)-p.ptb.fc_size,fix(2)-1,fix(1)+p.ptb.fc_size,fix(2)+1];
% Screen('FillRect', p.ptb.w, [0,0,0], FixCross');%draw the prestimus cross
Screen('DrawingFinished',p.ptb.w,0);
TimeCrossOn = Screen('Flip',p.ptb.w,0,0);
% fprintf('\nTimeCrossOn: %f\n',TimeCrossOn)
end
Log(TimeCrossOn,2,NaN);%cross onset.
%turn the eye tracker on
if EyelinkWanted
StartEyelinkRecording(nTrial,stim_id,p.var.ExpPhase,stim_id);%I would be cautious here, the first trial is never recorded in the EDF file, reason yet unknown.
end
%% Draw the stimulus to the buffer
Screen('DrawTexture', p.ptb.w, p.ptb.stim_sprites(stim_id),[],p.ptb.rect2draw);
%% STIMULUS ONSET
TimeStimOnset = Screen('Flip',p.ptb.w,TimeStimOnset,0);%asap and dont clear
% fprintf('Real Onset: %f secs.\n',TimeStimOnset)
%send eyelink and ced a marker asap
if EyelinkWanted
Eyelink('Message', 'Stim Onset');
Eyelink('Message', 'SYNCTIME');
end
MarkCED( p.com.lpt.address, p.com.lpt.StimOnset );%this actually didn't really work nicely.
%the first stim onset pulse is always missing. This could be due to
%the fact that the state of the port was already 1 and thus CED
%didn't realize this command.
Log(TimeStimOnset,3,stim_id+1000);%log the stimulus onset
WaitSecs('UntilTime',TimeEndStim);
%% Stimulus Offset - switch to fixation cross
% FixCross = [fix(1)-1,fix(2)-p.ptb.fc_size,fix(1)+1,fix(2)+p.ptb.fc_size;fix(1)-p.ptb.fc_size,fix(2)-1,fix(1)+p.ptb.fc_size,fix(2)+1];
% Screen('FillRect', p.ptb.w, [0 0 0], FixCross');%draw the prestimus cross atop
TimeCrossOn = Screen('Flip',p.ptb.w,0,0);
% fprintf('CrossOn: %f\n',TimeCrossOn)
Log(TimeCrossOn,6,nTrial)
Log(TimeCrossOn,2,nTrial)
%% record some more eye data after stimulus offset.
WaitSecs('UntilTime',TimeTrackerOff);
if EyelinkWanted
Eyelink('Message', 'Stim Offset');
Eyelink('Message', 'BLANK_SCREEN');
end
TimeTrackerOff = StopEyelinkRecording;
end
function SetParams
%mrt business
p.mrt.dummy_scan = 0;%this will wait until the 6th image is acquired.
p.mrt.LastScans = 0;%number of scans after the offset of the last stimulus
p.mrt.tr = 2;%in seconds.
%will count the number of events to be logged
p.var.event_count = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% relative path to stim and experiments
%Path Business.
[~, hostname] = system('hostname');
p.hostname = deblank(hostname);
if strcmp(p.hostname,'blab0')
p.path.baselocation = 'U:\kampermann\FearAdapt_Pilote';
else
p.path.baselocation = 'C:\Users\Lea\Documents\Experiments\FearAdapt_Pilote';
end
%create the base folder if not yet there.
if exist(p.path.baselocation) == 0
mkdir(p.path.baselocation);
end
p.subID = sprintf('sub%02d',subject);%subject id
p.path.experiment = [p.path.baselocation filesep 'data\'];
p.path.stim = [p.path.experiment p.subID filesep 'exp' filesep 'stim\'];
p.path.stim24 = [p.path.stim '24bit' filesep];%location of 24bit stimuli, useful only to send it to the eyelink system
% p.path.stim_cut = [p.path.stim 'cut' filesep];%stimuli without borders, necessary for the facecircle
%
timestamp = datestr(now,30);%the time_stamp of the current experiment.
p.path.subject = [p.path.experiment 'tmp' filesep p.subID '_exp_' timestamp filesep ];%subject folder, first we save it to the temp folder.
p.path.finalsubject = [p.path.experiment p.subID '\exp\'];%final location of the subject folder
p.path.path_edf = [p.path.subject 'eye' filesep];%location of the edf file in the eyelink computer
p.path.edf = sprintf([p.subID 'p%02d.edf' ],phase);%EDF file in the stimulus computer
p.path.path_param = [p.path.subject 'stimulation' filesep 'data.mat'];%location of the paradigm file.
%create folder hierarchy for this subject
mkdir(p.path.subject);
mkdir([p.path.subject 'scr']);%location for the SCR data
mkdir([p.path.subject 'eye']);%location for the edf file and eye-movement related data.
mkdir([p.path.subject 'stimulation']);%location of the stimulus presentation paradigm
mkdir([p.path.subject 'midlevel']);%other data.
%% %%%%%%%%%%%%%%%%%%%%%%%%%
%get stim files
[p.stim.files, p.stim.label] = FileMatrix([p.path.stim '*.png']);%read in the stimlus
p.stim.tFile = numel(p.stim.files);%number of different files
%
display([mat2str(p.stim.tFile) ' found in the destination.']);
%set the background gray according to the background of the stimuli
for ii = 1:p.stim.tFile;
im = imread(p.stim.files{ii});
bg(ii) = im(1,1,1);
end
%is all the captured bg values the same?
if sum(diff(bg))==0;
%if so take it as the bg color
p.stim.bg = double([bg(1) bg(1) bg(1)]);
else
fprintf('background luminance was not successfully detected...\n')
keyboard;
end
%bg of the rating screen.
p.stim.bg_rating = p.stim.bg;
p.stim.white = [255 255 255];
%% font size and background gray level
p.text.fontname = 'Times New Roman';
p.text.fontsize = 18;%30;
p.text.fixsize = 60;
p.text.color = [0 0 0];
%rating business, how many ticks
p.rating.division = 10;%number of divisions for the rating slider
p.rating.repetition = 2;%how many times a given face has to be repeated...
%% get the actual stim size (assumes all the same)
info = imfinfo(p.stim.files{1});
p.stim.width = info.Width;
p.stim.height = info.Height;
%% define rect around stimulus for outcome
p.stim.rectsize = 300; %one half only, will be drawn around midpoint, that we get from resolution in SetPTB, which is not yet run.
p.stim.rect_pix = 8; %one half only, will be dr
p.stim.dist_counter = 1.2;
p.stim.dist_worldinfo = 1.5;
%% keys to be used during the experiment:
%This part is highly specific for your system and recording setup,
%please enter the correct key identifiers. You can get this information calling the
%KbName function and replacing the code below for the key below.
%1, 6 ==> Right
%2, 7 ==> Left
%3, 8 ==> Down
%4, 9 ==> Up (confirm)
%5 ==> Pulse from the scanner
% KbName('UnifyKeyNames');
p.keys.confirm = KbName('space');%
p.keys.increase = KbName('right');
p.keys.decrease = KbName('left');
p.keys.pulse = KbName('5%');
p.keys.el_calib = KbName('v');
p.keys.el_valid = KbName('c');
p.keys.escape = KbName('esc');
%% %%%%%%%%%%%%%%%%%%%%%%%%%
%Communication business
%parallel port
if strcmp(p.hostname,'blab0') && strcmp(lab,'204')
p.com.lpt.address = 59392;%hex2dec('0378A');%parallel port of the computer.
elseif strcmp(p.hostname,'blab0') && strcmp(lab,'201')
p.com.lpt.address = hex2dec('0378A');
else
p.com.lpt.address = 888;%parallel port of the computer.
end
%codes for different events that are sent for logging in the
%physiological computer.
p.com.lpt.digitimer = 1;%12;%8
p.com.lpt.StimOnset = 4;
% %%%%%%%%%%%%%%%%%%%%%%%%%%% Parallel port settings
% p.com.lpt.BVRaddress = 59392; %49232; %49020
% p.com.lpt.CEDaddress = 888 %55296; %888;
% if p_slave_on
% p.com.lpt.CEDaddress = 59392;
% end
%
% p.com.lpt.duration = 0.005;
%
% % p.com.lpt.CEDduration = 0.005;
% % if p.mri.on == 1
% % p.com.lpt.BVRduration = 0.005;
% % else
% % p.com.lpt.BVRduration = 0;
% % end
% % Codes for different events
% p.com.lpt.scannerPulseOnset = 255;
% p.com.lpt.FixOnset = 1;
% p.com.lpt.StimOnset = 2;
% p.com.lpt.StartleOnset = 4;
%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%timing business
%these are the intervals of importance
%time2fixationcross->cross2onset->onset2shock->shock2offset
%these (duration.BLA) are average duration values:
p.duration.stim = 3;%2;%s
p.duration.shock = 0.1;%s;x
p.duration.shockpulse = 0.005;%ms; duration of each individual pulses
p.duration.intershockpulse = 0.01;%ms; and the time between each pulse
p.duration.keep_recording = 0.25;%this is the time we will keep recording (eye data) after stim offset.
p.duration.prestim = .85;
p.duration.outcomedelay = 3;
speedup = 1; %factor to speed up things, e.g. for debugging or testing
p.duration.outcomedelay = p.duration.outcomedelay /speedup;
p.duration.stim = p.duration.stim /speedup;
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%stimulus sequence: Explanation of the fields:
% s = load([p.path.baselocation '\seq\exp\seq.mat']);
s = load([p.path.baselocation '\seq\exp\seq_6runs_38trials.mat']);
s = s.seq(subject,:);
%this will deal all the presentation sequence related information
p.presentation = s;
clear s;
%% create the randomized design
%Record which Phase are we going to run in this run.
% p.stim.phase = phase;
p.out.rating = [];%will contain explicite ratings of UCS likelihood
p.out.log = zeros(1000000,4).*NaN;%Experimental LOG.
p.out.response = zeros(p.presentation(1).tTrial,1);%
p.out.RT = nan(p.presentation(1).tTrial,1);%
p.out.counter = zeros(p.presentation(1).tTrial,1);%
p.out.PainThreshold = PainThreshold;%the pain threshold (i.e. pain intensity where p(painful) = .5 for the subject, it is an input argument, must be computed before the experiment.
p.out.ShockFactor = 2;%factor to multiply the PainThreshold with, will use this factor to propose the experimenter the final shock intensity to be used during the FearGen Experiment. p.out.ShockIntensityRating = nan(1,10);
p.out.ShockIntensityRating = nan(1,10);
%%
p.var.current_bg = p.stim.bg;%current background to be used.
%Save the stuff
save(p.path.path_param,'p');
%
function [FM labels] = FileMatrix(path)
%Takes a path with file extension associated to regexp (e.g.
%C:\blabl\bla\*.bmp) returns the file matrix
dummy = dir(path);
nstim = numel(dummy);
for nst = 1:nstim
FM{nst} = [fileparts(path) filesep dummy(nst).name];
end
labels = {dummy(:).name};
end
end
function RateShockIntensity
ShowInstruction(505,1);
%instruction has been shown already
%
%
WaitSecs(2);
ShowInstruction(10,0,1+rand(1));%shock is coming message...
t = GetSecs + p.duration.shock;
while GetSecs < t;
Buzz;
end
%
WaitSecs(2);
message1 = 'Bewegen Sie den "Zeiger" mit der rechten und linken Pfeiltaste\n und bestätigen Sie dann mit der Leertaste.';
rect = [p.ptb.width*0.2 p.ptb.midpoint(2) p.ptb.width*0.6 100];
response = RatingSlider(rect,10,Shuffle(1:10,1),p.keys.increase,p.keys.decrease,p.keys.confirm,{ 'gar nicht\nschmerzhaft' 'maximal\nschmerzhaft'},message1,1);
p.out.ShockIntensityRating(find(isnan(p.out.ShockIntensityRating),1)) = response;
Screen('FillRect',p.ptb.w,p.stim.bg);
Screen('Flip',p.ptb.w);
WaitSecs(2);
end
function AskStimRating
p.var.ExpPhase = 5;
p.var.current_bg = p.stim.bg_rating;
%% create the order of presentation and balance the position of fixation cross
nseq = 0;
rating_seq = [];
pos1_seq = [];
idx = [];
stim_order = 1:p.stim.tFile;
while nseq < p.rating.repetition
nseq = nseq + 1;
[dummy idx] = Shuffle( stim_order );
rating_seq = [rating_seq dummy];
%this balances both directions
pos1_seq = [pos1_seq ones(1,p.stim.tFile)];%+1 to make [0 1] --> [1 2]
end
rating_seq = rating_seq(:);
pos1_seq = pos1_seq(:);
%%
message = GetText(11);
SliderTextL = GetText(13);
SliderTextR = GetText(12);
% set the background to different color
Screen('FillRect', p.ptb.w , p.var.current_bg );
Screen('Flip',p.ptb.w);
WaitSecs(2);
%
ShowInstruction(7,1);
rect = [p.ptb.width*0.2 p.ptb.midpoint(2) p.ptb.width*0.6 100];%for the rating slider
tRatend = length(rating_seq);
%save the rating sequence just for security
p.out.rating_seq = rating_seq;
p.out.pos1_seq = pos1_seq;
%run over all the pictures to be rated.
for nRatend = 1:tRatend;
%
%the variable that are used by Trial function
stim_id = rating_seq(nRatend);
fix_y = pos1_seq(nRatend);
%
next_stim_id = [];%this is a trick, otherwise a fixation cross appears right before the rating :(
next_pos1 = [];
%
% %to send know the distance here, little dummy setup:
% dummy = -135:45:180;
% dist = dummy(stim_id);
% show the picture
% [TimeEndStim]=TrialRating(nTrial,TimeStimOnset , jitter, stim_id)
TrialRating(1000+nRatend,GetSecs+1,0,stim_id);
% show the slider
rate(nRatend,1) = RatingSlider(rect, p.rating.division, Shuffle(1:p.rating.division,1), p.keys.increase, p.keys.decrease, p.keys.confirm, {SliderTextL{1} SliderTextR{1}},message,1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Verbose the rating of the subject
fprintf('============\nRating Results %d (%d/%d):\n', stim_id, nRatend, tRatend);
dummy = rating_seq(1:nRatend);%trials shown so far
for iii = 1:p.stim.tFile
r = round(mean(rate(dummy == iii)));
if isnan(r)
r = 0;
end
if ismember(iii,[2 3]) %stimulus 2 and 3 are stimuli for condition 2 and 4
fprintf('Stimulus %02d: * %s \n',iii,repmat('+',1,1+r));
else
fprintf('Stimulus %02d: %s \n',iii,repmat('+',1,1+r));
end
end
end
%sort the stim_ids and then sort the same the rates and make a
%matrix out of that to store
[~, i] = sort(rating_seq);
rate = reshape(rate(i),p.rating.repetition,p.stim.tFile)';
p.out.rating = rate;
save(p.path.path_param,'p');
Screen('FillRect',p.ptb.w,p.var.current_bg);
%
save(p.path.path_param,'p');
end
function [rating] = RatingSlider(rect,tSection,position,up,down,confirm,labels,message,numbersOn)
%
%Detect the bounding boxes of the labels.
for nlab = 1:2
[~ , ~, bb(nlab,:)]=DrawFormattedText(p.ptb.w,labels{nlab}, 'center', 'center', p.text.color,[],[],[],2);
Screen('FillRect',p.ptb.w,p.var.current_bg);
end
bb = max(bb);
bb_size = bb(3)-bb(1);%vertical size of the bb.
%
DrawSkala;
ok = 1;
while ok == 1
[secs, keyCode, ~] = KbStrokeWait(p.ptb.device);
keyCode = find(keyCode);
Log(secs,7,keyCode);
if length(keyCode) == 1%this loop avoids crashes to accidential presses of meta keys
if (keyCode == up) || (keyCode == down)
next = position + increment(keyCode);
if next < (tSection+1) && next > 0
position = position + increment(keyCode);
end
DrawSkala;
elseif keyCode == confirm
WaitSecs(0.1);
ok = 0;
Screen('FillRect',p.ptb.w,p.var.current_bg);
t=Screen('Flip',p.ptb.w);
end
end
end
function DrawSkala
%rating = tSection - position + 1;
rating = position ;
increment([up down]) = [1 -1];%delta
tick_x = linspace(rect(1),rect(1)+rect(3),tSection+1);%tick positions
tick_size = rect(3)./tSection;
ss = tick_size/5*0.9;%slider size.
%
for tick = 1:length(tick_x)%draw ticks
Screen('DrawLine', p.ptb.w, [255 0 0], tick_x(tick), rect(2), tick_x(tick), rect(2)+rect(4) , 3);
if tick <= tSection && numbersOn
Screen('TextSize', p.ptb.w,p.text.fontsize);
DrawFormattedText(p.ptb.w, mat2str(tick) , tick_x(tick)+ss/2, rect(2)+rect(4), [0 0 0 ]);
Screen('TextSize', p.ptb.w,p.text.fontsize);
end
if tick == 1
DrawFormattedText(p.ptb.w, labels{1},tick_x(tick)-bb_size*1.4,rect(2), [0 0 0 ]);
elseif tick == tSection+1
DrawFormattedText(p.ptb.w, labels{2},tick_x(tick)+bb_size*0.4,rect(2), [0 0 0 ]);
end
end
%slider coordinates
slider = [ tick_x(position)+tick_size*0.1 rect(2) tick_x(position)+tick_size*0.9 rect(2)+rect(4)];
%draw the slider
Screen('FillRect',p.ptb.w, [0 0 0], round(slider));
Screen('TextSize', p.ptb.w,p.text.fontsize);
DrawFormattedText(p.ptb.w,message, 'center', p.ptb.midpoint(2)*0.2, p.text.color,[],[],[],2);
Screen('TextSize', p.ptb.w,p.text.fontsize);
t = Screen('Flip',p.ptb.w);
Log(t,-2,NaN);
end
end
function BlockInstruction(nBlock,press2shock,waitforkeypress,varargin)
%ShowInstruction(nInstruct,waitforkeypress)
%if waitforkeypress is 1, ==> subject presses a button to proceed
%if waitforkeypress is 0, ==> text is shown for VARARGIN seconds.
[text]= sprintf('Block %d.\n In diesem Block gilt folgende Regel: \n\n %d Tastendrücke = 1 elektr. Reiz am Ende des Blocks.\n\nDrücken Sie die Leertaste, um zu starten.',nBlock,press2shock);
ShowText(text);
if waitforkeypress %and blank the screen as soon as the key is pressed
KbStrokeWait(p.ptb.device);
else
WaitSecs(varargin{1});
end
Screen('FillRect',p.ptb.w,p.var.current_bg);
t = Screen('Flip',p.ptb.w);
function ShowText(text)
Screen('FillRect',p.ptb.w,p.var.current_bg);
DrawFormattedText(p.ptb.w, text, 'center', 'center',p.text.color,[],[],[],2,[]);
t=Screen('Flip',p.ptb.w);
Log(t,-1,100+nBlock);
%show the messages at the experimenter screen
fprintf('=========================================================\n');
fprintf('Text shown to the subject:\n');
fprintf(text);
fprintf('=========================================================\n');
end
end
function ShowInstruction(nInstruct,waitforkeypress,varargin)
%ShowInstruction(nInstruct,waitforkeypress)
%if waitforkeypress is 1, ==> subject presses a button to proceed
%if waitforkeypress is 0, ==> text is shown for VARARGIN seconds.
[text]= GetText(nInstruct);
ShowText(text);
if waitforkeypress %and blank the screen as soon as the key is pressed
KbStrokeWait(p.ptb.device);
else
WaitSecs(varargin{1});
end
Screen('FillRect',p.ptb.w,p.var.current_bg);
t = Screen('Flip',p.ptb.w);
function ShowText(text)
Screen('FillRect',p.ptb.w,p.var.current_bg);
DrawFormattedText(p.ptb.w, text, 'center', 'center',p.text.color,[],[],[],2,[]);
t=Screen('Flip',p.ptb.w);
Log(t,-1,nInstruct);
%show the messages at the experimenter screen
fprintf('=========================================================\n');
fprintf('Text shown to the subject:\n');
fprintf(text);
fprintf('=========================================================\n');
end
end
function [text]=GetText(nInstruct)
if nInstruct == 0%Eyetracking calibration
text = ['Wir kalibrieren jetzt den Eye-Tracker.\n\n' ...
'Bitte fixieren Sie die nun folgenden weißen Kreise und \n' ...
'bleiben so lange darauf, wie sie zu sehen sind.\n\n' ...
'Nach der Kalibrierung dürfen Sie Ihren Kopf nicht mehr bewegen.\n'...
'Sollten Sie Ihre Position noch verändern müssen, tun Sie dies jetzt.\n'...