Adaptive in Sensor Networks

Santashil PalChaudhuri Amit Kumar Saha David B. Johnson [email protected] [email protected] [email protected] Department of Computer Science Rice University Houston, TX 77005

ABSTRACT 1. INTRODUCTION Recent advances in technology have made low cost, low Recent advances in technology have made low-cost, low- power wireless sensors a reality. Clock synchronization is an power wireless sensors a reality. Sensor networks formed important service in any distributed system, including sen- from such sensors can be deployed in an ad hoc fashion and sor network systems. Applications of clock synchronization cooperate to sense and process a physical phenomenon. As in sensor networks include data integration in sensors, sen- each sensor has a finite battery source, an important feature sor reading fusion, TDMA medium access scheduling, and of sensor network is energy efficiency to extend the network’s power mode energy saving. However, for a number of rea- lifetime. sons, standard clock synchronization protocols are unsuit- As in any distributing computer system, clock synchro- able for direct application in sensor networks. nization is an important service in sensor networks. Sensor In this paper, we introduce the concept of adaptive applications can use synchronization for data inte- synchronization based on the need of the application and gration and sensor reading fusion. A sensor network may the resource constraint in the sensor networks. We describe also use synchronization for TDMA medium access schedul- a probabilistic method for clock synchronization that uses ing, power mode energy savings, and scheduling for direc- the higher precision of receiver-to-receiver synchronization, tional antenna reception. Sensor networks show some unique as described in Reference Broadcast Synchronization (RBS) characteristics that make it difficult to directly apply tradi- protocol. This deterministic protocol is extended to pro- tional network clock synchronization approaches. vide a probabilistic bound on the accuracy of the clock syn- The error in clock synchronization comes mainly from the chronization, allowing for a tradeoff between accuracy and non-deterministic random time delay for a message transfer resource requirement. Expressions to convert service spec- between two nodes. Kopetz et al. [1] first characterized this ifications (maximum clock synchronization error and confi- message delay. In some recent work, this non-determinism dence probability) to actual protocol parameters (minimum has been reduced to provide tighter bounds on the clock number of messages and synchronization overhead) are de- synchronization error [2, 3]. Our work, which is based on the rived. Further, we extend this protocol for maintaining clock Reference Broadcast Synchronization (RBS) [3], provides an synchronization in a multihop network. analytical way to convert service specifications to protocol parameters. Categories and Subject Descriptors The need in sensor networks is to provide the best possible clock synchronization under existing circumstances, given C.2 [COMPUTER-COMMUNICATION NETWORKS]: the limited resources of the nodes and the network in the [Network Protocols, Applications]; G.3 [PROBABILITY system. Highly accurate clock synchronization typically re- AND STATISTIC]: [Probabilistic algorithms] quires more message transfers and processing as part of the synchronization protocol. In situations where the system General Terms energy is extremely low, it might not be possible to provide high accuracy. The accuracy needed in clock synchroniza- Algorithms, Design tion is variable, depending on the higher layer application requirements. If the need for determinism can be relaxed, Keywords probabilistic guarantees often suffice for the needs of an ap- Clock synchronization, Sensor Networks, Probabilistic Al- plication, while allowing for optimal use of resources. Prob- gorithms abilistic guarantees provide better accuracy in most cases as compared to deterministic accuracy in all cases. Also the failure probability of achieving a certain accuracy can be bounded. Quality of Service (QoS) in networks make exten- Permission to make digital or hard copies of all or part of this work for sive use of this concept to give probabilistic guarantees by personal or classroom use is granted without fee provided that copies are allowing resources to be allocated on the basis of expected not made or distributed for pro®t or commercial advantage and that copies aggregate demand. Previous work [4, 5] uses this concept for bear this notice and the full citation on the ®rst page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior speci®c providing probabilistic clock synchronization in distributed permission and/or a fee. systems. IPSN'04, April 26±27, 2004, Berkeley, California, USA. Clock synchronization might not be necessary at all times, Copyright 2004 ACM 1-58113-846-6/04/0004 ...$5.00.

340

