**Summary** – This post describes two ways of implementing an elementary RC network using the *acausal* modelling capabilities of Dymola, and also illustrates its filtering application. We will observe the properties of the network as a first order filter & noting Dymola’s causal & acausal modelling capabilities & automated computer algebra system.

The elementary system under consideration can be evaluated in many ways, and as long as one is not too concerned with the details of transient effects, this especially includes frequency-domain methods, which can deliver elegant solutions to the steady behaviour & range of stability of such systems.

Carrying out a time-domain, explicit analysis demonstrates the ease & flexibility of using Dymola, after which the user can easily proceed to nonlinear, time-variant systems that are less easily tackled by undergraduate signals & systems material.

Download a copy of this article as a pdf: ‘A State-Space Model of a simple RC Network in Dymola & potential Applications‘

**Introduction**

A simple resistor-capacitor (RC) circuit, Figure 1, consists of resistor (R) and capacitor (C) and an input voltage (V_{in}). It is assumed that the properties of the components are time-invariant for this demonstration, as can be seen from the expressions that will be developed below.

*Figure 1: An elementary RC network with a driving voltage*

Modelling of such electrical circuit can be cast in several ways. For linear systems, one useful approach is state-space modelling. This demonstration uses a continuous-time state-space model, implemented in Dassault Systemes’ Dymola software. Simple filtering applications are also discussed.

**Modelling**

The following steps describe a path to a state-space model for this linear, time-invariant system.

**Identification of the Inputs and Outputs of the Plant**

Based on the schematic of Figure 1, we suppose that input voltage V_{in }can be regulated. We label this the input. This is quite realistic should we wish to move on to practical applications, from signalling, to power delivery & so on.

Outputs are even more subjective. They really depend on what we’re interested in. So as to demonstrate the filtering ability of an RC network, we choose to see the voltage across the resistor, V_{R} and that across the capacitor, V_{C}, each as an output variable.

**Analysis by Inspection of the Underlying Energetics**

The following observations help us to conclude what the possible states of the system are:

- The resistor is unable to store any energy. It generates no electromotive force, under any circumstances (we note here that the resistor is assumed to have no inductance & no stray capacitance, because it is an idealised construct).
- The capacitor stores charge at a potential. As a result, its state influences the development of any current in the system.

We therefore infer that the state at any given time is described completely by:

- The stored charge in the capacitor, which we will label
^{1}*x(t)* - We note that the time derivative is current
*i(t)*with which we are familiar. Also note that in Figure 1 current flowing through the capacitor is the same current flowing through resistor, since resistor and capacitor are in series.

**Development of State & Output Equations via Fundamental Laws**

**Component Constitutive Relations**

It has been assumed that the resistor is Ohmic. As a result, the following constitutive equation applies, with *i* referring to the current passing through the resistor.

*Equation 1: Empirical relation known as Ohm’s Law assumed to apply*

It has been further supposed that the capacitor also displays idealised behaviour, such that the voltage across the capacitor is proportional to the stored charge. This represents the region of linear operation for a typical capacitor.

*Equation 2: Constitutive relation of a linear capacitor, with C representing a constant capacitanc*e

Due to Kirchhoff’s Laws the sum of currents converging on a point is zero & the sum of potential differences in a closed circuit is also zero.

**State Space Form**

State space systems are written in the following (Ogata, 2002) form. A generalised form for nonlinear equations exists, however the linear, time-invariant form, with matrices of coefficients multiplying the state vector & control vector are those usually intended by the term.

*Equation 3: Standard form of a linear, time-invariant state-space system*

The vector function *x(t)* represents the state of the system. Function *y(t)* represents outputs while function *u(t)* represents some control input that can be prescribed. A, B, C and D are state, input, output and direct transmission matrices respectively.

**Formulation of State Equation**

Expressing the charge in the capacitor *x(t)* in the form given in Equation 1, we first observe that Kirchhoff’s laws require:

*Equation 4: Potential differences add to zero. Charge on the capacitor is the chosen state variable, represented by x.*

The constitutive relation for the resistor (“Ohm’s Law”) noting that the rate of change of the charge on the capacitor is the same as current & that the input voltage is playing the role of input, referring to the form given by Equation 3 we obtain:

*Equation 5: Current through the resistor is equated to the sum of EMFs*

Comparing this to Equation 3 the new Equation 5 is of the form required, with the following relations implied:

*Equation 6: Matrix A implied by the constitutive relations*

*Equation 7: Matrix B implied by the constitutive relations*

