A Group Neighborhood Average Clock Synchronization Protocol for Wireless Sensor Networks

Clock synchronization is a very important issue for the applications of wireless sensor networks. The sensors need to keep a strict clock so that users can know exactly what happens in the monitoring area at the same time. This paper proposes a novel internal distributed clock synchronization solution using group neighborhood average. Each sensor node collects the offset and skew rate of the neighbors. Group averaging of offset and skew rate value are calculated instead of conventional point-to-point averaging method. The sensor node then returns compensated value back to the neighbors. The propagation delay is considered and compensated. The analytical analysis of offset and skew compensation is presented. Simulation results validate the effectiveness of the protocol and reveal that the protocol allows sensor networks to quickly establish a consensus clock and maintain a small deviation from the consensus clock.


OPEN ACCESS
In some of the applications, such as data fusion, target tracking and speed estimation, the system needs to have the knowledge of time among sensor nodes in order to determine the timing of the event. This is realized by clock synchronization (sometimes called time synchronization). Besides the application requirement, clock synchronization is important to avoid interference if the medium access control protocol uses time division medium access (TDMA) [6,7]. For the networks that utilize duty-cycling schemes and turn off the radio for energy saving, accurate time helps to save energy by shortening the necessary guard time.
Imperfections in low-cost sensor nodes will cause offsets and skew drifts. Environmental factors such as the temperature also contribute to this clock shift. Therefore, the sensors will lose synchronization with other sensor nodes. This leads to the meaninglessness of sensing data for many applications. Clock synchronization techniques are therefore needed to synchronize the sensor nodes in WSNs. The algorithms compensate the offset and skew rate by exchanging information among sensor nodes. There are several challenges to design a clock synchronization algorithm. First, since the information is shared among sensor nodes by passage exchanging, propagation delays would cause inaccuracy of time instant sharing, so a specific compensation technique is required. Second, because the sensor nodes are densely deployed in the monitoring area, the nodes can only communicate with the sink node via a multi-hop route. Designing an accurate, fast convergence and scalable global clock synchronization algorithm becomes a challenge. Third, the sensors are inexpensive devices, which may often incur failure. A dynamic and robust scheme is needed. Fourth, since sensor nodes are almost always powered by batteries, energy efficiency becomes one of the major concerns. These challenges need to be addressed in the design of any clock synchronization protocol.
In this paper, a novel distributed clock synchronization scheme, named group neighborhood averaging (GNA), is presented. It is a fully distributed, network-wide clock synchronization algorithm. Two-way communication is adopted to estimate the propagation delay and further used for offset and skew rate compensation. Without extra data exchange, just using the exchanged messages, the algorithm takes average of the offset and skew rate value among the neighboring nodes within the transmission range. The group-averaging algorithm leads to a fast convergence.
The rest of this paper is organized as follows: Section 2 discusses related work. Section 3 presents the system model and Section 4 explains the proposed GNA algorithm. Simulation results are given and discussed in Section 5. Section 6 concludes the paper and describes possible future work.

