Reputation: 125
I created a Stroop-like reaction time task in MATLAB and looking at pilot results suggests there might be something wrong with my code (the congruency effect is much bigger than expected). I suspect I may be recording RTs wrong, so could anyone help me out with whether the following setup is okay?
On any given trial, two events happen (following a fixation cross): first, the target stimulus is presented for a max of 3 seconds (or until response), then the participant has to press a button to start the next trial. RT for both buttonpresses (target and trial-start button) is recorded. Here's my code:
Screen('DrawTexture', mainwin, Target);
Screen('Flip', mainwin);
timeStart = GetSecs;keyIsDown=0; correct=0; rt=0;
while 1 & (GetSecs - timeStart) < 3
[keyIsDown, secs, keyCode] = KbCheck;
FlushEvents('keyDown');
if keyIsDown
nKeys = sum(keyCode);
if nKeys==1
if keyCode(Left)||keyCode(Right)||keyCode(Down)||keyCode(Up)
rt = 1000.*(GetSecs-timeStart);
keypressed=find(keyCode);
Screen('Flip', mainwin);
if ... [I removed some irrelevant ERROR feedback related code here]...
elseif keyCode(escKey)
ShowCursor; fclose(outfile); Screen('CloseAll'); return
end
keyIsDown=0; keyCode=0;
end
else
keypressed = 0; %the resp column in output is 0 if no button is pressed
end
end
if keypressed == 0 %indicates timeout errors
DrawFormattedText(mainwin, 'TOO SLOW', 'center', 'center', errorcol);
Screen('Flip', mainwin);
WaitSecs(1);
end
Screen('DrawTexture', mainwin, press5);
Screen('Flip', mainwin);
keyIsDown=0; timeSt = GetSecs;
while 1
[keyIsDown, secs, keyCode] = KbCheck;
if keyIsDown
if keyCode(MoveOn)
pause_rt = 1000.*(secs - timeSt);
break ;
elseif keyCode(escKey)
ShowCursor;
fclose(outfile);
Screen('CloseAll');
return;
end
end
end
My questions: the command GetSecs gets the time whenever it's called, right? So GetSecs - timeStart is an okay way of calculating RT - but so is secs - timeSt (as seen for the second stimulus), as secs is the time KbCheck returns for the buttonpress. The two methods are largely equivalent (with GetSecs - timeStart maybe slightly overestimating RT), is that correct?
My worry here is that RT estimates for the target on the NEXT trial might be influenced by the second button press RT of the PREVIOUS trial. Do you see any evidence of that?
Upvotes: 0
Views: 1218
Reputation: 1473
You are correct that GetSecs
returns the time whenever it is called. But, although not the cause of your error, calling GetSecs after each window Flip isn't necessary, because the Flip function returns the estimate of stimulus onset, as the second output of the function. So for example, instead of:
Screen('Flip', mainwin); timeStart = GetSecs;
You can just use
[~, timeStart] = Screen('Flip', mainwin);
I don't notice anything obviously wrong in the code, when you say the RTs seem incorrect, do they seem too fast, or too slow? Personally I would use KbReleaseWait
after collecting RT to wait until the Key has been released, but perhaps FlushEvents is doing a similar thing here.
Upvotes: 1