cBook‎ > ‎

System Identification

DC Motor Speed: PID Controller Design

posted May 3, 2015, 4:31 PM by Javad Taghia   [ updated May 3, 2015, 4:31 PM ]

DC Motor Speed: PID Controller Design

Key MATLAB commands used in this tutorial are: tf , step , feedback


From the main problem, the dynamic equations in the Laplace domain and the open-loop transfer function of the DC Motor are the following.

(1)$$ s(Js + b)\Theta(s) = KI(s) $$

(2)$$ (Ls + R)I(s) = V(s) - Ks\Theta(s) $$

(3)$$ P(s) = \frac{\dot{\Theta}(s)}{V(s)} = \frac{K}{(Js + b)(Ls + R) + K^2}  \qquad [\frac{rad/sec}{V}] $$

The structure of the control system has the form shown in the figure below.

For the original problem setup and the derivation of the above equations, please refer to the DC Motor Speed: System Modeling page.

For a 1-rad/sec step reference, the design criteria are the following.

  • Settling time less than 2 seconds
  • Overshoot less than 5%
  • Steady-state error less than 1%

Now let's design a controller using the methods introduced in the Introduction: PID Controller Design page. Create a new m-file and type in the following commands.

J = 0.01;
b = 0.1;
K = 0.01;
R = 1;
L = 0.5;
s = tf('s');
P_motor = K/((J*s+b)*(L*s+R)+K^2);

Recall that the transfer function for a PID controller is:

(4)$$ C(s) = K_{p} + \frac {K_{i}} {s} + K_{d}s = \frac{K_{d}s^2 + K_{p}s + K_{i}} {s} $$

Proportional control

Let's first try employing a proportional controller with a gain of 100, that is, C(s) = 100. To determine the closed-loop transfer function, we use the feedback command. Add the following code to the end of your m-file.

Kp = 100;
C = pid(Kp);
sys_cl = feedback(C*P_motor,1);

Now let's examine the closed-loop step response. Add the following commands to the end of your m-file and run it in the command window. You should generate the plot shown below. You can view some of the system's characteristics by right-clicking on the figure and choosing Characteristics from the resulting menu. In the figure below, annotations have specifically been added for Settling TimePeak Response, and Steady State.

         t = 0:0.01:5;
         title('Step Response with Proportional Control')

From the plot above we see that both the steady-state error and the overshoot are too large. Recall from the Introduction: PID Controller Design page that increasing the proportional gain Kp will reduce the steady-state error. However, also recall that increasing Kp often results in increased overshoot, therefore, it appears that not all of the design requirements can be met with a simple proportional controller.

This fact can be verified by experimenting with different values of Kp. Specifically, you can employ the SISO Design Tool by entering the command sisotool(P_motor) then opening a closed-loop step response plot from the Analysis Plots tab of the Control and Estimation Tools Manager window. With the Real-Time Update box checked, you can then vary the control gain in the Compensator Editor tab and see the resulting effect on the closed-loop step response. A little experimentation verifies what we anticipated, a proportional controller is insufficient for meeting the given design requirements; derivative and/or integral terms must be added to the controller.

PID control

Recall from the Introduction: PID Controller Design page adding an integral term will eliminate the steady-state error to a step reference and a derivative term will often reduce the overshoot. Let's try a PID controller with small Ki and Kd. Modify your m-file so that the lines defining your control are as follows. Running this new m-file gives you the plot shown below.

Kp = 75;
Ki = 1;
Kd = 1;
C = pid(Kp,Ki,Kd);
sys_cl = feedback(C*P_motor,1);
title('PID Control with Small Ki and Small Kd')

Inspection of the above indicates that the steady-state error does indeed go to zero for a step input. However, the time it takes to reach steady-state is far larger than the required settling time of 2 seconds.

Tuning the gains

In this case, the long tail on the step response graph is due to the fact that the integral gain is small and, therefore, it takes a long time for the integral action to build up and eliminate the steady-state error. This process can be sped up by increasing the value of Ki. Go back to your m-file and change Ki to 200 as in the following. Rerun the file and you should get the plot shown below. Again the annotations are added by right-clicking on the figure and choosing Characteristics from the resulting menu.

         Kp = 100;
         Ki = 200;
         Kd = 1;
         C = pid(Kp,Ki,Kd);
         sys_cl = feedback(C*P_motor,1);
         step(sys_cl, 0:0.01:4)
         title('PID Control with Large Ki and Small Kd')