except during sensor reading integration. In such a case, Multihop: Most of the typical synchronization pro- providing clock synchronization all the time will be a waste • tocols have a highly accurate clock present in the LAN, on the limited available resources of sensors. The sensor such that all the nodes in the system can directly ex- can be allowed to go out of sync, and then re-synchronize change messages. Sensor networks span many hops, only when there is a need for synchronization, thereby sav- with higher jitter. So the algorithms for sensor net- ing resources. work clock synchronization need to have some sort of We design our adaptive clock synchronization protocol localization to reduce this error, as well as some other keeping in mind the concepts discussed above. The remain- means of achieving multihop synchronization even in der of this paper is organized as follows. In Section 2, we the presence of high jitter. describe the various concepts of clock synchronization in de- Server-less: Traditional protocols have specified tail and motivate the design principles used in building our • algorithm. In Section 3, we survey the related work in this servers, with multiple accuracy levels which are sources area. Section 4 describes the RBS protocol, along with our of accurate time. Sensor networks do not have any ex- improvements. Section 6 evaluates the performance of the ternal infrastructure present and can be large in scale. protocol. Section 5 extends this protocol for multihop sensor Maintaining global time scale in this network is thus networks. Finally, we discuss our conclusions in Section 7. harder, if no external broadcast source of global time such as GPS is present. Elson et al. [7] proposed that each node maintain an undisciplined clock, augmented 2. DESIGN PRINCIPLES with the relative frequency and phase information of In the paper describing the (NTP), its neighbors. We also use this approach in our work. Mills [6] defines the various terms used in clock synchro- nization. The stability of a clock is how well the physical 2.2 Theoretical Bounds on Clock Synchroniza- clock can maintain a constant frequency. Accuracy refers tion to how well the maintained time is true to the standard There have been various theoretical results that have been time. The offset of two clocks is the actual time difference proven regarding clock synchronization. These analytical between them, and the skew is the frequency difference be- results and their consequences are useful when designing a tween them. To synchronize frequency means to adjust the clock synchronization protocol: clocks to run at the same frequency, and to synchronize time From the causality property in a system, the ordering of means to set their time at a particular epoch to be exactly events can be formally stated. If an event a occurs before the same. To synchronize clock means to synchronize the another event b, then a should happen at an earlier time clocks in both frequency and time. In this paper, our algo- than b. Let Ci(a) be the clock value of process i when event rithm will synchronize clocks, i.e., it will synchronize both a occurs. Then it can be formally stated that: frequency and time. If a and b are events in process i, and event a 2.1 Traditional versus Sensor Network occurs before event b, then C (a) < C (b) . Synchronization i i NTP is scalable, robust to failures, self-configuring, and Lamport [8] showed that, when the value of a clock needs to has various properties that are needed in the sensor network be adjusted, it always has to be set forward and never back. world. However, wireless sensor networks pose a number of Setting the clock back could cause the above condition to be challenges beyond traditional network systems. Elson and violated. Hence, in an ideal system, the slower clocks needs Romer [7] describe the differences quite exhaustively. We to be adjusted to the value of the fastest clock, for all clocks state the design principles that are used in the design of the to be synchronized. This restriction will also maintain the protocol. partial ordering of the events. It is useful to have a bound on the best accuracy achiev- Energy Constraint: Energy efficiency is very im- able in any system, such that no bound lower than that is • portant for sensor networks as opposed to traditional specified. Srikanth et al. [9] have shown that for any syn- networks. chronization algorithm, even in the absence of faults, the bound on the rate of drift of logical clocks from real time Tunable Accuracy: Traditional synchronization is greater than the bound on the rate of drift of physical • protocols try to achieve the highest degree of accuracy clocks. In the presence of faults — such as message losses possible. The higher the level of accuracy required, and node failures — the accuracy of logical clocks becomes the higher the resource requirement. The accuracy of even worse. required synchronization depends on the application Most clock synchronization algorithms proposed in liter- requirement. Therefore, there is a need for a trade- ature try to guarantee a deterministic upper bound on the off between resource requirements and accuracy, de- clock skew. Lundelius et al. [10] derived a theoretical limit pending on the need of the application and resource on the best achievable clock skew that deterministic algo- availability of the system. rithms can guarantee. They show that the upper bound on clock skew that can be deterministically guaranteed by Non-determinism: Sensor networks are dynamic any clock synchronization algorithm can be no smaller than • systems with considerably higher rate of failures and (dmax dmin)(1 1/n), where n is the number of nodes in the − − non-determinism of the individual nodes than in tra- system, and dmax and dmin are the maximum and minimum dition networks. Thus the synchronization protocol value of message delays in the system, respectively. Signifi- needs to be more robust to failures and also to the cantly smaller bounds on the upper bound of clock skew can greater variability in communication delay. be achieved if the condition of determinism is loosened. If

341

the deterministic guarantee is replaced with a probabilistic Relative clock: This is the relative notion of time guarantee, where the probability of failing can be bounded, • within the sensor network. Each node is synchronized it might suffice for many applications. with every other node with a time which might be This probabilistic guarantee is specially significant for sen- totally different from UTC. This suffices for most of sor networks, as sensor networks inherently assume a level the applications of clock synchronization that we have of redundancy present in the number of nodes and are fairly described earlier. In this work, we provide this syn- robust to failures. This approach might entail saving a sig- chronization with an accuracy which is bounded with nificant amount of resources in the sensor network, while a tunable confidence probability. giving some guarantees. We thus develop a probabilistic Relative notion of time: Time can also be main- clock synchronization protocol for sensor networks, basing • our work done previously by Christian [5] and Arvind [4]. tained between nodes, not with real time, but with some logical notion. This logical notion need not match with physical clock. For example, two nodes might 2.3 Sources of Clock Synchronization Error need to trigger an alarm 10 time units after some event The biggest source of error in synchronization algorithms has occurred (time unit might not be seconds). This stems from non-determinism in message delivery latency. sort of time is very often enough for a variety of ap- In an effort to reduce this non-determinism, we review the plications. But, providing the previous type of clock synchronization also automatically provides this type sources of this latency. Kopetz et al. [1] have characterized the message delivery latency into four distinct components: of clock synchronization. So, we indeed provide this notion of clock synchronization. Send Time: The time spent at the sender to build Physical ordering: In many cases precise times • the message. • might not be important, but what is important is the ordering of events. If the system can state whether an Access Time: This is the delay incurred when wait- event occurred before or after another, that is enough. • ing in the network interface for access to the transmis- This type of synchronization simply involves ordering sion channel. of events in some partial or total order. Having previ- ous clock synchronization types automatically provide Propagation Time: This is the time needed for the this type. However, we note that this might be signif- • message to propagate from sender to receiver over the icantly cheaper in terms of resources to achieve. So, wireless medium. if application need only this type of synchronization, alternate means should be used to preserve scarce re- Receive Time: This is the time needed for process- sources. • ing at the receiver’s network interface.

