-
Notifications
You must be signed in to change notification settings - Fork 1
/
micb_soa.m
399 lines (339 loc) · 14.5 KB
/
micb_soa.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
% Motion-Induced Change Blindness,
% Developed by Richard Yao
% Modified by Katherine Wood
% Modified by Kyle Mathewson
%to test asynchrony between change and motion change
clear all
Screen('Preference', 'SkipSyncTests', 1)
clc;
seed = ceil(sum(clock)*1000);
rand('twister',seed);
global w bgcolor rect gaborPatch arrayRects rotation centerOfArray ...
direction movementIncrement fixationSize fixationColor fixationRect
% /////////////////////////////////////////////////////////////////////////
%% Input
Info.number = input('Participant Number:','s');
Info.date = datestr(now,30); % 'dd-mmm-yyyy HH:MM:SS'
% output file will be named after the inputs
Filename = [Info.number '--' Info.date '_data.mat'];
% /////////////////////////////////////////////////////////////////////////
%% Basic parameters
bgcolor = [128 128 128];
[w rect] = Screen('OpenWindow',0,bgcolor);
xc = rect(3)./2;
yc = rect(4)./2;
xBorder = round(rect(3)./6);
yBorder = round(rect(4)./6);
textSize = round(rect(4)*.02);
Screen('TextSize',w,textSize);
directionNames = {'Right' 'Left'};
% fixation parameters
fixationPause = .5;
fixationColor = [0 0 0];
fixationSize = 2;
% gabor array parameters
numberOfGabors = 8;
arrayCenters = zeros(numberOfGabors,2);
r = round(rect(4)./10);
g = round(.8*r);
gaborSize = g;
% stimulus motion parameters
movementSpeed = 3;
rotationSize = 30;
% trial parameters
practiceTrials = 30;
breakEvery = 48; %so equal # trials per block (5 blocks at reps = 5)
timeLimit = 5;
feedbackPause = .5;
%pick soas
soas = sort([-7:2:7,0]); %changed SOAs
nsoas = length(soas);
% /////////////////////////////////////////////////////////////////////////
%% Read in image
Screen('BlendFunction',w,GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
[gaborMatrix map alpha] = imread('single_gabor_75px.png');
gaborMatrix(:,:,4) = alpha(:,:);
gaborPatch = Screen('MakeTexture',w,gaborMatrix);
% /////////////////////////////////////////////////////////////////////////
%% Counterbalancing
reps = 5; % Number of reps per angle condition per direction
% reps = 4; % Number of reps per angle condition per direction
trialList = [repmat(1:numberOfGabors,1,3*reps);... %list of which target
zeros(1,numberOfGabors*reps) ... %list of which angle
repmat(90,1,numberOfGabors*reps)...
repmat(270,1,numberOfGabors*reps)];
%list of which direction
trialList = [trialList trialList; ...
zeros(1,numberOfGabors*3*reps) ones(1,numberOfGabors*3*reps)];
trialList = trialList(:,randperm(length(trialList)));
practiceList = trialList(:,randperm(length(trialList)));
trialList = trialList';
practiceList = practiceList';
totalTrials = length(trialList);
% /////////////////////////////////////////////////////////////////////////
%% Array Center Points
for i = 1:numberOfGabors
arrayCenters(i,1) = r*cos((i-1)*(2*pi/numberOfGabors));
arrayCenters(i,2) = r*sin((i-1)*(2*pi/numberOfGabors));
end
arrayCenters = round(arrayCenters);
centeredRects = [arrayCenters arrayCenters] + ...
round(repmat([xc-g/2 yc-g/2 xc+g/2 yc+g/2],numberOfGabors,1));
centeredRects = centeredRects';
% /////////////////////////////////////////////////////////////////////////
%% Set-up Output Variables
out_soa = [];
out_direction = [];
out_angle = [];
out_accuracy = [];
out_RT = [];
out_rotation = cell(1,length(trialList)); %pre-allocate
% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
% /////////////////////////////////////////////////////////////////////////
%% Instructions %%
Screen('FillRect',w,bgcolor);
DrawFormattedText(w,'In the following task, you will follow, with your eyes, an array of striped patches moving across the screen.\n\nOn EVERY TRIAL, one of the patches will rotate slightly while moving with its neighbors. When prompted, you will have to click on the patch that rotated.\n\nWe are testing what conditions make that rotation harder or easier to see, so do not be surprised if you did not see any rotation. Just do your best and take a guess if you are unsure.\n\nThe task is easiest if you follow the dot that appears at the middle of the array, so follow that with your eyes on each trial.\n\n\nLet the experimenter know if you have any questions.\n\nClick the mouse to start the practice trials.','center','center',[]);
Screen('Flip',w)
GetClicks(w);
WaitSecs(1.25);
% /////////////////////////////////////////////////////////////////////////
%% ---- Experiment ----
% /////////////////////////////////////////////////////////////////////////
for k = -(practiceTrials+1):length(trialList)
fprintf(num2str(k))
fprintf('\n')
%pick SOA
this_soa = soas(randi(nsoas));
%Trial type
if k < 0
direction = practiceList(-k,3);
target = practiceList(-k,1);
angle = practiceList(-k,2);
trialNum = 'Practice';
elseif k == 0
direction = practiceList(practiceTrials,3);
target = practiceList(practiceTrials,1);
angle = practiceList(practiceTrials,2);
trialNum = 'Practice';
else
direction = trialList(k,3);
target = trialList(k,1);
angle = trialList(k,2);
trialNum = num2str(k);
end
%Stimuli bounds
arrayRects = [arrayCenters arrayCenters] + ...
round(repmat([g/2+r-g/2 yc-g/2 g/2+r+g/2 yc+g/2],numberOfGabors,1));
if direction
arrayRects = arrayRects + repmat([-(2*r+g)+rect(3)-xBorder 0],numberOfGabors,2);
else
arrayRects = arrayRects + repmat([xBorder 0],numberOfGabors,2);
end
arrayRects = arrayRects';
% /////////////////////////////////////////////////////////////////////////
%% Gabors
rotation = round(rand(1, numberOfGabors) * 360);
if k >= 1
out_rotation{k} = rotation;
end
gaborPatch = Screen('MakeTexture',w,gaborMatrix);
%%%%%%%%
%%%%%%%%
%%%%%%%%
% /////////////////////////////////////////////////////////////////////////
%% STIMULUS CODE %%
HideCursor
motion_changePoint = xc;
motion_flexion_height = yc;
%%%
gabor_soa_frames = this_soa; % negative before motion
%%%
gabor_soa_frames = -gabor_soa_frames; %switch sign
gabor_changePoint = gabor_soa_frames * 3; % moves three pixels on each frame
trialOver = 0;
motionOver = 0; % motion change
gaborOver = 0; % gabor change
movementIncrement = repmat([movementSpeed 0 movementSpeed 0],numberOfGabors,1)';
DrawStim()
WaitSecs(fixationPause);
while ~trialOver
% check if reached the edge and set flag
if max(arrayRects(3, :)) > rect(3)-xBorder || ...
max(arrayRects(4, :)) > rect(4)-yBorder || ...
min(arrayRects(3, :)) < xBorder || ...
min(arrayRects(4, :)) < yBorder
trialOver = 1;
end
% check for first motion change point, change, and flag
motion_howfar = ((-1) ^ (direction+1)) * (centerOfArray(1) - motion_changePoint) + ...
(-1) * abs(centerOfArray(2) - motion_flexion_height);
if motion_howfar < 1 & ~motionOver
motionOver = 1;
% Change movement direction
movementIncrement = repmat(movementSpeed.*[cosd(angle) ...
sind(angle) cosd(angle) sind(angle)], ...
numberOfGabors, 1)';
end
% check for gabor change point, change, and flag
gabor_howfar = ((-1) ^ (direction+1)) * (centerOfArray(1) - motion_changePoint) + ...
(-1) * abs(centerOfArray(2) - motion_flexion_height);
if gabor_howfar < gabor_changePoint & ~gaborOver
gaborOver = 1;
%Change Gabor angle
rotation(target) = rotation(target) + rotationSize;
end
MoveStim()
DrawStim()
end
%%%%%%%%
%%%%%%%%
%%%%%%%%
% /////////////////////////////////////////////////////////////////////////
%% Probe %%
Screen('FillRect',w,bgcolor,rect);
Screen('Flip',w);
WaitSecs(.1);
ShowCursor('Arrow');
SetMouse(xc,yc)
Screen('FillRect',w,bgcolor,rect);
DrawFormattedText(w,'Click the patch that rotated:','center',yc-r-g);
Screen('DrawTextures',w,gaborPatch,[],centeredRects,rotation);
Screen('FillOval',w,fixationColor,[xc-fixationSize yc-fixationSize xc+fixationSize yc+fixationSize]);
Screen('Flip',w);
accuracy = 2;
startTime = GetSecs;
clicked = 0;
while GetSecs-startTime<timeLimit && ~clicked
[x y buttons] = GetMouse;
if any(buttons)
clicked = 1;
timesUp = 1;
end
end
incorrectRect = centeredRects(:,:);
correctRect = centeredRects(:,target);
correctRect = correctRect';
gabor_press = 0;
if clicked==1&&x>=correctRect(1)&&x<=correctRect(3)&&y>=correctRect(2)&&y<=correctRect(4)
accuracy = 1;
RT = GetSecs-startTime;
Screen('FillRect',w,bgcolor,rect);
DrawFormattedText(w,'Correct!','center','center');
RT = GetSecs-startTime;
Screen('Flip',w);
elseif clicked==1
for i = 1:length(incorrectRect)
if x>=incorrectRect(1,i)&&x<=incorrectRect(3,i)&&y>=incorrectRect(2,i)&&y<=incorrectRect(4,i)%%%
accuracy = 0;
gabor_press = 1;
Screen('FillRect',w,bgcolor,rect);
DrawFormattedText(w,'Incorrect patch','center','center');
RT = GetSecs-startTime;
Screen('Flip',w);
break
end
end
if gabor_press == 0
accuracy = -1;
Screen('FillRect',w,bgcolor,rect);
DrawFormattedText(w,'Incorrect patch','center','center'); %%%Please Click on a Gabor
RT = GetSecs-startTime;
Screen('Flip',w);
end
elseif clicked == 0
Screen('FillRect',w,bgcolor,rect);
DrawFormattedText(w,'Please respond more quickly','center','center');
Screen('Flip',w);
accuracy = 2;
RT = timeLimit;
end
WaitSecs(feedbackPause);
Screen('FillRect',w,bgcolor,rect);
Screen('flip',w);
%//////////////////////////////////////////////////////////////////////
if k==0 %end of practice trials
Screen('FillRect',w,bgcolor);
DrawFormattedText(w,'You have completed the practice trials\n\nLet the experimenter know you if you have questions.','center','center',[]);
Screen('Flip',w)
GetClicks(w);
WaitSecs(0.05);
Screen('FillRect',w,bgcolor);
DrawFormattedText(w,'When you are ready to start the experiment, click the mouse to continue.','center','center',[]);
Screen('Flip',w)
GetClicks(w);
WaitSecs(0.05);
elseif k>0 %save data of experimental trials
out_soa = [out_soa this_soa];
out_direction = [out_direction direction];
out_angle = [out_angle angle]; %270 left, 90 Right, 0 straight
out_accuracy = [out_accuracy accuracy];
out_RT = [out_RT RT];
if accuracy == 0
out_incorrect_gabor(k) = i; %% adds value i to the incorrect gabor array at trial k
else
out_incorrect_gabor(k) = NaN; %so dim matches other out_ variables
end
end
%//////////////////////////////////////////////////////////////////////
%% Break %%
% k>0 so don't break during practice or at end of practice &
% k~=totalTrials so break screen does not show up at end of experiment
if k>0 && k~=totalTrials && mod(k,breakEvery)==0 %whenever k trials is divisible w/out remainder by breakEvery
Screen('FillRect',w,bgcolor);
DrawFormattedText(w,'Feel free to take a break at this time\n\nWhen you are ready, click the mouse to continue.','center','center',[]);
Screen('Flip',w)
GetClicks(w);
WaitSecs(1.25);
end
%//////////////////////////////////////////////////////////////////////
Screen('Close');
end
% /////////////////////////////////////////////////////////////////////////
% -------------------------------------------------------------------------
% ------------------------------- END TASK --------------------------------
% -------------------------------------------------------------------------
% /////////////////////////////////////////////////////////////////////////
fclose('all');
Screen('CloseAll');
%clearing unneeded variables from workspace before saving
clear i accuracy RT x y timesUp clicked angle this_soa gabor_press
% /////////////////////////////////////////////////////////////////////////
turn_trials = out_angle ~= 0;
control_trials = out_angle == 0;
responded = out_accuracy ~= 2; %select only trials with a response
isoa = 0;
for this_soa = soas
isoa = isoa + 1;
temp_turn = out_accuracy(out_soa == this_soa & responded & turn_trials);
turn_out(isoa) = sum(temp_turn)/length(temp_turn);
temp_cont = out_accuracy(out_soa == this_soa & responded & control_trials);
control_out(isoa) = sum(temp_cont)/length(temp_cont);
end
% /////////////////////////////////////////////////////////////////////////
%% Save data
save(Filename)
% /////////////////////////////////////////////////////////////////////////
%% Plot results
figure;
plot(soas,turn_out,'r',soas,control_out,'b');
legend({'Flexion','Control'});
xlim([min(soas) max(soas)]); xticks(min(soas):1:max(soas))
xlabel('Gabor Change First < ------ SOA (frames) ------ > Gabor Change After')
ylabel('Detection Proportion')
ylim([.01 1.05])
% Save figure
savefig([Info.number '--' Info.date '_plot'])
% /////////////////////////////////////////////////////////////////////////
function MoveStim()
global arrayRects direction movementIncrement
arrayRects = arrayRects + ((-1)^direction)*movementIncrement;
end
function DrawStim()
global w bgcolor rect gaborPatch arrayRects rotation centerOfArray fixationSize fixationColor fixationRect
Screen('FillRect',w,bgcolor,rect);
Screen('DrawTextures',w,gaborPatch,[],arrayRects,rotation);
centerOfArray = [(min(arrayRects(1,:))+max(arrayRects(3,:)))/2 (min(arrayRects(2,:))+max(arrayRects(4,:)))/2];
fixationRect = round([centerOfArray(1)-fixationSize centerOfArray(2)-fixationSize centerOfArray(1)+fixationSize centerOfArray(2)+fixationSize]);
Screen('FillOval',w,fixationColor,fixationRect);
Screen('Flip',w);
end