As expected, the steady-state error is now eliminated much more quickly than before. However, the large Ki has greatly increased the overshoot. Let's increase Kd in an attempt to reduce the overshoot. Go back to the m-file and change Kd to 10 as shown in the following. Rerun your m-file and the plot shown below should be generated.

         Kp = 100;
         Ki = 200;
         Kd = 10;
         C = pid(Kp,Ki,Kd);
         sys_cl = feedback(C*P_motor,1);
         step(sys_cl, 0:0.01:4)
         title('PID Control with Large Ki and Large Kd')

As we had hoped, the increased Kd reduced the resulting overshoot. Now we know that if we use a PID controller with

Kp = 100, Ki = 200, and Kd = 10,

all of our design requirements will be satisfied.

Interactively Estimate Plant from Measured or Simulated Response Data

posted Apr 12, 2015, 7:37 PM by Javad Taghia

Interactively Estimate Plant from Measured or Simulated Response Data

This example shows how to use PID Tuner to fit a linear model to SISO response data.

If you have System Identification Toolbox™ software, you can use the PID Tuner to estimate the parameters of a linear plant model based on time-domain response data. PID Tuner then tunes a PID controller for the resulting estimated model. The response data can be either measured from your real-world system, or obtained by simulating your Simulink® model. Plant estimation is especially useful when your Simulink model cannot be linearized.

PID Tuner gives you several techniques to graphically, manually, or automatically adjust the estimated model to match your response data. This topic illustrates some of those techniques.

Obtain Response Data for Identification

In the PID Tuner, in the PID Tuner tab, in the Plant menu, select Identify New Plant.

In the Plant Identification tab, click  Get I/O data. This menu allows you to obtain system response data in one of two ways:

Once you have imported or simulated data, the Plant Identification tab displays the response data and the response of an initial estimated plant. You can now select the plant structure and adjust the estimated plant parameters until the response of the estimated plant is a good fit to the response data.

Adjust Plant Structure and Parameters

PID Tuner allows you to specify a plant structure, such as One PoleTwo Real Poles, or State-Space Model. In the Structure menu, choose the plant structure that best matches your response. You can also add a transfer delay, a zero, or an integrator to your plant.

In the following sample plot, the one-pole structure gives the qualitatively correct response. You can make further adjustments to the plant structure and parameter values to make the estimated system's response a better match to the measured response data.

PID Tuner gives you several ways to adjust the plant parameters:

  • Graphically adjust the estimated system's response by dragging the adjustors on the plot. For example, for a one-pole structure, drag the red x to adjust the estimated plant time constant. PID Tuner recalculates system parameters as you do so. In the following sample plot, it is apparent that there is some time delay between the application of the step input (at t = 5 s), and the response of the system to that step input.

    In the Plant Structure section of the tab, check Delay to add a transport delay to the estimated plant model. A vertical line appears on the plot, indicating the current value of the delay. Drag the line left or right to change the delay, and make further adjustments to the system response by dragging the red x.

  • Adjust the numerical values of system parameters such as gains, time constants, and time delays. To numerically adjust the values of system parameters, click  Edit Parameters.

    Suppose that in this example you know from an independent measurement that the transport delay in your system is 1.5 s. In the Plant Parameters dialog box, enter 1.5 for τ. Check Fix to fix the parameter value. When you check Fix for a parameter, neither graphical nor automatic adjustments to the estimated plant model affect that parameter value.

  • Automatically optimize the system parameters to match the measured response data. Click  Auto Estimate to update the estimated system parameters using the current values as an initial guess.

You can continue to iterate using any of these methods to adjust plant structure and parameter values until the estimated system's response adequately matches the measured response.

Save Plant and Tune PID Controller

When you are satisfied with the fit, click  Save Plant. Doing so saves the estimated plant, Plant1, to the PID Tuner workspace. Doing so also selects the Step Plot: Reference Tracking figure and returns you to the PID Tuner tab. The PID Tuner automatically designs a PI controller for Plant1, and displays a response plot for the new closed-loop system. The Plant menu reflects that Plant1 is selected for the current controller design.

    Tip   To examine variables stored in the PID Tuner workspace, open the Data Browser.

