KbCheck (?) 在 Psychtoolbox RT 范式中不可靠



我正在尝试使用Psychtoolbox在MATLAB R2014b中创建一个简单的RT实验。参与者必须对面部进行分类,尽可能快地按下两个按钮中的一个。我在一台计算机上创建了范式,它工作正常,但是当我将其移动到另一台计算机(我想测试的那台)时,出现了一个奇怪的错误:即使该程序似乎在大多数试验中记录按键,有时它不会响应,我不得不多次按下该键才能进行下一次试验。我不确定发生了什么,但我认为计算机本身可能有问题(可能是什么?),或者这段特定的代码:

Screen('Flip', mainwin);
timeStart = GetSecs;keyIsDown=0; correct=0; rt=0;
while 1
bf = 0; %this variable is irrelevant here, I use it later to break 
out of a loop 
while (GetSecs - timeStart) < 0.2 %faces are presented briefly, but 
%I'm recording responses here anyway, just in case there are some 
%fast anticipatory responses - after this loop is over, I keep 
%recording RT and button press the exact same way, but with no 
%stimulus present
[keyIsDown, secs, keyCode] = KbCheck;
FlushEvents('keyDown');
if keyIsDown
nKeys = sum(keyCode);
if nKeys==1
if keyCode(Key1)||keyCode(Key2)
rt = 1000.*(GetSecs-timeStart);
keypressed=find(keyCode);
Screen('Flip', mainwin);
type = 'T';
bf = 1;
if keyCode(Key1) & targ_pic == 1
correct = 1;
elseif keyCode(Key2) & targ_pic == 0
correct = 1;
end
break;
elseif keyCode(escKey)
ShowCursor; fclose(outfile);  Screen('CloseAll'); 
return
end
keyIsDown=0; keyCode=0;
end
else
keypressed = 0; 
end
end

谁能发现这可能有什么问题?

顺便说一句:这是让 RT 摆脱 PTB 的正确方法吗?我在网上找到了那段代码,但我有点不确定为什么不使用"secs"变量。

两台计算机都运行Windows 10。

一些建议:

Flip命令将返回刺激开始时间的估计值,当前您在 Flip 命令之后调用GetSecs,这不是必需的,并且将始终返回一个略晚于实际屏幕 Flip 的值。同样,您可以使用KbCheck返回的按键时间,而不是在识别按键后调用GetSecs

我认为您不需要 FlushEvents 命令,它可能会导致一些时间变化。

有时,在 KbCheck 事件之间暂停一小段时间(例如 1 毫秒)也很有用。

下面是包含其中一些更改的代码片段版本。使用单个响应检查循环也可能更简洁,在该循环中,您可以在 200 毫秒后关闭刺激,而不是将 200 毫秒前和 200 毫秒后的响应检查循环分开,尽管我在这里没有进行更改。

keyIsDown=0; correct=0; rt=0;
[~, timeStart] = Screen('Flip', mainwin);
while 1
bf = 0; %this variable is irrelevant here, I use it later to break
%out of a loop
while (GetSecs - timeStart) < 0.2 %faces are presented briefly, but
%I'm recording responses here anyway, just in case there are some
%fast anticipatory responses - after this loop is over, I keep
%recording RT and button press the exact same way, but with no
%stimulus present
[keyIsDown, secs, keyCode] = KbCheck;
if keyIsDown
nKeys = sum(keyCode);
if nKeys==1
if keyCode(Key1)||keyCode(Key2)
rt = 1000.*(secs-timeStart);
keypressed=find(keyCode);
Screen('Flip', mainwin);
type = 'T';
bf = 1;
if keyCode(Key1) & targ_pic == 1
correct = 1;
elseif keyCode(Key2) & targ_pic == 0
correct = 1;
end
break;
elseif keyCode(escKey)
ShowCursor; fclose(outfile);  Screen('CloseAll');
return
end
keyIsDown=0; keyCode=0;
end
else
keypressed = 0;
end
WaitSecs(.001);
end
end

相关内容

  • 没有找到相关文章

最新更新