Timestamp Correction for Accurate Temporal Reference and Signal Synchronization

This post explains:

1) How timestamps are collected during real-time acquisition, and the timestamp correction we apply when exporting the data to make the timestamps more accurate.

2) Depending on the output format, how to use the corrected timestamps to align external events with the recorded signals.

1) Timestamp Acquisition and Correction

The amplifiers use a wireless connection (either standard Bluetooth or Low Energy Bluetooth) to send the data packages to the computer. Every data package contains a sequence number we use to detect potential data loss, and the real-time (or reception timestamps) are captured on data arrival in the computer.

There is an inherent variability (commonly referred to as jitter) in the arrival of the packages, being larger when the quality of the connection is poor (e.g, due to many connections, or large distance to the computer). Thanks to the fact that we know that the amplifier sends the data packages at a constant rate, it is possible to correct the real-time timestamps (reception timestamps). More specifically, we use robust statistical methods to remove the jitter in the timestamps, and provide timestamps uniformly distributed.

2) Event Alignment and Synchronization 

We explain below the two output methods we provide (full and lite) and how to use the corrected timestamps to align external events with the recorded signals. Note that the exact same timestamp correction algorithm is performed in both cases.

EDF and CSV-Full formats 

In Full format (either EDF or CSV), we guarantee a common starting point for all the signals (even when recorded with multiple devices) and fill the potential gaps due to data loss. This approach ensures that the temporal structure of the data is consistent and that all signals are properly aligned. More in detail:

  • Common start point: when a signal starts recording later than others, its initial samples are filled with NaN values (padding).
  • Gaps filling: potential gaps (identified using the sequence numbers) are filled with NaN values.

Along with the exported signal files, a metadata file (in JSON format) is generated. This file contains the initial timestamp (t₀), expressed both in the computer’s internal clock and as a UTC timestamp in microseconds. This t₀ corresponds to the initial timestamp of all the signals.

Per-sample timestamps and alignment with events

Based on this reference, the timestamp of each sample can be computed using the sampling rate (SR) of the signal, following the expression:

ti = t0 + i / SR

where ti represents the timestamp of sample i. 

Given an event happening in te, its sample in each signal can be computed easily using the following expression:

Samplee ​= SR ⋅ (te​−t0) / 106 

CSV-Lite format 

In the CSV-Lite format, signals are not aligned to a common starting point, and the potential missing samples are not filled with NaNs. Therefore, we provide the sequence numbers (to detect data loss), the real-time (reception) timestamps per data block, as well as the per-sample corrected timestamps. This method would allow the researchers to access the real-time timestamps and sequence numbers to perform their own synchronization procedure if needed.

Alignment with events

Given an event happening in te, its sample in a given signal can be computed easily by searching for the closest sample with a corrected timestamp similar to te.