Related Work
Many dedicated strategies and protocols have been proposed to address the problem of clock synchronization in WSNs in the past decades as surveyed in [8][9][10][11]. The Network Time Protocol (NTP) [12] is one of the popular clock synchronization protocols in use. It adopts a hierarchical tree of timeservers. By recording the sending and receiving timestamps, the propagation delay is estimated. The time is then compensated using this value. NTP is not suitable for WSNs for two main reasons. First, it takes long time for the entire network to synchronize to the reference clock. Second, the accuracy is low and the complexity is relatively high. Reference Broadcast Synchronization (RBS) [13] uses a node to send a reference broadcast beacon to neighbors in the physical layer. The receivers exchange the time of arrival and compensate their own clocks. The advantage is that RBS shortens the critical path since the broadcast beacon is only used as a reference. The potential drawback lies that the exchanges of time of arrival between the neighbors incur a large overhead and the performance may decrease in large-scale multi-hop networks. In [14], by recording the sending and receiving time of the probe message, the bounds of the relative offset and drift can be obtained and then the relative offset and relative drift are estimated. It is simply a computational task. The algorithm is based on a tree topology network and the sensor nodes only synchronize with their parent fusion nodes. The disadvantage of the protocol is that it is designed only for a tree topology network, not a mesh network which is more common. Another problem is that if synchronization were required for the entire network, the convergence time would be very large. Timing-sync protocol for sensor networks (TPSN) [15] and recursive time synchronization protocol (RTSP) [16] have similar solutions. The protocols periodically elect a root node, which acts as reference clock. Root node rotation balances the energy consumption among all the sensor nodes. A tree architecture is formed for clock synchronization. A similar NTP algorithm, which uses four time stamps to estimate the propagation delay, is adopted. The disadvantage is that the level discovery phase consumes quite a large amount of energy and time, which leads to slow convergence. In addition, due to the hierarchical topology, the protocol is prone to node failure. The flooding time synchronization protocol (FTSP) [17] also randomly elects a root node, but for time synchronization, either single hop or multi-hop, FTSP adopts one way synchronization. The message delivery delay is decomposed into interrupt handling of CPU, encoding and decoding of radio chip to transform the message, byte alignment of radio chip at the receiver side and the propagation delay. The time stamping effectively reduces the error introduced by interrupt handing, encoding and decoding. Compared to them, propagation is relatively small and neglected. Time-diffusion synchronization protocol (TDP) [18] uses NTP-like information exchange and spreads the reference time to the whole network. The performance is good, but the algorithm is complicated and not energy efficient. In summary, for tree hierarchical clock synchronizations, the disadvantages include slow convergence, energy waste and complexity of root node election, proneness to node and link failure and difficulties for mobile scenarios.
Distributed consensus-based protocols for global clock synchronization have been proposed in [19][20][21][22][23]. In [21], local synchronization is conducted by averaging the offset and finally the entire network converges to a virtual consensus clock, but only clock offset is compensated. Clock drift is not discussed. References [19] and [22] consider both offset and clock drift compensation. Each node periodically broadcasts a synchronization beacon. The receiving node takes an average of the offset and drift. The solution is fully distributed without the need of a root node. All nodes run the same algorithm. The protocol is robust to dynamic ad-hoc networks issues such as node and link failure. In [20], the algorithm is further improved. A confidence weight parameter is introduced for the average calculation. The node, which has conducted an averaging calculation, would be given a big weight. In [23], the protocol adopts max consensus to compensate for clock drift but the reason is not clearly presented. One limitation in the works presented in [19][20][21][22] is that the protocol is designed in the absence of propagation delay. However, the propagation delay is a very important issue, which cannot be ignored in real clock synchronization scenarios. Another limitation is that they take averaging only between one sender and one receiver at each time. This leads to a slow convergence. The authors of [24] use a group average and assume the propagation delay follows Gaussian distribution. However, the algorithm only achieves good performance when the network is time delay balanced. The reason is that the averaging operation for a Gaussian distributed delay approaches zero. This method would not be suitable for an unbalanced network. [25] considers both fixed and random propagation delays and proposes a distributed synchronization algorithm. By using the maximum likelihood estimation and belief propagation on graphical models, global clock synchronization is achieved. [26] improves it and proposes an asynchronous algorithm. Different nodes could update their estimates based on different frequencies. For these two methods, the algorithms are relatively complicated and need more storage and computational resources.
This paper proposes a fully distributed, network-wide clock synchronization scheme. The scheme is scalable and not constrained to a certain network topology. It is also robust to node failure. Two-way communication is adopted to estimate the propagation delay. The exchanged messages are multiply used for offset and skew rate compensation. Nodes take turns to ask their neighbors for clock information. Then they average all the received offset and skew rate values in each round and broadcast the values back to their neighbors. A fast convergence is achieved by the proposed group-averaging algorithm. The procedure of the algorithm is clearly presented. It has the advantages of accuracy, fast convergence, low complexity and easy implementation. The main contributions of this paper are: (1) Group averaging is used instead of point-to-point averaging for faster convergence.
(2) Propagation delay is compensated compared with several important related papers.
(3) Minimum data exchange is achieved for both offset and skew rate compensation, and at the same time the propagation delay is considered and compensated.