You can now use the PID Tuner tools to refine the controller design for the estimated plant and examine tuned system responses.

You can also export the identified plant from the PID Tuner workspace to the MATLAB® workspace for further analysis. In the PID Tuner tab, click  Export. Check the plant model you want to export to the MATLAB workspace. For this example, exportPlant1, the plant you identified from response data. You can also export the tuned PID controller. Click  OK. The models you selected are saved to the MATLAB workspace.

Identified plant models are saved as identified LTI models, such as idproc or idss.

    Tip   Alternatively, right-click a plant in the Data Browser to select it for tuning or export it to the MATLAB workspace.

System Identification for PID Control

posted Apr 12, 2015, 7:35 PM by Javad Taghia

System Identification for PID Control

Plant Identification

In many situations, a dynamic representation of the system you want to control is not readily available. One solution to this problem is to obtain a dynamical model using identification techniques. The system is excited by a measurable signal and the corresponding response of the system is collected at some sample rate. The resulting input-output data is then used to obtain a model of the system such as a transfer function or a state-space model. This process is called system identification orestimation. The goal of system identification is to choose a model that yields the best possible fit between the measured system response to a particular input and the model's response to the same input.

If you have a Simulink® model of your control system, you can simulate input/output data instead of measuring it. The process of estimation is the same. The system response to some known excitation is simulated, and a dynamical model is estimated based upon the resulting simulated input/output data.

Whether you use measured or simulated date for estimation, once a suitable plant model is identified, you impose control objectives on the plant based on your knowledge of the desired behavior of the system that the plant model represents. You then design a feedback controller to meet those objectives.

If you have System Identification Toolbox™ software, you can use PID Tuner for both plant identification and controller design in a single interface. You can import input/output data and use it to identify one or more plant models. Or, you can obtain simulated input/output data from a Simulink model and use that to identify one or more plant models. You can then design and verify PID controllers using these plants. The PID Tuner also allows you to directly import plant models, such as one you have obtained from an independent identification task.

For an overview of system identification, see About System Identification in the System Identification Toolbox documentation.

Linear Approximation of Nonlinear Systems for PID Control

The dynamical behavior of many systems can be described adequately by a linear relationship between the system's input and output. Even when behavior becomes nonlinear in some operating regimes, there are often regimes in which the system dynamics are linear. For example, the behavior of an operational amplifier or the lift-vs-force dynamics of aerodynamic bodies can be described by linear models, within a certain limited operating range of inputs. For such a system, you can perform an experiment (or a simulation) that excites the system only in its linear range of behavior and collect the input/output data. You can then use the data to estimate a linear plant model, and design a PID controller for the linear model.

In other cases, the effects of nonlinearities are small. In such a case, a linear model can provide a good approximation, such that the nonlinear deviations are treated as disturbances. Such approximations depend heavily on the input profile, the amplitude and frequency content of the excitation signal.

Linear models often describe the deviation of the response of a system from some equilibrium point, due to small perturbing inputs. Consider a nonlinear system whose output, y(t), follows a prescribed trajectory in response to a known input, u(t). The dynamics are described by dx(t)/dt = f(xu), y = g(x,u) . Here, x is a vector of internal states of the system, and y is the vector of output variables. The functions f and g, which can be nonlinear, are the mathematical descriptions of the system and measurement dynamics. Suppose that when the system is at an equilibrium condition, a small perturbation to the input, Δu, leads to a small perturbation in the output, Δy:


For example, consider the system of the following Simulink block diagram:

When operating in a disturbance-free environment, the nominal input of value 50 keeps the plant along its constant trajectory of value 2000. Any disturbances would cause the plant to deviate from this value. The PID Controller's task is to add a small correction to the input signal that brings the system back to its nominal value in a reasonable amount of time. The PID Controller thus needs to work only on the linear deviation dynamics even though the actual plant itself might be nonlinear. Thus, you might be able to achieve effective control over a nonlinear system in some regimes by designing a PID controller for a linear approximation of the system at equilibrium conditions.

Linear Process Models

A common use case is designing PID controllers for the steady-state operation of manufacturing plants. In these plants, a model relating the effect of a measurable input variable on an output quantity is often required in the form of a SISO plant. The overall system may be MIMO in nature, but the experimentation or simulation is carried out in a way that makes it possible to measure the incremental effect of one input variable on a selected output. The data can be quite noisy, but since the expectation is to control only the dominant dynamics, a low-order plant model often suffices. Such a proxy is obtained by collecting or simulating input-output data and deriving a process model (low order transfer function with unknown delay) from it. The excitation signal for deriving the data can often be a simple bump in the value of the selected input variable.

