-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTasks_AATEC_V8.m
1875 lines (1688 loc) · 89.1 KB
/
Tasks_AATEC_V8.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
%----------------------------------------------------------------------
% AATEC Tasks
% Copyright: @A.Zahedi 2024
%----------------------------------------------------------------------
% Clear the workspace
close all;
clc;
clear;
sca;
IOPort('closeall');
rng('shuffle');
Texts_AATEC_Object;
Screen('Preference', 'SkipSyncTests', 1);
% Setup PTB with some default values
PsychDefaultSetup(2);
% Seed the random number generator.
rng('shuffle');
%----------------------------------------------------------------------
% conditions
%----------------------------------------------------------------------
debug = false;
debug_key = true;
conBlack = false;
%----------------------------------------------------------------------
% Essential Paths
%----------------------------------------------------------------------
currentDir = pwd;
ImgPath = fullfile(currentDir,'Pictures','Object');
ImgPracPath = fullfile(currentDir,'Pictures', 'PicsPracObj');
ImgEmoPath = fullfile(currentDir,"Pictures");
addpath(genpath(currentDir));
if ~exist(fullfile(currentDir, 'Results'),'dir')
mkdir(fullfile(currentDir, 'Results'))
end
resultsDir = fullfile(currentDir,'Results');
%----------------------------------------------------------------------
% Monitor
%----------------------------------------------------------------------
% Set the screen number to the external secondary monitor if there is one
% connected
screenNumber = max(Screen('Screens'));
% Screen('Preference', 'SkipSyncTests', 0)
% Query the maximum priority level
% topPriorityLevel = MaxPriority(window);
% Priority(topPriorityLevel);
% Define black, white and grey
white = WhiteIndex(screenNumber);
WhiteTrans = [white white white 0.5];
grey = (white*.5412);
black = BlackIndex(screenNumber);
% Open the screen
if debug
winCor = []; %[0 0 720 450];
else
winCor = [];
end
if conBlack
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, black, winCor, 32, 2);
else
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey, winCor, 32, 2);
end
% Flip to clear
DrawFormattedText(window, 'Please wait!!!',...
'center', 'center', white);
vbl = Screen('Flip', window);
HideCursor();
% Query the frame duration
ifi = Screen('GetFlipInterval', window);
% Get the size of the on screen window
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
% Get the centre coordinate of the window
[xCenter, yCenter] = RectCenter(windowRect);
% Set the blend funciton for the screen
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% We will use a range of text sizes
textSize = 44;
smallTextSize = 32;
% Set just now to the standard text size
Screen('TextSize', window, textSize);
Screen('TextFont',window, 'Helvetica');
Screen('TextStyle', window, 0);
%----------------------------------------------------------------------
% Timing Information
%----------------------------------------------------------------------
% Number of frames to wait before updating the screen
waitframes = 1;
% The timing will be base time (stimulusTime)
% plus a random variable ranging from
% 0-stimulusExtra
stimulusTimeChoice = 1.5;
stimulusTimePreference = 4;
stimulusTimeColorTest= 10;
if debug
% you can chnage the number of trials for
% the practice and main part
NumberofTrials = [6; 6; 4];
NumberofTrialsPractice = [1; 1; 1];
attention_trial = 2;
color_attention_trial = 2;
color_attention_trial_learning = 2;
attentionTime = 3*6;
attentionTimeLong = 8*6;
endTime = 5;
% wait for Key press interval time in seconds
waitVarLong = .5;
waitVarShort = .3;
waitPunishment = .5;
else
% you can chnage the number of trials for
% the practice and main part
NumberofTrials = [48; 48; 15];
NumberofTrialsPractice = [6; 6; 6];
attention_trial = 4;
color_attention_trial = 10;
color_attention_trial_learning = 8;
attentionTime = 3*60;
attentionTimeLong = 8*60;
endTime = 20;
% wait for Key press interval time in seconds
waitVarLong = 3.5;
waitVarShort = .3;
waitPunishment = 1.5;
end
% Learning Timing
stimulusTimeAAT = .65;
stimulusTimeEC = .65;
waitLearningAAT = 2;
waitLearningEC = 2;
TimeBegin = GetSecs;
AttentionTestFailed = false;
%----------------------------------------------------------------------
% Fixation Cross
%----------------------------------------------------------------------
% Here we set the size of the arms of our fixation cross
fixCrossDimPix = 40;
% Now we set the coordinates (these are all relative to zero we will let
% the drawing routine center the cross in the center of our monitor for us)
xCoords = [-fixCrossDimPix fixCrossDimPix 0 0];
yCoords = [0 0 -fixCrossDimPix fixCrossDimPix];
allCoords = [xCoords; yCoords];
% Set the line width for our fixation cross
lineWidthPix = 6;
%----------------------------------------------------------------------
% Keyboard information
%----------------------------------------------------------------------
% Define the keyboard keys that are listened for. We will be using the left
% and right arrow keys as response keys for the task and the escape key as
% a exit/reset key
escapeKey = KbName('ESCAPE');
leftKey = KbName('LeftArrow');
rightKey = KbName('RightArrow');
downKey = KbName('DownArrow');
upKey = KbName('UpArrow');
aKey = KbName('a');
dKey = KbName('d');
gKey = KbName('g');
kKey = KbName('k');
qKey = KbName('q');
rKey = KbName('r');
uKey = KbName('u');
cKey = KbName('c');
mKey = KbName('m');
key1 = KbName('1!');
key2 = KbName('2@');
key3 = KbName('3#');
key4 = KbName('4$');
spacekey = KbName('space');
%----------------------------------------------------------------------
% Likert Scale
%----------------------------------------------------------------------
% Our scale will span a proportion of the screens x dimension
scaleLengthPix = screenYpixels / 1.5;
scaleHLengthPix = scaleLengthPix / 2;
% setting the y position of the elements
yDownward = .24;
yScalePosition = yCenter + screenYpixels*yDownward;
% Coordiantes of the scale left and right ends
leftEnd = [xCenter - scaleHLengthPix yScalePosition];
rightEnd = [xCenter + scaleHLengthPix yScalePosition];
scaleLineCoords = [leftEnd' rightEnd'];
% Scale line thickness
scaleLineWidth = 10;
% Make a base Rect relative to the size of the screen: this will be the
% toggle we can slide on the slider
dim = screenYpixels / 36;
hDim = dim / 2;
baseRect = [0 0 dim/2 dim*1.5];
% Number of lines on our likert scale
numScaleLines = 11;
% The lines will be linearly spaced over the scale: here we make the xy
% coordinateas of each point
xPosScaleLines = linspace(xCenter - scaleHLengthPix, xCenter + scaleHLengthPix, numScaleLines);
yPosScaleLines = repmat(yScalePosition, 1, numScaleLines);
xyScaleLines = [xPosScaleLines-2; yPosScaleLines - 10; xPosScaleLines + 2; yPosScaleLines + 10];
% Text labels for the scale
sliderLabels = {lowerLikert, upperLikert};
% Get bounding boxes for the scale end label text
textBoundsAll = nan(2, 4);
for i = 1:2
[~, ~, textBoundsAll(i, :)] = DrawFormattedText(window, sliderLabels{i}, 0, 0, white);
end
% Width and height of the scale end label text bounding boxs
textWidths = textBoundsAll(:, 3)';
textHeights = (-textBoundsAll(:, 2) + textBoundsAll(:, 4))';
halfTextHeights = textHeights / 2;
% Do the same for the numbers that we will put on the buttons. Here we
% toggle first to the smaller text size we will be using for the labels for
% the buttons then reinstate the standard text size
numBoundsAll = nan(numScaleLines, 4);
for i = 1:numScaleLines
[~, ~, numBoundsAll(i, :)] = DrawFormattedText(window, num2str(i), 0, 0, white);
end
% Width and height of the scale number text bounding boxs
numWidths = numBoundsAll(:, 3)';
halfNumWidths = numWidths / 2;
numHeights = (-numBoundsAll(:, 2) + numBoundsAll(:, 4))';
halfNumHeights = numHeights / 2;
% Position of the scale text so that it is at the ends of the scale but does
% not overlap with the scales lines. Make sure it is also
% centered in the y dimension of the screen. To do this we used the bounding
% boxes of the text, plus a little gap so that the text does not completely
% edge the slider toggle in the x dimension
textPixGap = 50;
leftTextPosX = xCenter - scaleHLengthPix - hDim - textWidths(1) - textPixGap;
rightTextPosX = xCenter + scaleHLengthPix + hDim + textPixGap;
leftTextPosY = yScalePosition + halfTextHeights(1);
rightTextPosY = yScalePosition + halfTextHeights(2);
% The numbers are aligned to be directly under the relevent button (tops of
% their bounding boxes "numShiftDownPix" below the button y coordinate, and
% aligned laterally such that the centre of the text bounding boxes aligned
% with the x coordinate of the button
numShiftDownPix = 80;
xNumText = xPosScaleLines - halfNumWidths;
yNumText = yPosScaleLines + halfNumHeights + numShiftDownPix;
% Our slider will span a proportion of the screens x dimension
sliderLengthPix = screenYpixels / 1.5;
sliderHLengthPix = sliderLengthPix / 2;
%----------------------------------------------------------------------
% Attention vector
%----------------------------------------------------------------------
attention_counter = 0;
InBetweenTask_vec = [InBetweenTask1; InBetweenTask2; InBetweenTask3; InBetweenTask4];
InBetweenTask_key = [aKey, dKey, gKey, kKey];
color_test_correct = 0;
color_test_number = 0;
%----------------------------------------------------------------------
% Participant Info
%----------------------------------------------------------------------
% Rect for the stopsign
squareSize = 150;
rectStop = [xCenter - squareSize, yCenter - squareSize,...
xCenter + squareSize, yCenter + squareSize];
StopY = yCenter + screenYpixels*.20;
try
getNumber = true;
participantNum = 100000 + randperm(899999,1);
while getNumber
if ~isfolder(fullfile(resultsDir, ['Participant_', int2str(participantNum)]))
getNumber = false;
else
participantNum = 100000 + randperm(899999,1);
end
end
participantNumInt = participantNum;
participantNum = int2str(participantNum);
if ~exist(fullfile(resultsDir, ['Participant_', participantNum]),'dir')
mkdir(fullfile(resultsDir, ['Participant_', participantNum]))
end
ParticipantDir = fullfile(resultsDir, ['Participant_', participantNum]);
% Text with attention time
AttentionTestFailed = general_attention(ParText, waitVarShort*3, 1);
if AttentionTestFailed
return
end
catch error
pnet('closeall');
sca;
warning('something is not working properly: Participant Number!!');
rethrow(error);
end
%----------------------------------------------------------------------
% Sound Setting
%----------------------------------------------------------------------
AssertOpenGL;
Fs = 48000; % Sampling Frequency wave high
secs = .1;
t = linspace(0, secs, Fs*secs+1); % Time Vector + 1 sample
t(end) = []; % remove extra sample
w1 = 2*pi*1440;
s1 = [sin(w1*t); sin(w1*t)];
w2 = 2*pi*2500; % Radian Value To Create 1440 Hz Tone
s2 = [sin(w2*t); sin(w2*t)]; % Create second Tone
% Counterbalancing the sound order based on the participants number
sound = [];
sound_name = [];
if rem(participantNumInt,4) == 0
sound = [{s1} {s2}];
sound_name = [{'S1'} {'S2'}];
elseif rem(participantNumInt,4) == 1
sound = [{s2} {s1}];
sound_name = [{'S2'} {'S1'}];
elseif rem(participantNumInt,4) == 2
sound = [{s2} {s1}];
sound_name = [{'S2'} {'S1'}];
elseif rem(participantNumInt,4) == 3
sound = [{s1} {s2}];
sound_name = [{'S1'} {'S2'}];
end
save(fullfile(ParticipantDir, strcat('sound_', participantNum, '.mat')), 'sound');
% % Perform basic initialization of the sound driver:
% InitializePsychSound;
nrchannels = 2;
% Try with the 'freq'uency we wanted:
pahandle = PsychPortAudio('Open', [], [], 0, Fs, nrchannels);
try
% Sound checkup
sound_test_order = repelem([1 2], 3);
sound_test_order = sound_test_order(randperm(length(sound_test_order)));
ll = 1;
DrawFormattedText(window, SoundText,...
'center', 'center', white);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
WaitSecs(waitVarShort*3);
timeStart = GetSecs;
wait = true;
while wait && GetSecs - timeStart < attentionTime
if (GetSecs - timeStart) > (attentionTime - endTime)
img = imread(fullfile(ImgEmoPath,'StopSign', 'Stop.png'));
Texture = Screen('MakeTexture', window, img);
Screen('DrawTexture', window, Texture, [], rectStop);
DrawFormattedText(window, InBetweenTextAttention,...
'center', StopY, white)
DrawFormattedText(window, SoundTextShort,...
'center', StopY*1.15, white);
else
DrawFormattedText(window, SoundText,...
'center', 'center', white);
end
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
% Fill the audio playback buffer with the audio data 'wavedata':
PsychPortAudio('FillBuffer', pahandle, sound{sound_test_order(ll)});
if ll < length(sound_test_order)
ll = ll +1;
else
ll = 1;
sound_test_order = sound_test_order(randperm(length(sound_test_order)));
end
% Start audio playback for 'repetitions' repetitions of the sound data,
% start it immediately (0) and wait for the playback to start, return onset
% timestamp.
t1 = PsychPortAudio('Start', pahandle, 1, 0, 1);
timeStartSound = GetSecs;
while (GetSecs - timeStartSound) < 4*waitVarShort
RestrictKeysForKbCheck(spacekey);
[keyIsDown,secs, keyCode] = KbCheck;
if keyCode(spacekey)
wait = false;
end
end
end
if wait && (GetSecs - timeStart) > attentionTime
% Setting the parameters for the last part
AttentionTestFailed = true;
TimeEnd = GetSecs-TimeBegin;
attentional_text(ParticipantDir, participantNum, AttentionTestFailed, TimeEnd, ...
color_test_correct, color_test_number)
img = imread(fullfile(ImgEmoPath,'StopSign', 'Stop.png'));
Texture = Screen('MakeTexture', window, img);
Screen('DrawTexture', window, Texture, [], rectStop);
DrawFormattedText(window, UnattentiveText,...
'center', StopY, white)
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
WaitSecs(waitPunishment);
ShowCursor;
close all
warning('Terminated by user input:!!nothing is saved!!')
sca;
return
end
catch error
pnet('closeall');
sca;
warning('something is not working properly: Participant Number!!');
rethrow(error);
end
%----------------------------------------------------------------------
% logfile
%----------------------------------------------------------------------
ChoiceResponses = [];
realNumber = [];
realSychronicity = [];
realDuration = [];
TaskOneData = struct('ID',{}, 'Session', {},'TrialID1',{},'ImageNr',{},'Color',{},...
'YesNoPosition',{},'RT',{},'Choice',{});
TaskTwoData = struct('ID',{}, 'Session', {},'TrialID2',{},'ImageNr',{},'Color',{},...
'LikertPos',{},'RT',{}, 'Pref',{});
TaskThreeData = struct('ID',{}, 'Session', {},'TrialID3',{},'ImageRightNr',{},...
'ImageLeftNr',{}, 'ColorImageRight',{},'ColorImageLeft',{},...
'Choice',{},'RT',{});
LearningData = struct('ID',{}, 'Session', {},'TrialID',{},'ImageNr',{},...
'Color',{}, 'LearningMethod',{}, 'LearningValence',{},'Response',{},...
'RT',{},'RTAfter',{},'Accuracy', {},'ExtraTime',{},'YesNoPosition',{},...
'SoundWave',{},'SoundOrder',{},'ECImageValence',{}, 'ECImageNr',{}, ...
'Block_order_var',{});
for sessionNum = 1:3
%----------------------------------------------------------------------
% Images
%----------------------------------------------------------------------
% Practice Images
dirImagesPrac = dir(ImgPracPath);
list= cellfun(@isempty,regexp({dirImagesPrac.name},'.*\.png$'));
dirImagesPrac=dirImagesPrac(~list);
dirImagesPrac = dirImagesPrac(randperm(size(dirImagesPrac, 1)), :);
% Main Images
dirImages = dir(ImgPath);
list= cellfun(@isempty,regexp({dirImages.name},'.*\.png$'));
dirImages=dirImages(~list);
dirImages = dirImages(randperm(size(dirImages, 1)), :);
if sessionNum == 1
color = [{'r'}; {'b'}; {'y'}; {'o'}; {'g'}; {'p'}];
color = color(randperm(size(color, 1)), :)';
n =length(dirImages)/length(color);
color_vec = repmat(color,1,n)';
[dirImages.color] = color_vec{:};
save(fullfile(ParticipantDir, strcat('color_', participantNum, '.mat')), 'color');
save(fullfile(ParticipantDir, strcat('dirImages_', participantNum, '.mat')), 'dirImages');
elseif sessionNum == 3 || sessionNum == 2
if isfile(fullfile(ParticipantDir,strcat('dirImages_', participantNum, '.mat')))
load(fullfile(ParticipantDir,strcat('dirImages_', participantNum, '.mat')));
load(fullfile(ParticipantDir,strcat('color_', participantNum, '.mat')));
else
pnet('closeall');
sca;
error(sprintf(['The participant should first finish the first session correctly!\n' ...
'Also please check whether you entered the participants ID correctly.']));
rethrow(error);
end
end
% randomizing the practice vectors
colorPrac = [{'.'}; {','}; {';'}; {'['}; {']'}; {'!'}];
[dirImagesPrac.color] = colorPrac{:};
dirImagesTask1Prac = dirImagesPrac(randperm(size(dirImagesPrac, 1)), :);
dirImagesTask2Prac = dirImagesPrac(randperm(size(dirImagesPrac, 1)), :);
% randomizing the Task One vector
randomize = true;
while randomize
randomize = false;
dirImagesTask1 = dirImages(randperm(size(dirImages, 1)), :);
for ii = 3:length(dirImagesTask1)
if strcmp(dirImagesTask1(ii).color,dirImagesTask1(ii-1).color)
if strcmp(dirImagesTask1(ii-1).color,dirImagesTask1(ii-2).color)
randomize = true;
end
end
end
end
% randomizing the Task Two vector
randomize = true;
while randomize
randomize = false;
dirImagesTask2 = dirImages(randperm(size(dirImages, 1)), :);
for ii = 3:length(dirImagesTask2)
if strcmp(dirImagesTask2(ii).color,dirImagesTask2(ii-1).color)
if strcmp(dirImagesTask2(ii-1).color,dirImagesTask2(ii-2).color)
randomize = true;
end
end
end
end
dirImagesTask3 = struct('NameRight', {}, 'NameLeft', {},...
'ColorRight', {}, 'ColorLeft', {});
dirImagesTask3Prac =struct('NameRight', {}, 'NameLeft', {},...
'ColorRight', {}, 'ColorLeft', {});
if sessionNum == 3
dirImagesTask3 = task_three_maker(dirImages,color, NumberofTrials);
dirImagesTask3Prac = task_three_maker(dirImagesPrac,colorPrac', NumberofTrialsPractice);
end
% randomizing the Task Three vector
dirImagesTask3 = dirImagesTask3(randperm(size(dirImagesTask3, 1)), :);
dirImagesTask3Prac = dirImagesTask3Prac(randperm(size(dirImagesTask3Prac, 1)), :);
% loading a template Image for finding the size of the image
imgSize = imread(fullfile(ImgPath, dirImagesTask1(1).name));
% Rect for the faces
scaleFactor = .25;
baseSize = scaleFactor*[size(imgSize,2) size(imgSize,1)];
rect = [xCenter - baseSize(1)/2, yCenter - baseSize(2)/2,...
xCenter + baseSize(1)/2, yCenter + baseSize(2)/2];
% Rect for the stopsign
squareSize = 150;
rectStop = [xCenter - squareSize, yCenter - squareSize,...
xCenter + squareSize, yCenter + squareSize];
% Rect for comparative choice task
scaleFactorComp = .25;
baseSizeComp = scaleFactorComp*[size(imgSize,2) size(imgSize,1)];
xCenterRight = screenXpixels*.60;
rectRight = [xCenterRight - baseSizeComp(1)/2, yCenter - baseSizeComp(2)/2,...
xCenterRight + baseSizeComp(1)/2, yCenter + baseSizeComp(2)/2];
xCenterLeft = screenXpixels*.40;
rectLeft = [xCenterLeft - baseSizeComp(1)/2, yCenter - baseSizeComp(2)/2,...
xCenterLeft + baseSizeComp(1)/2, yCenter + baseSizeComp(2)/2];
% position of questions according to images
YesNoX = [xCenter + baseSize(1)/2 - 55, xCenter - baseSize(1)/2 - 20];
YesNoY = yCenter + screenYpixels*yDownward;
StopY = yCenter + screenYpixels*.20;
% Producing Zooming matrix based on the image size
ZoomingDistance = 50;
ZoomingDistanceMin = 30;
xyZoomScale=(size(imgSize,2)/size(imgSize,1));
ZoomingMatrix = 2*[-1*xyZoomScale,-1,1*xyZoomScale,1];
% Rect for the box
pen_width = 10;
baseBoxNum = 20;
rectBox = rect + [-baseBoxNum*xyZoomScale,-baseBoxNum,baseBoxNum*xyZoomScale,baseBoxNum];
rectBoxRight = rectRight + [-baseBoxNum*xyZoomScale,-baseBoxNum,baseBoxNum*xyZoomScale,baseBoxNum];
rectBoxLeft = rectLeft + [-baseBoxNum*xyZoomScale,-baseBoxNum,baseBoxNum*xyZoomScale,baseBoxNum];
%----------------------------------------------------------------------
% creating the LearningImageVector
%----------------------------------------------------------------------
if sessionNum == 2
dirImagesLearning = struct;
LearningMethod = [{'AAT'} {'EC'}];
LearningValence = [{'p'} {'m'} {'n'}];
for ii = 1:length(LearningMethod)
for jj = 1:length(LearningValence)
tmp = [];
if ii == 1
tmp = [dirImages([dirImages.color] == color{jj})];
elseif ii == 2
tmp = [dirImages([dirImages.color] == color{(jj+3)})];
end
LearningMethod_vec = repmat(LearningMethod(ii),1,length(tmp));
[tmp.LearningMethod] = LearningMethod_vec{:};
LearningValence_vec = repmat(LearningValence(jj),1,length(tmp));
[tmp.LearningValence] = LearningValence_vec{:};
if ii == 1 && jj == 1
f = fieldnames(tmp)';
f{2,1} = {};
dirImagesLearning = struct(f{:});
end
for kk = 1:length(tmp)
dirImagesLearning(end+1) = tmp(kk);
end
end
end
% randomizing the LearningVector for separate mini blocks
dirImagesLearning = struct2table(dirImagesLearning');
dirImagesLearningAAT = dirImagesLearning(strcmp(dirImagesLearning.LearningMethod, 'AAT'),:);
dirImagesLearningAAT = dirImagesLearningAAT(randperm(size(dirImagesLearningAAT, 1)), :);
dirImagesLearningEC = dirImagesLearning(strcmp(dirImagesLearning.LearningMethod, 'EC'),:);
dirImagesLearningEC = dirImagesLearningEC(randperm(size(dirImagesLearningEC, 1)), :);
dirImagesLearning = table2struct( ...
[dirImagesLearningAAT(1:height(dirImagesLearningAAT)/2,:);...
dirImagesLearningEC(1:height(dirImagesLearningEC)/2,:);...
dirImagesLearningAAT((height(dirImagesLearningAAT)/2)+1:end,:);...
dirImagesLearningEC((height(dirImagesLearningEC)/2)+1:end,:)] ...
);
% the LearningVector for practice part
dirImagesLearningPrac = [dirImagesPrac(randperm(size(dirImagesPrac, 1)), :); ...
dirImagesPrac(randperm(size(dirImagesPrac, 1)), :)];
PracLearningMethodVector = [{'AAT'} {'AAT'} {'AAT'} {'AAT'} {'AAT'} {'AAT'} ...
{'EC'} {'EC'} {'EC'} {'EC'} {'EC'} {'EC'}];
[dirImagesLearningPrac.LearningMethod] = PracLearningMethodVector{:};
PracLearningValence = [{'p'} {'m'} {'n'} {'p'} {'m'} {'n'} {'p'} {'m'} {'n'} {'p'} {'m'} {'n'}];
[dirImagesLearningPrac.LearningValence] = PracLearningValence{:};
dirImagesPositive = dir(fullfile(ImgEmoPath,'Positive'));
list= cellfun(@isempty,regexp({dirImagesPositive.name},'.*\.jpg$'));
dirImagesPositive=dirImagesPositive(~list);
dirImagesPositive = dirImagesPositive(randperm(size(dirImagesPositive, 1)), :);
dirImagesNegative = dir(fullfile(ImgEmoPath,'Negative'));
list= cellfun(@isempty,regexp({dirImagesNegative.name},'.*\.jpg$'));
dirImagesNegative=dirImagesNegative(~list);
dirImagesNegative = dirImagesNegative(randperm(size(dirImagesNegative, 1)), :);
% loading a template Image for finding the size of the image
imgSize2 = imread(fullfile(dirImagesPositive(1).folder, dirImagesPositive(1).name));
% Rect for the emotional images
scaleFactorEmo = .4;
xCenterRightEmo = screenXpixels*.65;
xCenterLeftEmo = screenXpixels*.35;
baseSize2 = scaleFactorEmo*[size(imgSize2,2) size(imgSize2,1)];
rect2 = [xCenter - baseSize2(1)/2, yCenter - baseSize2(2)/2,...
xCenter + baseSize2(1)/2, yCenter + baseSize2(2)/2];
rect2Left = [xCenterLeftEmo - baseSize2(1)/2, yCenter - baseSize2(2)/2,...
xCenterLeftEmo + baseSize2(1)/2, yCenter + baseSize2(2)/2];
rect2Right = [xCenterRightEmo - baseSize2(1)/2, yCenter - baseSize2(2)/2,...
xCenterRightEmo + baseSize2(1)/2, yCenter + baseSize2(2)/2];
end
if sessionNum == 1
% Text with attention time
AttentionTestFailed = general_attention(ParText2, waitVarShort*3, 4);
if AttentionTestFailed
return
end
end
%----------------------------------------------------------------------
% Experimental loop
%----------------------------------------------------------------------
try
%----------------------------------------------------------------------
% Adiminstrating Tasks
%----------------------------------------------------------------------
if sessionNum == 1 || sessionNum == 3
iBlocks = 8;
startingBlock = 1;
if sessionNum == 3
startingBlock = 3;
end
% Text with attention time
if sessionNum == 1
AttentionTestFailed = general_attention(SessionOneText, waitVarLong);
elseif sessionNum == 3
AttentionTestFailed = general_attention(SessionThreeText, waitVarLong);
end
if AttentionTestFailed
return
end
for Block = startingBlock:iBlocks
%----------------------------------------------------------------------
% The Choice Task
%----------------------------------------------------------------------
if Block == 1 || Block == 3 || Block == 5 || Block == 7
Screen('TextSize', window, textSize);
if Block == 1
numTrials = NumberofTrialsPractice(1);
else
numTrials = NumberofTrials(1);
end
isiTimeSecs = .45 + rand(numTrials,1)/10; isiTimeFrames = round(isiTimeSecs / ifi);
% Text with attention time
if Block == 3 && sessionNum == 3
AttentionTestFailed = general_attention(RestTextOneBlockThree, waitVarLong/2);
elseif Block == 1
AttentionTestFailed = general_attention(TaskOneText, waitVarLong/2);
elseif Block == 3 && sessionNum == 1
AttentionTestFailed = general_attention(EndofPracticeText, waitVarLong/2);
elseif Block == 5 || Block == 7
AttentionTestFailed = general_attention(RestTextOne, waitVarLong/2);
end
if AttentionTestFailed
return
end
if Block ~= 1
if debug
attention_trial_vec = attention_vector(NumberofTrials, 1, attention_trial,2);
color_attention_trial_vec = color_attention_vector(NumberofTrials, 1, color_attention_trial);
else
attention_trial_vec = attention_vector(NumberofTrials, 1, attention_trial,6);
color_attention_trial_vec = color_attention_vector(NumberofTrials, 1, color_attention_trial);
end
end
for trial= 1: numTrials
% start of the main task
trialsub = [];
if Block == 1 || Block == 3
trialsub = trial;
elseif Block == 5
trialsub = trial + numTrials;
elseif Block == 7
trialsub = trial + 2*numTrials;
end
Screen('DrawLines', window, allCoords,...
lineWidthPix, white, [xCenter yCenter], 2);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
WaitSecs(isiTimeFrames(trial)*ifi);
RT = [];
Choice = [];
% Drawing the yes-no question
DrawFormattedText(window, YesText,...
YesNoX(1), YesNoY, white);
DrawFormattedText(window, NoText,...
YesNoX(2), YesNoY, white);
% loading the image for the presentation
if Block == 1
img = imread(fullfile(ImgPracPath, dirImagesTask1Prac(trialsub).name));
colortmp = colorTranslator(dirImagesTask1Prac(trialsub).color);
img = coloring_fucntion(img, colortmp);
else
img = imread(fullfile(ImgPath, dirImagesTask1(trialsub).name));
colortmp = colorTranslator(dirImagesTask1(trialsub).color);
img = coloring_fucntion(img, colortmp);
end
% drawing the Image
Texture = Screen('MakeTexture', window, img);
% drawing the box around the image
Screen('FrameRect', window, colortmp, rectBox, pen_width);
%drawing the image
Screen('DrawTexture', window, Texture, [], rect);
% Flip to the screen
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
timeStart = GetSecs;
WaitSecs(waitVarShort);
RestrictKeysForKbCheck([]);
respToBeMade = true;
while respToBeMade && (GetSecs - timeStart) < stimulusTimeChoice
% Check the keyboard. The person should press either
% 'm' or 'c' to accept or reject the picture
[keyIsDown,secs, keyCode] = KbCheck;
if keyCode(escapeKey) && debug_key
ShowCursor;
close all
warning('Terminated by user input:!!nothing is saved!!')
sca;
return
elseif keyCode(mKey)
Choice = 'Yes';
RT = GetSecs - timeStart;
respToBeMade = false;
elseif keyCode(cKey)
Choice = 'No';
RT = GetSecs - timeStart;
respToBeMade = false;
end
end
% For the missing trials
if respToBeMade
% Punishment Image
img = imread(fullfile(ImgEmoPath,'StopSign', 'Stop.png'));
Texture = Screen('MakeTexture', window, img);
Screen('DrawTexture', window, Texture, [], rectStop);
DrawFormattedText(window, StopText,...
'center', StopY, white);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
WaitSecs(waitPunishment);
respToBeMade = false;
end
% Managing logfiles
if Block ~= 1
TaskOneData(trialsub).ID = ['Sub_', num2str(participantNum)];
TaskOneData(trialsub).Session = ['Session_', num2str(sessionNum)];
TaskOneData(trialsub).TrialID1 = ['Trial_',num2str(trialsub)];
TaskOneData(trialsub).ImageNr = dirImagesTask1(trialsub).name;
TaskOneData(trialsub).Color = dirImagesTask1(trialsub).color;
TaskOneData(trialsub).YesNoPosition = '1';
TaskOneData(trialsub).RT = RT;
TaskOneData(trialsub).Choice = Choice;
end
%----------------------------------------------------------------------
% Attention test
%----------------------------------------------------------------------
if Block ~= 1 && any(trial == color_attention_trial_vec)
Screen('DrawLines', window, allCoords,...
lineWidthPix, white, [xCenter yCenter], 2);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
WaitSecs(isiTimeFrames(trial)*ifi);
[color_test_correct, color_test_number] = color_test(dirImagesTask1(trialsub).color, ...
color_test_correct, color_test_number);
end
if Block ~= 1 && any(trial == attention_trial_vec)
Screen('DrawLines', window, allCoords,...
lineWidthPix, white, [xCenter yCenter], 2);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
WaitSecs(isiTimeFrames(trial)*ifi);
[AttentionTestFailed,attention_counter] = attention_frame_test(attention_counter);
if AttentionTestFailed
return
end
end
end
%----------------------------------------------------------------------
% The Preference Task
%----------------------------------------------------------------------
elseif Block == 2 || Block == 4 || Block == 6 || Block == 8
Screen('TextSize', window, smallTextSize);
if Block == 2
numTrials = NumberofTrialsPractice(2);
else
numTrials = NumberofTrials(2);
end
Screen('TextSize', window, textSize);
isiTimeSecs = .45 + rand(numTrials,1)/10; isiTimeFrames = round(isiTimeSecs / ifi);
% Text with attention time
if Block == 2
AttentionTestFailed = general_attention(TaskTwoText, waitVarLong/2);
elseif Block == 4
AttentionTestFailed = general_attention(RestTextTwoOne, waitVarLong/2);
elseif Block == 6 || Block == 8
AttentionTestFailed = general_attention(RestTextTwo, waitVarLong/2);
end
if AttentionTestFailed
return
end
if Block ~= 2
if debug
attention_trial_vec = attention_vector(NumberofTrials, 2, attention_trial,2);
color_attention_trial_vec = color_attention_vector(NumberofTrials, 2, color_attention_trial);
else
attention_trial_vec = attention_vector(NumberofTrials, 2, attention_trial,6);
color_attention_trial_vec = color_attention_vector(NumberofTrials, 2, color_attention_trial);
end
end
for trial= 1: numTrials
% start of the main task
trialsub = [];
if Block == 2 || Block == 4
trialsub = trial;
elseif Block == 6
trialsub = trial+numTrials;
elseif Block == 8
trialsub = trial+2*numTrials;
end
Screen('DrawLines', window, allCoords,...
lineWidthPix, white, [xCenter yCenter], 2);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
WaitSecs(isiTimeFrames(trial)*ifi);
RT = [];
Pref = [];
% Reading the correct Image
if Block ==2
img = imread(fullfile(ImgPracPath, dirImagesTask2Prac(trialsub).name));
colortmp = colorTranslator(dirImagesTask2Prac(trialsub).color);
img = coloring_fucntion(img, colortmp);
else
img = imread(fullfile(ImgPath, dirImagesTask2(trialsub).name));
colortmp = colorTranslator(dirImagesTask2(trialsub).color);
img = coloring_fucntion(img, colortmp);
end
Texture = Screen('MakeTexture', window, img);
% Draw the scale line
Screen('DrawLines', window, scaleLineCoords, scaleLineWidth, WhiteTrans);
% Text for the ends of the slider
DrawFormattedText(window, sliderLabels{1}, leftTextPosX, leftTextPosY, WhiteTrans);
DrawFormattedText(window, sliderLabels{2}, rightTextPosX, rightTextPosY, WhiteTrans);
% Draw the Question for the slider
% DrawFormattedText(window, LikertQues, 'center', yCenter + screenYpixels*.25, white);
% Draw the likert scale lines
Screen('FillRect', window, WhiteTrans, xyScaleLines);
% We now set the toggles initial position
sx = xPosScaleLines(round(length(xPosScaleLines)/2));
centeredRect = CenterRectOnPointd(baseRect, sx, yPosScaleLines(1));
% Draw the slider
Screen('FillRect', window, white , centeredRect);
% drawing the box around the image
Screen('FrameRect', window, colortmp, rectBox, pen_width);
% Draw the actual image
Screen('DrawTexture', window, Texture, [], rect);
% Flip to show
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
% Preparing for the response
RestrictKeysForKbCheck([]);
respToBeMade = true;
% Here we set the initial position of the mouse to the centre of the screen
SetMouse(xCenter, yCenter, window);
% timing information
timeStart = GetSecs;
WaitSecs(waitVarShort);
while respToBeMade && (GetSecs - timeStart) < stimulusTimePreference
% Get the current position of the mouse
[mx, my, buttons] = GetMouse(window);
% sliding the red cox based on the cursor's
% psoition
if mx > xCenter + scaleHLengthPix
sx = xCenter + scaleHLengthPix;
elseif mx < xCenter - scaleHLengthPix
sx = xCenter - scaleHLengthPix;
else
sx = mx;
end
Preftmp = (sx - (xCenter - scaleHLengthPix)) / scaleLengthPix;
% Check the keyboard
[keyIsDown,secs, keyCode] = KbCheck;
if keyCode(escapeKey) && debug_key
ShowCursor;
close all
warning('Terminated by user input:!!nothing is saved!!')
sca;
return
elseif buttons(1) || buttons (2) || buttons (3)
RT = GetSecs - timeStart;
Pref = Preftmp;
respToBeMade = false;
end
% Draw the scale line
Screen('DrawLines', window, scaleLineCoords, scaleLineWidth, WhiteTrans);
% Text for the ends of the slider
DrawFormattedText(window, sliderLabels{1}, leftTextPosX, leftTextPosY, WhiteTrans);
DrawFormattedText(window, sliderLabels{2}, rightTextPosX, rightTextPosY, WhiteTrans);
% Draw the Question for the slider
% DrawFormattedText(window, LikertQues, 'center', yCenter + screenYpixels*.25, white);
% Draw the likert scale lines
Screen('FillRect', window, WhiteTrans, xyScaleLines);
% Center the slidre toggle on its new screen position
centeredRect = CenterRectOnPointd(baseRect, sx, yPosScaleLines(1));
Screen('FillRect', window, white , centeredRect);
% drawing the box around the image
Screen('FrameRect', window, colortmp, rectBox, pen_width);
% Draw the actual image
Screen('DrawTexture', window, Texture, [], rect);
% Report the current slider position
% DrawFormattedText(window, ['Rating: ' num2str(round(Preftmp * 100)) '%'],...