# FL-LoRaMAC: A Novel Framework for Enabling On-Device Learning for LoRa-Based IoT Applications
## 6 Results and Discussions
### Performance Study of FL-LoRaMAC
#### 6.2.2 Model Training Time with FL-LoRaMAC  
The time duration for computing gradient updates during the training phase was measured experimentally and the communication time was calculated mathematically for the training hyperparameters used. With these, the total training time was calculated as follows:  
\[T_{Train}=T_{DU}+N*(T_{C}+T_{Up}+T_{FAU}+T_{D}) \tag{4}\]  
In (4), \(T_{DU}\) is the average time taken by the server to transmit all the untrained global model parameters, \(N\) is the number of communication rounds used, \(T_{C}\) is the average time taken to compute local model updates, \(T_{Up}\) is the average time taken by end devices to transmit local updated model parameters, \(T_{FAU}\) is the average time taken by the federated averaging algorithm to compute the updated global model from local updates, and \(T_{D}\) is the average time taken to transmit the updated global model parameters.  
All calculations for communication time were made considering a spreading factor of SF-7. The same can be calculated if other spreading factors were to be used. To calculate communication time, the total number of model parameters that need to be communicated was determined. The model has 635 parameters, which equates to 2540 bytes. Each fragment was considered to be 28 bytes long. Hence, there were 91 fragments that need to be communicated from each end device in each communication round. Considering that each end device transmits one packet every 60 s, \(T_{Up}\) was calculated to be 5460 s.  
The size of the frame was chosen to be 28 bytes based on the fact that LoRa technology in the U.S. has a dwell time restriction of 400 millis. When SF-10 is used, the duration of a 28 bytes packet is 400 millis. Hence, the size of the fragment was chosen to be 28 bytes for the simplicity of implementation with other SFs. Note that when lower spreading factors are used, more data can be sent in one packet. However, a longer packet means a higher probability of collision when there are multiple devices transmitting, which is the case during end devices sending local updates.  
When the global model is sent by the server, only one gateway will be transmitting. Hence, the maximum number of bytes that can be packed in a packet can be sent more frequently, with a negligible probability of packet loss due to collisions. Assuming that the gateway transmits using SF7, each packet can have 200 bytes with 100 ms of the preamble. Hence, the gateway can send all 635 parameters with 13 packets, transmitting 1 packet every 10 s. Considering that no packets are lost during transmission, \(T_{DU}\) as well as \(T_{D}\) will be 130 s.  
The values of \(T_{C}\) and \(T_{FAU}\) were measured to be 4.95 s and 0.016 s, respectively. By putting all the values in Equation (4), the total training time in s was calculated to be 16914.9 s, or 4.7 h:  
\[T_{Train}=130+(3*(5460+130+4.95+0.016))\;\text{s} \tag{5}\]  
Note that the communication of model parameters takes the most time during the training phase. The training time can be reduced if the number of communication rounds is reduced; however, doing so will deteriorate the performance of the model as shown in Table 5. This trade-off can be exploited depending on the nature of the application.