Time and timestamps - windytan/redsea GitHub Wiki

Clock time and date - group 4A

(Please read this before considering updating your system clock using clock_time!)

Ideally...

Some stations transmit a clock time and date signal in group 4A. According to the standard, it will be transmitted once every minute, so that the UTC minute edge accurately coincides with the end of the 4A group ±0.1 seconds. The number of seconds are not transmitted and redsea assumes :00 seconds as per the standard:

 transmitted in 4A ─────┐           ┌─ transmitted in 4A
                        │           │
              ┌─────────┴────┐   ┌──┴─┐
"clock_time":"2008-03-19T09:37:00+01:00"
                              └┬┘
                               │
                               └── added by redsea

In practice...

However, not all stations follow this standard! There are stations that update the clock almost every second (example: Radio Capital in Italy). And RDS 4A doesn't contain the seconds information. 00 seconds is always assumed by redsea, which can cause abrupt jumps in the clock time if it's used to update a local clock. This should be taken into consideration.

Some stations are known to have their clock set wrong, or it might even be in the wrong year. In this case of course, you will receive the wrong time. One solution could be to keep a list in the receiver of trusted stations that are known to keep their clock in correct time.

Also, since RDS is prone to errors in noisy conditions, this can cause incorrect interpretations of the date code. It would make sense to e.g. wait for two consecutive clock_time updates that make sense together, before trusting the time to update a local clock. A bit error will likely cause a huge jump in the time, rather than a shift of a minute or two.

Rx timestamps

Using the option -t (--timestamp) it's possible to timestamp every output line with the local system time up to the precision of 0.01 seconds. The time format is normal C strftime but an %f character can be used to insert hundredths of seconds: -t %H:%M:%S.%f gives 12:34:56.78. It works for both JSON and hex output.

Unlike the 4A clock_time above, this is the local system's time. It refers to the moment that the end of the last bit of the group was received. This is the same convention that's used in transmitter timestamps in group 4A, to make it possible to compare the radio station's clock to the system clock. We tried to compensate for buffer delays (internal to redsea) when decoding live MPX, so it should refer to the moment the bit was actually read in, and not when it was printed to the output.

Note that it takes about 0.09 seconds to transmit one group. By specification, 4A groups are only accurate up to ±0.1 seconds.

If there are large buffers between the radio and redsea, these cannot be compensated for, and the timestamp will lag behind.

Timestamp since file start

With --time-from-start, redsea (since v1.3) marks every group with its offset in the input MPX file or sample stream. That is, it prints the number of seconds from the beginning of the file until sampling the first bit in each group. This works for both JSON and hex output; in the JSON output, the field is called time_from_start.

It refers to the center of the first biphase symbol:

Position of the time offset

Some caveats:

  • If you're using the raw PCM input, make sure your radio program doesn't add any headers (WAV, ...) in the sample stream. These could shift the timestamps in an unpredictable way. If the pipe input has headers use -f - instead.
  • Even though the JSON library prints a great number of decimals, the granularity is ~7 kHz (±0.14 ms). The timestamps are not high-resolution enough for e.g. validating the symbol phase shift between RDS2 data-streams.
  • This is currently based on a 32-bit sample counter that overflows at around 8 hours (~25 000 seconds).