• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accuracy of timestamping streamed data (code included - long)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accuracy of timestamping streamed data (code included - long)


  • Subject: Re: Accuracy of timestamping streamed data (code included - long)
  • From: Jakob Olesen <email@hidden>
  • Date: Tue, 26 Sep 2006 00:50:45 +0200


On 25/09/2006, at 23.07, Hank Heijink wrote:

For an application in behavioral science, I'm recording cursor movements on an old (10+ years) and big (3 by 5 feet) Quora digitizing tablet. The tablet streams 6-byte coordinates at a constant rate of about 160 Hz, and I want to get as constant a recording rate as I can get. After saving my data to a file, I find I'm fairly accurate, that is, I've timestamped my coordinates such that they're between 5 and 7.5 ms apart. The standard deviation of the differences in time is about 0.3 ms.

My question is, can I achieve even better accuracy, and if so, how? I'd like a more constant rate - I know the output rate of the tablet is more constant than this, and I'm not sure what causes the variability. My application is built in release mode and it's the only one running. Not sure if background daemons are having an effect and I don't know much about USB timing accuracy, but I guess at this level of accuracy, everything could have an effect...

You shouldn't use NSTimers for this. They are not accurate enough, and more importantly, you are introducing aliasing in your samples. If your tablet generates data at 160Hz, and you are sampling at 200Hz, you will get a 40Hz aliased noise signal.


The 0.3ms standard deviation you measured does not come from gaussian noise, it has a spike every 4-5 samples. That is aliasing.

Let the tablet drive the timing. Create a high priority thread that calls read(). Don't use non-blocking I/O and select(), just let read () block. Call mach_absolute_time() right after read() returns. Then send the MVCoordinate to the main thread using performSelectorOnMainThread:

Note that read() returns -1 on an error. You shouldn't pass that on to memcpy()

Alternatively you can use [NSFileHandle readInBackgroundAndNotify]. Then you don't need a new thread, but receive notifications instead. This is probably not as accurate as a high priority thread.


If the tablet is really sending coordinates at a constant rate, you can improve your variance by orders of magnitude through filtering or smoothing, but that is off-topic for this list.



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Accuracy of timestamping streamed data
      • From: Hank Heijink <email@hidden>
References: 
 >Accuracy of timestamping streamed data (code included - long) (From: Hank Heijink <email@hidden>)

  • Prev by Date: Re: Accuracy of timestamping streamed data (code included - long)
  • Next by Date: Re: How to implement an Xcode-style hierarchical file browser
  • Previous by thread: Re: Accuracy of timestamping streamed data (code included - long)
  • Next by thread: Re: Accuracy of timestamping streamed data
  • Index(es):
    • Date
    • Thread