[time-nuts] First success with very simple, very low cost GPSDO

WarrenS warrensjmail-one at yahoo.com
Mon Apr 14 20:31:38 EDT 2014


Magnus wrote:
>We still disagree
Ok, but I do see progress because we are getting closer.
If you will now allow me to initialize both code's DC offsets to zero before 
the code is run, then because their AC performance is the same, their 
outputs will remain the same if their inputs are the same, as long as there 
is no clipping or rounding in the math.

Thanks for the long and most interesting analysis.

To test the hypothesis that the P and F gains in your code example always 
have the same effect,
I did a black box test of the two code sections below, using Excel with 
double floating point math
I provided the same data string to both code's inputs, using various P, F, & 
I, gains and compared their outputs to each other.
Of course I can never be sure I've included all cases,
But I did enough variations to satisfy me that with this black box test, the 
outputs of both codes where always equal under all of the variations that I 
tried, which included ramps, steps, sine-waves and random noise in various 
combinations, as long as F did not change during a data run. (note 4)
If you can tell me some simulation values to use where the two black box 
outputs will not be equal what would be most helpful in understanding any 
differences that these two codes may have.
If not,  I must trust the simulation results, that I do understand, more 
than I can trust some of your analysis, that I do not fully understand.

Because their outputs are always equal with any combination of inputs and 
gains, until I see some case where the outputs do not remain equal, I must 
concluded that the performance of the two codes will also be equal in any 
loop, under all conditions, whether locked or not, even then there are 
discontinuous phase wraps or when a non-linear phase detector is in the 
loop.
In other words, the MD code as shown below, does the exact same thing as the 
PI code beneath it.
I'd be most interested to hear if there is a flaw in this limited simple but 
thorough black box type of test or the conclusion that both codes always 
provide the exact same function

MD code
First initialize  Vdp_pre & Vi to zero and then run the loop:
> Vdf = Vdp - Vdp_pre Vdp_pre = Vdp
> Vi = Vi + I*Vdp + F*Vdf
> Vf = Vi + P*Vdp

PI code
 Initialize Vi to zero before running the loop
> Vi = Vi + I*Vdp               // PI integrator
> Vf = Vi + (P + F) * Vdp  // PI Output


notes,
1) The DC offsets, which is the only difference between these two code 
examples are both first set to zero at the initialization time.

2) Any time after initialization, their outputs depends on their AC 
response, which are exactly equal.

3) The two outputs remained equal to each other, with all of the input data 
streams I tried and with various gain factors when the gains remained 
constant during a run.

4) To insure that the outputs remain the same during any dynamic gain 
changes, This slightly modified code removes the possible derivative skew 
that can happen during a F gain change.
MD+ Modified code if the F gain is dynamic. (If F gain is static, this code 
provided the exact same results as the MD code above.)
First initialize  Vdp_pre & Vi to zero, F1= F, then run the loop:
> Vi = Vi + I*Vdp + (F*Vdp - F1*Vdp_pre)
> Vf = Vi + P*Vdp
> Vdp_pre = Vdp
> F1 = F

ws

*******************
Warren,

On 13/04/14 19:24, WarrenS wrote:
> Magnus wrote
>
>> You are over-focusing ...
> At least on that we totally agree.
> The same can be said of you in over-focusing on what comes before the
> Phase error term Vdp. The PI code we've been discussing does not care.
> Can we just focus to see if you can find a mistake in my understanding
> of your code below?

Here we disagree, and it's not that I want to disagree with you, let me
assure you.

The thing is that one has to have a split vision, as there is different
base-cases to consider. If we where only discussing the dynamics of the
loop while being locked, then F and P does about the same thing. That I
have already said and there we agree. If we where *only* looking at that
case, then we are in full agreement that F does not really add any value
over P. To do this part of the analysis, the code-snippet I provided is
sufficient, even if we is cheating a little.

However, as I am trying to pointing out, it's when the loop is in
frequency acquisition, that's where the F contribution aids the loop by
providing a FLL. In order to analyze this behaviour, you will have to
analyze the complete loop.

This is why I have a split vision. Just analysing the loop for frequency
acquisition behaviour using the AC dynamics of the locked-in behaviour
simply does lead oneself astray, me too.

