Looking for Matlab code to implement the Pscyhomotor Vigilance Task (PVT)
Show older comments
Hi,
I'm not sure if this is the correct place to post this, if not, I apologize. I am looking for code to run the Psychomotor Vigilance Task. It is a visual vigilance task that is commonly used in fatigue research. If anyone has options they would be willing to share, particularly if you have used it in published research, it would be much appreciated.
Thank,
Ben
2 Comments
David Hill
on 10 Feb 2022
Edited: David Hill
on 10 Feb 2022
I would recommend a GUI with an indicator randomly going on/off periodically over the testing period and recording mouse clicks. Seems quite simple. What have you done? Show us some code and as a specific question.
Ben Hornsby
on 10 Feb 2022
Answers (1)
David Hill
on 11 Feb 2022
Edited: David Hill
on 11 Feb 2022
I coded this quickly. Here is a back bone for the PVT. Modify as desired.
function [sleepAttack,lapse,good,tooFast,excessiveClick]=pscyhomotorVT(lengthTime)
%input length of time you desire for test duration (seconds)
%outputs provide data on how many occurances of each category happen
%When the red light appears, hit any key, continue until test is complete
gui=uifigure('Position',[300 300 950 600],'Color','k','KeyPressFcn',@keyPress);
Rect = uipanel(gui,'Units','pixels','Position',[465 290 20 20],...
'BackgroundColor','r','BorderType','none','Visible','off');
pause('on');
rng('shuffle');
tooFast=0;good=0;lapse=0;excessiveClick=0;count=0;
pause(3);
tStart=clock;
while etime(clock,tStart)<lengthTime
pause('on');
pause(rand*10+1);
Rect.Visible='on';
Tstart=clock;
flag=1;
for k=1:120
pause(.25);
end
Rect.Visible='off';
flag=0;
count=count+1;
end
sleepAttack=count-sum([tooFast,good,lapse]);
function keyPress(~,~)
d=etime(clock,Tstart)*1000;
if ~flag
excessiveClick=excessiveClick+1;
return;
end
pause('off');
if d<150
tooFast=tooFast+1;
elseif d<500
good=good+1;
else
lapse=lapse+1;
end
end
end
2 Comments
David Hill
on 12 Feb 2022
Edited: David Hill
on 12 Feb 2022
Modified above and added to file exchange.
Ben Hornsby
on 14 Feb 2022
Categories
Find more on Debugging and Improving Code in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!