Sampled Systems

1 Simple Periodic Sampler

The following model is a simple periodic sampler with a sampling period T that is constant and defined as a parameter that can be changed by the model user. This model has only one kind of event, the sampling event. We use the built-in function sample in the when-condition sample(0, T) to periodically generate the sampling events with a period time T. This is a simple model using the state space equations.







2 Simple Periodic Sampler Clocked

A clocked version of the same model appears as follows. A clocked output variable y1 had to be introduced since only equations for clocked variables are allowed inside a clocked when-equation. The equation for the unclocked variable y which is just a hold version of y1, had to be placed outside the clocked when-equation.



We simplify even further by replacing the calls to the functions f and h by simple example expressions, removing the protected keyword to make the state variable x accessible for plotting, and setting u=time as an example instead of a real input signal:



This model contains clocked synchronous constructs that are not yet fully supported by OpenModelica as of October 2015, but may start working within the near future.Hence the Simulation of this models does not work





2.1 Unclocked version of VerySimplePeriodicSampler





3 Base Class for Sampling Models Unclocked

It is possible to formulate a base class for scalar sampling models using state-space equations.The class BaseSampler below can for example be specialized to either a periodic sampler or an aperiodic sampler.




We use two very simple example functions f2 and h2 for the redeclarations:





Below the base model is extended to a periodic sampling model
PeriodicSampler with a fixed period time T.



In order to simulate the model it is instantiated below.






4 Base Class for Sampling Models clocked

The clocked base sample model uses a clock variable doSample of built-in type Clock.




This model contains clocked synchronous constructs that are not yet fully supported by OpenModelica as of October 2015, but may start working within the near future.Hence the Simulation of this models does not work





5 Aperiodic Sampler Unclocked

Besides the above periodic sampler, an aperiodic sampling model with a time-varying sample period can be obtained by specializing the base class. A variable nextSampling is used for the next sampling time, which is current time + periodTime when the current time has reached the previous value of nextSampling. In this example we increase the period time by the logarithm of the current time just to have a time varying period time.






6 Aperiodic Sampler Clocked


This model contains clocked synchronous constructs that are not yet fully supported by OpenModelica as of October 2015, but may start working within the near future.Hence the Simulation of this models does not work




7 Discrete Scalar State Space Sampling Model

A discrete first order scalar state space model with periodic sampling can be formulated as follows, essentially being a special case of the above BaseSampler model even though we do not extend that class in this particular case.







Alternatively, the discrete scalar state space model can be expressed by extending the
BaseSampler model for periodic sampling and redeclaring the functions f and g as below. However, in this case the result is not shorter or more readable since the syntax for expressing the local functions f1 and h1 is not very concise. On the other hand, if the functions f1 and h1 instead would be used in several places, the modeling style based on replaceable functions would be preferable.






8 Discrete Vector State Space Sampling Model Clocked


This model contains clocked synchronous constructs that are not yet fully supported by OpenModelica as of October 2015, but may start working within the near future.Hence the Simulation of this models does not work




9 Discrete Vector State Space Sampling Model

Usually state space models are expressed using the more general vector form, as in the DiscreteVectorStateSpace periodic sampling model below:




9.1 Simulation of DVSSTest




10 Two Rate Sampling Model Unclocked

In the TwoRateSampler model below the slow sampler is five times slower than the fast sampler, i.e. the slowSample when-equation is evaluated at every 5th activation of the fastSample when-equation. The two samplers are synchronized via equations involving the cyCounter variable.



10.1 Simulation of TwoRateSampler




11 Two Rate Sampling Model Clocked


This model contains clocked synchronous constructs that are not yet fully supported by OpenModelica as of October 2015, but may start working within the near future.Hence the Simulation of this models does not work