# I'm build an app for mountain biking, and I would like to estimate the ground slope using the phone'

I'm build an app for mountain biking, and I would like to estimate the ground slope using the phone's integrated accelerometer so that I can adapt my pedaling effort based on the current slope.
I took the Y-axis value of the accelerometer and converted it to degrees, using a notion abs(y-axis) * 90 with a offset. So, for example, if the accelerometer reads 0.5 or -0.5 on the Y-axis, that's converted to 45°. If I zero out the accelerometer, that 45° is now considered as 0°, and any frontal movement is negative and back movement is positive. I use that value for slope calculation.
Now, that works perfectly fine when standing still. When I angle the phone at 45° the slope is 100%.
But, problems arise in the real world. Since I'm using a accelerometer for my angle detection, readings when hitting potholes and bumps in the road go all over the place. One second I read 80%, the next -300%, and so on.
What can I do to smooth out the readings and make them semi-accurate?
I could try to discard any invalid value, such as anything +-20% of slope and average that over 10 seconds, but I feel that would be inaccurate.
I was looking into the Kalman filter, based on a thesis on slope detection using an accelerometer for Scania trucks, but the jerking of a truck is much less violent than that of a mountain bike.
What can I do to predict and smooth out sensor values over time?
You can still ask an expert for help

• Questions are typically answered in as fast as 30 minutes

Solve your problem for the price of one coffee

• Math expert for every subject
• Pay only if we can solve it

isscacabby17
The easiest way is to simply low pass filter it to get rid of frequencies that you are not interested in. For example, let's say that on most roads and trails, the inclination can only change at $\alpha$ Hertz. Think of riding a bicycle on a sinusoid with a certain frequency. How high of a frequency sinusoid do you think you will be navigating? Even if you don't know the value, you can start with a ballpark, say 5 Hertz (that sounds like a lot) and roll back.
$\stackrel{^}{\theta }\left(k\right)$ be an estimate of your inclination at time k,
and ${\theta }_{\text{a}ccel}\left(k\right)$ be the measurement. Then from your estimate, chop off everything above a frequency of ${w}_{c}$:
$\stackrel{^}{\theta }\left(k+1\right)=\left(1-{w}_{c}{T}_{s}\right)\stackrel{^}{\theta }\left(k\right)+{w}_{c}{T}_{s}{\theta }_{\text{a}ccel}\left(k\right),$,where wc is the cutoff frequency in Hz and Ts is the sample rate. I think you can get about 50Hz sample rate from Android phones. That depends on your device.
The Kalman filter route is more complicated and its performance comes when you know more about the problem. You need a model for your movement (can you tell me what your inclination will be for the next ten seconds if I gave you your correct inclination now and removed the accelerometer?), and noise modeling (can you tell me how much noise on the accelerometer is because of the fact that any movement means the accelerometer is no longer measuring gravity?).