Spreading Factor and Coding Rate Allocation Method for LoRa Network

Aiming at the problems of frequent packet loss and high energy consumption in large-scale LoRa networks, this paper proposes a joint allocation method of Spreading Factor (SF) and Coding Rate (CR). Firstly, we establish the effect relationship of SF and CR on Frame Error Rate(FER), and pre-allocate SF and CR based on the node position to minimize the energy consumption of the node while meeting the FER requirement. Then, according to the collision model, the collision probability of each SF group is calculated, and the sequential water injection method is used to equalize the collision probability within each SF group, to improve the average packet arrival rate of the entire network. The simulation results show that compared to mainstream algorithms, the proposed algorithm obtains a 13% increment in terms of the network average packet success probability, and a 104% one in terms of the average energy efficiency. The proposed algorithm has high application value in many application scenarios such as smart agriculture and smart cities.


Introduction
LoRa is currently one of the most representative LPWAN technologies due to its low power consumption, wide coverage, multi-connection, and low-cost characteristics [1].A single LoRa gateway can provide coverage to thousands of nodes in a radius of several tens of kilometers, streamlining the network infrastructure and lowering the implementation cost [2][3][4].
As the transmission distance of LoRa continues to expand, the signal becomes very weak, and Data packets are prone to collisions, resulting in a sharp decrease in the Packet Success Probability (PSP) of data packets and frequent packet loss retransmissions [5].To improve the PSP performance of LoRa networks, scholars have proposed many effective parameter configuration methods.Overall, the current parameter allocation algorithms are mainly divided into two categories: 1) Adaptive Data Rate (ADR) algorithms for link quality perception [6]; 2) Conflict-aware ADR algorithms [7][8][9].The first type of algorithm does not consider the conflicts and collisions between packets, so its performance is poor in dense networks.Conflict-aware ADR algorithm considers the link quality of both the receiver and the sender and takes into account the collision of data packets, so it achieves higher PSP performance than the link-quality ADR algorithm.[9] proposed a collision-aware SF allocation algorithm, which can achieve high PDR under various network radii and communication loads.However, the algorithm only considered the allocation of SF and ignored the allocation of CR.In recent years, some literature has begun to pay attention to the CR of LoRa.[10] tested the impact of CR on energy efficiency, and simulation results showed that the energy efficiency difference under different code rates was up to 40%.The study only studied the mechanism of the impact of CR on FER and did not propose a rate adaptive scheme.
In response to the above issues, this article first analyzed the effect of CR on the PDR and energy efficiency of LoRa networks under the slotless ALOHA protocol, established the PDR and EE model, and designed an SF and CR adaptation method based on the joint perception of conflict and FER.

System model
In the LoRa star network, the LoRa gateway is located in the center of the network, and the terminal nodes are distributed around it.LoRa supports flexible physical layer parameter configuration, and terminal nodes can dynamically change the SF and CR of their transmitted signals to adapt to different link qualities.

PDR model
Whether the node's data packets can be delivered to the gateway normally depends on two conditions: 1) Whether the node's data packets collide with the data packets of other nodes; 2) The signal-to-noise ratio of the node signal reaching the gateway higher than the demodulation threshold of the receiver.Assuming that the probability of the data packet not colliding is nc p , and the probability of the signalto-noise ratio of the node signal reaching the gateway being higher than the demodulation threshold is ne p , the probability of successful delivery of the data packet is According to [11], the probability is that the data packets transmitted by node(i) do not collide with other nodes under the slotless ALOHA protocol.It can be expressed as where Ni represents the number of nodes with the same SF as node i, total T represents the transmission period, and ToA represents the air time of the data packet, which can be expressed as is the number of symbols generated by the preamble, s T is the symbol period, BW is the signal bandwidth, and payload n is the number of symbols generated by the load data, which can be expressed as payload 8 4 24 8 max 4 ,0 4 where PL is the length of the payload.
where SNR is the signal-to-noise ratio of the received signal, which can be expressed as 174 10log10 R SNR P BW NF (7) where R P is the received signal power, and NF is the receiver noise factor.By synthesizing Formulas ( 5) to (7), the LoRa demodulation error rate is obtained as LoRa uses Hamming code to improve the error correction capability of the physical layer.According to the error correction principle of Hamming code, the probability of no error in Hamming code codeword can be expressed as where L is the length of Hamming code, By synthesizing Formulas ( 8) to (10), we can calculate ne p .