Most clock synchronization algorithms go to great lengths Another classification is in terms of the initiator of synchro- to reduce the above non-determinism in message delivery. nization procedure. In this work, we provide all three types A significantly different approach has been taken in the Ce- of synchronization below, depending on the system need. siumSpray system [2]. CesiumSpray takes advantage of the They are as follows: inherent broadcast nature of the wireless medium. The Send Always On: In this model, clock synchronization Time and Access Time are unknown and highly variable. • However, for a set of receivers listening to a common sender, between nodes is always present. Many applications those times are identical for all of the receivers. The only like TDMA scheduling might need this model. This variable time is the Propagation Time and Receive Time, model is the model of traditional clock synchronization which are much smaller in value. This approach entails syn- protocols. But, maintaining this model might present chronizing a set of receivers with each other, in contrast to a significantly higher overhead, if the applications re- synchronizing with the sender. We use this idea to signifi- quire clock synchronization rarely. cantly reduce the sources of error in our clock synchroniza- Sensor Initiated: In this model the sensor nodes tion protocol. • decide whether to have synchronization or not. They synchronize between themselves or a subset of the nodes, 2.4 Models of Clock Synchronization whenever necessary. This is useful when the need for synchronization is not required frequently. But it might There are many different types of clock synchronization. entail a certain degree of latency before synchroniza- Each type has its usage. They are as follows: tion can be achieved. So the applications will need to tolerate this latency. Global clock: There is a precise global time, UTC, • which is maintained by atomic clocks in standard lab- Outsider Initiated: This is similar to the previous oratories. Traditional Internet clock synchronization • model. But here the initiator of clock synchronization algorithms try to maintain this global time in all com- is somewhere outside the sensor network, for example puter systems. Maintaining this time in sensor net- a control center. This model degrades to the previous works is significantly harder. Sensor networks also do model though, once the message to start synchroniza- not typically need this strict clock synchronization. In tion has reached from the outsider to the necessary this paper, we can provide this service with a certain sensor nodes. So, this is essentially same as the previ- degraded accuracy if a GPS is available. But, main- ous one and we will not treat this as different. taining this time is not the thrust of this work.

342

