# Narrowband-Internet of Things Device-to-Device Simulation: An Open-Sourced Framework
## 3 NB-IoT D2D Framework, Model, and Simulation
### Channel Propagation Models  
The most important IoT signal quality parameters are SINR, Signal-to-Noise Ratio (SNR), and path loss. Thus, we studied the SINR of NB-IoT, demonstrating its relatively high interference immunity compared to e.g. Sigfox and LoRa. Additionally, we simulated the path loss model of NB-IoT in terms of a microcell, a macrocell of an urban area, and a macrocell of a rural area. This NB-IoT D2D framework involves two types of path loss models. First, the path loss between CH and BS (i.e., long range transmission), which was simulated based on [17; 19; 20; 37; 38]. Second, the path loss between NB-IoT D2D nodes (i.e., short range transmission between the CH and the respective associated cluster nodes), that was simulated based on [24; 31; 33; 39; 40]. The MAC layer verifies whether frames have been received correctly. The communication data link between CHs and BSs is attenuated following the used path loss / propagation models. Figure 4 depicts (a) an NB-IoT downlink OFDMA frame structure and (b) an NB-IoT uplink SC-FDMA frame structure. However, the procedure is decided based on the cell scenario of the intended application. For instance, the path loss pattern of a microcell scenario between CHs and BSs for smart homes, smart devices, and industrial applications is shown in (2) while between NB-IoT D2D nodes is presented in (3):  
\[PL_{CH-BS}=24+45\ log_{10}\ (d_{eNB}+16) \tag{2}\]  
\[PL_{D2D}=\ G_{Rx}+G_{Tx}+PTX_{j}+\ \bigg{[}4\ \times\ 10\ log_{10}\bigg{(} \frac{6}{4\times\pi\times d_{CH-N}}\bigg{)}\ \bigg{]}. \tag{3}\]Equation (4) illustrates the path loss pattern of an urban macrocell between CHs and BSs for smart cities and suburban areas with smart grids, whereas (5) shows the path loss pattern of an urban macrocell between the CH and the respective associated cluster nodes:  
\[PL_{CH-BS}=103.8+37.6\ log_{10}(d_{eNB}) \tag{4}\]  
\[PL_{D2D}=\ G_{Rx}+G_{Tx}+PTX_{j}+\ 2.7\ \times\ 10\ log_{10}\bigg{(}\frac{3.5}{4 \times\pi\times d_{CH-N}}\bigg{)}. \tag{5}\]  
The path loss formula of the rural macrocell, between CHs and BSs, which can be used for smart-farms and wind turbine parks, is demonstrated through (6). And, the path loss formula of the rural macrocell, between NB-IoT D2D nodes is given through (7):  
\[PL_{CH-BS}=96+34.1\ log_{10}(d_{eNB}) \tag{6}\]  
\[PL_{D2D}=\ G_{Rx}+G_{Tx}+PTX_{j}+\ 2\times\ 10\ log_{10}\bigg{(}\frac{2}{4 \times\pi\times d_{CH-N}}\bigg{)}. \tag{7}\]  
Figures 5, 6, and 7 depict the path loss model for a given BS in the microcell, urban macrocell, and rural macrocell scenarios, respectively. The MAC layer reflects the technical features of the channel associated with NCH and CH or CH and BS. In the NB-IoT attocell network simulation, the Maximum Coupling Loss (MCL) of the three coverage zones is 144, 155, and 164 dB. The uplink coverage class uses SC-FDMA with a subcarrier spacing of 3.75 or 15 kHz, while the downlink coverage class applies OFDMA with a subcarrier spacing limited to 15 kHz. Moreover, the data transmission rate for uplink coverage classes ranges between 160 and 200 kbits/s, whereas the data transmission rate for downlink coverage classes ranges between 160 and 250 kbits/s [17]. The effective bandwidth was calculated, and the frequency factor \(f\) was considered for the purpose of enhancing the SNR as follows [17]:  
\[BW\ =\ \frac{180,000\ \mathrm{Hz}}{f},\ \mathrm{where}\ f\ =\ \frac{12}{\ Tones} \tag{8}\]  
\[NsSpctrldnsty\ =\ Nsfigr\ \times\ N_{0} \tag{9}\]  
\[TxSpctrlDnsty\ =\ PRX_{i,j}\ \times\ BW^{-1},\mathrm{where}\]  
\[Reception\ power\ of\ equipment\ i\ for\ subchannel\ j \tag{10}\]  
\[PL_{D2D}=\ G_{Rx}+G_{Tx}+PTX_{j}+\ \bigg{[}4\ \times\ 10\ log_{10}\bigg{(} \frac{6}{4\times\pi\times d_{CH-N}}\bigg{)}\ \bigg{]}. \tag{3}\]0  
\[PL_{D2D}=\ G_{Rx}+G_{Tx}+PTX_{j}+\ \bigg{[}4\ \times\ 10\ log_{10}\bigg{(} \frac{6}{4\times\pi\times d_{CH-N}}\bigg{)}\ \bigg{]}. \tag{3}\]1  
The SNR for a given BS in the microcell, urban macrocell, and rural macrocell scenarios is presented in Figures 8, 9, and 10, respectively.