|
8.2.2 Identifying the Dynamics of a DC Motor
In this example you will see how the Neural Networks package can be used to model the dynamics of a DC motor. The input signal is the applied voltage and the output signal is the angular speed of the motor.
Load the Neural Networks package and the data.
In[1]:=
In[2]:=
The input data is placed in u and the output data in y.
Check the dimensions.
In[3]:=
Out[3]=
Out[4]=
There are 200 data samples available, and the plant has one input and one output.
It is always a good idea to visually inspect the data before the modeling. This might allow you to detect any outliers in the data.
Show the input signal.
In[5]:=

Show the output signal.
In[6]:=

By inspecting the plots you might find outliers, which should be removed before the system identification procedure starts.
The first half of the data set is used for identification and the second half for validation of the model.
Divide the data into identification and validation data.
In[7]:=
It is a good idea to try a linear model first and then try to obtain a better nonlinear model. Using Maxwell's and Newton's laws, the following linear relationship for the DC motor could be expected.
 This means that the regressor should be chosen to x(t)={y(t-1) u(t-1)}, which is obtained by choosing =1, =1, and =1.
The linear model has three parameters, a, b, and, c. You specify and train this linear model structure with the following call.
In[11]:=
Find some information about the model.
In[12]:=
Out[12]=
The command NetComparePlot is very convenient for evaluating dynamic models. Depending on which option you choose, the model can be a simulator or a predictor. The model output is displayed together with the true output signal. This type of test is only fair if you use fresh data, that is, the validation data for the comparison.
Simulate the linear model and compare it with the true output signal.
In[13]:=

By including the whole data set in the call, and then indicating the validation data with the option ShowRange, you avoid transients in the beginning of the simulation.
You can also use the command NetSimulate or NetPredict directly instead of calling NetComparePlot.
It is hard to see any difference between the true and the simulated output signal in the plot, and, obviously, the linear model is quite good at explaining the relationship in the data. A nonlinear model will now be trained to see if it becomes better than the linear model. The dynamic model can be described by
 where g( , , ) is the neural network function whose parameters are to be trained.
Train an FF network on the DC-motor data.
In[14]:=

Depending on the initialization you may end up in any one of many local minima. Notice that the result changes if you reevaluate the training command due to the randomness in the initialization of the neural network. If the criterion at the end of the learning is larger than 0.05, you should repeat the command.
Simulate the nonlinear neural network model.
In[15]:=

The nonlinear neural network model should give an RMS error of less than half of what you obtained for the linear model. However, since the models are so good it is hard to see any difference in the plots. Instead you can look at the prediction errors, that is, the difference between the true output and the model output. To do that you can use the command NetPredictionError.
Compute and plot the prediction errors using the linear and nonlinear models.
In[16]:=

It should be evident from the plot that the prediction errors of the nonlinear model are much smaller than those of the linear model.
Since the model describing the DC motor has only two regressor components, it is possible to look at g( ,x). But since the linear and nonlinear models are very similar, it is hard to see anything other than a linear relationship.
Plot the nonlinear model of the DC motor.
In[20]:=

It is, however, fairly easy to plot the difference between the linear and nonlinear models. This can be done by extracting the linear parameters from the linear model and inserting them with opposite signs as a linear submodel in the nonlinear model. In Section 13.1, Change the Parameter Values of an Existing Network, more details are given on how you can change the parameters in an existing neural network.
Plot the difference between linear and nonlinear models.
In[21]:=

Now it is easy to see that the relationship is far from being linear.
An analytic expression of the dynamic model can be obtained by using the neural net placed at the first position.
Express the neural ARX model analytically.
In[24]:=
Out[24]=
Similarly, it might be interesting to have the equation of the plane describing the first linear ARX model.
Describe the first linear ARX model.
In[25]:=
Out[25]=
|