% Notation:
% Menge aller APs und deren Position
% Gemessene Distanz vs true Distanz vs Schätzung
% Selbe für Position

\section{Position Estimation}
\label{sec:position}

%Bei Indoor Lokalisierung geht es darum eine Position zu ermitteln. Hierfür nutzen wir unterschiedliche Verfahren. namley... usw. 

After measuring several distances to different anchor points one can calculate his current position.
%TODO Alles mit 2D, weil halt

\subsection{Multilateration}
%Ganz kurz erläutern was Multilateration eigentlich ist. in 2D min 3 aps und in 3D min. 4D. Aber grundsätzlich gilt: viel hilft viel.
%Es ist uns klar, dass Trilat nichts taugt aber ist halt der einfachste Schritt
%Typische Nachteile: Wenn Schnittpunkt nicht analytisch exakt bestimmt werden können
%FTM Nachteil: Häufig fallen die Messungen aus? Was tun? Alte Werte statisch halten? Keine est berechnen?
%Conceptually, multilateration determines the position by analytically intersecting at least $3$ circles for a 2-dimensional position, or at least $4$ spheres in case of a 3-dimensional coordinate system.
In two dimensions each distance measurement $d_i$ constrains the position estimate $\hat{\mPosVec}$ to a circle with radius equals $d_i$, where the center of the circle is the known position $\mPosVec_i = (x,y)^T$ of AP $i$.
Formally the distance is the euclidean distance between the known position and the estimate
\begin{equation}
d_i = \| \mPosVec_i - \hat{\mPosVec} \|   \text{.}
\end{equation}
Three ideal distances form a system of linear equations which can be uniquely solved to obtain the position.
Given more than three distances no solution can be found which satisfies all the constraints as the linear system is overdetermined.
Additionally, in the presence of noise and inaccurate measurements an exact analytical solution is not possible.
In this case an approximative solution $\mPosVec^*$ can be found by using a least squares approach which minimizes the quadratic error between the measured distance and the actual distance at a given point
\begin{equation}
  \mPosVec^* = \argmin_{\hat{\mPosVec}} \sum_{i}^{} \left(  \| \mPosVec_i - \hat{\mPosVec} \| - d_i \right)^2  \text{.}
\label{eq:leastSquare}
\end{equation}

This forms a classical non linear least squared optimization problem which can be solved with a numerical optimization method like \docGaussNetwon or \docLevenbergMarq.
The position $\hat{\mPosVec}$ which minimizes the error provides an approximative estimate $\mPosVec^*$.
In contrast to an analytical solution this results not in an ideal point intersection but an area where the error of \eqref{eq:leastSquare} is acceptable small.

A good starting value for the optimization can be obtained by computing the pseudo inverse of the matrix. % TODO formeln
Note that the linearization of \ref{?} is obtained by subtracting one equation from the remaining equations which introduces a potentially significant offset in the estimate.
This offset depends on the particular choice of equation to subtract.
%TODO local minima vs global?
%TODO was noch?

Another factor which influences the localization accuracy is the geometry of the setup where the measurements were taken.
The accuracy of multilateration estimate depends on the position of the APs and the position of the smartphone relatively to each other.
Therefore, it is important to consider the actual AP locations and the walkable area where the localization system is used to improve localization accuracy.
However, the best geometrical setup for localization is not necessarily the best setup for signal coverage.

Best localization results are archived when the distance circles of the APs intersect in a near orthogonal angle.
Localization performance degrades with wider intersection angles.
The optimal setup in a simple scenario given four APs is to place them at the corners of a square.
This yields best localization performance inside of the square.

Usually non-optimal AP locations need to be chosen due to environmental constrains like building structure or signal coverage.
These geometrical considerations can be founded on geometric dilution of precision (GDOP), which is a rating of the expected localization performance based on the sender-receiver geometry.
Lower GDOP values indicate better estimation precision due to smaller intersection angles.
GDOP allows to plan the deployment of APs for location estimation before actually installing the APs.

