# How to classify accelerometer data?

I am trying to detect if a car did accelerate or did brake by using the accelerometer of the iPhone.

In the figure below I plotted the collected data. (To collect the data the phone was laying flat in the car facing the top of the phone to the front).

The issue I am having now is that visually I can clearly see where the car accelerated and where it did brake (see below). But can't figure out how to do that programatically.

What I basically want is to know how often a car did brake or accelerate during a certain time window. (Window size around 10-30 seconds).

Any help would be highly appreciated.

• What is the unit on the $x-\text{axis}$ ? Aug 19, 2014 at 22:23
• The unit of the x axis is time. I sampled with 60 Hz. So the values on the x axis divided by 60 would represent seconds.
– riik
Aug 20, 2014 at 6:56
• Okay it's the number of samples. One way would be getting a sliding window of the size you're suggesting and putting conditions on the mean and variance of the collected samples , if necessary adding conditions on zero crossing intervals. But if you do the analysis without the short-time windows, can't the number of rising edges of the activity signal (blue signal) give you how many times you've accelerated, and falling edges for breaking ? Aug 20, 2014 at 8:04
• @PaulR thanks for the clarification! I just updated the question accordingly.
– riik
Aug 20, 2014 at 13:23
• OK, if you use the accelerometer data, you could in principle just use the sign of the acceleration (- for braking, + for accelerating). The problem is the noise. Probably you can sufficiently increase the SNR by using a Savitzky Golay filter. Aug 20, 2014 at 15:53

You should know the orientation of the phone because the axis signum must be the same of the car motion. Assuming the axis signum is correct you can filter the accelerometer signal in lowpass, to clean the high frequency noise and then see the signal signum to detect if it is a break $a(t_i)<0$ or an acceleration $a(t_i)>0$.
You should try to filter with a butterworth low pass of the second or third order with a low frequency for example $10Hz$ or also less, you should try some cut frequencies looking the graphic.