[time-nuts] Timestamping counter techniques : phase computation question

Erik Kaashoek erik at kaashoek.com
Sun Jan 30 11:46:19 UTC 2022


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)

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?
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?
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?









More information about the Time-nuts_lists.febo.com mailing list