2.2.Energy efficiency model
Assuming that the LoRa terminal node enters a sleep state immediately after transmitting data, the current during emission is 1 I .The duration is 3 T .The sleep current is 2 I .The energy consumption of the terminal node can be expressed as where V is the working voltage of the terminal.The energy efficiency (EE) of a terminal node is the number of effective bits transmitted per unit of energy, which can be expressed as

Joint Allocation Algorithm for SF and CR
The allocation of SF and CR should consider the constraints between node link performance and node energy consumption, comprehensively considering the performance of individual nodes and the overall network, ultimately maximizing the average energy efficiency of the network.

3.1.Elite Solution Selection for SF and CR
Figure 1 shows the FER curves of different CR for SF=7.It can be seen that the FER of CR=4/5 is near to the one of CR=4/6.A similar situation happened between CR=4/7 and CR=4/8.To Set the FER threshold value, the signal-to-noise ratio threshold value is r.Then we obtain the receiver sensitivity according to the formula, expressed as RSSI 174 NF 10log10 BW J .Using the same method, we obtain the sensitivity of other combinations of receivers.In addition, according to Formulas (2) and (3), the airborne time under 24 parameter combinations is obtained.The receiver sensitivity RSSI and air time ToA for 24 alternative SF and CR combinations are shown in Figure 2.
Analyzing the data in Figure 2, it can be seen that the signal air time of spread factor 7 is the shortest, only 1/35 of the signal air time corresponding to spread factor 12. According to the fairness principle within the collision probability spread factor group [7], the number of nodes assigned to spread factor 7 is the highest.Therefore, retaining four CR with an SF of 7 allows the algorithm to adjust parameters with the minimum granularity based on the distance between the node and the gateway, thereby effectively reducing the energy consumption of the node while ensuring reception sensitivity.
In addition, by observing the four combinations of sequence number 3 (SF=7, CR=4/7), sequence number 4 (SF=7, CR=4/8), sequence number 5 (SF=8, CR=4/7), and sequence number 6 (SF=8, CR=4/8), it can be seen that their reception sensitivity is not significantly different.However, the signal air time at a SF of 8 is nearly twice that at an SF of 7. If starting from the perspective of the node itself, the two combinations with an SF of 8 should be discarded.But it will result in an excessive number of nodes in the spread spectrum factor 7 group, increasing the probability of collisions within the group.Instead, it wastes the energy consumption of nodes.Therefore, considering the overall performance of the global network, a combination of SF 8 and CR 4/5 should be retained.In this way, within the group of SF 8, nodes closer to the gateway can allocate a CR of 4/5 to minimize the airborne time of the signal, thereby saving node energy consumption and reducing collision probability; For nodes far from the gateway, the CR of 4/7 can be allocated to ensure good link performance.Finally, considering that the reception sensitivity of the code rate 4/5 (4/7) and the code rate 4/6 (4/8) is not very different, selecting one of them can minimize the search space for the optimal solution and improve the Algorithmic efficiency.In summary, a set of elite solutions with SF and CR was ultimately selected, as shown in Table 1

Algorithm Flow
The core idea of the algorithm is to find the combination of SF and CR with the shortest air time, based on the constraint of meeting the receiving sensitivity of nodes, and predict the secondary allocation of collision probability in real-time to minimize the network collision probability.It minimized node energy consumption while ensuring link performance.The process is as follows: (1) Initialization: we initialize the radiant flux tx P of all nodes to the maximum value, and set the expected value of the average probability of successful data transmission in the network, then exp =1 p .We set the SF of all nodes to 7, the CR to 4/5, and the corresponding index number to zero.Then, =0,0 1 (2) Parameter preallocation: We use the path loss model to obtain the path loss vectors Li of nodes in the network, arranged in ascending order.According to the FER formula, we obtain the SF corresponding to the FER threshold and the reception sensitivity vectors Sj of 14 combinations in the rate candidate set, arranged in descending order.Based on the receiving sensitivity constraint conditions, the initial allocation of SF and CR is carried out, traversing each terminal node to find the minimum j that satisfies (3) Parameter allocation: We assign parameters to each terminal node in the network from near to far based on the distance between the node and the gateway, starting from where the terminal node number i is zero.We set the matrix cur i N s of the number of SF nodes to 0, that is ) Collision probability prediction: For terminal node i, the sensitivity constraint solution i k is obtained according to the mapping relationship in Table 1 to obtain the SF i s .If the number of nodes cur i N s is less than max i N s , it indicates that the collision probability within the group is less than the set threshold requirement.Then, it is determined to allocate i k to node i and let , and then we skip to step (6); If , it indicates that the sensitivity constraint solution selection does not meet the limit, and we skip to step (5).
(5) Parameter secondary allocation: We set indicates that there are still SFs and rate combinations with higher reception sensitivity available for selection.Therefore, we skip to step (4) to perform collision probability prediction again; If