System Model
A typical WSN is composed of tens, hundreds or even up to thousands of sensor nodes which are deployed in an ad-hoc fashion without careful planning, as shown in Figure 1. The sensor nodes collect and transmit the sensing data to a sink node. The sink node stores and processes the data. As discussed in Section 1, the sensor nodes need to store the time instants of the data collection so that later the sink node can aggregate and process the data from different sensor nodes. Therefore, the requirement that all the sensor nodes strictly keep a common clock becomes essential. For each sensor node, we define the clock model as Equation (1). ( ) is the clock reading at time t. α is the skew rate and β is the offset. In the ideal situation, α is equal to 1 and β is equal to 0: The clocks in the sensor network may not be consistent for several reasons. First, the clock may drift, which can be caused by the manufacture of the oscillator components. Second, the clock could change due to some environmental condition such as temperature, pressure, battery voltage, etc. Third, the clocks from different sensor nodes may not be synchronized well at the beginning of the network deployment. All these reasons lead to clock readings varying from the real value. The clock reading ( ) of node i is then expressed in Equation (2): The aim is to find the compensated α � and β � , so as to make the compensated clock (̂( ) expressed in Equation (3)) to converge to a consensus clock ( ) (as shown in Equation (4)): Consensus clock is a virtual clock within the sensor network. For most WSN applications, there is no need for the clocks of sensor nodes to converge to the real clock. Take speed estimation as an example. As long as all sensor nodes are synchronized, they can successfully locate the target, and therefore successfully estimate the moving speed. In this case clock synchronization to a virtual clock is enough.  Figure 2 shows an example of offset and skew rate compensation. In Figure 2a, before clock synchronization, Node 1 and Node 2 have different offset and skew rates. For offset compensation, clock readings "2" for Node 1 and Node 2 are not aligned. For skew rate, it is equal to the multiplication of tick duration, , and counter limit, , as shown in Equation (5). Either different or different could make the two nodes have different α : After clock synchronization, as shown in Figure 2b, Node 2 is synchronized to Node 1. For offset compensation, the two nodes align the start time of the clock reading "2". For skew rate compensation, Node 2 adjusts its counter limit to make the clock duration equal to that of Node 1. It should be noted that only the counter limit can be adjusted by users. Tick duration is a natural property of the oscillator and therefore cannot be modified.

The Proposed GNA Algorithm for Clock Synchronization
The GNA algorithm includes two parts: offset compensation and skew rate compensation. They are realized by clock exchange and computation. The clocks of the sensor nodes will eventually converge to a consensus clock. One thing that should be noted for clock exchange among sensor nodes, is that the propagation delay incurs errors and this leads to inaccuracy. This will be compensated by two-way message exchange.

Propagation Delay Model
The signal transmission from one node to another experiences a propagation delay. This delay would cause the inaccuracy for clock synchronization between two nodes [15][16][17]. The idea for compensating this propagation delay is using two-way message exchange. As shown in Figure 3, Node 2 asks Node 1 for time. Node 2 records the time instant t 1 , when it sends message. Node 1 receives the message and records the instant t 2 . Then Node 1 returns the time information message and records the time instant t 3 . Node 2 receives it and keeps the time instant t 4 . Using these four time instants, Node 2 would estimate the propagation delay using Equation (6). Then it can compensate for the time offset. In the remainder of this paper, all the message exchanges adopt two-way message exchange. This is minimum information exchange for propagation delay estimation.

