# Timing and accuracy

> How the API gives every high-rate sample its own time, and how it keeps those times consistent from one packet to the next.

Vibration analysis depends on knowing exactly when each sample was taken. A frequency estimate is only as good as the spacing of its samples, and comparing two sensors needs a shared time base. This page explains where Asense timestamps come from and what the API does to make them consistent.

## Times come from the device

Every record is stamped by the sensor when it is measured. Network delays don't change it, and a record that reaches the cloud late still carries its true measurement time. All times in the API are UTC: `time` in Unix milliseconds and `datetime` in ISO 8601 with a `Z`.

## Samples inside a packet

The high-rate tables (`acc`, `gyr` and `ain`) are stored in packets. A packet is a block of samples with one timestamp: the time of its **last** sample. The API places the earlier samples backwards from that time, one sample period apart.

The nominal sample period is `1000 / odr` milliseconds, where `odr` is the output data rate in hertz. A sensor's real rate differs slightly from its nominal rate, because every oscillator drifts a little with temperature and age. Over a long recording those small differences add up, so the API does better than the nominal rate by default.

## Measured sample spacing (auto_odr)

With `auto_odr=true` (the default), the API measures the time between the end of one packet and the end of the next. It then spreads the samples of the second packet evenly over that interval. The spacing therefore follows the sensor's real rate, and the samples of consecutive packets join without gaps or overlaps.

This only applies when two packets are between 1.0 and 1.5 seconds apart, which is the normal packet interval. A longer gap means the recording paused, and the nominal rate is used for the packet after it. Because the measured spacing is rarely a whole number of milliseconds, sample times can have fractions, such as `1764547200019.53125`.

The first packet of a request has no packet before it in the window. So the API also reads up to 3 seconds of data before `start_time`, uses it to time the first packet, and leaves it out of the response. The `load_prior_elements` parameter controls this.

## Repairing out-of-step packets (enable_correction)

On a few devices a packet can occasionally carry a timestamp that is out of step: one interval comes out too long, and the next too short by about the same amount. With `enable_correction` on, the API finds these pairs by comparing each interval with the median interval of the page. It moves the packet in between back into step when both intervals are more than 1.5% away from the median. This setting is on by default only for the devices that need it.

## Gyroscope and accelerometer on one time base (sync_acc_gyr)

The accelerometer and the gyroscope send separate packets. With `sync_acc_gyr` on, the API gives each gyroscope packet the time of the accelerometer packet recorded up to 200 ms before it. A gyroscope packet with no accelerometer packet in that range keeps its own time. The setting follows `enable_correction` unless you set it yourself.

## Getting the raw times

To work with the times exactly as the device sent them, turn the corrections off:

```text
auto_odr=false&enable_correction=false&sync_acc_gyr=false
```

Samples are then spaced at the nominal rate, `1000 / odr` milliseconds, back from each packet's timestamp.

## Summary records

The `data`, `env` and `connected` tables hold one value per field and per record, so no sample timing is involved. Their `time` is the timestamp the device gave the record. The `w_s_avg` series in `data` is the only exception: its six points are placed 10 minutes apart, ending at the whole hour the record falls in.

Source page: https://asense.semitronica.pt/docs/timing-and-accuracy/
