# Correct way to quantize accelerometer data with microsecond precision?

I am analyzing large volumes of raw accelerometer data (~12 hours @ 200Hz) using Python. Some calculations (e.g. deriving Jerk) necessitate a time index with a regular interval. I have microsecond-precision time associated with my data but I can see variance in the +/- 80μs range. Which method of time quantization will help me achieve a regular time interval while introducing the least amount of error?

I'm a DSP novice so please excuse and correct me if I'm misusing any terminology

# useless ramblings first

As an SDR person: 12h · 200 S/s = 12·3600s·200S/s = 8.64 MS is not a "large volume of data" (we usually deal with a multiple of that per second), so rest assured, most of your computation should probably be pretty fast to complete, which is good news!

Now, with 200 Hz, your sample period is 5000 µs, so a 80 µs variance (something doesn't add up with the units here, it should be s², not s) would be an error of ca 1.6%, or -18dB. If you assume sufficient band-limitation, rule of thumb says that the resulting phase noise would be in the same order of magnitude, ie. -18dB.

It's generally a good idea to define first what noise level are you aiming for; otherwise you'll be optimizing something that is already good enough.

Of course, you could properly resample, with much less distortion, but frankly, accelerometer data doesn't sound like you necessarily have great SNR in the first place (but I might be totally wrong about that!).

# Interpolator considerations

What you need, if you actually want to generate a perfectly periodically sampled signal, is an interpolator.

What confuses me is that especially jerk is a derivative measure, i.e. you'd be finding an interpolation of your signal more or less anyway; so, where's the problem in using a standard interpolation method (scipy comes with some) to get perfectly periodic samples, should you not choose to implement your own interpolating differentiator (hint: splines are of polynomial shape and that makes differentiation especially easy, so you can directly calculate a derivative from your data/time points, and be done with it, without first calculating a periodically-sampled signal representation).

# Bandwidth considerations

If you know that your signal of interest is contained in frequencies significantly below 100 Hz, then consider this:

Assume your signal is a sum of individually delayed, scaled sines of different frequencies.

The point of maximum derivative, i.e. maximum steepness, is the point where our sampling time offset $\Delta t$ hurts the most.

A single sine has a maximum derivative of 1 (proof: the derivative of a sine is a cosine, which has a max of 1).

If each of your $N$ sines $s_i$ is scaled with an amplitude factor $a_i$ and has frequency $f_i$ (and phase==delay $\varphi_i$, which we do not care about right now), then its formula is

$$s_i = a_i \sin(2\pi f_i t + \varphi_i)$$

and its time derivative

$$\dot s_i = a_i\cdot 2\pi f_i \cdot \cos(2\pi f_i t + \varphi_i)$$

has a maximum of

$$\max \dot s_i = 2\pi a_i f_i = (\max s_i) \cdot 2\pi f_i \text.$$

In a linear approximation (and that's a prett good approximation for a range of less than 1.6%/2 = 0.8% of a cycle of a cosine around it's zero crossing; the non-scaled cosine is pretty much a 45° line there), the (defined-by-me) relative error (relation of error magnitude to amplitude of sine) you get is

\begin{align} \max |e_i| &:= \max \left\lvert\frac{\dot s_i \cdot \Delta t}{a_i}\right\rvert\\ & = 2\pi f_i \Delta t\text, \end{align}

which means that the lower the sine's frequency, the less you're sensitive to jitter.

Let's look at the case where you only care about frequency up to 50 Hz, or 5 Hz:

\begin{align} \max |e_i| &= 2\pi f_i \Delta t&f_i = 50\,\text{Hz}\\ &= 2\pi\, 5\cdot10^1\, \cdot\, 8\cdot10^{-5}\\ &= 2\pi\, 4\cdot10^{-3}\\ &\approx 2.5 \%\\[4em] \max |e_l| &= 2\pi f_l \Delta t&f_l = 5\,\text{Hz}\\ &\approx 0.25 \% \end{align}

So, the lower your signal of interest's frequency is, the less you need to actually care about the jitter!

• Marcus, thank you for this thoughtful and incredibly articulate answer. As a novice I can't fully appreciate all of the math behind it, but I believe I understand the main takeaways. I will attempt to use interpolation as suggested, since it's so simple to do with my toolset. I'm curious how I could compare different methods? For example, how does spline interpolation compare to rounding the time values? Nov 22, 2017 at 23:52
• Well, you can define one to be "right", and then calculate the mean squared error between the two. Nov 24, 2017 at 9:46