# A Novel Ranging Technique Based on Optical Camera Communications and Time Difference of Arrival
## 5 Statistical Analysis of the OCC Subsystem
\begin{array}{ll}\frac{D_{y}-n_{pulse}+1}{n_{pulse}+n_{ guard}}&e=0\\ \frac{2}{n_{pulse}+n_{guard}}&e=i\cdot v_{2}(T)\delta t&/i\in\left[1,\lfloor n_{ pulse}/2\rfloor\right]\\ \frac{1}{n_{pulse}+n_{guard}}&e=n_{pulse}/2\cdot v_{2}(T)\delta t&/D_{y}-n_{ guard}\text{ even}\end{array} \right. \tag{10}\]  
The three probability density functions present the same shape, since their underlying variables (\(n\), \(r\), and \(e\)) are related by linear transformations. This means that the final distance error depends on the row-counting mismatch. When the light source's projection is large enough, the distance error measurement would tend to zero since the pulsed signals would be entirely allocated within the ROI. On the other hand, as the ROI decreases (which is the scenario corresponding to the presented pdfs), the detected number of activated rows could be lower than the actual period of the signal (\(n_{pulse}\)). When this occurs, there are three possibilities:  
* The pulse is allocated entirely (\(n=n_{pulse}\), \(r=0\), \(e=0\)). This corresponds to zero error. * The detected pulse size is smaller than the actual one (\(n=n_{pulse}-i\), \(r=i\), \(e=i\cdot v_{2}(T)\delta t\)). This part of the pdf corresponds to a uniform distribution, whose span ranges from 1 to \(n_{pulse}/2\). * The last item corresponds to the case in which the detected pulse is half the actual one. This only occurs when the difference between \(D_{y}\) and \(n_{pulse}\) is even. Since the shape of \(f_{e}(e)\) is asymmetrical, error reduction based on averaging is not optimal. However, there is a predominance of the zero-error measurement with respect to the uniformly distributed rest. In this work, an error-reduction technique based on the mode of a sequence of \(M\) measurements (\(\vec{n}\)) is proposed (Equation (11)). \[\hat{n}_{pulse}=\sup\text{mode}(\vec{n}) \tag{11}\]  
where \(\vec{n}=\{n_{0},n_{1},...,n_{M-1}\}\) is a M-element vector of measurements, \(\hat{n}_{pulse}\) is the final estimated pulse length, and \(\sup\text{mode}(\cdot)\) is the maximum value of the mode (since several maxima can be found on \(\vec{n}\)). Focusing (for simplicity) on a situation in which \(D_{y}-n_{guard}\) were odd, and naming \(p\) and \(q\) the probabilities of no measurement error and the rest respectively, the following analysis regarding \(\vec{n}\) can be made. \[ \begin{array}{ll}\#\left\{\vec{n}=n_{pulse}\right\}&\sim&B(M,p)\\ \#\left\{\vec{n}=n_{pulse}-i\right\}&\sim&B\left(M-\sum_{j=0}^{i-1}\#\left\{ \vec{n}=n_{pulse}-j\right\},q\right),\\ \sum\#\left\{\vec{n}=n_{i}\right\}=M&&\end{array}  \tag{12}\]  
where \(\#\{\cdot\}\) denotes cardinality, and \(B(M,p)\) is the Binomial distribution. The last equations establish the statistical behavior of the absolute frequencies for each possible measurement. The number of correct measurements (\(n=n_{pulse}\)) follows a Binomial distribution with \(M\) tries with success probability \(p\) (first equation). \(p\) corresponds to \(f_{n}(n_{pulse})\) from Equation (8). The second equation describes the number of occurrences for each row count. It must be taken into account that this definition arises from conditional probabilities, and the Binomial distribution of the \(j\)th element depends on both the boundary condition of the third equation and the distribution of the \((j-1)\)th element. This definition leads to a \(M-1\) dimensional probability density function, in which each capture is considered independent. In this case, the mode is associated with the superior argument maximum of the cardinality vector. This problem must be solved numerically, which is illustrated in Section 6.