Abstract
Distributed sensor systems require clock synchronization between all sensor nodes to provide consistent view of the overall system. Owing the growing size of networks, the evaluation of the synchronization performance becomes difficult, if done by means of experiments. Simulation is another method to tackle this issue. Realistic simulation of synchronization schemes requires accurate modelling of oscillators which are the driving timers generating various events. One way to characterise oscillators is to utilize the Allan variance, which can be used to generate a phenomenological model based on power spectral density. Since discrete event simulation (DES) tools are widely used to model network protocols, models which combine accuracy and performance are needed. This paper presents a model that was optimised for use in DES. To verify that the simulation results sufficiently match measurements, an implementation in OMNeT++ was done. The results show that the behaviour of distributed sensor systems, resulting from imperfect timebases, can be accurately simulated.
1. Introduction
Common timebases in distributed sensor networks are a prerequisite for many applications in automation or instrumentation. They permit event ordering and the synchronization of actions across a network, even if these networks are not genuine real-time networks. Industrially relevant examples from the recent past are the LXI (LAN extensions for instrumentation) standard [1, 2], where IEEE 1588 [3] is used for distributed test and measurement, as well as for many industrial automation networks [4]. Sensor applications that are spatially distributed also significantly benefit from an accurate, common timebase. Examples for this are remote metering applications, data acquisition in particle accelerators, as well as structural health monitoring of bridges.
Ways to establish such a distributed timebase rely on appropriate clock synchronization strategies. Many methods have been devised and investigated in the past, such as the network time protocol (NTP) [5], the precision time protocol (IEEE 1588), or various academic approaches [6–9]. For all such synchronization approaches, evaluation of steady-state and transient performance (in terms of synchronization errors) is a central question. This is not an easy task since the processes leading to synchronization imperfections are mostly of stochastic nature and therefore difficult to describe. In some cases, analytical bounds can be found, which are however typically very coarse. Additionally, contemporary applications demand both large-scale, possibly heterogeneous networks and high accuracy. Implementations of distributed measurement and control [10] have to be evaluated (simulated) regarding their achievable performance [11] in order to show the feasibility of a networked control system as well as to optimise control algorithms. As analytical bounds may become too conservative, simulation-based behavioural investigations can come closer to the actual performance of a clock synchronization scheme.
The challenge for simulation approaches is the quality of the underlying models, and in particular the models of the oscillator as actual time reference. State-of-the-art simulators are event driven to achieve maximum performance. Compared to the time constants in a behavioural system simulation (typically in the ms range and above), an oscillator running at several 100 MHz is a continuous process which would slow down the simulation significantly if modelled in a straightforward way tick by tick. Therefore, this paper proposes a new model for oscillators combining high accuracy and efficient implementation to allow for simulation of large sensor networks with a high number of nodes.
Section 2 discusses the problem in more detail. Sections 3 and 4 are devoted to the behaviour and characterisation of oscillators and the modelling approach derived from it. Section 5 describes the actual implementation of the simulation model, and Section 6 presents an experimental verification. Finally, Section 7 draws conclusions.
2. Problem Definition
Straightforward continuous-time simulation (as done by, e.g., SPICE and its derivatives) is widely used for low-level, physical effects but has the drawback that even short simulation time spans are very compute intensive. Another technique well suited for digital systems is to assign a discrete point on a time scale to all important events and start the simulation with the occurrence of this time. This approach is usually known under the term discrete event simulators, and they are the state-of-the-art tools for network simulation (for instance ns-3 [12] or OMNeT++ [13]) or system and circuit design (like ModelSim [14]). In the case of the first two oscillators, respective clocks are modelled as a static, absolute in terms of the physical definition perfect reference to time. Thus, in order to model imperfect clocks users typically implement simple drift models where the absolute time is changed with linear models such as, for example, in the
In this kind of simulation approach, systems are simulated in terms of individual events rather than a continuous time scale. These events are typically stored in a global event list, which contains the actual event and the triggering time of the event. The advantage is that this approach dynamically scales to the requirements of the simulation scenario in terms of timely resolution. For example, if one wants to simulate a distributed sensor system, which acquires data once a second, the time in between two samples does not need to be simulated in detail. However, the actual measurement and initial processing timespan could need a very fine grained simulation. Exactly this is the strength of a DES system, which tackles this by processing all events according to a virtual time scale.
The oscillator model must take into account stochastic frequency and phase variations. In addition, for DES systems, the model typically must provide the number of oscillator ticks elapsed from simulation start until any given arbitrary simulation time without actually running the simulation up to that point. Given the stochastic nature of the oscillator, this is a challenge as it has to be possible to incrementally draw samples for points which are close to each other without producing inconsistent output. It has to be noted that this modelling explicitly considers only the stochastic error, rather than parameters such as temperature dependency or errors due to vibration. The actual requirements for this simulation model therefore boil down to the following:
the behaviour of the simulator output has to be quantised. For an oscillator model, the generated ticks have to be assigned to a discrete simulation time. This is usually no problem as it is possible to have a much finer grained simulation time scale than the actual requirements to the result. For example, the least possible difference between two events in a DES system can be picoseconds when the simulation accuracy aims at values in the nanosecond range; the model has to support two basic request types: it must be possible to request the number of ticks elapsed until a given simulation time and also vice versa, that is, obtain the simulation time reached by a given number of ticks; all data have to be consistent. Pairs of simulation time and ticks
In addition, in general the always limited resources of a simulation environment have to be considered. In this sense, the most limiting factors are the available memory and the processing time. The above requirements could be easily satisfied by storing the exact time of every single oscillator tick. However, this is unfeasible due to the lack of memory. Thus, a caching strategy has to be developed where—for the sake of consistency—already calculated and scheduled events (instead of the ticks themselves) can be stored.
3. Related Work
The behaviour of an oscillator is in many ways production dependent. One key parameter is the technology. Nowadays, many types of oscillators are available, starting at low—cost AT—cut crystals used in the commonly known XOs (crystal oscillators). Here, the main influence factor on the frequency, the temperature, is neither physically stabilised nor mathematically compensated. The latter is done in the so-called microcontroller compensated oscillators (MCXOs), where the actual temperature is taken into account and the output frequency is corrected with a preconfigured temperature-frequency calibration curve. The most expensive crystal oscillators are oven controlled oscillators (OCXOs). This type of oscillators stabilises the ambient temperature of the crystal to a certain temperature. Additionally—to increase the performance—a special crystal selection process is done for the latter two types.
The actual stability of an oscillator depends on several external parameters, such as the above-mentioned temperature. Furthermore, supply voltage and mechanical effects like vibrations influence the output signal. All of these effects can be summarised in terms of their impact on the frequency stability or equivalent phase stability. The following considerations take a constant set of these parameters into account and characterise in a first step only the behaviour of an oscillator in a stable environment.
3.1. Frequency Domain Characterisation
Oscillators exhibit a variety of instabilities which are manifested in phase and frequency changes. A portion of these instabilities are well-known deterministic trends, like frequency and phase offset, drift, and periodic terms. A typical model for this is published in [15].
These instabilities cause a linear (or at most quadratic) time error term that can be easily corrected, for example, by clock synchronization with a control loop. However, for a complete model of an oscillator, it is also necessary to include the stochastic trends. According to [16], this noise can be categorised depending on the power spectral density (PSD),
(a) White Noise Family
White, bandwidth-limited noise, probably the best known noise family, is an uncorrelated, random noise process which has a constant power spectral density for all frequencies in its band. In the case of oscillators, the noise processes usually have a normal or Gaussian distribution.
In particular, two types of white noise are contributing: the commonly called white noise phase modulation (WPM,
(b) Flicker Noise Family
This noise family is usually also referred to as pink or flicker noise, which has as its identification property a
Theories about the cause of flicker noise are relatively vague. Some sources [18] say that FPM,
The spectrum of the FFM has a power spectral density, proportional to
(c) Random Walk Noise
This noise type can be identified by its typical
More commonly the power spectral density of the frequency noise
3.2. Time Domain Characterisation
In the time domain, the so-called Allan variance is used to estimate the stability of a clock. The introduction of this measure is necessary, since the classical variance diverges for a certain type, random walk noise. It is the typical effect of an oscillator's frequency to depart with variable progression and direction from the nominal frequency. As for this effect, the (temporal) mean value does not converge, also the variance does not show useful results. The Allan variance solves this issue for all noise types commonly observed in crystal oscillators. It is easy and fast to compute as well as more accurate in estimating noise processes [20–22]. The Allan variance
Using this algorithm, the Allan variance has become a de-facto standard to predict the quality of clocks. Nevertheless, it should be noted that for the computation of
Finally, it has to be mentioned that a relationship between the time and frequency domain exists which is defined by [19]
3.3. DES Clock Models
There have been attempts to bring realistic notion of time to discrete event simulation systems in literature. The main issue with DES is the one virtual time scale which is shared amongst the different components of the system, thereby making them perfectly synchronized. To make the simulation more realistic, it is necessary to introduce, as in the real world, statistically independent oscillator models every spatially distributed device. In [24], such a local clock modelling approach for DES is introduced. The clock model provides an API for other node's modules and implements several mapping utilities: (a) conversion from local time to virtual time, (b) conversion from virtual to local time, (c) conversion of local duration to virtual duration, and (d) conversion of virtual duration to local duration. With this conversions functionality, it is easy to map the nodes' notion of time to a global, absolute perfect time scale. While this solution is generic and can be easily applied in simulation, the issue of realistic clock behaviour still remains. Although the clock model exhibits most of the deterministic characteristics of real world clocks (time and frequency offset, drift, etc.), the random processes described in Section 3.1 are modelled by simple white noise which is not efficient for simulations that require high precision clock synchronization.
4. Oscillator Model Concept
Based on the considerations in the previous sections, the actual task is to model the five noise types. For this matter, the PSD of the noise can be useful, since it is deterministic and independent of time (for these certain noise types). The approach is the following.
If a random signal

Concept of the oscillator model. A filter, with a frequency response equal to the power spectral density of an oscillator, is used to extract similar noise behaviour from a bandwidth-limited white noise. The exact properties of the dashed box, which contains five filter elements, are developed in this section. So far, it is only important that the box as a whole forms the spectrum according to the Allan variance of the oscillator.
Therefore, the key step is to define the PSD of the noises. However, since it is easier to perform time-based measurements and, therefore, calculate the Allan variance, the relation between the Allan variance and the power spectral density has to be found.
For a system with limited bandwidth, this correspondence between the Allan variance and the power spectral density is given by [16]
The modification concerns the always positive cutoff frequencies
4.1. Power Spectral Density Correspondence
Using (11), the Allan variance on a limited bandwidth,
As it can be seen from inserting (10) into (12), the integral is defined only for
Additionally, the theorem of transposed integral limits can be used to obtain a solution for nonzero lower cutoff frequencies, that is,
This result can be checked, by using the lemma of JORDAN to get a limit for the integralsine [27]
In consequence, using the fact that the second fraction (
4.2. Power Spectral Density Forming
After the measurement of the Allan variance, the
A second approach is to make an approximation of the Allan variance by calculating a fitting curve using the least-square method [28]. Another way to do the approximation can be done using the infinity norm
The next step is to bring the PSD function of the oscillator noise into a form that the transfer function
Due to the fact that the input signal of the filter is white noise, the power spectral density of the output signal is
and factorizing the polynomial
where
Therefore, one can consider
If one examines one of the first four parts of the cascade more closely, it is clear that it has a 10 dB/decade slope. Since it is not possible to make a filter using discrete components which has this amplitude characteristics, an approximation is needed. This can be successfully done by the lead-lag-filter [29],
where the zeros,
5. DES Model Implementation
Following the approach explained above, the practical implementation of the oscillator model starts with the measurement of the Allan variance and the extraction of the spectrum defining a digital filter with the same frequency response as the analog white noise has to be modelled. Usually white noise is modelled using random number generators providing a normal distribution.
In practice, this problem turns out to be a linear optimisation of the
5.1. OMNeT++ Model Structure
As a basis for the model, a typical clock synchronization problem is taken as test case. In this scenario, the oscillator is used as a time reference for a clock. This clock consists of the clock logic that increases the value of the clock with each tick (or couple of ticks) of the oscillator by a variable increment. By the adjustment of this increment, the clock can be steered to a desired value. This clock is then synchronized by a second, in the context of this paper ideal master clock which is per definition running perfectly aligned with the time scale of the simulation. At predefined points in time, the master clock synchronizes the slave clock. The latter then requests from the oscillator model the number of ticks elapsed since the last clock update and calculates the actual local time with the current increment. Using this and a PI-controller structure, a new increment is calculated in order to steer the slave clock according to the transmitted timestamps of the master. From an implementation viewpoint, the more complicated case is another one: for a full integration into a typical OMNeT++ simulation, it has not only to be possible to request the number of ticks at the current simulation time, but also to request the number of ticks at a given simulation time in the future (or vice versa the simulation time at a future number of ticks). This prediction is necessary, for example, to schedule clock alarms at given times when an action of the simulated system has to be performed. The latter is relatively simple in the framework because it comes down to scheduling an interrupt. However, it is not that easy for the oscillator model, since it has to be ensured that the replies to requests are consistent. This consistency is twofold: first, a repeated request has to be answered in any case with the same value, and second, it has to be ensured that the number of ticks of request 1 is always smaller or equal to the ones of request 2, given that the simulation time for the ticks in request 1 is smaller.
5.2. Power Spectral Density Shaping
As it will be shown in Section 6, the oscillator model exhibits realistic behaviour in terms of the Allan variance; however, it has to be considered whether this is sufficient for direct implementation in a DES system. One evident drawback of the model is the fact that the oscillator and, hence, local time is incremented by single, small ticks. Not only is this resource consuming in case of a network containing a large number of clocks; but also, the actual advantage of the discrete event simulation concept explained in Section 2 cannot be used properly. Therefore, following this concept, the oscillator model has to be modified in a way that it is able to simulate long periods of time efficiently and also to keep the fine granularity when needed.
Inspired by multirate filtering, where filters with different sample rates are used within a system to achieve processing efficiencies [30], a filter structure was designed which shapes the PSD according to the one of a real-world oscillator. The main idea behind this concept is to employ several filters with different sampling rates where each of them models the noise within a certain frequency band. Therefore, longer period of time would be calculated with the help of a filter modelling an oscillator with relatively low frequency. In case finer granularity is needed, the intermediate values would be obtained employing a second filter.
By combining the outputs of the filters, the requested time intervals can be simulated in an optimised manner. The reason for using this approach instead of the standard multirate filtering method is that the proposed solution provides more realistic results for the oscillator noise on higher frequencies. While in multirate filtering, the values are obtained by interpolation, in the proposed approach the filters with higher sampling rates have the same power spectral density as the short-term oscillator noise. Since the long-term behaviour of the overall structure is determined by the transfer function of the 1 ms filter shown in Figure 2, the rest of the filters only need to cover a part of the overall frequency range of the oscillator noise. Hence, their transfer functions can be simpler than the one defined by (30). A comparison of the Allan variance plots is shown in Figure 3. The figure shows the variance of the real-world oscillator and the variance of an oscillator noise simulated using a filter cascade with a sampling time of 1 ms. Besides these, the figure shows the variance obtained using the proposed approach and by using a multirate filter. In the last case, the values were obtained in two stages. In the first one, the noise was computed using the filter cascade for

The structure of the OMNeT++ oscillator model.

Comparison of Allan variance for various modeling approaches. The filter cascade (red) according to (31)–(35) has a tight matching to the measured Allan variance (black). The disadvantage, that is, poor performance, is solved by multirate filters (green) and with better fitting using the proposed model (blue).
Finally, in the OMNeT++ implementation, three filters,
Even with the improvements, the model would be still ineffective if the simulation time was calculated from the oscillator start-up time for every request. Instead, the last calculated simulation time and number of ticks (together with the current filter values) are stored whenever an event is processed. These values are then used later on as reference points for calculating future events. The structure of the OMNeT++ model is shown in Figure 2.
6. Model Evaluation
In order to evaluate the model, two test cases have been examined. In the first case the oscillator model was used as the time reference for a free running clock, and the time error between the simulation time and the clock was recorded in order to calculate the Allan variance. In the second case, a real-world measurement results were compared to the output of the oscillator model.
6.1. Free Running Clock
In the first scenario, the OMNeT++ oscillator model was applied to the time reference of a free running clock with nominal period equal to

Comparative time domain plot of the output of the simple and the proposed oscillator model for an exemplary simulation run. While the simple model only shows simple jitter around the (compensated) nominal frequency, the proposed model also includes other noise effects and therefore provides more realistic behaviour compared to a real oscillator.
Although Figure 4 shows the principle working scheme of the proposed oscillator model, a comparison between a real-world measurement would not make any sense as the considered curve is the manifestation of a random variable.
In a next and quantitatively more interesting step, a comparison of the Allan deviation of the model and a real-world clock can be done. For this experiment, a simulation was set up such that after every 0.1 s of simulation time the number of elapsed ticks was requested from the oscillator. Based on the ticks, the local time and the Allan variance of the free running clock were calculated. As shown in Figure 5, the long-term behaviour of the model corresponds to the behaviour of the measured oscillator: the flicker floor is reached in the range 1–10 s, and at larger sampling time, the variance increases.

The Allan variance plot of the measured oscillator and the OMNeT++ oscillator model.
This result can now be used to compare the proposed oscillator model to a usual white-noise model. A comparison study like this is done in Figure 6. In this figure, the desired u-shape of the proposed model can be seen. As expected, the Allan variance plot of a simple white noise compares to that of a single slope without the important contributions of the other noise types.

Comparison between the simple oscillator model and the proposed multinoise model. As shown in this graph, the proposed model covers more slopes of the spectrum.
6.2. Synchronized Clock
Finally, to prove the practicability of the oscillator model, a typical simulation has been set up. In this scenario, a comparison between the simple model and real-world experiments typically fails. The test includes two instances of an oscillator. The master is set up to send out a synchronization message periodically at a given number of ticks. The slave receives the synchronization messages and steers its local clock with this information. The steering is done using a PI control algorithm commonly used for IEEE 1588 and a clock model with an adaptable speed (or increment). The main question behind this experiment is to investigate the influence of the longest reasonable synchronization interval. As it can be seen from the Allan variance of Figure 5, an absolute minimum is reached in the area of

Comparison between the simple oscillator model and the proposed multinoise model with a real-world measurement.
7. Conclusions
Discrete event simulators are an efficient tool to simulate distributed sensor networks that need clock synchronization across a large number of nodes. However, in order to have meaningful results, accurate oscillator models are needed. The presented approach proposes a modelling strategy, which uses proper design of a noise filter to allow for a resource-saving implementation. The filter is shaped in a fashion which not only models the white-noise contributions to the output of an oscillator, but also the flicker components as well as the integral parts of the latter. It is shown by a real-world oscillator comparison that the output of the OMNeT++ model implements the same noise types in terms of the Allan variance. This oscillator model has been verified by comparing a real free running oscillator with the one simulated using the proposed model, and the results show a very good match between the two. The practical work for this paper showed that the intermediate step to calculate the
Footnotes
Acknowledgments
This project was partly financed by the province of Lower Austria, the European Regional Development Fund, the FIT-IT project ε-WiFi under Contract 813319, the EU under the FP7 STREP flexWARE Contract no. 224350, and Oregano Systems Design and Consulting. The authors would like to thank Roman Beigelbeck for his assistance in this project.