3. RELATED WORK since they might be out of range of each other. For multihop synchronization, unlike RBS, our protocol does not require 3.1 Traditional Clock Synchronization all sensor nodes to be within one hop of at least one sender. Protocols 3.4 Probabilistic Clock Synchronization As mentioned earlier, most traditional clock synchroniza- tion protocols share the same basic design: a connection-less There are a few synchronization protocols that are prob- messaging protocol, exchange of clock information between abilistic in nature. The clock skew that a probabilistic pro- client and server(s), methods to reduce the effects of ran- tocol guarantees, has a probability of invalidity associated dom non-deterministic communication delay, and a method with the guarantee. However, the probability of invalidity to upgrade the client time based on the information from can be bounded. All the probabilistic algorithms proposed the server. NTP is widely deployed in the internet, since are for server-client architecture, where the clients try to it is scalable, robust and has good performance. It consists synchronize with the clock of the server. This is funda- of various levels (or stratum) of servers in a hierarchy pro- mentally different from our approach where we synchronize viding synchronization to the clients which are leaves in a amongst receivers. hierarchical tree. These protocols cannot be applied directly However, we adapt the idea of the probability analysis to sensor networks because of the differences pointed out in techniques proposed in the following two papers. The idea Section 2.1. of probabilistic protocol was proposed by Christian [5]. He realized that guarantee cannot be provided when unbounded 3.2 Wireless Clock Synchronization Protocols message delays are possible or messages can be lost. Hence, There have been a few synchronization protocols which his principle is to retry sufficient number of times to read the are specifically for wireless or ad hoc networks. Romer [11] clock of another process with a given precision with prob- proposed a scheme for sparse ad hoc networks. The algo- ability as close as desired. However, there are some fun- rithm does not synchronize the computer clocks of the nodes, damental limitations to the accuracy that can be achieved. but generates time-stamps which is used by the unsynchro- His algorithm reads the remote server clock within the spec- nized clocks to transform the message time-stamp. As a ified precision. It repeats these attempts till a reply comes message moves from hop to hop, each node transforms the back within a certain desired interval of time. The lower the message time-stamp to its local time-stamp with some intro- round trip time for a reading attempt and its reply to come duced error. This error increases with the number of hops. back, the higher the accuracy achieved in reading the clock Huang et al. [12] showed that the 802.11 MAC time synchro- of the remote server. The average number of messages to reach synchronization is 2/(1 p), where p is the probability nization protocol is not scalable for large number of nodes. − They proposed a simple modification to the MAC proto- of failure of message delivery within a fixed period of time. col which maintains synchronization among nodes in a sin- This process is repeated k times, such that the probability of reaching synchronization is 1 pk. By choosing a large gle broadcast region. Saurabh et al. [13] recently proposed − a timing synchronization protocol based on sender-receiver enough k, the probability can be made arbitrarily close to 1. synchronization. Arvind [4] proposed another probabilistic synchronization protocol. It has two main parts — the Time Transmission 3.3 Receiver-Receiver Synchronization Protocol (TTP), by which the clock value of the sender is A couple of previous works use a completely different ap- read by the receiver, and Probabilistic Clock Synchroniza- proach than the traditional approaches. They synchronize tion (PCS), which uses this value to adjust the receivers a set of receivers among themselves. This reduces much clock. In TTP, the sender sends a sequence of n synchro- of the message delivery latency non-determinism associated nization messages, each having the sender time-stamp. The with traditional protocols. CesiumSpray [2] was the first receiver adjusts the clock value using these n time-stamps. to use this idea. It is a hybrid external/internal synchro- The synchronization procedure is repeated every interval of nization protocol. It uses a two-level hierarchy to improve time. He analytically showed the minimum number of mes- scalability. sages necessary for achieving a given maximum synchroniza- Our work is based on the Reference Broadcast Synchro- tion error. This paper has less overhead than Christian’s nization (RBS) [3]. Least-squares linear regression is used paper, if the physical medium is considered to be broadcast. to find the relative frequency of the clocks. RBS uses post- facto synchronization to synchronize two nodes’ clocks by 4. SINGLE-HOP CLOCK SYNCHRONIZA- extrapolating backwards to estimate the phase offset at any previous time. It extends the work to do multihop clock syn- TION chronization. Our protocol is similar to this work in terms In this section, we describe the technique of receiver-receiver of protocol in the single-hop case, other than some minor synchronization used in our protocol. Next, we present the improvements. However, RBS does not contain any analy- extension of this technique to probabilistic synchronization sis on the number of reference broadcasts necessary, or the for use within a single broadcast region. We then analyse it frequency of reference broadcasts. We analyse these issues mathematically to find the probabilistic bounds. and provide a probabilistic bound on the maximum error. We also relate this probability with the number of reference 4.1 Receiver-Receiver Synchronization Error broadcasts required. RBS also has more overhead in terms The sources of non-deterministic error in message latency of exchanging information between the receivers. It assumes have been described in Section 2.3. In RBS and Cesium- a single broadcast region for the sender and all the receivers, Spray, this non-deterministic error was significantly reduced which is not the case. Two receivers, lying in the broadcast by synchronizing among the receivers, instead of synchro- range of a sender, might not be able to exchange messages nizing between the sender and receivers. In receiver-receiver

343

