# Adaptive Parameters for LoRa-Based Networks Physical-Layer
## 3 Proposal
### SlidingChange: A Proposal of a Sliding Window for Automatic Parameter Changing  
The proposed _SlidingChange_ algorithm comprises two different stages: (i) the data transmission step and (ii) the network control step. In the first stage, a sequence of messages is sent by the secondary nodes trying to reach the primary node. The only goal of doing that is to record SNR values in the network during an instant \(t\) (represented by a call to **sendDataPacket0 function** in the Algorithm 2). After reaching a predefined amount of messages, the system starts the control stage. While in this step, the primary node sends some messages containing the next configuration to be tested and then waits for an answer from the secondary nodes. The configuration parameters consist of \(SF\), \(BW\) and \(F_{carrier}\) (carrier frequency). The answer must come with the previous configuration and, after a previously set time frame (set by the primary node), every device changes its configuration. This process repeats itself until all the possible configurations are fully tested. With these data, the primary node computes an SNR sliding window value using the secondary nodes' responses compared with other configurations to decide on changing or not the carrier frequency parameter. Even if the algorithm changes the parameters, the scanning process keeps testing all possible configurations because, in the future, the discarded parameters could become the optimal ones again, and it would be possible to reanalyze these data. This study observed the behavior of the sliding window algorithm, which considered the SNR values obtained from the data packets. The configurations considered were those with windows of length equal to \(W=10,\ 20,\ 30\), and 40 samples because it was desired to compare the different window lengths. Figure 4 presents the operating principle of the sliding window, which can also be seen on Algorithm 3. ```
1:\(\alpha\leftarrow\) 0.1:\(\alpha\leftarrow\) 0.2:\(\alpha\leftarrow\) 0.3:\(\alpha\leftarrow\) 0.4:\(\alpha\leftarrow\) 0.5:\(\alpha\leftarrow\) 0.6:\(\alpha\leftarrow\) 0.7:\(\alpha\leftarrow\) 0.8:\(\alpha\leftarrow\) 0.9:\(\alpha\leftarrow\) 0.1:\(\alpha\leftarrow\) 0.1:\(\alpha\leftarrow\) 0.2:\(\alpha\leftarrow\) 0.3:\(\alpha\leftarrow\) 0.4:\(\alpha\leftarrow\) 0.5:\(\alpha\leftarrow\)
```
1\(F=\{433,915\}\)// Carrier frequencies
2\(SF=\{11\}\)// Spreading factor
3\(BW=\{125\}\)// Bandwidth
4\(W=W_{0}\)// Slimding window length
5 samples\({}_{433}[W]\), \(samples_{155}\leftarrow\{0\},\{0\}\)
6\(\gamma\gets 9\)// Number of data packets to be sent
7 whileexist packet to be sent do
8 ifcontrol\(<\gamma\)then
9 control\(\leftarrow\)control\(+1\);// Spreading factors
10 sendDataPacket()
11 else
12\(control\gets 0\)
13\(samples_{433}\leftarrow\)slidingWindow\((W,samples_{433})\)
14\(samples_{915}\leftarrow\)slidingWindow\((W,samples_{915})\)
15\(avg_{433}\leftarrow\)movingAverage\((W,samples_{433})\)
16\(avg_{915}\leftarrow\)movingAverage\((W,samples_{915})\)
17 if\(avg_{433}>avg_{951}\)then
18 setFrequencyTo433()
19 else
20 setFrequencyTo915()
21 endif
22 endif
23 endwhile
```
**Algorithm 2**Moving average in cognitive LoRa. The process described above is detailed in Figure 4. Figure 4 presents the first step of the sliding window parameter change solution. The samples \(C_{1}\), \(C_{2}\), and \(C_{3}\) are added to the sliding window, the sample \(C_{0}\), which is part of the window, is discarded, and other samples will be collected (future samples). In practice, they were not recorded on the system memory yet. In the second step, illustrated in Figure 4, a newer sample \(C_{4}\) arrives at the micro-controller and the window is moved to the left, writing this sample in the data set and discarding the sample \(C_{1}\). Then, this process repeats in the third step as shown in Figure 4.

Figure 4: Sliding window operating principle within the scope of this proposal. (**a**) Stage 1: First window state in a given time. (**b**) Stage 2: Window state when an element was discarded.