## Vertical speed estimation by least squares method

This method finds the line $$y = ax + b$$ that has minimal sum of squared residuals (RSS) in a given set of $$n$$ pairs $$(x_i, y_i)$$:

$$$(x_1, y_1), (x_2, y_2), ... (x_{n}, y_{n})$$$

In this case, $$x$$ is time and $$y$$ is altitude.

Residual at each point is the vertical distance from the line:

$$$\hat\epsilon_i = y_i - (ax_i + b)$$$

Sum of squared residuals:

$$$\sum_{i=1}^n \hat\epsilon_i^2 = \sum_{i=1}^n (y_i^2 - 2ax_{i}y_{i} - 2by_{i} + a^{2}x_i^2 + 2abx_{i} + b^2)$$$

For the given set of $$(x, y)$$ pairs, RSS can be defined as a function of the line parameters $$g(a, b)$$, with all $$x_i$$ and $$y_i$$ held constant.

At the minimum point, partial derivatives will be zero.

$$$\frac{\partial g}{\partial a} = \sum_{i=1}^n (2ax_i^2 + 2bx_{i} - 2x_{i}y_{i}) = 0$$$ $$$\frac{\partial g}{\partial b} = \sum_{i=1}^n (2ax_{i} + 2b - 2y_i) = 0$$$

Line parameters can be found by solving the above set of two equations.

$$$a = \frac{n \sum_{i=1}^n x_{i}y_{i} - \sum_{i=1}^n x_i \sum_{i=1}^n y_i}{n \sum_{i=1}^n x_i^2 - (\sum_{i=1}^n x_i)^2}$$$ $$$b = \frac{\sum_{i=1}^n y_{i} - \sum_{i=1}^n ax_i}{n}$$$

If $$x$$ is time and $$y$$ is altitude, $$a$$ is the estimated vertical speed and $$b$$ is the altitude at zero time.

A plot of pressure measured by Galaxy Nexus pressure sensor (BOSCH BMP180) in an elevator of one of the Manhattan skyscrapers. Pressure altitude computed by Android SensorManager.getAltitude with standard baseline pressure. Descent rate is 6.9 m/s.

The Vertical Speed Indcator application uses this method to estimate climb/descent rate.

Adding vertical accelerometer and using Kalman filter to process the data may improve speed estimation, but this approach requires keeping track of sensor orientation.