-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspace_cued_recall.m
1845 lines (1629 loc) · 69.1 KB
/
space_cued_recall.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 [cfg,expParam] = space_cued_recall(w,cfg,expParam,logFile,sesName,phaseName,phaseCount)
% function [cfg,expParam] = space_cued_recall(w,cfg,expParam,logFile,sesName,phaseName,phaseCount)
%
% Description:
% This function runs the cued recall test task.
%
% Intermixed test target and lure stimuli are stored in
% expParam.session.(sesName).(phaseName)(phaseCount).testStims_img and
% expParam.session.(sesName).(phaseName)(phaseCount).testStims_word.
% Target+lure test stimuli must already be sorted in presentation order.
%
%
% Inputs:
%
%
% Outputs:
%
%
% NB:
% Once agian, test targets+lures must already be sorted
% in presentation order!
%
% NB:
% Test response time is measured from when response key image appears on
% screen.
%
% % durations, in seconds
fprintf('Running %s %s (cr) (%d)...\n',sesName,phaseName,phaseCount);
phaseNameForParticipant = 'test';
% whether to use GetChar (false) or GetKbChar (true)
%
% Linux, OS X, and Windows can use GetChar; I think Windows Vista and
% Windows 7 need to use GetKbChar, but I have not tested this
useKbCheck = false;
%% set the starting date and time for this phase
thisDate = date;
startTime = fix(clock);
startTime = sprintf('%.2d:%.2d:%.2d',startTime(4),startTime(5),startTime(6));
%% determine the starting trial, useful for resuming
% set up progress file, to resume this phase in case of a crash, etc.
phaseProgressFile = fullfile(cfg.files.sesSaveDir,sprintf('phaseProgress_%s_%s_cr_%d.mat',sesName,phaseName,phaseCount));
if exist(phaseProgressFile,'file')
load(phaseProgressFile);
else
trialComplete = false(1,length(expParam.session.(sesName).(phaseName)(phaseCount).testStims_img));
phaseComplete = false; %#ok<NASGU>
save(phaseProgressFile,'thisDate','startTime','trialComplete','phaseComplete');
end
% find the starting trial
incompleteTrials = find(~trialComplete);
if ~isempty(incompleteTrials)
trialNum = incompleteTrials(1);
else
fprintf('All trials for %s %s (cr) (%d) have been completed. Moving on...\n',sesName,phaseName,phaseCount);
% release any remaining textures
Screen('Close');
% go to the next block
return
end
%% start the log file for this phase
phaseLogFile = fullfile(cfg.files.sesSaveDir,sprintf('phaseLog_%s_%s_cr_%d.txt',sesName,phaseName,phaseCount));
phLFile = fopen(phaseLogFile,'at');
%% record the starting date and time for this phase
expParam.session.(sesName).(phaseName)(phaseCount).date = thisDate;
expParam.session.(sesName).(phaseName)(phaseCount).startTime = startTime;
% put it in the log file
fprintf(logFile,'!!! Start of %s %s (%d) (%s) %s %s\n',sesName,phaseName,phaseCount,mfilename,thisDate,startTime);
fprintf(phLFile,'!!! Start of %s %s (%d) (%s) %s %s\n',sesName,phaseName,phaseCount,mfilename,thisDate,startTime);
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',...
thisGetSecs,...
expParam.subject,...
sesName,...
phaseName,...
phaseCount,...
cfg.stim.(sesName).(phaseName)(phaseCount).isExp,...
'PHASE_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',...
thisGetSecs,...
expParam.subject,...
sesName,...
phaseName,...
phaseCount,...
cfg.stim.(sesName).(phaseName)(phaseCount).isExp,...
'PHASE_START');
%% general preparation for recognition study and test
phaseCfg = cfg.stim.(sesName).(phaseName)(phaseCount);
testStims_img = expParam.session.(sesName).(phaseName)(phaseCount).testStims_img;
testStims_word = expParam.session.(sesName).(phaseName)(phaseCount).testStims_word;
if phaseCfg.isExp
imgStimDir = cfg.files.imgStimDir;
else
imgStimDir = cfg.files.imgStimDir_prac;
end
% default is to preload the images
if ~isfield(cfg.stim,'preloadImages')
cfg.stim.preloadImages = false;
end
% read the proper old new response key image
oldNewKeyImg = imread(cfg.files.recogTestOldNewRespKeyImg);
oldNewKeyImgHeight = size(oldNewKeyImg,1) * cfg.files.respKeyImgScale;
oldNewKeyImgWidth = size(oldNewKeyImg,2) * cfg.files.respKeyImgScale;
oldNewKeyImg = Screen('MakeTexture',w,oldNewKeyImg);
% read the proper sure maybe response key image
sureMaybeKeyImg = imread(cfg.files.recogTestSureMaybeRespKeyImg);
sureMaybeKeyImgHeight = size(sureMaybeKeyImg,1) * cfg.files.respKeyImgScale;
sureMaybeKeyImgWidth = size(sureMaybeKeyImg,2) * cfg.files.respKeyImgScale;
sureMaybeKeyImg = Screen('MakeTexture',w,sureMaybeKeyImg);
% set the old new response key image rectangle
oldNewKeyImgRect = SetRect(0, 0, oldNewKeyImgWidth, oldNewKeyImgHeight);
oldNewKeyImgRect = CenterRect(oldNewKeyImgRect, cfg.screen.wRect);
oldNewKeyImgRect = AlignRect(oldNewKeyImgRect, cfg.screen.wRect, 'bottom', 'bottom');
% set the sure maybe response key image rectangle
sureMaybeKeyImgRect = SetRect(0, 0, sureMaybeKeyImgWidth, sureMaybeKeyImgHeight);
sureMaybeKeyImgRect = CenterRect(sureMaybeKeyImgRect, cfg.screen.wRect);
sureMaybeKeyImgRect = AlignRect(sureMaybeKeyImgRect, cfg.screen.wRect, 'bottom', 'bottom');
% default is to not print out trial details
if ~isfield(cfg.text,'printTrialInfo') || isempty(cfg.text.printTrialInfo)
cfg.text.printTrialInfo = false;
end
% default is to not play sounds
if ~isfield(phaseCfg,'playSound') || isempty(phaseCfg.playSound)
phaseCfg.playSound = false;
end
% initialize beep player if needed
if phaseCfg.playSound
Beeper(1,0);
if ~isfield(phaseCfg,'correctSound')
phaseCfg.correctSound = 1000;
end
if ~isfield(phaseCfg,'incorrectSound')
phaseCfg.incorrectSound = 300;
end
if ~isfield(phaseCfg,'correctVol')
phaseCfg.correctVol = 0.4;
end
if ~isfield(phaseCfg,'incorrectVol')
phaseCfg.incorrectVol = 0.6;
end
end
% are they allowed to respond while the stimulus is on the screen?
if ~isfield(phaseCfg,'respDuringStim')
phaseCfg.respDuringStim = false;
end
% default is to show fixation during ISI
if ~isfield(phaseCfg,'fixDuringISI')
phaseCfg.fixDuringISI = true;
end
% default is to show fixation during preStim
if ~isfield(phaseCfg,'fixDuringPreStim')
phaseCfg.fixDuringPreStim = true;
end
% default is to show fixation with the stimulus
if ~isfield(phaseCfg,'fixDuringStim')
phaseCfg.fixDuringStim = true;
end
if ~isfield(phaseCfg,'impedanceAfter_nTrials')
phaseCfg.impedanceAfter_nTrials = 0;
end
if ~isfield(phaseCfg,'showRespInBreak')
phaseCfg.showRespInBreak = true;
end
% whether to ask the participant if they have any questions; only continues
% with experimenter's secret key
if ~isfield(phaseCfg.instruct,'questions')
phaseCfg.instruct.questions = true;
end
% if expParam.photoCellTest
% phaseCfg.impedanceBeforePhase = false;
% phaseCfg.impedanceAfter_nTrials = 0;
% phaseCfg.secUntilBlinkBreak = 0;
% end
%% set up text rectangles
% create a rectangle for placing fixation symbol using Screen('DrawText')
Screen('TextSize', w, cfg.text.fixSize);
fixRect = Screen('TextBounds', w, cfg.text.fixSymbol);
% center it in the middle of the screen
fixRect = CenterRect(fixRect, cfg.screen.wRect);
% get the X and Y coordinates
fixRectX = fixRect(1);
fixRectY = fixRect(2);
% create a rectangle for placing response symbol using Screen('DrawText')
Screen('TextSize', w, cfg.text.fixSize);
respRect = Screen('TextBounds', w, cfg.text.respSymbol);
% center it in the middle of the screen
respRect = CenterRect(respRect, cfg.screen.wRect);
% get the X and Y coordinates
respRectX = respRect(1);
respRectY = respRect(2);
%% Prepare the cued recall test task
stimImgRect_all = nan(length(testStims_img),4);
recallX_all = nan(length(testStims_img),1);
recallY_all = nan(length(testStims_img),1);
errorTextY_all = nan(length(testStims_img),1);
% initialize to hold all recallResponses
recallResp_all = {};
recallCounter = 0;
recallsInARowCounter = 0;
[~, screenCenterY] = RectCenter(cfg.screen.wRect);
% load up the stimuli for this block
testImgTex = nan(1,length(testStims_img));
message = sprintf('Preparing images, please wait...');
Screen('TextSize', w, cfg.text.basicTextSize);
% put the "preparing" message on the screen
DrawFormattedText(w, message, 'center', 'center', cfg.text.instructColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
% Update the display to show the message:
Screen('Flip', w);
for i = 1:length(testStims_img)
% make sure this stimulus exists
stimImgFile = fullfile(imgStimDir,testStims_img(i).categoryStr,testStims_img(i).fileName);
if exist(stimImgFile,'file')
% load up this stim's texture
stimImg = imread(stimImgFile);
% resize the image, if necessary
if size(stimImg,1) > cfg.stim.nRows
stimImg = imresize(stimImg,[cfg.stim.nRows, NaN]);
end
% crop the image, if necessary
if size(stimImg,2) > cfg.stim.cropWidth
widthCenter = round(size(stimImg,2) / 2);
stimImg = stimImg(:,(widthCenter - round(cfg.stim.cropWidth / 2)):(widthCenter + round(cfg.stim.cropWidth / 2)),:);
end
% set the coordinates that we will use later
stimImgHeight = size(stimImg,1) * cfg.stim.stimScale;
stimImgWidth = size(stimImg,2) * cfg.stim.stimScale;
% set the stimulus image rectangle
stimImgRect_all(i,:) = [0 0 stimImgWidth stimImgHeight];
stimImgRect_all(i,:) = CenterRect(stimImgRect_all(i,:), cfg.screen.wRect);
% put the recall text below the image
Screen('TextSize', w, cfg.text.fixSize);
recallRect = Screen('TextBounds', w, cfg.text.recallPrompt);
recallRect = CenterRect(recallRect, cfg.screen.wRect);
recallRect = AdjoinRect(recallRect, stimImgRect_all(i,:), RectBottom);
recallX_all(i) = recallRect(1);
recallY_all(i) = recallRect(2);
%recallY_all(i) = screenCenterY + (stimImgHeight / 2);
% text location for error (e.g., "too fast") or response text
errorTextY_all(i) = screenCenterY + (stimImgHeight / 2);
%responsePromptY_all(i) = screenCenterY + (stimImgHeight / 2);
if cfg.stim.preloadImages
testImgTex(i) = Screen('MakeTexture',w,stimImg);
% TODO: optimized?
%testImgTex(i) = Screen('MakeTexture',w,stimImg,[],1);
%elseif ~cfg.stim.preloadImages && i == length(testStims_img)
% still need to load the last image to set the rectangle
% stimImg = imread(fullfile(imgStimDir,testStims_img(i).categoryStr,testStims_img(i).fileName));
end
else
error('Test stimulus %s does not exist!',stimImgFile);
end
end
%% do an impedance check before the phase begins, if desired
if ~isfield(phaseCfg,'impedanceBeforePhase')
phaseCfg.impedanceBeforePhase = false;
end
if ~expParam.photoCellTest && expParam.useNS && phaseCfg.impedanceBeforePhase
% run the impedance break
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_START');
thisGetSecs = et_impedanceCheck(w, cfg, false, phaseName);
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_END');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_END');
end
%% start NS recording, if desired
% put a message on the screen as experiment phase begins
message = sprintf('Starting %s phase...',phaseNameForParticipant);
if expParam.useNS
% start recording
[NSStopStatus, NSStopError] = NetStation('StartRecording'); %#ok<NASGU,ASGLU>
% synchronize
[NSSyncStatus, NSSyncError] = NetStation('Synchronize'); %#ok<NASGU,ASGLU>
message = sprintf('Starting data acquisition for %s phase...',phaseNameForParticipant);
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'NS_REC_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'NS_REC_START');
end
Screen('TextSize', w, cfg.text.basicTextSize);
% draw message to screen
DrawFormattedText(w, message, 'center', 'center', cfg.text.basicTextColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
% put it on
Screen('Flip', w);
% Wait before starting trial
WaitSecs(5.000);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
% Clear screen to background color (our 'bgColor' as set at the beginning):
Screen('Flip', w);
%% show the test instructions
if ~expParam.photoCellTest
for i = 1:length(phaseCfg.instruct.cr)
WaitSecs(1.000);
et_showTextInstruct(w,cfg,phaseCfg.instruct.cr(i),cfg.keys.instructContKey,...
cfg.text.instructColor,cfg.text.instructTextSize,cfg.text.instructCharWidth);
end
% Wait a second before starting trial
WaitSecs(1.000);
end
%% questions? only during practice. continues with experimenter's key.
if ~expParam.photoCellTest && ~phaseCfg.isExp && phaseCfg.instruct.questions
questionsMsg.text = sprintf('If you have any questions about the %s phase,\nplease ask the experimenter now.\n\nPlease tell the experimenter when you are ready to begin the task.',phaseNameForParticipant);
et_showTextInstruct(w,cfg,questionsMsg,cfg.keys.expContinue,...
cfg.text.instructColor,cfg.text.instructTextSize,cfg.text.instructCharWidth);
% Wait a second before continuing
WaitSecs(1.000);
end
%% let them start when they're ready
if ~expParam.photoCellTest
if phaseCfg.isExp
expStr = '';
else
expStr = ' practice';
end
readyMsg.text = sprintf('Ready to begin%s %s phase.\nPress "%s" to start.',expStr,phaseNameForParticipant,cfg.keys.instructContKey);
et_showTextInstruct(w,cfg,readyMsg,cfg.keys.instructContKey,...
cfg.text.instructColor,cfg.text.instructTextSize,cfg.text.instructCharWidth);
% Wait a second before starting trial
WaitSecs(1.000);
end
%% Run recognition and cued recall test
% only check these keys
RestrictKeysForKbCheck([cfg.keys.recogOld, cfg.keys.recogNew, cfg.keys.newSure, cfg.keys.newMaybe]);
% start the blink break timer
if phaseCfg.isExp && phaseCfg.secUntilBlinkBreak > 0
blinkTimerStart = GetSecs;
end
for i = trialNum:length(testStims_img)
% do an impedance check after a certain number of trials
if ~expParam.photoCellTest && expParam.useNS && phaseCfg.isExp && i > 1 && i < length(testStims_img) && mod((i - 1),phaseCfg.impedanceAfter_nTrials) == 0
% run the impedance break
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_START');
thisGetSecs = et_impedanceCheck(w, cfg, true, phaseName);
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_END');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_END');
RestrictKeysForKbCheck([cfg.keys.recogOld, cfg.keys.recogNew, cfg.keys.newSure, cfg.keys.newMaybe]);
% show preparation text
DrawFormattedText(w, 'Get ready...', 'center', 'center', cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
WaitSecs(2.0);
if (phaseCfg.cr_isi > 0 && phaseCfg.fixDuringISI) || (phaseCfg.cr_isi == 0 && phaseCfg.fixDuringPreStim)
Screen('TextSize', w, cfg.text.fixSize);
DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
WaitSecs(1.0);
% reset the blink timer
if phaseCfg.secUntilBlinkBreak > 0
blinkTimerStart = GetSecs;
end
end
% Do a blink break if specified time has passed
if ~expParam.photoCellTest && phaseCfg.isExp && phaseCfg.secUntilBlinkBreak > 0 && (GetSecs - blinkTimerStart) >= phaseCfg.secUntilBlinkBreak && i > 3 && i < (length(testStims_img) - 3)
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_START');
Screen('TextSize', w, cfg.text.basicTextSize);
if expParam.useNS
pauseMsg = 'Blink now.\n\n';
else
pauseMsg = '';
end
pauseMsg = sprintf('%sReady for trial %d of %d.\nPress any key to continue.', pauseMsg, i, length(testStims_img));
if phaseCfg.showRespInBreak
% draw response prompt, one on top of the other
Screen('DrawTexture', w, sureMaybeKeyImg, [], sureMaybeKeyImgRect);
%Screen('DrawTexture', w, oldNewKeyImg, [], oldNewKeyImgRect);
Screen('DrawTexture', w, oldNewKeyImg, [], AdjoinRect(oldNewKeyImgRect,sureMaybeKeyImgRect,RectTop));
end
% just draw straight into the main window since we don't need speed here
DrawFormattedText(w, pauseMsg, 'center', 'center', cfg.text.instructColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
% listen for any keypress on any keyboard
RestrictKeysForKbCheck([]);
thisGetSecs = KbWait(-1,2);
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_END');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_END');
% only check these keys
RestrictKeysForKbCheck([cfg.keys.recogOld, cfg.keys.recogNew, cfg.keys.newSure, cfg.keys.newMaybe]);
% show preparation text
DrawFormattedText(w, 'Get ready...', 'center', 'center', cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
WaitSecs(2.0);
if (phaseCfg.cr_isi > 0 && phaseCfg.fixDuringISI) || (phaseCfg.cr_isi == 0 && phaseCfg.fixDuringPreStim)
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
WaitSecs(1.0);
% reset the timer
blinkTimerStart = GetSecs;
end
% load the stimulus now if we didn't load it earlier
if ~cfg.stim.preloadImages
stimImg = imread(fullfile(imgStimDir,testStims_img(i).categoryStr,testStims_img(i).fileName));
% resize the image, if necessary
if size(stimImg,1) > cfg.stim.nRows
stimImg = imresize(stimImg,[cfg.stim.nRows, NaN]);
end
% crop the image, if necessary
if size(stimImg,2) > cfg.stim.cropWidth
widthCenter = round(size(stimImg,2) / 2);
stimImg = stimImg(:,(widthCenter - round(cfg.stim.cropWidth / 2)):(widthCenter + round(cfg.stim.cropWidth / 2)),:);
end
% create the texture
testImgTex(i) = Screen('MakeTexture',w,stimImg);
end
% pull out the coordinates we need
stimImgRect = stimImgRect_all(i,:);
recallX = recallX_all(i);
recallY = recallY_all(i);
errorTextY = errorTextY_all(i);
%responsePromptY = responsePromptY_all(i);
% initialize
test_preStimFixOn = nan;
%test_imgOn = nan;
% recognition
keyIsDown_recog = false;
recogEndRT = nan;
recogRespPromptOn = nan;
recogAcc = false;
recogRespKey = 'NO_RESPONSE_KEY';
recogResp = 'NO_RESPONSE';
%recogResp_rt = int32(-1);
% new - sure/maybe response
keyIsDown_new = false;
newEndRT = nan;
newRespPromptOn = nan;
newAcc = false;
newRespKey = 'NO_RESPONSE_KEY';
newResp = 'NO_RESPONSE';
newResp_rt = int32(-1);
% old - recall response
madeRecallResp = false;
recallEndRT = nan;
recallRespPromptOn = nan;
corrSpell = false;
recallResp = 'NO_RESPONSE';
recallResp_rt = int32(-1);
% resynchronize netstation before the start of drawing
if expParam.useNS
[NSSyncStatus, NSSyncError] = NetStation('Synchronize'); %#ok<NASGU,ASGLU>
end
% ISI between trials
if phaseCfg.cr_isi > 0
if phaseCfg.fixDuringISI
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
end
WaitSecs(phaseCfg.cr_isi);
end
% preStimulus period, with fixation if desired
if length(phaseCfg.cr_preCueStim) == 1
if phaseCfg.cr_preCueStim > 0
if phaseCfg.fixDuringPreStim
% draw fixation
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
[test_preStimFixOn] = Screen('Flip',w);
else
test_preStimFixOn = NaN;
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
end
WaitSecs(phaseCfg.cr_preCueStim);
end
elseif length(phaseCfg.cr_preCueStim) == 2
if ~all(phaseCfg.cr_preCueStim == 0)
if phaseCfg.fixDuringPreStim
% draw fixation
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
[test_preStimFixOn] = Screen('Flip',w);
else
test_preStimFixOn = NaN;
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
end
% fixation on screen before stim for a random amount of time
WaitSecs(phaseCfg.cr_preCueStim(1) + ((phaseCfg.cr_preCueStim(2) - phaseCfg.cr_preCueStim(1)).*rand(1,1)));
end
end
% draw the stimulus
Screen('DrawTexture', w, testImgTex(i), [], stimImgRect);
if phaseCfg.fixDuringStim
% and fixation on top of it
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
% photocell rect with stim
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellRectColor, cfg.stim.photoCellRect);
end
% Show stimulus on screen at next possible display refresh cycle,
% and record stimulus onset time in 'test_imgOnset':
[test_imgOn, test_imgOnset] = Screen('Flip', w);
if cfg.text.printTrialInfo
fprintf('Trial %d of %d: %s, targ (1) or lure (0): %d.\n',i,length(testStims_img),testStims_img(i).fileName,testStims_img(i).targ);
end
% while loop to show stimulus until "duration" seconds elapsed.
while (GetSecs - test_imgOnset) <= phaseCfg.cr_cueStimOnly
% check for too-fast response
if ~phaseCfg.respDuringStim
[keyIsDown_recog] = KbCheck;
% if they press a key too early, tell them they responded too fast
if keyIsDown_recog
% draw the stimulus
Screen('DrawTexture', w, testImgTex(i), [], stimImgRect);
if phaseCfg.fixDuringStim
% and fixation on top of it
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
% and the "too fast" text
Screen('TextSize', w, cfg.text.instructTextSize);
DrawFormattedText(w,cfg.text.tooFastText,'center',errorTextY,cfg.text.errorTextColor, cfg.text.instructCharWidth);
% photocell rect with stim
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
keyIsDown_recog = 0;
break
end
else
[keyIsDown_recog, recogEndRT, keyCode] = KbCheck;
% if they push more than one key, don't accept it
if keyIsDown_recog && sum(keyCode) == 1
% wait for key to be released
while KbCheck(-1)
WaitSecs(0.0001);
% % proceed if time is up, regardless of whether key is held
% if (GetSecs - recogRT) > phaseCfg.cr_recog_response
% break
% end
end
% if cfg.text.printTrialInfo
% fprintf('"%s" typed at time %.3f seconds\n', KbName(keyCode), endRT - recogRT);
% end
if (keyCode(cfg.keys.recogOld) == 1 && all(keyCode(~cfg.keys.recogOld) == 0)) ||...
(keyCode(cfg.keys.recogNew) == 1 && all(keyCode(~cfg.keys.recogNew) == 0))
recogRespPromptOn = nan;
break
end
elseif keyIsDown_recog && sum(keyCode) > 1
% draw the stimulus
Screen('DrawTexture', w, testImgTex(i), [], stimImgRect);
if phaseCfg.fixDuringStim
% and fixation on top of it
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
% don't push multiple keys
Screen('TextSize', w, cfg.text.instructTextSize);
DrawFormattedText(w,cfg.text.multiKeyText,'center',errorTextY,cfg.text.errorTextColor, cfg.text.instructCharWidth);
% photocell rect with stim
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellRectColor, cfg.stim.photoCellRect);
end
% put them on the screen
Screen('Flip', w);
keyIsDown_recog = 0;
end
end
% Wait <1 ms before checking the keyboard again to prevent
% overload of the machine at elevated Priority():
WaitSecs(0.0001);
end
% wait out any remaining time
while (GetSecs - test_imgOnset) <= phaseCfg.cr_cueStimOnly
% Wait <1 ms before checking the keyboard again to prevent
% overload of the machine at elevated Priority():
WaitSecs(0.0001);
end
keyIsDown_recog = logical(keyIsDown_recog);
if ~keyIsDown_recog
% draw the stimulus
Screen('DrawTexture', w, testImgTex(i), [], stimImgRect);
% draw response prompt
Screen('DrawTexture', w, oldNewKeyImg, [], oldNewKeyImgRect);
if phaseCfg.fixDuringStim
% and fixation on top of it
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
% photocell rect with stim
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellRectColor, cfg.stim.photoCellRect);
end
% photocell rect with stim
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellRectColor, cfg.stim.photoCellRect);
end
% put them on the screen; measure RT from when response key img appears
[recogRespPromptOn, recogRespPromptStartRT] = Screen('Flip', w);
% poll for a recogResp
while (GetSecs - recogRespPromptStartRT) <= phaseCfg.cr_recog_response
[keyIsDown_recog, recogEndRT, keyCode] = KbCheck;
% if they push more than one key, don't accept it
if keyIsDown_recog && sum(keyCode) == 1
% wait for key to be released
while KbCheck(-1)
WaitSecs(0.0001);
% % proceed if time is up, regardless of whether key is held
% if (GetSecs - recogRT(i)) > phaseCfg.cr_recog_response
% break
% end
end
% if cfg.text.printTrialInfo
% fprintf('"%s" typed at time %.3f seconds\n', KbName(keyCode), endRT - recogRT);
% end
if (keyCode(cfg.keys.recogOld) == 1 && all(keyCode(~cfg.keys.recogOld) == 0)) ||...
(keyCode(cfg.keys.recogNew) == 1 && all(keyCode(~cfg.keys.recogNew) == 0))
break
end
elseif keyIsDown_recog && sum(keyCode) > 1
% draw the stimulus
Screen('DrawTexture', w, testImgTex(i), [], stimImgRect);
% draw response prompt
Screen('DrawTexture', w, oldNewKeyImg, [], oldNewKeyImgRect);
if phaseCfg.fixDuringStim
% and fixation on top of it
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
% don't push multiple keys
Screen('TextSize', w, cfg.text.instructTextSize);
DrawFormattedText(w,cfg.text.multiKeyText,'center',errorTextY,cfg.text.errorTextColor, cfg.text.instructCharWidth);
% photocell rect with stim
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellRectColor, cfg.stim.photoCellRect);
end
% put them on the screen
Screen('Flip', w);
keyIsDown_recog = 0;
end
% wait so we don't overload the system
WaitSecs(0.0001);
end
keyIsDown_recog = logical(keyIsDown_recog);
end
if ~keyIsDown_recog
if phaseCfg.playSound
Beeper(phaseCfg.incorrectSound,phaseCfg.incorrectVol);
end
% "need to respond faster"
Screen('TextSize', w, cfg.text.instructTextSize);
DrawFormattedText(w,cfg.text.respondFaster,'center','center',cfg.text.respondFasterColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
% need a new endRT
recogEndRT = GetSecs;
% wait to let them view the feedback
WaitSecs(cfg.text.respondFasterFeedbackTime);
end
% if this is an old image, get the word paired with it
if testStims_img(i).targ
thisWord = testStims_word([testStims_word.pairNum] == testStims_img(i).pairNum);
if length(thisWord) == 1
thisPairedWord = lower(thisWord.word);
w_stimNum = int32(thisWord.stimNum);
else
error('Cannot have more than one word paired with an image');
end
else
% otherwise leave it empty
thisPairedWord = 'LURE_STIM';
w_stimNum = int32(-1);
end
if keyIsDown_recog && sum(keyCode) == 1
% get the key they pressed
recogRespKey = KbName(keyCode);
if (keyCode(cfg.keys.recogOld) == 1 && all(keyCode(~cfg.keys.recogOld) == 0))
recogResp = 'old';
% if they answer 'old', get their answer and type it to the screen
dispRecallResp = cfg.text.recallPrompt;
recallStr = '';
if ~useKbCheck
% Flush the keyboard buffer:
FlushEvents;
end
% initialize
typedRecallStr = false;
if phaseCfg.cr_corrSpell && phaseCfg.cr_nAttempts > 0
attemptCounter = 0;
end
% draw the stimulus
Screen('DrawTexture', w, testImgTex(i), [], stimImgRect);
if phaseCfg.fixDuringStim
% and response symbol on top of it
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.respSymbol, respRectX, respRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.respSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
% draw the recall resonse prompt
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, sprintf('%s',dispRecallResp), recallX, recallY, cfg.text.basicTextColor);
% photocell rect and stim
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellRectColor, cfg.stim.photoCellRect);
end
[recallRespPromptOn, recallRespPromptStartRT] = Screen('Flip', w);
while ~typedRecallStr
while true
%while (GetSecs - probOnset) <= phaseCfg.dist_response
% reimplementing GetEchoString to get RT
if useKbCheck
[char, GetCharEndRT] = GetKbChar; %#ok<UNRCH>
else
[char, GetCharEndRT] = GetChar;
end
if isempty(char)
return
else
% get the time the key was pressed using GetSecs
respMadeRT = GetSecs;
end
switch (abs(char))
case {13, 3, 10}
% ctrl-C, enter, or return
break
case {8}
% 8 = backspace
if ~isempty(recallStr)
recallStr = recallStr(1:length(recallStr)-1);
end
if ~isempty(recallStr)
dispRecallResp = recallStr;
else
dispRecallResp = cfg.text.recallPrompt;
end
otherwise
if ismember(char, cfg.keys.recallKeyNames)
recallStr = [recallStr, char]; %#ok<AGROW>
end
if ~isempty(recallStr)
dispRecallResp = recallStr;
else
dispRecallResp = cfg.text.recallPrompt;
end
end
% draw the stimulus
Screen('DrawTexture', w, testImgTex(i), [], stimImgRect);
if phaseCfg.fixDuringStim
% and response symbol on top of it
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.respSymbol, respRectX, respRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.respSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
% draw their text
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, sprintf('%s',dispRecallResp), recallX, recallY, cfg.text.basicTextColor);
% photocell rect and stim
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellRectColor, cfg.stim.photoCellRect);
end
%[respMadeRT] = Screen('Flip', w);
Screen('Flip', w);
WaitSecs(0.0001);
end
if testStims_img(i).targ
% if it's a targ stim, see if they needed the correct spelling
if phaseCfg.cr_corrSpell
attemptCounter = attemptCounter + 1;
if strcmpi(recallStr,thisPairedWord)
corrSpell = true;
typedRecallStr = true;
%break
else
corrSpell = false;
if attemptCounter >= phaseCfg.cr_nAttempts
typedRecallStr = true;
%break
end
end
else
% if we're not checking spelling then set correct=true if they
% made some kind of response
if ~isempty(recallStr)
corrSpell = true;
end
typedRecallStr = true;
%break
end
else
% this was a lure image and they're making a response
corrSpell = false;
typedRecallStr = true;
end
end
% get the time they pressed return
recallEndRT = respMadeRT;
% only need the seconds, only for when using GetChar
% recallEndRT = endRT.secs;
% collect their response and make sure they're behaving appropriately
if ~isempty(recallStr)
recallResp = recallStr;
recallResp_all = cat(1,recallResp_all,recallResp);
madeRecallResp = true;
% see if they're behaving badly (making the same response over and
% over)
recallCounter = recallCounter + 1;
if recallCounter > 1
if strcmpi(recallResp,recallResp_all(recallCounter-1))
% they made the same response as last time
recallsInARowCounter = recallsInARowCounter + 1;
else
recallsInARowCounter = 0;
end
if length(recallResp_all) > 2 && recallsInARowCounter >= 3
% if they've made the same response more than 3 times in a row
%if phaseCfg.playSound
% % play a loud angry beep
% Beeper(440, 0.9, 3);
%end
% tell them that they're not responding correctly
tooManyInARowText1 = sprintf('It seems that you are not doing the task correctly.\n\nYou have made the response "%s" many times in a row.',recallResp);
tooManyInARowText2 = sprintf('\n\nPlease talk to the experimenter now.\n\nPress "%s" when you know how to do the task correctly.',cfg.keys.instructContKey);
Screen('TextSize', w, cfg.text.instructTextSize);
DrawFormattedText(w,sprintf('%s%s',tooManyInARowText1,tooManyInARowText2),'center','center',cfg.text.instructColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);