Offset Compensation
Offset compensation is to make the sensor nodes to align at a common value of time. It is equivalent to obtaining β � to satisfy Equation (4). We expand it as illustrated in Equation (7): We have: Since sensor networks normally have a large number of sensor nodes covering a relatively big area, is impossible for a certain node to directly communicate with all the nodes in a single hop way. Therefore, local information exchange and averaging is used in this algorithm. The nodes take turns to collect time information from their neighbors and take an average of the collected time information and their own value. The result is estimated as the consensus value of the node and neighbors. The algorithm of offset compensation is presented as below: Step 1: Periodically sense the channel, if the channel is clear, then broadcast a requesting packet to ask the neighbors within its transmission range for the clock information.
Step 2: The neighbors return the clock values.
Step 3: Compensate for the propagation delay Step 4: The node calculates the average offset of all the neighbors as well as itself.
Step 5: Update its own offset value.
Step 6: Broadcast the compensation table. The table includes node ID and compensated offset.
Step 7: The neighbors receive the table and update their own clock offset.
In this paper, 2-node offset averaging which is used in [19][20][21][22] is replaced by group neighborhood averaging with propagation delay compensation. As shown in Figure 4, it is assumed that Node 1 is the randomly selected node which synchronizes neighboring nodes. In Figure 4a, 2-node offset averaging is realized by broadcasting the synchronization message. Node 2 and Node 3 receive this message and calculate the average of the offsets of Node 1 and themselves. In this model, the propagation delay is ignored. The three nodes obtain different clock values and the deviation of errors becomes smaller. This method is used in [19][20][21][22]. In Figure 4b, two-way message exchange is adopted to compensate for the propagation delay between two nodes. Node 1 broadcasts a request message and records the time instant. Assume Node 2 replies earlier. Node 1 takes the average of Node 1 and Node 2's offsets. Then Node 1 sends the clock and propagation delay information to Node 2. Node 2 is synchronized with Node 1. Next Node 3 follows the same procedure. In this scenario, Node 1 needs to send different synchronization messages to every neighboring node, and these nodes do not converge to a single clock. In Figure 4c which is proposed by this paper, Node 1 waits to collect all the clock information from neighboring nodes. It calculates the propagation delay and takes the group average among all the nodes. In this way, an accurate, fast offset convergence is achieved. It should be mentioned that because there are three time message exchanges between the randomly elected node and its neighbor, one can use the first two message exchanges to estimate and compensate the propagation delay. There is no extra information exchange needed, therefore minimum information exchange is adopted for both propagation delay compensation and offset compensation.
Next, it will be shown that the algorithm of offset compensation achieves global synchronization throughout the entire network. As defined in Section 2, β is the offset value of node i. It can be obtained as below: The offset values of all the sensor nodes in the network converge to certain value.
Proof. Assume that β 0 and β 0 are the maximum and minimum offset values among all the sensor nodes in the network at the initial time. β and β are the maximum value and minimum value among the offset values of all the sensor nodes after the nth round synchronization. For the (n + 1)th round of synchronization, each node conducts the group averaging within its transmission range. The maximum offset value would be averaged with some other offset values which are smaller than or equal to it. Then the result should be smaller than or equal to β . If this result is the new maximum offset value after the (n + 1)th round of synchronization, we can say β +1 ≤ β . If β +1 is from the averaging operation group without β node, since the offset values in the group is smaller than or equal to β , we can also obtain β +1 ≤ β . β +1 is equal to β only when all the offset values of the neighbors are equal to β . From β 0 , to β , until β +∞ , the maximum offset value is non-increasing over the whole synchronization time. Similarly, we have β +1 ≥ β , meaning that from β 0 , to β , until β +∞ , the minimum offset value is non-decreasing over the whole synchronization time. Because the averaging operation is conducted all the time, we can obtain that lim →+∞ β = lim →+∞ β = β . This demonstrates that the offset values of all the sensor nodes converge to the certain value β finally.
Next we discuss the relationship between β and the initial average offset value of all the sensor nodes β 0 . For each neighborhood averaging, the average value of this sensor group does not change.
Similarly, for each round of synchronization, the average value of the entire network does not change. Then we have β 0 = β = β ∞ . As discussed above, after certain rounds of synchronization, the offset values of all the sensors converge to β . Then the average offset value of these sensors would be = β . Therefore, we obtain β = β ∞ = β 0 . The offset values of all the sensor nodes in the network converge to the initial average offset value. MAC layer time stamping is adopted in the proposed protocol. It is well explained in detail in [19,22]. On the transmitter side, the timestamp is recorded into the message just before the packet is transmitted into the air at the physical layer. On the receiver side, once the message "Start Frame Delimiter" (SFD) is received, the instant time is recorded as the start of the packet reception. This mechanism significantly reduces the unpredictable delays in the protocol stacks at both transmitter and receiver sides. The computational complexity of the algorithm T(n) = (n), where n is the number of nodes within the transmission range of a sensor node.

