# Modeling

We propose the following cyber-physical system model. The model is considered a cyber-physical because it consists of both physical components (oscillators) and cyber components (finite state machines, computation modules)

Figure 2 – a full cyber-physical system

## Overview

### The Phase Oscillator model

The Phase Oscillator model is the simplest way we can describe an oscillator system. The state of the system is represented by the state variable θ ∈ [0, 2π], and θ = 0 = 2π. It represents the angle going around the unit circle. The unit circle is embedded into a complex plane. So θ becomes the angle between the positive real axis and the vector as shown in Figure 3 below.

Figure 3 – the phase oscillator model

The state variable θ is further placed into the sin() function, and can be visualized as in Figure 4 below.

Figure 4 – rotating phasor and sine wave

The cyber-physical system in Figure 2 consists of two oscillators. They are described with differential equations. Both of the oscillators run with their own intrinsic frequencies. The oscillator on the right does not get any feedback, and always run at the constant rate of change. Thus, it is called a master oscillator. On the other hand, we provide feedback to the physical system that is on the left. The feedback to the system is either 0 or 1. We can make an analogy with a simple switch: 0 = OFF and 1 = ON. When the switch is ON, the system speeds up by a particular constant. Otherwise, it runs at its own frequency. If two systems are synchronized, the feedback will be OFF all the time. The physical system on the left is called a slave oscillator.

Because we have an interface in the system, in our case a network, we inevitably will have a delay. Moreover, because we are sending the actual value of the phase, there is no way we will be able to achieve 100% synchronization of two oscillators. For this reason, we decided to solve this problem by doing the following:

1. Introduce ordinary time as a state of the system.
2. Pick particular phase value that will serve as a point of synchronization. In our case, we picked θ = π or the point where sine wave crosses the zero line from positive to negative.
3. Stamp the time when θ = π and send the time-stamp through the network.

The computation module does the following:

1. Receive the time-stamp from the master.
2. Receive the time-stamp from the slave.
3. Calculate the time difference.
4. Restart the timer of the “switch” control module to the calculated value.

The system can be expanded from two oscillators to many by adding desired amount of slave systems. All of the slaves will be synchronized to the master.

## Detailed discussion on modeling

### Modeling of the physical components

#### Model of the first physical system (A master system)

The frequency of the oscillation is determined by a state constant ω. As a result, we can describe the physical system with the following simple differential equation:

As shown in Figure 2, both of the physical systems run with their intrinsic frequencies and . The physical system on the right has no inputs and always runs at the frequency .

#### Model of the second physical system (A slave system)

The system on the left, on the other hand, has an input. The input is provided to speed up the frequency of the slave by some constant C, and catch up to the frequency of the master.

The control algorithm for the input is explained further in the post.

### Modeling of the cyber components

#### Time stamping

We designed a finite state machine (FSM) that keeps track of the state variable θ, and stamps the time when sin(θ) passes zero line from positive to negative. Refer to Figure 5 for visual representation of the FSM design.

Figure 5 – time stamping FSM

The FSM has three states, and constantly makes loop transitions from 1->2->3->1…As long as the sine wave is on the positive side of the y-axis, the FSM remains in the first state. When the wave crosses the zero line, the state machine makes transition to the state two, samples the time, and immediately passes to the state three. It remains in the third state while the sine wave is on the negative side of the y-axis.

This is the mathematical model of the FSM:

The output function K is:

where t is an ordinary time.

The transition function is defined as follows:

Finally, the description of this FSM with difference and differential equations is:

#### Model of the computation module

The computation module

• accepts two time-stamps;
• outputs the difference of the stamps;
• and restarts the timer of the feedback control module.

To assure accuracy, the output must become available only when both inputs have the most updated value. In other words, if one of the inputs has outdated timestamp the calculation will be misleading. Consider the following example:

Imagine that at some point it took the timestamp from the network longer than usual. Which means that the computation module still has the value that was sampled before. Meanwhile at the slave CPS, the FSM might have sampled the time several times. The computation of the old value from the master and the new value from the slave will result in misleading phase difference.

We resolved this issue by introducing a finite-state machine. The FSM assures that the data is sampled in a particular order:

• First, get the update from the network.
• Second, get the update from the local system.
• Third, compute the new value.

Refer to Figure 6 for visual representation of this FSM.

Figure 6 – computation module FSM

The FSM has four states, and constantly makes loop transitions from 1->2->3->4->1… The FSM waits in the first state until the updated timestamp is received. This event can be triggered when the network timer is expired. In the second, state the FSM updates the value and immediately jumps to the state three. Then, the FSM waits in that state until the local timestamp is received. This event can be triggered when the state of timestamping FSM is the state two. In the state four, we compute the value and immediately go back to the state one.

We can describe this FSM mathematically:

The output function K is:

The transition function is defined as follows:

Finally, the description of this FSM with difference and differential equations is:

#### Model of the network

The networking technologies that we use these days does not guarantee a periodic delivery of the packets. To model a nonperiodic behavior, we define sequence of the events:

Where t represents a moment in time, and the sequence satisfies the following property:

Further, we must introduce the mechanism that will trigger the event. To do this, we define the countdown timer . When the timer expires, the following two things happen:

• the timer is reset to a random number between and ;
• the input that is fed into the the network is sampled and made available to the output;

To summarize, we will describe the whole network through difference and differential equations.

#### The feedback control algorithm

The slave physical system behaves according to the following differential equation:

The value of the u is controlled by the timer:

The timer behaves according to the following differential equation:

The timer is reset by the computation module whenever it makes new value available to the output:

where x equals to the value computed by computation module. This value is proportional to the phase difference of two systems.

where  is the local time-stamp, and  is the time-stamp sent from the master through the network. Every time the slave system speeds up, it becomes closer to the master. Consequently, the value of approaches 0, which implies the synchronization of the system.

#### Define state vector x, flow map, and jump map

All of the difference and differential equation described above can be grouped into a single state variable x.

In the overall system we have 5 components that trigger jumps: three FSMs, one network timer, and feedback control timer. To cover the whole jump map we have consider all of the combinations of the events. Table 1 shows all possible triggers, where each of the columns represent event generators and black boxes represent occurrence of the event. In total, we have 31 possible unique combinations of the events.

Table 1 – event table

The continuous dynamics of the state is defined by:

The discrete dynamics of the state should be changed according to the table 1, and Figure 2.