[time-nuts] And, for my next trick, 50Hz

Tom Van Baak tvb at LeapSecond.com
Fri Oct 3 18:33:11 UTC 2008


> This would produce a lot of data and be quite intensive in processor
> time. Sampling the input waveform is easy as it's done in hardware on

There's no need to time-stamp each sample (and I'm not sure
this is even possible with sound card API's). What I meant is to
time-stamp each sound card input buffer completion interrupt.

For example, a 512 byte buffer would give you 86.1 interrupts
per second which should be plenty of time-stamps to precisely
determine the relative clock rates of NTP vs. the sound card
without creating much overhead.

You could play with the trade-off of buffer size and the number
of circular buffers to achieve both the desired precision and the
desired reliability. Your precision goal is to know the frequency
offset of the sound card to 1ppm vs. NTP. Your reliability goal is
zero input buffer data loss.

> Lets see, phase shift of 1ppm in 10 seconds at a sampling rate of
> 44KHz. So our error is 10^-6 so over 10 seconds becomes a 10^-5
> change. Now 44KHz is a rate of 4.4x10^4 or 0.44x10^5. So that looks
> like we would come up a bit short on data to verify the 1ppm
> difference, IE. only 0.44 sample to indicate the error which would not
> show up. at 10ppm we would have 4.4 samples to show the difference
> which would be more workable. Is my logic wrong here or when do I get
> my Thunderbolt?

My calculations were -- a frequency error of 1 ppm is a 1 us per
second phase drift. Since you are sampling at 44.1 kHz (which
is one sample every 22.67 us) the leading edge (or the peak, or
centroid, or whatever) of the sampled UUT waveform will drift by
one "quantum" (a sample bucket) in just 22 seconds. I think we
are on the same page so far.

Now, with not much math, and because you see 1000 waveforms
per second, you should be able to nail down the *average* phase
of the UUT to less than one bucket; depending on the noise level,
maybe way less than one bucket. But if even half a bucket, you'd
detect 1ppm in 10 seconds. At least that was my hunch.

Note that since the UUT frequency (nominally 1 kHz) is not exactly
synchronized with the sound card sampling frequency (nominally
44.1 kHz) the saw-tooth like effect you will see is also to your
great advantage.

In addition, any modest jitter in the sound card or in your UUT will
further make your phase measurements average down better than
one bucket.

Watching the std dev of your edge detect measurements would
be a good indication of how long you actually need to continue
sampling in order to meet a 1 ppm resolution goal. Clearly, if
you can't nail down the UUT waveform to even within ten 44.1 kHz
samples, you're talking a frequency measurement duration of
minutes rather than seconds.

/tvb
http://www.LeapSecond.com





More information about the time-nuts mailing list