# online detection of plateaus in time series

I need to detect plateaus in time series data online. The data I am working with represents the magnitude of acceleration of a tri-axis accelerometer. I want to find a reference time window that I can use for calibration purposes. Because of that, the system must not move and hence only gravity should influence the system.

How can I find such plateaus or is there even a more principled approach that I can take?

– Emre
Mar 23 '16 at 17:38

Here is a signal processing approach:

1. Remove the mean value of 1g
2. Square the signal to convert to power.
3. Low pass filter a little bit to remove the highest frequency noise.

Whenever the result is lower than a threshold you define, the system is stable (up to a degree that depends on the threshold; the lower the threshold the more stable the system).

For best results you should take into account the x and y values as well, as your system may be static wrt to z but moving in the xy plane. The steps are the same: just remove 1g from the z component in the first step, calculate the vector power in the second and the rest is identical.

Here's a classic, econometric time series approach: find variance "regimes" as in an ARCH (autoregressive, conditional heteroscedasticity) method. Here's what Wiki has to say about ARCH models:

In econometrics, autoregressive conditional heteroskedasticity (ARCH) models are used to characterize and model time series. They are used at any point in a series, the error terms are thought to have a characteristic size or variance. In particular ARCH models assume the variance of the current error term or innovation to be a function of the actual sizes of the previous time periods' error terms: often the variance is related to the squares of the previous innovations.

Such models are often called ARCH models (Engle, 1982),[1] although a variety of other acronyms are applied to particular structures that have a similar basis. ARCH models are commonly employed in modeling financial time series that exhibit time-varying volatility clustering, i.e. periods of swings interspersed with periods of relative calm. ARCH-type models are sometimes considered to be in the family of stochastic volatility models, although this is strictly incorrect since at time t the volatility is completely pre-determined (deterministic) given previous values.

https://en.wikipedia.org/wiki/Autoregressive_conditional_heteroskedasticity

Correct me if I am wrong. Univariate analysis will make over-segmentation for sure. I see that mean of data points remain constant during the time.

Unsupervised way: What if you model the distribution based on all data points of the time series, than choose a resolution of your algorithm (size of sliding window), then (based on your distribution) construct a statistic (similar to chi-squared statistic which can be constructed from squared normal distributions) and then detect windows that have a statistic value lower than 5% quantile of your distribution? I mean, left-sided test (that will mean that data points within sliding window fit your distribution extremely good, so they are close to the mean). You can do it online, but the accuracy for the first data points will be extremely low.

Supervised way: Also you can label windows of fixed size for plateaus manually and create a distribution for them and consider all deviations from this multivariate distribution as "not a plateaus". Also you may construct 2 distributions (with manual labelling of regions) and consider likelihood ratio as a measure.

These are standard approaches, may be not really sophisticated. For online recognition I would recommend to feed your classifier with the first $n$ data points to train it (you need to have at least some estimations) or use algorithm that can do backwards and re-analyse the first data points.

Here is a machine learning based approach:

Train the machine:

1. Remove 1g from the z signal.
2. Buffer the signal.
3. For each buffer determine the corresponding label: 1 for plateau, 0 otherwise.
4. Feed all buffers and labels into a machine learning classifier to train the classifier.

For real time processing, construct the buffers, feed them into the machine and obtain the output which will indicate if you're in a plateau or not.

• Thank you for helping me out and don't get me wrong, but isn't that just the same as using standard deviation? Mar 14 '16 at 12:18
• Also, I want to get as much of the potential plateau as possible. That means I don't want to have a fix-sized buffer running over my data, but rather a window which gets bigger if the next n-samples are also low. Mar 14 '16 at 12:21
• This approach learns when your buffered signal is part of a plateau or not, based on a family of possible models that you allow. A technique based on standard deviation may be one possible model, though probably not the optimal one, while the optimal one could be learned pretty easily. I removed the signal squaring step from my answer, as this too can be learned by the model if necessary. Mar 30 '16 at 12:50
• If you are familiar with machine learning this approach could be interesting, as it is generic and it may need fewer free parameters to set compared to my other answer (filter parameters, etc. stats.stackexchange.com/a/201315/11179). If you are unfamiliar with machine learning it may be overkill though. Here's an overview en.wikipedia.org/wiki/Statistical_classification. Mar 30 '16 at 12:50
• As for the buffer length, an easy approach would be to postprocess the outputs predicted by the machine. If several contiguous buffers indicate stationarity obviously you can concatenate the result. Mar 30 '16 at 12:50