Let's imagine that you want a system to be controlled. Therefore, you go to Simulink, you build the model, you simulate it, you compare the response obtained in simulation with your real measured data, and you see that they do not match, what happened? Are you sure that you have found the correct parameters for your model? No? Don't worry about it, with Simulink Design Optimization it is straight forward to discover this, you will only need actual measured data from your system, and then we will see how to estimate the parameters of your model. Actually, if you want more, we could use the same toolbox to get a proper response from the system according to your requirements.
Simulink Design Optimization is an exciting toolbox since it allows you to use some optimization methods to minimize a cost function. This toolbox is commonly used for dynamical systems, as seen in control systems. It can help you in improving your system response and estimate the parameters of your model. On this blog, the most important features of Simulink Design Optimization will be covered to give you a complete insight. Two important topics which will be discussed here:
First, we will use Parameter estimator app to match the response of a simulated model in Simulink comparing its response with real measured data, we will see that some previous steps will need to be done until estimate the model parameters like do preprocessing data.
Then, for the other approach, we are using the Response optimizer app to get a proper system response for some user-given requirements, there will be different ways to do this, and we will see the main ones.
Note: You must have Simulink Design Optimization Toolbox installed in your MATLAB. To check if it is present, use >>ver in MATLAB Command Window and locate this toolbox.
Simulink Design Optimization for parameter estimation
Simulink design optimization allows us to find some parameters of our model if they are missed or even give us an insight into possible parameter values according to the system's response (measured data). Next, we will introduce the model that we are using for parameter estimation.
In this case, we have chosen a MATLAB built-in model: Engine Throttle model. The throttle system controls the flow of air and fuel mixture to the engine cylinders. There is a butterfly valve that opens when a driver presses the accelerator pedal. Opening this valve and depending on how the valve opens the engine speed will increase or decrease.
As you see, there are two subsystems:
- T= torque applied to the motor
- Kt= torque gain
- Td=time delay
- U=current input applied to the motor
This model contains the butterfly valve dynamics
- J= valve inertia
- C=valve viscous friction
- K= valve spring constant
- : angular position and velocity.
Also there is a term which block the valve angular position between 15-90 degrees:
Sometimes our data is noisy and contains unexpected values (also called outliers. Despite this, It could be improved. Actually, with Simulink design optimization, it is possible to remove noise and, in general, do preprocessing of data (scale, offset removal, filters, replacing outliers, etc.). Let's see how real and simulated data looks!
Comparing real data vs simulated data
Let's imagine that real measured data is given, let's plot the measured data, for this, you have to run the model in Simulink and see how the workspace in MATLAB is updated.
For this, write spe_engine_throttle1 on MATLAB command windows
If that does not work, write: load('spe_engine_throttle1.mat') on MATLAB command windows
For simulated output data it is nothing but to see the graph in your scope block in Simulink:
As you see, Real Output measured is, actually, noisy. This response is established about in 0.15 seconds, while the Simulated Output does it in about 0.33 seconds. So maybe the parameters of your model may not be the same as the real model. So, you could think about it is time to use the Parameter estimator app to do model parameters fit the real response. However, notice that because of Real Output measured remains noisy, it could be so difficult to obtain real values. Don't worry; using the Parameter estimator app is also possible to remove noise in signals and, in general, do preprocessing data.
I want you to first notice that simulated data is going until 0.5 seconds while measured data is until 0.7 seconds, so, let's cut the data, go to Simulink, and then select the app menu, finally find and choose Parameter estimator.
Now click on the Experiments menu and select New Experiment:
- Write: [time1,position1]
- Write: [time1,input1]
Then select Save As, now you will see how Exp_1 data is created in the Experiments window. Now select Exp_1 data and select plot measured experiment data.
You will notice now that there are some outliers values in the data. They are not expected, so it is time to remove them. Go again to the Experiment plot menu but now choose to replace data. Doing this will be useful for the estimation algorithm!
- Select the last 7 outlier values
- Choose replace with constant value option and select 90
Then do the same for the other outlier values, replace them by 15, 15, and 86. Then apply the changes and see the new data. Choosing these values will provide the data which is more flatter!
This is an optional step, maybe you could be interested in applying some filter to smoothen the signal. Go again to the experiment plot menu and select a low-pass filter. Choose 0.4 as the value for normalized cutoff frequency and then choose your filter as a first-order one.
Then apply the changes, and finally, your signal will be ready to be used for estimating your real model values.
This is the easiest part of the app. The next step is to choose what parameters you want to find, let's say we are interested in estimating J, c, input delay, and k values. So, go to parameters window => Edit => Select Parameters.
Now select the mentioned previously:
Now, save your session, and then feel free to click on the Estimate option!
Note: Please ensure that your data has been selected for estimating as is shown below, in fact, remember we are using two different kinds of data, one for estimating and the other for validation, the second one will be used later to compare if our estimated parameters are correct.
Next, click again in the estimate, and you should wait while MATLAB computes the parameter values when the algorithm finishes you could see the graphs. This one shows you the number of iterations and function cost values as well.
This other one shows the final real and simulated signals so that you can compare the results of parameter estimation, you will notice how the cost function values are decreasing, which is good! This means our parameters are being estimated correctly.
Now that our parameters have been updated, It would be a good idea to validate if we change the input, the real data will be similar to simulated data to identify if there was or not some kind of overfitting in the estimated parameters. Go now to Experiments window and add next real data measures:
- Validation1: for output signal use [time2,position2] while for input [time2,input2]
- Validation2: for output signal use [time3,position3] while for input [time3,input3]
Next, do right click on validation1 and select it as use experiment for validation, then do click on validate option, then, do the same for Validation2 experiment. You will see something like this:
So, the result is not as expected since, in both cases, graphs Measured and Simulated should be similar; this is because the estimation is overfitted. We have to recompute the estimated parameters, go to parameter windows, and do them be only positive. Then do the estimation again:
So, ensure your minimum data value is zero for all your parameters!
Then, re-estimate the parameter values again and do the validation again, if the parameters are well estimated, the validation graphs should be like:
Simulink Design Optimization for Response Estimation
Now, we are exploring some approaches that could be used for response estimation.
Using time-domain specifications
We are using a MATLAB built-in model: watertank_stepinput, so you can open or create this model from the command window.
The Water-Tank system is given by:
- A= cross-sectional area
- b= flow rate constant
- a= flow rate constant
- H= height of the water in the tank
- V= voltage applied to the pump
This is a nonlinear model with single-input and single-output (SISO), where the height of the water is the output. We are starting with adding the model parameter values:
Go to the model workspace and add the model values:
Now, there are different forms to specify the time-domain requirement, let's use the most friendly one! We are using Check Step Response Characteristics block, only be sure that this block is connected to the system output.
And add your time-domain requirements:
Now click on Ok and open response optimizer app
Click on plot model response
Black lines show the boundary constraints for time-domain requirements (settling time, rise time, so on) so, when optimization finishes, the model response should accomplish these boundaries.
Now it is time to select the parameters of the controller to obtain the desired response. Select Ki and Kp.
Next step is to click on optimize, and finally, the result is shown:
The final response (blue) met all the requirements, and Kp and Ki values are updated!
Specifying a tracking signal
With response optimization, you could improve your time-domain requirements as shown previously, but also you could try to track some reference signal
Let's say we are interested in tracking a reference r(t) = 1-exp(-t) but first we are using another model (previous does not work since we have already designed a PI controller)
So let's consider the next model:
Initialize the controller parameters in the value that you want, create the variables in the model workspace.
Remember update your PID block as shown below:
Now, go to new requirements and select Signal tracking.
Also, remember to select and add the system output signal because this signal is the one that should track the reference.
Then plot the actual model response :
The optimized response is:
Simulink Design Optimization is an excellent tool if you are looking for how to estimate parameters of a model, you can both estimate and validate the obtained parameters, and this will help you to notice if there is any overfitting or underfitting as well. On the other side, you can use the estimating Parameter not only for your model but also to find your best controllers for any requirements and even if you need to track some user-defined reference.
Get instant access to the code, model, or application of the video or article you found helpful! Simply purchase the specific title, if available, and receive the download link right away! #MATLABHelper #CodeMadeEasy
Ready to take your MATLAB skills to the next level? Look no further! At MATLAB Helper, we've got you covered. From free community support to expert help and training, we've got all the resources you need to become a pro in no time. If you have any questions or queries, don't hesitate to reach out to us. Simply post a comment below or send us an email at [email protected].
And don't forget to connect with us on LinkedIn, Facebook, and Subscribe to our YouTube Channel! We're always sharing helpful tips and updates, so you can stay up-to-date on everything related to MATLAB. Plus, if you spot any bugs or errors on our website, just let us know and we'll make sure to fix it ASAP.
Ready to get started? Book your expert help with Research Assistance plan today and get personalized assistance tailored to your needs. Or, if you're looking for more comprehensive training, join one of our training modules and get hands-on experience with the latest techniques and technologies. The choice is yours – start learning and growing with MATLAB Helper today!
Education is our future. MATLAB is our feature. Happy MATLABing!