[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