synchronization, the only remaining sources of non-determinism ways On or Sensor Initiated model is the same. So, are the Propagation Time and Receive Time. Propagation we present and analyse them together, pointing out Time is very small, considering the range of the sensors and the differences as and when necessary. The steps in the speed of radio waves. Receive Time is much more deter- this protocol are described next. The subset of nodes ministic and can be bounded by time-stamping the receiving chosen as senders is random among the set of sensor time at the hardware level [1, 3]. If the total error previ- nodes. If the relative density of sensor sender nodes ously was sr, for sender-receiver synchronization, and the and all sensor nodes is above a threshold, and if we as- error in this case is rr, for receiver-receiver synchronization, sume uniform distribution of the sensor nodes, we can then sr >> rr. assume the presence of sender sensors in every broad- The receiver-receiver synchronization works in the follow- cast region. But, this assumption is not necessary, as ing manner. The sender sends a reference pulse at any time. we will see in section 5, when we extend our protocol Each receiver marks when it received the reference pulse ac- for multihop synchronization. cording to its local clock. All the receivers exchange with each other the time of reception of the reference pulse. Since The following happens for every sender sensor in a single- each receiver assumes that the pulse should have been re- hop broadcast region. A particular sensor being in the ceived by all other receivers at approximately the same real broadcast region of two senders will do all of the steps below time, a receiver A is able to estimate the offset of its clock separately for each sender. When synchronization is neces- with respect to another receiver B which has exchanged in- sary in a sensor-initiated model, the sensors needing syn- formation with A. The number of reference packets may be chronization send out a REQUEST . This request is broad- increased in order to get better synchronization. casted till it reaches a sender sensor, which starts a cycle of Elson et al. [3] have found the distribution of the synchro- the algorithm. In the Always On model, each sender sensor nization error among a receiver set. Multiple pulses are sent starts the cycle and repeats it periodically (period is deter- from the sender to the set of receivers. The difference in mined analytically in Section 4.3). actual reception time at the receivers is plotted. As each of these pulses are independently distributed, the difference 1. A sender broadcasts n reference packets to its neigh- in reception times gives a Gaussian (or normal) distribution bors. Each packet contains two counters, one showing with zero mean. a cycle number, and another the reference packet num- Given a Gaussian probability distribution for the synchro- ber in the current cycle. The interval between each nization error, it is possible to calculate the relation between packet is fixed and greater than some minimum, such a given maximum error in synchronization and probability that they are independent of each other. of actually synchronizing with an error less than the max- imum error. If the maximum error that we allow between 2. Each receiver records the time according to its own two synchronizing nodes is max, then the probability of local clock, when each of these reference packets are synchronizing with an error  max is given from Gaus- received. Using these time-stamps, the receiver uses sian distribution property. ≤ linear regression to fit a line on these data. The slope of the line will approximate the relative clock skew 2  x max e 2 dx between the receiver and the sender. max − P (   ) = − max √2π | | ≤ 3. Each receiver sends back to the sender, a packet con- So, as the max limit is increased, the probability of failure taining the slope of the line and one point on that line. (1 P (  max)) decreases exponentially. We use this The sending back of these packets are jittered over an observ− ation| | ≤in the analysis below. interval so that the packets sent back by different re- ceivers have less chance of colliding with each other. 4.2 Description of the Protocol In this section, we present our protocol, extending the 4. The sender composes all these slopes together, and deterministic RBS protocol to provide adaptive clock syn- broadcasts a packet containing its relative clock skew chronization. The frameworks for providing external syn- slope to all the receivers who have replied back. chronization with UTC and for providing relative synchro- 5. Each receiver after receiving this packet, can now cal- nization among the nodes are different. In this paper, we culate its own slope relative to all the receivers in the concentrate on providing relative synchronization, as it is broadcast region of a a particular sender. So, for ev- sufficient for most sensor network applications. ery pair of receivers, within the broadcast region of the sender, the clock skew and clock offset are now known For external synchronization, we assume the availabil- with some synchronization error. The Send Time and • ity of GPS in a subset of the nodes. These nodes will Access Time errors are factored out when calculating be senders of synchronization messages. The sensor this relative slope, as that error is the same for any nodes will synchronize with these GPS receivers us- two receivers. The only error present will be that due ing any of the many sender-receiver probabilistic algo- to propagation time and receive time. rithms proposed previously [4, 5]. Obviously, the syn- chronization error will be more than receiver-receiver 4.3 Mathematical Analysis synchronization because of the reasons pointed out in the Section 4.1. The preceding section shows how our algorithm keeps the clocks of sensor nodes synchronized. In this section we will For relative synchronization, we use receiver-receiver analyse the probabilistic guarantee of achieving the desired • algorithm. The basic framework for providing the Al- synchronization skew. We will derive how to convert the

344

service specifications (maximum clock synchronization er- n 2 2 µ 2 i µ t σ t (i t σ t )n ror and confidence probability) to actual protocol param- n ( n ) 2 © n 2 2 φZ (t) = ¨ e − = e − n eters (minimum number of messages and synchronization 2 σ 2 t2 interval). (iµt σ2 t ) (iµt ( ) ) = e − 2n = e − √n 2

σ2 4.3.1 Synchronization overhead Using the Gaussian distribution N(µ, n ) of Z, the syn- The error among the receivers is a normal distribution, chronization error function can be found. Theorem 1 gives as described in Section 4.1. Normal distribution makes it the relation between the synchronization bound with asso- easier to study a distribution statistically. The following ciated probability, and the minimum number of messages theorem gives a relation between the synchronization error necessary. As the number of messages is the overhead of the and its associated probability, with the message overhead. protocol, this also gives the resource requirement to achieve For n synchronization pulses from the sender, the receivers a specified synchronization bound. This is the error in syn- exchange their observations via the sender. As explained chronization at the time when synchronization is done. earlier, the slope of the skew between the receivers is found √n max Theorem 1: P (  max) = 2 erf by a least square linear estimation using the n data points. | | ≤ σ The calculated slope of the skew has an associated error in where  is the clock skew at synchronization, max is the it. This error is the difference in phase between the cal- maximum specified clock skew at synchronization point, n is culated slope and the actual slope. As the points have a the minimum number of synchronization messages to guar- Gaussian distribution, this error can be calculated. As the antee the specified error, and σ is the variation of the dis- number of data samples, n, increases, this error reduces. To tribution. prove the theorem, the following lemmas will be used. Proof: For a Gaussian distribution N(µ, σ2), the pdf, 1 x µ 2 [ − ] f(x) = e− 2 σ In Lemma 1, it is proved that the characteristic function √2πσ2 of the sum of independent random variables is a product of the characteristic function of each random variable. Hence, for the Gaussian distribution of Z, 2 1 x µ

