frequency of cursor position recording
David McFarlane
mcfarla9 at msu.edu
Mon Mar 28 18:26:03 UTC 2011
Ashtyster,
If I may jump in here...
So, e.g., for a sampling rate of 50 Hz, you could use
Sleep 20
(i.e., same as your example), or, for slightly better documentation,
Sleep 1000/50
or, for even better documentation without "magic numbers",
Const SampleRate_Hz as Long = 50
Sleep 1000/SampleRate_Hz
Now, I don't quite trust the Sleep command myself -- what happens if
some process interrupts during the Sleep? Then the effective
duration of the Sleep will be a little longer, and with each delay
things get more desynchronized (note that this acts exactly the same
as E-Prime's Event timing mode, see Chapter 3 of the User's Guide
that came with E-Prime). If you need to keep things better
synchronized (i.e., more like E-Prime's Cumulative timing mode), then
you will have to roll your own delay loop, something like
Const SampleRate_Hz as Long = 50
Const tSample_ms as Long = 1000/SampleRate_Hz
Dim tDelay as Long
tNext = Clock.Read ' initialize *once* at the start of the sampling loop
Do Until <condition to end sampling loop>
<record mouse cursor position>
tNext = tNext + tSample_ms
Do Until Clock.Read >= tNext
<stuff to do while waiting for the next sample>
Loop
Loop
Now the mouse cursor will be sampled on more or less exact 20 ms
boundaries, with minimal drift. Note that this method also does not
completely stall your program in between mouse cursor samples.
BTW, you can find the Sleep command, and much more besides,
documented in the online E-Basic Help.
-- David McFarlane, Professional Faultfinder
At 3/28/2011 05:17 AM Monday, you wrote:
>Hi Paul,
>
>thank you for your reply.
>
>So if I understand you correctly, I should just calculate temporal
>resolution from the output, and adjust the sleep value according to
>the temporal resolution I'd like to have?
>
>All best,
>A.
>
>On Mar 25, 11:54 pm, Paul Groot <pfc.gr... at gmail.com> wrote:
> > Hi Ashtyster,
> >
> > The sleep instruction simple puts the running script in 'idle'mode for
> > the specified number of milliseconds. Windows can use this time to
> > allow other processes to consume some CPU time. This construction is
> > often used in loops to prevent the system to become stalled. A
> > duration of about 20 milliseconds might be sensible on systems that
> > are connected to a display at 50Hz. The value could even slightly less
> > on systems with a typical refresh rate of 70-80Hz. However, windows
> > will probably update the mouse cursor position completely independend
> > of the refresh cycle, so the temporal resolution might be very
> > different...
> >
> > Also, the DoEvent function is probably a leftover from the standard
> > basic language. It is used to allow other applications to handle the
> > message queue. I would normally not include this call in eprime
> > experiments.
> >
> > best,
> > Paul
> >
> > 2011/3/25 Ashtyster <ashtys... at gmail.com>:
> > > Hi!
> >
> > > I've gotten a bit confused trying to understand how to set the
> > > frequency of cursor position recording in E-Prime.
> >
> > > I am presenting images and recording mouse cursor positions while
> > > subjects view the images. I would like to set the "sampling rate" for
> > > the cursor position recording to 50 Hz. The in-line script has the
> > > following sampling rate preset:
> >
> > > 'Give some time back (required) - i.e. sampling rate.
> > > Sleep 20
> > > DoEvents
> >
> > > What I am confused about is what does this '20' value mean? Does it
> > > mean 20 cycles per second?
> >
> > > I would appreciate if somebody could answer this question.
> >
> > > All best,
> > > Ashtyster
--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.
More information about the Eprime
mailing list