**Formulation of Output Equation**

Due to the simplicity of this initial example system, one can make relatively trivial observations as to how to derive equations explicit in the outputs, which were selected as .

The simplest observation about the outputs is a restatement of Equation 2:

*Equation 8: Output equation: voltage across capacitor*

Using this, we reach the following directly via Kirchhoff’s Voltage Law:

*Equation 9: Output equation: voltage across resistor*

Combining the two:

*Equation 10: Output equation with outputs using their original notation*

Or adopting the state-space notation for the outputs:

*Equation 11: Output equation using conventional state-space notation for the outputs (y)*

Equations 6, 7 and 10 would be automatically derived by Dymola and would not require the user to supply them.

**Implementing the Model**

**Acausal Implementation**

Implementation instructions for the model below will be given in upcoming posts, but the code has been included in the appendix. This code is automatically generated by the GUI only, but can be copied to your own package structure if needed.

*Figure 2.a: The RC network is depicted as an acausal equation-based model in Dymola*

**Causal Implementation**

The implementation of a causal “block” model will be shown in a later post. The following diagram describes the form in which such a model is constructed, as a closed-loop system, using blocks, defined in Dymola with specified I/O and algorithmic, stepwise calculations, which are the norm in many industry standard software and represent a considerably less flexible and less error-resistant approach.

*Figure 2.b: The RC network is depicted as a reference signal (external input voltage)*

The block implementation calculates current based on the sum of EMFs then uses that result to integrate for the capacitor voltage, completing the closed loop.

**Experimentation with the Model**

**Steady-State Simulation**

The response to a sinusoidal (cosine) input voltage of 4.2V and excitation frequency of 0 Hz is simulated for 30s. Keeping Kirchhoff’s laws in mind, it can be seen that at any given time the sum of voltages appears to sum to zero, with the capacitor rising to equal the applied voltage, thus stopping the current, making the voltage drop at the resistor zero.

*Figure 3: A step input voltage charges the capacitor until the current stops*

**Low Frequency Input**

Taking a note of the steady-state response we found, a sinusoidal excitation with a frequency of 0.2rad/s or 0.03183 Hz is introduced. The amplitude is 4.2 V again.

*Figure 4: The voltage response of RC network at the excitation frequency of 0.2 rad/s*

**High Frequency Input**

A much higher frequency is now used as input, arbitrarily, we select 10 rad/s or 1.59 Hz is simulated for 10s, as this is substantially greater. Therefore, comparing to steady state simulation in Figure 3 the input votltage oscillates several times during the simulation at high frequency.

*Figure 5: For a high frequency input V _{R} follows the input, not V_{C}*

This time, the potential drop across the resistor follows the input close to exactly. Meanwhile the voltage on the capacitor lags behind and rises to only a small amplitude.

In summary, from the simulation results above, it is evident that, at a very low frequency, most of the voltage is passed on to the capacitor, whereas at high frequencies, most of the voltage passed through the resistor. Thus, if we consider the capacitor voltage as the output signal, the presented circuit can be used as a low pass filter at very low frequency. On the other hand, at high frequency signal, if we consider the resistor voltage as the output, then the presented circuit can be used as a high pass filter.

**Conclusion**

The construction of state-space equations has been examined for an elementary example system. Leaving implementation instructions for the simulation software for later posts, the Dymola software has been used to carry out an elementary design-of-experiment exercise, where the frequency response properties of the network are examined in an ad-hoc way, by time-domain simulations.

**Implications & Usefulness of Results**

**The Concept of Signal “Filtering”**

The idea of filtering refers to “listening” to some portions of a signal, but ignoring others, based on frequency. This extends to engineering systems, including, but not restricted to, electrical & (micro)electronic systems that will respond usefully to an imperfect input, by ignoring the aspects of the input representing spurious phenomena, and responding, and adjusting only to the useful information.

**Applications**

The most obvious use of this in everyday life is (or at least has been) analogue radio, where any aerial (disregarding the finer points of antenna theory for a moment) essentially receives all signals, and all RF noise, leaving the radio device to filter out all the unwanted signals and literally “listen” to that transmitted on a given frequency carrier-wave!

Filters (Storey, 2006) are also indispensable when dealing with “noisy” data which for inherent or extrinsic reasons contains (usually high frequency) oscillations that have nothing to do with the quantity being measured^{2} such as thermal white noise or semiconductor device “shot” noise.

