Message Boards Message Boards

2
|
3576 Views
|
0 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Simple Reaction Timer in Mathematica

This is my attempt to use Dynamic to program a simple reaction timer.

Execute the following. The first section sets up the dynamic canvas where the action takes place. The second section executes the trials for the reaction time measurements, while the final two lines perform some simple analysis. In the second section, you can set the number of trials for the experiment. The display will show a small dot in the center to start. With some random time delay between 3 and 8 seconds a large disk will appear which is the signal to mouseclick inside the disk as quickly as possible. A smaller disk will appear signalling the end of the trials.

times = {}; gItem = Point[{0, 0}];
DynamicModule[{rT}, 
 Dynamic@EventHandler[Framed@Graphics[gItem, PlotRange -> 1], 
   "MouseDown" :> (rT = AbsoluteTime[] - startTime; 
     AppendTo[times, rT];
     gItem = Point[{0, 0}])]]

nTrials = 15;
times = {};
n = 1; While[n <= nTrials,
 Pause[RandomReal[{3, 8}]];
 gItem = Disk[{0, 0}]; startTime = AbsoluteTime[];
 n++];
Pause[1.0];
gItem = Disk[{0, 0}, 0.15];
t1 = 1000*times;

{Mean[t1], StandardDeviation[t1], Min[t1], Max[t1]}

Histogram[t1, 10, "Probability"]

For comparison I made a little arduino device to make measurements of my reaction time, callibrated to 1 millisecond, and took quite a bit of data. That gave a mean RT of 190 msec with a standard deviation of 20 msec. When I ran the above program I got a mean RT of 270 msec with a standard deviation of 19 msec. So it looks like there is a very consistent lag of about 80 msec in the above program (which is actually better than I expected). This was on a Mac Pro (Early 2009) with a 2 x 2.26 GHz Quad-Core Intel Xeon running OS X 10.11.2 and Mm 10.3.0.0.

This exercise was mostly an excuse to explore Dynamic, so I would be interested in any suggested improvements. I've read the Introductory and Advanced Tutorials on Dynamic, but I think I don't fully understand them. For example, I haven't attempted to change the 20 times per second (50 msec) refresh time, nor have I figured a way to use DynamicModule to replace the kernel variable I use to change the stimulus. Ultimately I guess I don't have a good enough mental model of what is actually going on to make meaningful changes.

POSTED BY: Michael Burns
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract