[time-nuts] Re: Timestamping counter techniques : phase computation question
Magnus Danielson
magnus at rubidium.se
Mon Jan 31 16:41:54 UTC 2022
Hi Erik,
On 2022-01-30 12:46, Erik Kaashoek wrote:
> In a timestamping counter I'm trying to calculate phase and frequency
> using statistical techniques.
> The counter has two counters, one for the input events and one for an
> internal clock.
> The capturing of these counters happens synchronized with an event.
> The counter takes the timestamps at more or less regular, but not
> identical, intervals
> An example of 20 captures is:
>
> Events      Clock
> 280707207Â Â Â 1693452332
> 280708207Â Â Â 1693473665
> 280709207Â Â Â 1693494999
> 280710207Â Â Â 1693516332
> 280711207Â Â Â 1693537665
> 280712207Â Â Â 1693558999
> 280713207Â Â Â 1693580332
> 280714206Â Â Â 1693601644
> 280715207Â Â Â 1693622999
> 280716206Â Â Â 1693644310
> 280717206Â Â Â 1693665644
> 280718206Â Â Â 1693686977
> 280719206Â Â Â 1693708311
> 280720206Â Â Â 1693729644
> 280721206Â Â Â 1693750977
> 280722206Â Â Â 1693772311
> 280723206Â Â Â 1693793644
> 280724206Â Â Â 1693814977
> 280725206Â Â Â 1693836310
> 280726206Â Â Â 1693857644
>
> By subtracting the counts at the first capture one gets:
>
> Events Clock
> 0 Â Â Â Â 0
> 1000Â Â Â 21333
> 2000Â Â Â 42667
> 3000Â Â Â 64000
> 4000Â Â Â 85333
> 5000Â Â Â 106667
> 6000Â Â Â 128000
> 6999Â Â Â 149312
> 8000Â Â Â 170667
> 8999Â Â Â 191978
> 9999Â Â Â 213312
> 10999Â Â Â 234645
> 11999Â Â Â 255979
> 12999Â Â Â 277312
> 13999Â Â Â 298645
> 14999Â Â Â 319979
> 15999Â Â Â 341312
> 16999Â Â Â 362645
> 17999Â Â Â 383978
> 18999Â Â Â 405312
>
> It is visible the clock count interval is not completely constant and
> the mathematical method used should be able to deal with these
> interval variations.
> To calculate the ratio between the frequency of the events and the
> frequency of the clock a linear regression is calculated where the
> event capture is the X and the clock capture is the Y.
> The slope of the linear regression is the ratio between the frequency
> of the events and the frequency of the clock.
> To calculate the phase between the clock and the events it is assumed
> that the regression also provides the Y intersect for X is zero as the
> fractional correction of the clock count at event count zero as the
> capture happened synchronized with the event (and NOT with the clock)
I think you got off to a great start there.
>
> This leads me to my questions:
> 1: Is using linear regression as described above a good method to
> calculate the phase relation between events and clock? If not, what
> method to use?
Modern counters use linear regression. However, the usual formulas can
run into numerical precission issues. An alternative approach is to do
least square analysis, that gives the same benefit as linear regression,
but the calculation can be made to avoid or control numerical precission
issues.
To get started, classic linear regression is doing just fine.
You should be aware that the effective bandwidth you have will depend on
the number of samples, so as you later perform ADEV it will be affected
by the filtering of the linear regression/least square, the same
filtering helping you do good measures, as it supress white noise.
It is often incorrectly claimed that linear regression will give optimum
frequency estimation, this is not true.
> 2: For highest accuracy of the calculation output, is it best the
> captures are at (almost) regular intervals (as above) or is some form
> of dithering of the interval better? And what form of dithering is best?
That will not help you in a good way. Keep it as close to the same
interval as you can, and then let the linear regression work for you.
The supression slope will be the optimum 1/(N^1.5) until you hit the
noise floor of other noises.
There is a systematic noise you want to fight, and the best way to fight
it is with dither-signal onto the quantization, and the sample points on
a large scale is not the best method. Typically a "white noise" is
better. However, the other filtering method does most of this anyway so
it is rarely done.
> 3: Assuming it is possible to have a large amount (1e+5) of captures
> per measurement interval, are there other or additional methods to
> further improve the accuracy?
Linear regression / least square at a high rate can let you decimate
data for good precision and high read-out rate.
Maybe this [1] article of mine can be of inspiration.
Cheers,
Magnus
[1]
https://www.academia.edu/63957662/Memory_efficient_high_speed_algorithm_for_multi_%CF%84_PDEV_analysis
More information about the Time-nuts_lists.febo.com
mailing list