Skew Rate Compensation
Offset compensation is for time alignment among the network nodes. The skew rate also needs to be synchronized so that the sensor nodes can have a common clock speed. The method is the same as offset compensation by taking average of the skew rate values among the sensor nodes as illustrated in Equation (9): The algorithm of skew rate compensation is given below: Step 1: Periodically sense the channel, if channel is clear, then broadcast a requesting packet to ask the neighbors within its transmission range for the skew rate.
Step 2: The neighbors return the skew rate.
Step 3: Compensate for the propagation delay Step 4: The node calculates the average skew rate for all these nodes of the neighbors and itself.
Step 5: Update its skew rate value.
Step 6: Broadcast the compensation table. The table includes node ID and compensated skew rate.
Step 7: The neighbors receive the table and update their own skew rates.
The skew rates of sensor nodes in the network will converge finally to a certain value. The proof is the same as Theorem 1. The computational complexity of the algorithm ( ) = ( ), where n is the number of nodes within the transmission range of a sensor node. This is the same as the reference protocols, FWA and CWA.
To illustrate the skew rate compensation clearly, we take an example of two-node skew rate compensation. We collect the clock readings ( 1 ) and ( 1 ) at the absolute time 1 from node i and node j, and the clock readings ( 2 ) and ( 2 ) at the absolute time 2 as shown in Figure 5 (clock readings collected at the same time are achieved by delay estimation mentioned in Part A in this section. The algorithm demonstrates that there is a two-way message exchange). and are the maximum limit of the clocks of node i and node j. When the counter reaches the maximum limit, an interrupt is triggered and the clock value increments. The relationship of the clock duration , tick duration and counter limit N is given in Equation (10).
For skew rate synchronization, based on the pre-defined counter limits , and the collected clock readings τ ( 1 ), τ ( 1 ), τ ( 2 ) and τ ( 2 ), the goal is to find + , which is the compensated counter limit of node j, to satisfy = + .
For node i, the duration between the two probe messages, 2 − 1 , can be expressed as Equation (11). Similarly, 2 − 1 can also be expressed from node j as shown in Equation (12): Combining Equations (11) and (12), we have: Since the goal is to satisfy = + , we expand it as Equation (14): Combining Equations (13) and (14), the new counter limit of node j's oscillator is obtained in Equation (15): The above discussion is to synchronize node j to node i. If the average compensation is desired, then the goal becomes to find + and + , which satisfies Equation (16): Since = × , for node i we have: By dividing on both sides of Equation (17) and combining it with Equation (13), we obtain: Similarly: So far, the skew rates are compensated to a consensus value for the two nodes by adjusting the counter limit. This method can be extended to more nodes. After a certain number of compensation rounds, the entire network would eventually be synchronized. It should be noted that for neighboring information exchange, it is a two-way communication. By using the recorded clock values, the propagation delay can be estimated. Using the estimated propagation delay value, the clock readings of different nodes at the same time, e.g., τ ( 1 ) and τ ( 1 ), can be obtained. In Section 4 the algorithms are evaluated by simulations and the results are analyzed.

