-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPresentWords.m
More file actions
350 lines (314 loc) · 15 KB
/
PresentWords.m
File metadata and controls
350 lines (314 loc) · 15 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
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
function [out_recorder,out_rngstate,restruct] = PresentWords(randstate,window,windowRect,faces,observer_mode,recorder,just_record,extra_params)
% randstate - state of rng to set to. Useful for reproduction.
% window - Psychtoolbox window handle
% windowRect - PTB rectangle enclosing the window
% faces - cell matrix containing faces to display
% observer_mode - true/false to indicate if just observing as experimenter.Defaults to false
% recorder - If observer_mode is true then we expect the recorder
if nargin<5
observer_mode = false;
elseif nargin==5 && observer_mode==true
error('We expect a recorder to be passed in observer mode');
end
if nargin<7 || observer_mode==false
just_record = false;
end
if nargin<8
extra_params = struct('pid','p1','socialOG',0);
end
if observer_mode == true
move_index = 1;
end
rng(randstate);
out_recorder = outholder;
restruct = [];
if just_record ~= true
% Get the screen numbers. This gives us a number for each of the screens
% attached to our computer. For help see: Screen Screens?
screens = Screen('Screens');
% Draw we select the maximum of these numbers. So in a situation where we
% have two screens attached to our monitor we will draw to the external
% screen. When only one screen is attached to the monitor we will draw to
% this. For help see: help max
screenNumber = max(screens);
% Define black and white (white will be 1 and black 0). This is because
% luminace values are (in general) defined between 0 and 1.
% For help see: help WhiteIndex and help BlackIndex
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
% Get the size of the on screen window in pixels.
% For help see: Screen WindowSize?
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
% Get the centre coordinate of the window in pixels
% For help see: help RectCenter
[xCenter, yCenter] = RectCenter(windowRect);
% Instruction rect is 70% at center
Instr_dst_rect = CenterRectOnPointd([0,0,0.7*screenXpixels,0.7*screenYpixels],xCenter,yCenter);
end
dictionary = {'pencil', 'farmer', 'curtain', 'house', 'parent', 'garden',...
'turkey', 'mountain', 'river', 'bell', 'coffee', 'nose', 'hat', 'school',...
'moon', 'drum'};
numwords = size(dictionary,2);
wordpermute = randperm(numwords)';
%Create face indices for easy cell access, each row in the indices
%correspond to a face
[p,q] = meshgrid(1:size(faces,1),1:size(faces,2));
faceindices = [p(:) q(:)];
numfaces = size(faceindices,1);
%Associate words with faces (randomly). Stores indices to look up faces and
%words. shuffle order so display is also random and not it any order.
associations = [ repmat(faceindices,numwords/numfaces,1), wordpermute];
num_associations = size(associations,1);
associations_shuffle = randperm(num_associations);
associations = associations(associations_shuffle,:);
% Critical lures - Associate words with equivalent faces. So swap row
% values
critical_lures = associations;
critical_lures(:,1) = mod(critical_lures(:,1),2)+1;
num_critical = size(critical_lures,1);
% Control lures - Associate words with non-equivalent faces. So swap column
% values and in both rows. Use critical lure merged with original set for
% the transform
control_lures = [associations; critical_lures];
control_lures(:,2) = mod(control_lures(:,2),2)+1;
num_control = size(control_lures,1);
if just_record ~= true
%stage 5 instructions
instr_text = ['Good! The next section of the study is about memory.\n',...
'It is divided into two sections, a study section and a test section ',...
'In the study section, you will see several words presented one at a time on different screens. ',...
'Each word will be displayed for 2 seconds, after which the screen will automatically advance. ',...
'After you see all of the words, you will proceed to the test section, where you will be tested on your ',...
'memory for these words.\n\n',...
'You may now continue onto the study section. Study the words presented on the following screens ',...
'for the upcoming memory test!',...
'\n\n Press any button to continue'];
Screen('TextSize', window, 24);
Screen('TextFont', window, 'Times');
DrawFormattedText(window, instr_text,'wrapat', 'center', black, 70, [], [], 1.5, [], Instr_dst_rect);
Screen('Flip', window);
KbStrokeWait;
end
%stage 5
for word_num=1:num_associations
%create struct for the trial
trial_struct = struct('ID',extra_params.pid,'Cond',extra_params.socialOG,'Stage',5,'Learning_Trial','','Test_Trial','','Test_Trial_Final','',...
'Trial_typefish','','WordL_Trial',word_num,'WordT_Trial','','Trial_typeword','',...
'Face',(associations(word_num,1)-1)*2+associations(word_num,2),...
'Fish_left','','Fish_right','',...
'Word',dictionary{associations(word_num,3)},'Resp','','Ans','','Corr','','RT','');
restruct = [restruct;trial_struct];
%Debug print
disp(['Showing word ' dictionary{associations(word_num,3)} ' for face ' num2str(associations(word_num,1)) ',' num2str(associations(word_num,2))]);
if just_record ~= true
%Calculate image sizes and scaling.
[As1,As2,As3] = size(faces{associations(word_num,1),associations(word_num,2)});
A_asp_ratio = As2/As1;
A_newh = screenYpixels/6;
A_neww = A_asp_ratio*A_newh;
A_theRect = [0 0 A_neww A_newh];
%Position it in X center and 1/4th way from top.
A_dst_rect = CenterRectOnPointd(A_theRect,screenXpixels/2,screenYpixels/6);
%Draw the face
imageTexture = Screen('MakeTexture',window,faces{associations(word_num,1),associations(word_num,2)});
Screen('DrawTexture', window, imageTexture, [], A_dst_rect, 0);
% Draw text (word) in the bottom of the screen in black
Screen('TextSize', window, 40);
Screen('TextFont', window, 'Times');
DrawFormattedText(window, dictionary{associations(word_num,3)}, 'center',...
screenYpixels * 0.45, [0 0 0]);
% Flip to the screen. This command basically draws all of our previous
% commands onto the screen. See later demos in the animation section on more
% timing details. And how to demos in this section on how to draw multiple
% rects at once.
% For help see: Screen Flip?
Screen('Flip', window);
%Wait 5 sec before clearing and displaying next word
WaitSecs(5);
%Clear screen and display blank for 500 msec
Screen('Flip', window);
WaitSecs(0.5);
end
end
if just_record ~= true
%stage 6 instructions
instr_text = ['Good! You just completed the study section.',...
'You will now move onto the test section.\n\n',...
'In this section, we will test your memory for what you just saw. ',...
'On each screen answer the question presented based on what you ',...
'remember from the study section you just completed.\n\n',...
'In the next sections, press Y for ''yes'' and press N for ''no''.',...
'\n\n Press any button to continue'];
Screen('TextSize', window, 24);
Screen('TextFont', window, 'Times');
DrawFormattedText(window, instr_text,'wrapat', 'center', black, 70, [], [], 1.5, [], Instr_dst_rect);
Screen('Flip', window);
KbStrokeWait;
end
%Stage 6
%randomly choose 8 associations, 4 critical lures and 4 control lures
rand_associations = randperm(num_associations,8);
rand_critical = randperm(num_critical,4);
rand_control = randperm(num_control,4);
%Put all these random selections into a display matrix, also store what the
%correct answer is 1 = Yes, 2 = No. Correct answer is stored in 4th column
%commenting out to try adding in new test phase
%disp_matrix = [ associations(rand_associations,:), ones(8,1); critical_lures(rand_critical,:), 2*ones(4,1); control_lures(rand_control,:), 2*ones(4,1)];
%disp_num = size(disp_matrix,1);
%disp_shuffle = randperm(disp_num);
%disp_matrix = disp_matrix(disp_shuffle,:);
%Making a 16X5 matrix to put in all of my values. Disp_matrix equals the
%face word pairs matrix for the test
disp_matrix = zeros(16,5);
%Just renaming matrices to make referencing easier. Also store what the
%correct answer is 1=yes, 2=no. Correct answer is stored in 4th column
%5th column is word type, 1=Associations,2=control lure,3 = Critical Lure
A=[associations,ones(size(associations,1),1),ones(size(associations,1),1)];
B=[critical_lures,2*ones(size(critical_lures,1),1),3*ones(size(critical_lures,1),1)];
C=[control_lures,2*ones(size(control_lures,1),1),2*ones(size(control_lures,1),1)];
%creating an array that we reference to selectively sample from the A,B,C
%matrices. We then shuffle it to randomize
D = [1:size(A,1)];
E = Shuffle(D);
%Fill in the matrix with 8 rows from A, 4 from B, and 4 from C
for row = 1:size(disp_matrix,1)
if E(row)<9
disp_matrix(row,:)=A(row,:);
disp('A');
elseif E(row)<13
disp_matrix(row,:)=B(row,:);
disp('B');
else
disp_matrix(row,:)=C(row,:);
if rand(1)>.5
disp_matrix(row,1)=mod(disp_matrix(row,1),2)+1;
end
disp('C');
end
end
dispmatrix_num = size(disp_matrix, 1);
dispmatrix_shuffle = randperm(dispmatrix_num);
disp_matrix = disp_matrix(dispmatrix_shuffle,:);
for trial=1:dispmatrix_num
%create struct for the trial
trial_struct = struct('ID',extra_params.pid,'Cond',extra_params.socialOG,'Stage',6,'Learning_Trial','','Test_Trial','','Test_Trial_Final','',...
'Trial_typefish','','WordL_Trial','','WordT_Trial',trial,'Trial_typeword',disp_matrix(trial,5),...
'Face',(disp_matrix(trial,1)-1)*2+disp_matrix(trial,2),...
'Fish_left','','Fish_right','',...
'Word',dictionary{disp_matrix(trial,3)},'Resp','','Ans',-2*mod(disp_matrix(trial,4),2)+1,'Corr','','RT','');
%Debug print
disp(['TEST_STAGE:Showing word ' dictionary{disp_matrix(trial,3)} ' for face ' num2str(disp_matrix(trial,1)) ',' num2str(disp_matrix(trial,2))]);
if just_record ~= true
%Calculate image sizes and scaling.
[As1,As2,As3] = size(faces{disp_matrix(trial,1),disp_matrix(trial,2)});
A_asp_ratio = As2/As1;
A_newh = screenYpixels/6;
A_neww = A_asp_ratio*A_newh;
A_theRect = [0 0 A_neww A_newh];
%Position it in X center and 1/4th way from top.
A_dst_rect = CenterRectOnPointd(A_theRect,screenXpixels/2,screenYpixels/6);
%Draw the face
imageTexture = Screen('MakeTexture',window,faces{disp_matrix(trial,1),disp_matrix(trial,2)});
Screen('DrawTexture', window, imageTexture, [], A_dst_rect, 0);
% Draw text (word) in the bottom of the screen in black
Screen('TextSize', window, 40);
Screen('TextFont', window, 'Times');
DrawFormattedText(window, dictionary{disp_matrix(trial,3)}, 'center',...
screenYpixels * 0.45, [0 0 0]);
% Draw text in the bottom of the screen in black
Screen('TextSize', window, 40);
Screen('TextFont', window, 'Times');
DrawFormattedText(window, 'Did this word appear with this face?', 'center',...
screenYpixels * 0.65, [0 0 0]);
DrawFormattedText(window, 'Yes', screenXpixels * 0.3,...
screenYpixels * 0.75, [0 0 0]);
DrawFormattedText(window, 'No', screenXpixels * 0.7,...
screenYpixels * 0.75, [0 0 0]);
% Flip to the screen. This command basically draws all of our previous
% commands onto the screen. See later demos in the animation section on more
% timing details. And how to demos in this section on how to draw multiple
% rects at once.
% For help see: Screen Flip?
Screen('Flip', window,0,1);
%Get positions of Yes/No text to draw outline around chosen value
X_theRect = [0 0 100 50];
%Position it in X center and 4/6th way from top.
X1_dst_rect = CenterRectOnPointd(X_theRect,0.33*screenXpixels,0.78*screenYpixels);
X2_dst_rect = CenterRectOnPointd(X_theRect,0.72*screenXpixels,0.78*screenYpixels);
end
if observer_mode ~= true
%accept input and get time
initsec = GetSecs;
while(true)
[secs,keycode,deltasec] = KbStrokeWait;
yes = KbName('Y');
no = KbName('N');
escape = KbName('ESCAPE');
if keycode(yes) || keycode(no)
%Capture time
endsec = GetSecs;
out_recorder.input_timing = [out_recorder.input_timing (endsec-initsec)];
%Record correct answer
out_recorder.correct_ans = [out_recorder.correct_ans disp_matrix(trial,4)];
%Draw frame around selected value in grey - If not needed
%simply comment the 2 Screen('FrameRect'...) comands below.
display_color = [0.6,0.6,0.6];
%Record moves - 1 = yes, 2 = no
if keycode(yes)
out_recorder.moves = [out_recorder.moves 1];
Screen('FrameRect',window,display_color,X1_dst_rect,3);
else
out_recorder.moves = [out_recorder.moves 2];
Screen('FrameRect',window,display_color,X2_dst_rect,3);
end
Screen('Flip', window);
WaitSecs(1);
break
% elseif keycode(escape)
% disp('Exit by escape')
% sca;
% return
end
end
elseif just_record ~= true %Replay stuff
%Detect if correct answer
if recorder.correct_ans(move_index) == recorder.moves(move_index)
display_color = [0 1 0];
DrawFormattedText(window, 'Correct', 'center',...
screenYpixels * 0.85, display_color);
else
display_color = [1 0 0];
DrawFormattedText(window, 'Incorrect', 'center',...
screenYpixels * 0.85, display_color);
end
%Draw appropriate circle
if recorder.moves(move_index)==1
Screen('FrameRect',window,display_color,X1_dst_rect,3);
else
Screen('FrameRect',window,display_color,X2_dst_rect,3);
end
%Wait as long as input user did before display.
WaitSecs(recorder.input_timing(move_index));
move_index = move_index+1;
Screen('Flip', window);
%Wait 1 sec before clearing like in non-social input
WaitSecs(1);
else %Just record case
trial_struct.Resp = -2*mod(recorder.moves(move_index),2)+1;
trial_struct.RT = recorder.input_timing(move_index);
if recorder.correct_ans(move_index) == recorder.moves(move_index)
trial_struct.Corr = 1;
else
trial_struct.Corr = 0;
end
move_index = move_index + 1;
end
restruct = [restruct;trial_struct];
if just_record ~= true
%Clear screen and display blank for 1 sec
Screen('Flip', window);
WaitSecs(1);
end
end
out_rngstate = rng;
end