−σ

£ ¤¥ − 2 ¢ Lemma 1: Let Z = X + X with fX (x), fX (x) and e √n 1 2 1 2 f(z) = 2π( σ )2 fZ (z) denoting pdf’s of X1, X2, and Z respectively, X1 and √n X are independent random variables. Then, Φ (ω) = 2 Z The probability that the error,  lies within max is given Φ (ω)Φ (ω). Extending the result by induction, Φ (ω) = X1 X2 Z by: ΦX (ω)ΦX (ω) ΦX (ω). 1 2 · · · n (x µ)2 −σ 2 − 2( ) max √n In Lemma 2, the characteristic function of the sum of  e dx

max P (  max) = − independent random variables is derived, if the random vari- 2π( σ )2 | | ≤ √n able’s are Gaussian distributions. This derivation uses Lemma 1. Putting µ = 0, nx2  Lemma 2: The characteristic function of the summation 2√n max e− 2σ2 dx P (  max) = 0 of n Gaussian distributions is: | | ≤ √2πσ2

 2 max ny 2 2 σ t σ 2 iµt 2√nσ 0 e− dy x φZ (t) = e − 2n = [Putting y = ] √2πσ2 σ X1+X2+ +Xn Proof : Given that, Z = n ··· √n 2

max z σ 2 2 0 e− dz X1 X2 Xn = [Putting z = y√n] = + + + √2π n n · · · n 2

t 1 x µ 2 x [ − ]  √n e− 2 dt Now, f(x) = e− 2 σ = 2erf ( max ) [Where, erf (x) = 0 ] √2πσ σ √2π

x

Therefore, f(y) = f n ¡ 4.3.2 Synchronization interval µ 2 x n2 µ 2 1 ( n n ) y The previous theorem specified the minimum synchroniza-

− 1 − n

£ ¤¥ 2 ¢ σ σ − − 2 ¦ n § tion error, given the number of messages. That was the = ne = e √2πσ √ σ 2π( n ) error in synchronization precisely when synchronization was done. In the next theorem, given a maximum specified clock The characteristic function of a Gaussian distribution Xi 2 t2 skew, a time period within which re-synchronization has to iµt σ 2 is, φXi (t) = e − be done is derived. Xi So, the characteristic function of n is, Theorem 2: γmax = max + (Tsync + σmax)ρ µ σ 2 t2 i n t ( n ) 2 φ Xi (t) = e − where γmax is the maximum allowable synchronization at n any point in time, Tsync is the time period between syn- From the previous lemma, the characteristic function of chronization points for the Always On model (time period the summation of the independent random variables will by of validity for Sensor Initiated model), ρ is the maximum the product of the characteristic function of the individual drift of the clock rate, and σmax is the maximum delay (af- random variables. Therefore, the characteristic function of ter the synchronization procedure has been started) in the Z is time values of one receiver reaching another receiver.

345

