Close

Optimisation

A project log for Software Phase Locked Loop

The 567 tone decoder is perhaps most famous Phase Locked Loop (PLL) chip. This project looks at an Arduino software PLL.

agp.cooperagp.cooper 02/27/2017 at 11:260 Comments

Optimisation

I have been considering what to do next with the software PLL. Do I go the simple low pass filter and move on or spend more time optimising. It is a question of time versus likely outcomes. I have a good result, is it worth trying to make it better?

The second problem is how to optimise this problem? I can see two approaches:

  1. More theoretical research - Someone else may have already solved this problem.
  2. Use numerical methods to search the parameter space (maybe I will get lucky).

But first what is the problem I am trying to solve?

Here is a very good result from the Bell103A2 modem project:

What are the key attributes:

Here is a less than ideal response:

Back to phase locked loops

Here is my current low pass PLL response showing the data input (square wave), the LP output and a fitted sine wave:

So why is this important? Here is version that looked good in the beginning only to blow up latter:

What when wrong?

Searching Parameter Space

What controls the output of the PLL? Yes I know about Q (transit overshoot) and natural frequency but the above image shows a stable PLL becoming unstable. To fix the above I increased the lower bound frequency to reduce the work for the PLL to get into lock.

What parameters can I play with?

Sample Rate

I am obviously very reluctant to change (increase) the sample rate. But here is the impact (SR = 8065):

And (SR = 16667 Hz):

Note: the fitted sine wave (to the output) uses the last four cycles.

DDS Low Frequency

I already know this works but I don't know if the system is stable?

Low Pass Filter

Again, yes but the theory does not translate very well with a low sample rate.

What to do?

I am thinking that I could get really bogged down here. I have coded a steepest descent optimiser (but not run it ) but based on the rules of thumb that I already know I suspect I will not find anything new. The problem has multiple local optima (due to the discrete nature of a software PLL), so problem will not solve easily or reliable. I think I should move on!

Fitting a Sine Wave to the Data

I am familiar with multi-variate analysis so linearising and solving the equations is not too hard. The form of the equation I am trying to solve is:

where:

Separate the Frequency and Phase using:

Therefore (after relabelling the constants):

The error squared function is:

Solving the multi-variate problem:

Where N is the number of samples.

Fortunately the above simplifies if the range of "t" is a multiple of 2 * Pi, to:

Therefore:

Here it is in VBA code:

A0 = 0
A1 = 0
A2 = 0
For Time = Int(SR / 150 + 0.5) To Int(5 * SR / 150 + 0.5)
  A0 = A0 + Test(Time)
  A1 = A1 + Test(Time) * Cos(2 * Pi * Time * 150 / SR)
  A2 = A2 + Test(Time) * Sin(2 * Pi * Time * 150 / SR)
Next Time

A0 = A0 / Int(4 * SR / 150 + 0.5)
A1 = 2 * A1 / Int(4 * SR / 150 + 0.5)
A2 = 2 * A2 / Int(4 * SR / 150 + 0.5)
E2 = 0
For Time = 0 To Int(5 * SR / 150 + 0.5)
  ActiveSheet.Cells(Time + 3, 8).Value = Space - 20
  ActiveSheet.Cells(Time + 3, 9).Value = A0 + A1 * Cos(2 * Pi * Time * 150 / SR) + A2 * Sin(2 * Pi * Time * 150 / SR)
  If (Time >= Int(SR / 150 + 0.5)) Then
    E2 = E2 + (Test(Time) - (A0 + A1 * Cos(2 * Pi * Time * 150 / SR) + A2 * Sin(2 * Pi * Time * 150 / SR))) ^ 2
  End If
Next Time

Back to the Modem Problem

Yes a PLL will work (quite well).

The other problem was removing jitter by extracting the clock. Well I have not really looked at that but I can now extract a fitted sine wave (with limitations) that could resolve much of the jitter. The error would be low on the transition and the fitted sine wave used to determine zero crossing. The computation effort though is not likely to work with the limited computational bandwidth of the Arduino CPU.

Regards AlanX

Discussions