A further source of high frequency noise can even be numerical differentiation, which is occasionally needed in order to measure rates of change that for some reason, whether fundamental or practical cannot be measured directly. The HF noise can be filtered back out again using a network that has a favourable frequency response.

**Implications for Modelling**

There are several ways to approach the frequency characteristics of elementary systems like the ones shown in this article. Linear systems, in their steady states, which are reflected by all three of the result plots we have provided can just as easily be looked at using a frequency domain approach, but the point here is that the acasual modelling of these systems allows one to investigate nonlinear, or time-variant systems easily, and evaluate the transient qualities.

Dymola is moreover, so trivially easy to use, by comparison to expert CAE tools standard in many industries, that a carefree quality, with a great degree of modularity is introduced for the user, which the example in this and related blogs serve as an interesting start for developing professionals.

**References**

Duffin, W. J., 1990. *Electricity & Magnetism. *4th ed. New York City: McGraw-Hill.

Ogata, K., 2002. *Modern Control Engineering. *4th ed. Upper Saddle River: Prentice-Hall.

Storey, N., 2006. *Electronics, A Systems Approach. *3rd ed. Coventry: Prentice-Hall.

**Appendix – Modelica Code**

The code draws on the Modelica standard library, and refers to the acausal model used to develop the plots in the main text.

model ModularRC "Model of modular RC circuit" extends Modelica.Icons.Example; Modelica.Electrical.Analog.Basic.Resistor Resistance( alpha=1e-3, i(start=0), useHeatPort=false, R=1, T_ref=293.15) annotation (Placement(transformation( extent={{-10,10},{10,-10}}, rotation=0, origin={-22,20}))); Modelica.Electrical.Analog.Basic.Ground G annotation (Placement( transformation(extent={{-10,-54},{10,-34}}, rotation=0))); Modelica.Electrical.Analog.Sources.CosineVoltage Vin( freqHz=0, V=4.2) annotation (Placement(transformation( origin={-50,0}, extent={{-10,-10},{10,10}}, rotation=270))); Modelica.Electrical.Analog.Basic.Capacitor capacitor(C=1) annotation (Placement(transformation(extent={{10,10},{30,30}}))); Modelica.Electrical.Analog.Sensors.VoltageSensor VR annotation (Placement( transformation( extent={{10,-10},{-10,10}}, rotation=180, origin={-22,48}))); Modelica.Electrical.Analog.Sensors.VoltageSensor VC annotation (Placement( transformation( extent={{10,-10},{-10,10}}, rotation=180, origin={20,48}))); equation connect(Vin.n, G.p) annotation (Line(points={{-50,-10},{-50,-20},{0,-20},{0, -34}}, color={0,0,255})); connect(Vin.p, Resistance.p) annotation (Line( points={{-50,10},{-50,20},{-32,20}}, color={0,0,255}, smooth=Smooth.None)); connect(Resistance.n, capacitor.p) annotation (Line(points={{-12,20},{-12,20},{10,20}}, color={0,0,255})); connect(capacitor.n, G.p) annotation (Line(points={{30,20},{40,20},{40,-20},{ 0,-20},{0,-34}}, color={0,0,255})); connect(VC.p, capacitor.p) annotation (Line(points={{10,48},{4,48},{4,20},{10,20}}, color={0,0,255})); connect(VC.n, G.p) annotation (Line(points={{30,48},{36,48},{36,20},{40,20},{ 40,-20},{0,-20},{0,-34}}, color={0,0,255})); connect(VR.p, Resistance.p) annotation (Line(points={{-32,48},{-40,48},{-40, 20},{-32,20}}, color={0,0,255})); connect(VR.n, capacitor.p) annotation (Line(points={{-12,48},{-6,48},{-6,20}, {10,20}}, color={0,0,255})); annotation ( Diagram(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100, 100}}), graphics={Text( extent={{-52,76},{46,60}}, lineColor={0,0,255}, textString="Linear RC Circuit")}), Documentation(info="<html> <p><span style=\"font-family: Calibri,sans-serif;\">A simple resistor-capacitor (RC) circuit consists of a resistor (R), a capacitor (C) and an input voltage (V<sub>in</sub>). The electrical elements (components) of this circuit are linear. </span></p> </html>"), experiment(StopTime=30, Tolerance=1e-005), __Dymola_experimentSetupOutput); end ModularRC;

^{1} *This is purely convention, such that the equations we arrive at will resemble the standard form of state-space models.*

^{2} *And often comes from the sensor itself*

**Written by: Raees B. K. Parambu – project Engineer & Sas Harrison – Systems Engineer**