of any other sender at level 1. These packets are received by R1 R5 all sensor nodes which are within the broadcast region of a sender at level 1. Consider the scenario presented in Figure 1. Nodes R1, R6 S R2 R2, R3 and R4 are within the broadcast region of the sender R4 S. Using the single hop synchronization protocol nodes R1, R2, R3 and R4 are synchronized among themselves. Sup- R7 pose R2 gets to be the first node to end the reference broad- R3 cast, that is R2 starts behaving as a sender at level 1. By a similar synchronization procedure, R1, R3, R5, R6 and R7 get synchronized among themselves. Now suppose R6 needs Figure 1: Multihop clock synchronization to send a message to R4. The message would have to be routed through a node which is synchronized with R6, say R3. The assumption here is that due to the relative high Proof : In our protocol, successive re-synchronization at- density of sensor nodes, a node, such as R3 as shown in tempts are never spaced more than Tsync +σmax time units, Figure 1, will exist in the broadcast region of two senders; since once the re-synchronization has started, a receiver the two senders might be at the same level or they might might receive the vector corresponding to the times reported be separated by a single level. Now since R3 is synchro- by another receiver after, at most σmax time. Thus, due nized with R4, R3 can transform the time reported by R6. to clock drift, the maximum clock skew that can arise be- Finally, since R3 is synchronized with R4, R4 can trans- tween two receiver clocks, in this time interval is (Tsync + form the time reported by R3. Hence, all along the routing σmax)ρ. Moreover, our synchronization protocol guarantees path of the message suitable time transformations can be that after a synchronization attempt, the maximum skew performed. between two receivers is max with an invalidity probabil- However, from the description of the protocol it seems ity of 1 P (  max). Hence, the total maximum skew that the protocol will have a very high overhead since the − | | ≤ that can develop between two receiver clocks is given by protocol essentially floods the entire network with reference γmax = max + (Tsync + σmax)ρ. packets. This can be easily fixed by causing time synchro- nization to be sensor initiated so that a sender (at any level) 5. MULTIHOP SYNCHRONIZATION broadcasts reference packets only if the sender receives a re- quest for synchronization from a sensor node in the local In the previous section, we presented our algorithm for broadcast region of the sender. This ensures that a node achieving adaptive clock synchronization among all receivers does not broadcast reference packets if there is no sensor that are within a single wireless hop of a sender. In this node in its local broadcast region that can listen to the ref- section, we extend our algorithm to achieve clock synchro- erence packets. nization between receivers that may be multiple hops away from a sender. This multihop extension is in contrast to the multihop extension proposed by Elson et al. [3] that as- sumes that all sensor nodes are always within a single hop 5.2 Mathematical Analysis of at least one sender. Also, in order for two sensor nodes The mathematical analysis of this protocol is similar to (present in the broadcast regions of two different senders) the mathematical analysis presented in Section 4.3. If max to be synchronized, their algorithm requires the existence is the maximum error between two receivers present in the of a node that is within the broadcast region of both the broadcast region of a sender then the maximum error pos- senders. Our algorithm does not make any such assump- sible between two sensor nodes which are k hops apart is tions, and sensor nodes in our algorithm are allowed to be k max. We shall prove by mathematical induction on the multiple hops away from a sender and still be synchronized num· ber of time transforms performed on an actual reported with all other nodes within the nodes transmission range. time. 5.1 Protocol Description Base Case: If there is a single time transform performed on For this protocol, we consider senders at various levels. the message then by the analysis of Section 4.3 the maximum A sender which does not need any synchronization (like the error possible between the actual time reported and the level 0 sender in Section 4) is called a sender at . A sensor transformed time is max. Thus, if the actual time is t0 then max max node which is within the broadcast region of a sender at the reported time will lie in the interval [t0 , t0+ ]. level 0 can behave as a sender in order to synchronize sensor − 2 2 nodes which are two hops away from the sender at level 0. Induction Hypothesis: After k time transformations on level 1 Such a sender is called a sender at . This can be the actual reported time t0, the transformed time can lie in extended for multiple hops from the sender at level 0. max max the interval [t0 k 2 , t0 + k 2 ] since by induction The receivers which are within the broadcast region of hypothesis the maxim− · um error after· k time transformations the sender at level 0 get synchronized in the same way as is k max. described in Section 4. Once these receivers get synchro- Supp· ose we perform one more time transform on the time nized among themselves, each receiver starts behaving as a max max tr [t0 k 2 , t0 + k 2 ]. Then the transformed time sender at level 1 and starts sending n reference broadcast will∈ lie in− the· interval · packets. In order to avoid collision of reference broadcast packets, a sender at level 1 delays the transmission of its n max max max max reference packets until it does not hear the reference packets t0 k , t0 + k + − · 2 − 2 · 2 2 ¡

346

0.5

0.45

0.4

0.35

0.3

0.25 erf(x) 0.2 max σ Probability Number of messages 0.15 0.5 0.95 16 0.1 0.5 0.99 28

0.05 0.5 0.999 44

"erf" 0 1.0 0.95 4 0 0.5 1 1.5 2 2.5 3 3.5 4 x 1.0 0.99 7 1.0 0.999 11 Figure 2: Error function of x versus x 2.0 0.95 1 2.0 0.99 2

2.0 0.999 3 max max = t0 (k + 1) , t0 + (k + 1)

− · 2 · 2 ¡ max Thus, the error is 2(k+1) 2 = (k+1) max. This proves Table 1: Variation in probability and number of our induction hypothesis.· · max messages for different values of σ Moreover, if p is the probability that the maximum error between two receivers within broadcast region of a sender is k max, then p is the probability that k max is the maximum error between two receivers which are· k hops apart. Since p < 1 pk < p, the larger the number of time transforma- tions, ⇒the lesser the probability of staying within an error bound. However, if we consider the average error over a max single hop to be erravg = 2 then the average error over k hops will be erravg √k (since variance is additive). This PSfrag implies that the error·propagation is sublinear. h b o x replacemen 6. EVALUATION to 0pt The error function erf (x) is a standard function and has  max

been plotted in Figure 2. The function is defined for nega- σ tive values of x, yet since erf ( x) = erf (x), we plot the ts − − function only for positive values of x. As shown in Figure 2, 1 the function asymptotically reaches the value of 0.5. Theo- 0.9 rem 1 gives the probability of achieved error being less than 0.8 a maximum specified error as 0.7

√n max 0.6

P (  max) = 2 erf

| | ≤ σ ¡ 0.5 Probability 0.4 We can derive a relationship between n i.e. the number of messages and the achieved probability P . This relationship 0.3 is plotted in Figure 3. Each of the three different curves 0.2 max corresponds to the ratio of 0.5, 1.0, and 2.0. Thus, 0.1 ratio=0.5 σ ratio=1 ratio=2 given an max and the probability P of achieving an error 0 0 5 10 15 20 25 30 35 40  max we can find the required number of messages. As number of messages exp≤ected, if the ratio increases we need lesser number of messages in order to achieve a desired probability i.e. n Figure 3: Probability of achieved error being less 2 ∝ σ than a maximum

