From: dahls@fhydra.dnet.unit.no (Joern Yngve Dahl-Stamnes)
Subject: Re: Cateye Micro average speed algorithm?
Reply-To: dahls@fhydra.dnet.unit.no (Joern Yngve Dahl-Stamnes)
Organization: University of Trondheim, NORWAY
Date: Mon, 05 Oct 92 14:25:04 EDT

Thus spoke the keyboard of blodgett@bvc.edu:
>I've seen some pretty weird average speeds momentarily appear on the display of 
>my Cateye Micro. For example, I've seen the average jump from 17.1 to 18.3 
>then back to 17.3 all in a matter of 10-15 seconds or so. This morning the 
>average momentarily appeared as 210.3 then immediately jumped back to normal 
>range. Has anyone else experienced this phenomenon? 
>I don't really have reason to doubt the overall accuracy of the Micro because 
>the mph, distance, elapsed time, and cadence readings correspond with 
>readings on the cyclometers of the people I ride with. I have concluded, 
>perhaps erroneously, that the anomaly arises from the algorithm used to 
>compute average speed.

Here is the algorithm written in C:

----------------------cut here------------------------
#include stdio.h
#include math.h

main ()
{
    float   dst, tm, tmH, tmM, tmS, avs, speed;
    int     i, start;

    printf ("\n\t\tCateye average speed algorithm.\n");
    printf ("Emulate the average speed of a Cateye cyclo computer\n");
    printf ("over a periode of two minutes with 1 second interval\n\n");
    printf ("\t\twritten by Joern Yngve Dahl-Stamnes\n");
    printf ("\t\tdahls@fhydra.dnet.unit.no\n\n");

/* Read values. */

    printf ("Enter average speed (xx.x km/h) : ");
    scanf ("%f",&speed);

    printf ("Begin print at time (minutes) : ");
    scanf ("%d",&start);

/* Do the work. */

    tmH = (float) (start / 60);
    tmM = (float) (start % 60);
    tmS = 0.0;

    printf ("\n\n\nAverage speed : %5.1f\nStart time : %02.0f.%02.0f.%02.0f\n\n",
        speed,tmH,tmM,tmS);

    for (i = 0; i < 120; i++)
    {
        tm = tmH*3600.0 + tmM*60.0 + tmS;
        dst = speed * tm / 3600.0;

/* The time used to calculate the average speed (avs) is based on
** hours, minutes and 10 seconds. The LSD (Lowest Significant Digit)
** in the second field is ignored. */

        tm = tmH*3600.0 + tmM*60.0 + tmS - fmod(tmS,10.0);
        avs = dst * 3600.0 / tm;

        printf ("dst=%6.2f tm=%02.0f.%02.0f.%02.0f avs=%4.1f\n",
            dst,tmH,tmM,tmS,avs);

        if ((tmS += 1.0) > 59.0)
        {
            tmS = 0.0;
            if ((tmM += 1.0) > 59.0)
            {
                tmM = 0.0;
                tmH += 1.0;
            }
        }
    }
}
----------------------cut here------------------------

I've compiled this on a VAX running VMS, but I thing you should be able
to compile it on any UNI*X or DOS box too. Try run it with with a
constant average speed and begin the print after 5, 10, 20 and 40
minutes and watch the avs= field.

As you will see, the avs field will be more and more accurate after some
time because the "error" will become less and less important.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+-+-+-+-+-+-+
* I went back to my mother,           * Joern Yngve Dahl-Stamnes           *
* I said, "I'm crazy ma, help me!"    * University of Trondheim            *
* She said, "I know how it feels son, * The Norwegian Institute of Tech.   *
* 'cause it runs in the family."      * Division of Physical Electronics   *
*       - The Who, Quadrophenia       * e-mail: dahls@fhydra.dnet.unit.no  *
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+-+-+-+-+-+-+