Advanced System Identification Tasks

In the PID Tuner, you can only identify single-input, single output, continuous-time plant models. Additionally, the PID Tuner cannot perform the following system identification tasks:

  • Identify transfer functions of arbitrary number of poles and zeros. (PID Tuner can identify transfer functions up to three poles and one zero, plus an integrator and a time delay. PID Tuner can identify state-space models of arbitrary order.)

  • Estimate the disturbance component of a model, which can be useful for separating measured dynamics from noise dynamics.

  • Validate estimation by comparing the plant response against an independent dataset.

  • Perform residual analysis.

If you need these enhanced identification features, import your data into the System Identification Tool (systemIdentification). Use the System Identification Tool to perform model identification and export the identified model to the MATLAB®workspace. Then import the identified model into PID Tuner for PID controller design.

For more information about the System Identification Tool, see Identify Linear Models Using System Identification App.

Related Examples

Second Order System PD Design

posted Apr 12, 2015, 7:33 PM by Javad Taghia

Include gadget (iframe)

System Identification from Step Response Matalab

posted Apr 12, 2015, 7:31 PM by Javad Taghia

Extras: System Identification


System parameters such as the damping ratio, the natural frequency, and the DC gain can be found using the step response or bode plot.

Estimating the Order of a System

The order and relative degree of a system can be estimated from either the step response or the bode plot. The relative degree of a system is the difference between the order of the denominator over the order of the numerator of the transfer function and is the lowest order the system can be.

Step Response

If the response of the system to a non-zero step input has a zero slope when $t=0$, the system must be second order or higher because the system has a relative degree of two or higher.

If the step response shows oscillations, the system must be a second order or higher underdamped system and have a relative degree of two or higher.

Bode Plot

The phase plot can be a good indicator of order. If the phase drops below -90 degrees, the system must be second order or higher. The relative degree of the system has to be at least as great as the number of multiples of -90 degrees achieved asymptotically at the lowest point on the phase plot of the system.

Identifying a System from the Step Response

DC Gain

The DC gain, $K$, is the ratio of the steady state step response to the magnitude of a step input.

Damping Ratio

For an underdamped second order system, the damping ratio can be calculated from the percent overshoot using the following formula:

(1)$$ \zeta = \frac{-\ln \left( \frac{\%OS}{100} \right)}{\sqrt{\pi^2+\ln^2 \left( \frac{\%OS}{100} \right)}} $$

where \%OS is the percent overshoot, which can be approximated off the plot of the step response.

Natural Frequency

The natural frequency of an underdamped second order system can be found from the damped natural frequency which can be measured off the plot of the step response and the damping ratio which was calculated above.

(2)$$ \omega_n = \frac{\omega_d}{\sqrt{1-\zeta^2}} $$


(3)$$ \omega_d = \frac{2\pi}{\Delta t} $$

and $\Delta t$ is the time interval between two consecutive peaks on the plot of the step response.

Identifying a System from the Bode Plot

DC Gain

The DC Gain of a system can be calculated from the magnitude of the bode plot when $s=0$.

(4)$$ K = 10^{M(0)/20} $$

where $M(0$) is the magnitude of the bode plot when $jw=0$.

Natural Frequency

The damping ratio of a system can be found with the DC Gain and the magnitude of the bode plot when the phase plot is -90 degrees.

(5)$$ \zeta=\frac{K}{2\cdot10^{M(-90^o)/20}} $$

Identifying the System Parameters

If the type of system is known, then specific physical parameters may be found from the dynamic metrics determined above.

The general form of the transfer function of a first order system is

(6)$$ G(s) = \frac{b}{(s+a)}=\frac{K}{\tau s+1} $$

The general form of the transfer function of a second order system is

(7)$$ G(s) = \frac{a}{s^2+bs+c} = \frac{K\omega_n^2}{s^2+2\zeta\omega_n+\omega_n^2} $$

Matlab Simulink DC motor system identification

posted Apr 12, 2015, 7:28 PM by Javad Taghia

Estimating Parameters of a DC Motor

1-6 of 6