# FPGA-Based Manchester Decoder for IEEE 802.15.7 Visible Light Communications
## 2 Architecture of the Receiver
### Approximation of the Inverse Tangent  
The calculation of the phase (7) requires the inverse tangent. In general, the real-time calculation of the inverse tangent is not a trivial task. Several algorithms have been reported in the literature that produce approximations with different accuracies and calculation efforts. Readers interested in the subject can find some different implementing techniques for example in [34; 35; 36; 37], but several others are present in the literature. In order to optimize the effort, let us evaluate the accuracy required for the calculation of the inverse tangent in this application. As detailed in the previous section, the phase error \(\varphi_{e}\) is used by the receiver to correct the slice position on the next bit by applying (8). The quantized nature of \(l\), which must be integer (8), imposes a limitation to the requirements of resolution in the calculation of \(\varphi_{e}\), corresponding to the minimum variation \(\Delta\varphi_{e}\) of the phase \(\varphi_{e}\) that occurs for a unity variation of \(l\). The same applies for \(\Delta\varphi\) in the calculation of \(\varphi\). In other words, it is a waste to calculate the inverse tangent with a grade of resolution higher with respect to the minimum that changes the result of the rounding in (8), namely \(\mathrm{int}\big{(}\frac{\varphi_{e}}{360^{\circ}}N\big{)}\). This reasoning ends in the following reference for evaluating the resolution \(\Delta\varphi\):  
\[\frac{\Delta\varphi_{e}}{360^{\circ}}N=1\ \Rightarrow\Delta\varphi_{e}=\frac{360^{ \circ}}{N}\Rightarrow\Delta\varphi=\frac{360^{\circ}}{N} \tag{9}\]  
Another useful constraint is that the approximation produces no error when the system is synchronized, so the lock condition is effectively maintained. Following the reasons discussed so far, we approximated the four-quadrant inverse tangent through a very simple linear relation that crosses the origin. As will be clearer in the following, the \"origin crossing\" grants the condition of no error in lock condition. Formally we have:  
\[\varphi=\mathrm{i}\mathrm{n}\mathrm{n}\mathrm{p}(x)=m\cdot x \tag{10}\]  
where \(\mathrm{i}\mathrm{n}\mathrm{n}\mathrm{p}(x)\) is the approximate inverse tangent function, and \(m\) is the value that minimizes the maximum error in the octant:  
\[\min_{m}\left\{\max_{x}\left|m\cdot x-\frac{180^{\circ}}{\pi}\mathrm{atan}(x )\right|\right\}\ 0\leq x<1 \tag{11}\]  
After some basic steps of mathematical analysis, here omitted for brevity, we obtain the following closed expression for \(m\) that minimizes (11):  
\[\frac{180^{\circ}}{\pi}\mathrm{atan}\left(\sqrt{\frac{\frac{180^{\circ}}{\pi} -m}{m}}\right)-m\left(\sqrt{\frac{\frac{180^{\circ}}{\pi}-m}{m}}\right)-m+45^{ \circ}=0 \tag{12}\]  
The numerical solution of Equation (12) is \(m\approx 47.7434^{\circ}\). In addition to the approximation of Equation (10) with \(m\) given by Equation (12), it is worth of considering also the further approximation of the solution of Equation (12) for \(m=45^{\circ}\). In fact, being \(45^{\circ}=360^{\circ}/2^{3}\), the hardware implementation of this second approximation is particularly efficient, as will be clarified in Section 4.3. Once the \(\mathrm{atan}(x)\) is approximated inside an octant, it is trivial to extend the result to the quadrant by applying \(\mathrm{atan}(1/x)=90^{\circ}-\mathrm{atan}(x)\), and then to the full four-quadrant co-domain by evaluating the signs of the I, Q components. The steps are the following:  
1. The octant is determined from the absolute values of I and Q (see Table 3, where octants are numbered in anti-clockwise order starting from 0\({}^{\circ}\));
2. We calculate (10) with \(\mathrm{x}=\mathrm{min}(11\,,\,|\,Q|\,)/\mathrm{max}(11\,,\,|\,Q|\,)\). This way we approximate the inverse tangent or cotangent depending on the angle behaving to an even or odd octant; referring the result to the zero octant (\(0\leq\varphi<45^{\circ}\));
3.