Best/most accurate timer function?
14 次查看(过去 30 天)
显示 更早的评论
Hello, I am trying to decide which timer function to implement in my code. I am new to Matlab and have only been introduced to the classic tic and toc, but I know there are other timer functions available.
I am measuring reaction time after playing a sound, where the user needs to press a button to indicate that they heard the sound.
I have been encouraged to use a physical button box over a GUI button, as the time resolution is better using a physical button, however I am not familiar with the RPvdsEx software required to get it to work with the TDT hardware I am using.
Currently to avoid the RPvdsEx software, I am using the following code
tic
k = waitforbuttonpress;
app.elapsed_time_array(end+1) = toc;
Basically, I am now at the point where I need to know what the pros and cons are of different timer functions, and why tic and toc may not be my best option for an accurate reaction time. What are some other options, and what would you recommend?
Any help is appreciated.
回答(1 个)
Jan
2017-7-6
It depends on which resolution you want to achieve. I would not trust Matlab's tic/toc for less than 0.01 seconds. But instead of believings, you could measure this by your own: Create a java.awt.robot and emulate a keypress, such that you can measure the delay.
I would create a C-mex function using a high accuracy timer like https://www.mathworks.com/matlabcentral/fileexchange/16534-high-accuracy-timer and getchar(). The question remains, how the timer is started: There will be a delay between running the code to display the event until the time is started. In an experiment in my lab this time is measured by a photo diode, which is attached to the lower corner of the monitor and an micro controller board (arduino). This is more reliable, because it considers e.g. the frequency of the monitor also.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!