System Identification
DC Motor Speed: PID Controller Design
DC Motor Speed: PID Controller DesignKey MATLAB commands used in this tutorial are: tf , step , feedback ContentsFrom the main problem, the dynamic equations in the Laplace domain and the openloop transfer function of the DC Motor are the following. (1) (2) (3) 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 1rad/sec step reference, the design criteria are the following.
Now let's design a controller using the methods introduced in the Introduction: PID Controller Design page. Create a new mfile 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) Proportional controlLet's first try employing a proportional controller with a gain of 100, that is, C(s) = 100. To determine the closedloop transfer function, we use the feedback command. Add the following code to the end of your mfile. Kp = 100; C = pid(Kp); sys_cl = feedback(C*P_motor,1); Now let's examine the closedloop step response. Add the following commands to the end of your mfile and run it in the command window. You should generate the plot shown below. You can view some of the system's characteristics by rightclicking on the figure and choosing Characteristics from the resulting menu. In the figure below, annotations have specifically been added for Settling Time, Peak Response, and Steady State. t = 0:0.01:5; step(sys_cl,t) grid title('Step Response with Proportional Control') From the plot above we see that both the steadystate error and the overshoot are too large. Recall from the Introduction: PID Controller Design page that increasing the proportional gain Kp will reduce the steadystate 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 closedloop step response plot from the Analysis Plots tab of the Control and Estimation Tools Manager window. With the RealTime Update box checked, you can then vary the control gain in the Compensator Editor tab and see the resulting effect on the closedloop 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 controlRecall from the Introduction: PID Controller Design page adding an integral term will eliminate the steadystate 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 mfile so that the lines defining your control are as follows. Running this new mfile gives you the plot shown below. Kp = 75;
Ki = 1;
Kd = 1;
C = pid(Kp,Ki,Kd);
sys_cl = feedback(C*P_motor,1);
step(sys_cl,[0:1:200])
title('PID Control with Small Ki and Small Kd')
Inspection of the above indicates that the steadystate error does indeed go to zero for a step input. However, the time it takes to reach steadystate is far larger than the required settling time of 2 seconds. Tuning the gainsIn 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 steadystate error. This process can be sped up by increasing the value of Ki. Go back to your mfile 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 rightclicking 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) grid title('PID Control with Large Ki and Small Kd') As expected, the steadystate 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 mfile and change Kd to 10 as shown in the following. Rerun your mfile 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) grid 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
Interactively Estimate Plant from Measured or Simulated Response DataThis 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 timedomain response data. PID Tuner then tunes a PID controller for the resulting estimated model. The response data can be either measured from your realworld 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 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 Pole, Two Real Poles, or StateSpace 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 onepole 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:
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,
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, export Identified plant models are saved as identified LTI models, such as

System Identification for PID Control
System Identification for PID ControlPlant IdentificationIn 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 inputoutput data is then used to obtain a model of the system such as a transfer function or a statespace 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 ControlThe 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 liftvsforce 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(x, u), 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: Δ˙x=∂f∂xΔx+∂f∂uΔu,Δy=∂g∂xΔx+∂g∂uΔu. For example, consider the system of the following Simulink block diagram: When operating in a disturbancefree 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 ModelsA common use case is designing PID controllers for the steadystate 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 loworder plant model often suffices. Such a proxy is obtained by collecting or simulating inputoutput 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 TasksIn the PID Tuner, you can only identify singleinput, single output, continuoustime plant models. Additionally, the PID Tuner cannot perform the following system identification tasks:
If you need these enhanced identification features, import your data into the System Identification Tool ( For more information about the System Identification Tool, see Identify Linear Models Using System Identification App. Related Examples 
System Identification from Step Response Matalab