Skip to content

Define time filter behavior when max_error is 0 #302

Closed
Sendspin/time-filter
#10

Description

@maximmaxim345

The time filter divides by zero when the first three measurements have a max_error of 0. The second measurement leaves all covariances at 0, so S = P_oo_p + R is 0 on the third, and the filter state becomes NaN for good. The C++ reference does the same, and it fails silently: the conversions return wrong values and get_error() returns 0, so the filter looks fully converged.

Output from the C++ reference after three measurements with a max_error of 0, followed by five normal ones:

offset=nan drift=nan P_oo=nan P_od=nan P_dd=nan count=8
compute_client_time(10000000) = 0
get_error() = 0

Implementations already guard against it in different ways:

  • sendspin-cpp drops samples with a max_error of 0 or less
  • sendspin-dotnet drops samples with a round trip of 0 or less and floors max_error at 1 µs
  • SendspinDroid and sendspin-rs floor max_error at 1 µs
  • aiosendspin floors S at 1e-9
  • sendspin-js floors max_error at 1000 µs

One simple solution is flooring max_error at 1 µs, which three implementations already do.

Activity

  1. maximmaxim345 commented on Oct 8, 2026

    @maximmaxim345
    MemberAuthor

    @kahrendt Can you take a look at this when you have time?

  2. kahrendt commented on Oct 14, 2026

    @kahrendt
    Contributor

    Let's floor it at 1 microsecond

  3. kahrendt commented on Oct 14, 2026

    @kahrendt
    Contributor

    On second thought, let's just reject any error <= 0.0 (something is wrong at that point, so it should be ignored). I'll update the time filter code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions