Introduction: System Modeling

The first step in the control design process is to develop appropriate mathematical models of the system to be controlled. These models may be derived either from physical laws or experimental data. In this interactive live script, we quickly review the models of the two classical dynamic systems developed in the Introduction: System Modeling web page, a simple mass-spring-damper system and an LRC circuit. In this page, we investigate the time response of these two systems for different system parameters and different inputs. Investigating these two systems will help us to better understand the more complex systems that we investigate elsewhere in the Controls Tutorial website and in the other live script pages. Having a model and understanding a system's dynamics helps us in the process of designing its controller.
Key MATLAB commands used in this tutorial are: ss , tf

Example: Mass-Spring-Damper System

The free-body diagram for this system is shown below. The spring force is proportional to the displacement of the mass, x, and the viscous damping force is proportional to the velocity of the mass, . Both forces oppose the motion of the mass and are, therefore, shown in the negative x-direction. Note also that corresponds to the position of the mass when the spring is unstretched.
Now we proceed by summing the forces and applying Newton’s second law, in each direction. In this case, there are no forces acting in they-direction; however, in the x-direction we have:
This equation, known as the governing equation, completely characterizes the dynamic state of the system. Later, we will see how to use this to calculate the response of the system to any external input, , as well as to analyze system properties such as stability and performance.
To determine the state-space representation of the mass-spring-damper system, we must reduce the second-order governing equation to a set of two first-order differential equations. To this end, we choose the position and velocity as our state variables.
The position variable captures the potential energy stored in the spring, while the velocity variable captures the kinetic energy stored by the mass. The damper only dissipates energy, it doesn't store energy. Often when choosing state variables it is helpful to consider what variables capture the energy stored in the system.
The state equation in this case is:
If, for instance, we are interested in controlling the position of the mass, then the output equation is:
Rearranging the original governing equation, we arrive at the equivalent differential equation model where we understand the left-hand side of the equation captures the natural dynamics of the system, while the right-hand side is the forcing input for the system.
An alternative model called the transfer function can be found by taking the model into the Laplace domain and then rearranging it into the form output divided by input. Taking the Laplace transform of the above equation assuming zero initial conditions:
and then rearranging assuming a force input and displacement output results in the following transfer function:

System Free Response

Now we will demonstrate how to create the models derived above within MATLAB and will investigate the free response of the system (its position ) for different parameter values. First, let's attempt to understand how the system's parameters affect its behavior. The roots of the transfer function model's denominator (called poles) indicate the system's natural transient behavior. (These are also the roots of the system's characteristic equation.) Applying the quadratic formula, we arrive at the following:
If the damping coefficient is sufficiently large that the poles are purely real and distinct, then the system is said to be overdamped and the system's natural dynamics will decay exponentially (poles are negative) without oscillation. If the damping coefficient is small enough that the poles are complex, then the system is underdamped and the system's natural response will oscillated with decaying amplitude. The imaginary part of the pole (ω) corresponds to the frequency of oscillation, while the real part of the pole is the exponent in the expression which captures the speed with which the amplitude of the oscillation decays.
The following interactive script includes sliders that allow you to vary the values of the systems mass m, viscous damping coefficient b, and spring constant k. As these parameters are varied, you can observe the effect on the mass-spring-damper system's poles, as well as its natural response when the mass is given an initial position (with no forcing input and no initial speed).
m =60;
b =10;
k =60;
A = [0 1; -k/m -b/m];
B = [0 1/m]';
C = [1 0];
D = [0];
sys = ss(A,B,C,D);
t = 0:0.1:50;
0;
u = 0*t;
x0 = [1 0];
[y] = lsim(sys,u,t,x0);
pzmap(sys);
title('Pole Locations')
axis([-5,0,-5,5])
plot(t,y);
grid
xlabel('Time (seconds)')
ylabel('Position of Mass (x(t))')
title('System Free Response')
For further investigation of how to analyze how a system's behavior changes with different parameter values and different inputs, please visit the Introduction: System Analysis page.

Example: RLC Circuit

Like Newton’s laws for mechanical systems, Kirchoff’s circuit laws are fundamental analytical tools for modeling electrical systems. Kirchoff’s current law (KCL) states that the sum of the electrical currents entering a node in a circuit must equal the sum of electrical currents exiting the node. Kirchoff’s voltage law (KVL) states that the sum of voltage differences around any closed loop in a circuit is zero. When applying KVL, the source voltages are typically taken as positive and the load voltages are taken as negative.
We will now consider a simple series combination of three passive electrical elements: a resistor, an inductor, and a capacitor, known as an RLC Circuit.
Since this circuit is a single loop, each node only has one input and one output; therefore, application of KCL simply shows that the current is the same throughout the circuit at any given time, . Now applying KVL around the loop and using the sign conventions indicated in the diagram, we arrive at the following governing equation.
We note that that the governing equation for the RLC circuit has an analogous form to the mass-spring-damper mechanical system. In particular, they are both second-order systems where the charge (integral of current) corresponds to displacement, the inductance corresponds to mass, the resistance corresponds to viscous damping, and the inverse capacitance corresponds to the spring stiffness. These analogies and others like them turn out to be quite useful conceptually in understanding the behavior of dynamical systems.
The state-space representation is found by choosing the charge on the capacitor and current through the circuit (inductor) as the state variables.
where,
The state equation is, therefore:
We choose the current as ouput as follows:
The transfer function representation may be found by taking the Laplace transform as we did for the mass-spring-damper or from the state-space equation as follows:
The RLC state-space and transfer function models can be entered into MATLAB using the same procedure as discussed for the mass-spring-damper system above.

System Free Response

Examining the effect of the parameters R, L, and C on the circuit's poles and free response further drive home the relationship between the circuit and the mass-spring-damper system.
The effect of the parameters on the real and imaginary part of the poles can be understood as described above. You will notice that this circuit's transfer function additionally has an s in the numerator. Just as roots of the denominator are called poles, roots of the numerator are called zeros. This system has a zero at s = 0. Zeros affect a system's behavior too, but in this case the location of the zero is not affected by the circuit's parameters. In the following, an initial charge is placed on the capacitor and then allowed to discharge as current is released through the circuit. In the pole-zero map, the zero at the origin is indicated by an O, while the poles are indicated by Xs.
L =100;
R =10;
C =0.01;
A = [0 1; -1/(L*C) -R/L];
B = [0 1/L]';
C = [0 1];
D = [0];
sys = ss(A,B,C,D);
t = 0:0.1:50;
0;
V = 0*t;
x0 = [1 0];
[y] = lsim(sys,V,t,x0);
pzmap(sys);
title('Pole and Zero Locations')
axis([-5,0,-5,5])
plot(t,y);
grid
xlabel('Time (seconds)')
ylabel('Current through Circuit (i(t))')
title('System Free Response')

System Identification

In this section, we have seen how to model systems using basic physical principles; however, often this is not possible either because the parameters of the system are uncertain, or the underlying processes are simply not understood. In these cases, we must rely on experimental measurements and statistical techniques to develop a system model, a process known as system identification.
System identification may be performed using either time-domain or frequency-domain data, see the Extras: System Identification page for further details. A couple of system identification activities can also be found from the Hardware tab located at the top of pages in the Controls Tutorial website.
Also refer to MATLAB’s System Identification Toolbox for more information on this subject, as well as the “Estimate Process Model” and “Estimate State-Space Model” live editor tasks that you can find in your live script under the “Tasks” menu as seen in the snapshot below. For SISO systems, you can use the Estimate Process Model task to interactively estimate and validate a process model. The Estimate State-Space Model task lets you interactively estimate and validate a state-space model using time or frequency data.

System Conversions

Most operations in MATLAB can be performed on either the transfer function, the state-space model, or the zero-pole-gain form. Furthermore, it is simple to transfer between these forms if the other representation is required. If you need to learn how to convert from one representation to another, see the Extras: System Conversions page.