Best/most accurate timer function?

14 visualizaciones (últimos 30 días)
Peter Hutchison
Peter Hutchison el 6 de Jul. de 2017
Comentada: Peter Hutchison el 6 de Jul. de 2017
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 comentario
Jan
Jan el 6 de Jul. de 2017
This is not a timer function - see: doc timer.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 6 de Jul. de 2017
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.
  1 comentario
Peter Hutchison
Peter Hutchison el 6 de Jul. de 2017
Thank you for the advice on tic toc. Good to know. I saw the high accuracy timer post but didn't know much about it before delving in. Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by