Tuesday, February 19, 2013

Detecting speed bumps with accelerometer

Somebody came in from the internet some months ago and asked whether speed bumps (also called sleeping policemen) can be detected with an Android phone. You know, speed bumps like this:

I was cautious because there's a lot of traps here. Obviously the detected signal will differ depending on the form factor of the speed bump, the type of the car and even the way the phone is fixed to the car (or the lack of fixing). But I was also curious and as car-related phone applications are very fashionable today, I took the challenge. Meanwhile the guy who brought up the problem disappeared so I feel free to share what I achieved during the last one and half months.

The solution that I produced is far from perfect. First and foremost, I did not make any effort to target other phones than my trusty Nexus S. Phones which have sampling frequency of around 50 Hz in SENSOR_DELAY_FASTEST mode will work fine, significantly different sampling frequencies are not supported. It is more important, however, that I was not able to create a foolproof algorithm for the problem.

Initially I thought that some sort of rotation could be measured when the front of the car is lifted by the speed bump but I was not able to detect this rotation from the sensor signal. The car generates all sorts of vibrations and it is not easy to extract this relatively small rotation from the noisy background. So I went back to the acceleration spike which is generated when the car hits the bump and I used just the acceleration's absolute value as described in this presentation. The trouble is that this spike is pretty reminiscent of a class of other spikes like knocks, etc. For example here is a beautiful double street bump somewhere in Budapest.

One would think that signals like these could be easily detected. Now comes, however, a bumpy road with potholes, also typical in Budapest.

There are no street bumps in the second signal but the potholes generate "knocks" that are hard to distinguish from the "knocks" caused by street bumps.

There is no perfect solution to this problem, at least I could not find any. Eventually I obtained the best result by calculating the cross-correlation between the acceleration signal and a pre-recorded speed bump signal. I re-sampled this representative signal for +/- 10% of its initial frequency and calculated the cross-correlation with all the three variants (initial, +10% frequency, -10% frequency). Then I used a sliding window to calculate the power of the cross-correlation signal. This is the pre-recorded sample I used for cross-correlation:

Cross-correlating then calculating the power in a sliding window yields this signal for the double speed bump (different colors show the power of the 3 variants of the re-sampled signal):

And this is the result of the same calculation for the bumpy road:

Using a limit of about 150, the two signals can be separated and no fake bumps are detected even on the bumpy road.

Click here to download the example program.

There are a lot of problems with this approach. First, speed bumps come in all shapes and sizes and this method can detect speed bumps that are similar to the one used to generate the reference signal. Then there is the problem of the car itself. I did not have the chance to test with a lot of different cars but I bet the different suspension systems will yield drastically different signals in different car types. Anyway, I thought somebody may find this post and this post can start some thinking.


Alexander Kosenkov said...

You should consider driver's behavior too!

Almost all drivers will actually slow down in front of those bumps (it's their goal anyways). So, instead of looking just at the acceleration magnitude, check its projections too.

It might look like:
- slowing down (acceleration towards driving direction)
- stopping slowing down (common good practice to unload front wheels)
- front wheels bump and high osscilations
- rear wheels bump and lower osscilations
- car acceleration

Gabor Paller said...

Alexander: I my tests it was a suburban setting. So I drove quite slowly, say 30km/h and slowed down to about 10 km/h before the speed bumps (that I knew very well). That's a speed difference of about 20 km/h, about 5.5 m/s. But the deceleration phase took more than 1 sec - hard to estimate, let it be about 3 sec. That yields an acceleration of about 1.8 m/s^2.

I checked my samples and acceleration in random direction of about 1 m/s^2 was quite common in my samples. The car was shaking on the road because it was not perfectly smooth. In short: I was not able to extract that horizontal negative acceleration (the slowing down) from the noisy background caused by vibrations.

Maybe we can redefine the task so that we are interested only in dangerous passing of speed bumps. Then we can assume much larger deceleration and "knock".

Tejaswini Mayigowda said...


I am using LIS3DH accelerometer to detect Harsh acceleration and Harsh breaking.

The device is working for Harsh breaking perfectly but i am facing difficulty in Harsh acceleration,
With this bump,elevation's are appearing, How to remove the bump?
if i increase interrupt duration of my device i can able to detect only Harsh breaking,i cant detect HA.
Please suggest me for this problem??

Gabor Paller said...

Tejaswini, are you placing the device casually (in any position relative to the car) or do you have the possibility to fix the device to the car? E.g. usual handsfree kits fix the device in such a way that the device's Z axis points more or less to the main axis of the car (axis of driving). In this case the accelerating/braking acceleration can be measured only on the Z axis of the device and road problems (potholes, etc.) would cause acceleration only on the Y axis.

I don't understand your reference to the interrupt duration.

Sandra Johnson said...

Wow! There are way too many close calls and tragedies that could be prevented by drivers doing the right thing. Thanks for sharing your post!!
speed bumps

Ahmad Ali said...

Hi everyone can anyone give me bump detection algorithm?