. This proportionality suggests that once the max max has been specified, the number of messages required is very sensitive to the standard deviation. From Table 1, it is clear max that for lower values for the ratio of σ the number of messages required gets quite large. For example, to achieve max a probability of 0.99 with σ = 1, the algorithm requires max 7 messages whereas for σ = 2, the algorithm requires only 2 messages.

347

7. CONCLUSION 9. REFERENCES In this paper, we present and analyze a adaptive clock [1] Kopetz, H., wilhelm Ochsenreiter: Global time in synchronization protocol for sensor networks. This proto- distributed real-time systems. Technical Report 15/89, col is based on the earlier deterministic RBS protocol [3]. Technische Universitat Wien, Wien Austria (1989) The RBS protocol uses the concept of receiver-receiver syn- [2] Verissimo, P., Rodrigues, L., Casimiro, A.: chronization to achieve better synchronization bounds than CesiumSpray: A Precise and Accurate Global Time traditional synchronization protocols. Our protocol, being Service for Large-Scale Systems. Journal of Real-Time a probabilistic one, is not bound by the limit given by Lun- Systems 12 (1997) 243–294 delius et al. [10]. In our protocol, we periodically send n [3] Elson, J., Girod, L., Estrin, D.: Fine-Grained Network messages to probabilistically keep the clocks of the sensor Time Synchronization using Reference Broadcasts. In: network within the specified error bound. Our contributions Proceedings of the 5th Symposium on Operating in this paper are three-fold: Systems Design and Implementation, Boston, Massachusetts (2002) We extend the deterministic RBS protocol to provide • [4] Arvind, K.: Probabilistic Clock Synchronization in adaptive clock synchronization, allowing the trade-off Distributed Systems. IEEE Transactions on Parallel between the synchronization accuracy and the resources and Distributed Systems 5 (1994) 474–487 used by the protocol. [5] Cristian, F.: Probabilistic Clock Synchronization. We analyze the protocol to derive expressions for syn- 3 (1989) 146–158 • chronization overhead (in terms of number of mes- [6] Mills, D.: Internet Time Synchronization: The sages) and synchronization interval. For example, we Network Time Protocol. IEEE Transactions on show that to achieve a synchronization error less than Communications 39 (1991) 1482–1493 σ of the distribution with a confidence probability of [7] Elson, J., Romer, K.: Wireless Sensor Networks: A 99%, the protocol requires 7 synchronization messages New Regime for Time Synchronization. In: First per interval. We show how to convert service spec- Workshop on Hot Topics in Networks, Princeton, New ifications (maximum clock synchronization error and Jersey (2002) confidence probability) to actual protocol parameters [8] Lamport, L.: Time, Clocks, and the Ordering of (minimum number of messages and synchronization in- Events in a Distributed System. Communications of terval). the ACM 21 (1978) 558–565 [9] Srikanth, T.K., Toueg, S.: Optimal Clock We also extend the RBS protocol to handle multi- Synchronization. Journal of the ACM 34 (1987) • hop clock synchronization in which all nodes need not 626–645 be within single-hop range of a clock synchronization sender. Those nodes not within single-hop range will [10] Lundelius, J., Lynch, N.: A new fault-tolerant receive synchronization with some degradation of the algorithm for clock synchronization. In: Proceedings bounds, when compared to single-hop case. of the Third annual ACM Symposium on Principles of Distributed Computing, Vancouver, Canada (1984) We are currently implementing our adaptive clock syn- 75–88 chronization protocol in Berkeley sensor motes to show its [11] Romer, K.: Time Synchronization in Ad Hoc performance experimentally. We would like to build actual Networks. In: Proceedings of the Second ACM applications for sensor networks that utilize our adaptive International Symposium on Mobile Ad Hoc clock synchronization service. Networking and Computing, Long Beach, California (2001) 8. ACKNOWLEDGEMENTS [12] Huang, L., Lai, T.H.: On the Scalability of IEEE 802.11 Ad Hoc Networks. In: Proceedings of the Third This work was supported in part by NSF under grants ACM International Symposium on Mobile Ad Hoc ANI-0338856, CNS-0325971, and ANI-0209204, by NASA Networking and Computing, Lausanne, Switzerland under grant NAG3-2534, and by a gift from Schlumberger. (2002) The views and conclusions contained here are those of the [13] Ganeriwal, S., Kumar, R., Srivastava, M.B.: authors and should not be interpreted as necessarily repre- Timing-sync Protocol for Sensor Networks. In: senting the official policies or endorsements, either express Proceedings of the 1st ACM Conference on Embedded or implied, of NSF, NASA, Schlumberger, Rice University, Networked Sensor Systems (SenSys), Los Angeles, or the U.S. Government or any of its agencies. California (2003)

348