challenge -- the end?

[Hans Blom, 950920b]

This post analyzes the performance of the two controllers of the
challenge (with just a little bit of high school math). This analysis
may generate more insight into performance issues than mere simulat-
ions do. But first we have to put Bill's controller into the most
favorable light.

Bill, there was an error in your program. As I told you for MY
program, the computation of u which is done at iteration i, is
actually done for time i+1, and therefore needs to refer to r [i+1]
rather than r [i]. The same thing is necessary in your program. After
making this change in your program, you get better results (but not
yet as good as my program's :-). The new score:

                      HANS BILL
Slowing = 0.01 RMS ERROR = 2.0 RMS ERROR = 2.8
Slowing = 0.02 RMS ERROR = 1.9 RMS ERROR = 7.6
Slowing = 0.03 RMS ERROR = 3.1 RMS ERROR = 8.8
Slowing = 0.04 RMS ERROR = 5.2 RMS ERROR = 12.5
Slowing = 0.05 RMS ERROR = 7.3 RMS ERROR = 13.9
Slowing = 0.06 RMS ERROR = 8.7 RMS ERROR = 17.2
Slowing = 0.07 RMS ERROR = 10.8 RMS ERROR = 21.5
Slowing = 0.08 RMS ERROR = 15.2 RMS ERROR = 24.7
Slowing = 0.09 RMS ERROR = 17.7 RMS ERROR = 29.0
Slowing = 0.10 RMS ERROR = 20.6 RMS ERROR = 26.9
Slowing = 0.11 RMS ERROR = 19.5 RMS ERROR = 35.5
Slowing = 0.12 RMS ERROR = 24.0 RMS ERROR = 35.1
Slowing = 0.13 RMS ERROR = 29.8 RMS ERROR = 36.2
Slowing = 0.14 RMS ERROR = 33.2 RMS ERROR = 44.1
Slowing = 0.15 RMS ERROR = 36.2 RMS ERROR = 46.9
Slowing = 0.16 RMS ERROR = 38.5 RMS ERROR = 39.7
Slowing = 0.17 RMS ERROR = 45.0 RMS ERROR = 53.1
Slowing = 0.18 RMS ERROR = 45.5 RMS ERROR = 54.2
Slowing = 0.19 RMS ERROR = 54.2 RMS ERROR = 64.7
Slowing = 0.20 RMS ERROR = 53.7 RMS ERROR = 65.1

The change is in the fourth line of this section:

for i := 0 to maxtable do
begin
  x := b * u + d[i];
  u := u + (r[i+1] - x) / b; <<<<<<<<<<<<<<<< corrected
  sum := sum + sqr(r[i] - x);
end;

Run and see the improvement.

Now let's analyze the above (corrected) section, plugging in i's to
make things explicit:

x [i] = b * u [i] + d [i]

u [i+1] = u [i] + r [i+1] / b - x [i] / b
        = u [i] + r [i+1] / b - u [i] - d [i] / b
        = r [i+1] / b - d [i] / b

x [i+1] = b * u [i+1] + d [i+1]
        = r [i+1] + d [i+1] - d [i]

x [i+1] - r [i+1] = d [i+1] - d [i]

The goal of the controller is to minimize x [i] - r [i] for all i.
In Bill's algorithm this difference is determined by the smoothness
of d: d [i+1] - d [i]. So Bill's algorithm works perfectly only if
the disturbance is constant, and thus will also have good performance
if the disturbance has a square wave character with long periods of
being constant. The performance is bad in all those cases where sub-
sequent disturbance values are far apart, i.e. with high frequency
signals.

Now let's do the same analysis for my program. The code is:

  x := b * u + d[i];
  dnew := x - b * u;
  dpre := 2.0 * dnew - dold;
  u := (r [i+1] - dpre) / b;

x [i] = b * u [i] + d [i]
dnew = d [i]
dold = d [i-1]
dpre = 2 * d [i] - d [i-1]

u [i+1] = (r [i+1] - 2 * d [i] + d [i-1]) / b

x [i+1] = r [i+1] + d [i+1] - 2 * d [i] + d [i-1]

x [i+1] - r [i+1] = d [i+1] - 2 * d [i] + d [i-1]
                  = (d [i+1] - d [i]) - (d [i] - d [i-1])

In my algorithm, the difference between x [] and r [] is determined
by the smoothness of the DERIVATIVE of d. So my algorithm works
perfectly not only when the disturbance is constant, but also if the
disturbance has a constant derivative. And it will have good
performance if the disturbance has a square OR triangle wave
character with long periods of being constant or of having a constant
slope. Therefore, my algorithm subsumes Bill's.

Is this analysis rigorous enough?

You can probably figure out extensions to corrections for even higher
derivatives...

By the way, the gain term b drops out in both analyses, so its value
doesn't matter for the quality of control, as we both already demon-
strated informally in our simulations.

A nice problem for Rick, if you want it: given the above knowledge,
generate a disturbance sequence where Bill's controller performs
better than mine. Although quite unrealistic in practice, such
sequences can be found!

Greetings,

Hans