Given a setup with $i$ APs and their known positions $\mPosVec_i = (x,y)^T$, the GDOP value is calculated by forming a matrix 
%In order to compute the GDOP value in a setup with known AP positions $\mPosVec_i = (x,y)^T$ their correspondent unit vectors from a given position $(x,y)$ form the matrix
\begin{equation}
A = 
 \begin{pmatrix}
  \frac{(x_1 - x)}{R_1} & \frac{(y_1 - y)}{R_1}  \\[0.3em]
  \frac{(x_2 - x)}{R_2} & \frac{(y_2 - y)}{R_2}  \\[0.3em]
  \vdots                & \vdots                 \\[0.3em]
  \frac{(x_i - x)}{R_i} & \frac{(y_i - y)}{R_i}  \\
 \end{pmatrix}
\end{equation}
where $R_i=\sqrt{(x_i-x)^2+(y_i-y)^2}$. Each row of $A$ is a unit vector from a given position $(x,y)^T$ to the AP's position $\mPosVec_i$. Given the matrix $Q = (A^TA)^{-1}$ the GDOP value is the square root of the sum of the diagonal of $Q$:
\begin{equation}
\text{GDOP} = \sqrt{\text{trace}(Q)}
\end{equation}

While GDOP allows to rate the given scenario regarding position estimation precision it only takes the relative geometry of the senders and receiver into account.
Other factors like signal attenuation or absorption are not considered.
However, GDOP still gives a good first impression of the theoretical suitability of a geometrically arrangement of senders for position estimation and provides an indicator for further optimizations of it.
%DOP ganz nett aber signalstärken spielt auch eine Rolle

\subsection{Probabilistic}
%Dichte aus Messungen erzeugen.
%Distanzern werden mit Normalverteilung gewichtet
%Vorteil: Nicht ideale Schnittpunkte sind kein Problem, weil die Dichte sowas abbilden kann
%FTM Vorteil: Fehlen von Messungen kann probabilistisch erfasst werden indem Streuung der NV größer wird / Oder es enstehen einfach mehrere Hypthesen über die Position
Probabilistic frameworks allow to natively incorporate faulty or inaccurate measurements into the position model.
While multilateration produces a single point as position estimate the probabilistic framework allows to describe the estimated position as probability density function.
This approach has the advantage to model inaccurate measurments as variances and quantify them.

Assuming that FTM measurements follow a Gaussian distribution, the measured distance $d_i$ between the sender and AP $i$ is described by $\mathcal{N}(d^*_i, \sigma^2_i)$ where $d^*_i=\|\mPosVec_i - \mPosVec \|$ is the actual distance between the AP position $\mPosVec_i$ and a given position $\mPosVec$. $\sigma^2_i$ is the variance of the measurement.
Visualized on a two dimensional plane this produces a ring shaped density function where the cross section of the ring is the well known Gaussian curve.

Multiple distance measurements can be combined by a joint density function, if the individual distance measurements to the APs are statistical independent.
The probability to observe a distance measurement $d$ at position $\mPosVec$ is given as
\begin{equation}
  p(d | \mPosVec ) = \prod_i \frac{1}{\sqrt{2\pi\sigma^2_i}} \exp \left( - \frac{(d - d^*_i)^2}{2\sigma^2_i} \right)
\end{equation}

\subsection{Particle Filter}
%Warum auch noch PF? Weil... die meisten lokalisierungs systeme diesen als nicht-linearen schätzer benutzen. er ist vielseitig und kann einfach mit anderen sensoren kombiniert werden. ist das gängigste sensor fusionsverfahren. die dichte wird in samples repräsentiert und ist damit nur eine approximatino der wahrsch. dichte.. dadurch ganz ander repräsentation als probabilistic teil. außerdem ist es ein FILTER, hat also vergangenheit mit drin.
%Ganz schnell nochmal den PF einführen mit standard formel. ein größerer absatz. 
%Einfaches Bewegungsmodell mit NV random
%ftm bzw. rssi einfach über normalverteilung in die evaluation rein.







