# Performance Analysis of Time Synchronization Protocols in Wireless Sensor Networks
## 5 Evaluation Result
### Effect of Message Delay Jitter
#### 5.1.2 Enhanced FTSP (E-Ftsp)  
To prevent unnecessary adjustment of the compensated drift, we propose a mechanism to control the drift compensation process. The primary concept is that the nodes will decide whether they must compensate for clock drift whenever they receive a timing message. To implement this concept, the procedure to handle a received message with a newly defined variable _estimatedDelay_ is as below:  
* If _offsetError_ is smaller than _estimatedDelay_, the nodes will regard the previous compensated drift as sufficient and a recalculation will not be performed. In this case, the node must only compensate for the offset (see lines 3-5 in Algorithm 1). * Meanwhile, if _offsetError_ is larger than _estimatedDelay_, the nodes must calculate and compensate for the clock drift and clock offset using the algorithm of the original FTSP (see lines 7-9 in Algorithm 1). This modification allows the nodes to skip updating the compensation of the clock drift if the offset error is trivial (smaller than _estimatedDelay_). Therefore, the nodes can reduce the skew fluctuation and computation overhead. Figure 4b shows that the difference between the relative skews of the nearest node and the farthest node with the reference node is insignificant after applying the proposed concept. Figure 4: Relative skew of nearest node and farthest node with reference node in (**a**) FTSP and (**b**) E-FTSP with grid topology (\(7\times 7\)). To calculate _estimatedDelay_, we first analyze how FTSP stores the timing message in the regression table. Table 2 shows the regression table, where the offset error of node \(i\) is calculated as:  
\[O_{i}(t)=L_{j}(t)-h_{i}(t) \tag{3}\]  
where \(L_{j}(t)\) is the global clock value included in the message from node \(j\), and \(h_{i}(t)\) is the hardware clock value of node \(i\). Assuming that the clock drifts of nodes \(i\) and \(j\) remain constant in the short-term (several messages), the difference in hardware clock \(h_{i}(t_{n})-h_{i}(t_{n-1})\) should be constant if the messages are sent periodically. Subsequently, the difference between two continuous messages \(O_{i}(t_{n})-O_{i}(t_{n-1})\) should theoretically be constant. However, because of message delay jitter, the value of \(O_{i}(t_{n})-O_{i}(t_{n-1})\) varies. Therefore, (3) becomes  
\[O_{i}(t)=L_{j}(t)-h_{i}(t)+\sigma(t) \tag{4}\]  
where \(\sigma(t)\) is a random delay in message delivery. Although the value of \(\sigma(t)\) varies each time the message is sent, the maximum value of \(\sigma(t)\) can be calculated as  
\[max_{\sigma}=\frac{max\big{(}O(t_{n})-O(t_{n-1}):n\in\{1...N\}\big{)}}{2} \tag{5}\]  
where N is the number of entries in the regression table and \(max_{\sigma}\) is the _estimatedDelay_ value. Figure 5 shows the average _estimatedDelay_ value of nodes that have the same hop distance to the reference node. The maximum delay in message delivery is 5 us. The proposed protocol can estimate the maximum delay exactly with nodes that are received directly from the reference node (hop 1), and _estimatedDelay_ slightly increases with further hops. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Index** & **Local Time** & **Offset** \\ \hline
1 & h(\(t_{1}\)) & O(\(t_{1}\)) \\
2 & h(\(t_{2}\)) & O(\(t_{2}\)) \\
3 & h(\(t_{3}\)) & O(\(t_{3}\)) \\
4 & h(\(t_{4}\)) & O(\(t_{4}\)) \\
5 & h(\(t_{5}\)) & O(\(t_{5}\)) \\
6 & h(\(t_{6}\)) & O(\(t_{6}\)) \\
7 & h(\(t_{7}\)) & O(\(t_{7}\)) \\
8 & h(\(t_{8}\)) & O(\(t_{8}\)) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Regression table of a node. In addition to calculating _estimatedDelay_ automatically, it is possible to predefine the value of this variable. In a homogeneous WSN, the maximum and average delays can be obtained through experiments and manually configured in the software. This allows for the complexity of the algorithm to be reduced while maintaining the efficiency of the proposed protocol. We continue the first scenario by comparing the performances of E-FTSP, FTSP, and GTSP in the presence of message delay jitter.