Psychtoolbox 固定刺激持续时间
Psychtoolbox fixed duration of stimuli
我正在尝试记录参与者对需要在固定持续时间(500 毫秒)内显示的视觉刺激的反应。但是,我还想在刺激开始后 1 秒 window 内的固定持续时间后记录他们的反应。以下代码允许我仅在刺激呈现期间(500 毫秒)按下某个键时记录响应。
StimulusSecs = 0.50001;
StimDuration = round(StimulusSecs / ifi);
ISISecs = 0.50001;
ISI = round(ISISecs / ifi);
ITISecs = [1.00001, 2.00001, 3.00001];
intertrial = round(ITISecs / ifi);
waitframes = 1;
vbl = Screen('Flip', mainwin);
t2wait = 1;
[~, Onset]=Screen('Flip', mainwin); keyIsDown=0; rt=0;
tic % Stimulus Onset
for frame = 1:StimDuration
Screen('DrawTexture', mainwin, pics(picCounter));
vbl = Screen('Flip',mainwin, vbl + (waitframes - 0.5) * ifi);
[keyIsDown, secs, keyCode] = KbCheck;
FlushEvents('keyDown');
if keyIsDown
if keyCode(spaceKey)
rt = 1000.*(secs-Onset);
keypressed=find(keyCode);
% break; is missing as this would
% escape the loop
elseif (secs-Onset) > t2wait
break;
elseif keyCode(escKey)
ShowCursor; fclose(outfile); Screen('CloseAll');
return;
end
keyIsDown=0; keyCode=0; keypressed=0;
end
end
S2dur = toc;
我是 psychoolbox 的新手,非常感谢任何帮助!!!
我假设 picCounter
在给定试验的整个 1 秒时间内保持不变。我认为您可以通过更改循环来实现所需的功能,使其继续查询键盘 1 秒,但添加一个条件,以便显示的内容取决于经过了多少时间。
start_time = GetSecs; % stimulus onset
while GetSecs-start_time<1
% draw stimulus only if elapsed time is < 0.5 sec
if GetSecs-start_time<0.5
Screen('DrawTexture', mainwin, pics(picCounter));
end
vbl = Screen('Flip',mainwin, vbl + (waitframes - 0.5) * ifi);
% proceed by querying keyboard, etc.
[keyIsDown, secs, keyCode] = KbCheck;
(...)
end
您目前正在为每一帧重新绘制和重新翻转刺激物。如果这些是静态图像,则不需要这样做,因为您只需要在想要更改屏幕上的内容时重新绘制和翻转即可。这是一个假设静态图像的示例。按键响应循环在整个 t2wait 期间运行。在该循环中,条件语句比较分配给刺激的时间是否已经过去,如果已经过去,则将其从屏幕上移除:
StimulusSecs = 0.50001;
StimDuration = round(StimulusSecs / ifi);
ISISecs = 0.50001;
ISI = round(ISISecs / ifi);
ITISecs = [1.00001, 2.00001, 3.00001];
intertrial = round(ITISecs / ifi);
waitframes = 1;
vbl = Screen('Flip', mainwin);
t2wait = 1;
tic % Stimulus Onset
[~, Onset] = Screen('DrawTexture', mainwin, pics(picCounter));
OnScreen = 1; % variable to indicate whether the stim is still onscreen
keyPressed = 0; % variable will be 0 until the space key is pressed
rt=0;
while (GetSecs - Onset) <= t2wait
[keyIsDown, secs, keyCode] = KbCheck;
if keyPressed == 0 && keyIsDown
if keyCode(spaceKey)
rt = 1000.*(secs-Onset);
keypressed=find(keyCode);
elseif keyCode(escKey)
ShowCursor; fclose(outfile); Screen('CloseAll');
return;
end
end
% turn the stimulus off if StimulusSecs has elapsed
if OnScreen == 1 && ((GetSecs - Onset) >= StimulusSecs)
Screen('Flip',wPtr);
OnScreen = 0;
end
% Wait 1 ms before checking again to prevent
% overload of the machine at elevated priority
WaitSecs(0.001);
end
我正在尝试记录参与者对需要在固定持续时间(500 毫秒)内显示的视觉刺激的反应。但是,我还想在刺激开始后 1 秒 window 内的固定持续时间后记录他们的反应。以下代码允许我仅在刺激呈现期间(500 毫秒)按下某个键时记录响应。
StimulusSecs = 0.50001;
StimDuration = round(StimulusSecs / ifi);
ISISecs = 0.50001;
ISI = round(ISISecs / ifi);
ITISecs = [1.00001, 2.00001, 3.00001];
intertrial = round(ITISecs / ifi);
waitframes = 1;
vbl = Screen('Flip', mainwin);
t2wait = 1;
[~, Onset]=Screen('Flip', mainwin); keyIsDown=0; rt=0;
tic % Stimulus Onset
for frame = 1:StimDuration
Screen('DrawTexture', mainwin, pics(picCounter));
vbl = Screen('Flip',mainwin, vbl + (waitframes - 0.5) * ifi);
[keyIsDown, secs, keyCode] = KbCheck;
FlushEvents('keyDown');
if keyIsDown
if keyCode(spaceKey)
rt = 1000.*(secs-Onset);
keypressed=find(keyCode);
% break; is missing as this would
% escape the loop
elseif (secs-Onset) > t2wait
break;
elseif keyCode(escKey)
ShowCursor; fclose(outfile); Screen('CloseAll');
return;
end
keyIsDown=0; keyCode=0; keypressed=0;
end
end
S2dur = toc;
我是 psychoolbox 的新手,非常感谢任何帮助!!!
我假设 picCounter
在给定试验的整个 1 秒时间内保持不变。我认为您可以通过更改循环来实现所需的功能,使其继续查询键盘 1 秒,但添加一个条件,以便显示的内容取决于经过了多少时间。
start_time = GetSecs; % stimulus onset
while GetSecs-start_time<1
% draw stimulus only if elapsed time is < 0.5 sec
if GetSecs-start_time<0.5
Screen('DrawTexture', mainwin, pics(picCounter));
end
vbl = Screen('Flip',mainwin, vbl + (waitframes - 0.5) * ifi);
% proceed by querying keyboard, etc.
[keyIsDown, secs, keyCode] = KbCheck;
(...)
end
您目前正在为每一帧重新绘制和重新翻转刺激物。如果这些是静态图像,则不需要这样做,因为您只需要在想要更改屏幕上的内容时重新绘制和翻转即可。这是一个假设静态图像的示例。按键响应循环在整个 t2wait 期间运行。在该循环中,条件语句比较分配给刺激的时间是否已经过去,如果已经过去,则将其从屏幕上移除:
StimulusSecs = 0.50001;
StimDuration = round(StimulusSecs / ifi);
ISISecs = 0.50001;
ISI = round(ISISecs / ifi);
ITISecs = [1.00001, 2.00001, 3.00001];
intertrial = round(ITISecs / ifi);
waitframes = 1;
vbl = Screen('Flip', mainwin);
t2wait = 1;
tic % Stimulus Onset
[~, Onset] = Screen('DrawTexture', mainwin, pics(picCounter));
OnScreen = 1; % variable to indicate whether the stim is still onscreen
keyPressed = 0; % variable will be 0 until the space key is pressed
rt=0;
while (GetSecs - Onset) <= t2wait
[keyIsDown, secs, keyCode] = KbCheck;
if keyPressed == 0 && keyIsDown
if keyCode(spaceKey)
rt = 1000.*(secs-Onset);
keypressed=find(keyCode);
elseif keyCode(escKey)
ShowCursor; fclose(outfile); Screen('CloseAll');
return;
end
end
% turn the stimulus off if StimulusSecs has elapsed
if OnScreen == 1 && ((GetSecs - Onset) >= StimulusSecs)
Screen('Flip',wPtr);
OnScreen = 0;
end
% Wait 1 ms before checking again to prevent
% overload of the machine at elevated priority
WaitSecs(0.001);
end