-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask04.m
More file actions
262 lines (223 loc) · 9.1 KB
/
task04.m
File metadata and controls
262 lines (223 loc) · 9.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
function task04( logpars, PTB, LPT)
% 3-alternative forced choice task
ver = '2.0';
fprintf('3-alternative forced choice task version %s\n', ver);
fprintf('\n\n');
%% init experiment structure
EXP = {};
EXP.stimsdir = fullfile('textures-03');
EXP.assetsdir = fullfile('assets');
EXP.baseImg = [0 0 800 600];
EXP.baseImgSource = [0 0 800 600];
EXP.framePix = 4;
EXP.dotColor = [0 1; 0 1; 0 1];
EXP.dotSize = [20 14];
EXP.fixCrossDimPix = 80;
EXP.fixCrossWidth = 4;
EXP.xCoords = [-EXP.fixCrossDimPix EXP.fixCrossDimPix 0 0];
EXP.yCoords = [0 0 -EXP.fixCrossDimPix EXP.fixCrossDimPix];
EXP.allCoords = [EXP.xCoords; EXP.yCoords];
EXP.afcInstruction = 'Was wäre jetzt am wahrscheinlichsten gewesen?';
EXP.afcInst_yaxis = PTB.yCenter - 200;
EXP.markerTrialOn = 2;
EXP.markerTrialOff = 4;
EXP.markerStartTask = 150;
EXP.markerEndTask = 152;
EXP.RespFeedSec = .25;
EXP.sourceDuration = 3;
EXP.iti = 2;
EXP.keyCodeLeft = KbName('LeftArrow');
EXP.keyCodeCenter = KbName('DownArrow');
EXP.keyCodeRight = KbName('RightArrow');
%% get randomization
if str2double(logpars.subjid) == 1000
EXP.id = 1;
else
EXP.id = str2double(logpars.subjid);
EXP.id = EXP.id - 1000;
end
SI = load(fullfile(EXP.assetsdir, 'imgs_randomization.mat'));
EXP.imgs = SI.XX(EXP.id, :);
S = load(fullfile(EXP.assetsdir, 'afc_randomization.mat'));
EXP.XX = S.XX(EXP.id).X;
%% draw screen textures
% prepare image size for question options
if logpars.smallscreen == 1
EXP.baseImg = round(EXP.baseImg*.3);
elseif logpars.smallscreen == 2
EXP.baseImg = round(EXP.baseImg*.1);
else
EXP.baseImg = round(EXP.baseImg*.5);
end
% scale single source images to screensize
if logpars.smallscreen == 1
EXP.baseImgSource = round(EXP.baseImgSource*.66);
elseif logpars.smallscreen == 2
EXP.baseImgSource = round(EXP.baseImgSource*.33);
end
% load images and rescale them
EXP.textures = cell(length(EXP.imgs), 1);
for i=1:length(EXP.imgs)
img = imread(fullfile(EXP.stimsdir, EXP.imgs{i}));
img = imresize(img, flip(EXP.baseImg(3:4)));
EXP.textures{i} = Screen('MakeTexture', PTB.window, img);
% Show init screen
text = sprintf('%s %d%%', 'Loading resources...', round(i/length(EXP.imgs)*100));
drawInstructions(PTB.window, text);
Screen('Flip', PTB.window);
end
clear img;
% load images and rescale them
EXP.texturesSource = cell(length(EXP.imgs), 1);
for i=1:length(EXP.imgs)
img = imread(fullfile(EXP.stimsdir, EXP.imgs{i}));
img = imresize(img, flip(EXP.baseImgSource(3:4)));
EXP.texturesSource{i} = Screen('MakeTexture', PTB.window, img);
% Show init screen
text = sprintf('%s %d%%', 'Loading resources...', round(i/length(EXP.imgs)*100));
drawInstructions(PTB.window, text);
Screen('Flip', PTB.window);
end
clear img;
centeredImgSource = CenterRectOnPointd(EXP.baseImgSource, PTB.xCenter, PTB.yCenter);
centeredImgLeft = CenterRectOnPointd(EXP.baseImg, PTB.xCenter*.5, PTB.yCenter);
centeredImgCenter = CenterRectOnPointd(EXP.baseImg, PTB.xCenter, PTB.yCenter);
centeredImgRight = CenterRectOnPointd(EXP.baseImg, PTB.xCenter*1.5, PTB.yCenter);
%% init logfile
fprintf('\n\n');
fprintf('Initialising log files...\n')
logfile = fopen(logpars.logfilename,'w+');
fprintf(logfile, '%s', ...
sprintf(repmat('%s',1,5), ...
'trial,', ...
'conditionSource,', ...
'conditionLeft,', ...
'conditionCenter,', ...
'conditionRight,', ...
'pictureSource,', ...
'pictureLeft,', ...
'pictureCenter,', ...
'pictureRight,', ...
'decision,', ...
'decisionRt,')...
);
fprintf(logfile, '\n');
fclose(logfile);
%% init keyboard input
fprintf('\n\n');
fprintf('Initialising keyboard logger...\n')
% [keyboardIndices, productNames, allInfos] = GetKeyboardIndices;
kblog = Keylogger();
%% Welcome screen
fprintf('\n\n');
fprintf('Showing instructions...\n')
text = {...
'Ihnen werden verschiedene Farben in einer Reihenfolge präsentiert.\n ' ...
'Auf eine Farbe folgen drei weitere Farben.\n' ...
'Wenn Sie drei Farben sehen, wählen Sie diejenige aus,\n' ...
'die entsprechend Ihrer Erfahrung aus früheren Aufgaben nach dem vorherigen Farbbild erscheint.\n' ...
'Wenn Sie unsicher sind, welche Farbe Sie wählen sollen, folgen Sie Ihrer Intuition.\n\n' ...
'Benutzen Sie die Tastatur, um Antworten zu geben.\n', ...
'Um die Farbe auf der linken Seite auszuwählen, drücken Sie PFEIL LINKS.\n', ...
'Um die Farbe in der Mitte auszuwählen, drücken Sie PFEIL RUNTER.\n', ...
'Um die Farbe auf der rechten Seite auszuwählen, drücken Sie PFEIL RECHTS.\n\n', ...
'Seien Sie so schnell und genau wie möglich!\n\n' ...
'Die Aufgabe wird nur wenige Minuten dauern.\n\n', ...
'Drücken Sie den Pfeil nach links, um die Aufgabe zu beginnen...', ...
};
drawInstructions(PTB.window, strjoin(text));
Screen('Flip', PTB.window);
RestrictKeysForKbCheck(KbName('LeftArrow'));
KbStrokeWait;
Screen('Flip', PTB.window);
RestrictKeysForKbCheck([]);
%% start data collection
fprintf('\n\n');
fprintf('Starting data collection...\n')
% start recording
WaitSecs(1);
LPT.sendMarker(EXP.markerStartTask);
%% Trial loop
if logpars.debugging
nTrials = 4;
else
nTrials = length(EXP.XX);
end
% make sure that only arrow keys are read by KbWait
% to make sure that a participant provides a valid response
RestrictKeysForKbCheck([KbName('LeftArrow') KbName('DownArrow') KbName('RightArrow')]);
for trial = 1:nTrials
% start with the fixation cross
if trial == 1
vbl = Screen('Flip', PTB.window);
Screen('DrawLines', PTB.window, EXP.allCoords, ...
EXP.fixCrossWidth, 0, [PTB.xCenter PTB.yCenter], 2);
Screen('DrawDots', PTB.window, ...
[PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], ...
EXP.dotSize, EXP.dotColor, [], 2);
Screen('Flip', PTB.window, vbl + PTB.ifi/2);
WaitSecs(EXP.iti);
end
Screen('DrawTexture', PTB.window, EXP.texturesSource{EXP.XX(trial,1)}, [], centeredImgSource);
sourceOnset = Screen('Flip', PTB.window);
DrawFormattedText(PTB.window, EXP.afcInstruction, 'center', EXP.afcInst_yaxis, 0, 120, [], [], 1.5);
Screen('DrawTexture', PTB.window, EXP.textures{EXP.XX(trial,2)}, [], centeredImgLeft);
Screen('DrawTexture', PTB.window, EXP.textures{EXP.XX(trial,3)}, [], centeredImgCenter);
Screen('DrawTexture', PTB.window, EXP.textures{EXP.XX(trial,4)}, [], centeredImgRight);
optionsOnset = Screen('Flip', PTB.window, sourceOnset + EXP.sourceDuration + PTB.ifi/2, 1);
LPT.sendMarker(EXP.markerTrialOn);
kblog.startRecording(optionsOnset);
KbStrokeWait;
% log key response
keypress = kblog.dumpLog();
response = 'N/A';
RT = 'N/A';
for p=1:length(keypress)
% kblog still logs all keypresses
if keypress(p).pressed ...
&& ismember(keypress(p).keyCode, [EXP.keyCodeLeft EXP.keyCodeCenter EXP.keyCodeRight])
keyCode = keypress(p).keyCode;
RT = keypress(p).onset;
if keyCode == EXP.keyCodeLeft
response = 1;
Screen('FrameRect', PTB.window, 1, centeredImgLeft, EXP.framePix);
elseif keyCode == EXP.keyCodeCenter
response = 2;
Screen('FrameRect', PTB.window, 1, centeredImgCenter, EXP.framePix);
elseif keyCode == EXP.keyCodeRight
response = 3;
Screen('FrameRect', PTB.window, 1, centeredImgRight, EXP.framePix);
break
end
end
end
vbl = Screen('Flip', PTB.window);
Screen('DrawLines', PTB.window, EXP.allCoords, ...
EXP.fixCrossWidth, 0, [PTB.xCenter PTB.yCenter], 2);
Screen('DrawDots', PTB.window, ...
[PTB.xCenter PTB.xCenter; PTB.yCenter PTB.yCenter], ...
EXP.dotSize, EXP.dotColor, [], 2);
Screen('Flip', PTB.window, vbl + EXP.RespFeedSec + PTB.ifi/2);
% log response
logfile = fopen(logpars.logfilename,'a+');
fprintf(logfile, '%s,', ...
string(trial), ...
string(EXP.XX(trial,1)), ...
string(EXP.XX(trial,2)), ...
string(EXP.XX(trial,3)), ...
string(EXP.XX(trial,4)), ...
string(EXP.imgs{EXP.XX(trial,1)}), ...
string(EXP.imgs{EXP.XX(trial,2)}), ...
string(EXP.imgs{EXP.XX(trial,3)}), ...
string(EXP.imgs{EXP.XX(trial,4)}), ...
string(response), ...
string(RT));
fprintf(logfile, '\n');
fclose(logfile);
WaitSecs(EXP.iti);
end
%% save data
fprintf('\n\n');
fprintf('Saving data...\n');
LPT.sendMarker(EXP.markerEndTask);
end