¦
, there is a situation where the terminal node has not completed the allocation, proceeded with the parameter allocation of the next terminal node to find the optimal SF code rate combination.

Simulation results and analysis
In order to verify the effectiveness of the proposed algorithm, performance simulations were conducted using Matlab software, and the simulation parameters are shown in Table 2.

Comparison of performance between the fixed rate and dynamic rate algorithms
To demonstrate the effectiveness of dynamic rate algorithms, the performance of dynamic rate and fixed rate algorithms was simulated, as shown in Figure 3. From Figure 3 (a), it can be seen that compared to the fixed CR algorithm, the average PSP of the dynamic CR algorithm is significantly improved.When the number of nodes is 1000, the average PSP of the network increases by 13%.The dynamic CR algorithm fully utilizes the error correction ability of encoding and adaptively designs the CR of nodes at different positions.While ensuring good link performance and low collision probability of the node receiver, it shortened the airborne time of transmitting signals and effectively reduces the network collision probability.As the number of network nodes increased, the average PSP of dynamic CR increased significantly compared to the average PSP of fixed CR.The more nodes there are, the more severe the collision of data packets within the network is, and the better the effect of using dynamic bitrate algorithms is.In addition, the reduction of transmission signal air time effectively reduces the energy consumption of nodes, thereby significantly improving the average energy efficiency of the network, with an increase of up to 104%, as shown in Figure 3

Performance comparison of different algorithms
The performance of this algorithm compared to the current mainstream path loss-based SF allocation algorithm (PLB) and fair adaptive data rate (FADR) was shown in Figure 4.In terms of the average PSP performance of the network, the algorithm in this paper has improved by 5% to 18% compared to the PLB algorithm, and by 50% to 77% compared to the FADR algorithm.This was because compared to PLB only considering path loss and FADR only considering collision probability, the algorithm in this paper combined both the path loss of nodes and the overall collision probability of the network, thus achieving the highest average PSP performance.In terms of average network energy consumption, the PLB algorithm chose a larger SF to ensure the link performance of nodes, which has the highest energy consumption; The FADR algorithm did not consider the link performance of nodes at all, and only considered the fairness of air time within the SF group when allocating SF.The small number of SF group had the highest proportion and the lowest energy consumption.The algorithm in this article pursued a balance between node link performance and network collision probability, with energy consumption between the FADR algorithm and PLB algorithm.However, due to its advantage in average PSP performance, the network average energy efficiency of the algorithm in this paper has been still higher than that of the FADR algorithm.

Conclusion
For the slotless ALOHA protocol LoRa network, this paper proposed an SF and CR allocation method based on conflict and FER joint sensing.This method fully considered the influence of various parameters on the average PSP and energy efficiency of the network and established a complete mathematical model for the average PSP and energy efficiency of the network.By utilizing the orthogonality of SF and analyzing the constraint relationship between SF and CR on airborne time and reception sensitivity, the poorly performing parameter combinations were eliminated, reducing the complexity of subsequent parameter allocation algorithms.Based on pre-allocation, conflict prediction is carried out, and the sequential water injection method is used to iteratively adjust the number of nodes allocated by SF, reducing the overall collision probability of the network.The simulation results show that compared to the fixed CR algorithm, PLB, and FADR algorithms, the proposed algorithm has a higher network average PSP and energy efficiency.

T
is the preamble time, payload T is the duration of the load data, preamble n

Figure 1 .
Figure 1.FER curves at different CR Figure 2. Receiving Sensitivity and Aerial Time of SF and CR Combined Solutions number of nodes max N that the SF i s can tolerate based on the expected value exp p of the successful transmission probability of the data packet,

14 ik( 6 )
! , it indicates that no combination can meet all the current constraints, so the expected value exp p of the average packet success transmission probability of the network is reduced, then exp exp 0.01 p p, and the parameter allocation is restarted in step (3).We determine whether all terminal nodes have completed allocation.all terminal nodes have completed allocation, and then we output the parameter allocation results of all terminal nodes, and the algorithm ends; (b).

Figure 3 .
Performance Comparison between Dynamic CR and Fixed CR Average PSP (b) Average energy consumption (c) Average energy efficiency Figure 4. Performance Comparison of Different Algorithms

Table 1 .
. SF and CR Elite Solutions