> The output (Vf) is the sum of the integrator (Vi) and P*Vdp   (line 4)
> The output of the integrator (Vi) is the sum of the integral of  I*Vdp
> and the integral of F*derivative_of_Vdp  (Line #3)
> The integral of the derivative cancel  (reference below)
>
> So the above can be simplified to
> The output Vf is the sum of three terms:
> P*Vdp
> I * integral_of_Vdp
> F*Vdp
>
> The P and F gains above both have the exact same effect and can further
> be simplified to:
> The output Vf is the sum of two terms:
> (P+F)*Vdp
> I * integral_of_Vdp
>
>
> As far as I can tell, your code:
>>> Vdf = Vdp - Vdp_pre
>>> Vdp_pre = Vdp
>>> Vi = Vi + I*Vdp + F*Vdf
>>> Vf = Vi + P*Vdp
>
> Gives the exact same output as:
>> Vi = Vi + I*Vdp
>> Vf = (P + F) * Vdp + Vi
> Which is nothing more than a standard PI controller
> Do we still disagree?? If so where?

We still disagree, since you are looking at the AC behaviour of the PIF
loop contoler while I loop at the DC behaviour of the complete loop.

> reference
> http://www.mathmistakes.info/facts/CalculusFacts/learn/doi/doi.html
> that says in part;
> the fundamental theorem of calculus can be loosely expressed in words as:
> "the integral of a derivative of a function is that original function", 
> ...

Which only annoys me as I keep this part of my math knowledge active and
well-maintained. That statement isn't mathematical exact on the DC term,
which is what I'm looking at. Also, you need to look at the behaviour of
the complete *loop* rather than part of it. I only showed the modified
part of the loop as the other part is assumed known.

So, let's provide a model for the complete loop.

x is the input or reference phase of an oscillator of angular frequency
omega_0.
y is the output of the oscillator and loop.

The oscillator has the angular frequency omega_1, which is omega_0 +
omega_e where omega_e is the oscillators angular frequency error. Thus:

y = (omega_1 + K_o * Vf)/s

where is the LaPlace variable, 1/s is the LaPlace behaviour of an
integrator, in this case the phase-accumulation of the oscillator.

The phase comparator is modelled as

w = x - y
Vdp = K_d * w

This separation becomes handy as one builds the overall loop equation.

OK, so lets model the diffrentiation, it becomes s, which is the
LaPlace:ian model for a diffrentiation. The detected frequency thus becomes:

Vdf = s*Vdp

Modelling the PIF loop now becomes (using the 1/s for the integrator)

Vf = P*Vdp + I*Vdp/s + F*Vdf/s

Now, inserting Vdf into the Vf formula clearly have s/s thus cancelling
the effect, which is valid of the AC analysis that the LaPlacian loop
analysis allows. The open loop analysis gives (when dropping the static
part of oscillators behaviour, as this is an AC analysis)

G(s) = y/w = 1/s * K_o * (P + I/s + F) * K_d = K_o*K_d*((P+F)s+I)/s²

H(s) = y/x = G(s) / (1+G(s))
      = K_o*K_d*((P+F)s+I)/(s^2 + K_o*K_d*((P+F)s+I)

considering that a standard loop has the roots

s^2 + 2*d*omega_n*s + omega_n^2 = s^2 + K_o*K_d*(P+F)*s + K_o*K_d*I

we get

omega_n^2 = K_o*K_d*I
2*d*omega_n = K_o*K_d*(P+F)

So, in the PLL sense, as usual I is the sole control of the loops
bandwidth and P and F is equivalent in contributing to the loops damping.

However, as we dropped the fixed component of the oscillator, we assumed
that oscillator was in perfect agreement with the reference in terms of
frequency, so that part of the loop behaviour isn't very well modelled.
So, let's look at that part.

The reference source has the angular frequency of omega_0, so we then
model the oscillator as

x = omega_0/s

the loops oscillator is as before

y = (omega_1 + K_o * Vf)/s = omega_1/s + K_o*Vf/s

The phase comparator response thus becomes

w = x - y = omega_0/s - omega_1/s - K_o*Vf/s

considering that the loop oscillators angular frequency can be modelled
as the sum of the reference oscillators frequency and an error term

omega_1 = omega_0 + omega_e

we can reformulate the response as

w = -omega_e/s - K_o*Vf/s

We can understand this as the phase error between the input and output
is a linear ramp due to the omega_e frequency error until we have K_o*Vf
DC-level equivalent to -omega_e, at which case there remains a phase
error. Achieving this is the frequency acquisition, which for a PI (or
PIF) loop involves letting the integrator have it's state match-up.
Achieving this in an orderly manor is where the F contribution from the
derivate comes into play. Let's see what happens as we go further
through the phase comparator and loop:

Vdp = K_d*w = -K_d*omega_e/s - K_d*K_o*Vf/s
Vdf = Vdp*s = -K_d*omega_e - K_d*K_o*Vf

This looks all nice and dandy, but we have forgotten one aspect. The
phase detector wraps around in phase. This causes effective behaviour of
the phase detector part to have very high AC content, but very weak DC
part, which through the I term goes into the integrator. However, turns
out that the detected frequency can be made relatively independent of
the phase-wrapping.

If we look at the Vi terms we have (disregarding that the Vdp DC term is
weaker than this model)

Vi = (I*Vdp + F*Vdf)/s = -I*K_d*omega_e/s² - I*K_d*K_o*Vf/s²
     - F*K_d*omega_e/s - F*K_d*K_o*Vf/s

For large frequency error, s will be large, so the I parts will be small
while the F part will be larger, while as the integrator state shifts
towards cancelling the omega_e error, s becomes smaller and then the I
part of the PLL dominates.

Your normal loop analysis does not show this, but if you want to
understand lock-in behaviour, you need to do this type of complementary
analysis.

While there still is a few hand-wavings, I hope I spread some insight
into the different types of analysis one can do and while the F
contribution seems like meaningless in one type of analysis, it's quite
a different deal when doing the other type of analysis.

If you don't need or care about improved lock-in behaviour, skip the F
term refinement, but if you want improved lock-in behavious, then you
should look at this approach in parallel with a number of other approaches.

Cheers,
Magnus 



More information about the time-nuts mailing list