Simulation Evaluation
The algorithm of GNA clock synchronization has been simulated by MATLAB and compared with forward weighted average (FWA) and confidence weighted average (CWA) which are proposed in [20]. For FWA, Each node periodically broadcasts a synchronization beacon. The receiving node takes average of offset and drift. FWA calculates the average only between two nodes, as expressed as Equation (20). C � i (t) is the estimation of C i (t). C i (t) and C j (t) are the clock readings from node i and node j. CWA is the improved algorithm based on FWA. CWA includes a confidence parameter which gives more weighting to the nodes that conduct more rounds of synchronization. It is expressed in Equation (21). The initial values of γ i and γ j are set to 1: A 10 × 10 grid sensor network is built up. After two minutes, the synchronization procedure starts and it performs the algorithm every minute for ten rounds. The simulation parameters are described in Table 1. Several cases are discussed to evaluate the proposed GNA algorithm.
In Case 1, α is equal to 1, while β is not equal to 0. The skew rates of all the nodes in the network are always the same. An initial error following normal distribution is given to all the sensor nodes. Figure 6 shows the geographic distribution of synchronization error before and after the first round of offset compensation. It can be seen that before the offset synchronization, the range of clock error is from −600 to +600 ticks. After one round of synchronization, the range of clock error reduces to −20 to +40 ticks. The offset is significantly compensated. It is also noted that after the offset synchronization, the values are the same for several node clusters. This is because the average algorithm is conducted for all the nodes within the transmission range of a central node. Then after the average calculation for one cluster, the nodes within the cluster would have a common clock.  Figure 7 shows the relationship of the averaged standard deviation of errors and the synchronization rounds for 100 runs for three clock synchronization algorithms: FWA, CWA and GNA. For each run, random initial errors are generated for each sensor node. The standard deviation is calculated as in Equation (22): where: ̅ = 1 ∑ =1 .
After each round of synchronization, the standard deviation of clock offsets for a specific clock synchronization protocol is calculated and plotted. The standard deviation expresses the convergence performance by calculating how much variation exists from the average. A low standard deviation indicates that the errors of the sensor nodes tend to be very close to the mean, while a high standard deviation indicates that the errors are spread out over a large range of values. From Figure 7 it can be seen that the averaged standard deviation of the errors in the beginning is 290 ticks. It decreases as the synchronization is conducted round by round. As the synchronization is conducted, the standard deviation reduction trend becomes slow and the value goes towards zero. This is realized by the averaging behavior for the three clock synchronization algorithms. The algorithms average the clock offsets between two nodes or among a number of sensor nodes, therefore the standard deviation reduces. The performance of the proposed GNA protocol is better than that of FWA and CWA. For each round of clock synchronization, GNA achieves a lower standard deviation than FWA and CWA. This is because the offset averaging calculation is conducted among all the neighbor nodes and the obtained value is assigned to these sensor nodes when using GNA algorithm, but for FWA and CWA the average is taken only between a pair of nodes for each round. The speed of convergence of FWA and CWA is slower than that of GNA. The case of the errors in ticks of the FWA, CWA and GNA algorithm for 10 rounds of synchronization are shown in Figure 8. For each round of clock synchronization, the offsets are compensated. Because the skew rates in this case are set to 1, the tick errors would last until the next clock synchronization. The GNA algorithm achieves the fastest convergence among the three algorithms. The error converges to zero after two rounds of clock synchronization (3 min after the simulation). Zero means that the sensor nodes converge to a common virtual clock. FWA and CWA need a longer time to converge. From the figure it can be seen that FWA and CWA do not converge to zero even after 10 rounds of clock synchronization. As discussed above, the better performance of GNA is because GNA takes average of all neighbor nodes but FWA and CWA only calculate the average between two nodes. In Case 2, there is no initial offset given to the sensor nodes in the network. Therefore, β is equal to 0, but α, the skew rate of the sensor nodes clock is assigned a random value, which is not equal to 1, for each sensor node. The off-center skew rate causes clock errors. The clock errors for FWA, CWA and GNA algorithms within 12 min are compared in Figure 9. In this figure, only offsets are compensated, while the skew rates are not compensated. From the figure there are no initial errors in the first two minutes of the simulation. After that a random skew rate is generated for all the sensor nodes. Due to this skew rate, the errors increase in the next minute. At the third minute of the simulation, the three algorithms conduct the offset compensation. The clock errors of the sensor nodes are reduced, but because there is no skew rate compensation, the clock errors increase again in the next minute. The clock error patterns come out periodically. From the figure, for each clock synchronization at the integral time instant, the proposed GNA outperforms than FWA and CWA by obtaining a smaller clock error deviation of all the sensor nodes for each round of synchronization. As mentioned above, group averaging is the reason for GNA's better performance. Figure 10 gives the simulation result of the comparisons of FWA, CWA and GNA for both offset and skew rate compensation. At the time instant of 2 min random skew rates are initialized for all the sensor nodes. The clock errors increase in the next minute. At the time instant of 3 min, The FWA, CWA and GNA algorithms are executed for both offset compensation and skew rate compensation. The clock errors therefore become smaller. Since one round of skew rate compensation cannot make all sensor nodes achieve a common skew rate, the clock errors still deviate in the following minutes. Then the next round of synchronization comes. The offsets and skew rates of sensor nodes are compensated again. From the figure it can be seen that at the end of the simulation, the clock errors of all the three algorithms are synchronized to a virtual consensus clock which is already not the real time.  This is the nature of the consensus algorithm. The consensus algorithm can make the clocks of sensor nodes converge, but cannot guarantee that they will converge to the real time since there is no reference clock in the network. However, this is not an issue for most applications which require only internal clock synchronization. The convergence performance of GNA is much better than that of FWA and CWA. The two-node synchronization cannot make the clock converge.
In Figure 11, the skew rates of the proposed GNA, FWA and CWA are compared. Initial skew rates are generated at the beginning of the simulation. After 10 rounds of synchronization, the deviation of the skew rate becomes smaller. The proposed GNA converges faster than FWA and CWA. After six rounds of synchronization, the skew rate of GNA converges to a common value, but for FWA and CWA, the skew rates do not converge to a common value even after 10 rounds of synchronization. Group averaging within the transmission range is still the reason for the fast convergence of GNA. Figure 11. The skew rate of FWA, CWA and NA for the 10 round clock synchronizations.
In Case 3, both initial errors and skew rates are assigned to all the sensor nodes. The errors in ticks of FWA, CWA and GNA algorithm for 10 round synchronizations are shown in Figure 12. In this simulation both offset and skew rate compensation are conducted for FWA, CWA and GNA. The initial clock errors are assigned to the sensor nodes in the beginning. After two minutes, the first round of offset and skew rate compensation are conducted. The clock errors decrease. During the next minute, due to the existence of skew rate deviation, the clock errors increase. In this figure this clock error increase cannot be clearly seen because the increase is not that significant compared with the initial errors with the range of −1000 to 1000 ticks. After 10 rounds of offset and skew rate compensation, the clocks of the sensor nodes in the network converge. It can be seen that GNA converges faster than FWA and CWA. Figure 13 shows the averaged standard deviation of clock errors for FWA, CWA and the proposed GNA algorithm during the 10 rounds of offset and skew rate compensation for 100 runs. For each run random initial errors are generated for all the sensor nodes. This result indicates a similar explanation as in Figure 7. At the beginning of the simulation, the standard deviation of the clock errors of the sensor nodes are big, here around 300 ticks. After one round of synchronization, the standard deviation drops significantly to around 50. As time collapses, the standard deviation continues to decrease towards zero. This illustrates that the algorithms of FWA, CWA and the proposed GNA are effective for the purpose of clock synchronization for WSNs. From the figure it can also be seen that the proposed GNA achieves better performance of convergence than FWA and CWA.   Figure 14 shows the averaged standard deviation of errors for different transmission ranges using the proposed GNA for 100 runs. Transmission ranges equal to 1, 2 and 3 unit length are simulated. From the figure when the transmission range is equal to 1, the averaged standard deviation in the beginning is 28 ticks. As time collapses, the standard deviation decreases significantly. After ten rounds of synchronization, the standard deviation drops to zero. When the transmission range increases to 2 or 3, the performance of convergence becomes significantly better. This is because when the transmission range increases, more nodes are involved for the average calculation. N in Equations (6) and (7) becomes larger. The convergence becomes faster throughout the entire network.   The standard deviation of errors goes down as the synchronization iteration increases. This demonstrates the convergence of the proposed GNA algorithm. It can also be seen from the figure that the standard deviation of errors for bigger network size is larger than that for smaller network size. The reason is that the transmission range is limited. The averaging operation can only be taken within a small cluster. If the network size is larger, meaning that more sensor nodes are in the network, of course after the same rounds of synchronization, the standard deviation of errors is bigger. The convergence rate is slower if the network size increases. Therefore, more rounds of synchronization are needed for global synchronization if the network size becomes larger.

Conclusions
This paper has proposed a novel internal clock synchronization solution for wireless sensor networks. It is a fully distributed, network-wide synchronization algorithm. Compared with several recent popular synchronization algorithms, the proposed GNA algorithm considers the propagation delay. The two-way message exchange is adopted for the compensation of the propagation delay. Based on this new coming message exchange, a group average scheme was proposed. The random elected sensor node collects the offset and skew rate from neighbors and takes group averaging, which would achieve fast clock convergence. The analytical analysis of offset and skew compensation is described. The performance of the proposed GNA is fully simulated and analyzed for different kinds of offset and skew rate compensation scenarios. The simulation results showed that the proposed GNA algorithm achieves better performance in terms of accuracy and convergence speed than other algorithms like FWA and CWA. Future work would focus on full mathematical interpretation of clock synchronization in WSNs, energy consumption analysis and hardware testbed implementation.