-
Notifications
You must be signed in to change notification settings - Fork 6
/
RealTimePunisherInstruct.m
1414 lines (1184 loc) · 48.9 KB
/
RealTimePunisherInstruct.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 [blockData] = RealTimePunisherInstruct(subjectNum,subjectName,matchNum,runNum,debug)
% function [blockData] = RealTimeBehavInstruct(subjectNum,subjectName,matchNum,runNum,debug)
%
% These are the instructions for the behavioral version of the experiment.
%
%
% REQUIRED INPUTS:
% - subjectNum: participant number [any integer]
% if subjectNum = 0, no information will be saved
% - subjectName: subject initials for behavioral studies, ntblab naming
% convention for fmri scan [mmddyy#_rtat01]
% - matchNum: if the subject is matched to another subject [if so, input subjectNum, if not, input 0]
% - runNum: run number [any integer]
% - debug: whether debugging [1/0]
%
% OUTPUTS
% - blockData:
%
% Written by: Megan deBettencourt
% Version: 1.0
% Last modified: 10/22/12
%% check inputs
%check that there is a sufficient number of inputs
if nargin < 5
error('5 inputs are required: subjectNum, subjectName, matchNum, runNum, debug');
end
if ~isnumeric(subjectNum)
error('subjectNum must be a number');
end
if ~ischar(subjectName)
error('subjectName must be a string');
end
if ~isnumeric(matchNum)
error('matchNum must be a number');
end
if ~isnumeric(runNum)
error('runNum must be a number');
end
if (debug~=1) && (debug~=0)
error('debug must be either 1 (if debugging) or 0 (if not)')
end
%% Boilerplate
if (debug) %so that when debugging you can do other things
Screen('Preference', 'SkipSyncTests', 1);
else
%ListenChar(2); %prevent command window output
HideCursor; %hide mouse cursor
end
seed = sum(100*clock); %get random seed
RandStream.setDefaultStream(RandStream('mt19937ar','seed',seed));%set seed
%assert(strcmp(computer,'PCWIN'),'this code is only written to run on windows');
assert(isempty(findstr(computer,'64')),'this code is only written to run on 32 bit matlab');
%initialize system time calls
GetSecs;
%% Experimental Parameters
%stimulus number parameters
categStr = {'sc','fa'};
% block timing
instructOn = 0; % secs
instructDur = 1; % secs
instructTRnum = 1; % TRs
% trial timing
stimDur = 1; % secs
respWindowPractice = 10; % secs
respWindow = .85; % secs
% display parameters
textColor = 0;
textFont = 'Arial';
textSize = 16;
textSpacing = 25;
fixColor = 0;
respColor = 255;
backColor = 127;
imageSize = 256; % assumed square %MdB check image size
fixationSize = 4;% pixels
progWidth = 400; % image loading progress bar
progHeight = 20;
% how to average the faces and scenes
attImgProp = .5;
ScreenResX = 1600;
ScreenResY = 900;
%% Response Mapping and Counterbalancing
% skyra: use current design button box (keys 1,2,3,4)
LEFT = KbName('1!');
DEVICE = -1;
% counterbalancing response mapping based on subject assignment
% correctResp spells out the responses for {INDOOR,OUTDOOR,MALE,FEMALE}
if matchNum==0
respMap = mod(subjectNum-1,4)+1;
else
respMap = mod(matchNum-1,4)+1;
end
switch (respMap)
case 1
sceneInstruct{1} = 'For places you will be looking for INDOOR places. If you see an indoor place in the photo, press the 1 key.';
sceneInstruct{2} = 'If you see an OUTDOOR place in the photo do not press anything.';
sceneInstruct{3} = 'When you''re looking for indoor places you should IGNORE the faces. Faces will be irrelevant to the task';
sceneSummaryInstruct = 'indoor places = 1';
faceInstruct{1} = 'For faces you will be looking for MALE faces. If you see a male face in the photo, press the 1 key.';
faceInstruct{2} = 'If you see a FEMALE face in the photo do not press anything.';
faceInstruct{3} = 'When you''re looking for male faces you should IGNORE the places. Places will be irrelevant to the task';
faceSummaryInstruct = 'male faces = 1';
sceneShorterInstruct = 'indoor places';
faceShorterInstruct = 'male faces';
case 2
sceneInstruct{1} = 'For places you will be looking for OUTDOOR places. If you see an outdoor place in the photo, press the 1 key.';
sceneInstruct{2} = 'If you see an INDOOR place in the photo do not press anything.';
sceneInstruct{3} = 'When you''re looking for outdoor places you should IGNORE the faces. Faces will be irrelevant to the task';
sceneSummaryInstruct = 'outdoor places = 1';
faceInstruct{1} = 'For faces you will be looking for FEMALE faces. If you see a female face in the photo, press the 1 key.';
faceInstruct{2} = 'If you see a MALE face in the photo do not press anything.';
faceInstruct{3} = 'When you''re looking for female faces you should IGNORE the places. Places will be irrelevant to the task';
faceSummaryInstruct = 'female faces = 1';
sceneShorterInstruct = 'outdoor places';
faceShorterInstruct = 'female faces';
case 3
sceneInstruct{1} = 'For places you will be looking for OUTDOOR places. If you see an outdoor place in the photo, press the 1 key.';
sceneInstruct{2} = 'If you see an INDOOR place in the photo do not press anything.';
sceneInstruct{3} = 'When you''re looking for indoor places you should IGNORE the faces. Faces will be irrelevant to the task';
sceneSummaryInstruct = 'outdoor places = 1';
faceInstruct{1} = 'For faces you will be looking for MALE faces. If you see a male face in the photo, press the 1 key.';
faceInstruct{2} = 'If you see a FEMALE face in the photo do not press anything.';
faceInstruct{3} = 'When you''re looking for male faces you should IGNORE the places. Places will be irrelevant to the task';
faceSummaryInstruct = 'male faces = 1';
sceneShorterInstruct = 'outdoor places';
faceShorterInstruct = 'male faces';
case 4
sceneInstruct{1} = 'For places you will be looking for INDOOR places. If you see an indoor place in the photo, press the 1 key.';
sceneInstruct{2} = 'If you see an OUTDOOR place in the photo do not press anything.';
sceneInstruct{3} = 'When you''re looking for indoor places you should IGNORE the faces. Faces will be irrelevant to the task';
sceneSummaryInstruct = 'indoor places = 1';
faceInstruct{1} = 'For faces you will be looking for FEMALE faces. If you see a female face in the photo, press the 1 key.';
faceInstruct{2} = 'If you see a MALE face in the photo do not press anything.';
faceInstruct{3} = 'When you''re looking for female faces you should IGNORE the places. Places will be irrelevant to the task';
faceSummaryInstruct = 'female faces = 1';
sceneShorterInstruct = 'indoor places';
faceShorterInstruct = 'female faces';
otherwise
error('Impossible response mapping!');
end
contInstruct = sprintf('Please hit q to continue');
%% Initialize Screens
screenNumbers = Screen('Screens');
% show full screen if real, otherwise part of screen
if debug
screenNum = 0;
else
screenNum = screenNumbers(end);
end
%retrieve the size of the display screen
if debug
[screenX screenY] = Screen('WindowSize',screenNum);
screenX = screenX/2;
screenY = screenY/2;
else
[screenX screenY] = Screen('WindowSize',screenNum);
%to ensure that the images are standardized (they take up the same degrees of the visual field) for all subjects
if (screenX ~= ScreenResX) || (screenY ~= ScreenResY)
fprintf('The screen dimensions may be incorrect. For screenNum = %d,screenX = %d (not 1152) and screenY = %d (not 864)',screenNum, screenX, screenY);
end
end
%create main window
mainWindow = Screen(screenNum,'OpenWindow',backColor,[0 0 screenX screenY]);
% details of main window
centerX = screenX/2; centerY = screenY/2;
Screen(mainWindow,'TextFont',textFont);
Screen(mainWindow,'TextSize',textSize);
% placeholder for images
imageRect = [0,0,imageSize,imageSize];
% position of images
centerRect = [centerX-imageSize/2,centerY-imageSize/2,centerX+imageSize/2,centerY+imageSize/2];
% position of fixation dot
fixDotRect = [centerX-fixationSize,centerY-fixationSize,centerX+fixationSize,centerY+fixationSize];
% image loading progress bar
progRect = [centerX-progWidth/2,centerY-progHeight/2,centerX+progWidth/2,centerY+progHeight/2];
%% Load or Initialize Real-Time Data & Staircasing Parameters
if (~ispc)
dataHeader = ['data/subject' num2str(subjectNum)];
runHeader = [dataHeader '/run' num2str(runNum)];
fn = ls([runHeader '/blockdatadesign_' num2str(runNum) '_*']);
load(deblank(fn));
else
if matchNum ==0
dataHeader = ['data/' num2str(subjectNum)];
else
dataHeader = ['data/' num2str(matchNum) '_match'];
end
runHeader = [dataHeader '/run' num2str(runNum)];
fn = ls([runHeader '/blockdatadesign_' num2str(runNum) '_*']);
assert(~isempty(fn),'have not created the block design');
load([runHeader '/' deblank(fn)]);
end
%% Load Images
%cd instructstim;
cd instructstim
for categ=1:4
% move into the right folder
if (categ == INDOOR)
cd indoor;
elseif (categ == OUTDOOR)
cd outdoor;
elseif (categ == MALE)
cd male_neut;
elseif (categ == FEMALE)
cd female_neut;
else
error('Impossible category!');
end
% get filenames
dirList{categ} = dir; %#ok<AGROW>
dirList{categ} = dirList{categ}(3:end); %#ok<AGROW> skip . & ..
if (~isempty(dirList{categ}))
if (strcmp(dirList{categ}(1).name,'.DS_Store')==1)
dirList{categ} = dirList{categ}(2:end); %#ok<AGROW>
end
if (strcmp(dirList{categ}(end).name,'Thumbs.db')==1)
dirList{categ} = dirList{categ}(1:(end-1)); %#ok<AGROW>
end
numImages(categ) = length(dirList{categ}); %#ok<AGROW>
if (numImages(categ)>0)
% get images
for img=1:numImages(categ)
% update progress bar
Screen('FrameRect',mainWindow,0,progRect,10);
Screen('FillRect',mainWindow,0,progRect);
Screen('FillRect',mainWindow,[255 0 0],progRect-[0 0 round((1-img/numImages(categ))*progWidth) 0]);
Screen('Flip',mainWindow);
% read images
images{categ,img} = imread(dirList{categ}(img).name); %#ok<AGROW>
tempFFT = fft2(images{categ,img});
imagePower{categ,img} = abs(tempFFT); %#ok<AGROW>
imagePhase{categ,img} = angle(tempFFT); %#ok<AGROW>
end
cd ..;
end
else
error('Need at least one image per directory!');
end
end
cd ..;
Screen('Flip',mainWindow);
%% Welcome instructions
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
runInstruct{1} = 'Welcome! In this experiment you will be shown photos of overlapping faces and places';
runInstruct{2} = 'You will be told to look at either the face or the place';
runInstruct{3} = ' ';
runInstruct{4} = 'First let''s try the face task';
runInstruct{5} = contInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
Screen('Flip',mainWindow);
pause;
%% face instruct
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = faceInstruct{1};
runInstruct{2} = faceInstruct{2};
runInstruct{3} = ' ';
runInstruct{4} = faceInstruct{3};
runInstruct{5} = ' ';
runInstruct{6} = ' ';
runInstruct{7} = contInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
Screen('Flip',mainWindow);
pause;
%% face instruct #2
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = faceSummaryInstruct;
runInstruct{2} = ' ';
runInstruct{3} = ' ';
runInstruct{4} = 'Please repeat these instructions in your own words to the person helping you';
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
Screen('Flip',mainWindow);
pause;
%% face stim
% show fixation
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow);
for half=[SCENE FACE]
% get current images
tempPower{half} = imagePower{mode(blockData(1).categs{half}),1}; %#ok<NODEF>
tempImagePhase{half} = imagePhase{mode(blockData(1).categs{half}),1}; %#ok<AGROW>
tempImage{half} = real(ifft2(tempPower{half}.*exp(sqrt(-1)*tempImagePhase{half}))); %#ok<AGROW>
end
% generate image
fullImage = uint8(.5*tempImage{SCENE}+.5*tempImage{FACE});
% make textures
imageTex = Screen('MakeTexture',mainWindow,fullImage);
Screen('PreloadTextures',mainWindow,imageTex);
% wait for trigger and show image
FlushEvents('keyDown');
Priority(MaxPriority(screenNum));
Screen('FillRect',mainWindow,backColor);
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tStim = Screen('Flip',mainWindow,tFix+1);
tRespTimeout = tStim+respWindowPractice; %response timeout
stimOn = 1;
rts = NaN;
while(GetSecs < tRespTimeout)
% check for responses if none received yet
if isnan(rts)
[keyIsDown, secs, keyCode] = KbCheck(DEVICE); % -1 checks all keyboards
if keyIsDown
if (keyCode(LEFT))
rts = secs-tStim;
resps = find(keyCode,1);
Screen('FillRect',mainWindow,backColor);
if (stimOn) % leave image up if response before image duration
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
end
Screen(mainWindow,'FillOval',respColor,fixDotRect);
Screen('Flip',mainWindow);
end
end
end
end
Screen('FillRect',mainWindow,backColor);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow,tStim+TR);
%% Welcome instructions
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = 'Now let''s try the place task';
runInstruct{2} = ' ';
runInstruct{3} = sceneInstruct{1};
runInstruct{4} = sceneInstruct{2};
runInstruct{5} = ' ';
runInstruct{6} = sceneInstruct{3};
runInstruct{7} = ' ';
runInstruct{8} = contInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
Screen('Flip',mainWindow,tFix+TR);
pause;
%% Scene instructions
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = sceneSummaryInstruct;
runInstruct{2} = ' ';
runInstruct{3} = 'Please repeat these instructions in your own words to the person helping you';
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
Screen('Flip',mainWindow,tFix+TR);
pause;
%% scene stim
% show fixation
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow);
for half=[SCENE FACE]
% get current images
tempPower{half} = imagePower{mode(blockData(1).categs{half}),1}; %#ok<NODEF>
tempImagePhase{half} = imagePhase{mode(blockData(1).categs{half}),1}; %#ok<AGROW>
tempImage{half} = real(ifft2(tempPower{half}.*exp(sqrt(-1)*tempImagePhase{half}))); %#ok<AGROW>
end
% generate image
fullImage = uint8(.5*tempImage{SCENE}+.5*tempImage{FACE});
% make textures
imageTex = Screen('MakeTexture',mainWindow,fullImage);
Screen('PreloadTextures',mainWindow,imageTex);
% wait for trigger and show image
FlushEvents('keyDown');
Priority(MaxPriority(screenNum));
Screen('FillRect',mainWindow,backColor);
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tStim = Screen('Flip',mainWindow,tFix+1);
tRespTimeout = tStim+respWindowPractice; %response timeout
stimOn = 1;
rts = NaN;
while(GetSecs < tRespTimeout)
% check for responses if none received yet
if isnan(rts)
[keyIsDown, secs, keyCode] = KbCheck(DEVICE); % -1 checks all keyboards
if keyIsDown
if (keyCode(LEFT))
rts = secs-tStim;
resps = find(keyCode,1);
Screen('FillRect',mainWindow,backColor);
if (stimOn) % leave image up if response before image duration
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
end
Screen(mainWindow,'FillOval',respColor,fixDotRect);
Screen('Flip',mainWindow);
end
end
end
end
Screen('FillRect',mainWindow,backColor);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow,tStim+TR);
%% scene instruct 2
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
fixInstruct{1} = 'During the experiment, please look at the dot in the center';
fixInstruct{2} = 'You may have noticed that it will change from black to white when you respond';
fixInstruct{3} = ' ';
fixInstruct{4} = 'Please note that you will need to respond for most images';
fixInstruct{5} = ['That means, most images will be either ' sceneShorterInstruct ' or ' faceShorterInstruct ];
fixInstruct{5} = ' ';
fixInstruct{6} = contInstruct;
for instruct=1:length(fixInstruct)
tempBounds = Screen('TextBounds',mainWindow,fixInstruct{instruct});
Screen('drawtext',mainWindow,fixInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
tFix = Screen('Flip',mainWindow,tFix+TR);
pause;
%% scene instruct 2
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
runInstruct{1} = 'Now let''s try the scene task again.';
runInstruct{2} = 'This time, the photos will be presented for a much shorter amount of time';
runInstruct{3} = 'Also during the experiment, the only instructions you''ll see is:';
runInstruct{4} = ' ';
runInstruct{5} = sceneShorterInstruct;
runInstruct{6} = ' ';
runInstruct{7} = contInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
Screen('Flip',mainWindow,tFix+TR);
pause;
%% scene stim
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = sceneShorterInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
tInstruct = Screen('Flip',mainWindow);
% show fixation
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow,tInstruct+instructDur);
for half=[SCENE FACE]
% get current images
tempPower{half} = imagePower{mode(blockData(1).categs{half}),2}; %#ok<NODEF>
tempImagePhase{half} = imagePhase{mode(blockData(1).categs{half}),2}; %#ok<AGROW>
tempImage{half} = real(ifft2(tempPower{half}.*exp(sqrt(-1)*tempImagePhase{half}))); %#ok<AGROW>
end
% generate image
fullImage = uint8(.5*tempImage{SCENE}+.5*tempImage{FACE});
% make textures
imageTex = Screen('MakeTexture',mainWindow,fullImage);
Screen('PreloadTextures',mainWindow,imageTex);
% wait for trigger and show image
FlushEvents('keyDown');
Priority(MaxPriority(screenNum));
Screen('FillRect',mainWindow,backColor);
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tStim = Screen('Flip',mainWindow,tFix+1);
tRespTimeout = tStim+respWindow; %response timeout
stimOn = 1;
rts = NaN;
while(GetSecs < tRespTimeout)
% check for responses if none received yet
if isnan(rts)
[keyIsDown, secs, keyCode] = KbCheck(DEVICE); % -1 checks all keyboards
if keyIsDown
if (keyCode(LEFT))
rts = secs-tStim;
resps = find(keyCode,1);
Screen('FillRect',mainWindow,backColor);
if (stimOn) % leave image up if response before image duration
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
end
Screen(mainWindow,'FillOval',respColor,fixDotRect);
Screen('Flip',mainWindow);
end
end
end
end
Screen('FillRect',mainWindow,backColor);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow,tStim+TR);
WaitSecs(TR);
%% face instruct 2
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = 'Now let''s try the face task the same way';
runInstruct{2} = ' ';
runInstruct{3} = contInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
Screen('Flip',mainWindow,tFix+TR);
pause;
%% face stim
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = faceShorterInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
tInstruct = Screen('Flip',mainWindow);
% show fixation
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow,tInstruct+instructDur);
for half=[SCENE FACE]
% get current images
tempPower{half} = imagePower{mode(blockData(1).categs{half}),3}; %#ok<NODEF>
tempImagePhase{half} = imagePhase{mode(blockData(1).categs{half}),3}; %#ok<AGROW>
tempImage{half} = real(ifft2(tempPower{half}.*exp(sqrt(-1)*tempImagePhase{half}))); %#ok<AGROW>
end
% generate image
fullImage = uint8(.5*tempImage{SCENE}+.5*tempImage{FACE});
% make textures
imageTex = Screen('MakeTexture',mainWindow,fullImage);
Screen('PreloadTextures',mainWindow,imageTex);
% wait for trigger and show image
FlushEvents('keyDown');
Priority(MaxPriority(screenNum));
Screen('FillRect',mainWindow,backColor);
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tStim = Screen('Flip',mainWindow,tFix+1);
tRespTimeout = tStim+respWindow; %response timeout
stimOn = 1;
rts = NaN;
while(GetSecs < tRespTimeout)
% check for responses if none received yet
if isnan(rts)
[keyIsDown, secs, keyCode] = KbCheck(DEVICE); % -1 checks all keyboards
if keyIsDown
if (keyCode(LEFT))
rts = secs-tStim;
resps = find(keyCode,1);
Screen('FillRect',mainWindow,backColor);
if (stimOn) % leave image up if response before image duration
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
end
Screen(mainWindow,'FillOval',respColor,fixDotRect);
Screen('Flip',mainWindow);
end
end
end
end
Screen('FillRect',mainWindow,backColor);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow,tStim+TR);
WaitSecs(TR);
%% face instruct 3
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = 'During the real tasks, you will see instruction text followed by many images continuously';
runInstruct{2} = 'Let''s practice that now';
runInstruct{3} = ' ';
runInstruct{4} = contInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
Screen('Flip',mainWindow,tFix+TR);
pause;
%% face stim
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = faceShorterInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
tInstruct = Screen('Flip',mainWindow);
% show fixation
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow,tInstruct+instructDur);
iTrial = 3;
for half=[SCENE FACE]
% get current images
tempPower{half} = imagePower{mode(blockData(1).categs{half}),iTrial}; %#ok<NODEF>
tempImagePhase{half} = imagePhase{mode(blockData(1).categs{half}),iTrial}; %#ok<AGROW>
tempImage{half} = real(ifft2(tempPower{half}.*exp(sqrt(-1)*tempImagePhase{half}))); %#ok<AGROW>
end
% generate image
fullImage = uint8(.5*tempImage{SCENE}+.5*tempImage{FACE});
% make textures
imageTex = Screen('MakeTexture',mainWindow,fullImage);
Screen('PreloadTextures',mainWindow,imageTex);
% wait for trigger and show image
FlushEvents('keyDown');
Priority(MaxPriority(screenNum));
Screen('FillRect',mainWindow,backColor);
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tStim = Screen('Flip',mainWindow,tFix+1);
tRespTimeout = tStim+respWindow; %response timeout
stimOn = 1;
rts = NaN;
while(GetSecs < tRespTimeout)
% check for responses if none received yet
if isnan(rts)
[keyIsDown, secs, keyCode] = KbCheck(DEVICE); % -1 checks all keyboards
if keyIsDown
if (keyCode(LEFT))
rts = secs-tStim;
resps = find(keyCode,1);
Screen('FillRect',mainWindow,backColor);
if (stimOn) % leave image up if response before image duration
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
end
Screen(mainWindow,'FillOval',respColor,fixDotRect);
Screen('Flip',mainWindow);
end
end
end
end
for iTrial = 4:8;
for half=[SCENE FACE]
% get current images
if (half == FACE) && (iTrial==6)
x= blockData(1).categs{half}(find(blockData(1).categs{half}~=mode(blockData(1).categs{half}),1,'first'));
else
x = mode(blockData(1).categs{half});
end
tempPower{half} = imagePower{x,iTrial}; %#ok<NODEF>
tempImagePhase{half} = imagePhase{x,iTrial}; %#ok<AGROW>
tempImage{half} = real(ifft2(tempPower{half}.*exp(sqrt(-1)*tempImagePhase{half}))); %#ok<AGROW>
end
% generate image
fullImage = uint8(.5*tempImage{SCENE}+.5*tempImage{FACE});
% make textures
imageTex = Screen('MakeTexture',mainWindow,fullImage);
Screen('PreloadTextures',mainWindow,imageTex);
% wait for trigger and show image
FlushEvents('keyDown');
Priority(MaxPriority(screenNum));
Screen('FillRect',mainWindow,backColor);
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tStim = Screen('Flip',mainWindow,tStim+stimDur);
tRespTimeout = tStim+respWindow; %response timeout
stimOn = 1;
rts = NaN;
while(GetSecs < tRespTimeout)
% check for responses if none received yet
if isnan(rts)
[keyIsDown, secs, keyCode] = KbCheck(DEVICE); % -1 checks all keyboards
if keyIsDown
if (keyCode(LEFT))
rts = secs-tStim;
resps = find(keyCode,1);
Screen('FillRect',mainWindow,backColor);
if (stimOn) % leave image up if response before image duration
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
end
Screen(mainWindow,'FillOval',respColor,fixDotRect);
Screen('Flip',mainWindow);
end
end
end
end
end
Screen('FillRect',mainWindow,backColor);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow,tStim+stimDur);
WaitSecs(1);
%% scene instruct 3
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = 'Let''s practice that again for the places';
runInstruct{2} = ' ';
runInstruct{3} = ' ';
runInstruct{4} = contInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
Screen('Flip',mainWindow,tFix+TR);
pause;
%% scene stim
% clear screen
Screen(mainWindow,'FillRect',backColor);
Screen('Flip',mainWindow);
FlushEvents('keyDown');
% show instructions
clearvars runInstruct;
runInstruct{1} = sceneShorterInstruct;
for instruct=1:length(runInstruct)
tempBounds = Screen('TextBounds',mainWindow,runInstruct{instruct});
Screen('drawtext',mainWindow,runInstruct{instruct},centerX-tempBounds(3)/2,centerY-tempBounds(4)/5+textSpacing*(instruct-1),textColor);
clear tempBounds;
end
tInstruct = Screen('Flip',mainWindow);
% show fixation
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tFix = Screen('Flip',mainWindow,tInstruct+instructDur);
iTrial = 3;
for half=[SCENE FACE]
% get current images
tempPower{half} = imagePower{mode(blockData(1).categs{half}),iTrial}; %#ok<NODEF>
tempImagePhase{half} = imagePhase{mode(blockData(1).categs{half}),iTrial}; %#ok<AGROW>
tempImage{half} = real(ifft2(tempPower{half}.*exp(sqrt(-1)*tempImagePhase{half}))); %#ok<AGROW>
end
% generate image
fullImage = uint8(.5*tempImage{SCENE}+.5*tempImage{FACE});
% make textures
imageTex = Screen('MakeTexture',mainWindow,fullImage);
Screen('PreloadTextures',mainWindow,imageTex);
% wait for trigger and show image
FlushEvents('keyDown');
Priority(MaxPriority(screenNum));
Screen('FillRect',mainWindow,backColor);
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tStim = Screen('Flip',mainWindow,tFix+1);
tRespTimeout = tStim+respWindow; %response timeout
stimOn = 1;
rts = NaN;
while(GetSecs < tRespTimeout)
% check for responses if none received yet
if isnan(rts)
[keyIsDown, secs, keyCode] = KbCheck(DEVICE); % -1 checks all keyboards
if keyIsDown
if (keyCode(LEFT))
rts = secs-tStim;
resps = find(keyCode,1);
Screen('FillRect',mainWindow,backColor);
if (stimOn) % leave image up if response before image duration
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
end
Screen(mainWindow,'FillOval',respColor,fixDotRect);
Screen('Flip',mainWindow);
end
end
end
end
for iTrial = 4:8;
for half=[SCENE FACE]
% get current images
if (half == SCENE) && (iTrial==5)
x= blockData(1).categs{half}(find(blockData(1).categs{half}~=mode(blockData(1).categs{half}),1,'first'));
else
x = mode(blockData(1).categs{half});
end
tempPower{half} = imagePower{x,iTrial}; %#ok<NODEF>
tempImagePhase{half} = imagePhase{x,iTrial}; %#ok<AGROW>
tempImage{half} = real(ifft2(tempPower{half}.*exp(sqrt(-1)*tempImagePhase{half}))); %#ok<AGROW>
end
% generate image
fullImage = uint8(.5*tempImage{SCENE}+.5*tempImage{FACE});
% make textures
imageTex = Screen('MakeTexture',mainWindow,fullImage);
Screen('PreloadTextures',mainWindow,imageTex);
% wait for trigger and show image
FlushEvents('keyDown');
Priority(MaxPriority(screenNum));
Screen('FillRect',mainWindow,backColor);
Screen('DrawTexture',mainWindow,imageTex,imageRect,centerRect);
Screen(mainWindow,'FillOval',fixColor,fixDotRect);
tStim = Screen('Flip',mainWindow,tStim+stimDur);
tRespTimeout = tStim+respWindow; %response timeout
stimOn = 1;