# MAC/PHY Comprehensive Visible Light Communication Networks Simulation
## 4 Proposed Simulation Scheme
### Channel Simulation  
MCRT allows the evaluation of the impact of surrounding objects in indoor scenarios such as walls, furniture, or even other users on the communications link. In this work, a Modified MCRT (MMCRT) has been used [8]. The algorithm randomly generates a set of rays from a light source following the radiation pattern as the probability density function. These rays travel through the room impinging on the scenario's surfaces. After each rebound, a forced contribution is calculated and the rest of the energy is scattered taking into account the reflection pattern. The developed channel simulation tool receives a triangularized mesh file of the scenario (.obj file), and a table relating each material with its reflection pattern. The simulator has been divided into three main parts: Pre-processing, MMCRT calculation, and post-processing. During the pre-processing stage, an OCTREE (octal tree) structure is inflated using the triangularized mesh file that describes the scenario's geometry. The use of this structure enhances impact calculation performance, since it implements a logarithmic-complexity search algorithm. The MMCRT stage carries out the calculation of the ray contributions on each target point, using Equations (5) and (6) for the LOS and NLOS contributions:  
\[h(t,\hat{n}_{imp})_{LOS}=P_{tx}(\theta_{LOS},\varphi_{LOS})\frac{1}{d_{LOS}^{2 }}\delta\left(t-d_{LOS}/c_{0}\right)\cdot\hat{n}_{LOS}. \tag{5}\]  
\(\theta_{LOS}\) and \(\varphi_{LOS}\) are the ray emission angles from the transmitter's reference, whilst \(\hat{n}_{LOS}\) is the direction vector of the LOS ray. \(c_{0}\) is the speed of light, and \(d_{LOS}\) is the LOS link range:  
\[h(t,\hat{n}_{imp})_{NLOS}=\frac{1}{N}\sum_{i=1}^{M}R_{K(i)}\left(\theta_{i,K(i )},\varphi_{i,K(i)}\right)\delta\left(t-\sum_{j}d_{j}/c_{0}\right)\cdot\hat{n} _{i,K(i)}\prod_{j=1}^{K(i)}\frac{\rho_{j}}{d_{j}^{2}}\frac{1}{L}. \tag{6}\]  
The \(M\) arriving rays that conform to the NLOS contribution of the Channel Impulse Response (CIR) suffer from a different number of rebounds. Each random ray is weighed by a number of random directions generated on each rebound. \(N\) rays are generated at the transmitter and \(L\) after each impact. Since an emphasized random sampling scheme is used in MMCRT, the radiation pattern only has to be taken into account on the forced contributions. \(R_{K(i)}(\theta_{i,K(i)},\varphi_{i,K(i)})\) is the reflection pattern of the \(i\)-th ray's last rebound \(K(i)\) at the corresponding angles. Finally, \(\rho_{j}\) is the reflectivity of the \(j\)-th surface, and \(\hat{n}_{i,K(i)}\) is the direction of the last rebound (surface-to-receiver). Nevertheless, the obtained response does not take into account the receiver optics since it only stores the impact angle, power, and flight time. Hence, the result is a tensor that defines an angle-dependent impulse response \(h(t,\hat{n}_{imp})\), where \(\hat{n}_{imp}\) is the impact direction vector. Finally, during the post-processing stage the tensor-like impulse response is projected into a time-power signal using the description of the receiver optics and its attitude (Equation (7)):  
\[h(t)=A_{pd}G_{lens}\int h(t,\hat{n}_{imp})\cdot\hat{n}_{rx}\,\Theta\left( \hat{n}_{imp}\cdot\hat{n}_{rx}-\cos(FOV/2)\right)\ \mathrm{d}\hat{n}_{imp}. \tag{7}\]  
\(A_{pd}\) is the receiver's active area, \(G_{lens}\) is the lens gain, and \(\Theta\) is [PERSON]'s theta. In essence, the effective area of each impact is calculated taking into account the receiver's attitude \(\hat{n}_{rx}\), and those rays outside the receiver's FOV are neglected. The proposed three-stage algorithm provides improved flexibility, since time-variant receiver attitude (due to head movement, e.g.,) can be considered without executing the whole time-consuming algorithm again. Among the channel parameters that the impulse response provides, DC channel gain \(H(0)\) and bandwidth \(B\) are the most relevant, since they define the quality of the assumed linear system.