You are on page 1of 11

SYSTEM ID & ADAPTIVE

CONTROL


Laboratory 1


AUT University
Written By Jonathan Currie
October 2009
Jonathan Currie, p 1

Exercise 1a

Black Box Offline Identification


Aim
Identify an ARX model of the black box.

Background
Inside the black box is an active filter, which we wish to identify using System Identification techniques.
As this is a white room experiment, we assume there is no noise and thus we will fit an ARX model.

The DAQ has a input voltage range of +-10V and an output voltage range of 0-5V. Pin 13 should be
connected to the Black Box input (Analog Output) and Pin 1 should be connected to the Black Box
output (Analog Input). You also need a reference ground, obtained by connected Pin 3 to +12V on the
power supply.

There is a specially written toolbox for this laboratory: the AUT System ID Toolbox, found in the
Simulink Library Browser.


Step
Scope
Bl ack Box
Jonathan Currie, p 2

Method

1) Setup the black box experiment as below:


2) Start Matlab -> Simulink and create a new model.

3) Using the AUT System ID Toolbox, create the following model:



Use the following setup:
- Use the Black Box Block corresponding to your DAQ
- Zero-Order Hold with a sample time of 1
- Step with a Step Time of 20 and a Final Value of 4
- Random Number with a mean of 0 and a variance of 1

Zero-Order
Hol d
si mout
To Workspace
Step
Random
Number Manual Swi tch
Lab1a
Bl ack Box
USB 1208LS
24V 12V 0V
24V
12V
0V
USB
DAC ADC
13 1 3
Jonathan Currie, p 3

4) Setup the simulation to run for 100 samples, and use the following procedure:

- Make sure the manual switch is in the off position (no noise added), and click run
- The initial delay allows the plant to settle to zero, before a step test is performed at t = 20.
- At around t = 50, enable the noise input.

You should obtain something similar:



Note the initial settling delay is required as an initial transient is caused by the DAQ.

5) Input & Output data will be collected in the structure simout. Your task now is to extract the
collected data after the step test when the noise has been added. Using this data, as performed
in Assignment 4 Question 2b, fit an ARX model of the desired order to the data.

Hint: Use iddata(y,u) to create the data set, arx(data,[na nb nk]) to fit the model, and
compare(data,model) to validate the fit.

Once you are happy with your model, proceed to the next exercise.
Jonathan Currie, p 4

Exercise 1b

Online Model Validation

Aim
Validate the model against the real plant.

Method

1) Create a new model in Simulink:



Use the following setup:
- Zero-Order Hold with a sample time of 1
- Pulse Generator with an Amplitude of 3, Period of 10 and Pulse Width of 50
- The Model is a Discrete Filter block, with the numerator and denominator from your fitted
model in part (a).


2) Set the model to run for inf, and click run. Experiment with the pulse generator and manual set
point to see if the model is performing as required. You should see minimal differences between
the model (purple) and actual plant (yellow).

Below is an example response captured using the above method.





Zero-Order
Hol d1
2
Sl i der
Gai n
Pul se
Generator
G.b(z)
G.a(z)
Model
Manual Swi tch
Lab1b
1
Constant
Bl ack Box
USB 1208LS
Jonathan Currie, p 5


Comparison Of Model & Plant




Notice there is a small variation between plant and model, but overall this is minimal. The fit of this
model was over 90% with all orders less than 8.

Remember if you are not achieving good results, or your model has much higher order polynomials
(10+) to obtain a good result, re run part (a) and be sure to only use data which has enough excitation
(i.e. not the initial transient!). You may wish to extend the period of the experiment (eg 150) to provide
more data for fitting.

Jonathan Currie, p 6

Exercise 1c

Black Box Online Identification

Aim
Use Recursive Least Squares (RLS) to identify the black box model online.

Method

1) Create a new model in Simulink, using the AUT System ID Toolbox for the RLS Estimator block:

Use the following setup:
- Zero-Order Hold with a sample time of 1
- Random Number with a mean of 0 and a variance of 1
- The RLS block requires na, nb & E0, which you must decide on. Either enter these manually
(double click on it) or via an m file (preferred)

2) Set the model to run for inf and click run. Wait until the transient has died away and then switch
over to the input. Watch the scope to view the parameters converging (or not if you have it
wrong!). See the below figure for a typical result.

3) Experiment with different orders and values of lambda until you are satisfied with the result. At
this point you should read the last value of theta from theta_sim, and build an idpoly
model. Compare this model with the real plant by repeating part (b), this time with the RLS
identified model.

4) Extras for Experts
Find a way to use the parameters identified online in a model, such that part b & c can be run in
one simulation. Hint: You may need to look at the underlying S-Function!
Zero-Order
Hol d
theta_si m
Theta
Random
Number
theta
trace(p)
u
y
RLS Esti mator
Output Manual Swi tch
Lab1c
3
Constant
Bl ack Box
USB 1208LS
Jonathan Currie, p 7





A near perfect result. You may find this difficult to achieve! (Did I cheat perhaps?)

Jonathan Currie, p 8

Exercise 2a

Adaptive Control

Aim
Implement an Adaptive Controller in Simulink controlling a Simulated Process

Method

1) Create a new model in Simulink, using the AUT System ID Toolbox:

Use the following setup:
- Pulse Generator with an Amplitude of 1, Period of 50 and Pulse Width of 50
- The Adaptive Controller must be setup by you.
- The time varying plant allows 3 plants to be connected within the one block. You can use the
same three plants from Assignment 5 or invent your own, preferably stable & small order
models. Each of the 3 plants will be randomly selected during the simulation.

2) Set the model to run for 600 and click run. Make sure your scope is scaled as to ignore the initial
transient. You should observe the plant transitions and confirm the controller adapts to each
new plant. If not, try tuning E0, choosing a more relaxed T polynomial, or that you have chosen
the correct plant orders. Below is an example:



This exercise is to familiarize yourself with the Adaptive Control block before moving onto the real black
box.
u y
Ti me Varyi ng
Di screte Pl ant
Pul se
Generator
Lab2a
setp
y
u
Adapti ve Control l er
2
Jonathan Currie, p 9

Exercise 2b

Online Adaptive Control

Aim
Implement an Adaptive Controller in Simulink controlling a Real Process

Method

1) Create a new model in Simulink, using the AUT System ID Toolbox:


Use the following setup:
- Pulse Generator with an Amplitude of 2, Period of 100 and Pulse Width of 50
- Bias of 3
- Adaptive Controller with Sampling Period of between 0.5-1

2) Connect the second Black Box using Input1 & Output 1:


Pul se
Generator
Lab2b
Bl ack Box
USB 1208LS
u+3
Bi as
setp
y
u
Adapti ve Control l er
24V 12V 0V
DAC ADC
Jonathan Currie, p 10

3) This time you do not know the orders of this Box, and you will need to do some experimentation
to get the controller to work adequately. You may consider repeating some of the earlier
experiments in order to get a feel for the process. Note the input switch changes the dynamics
of the plant, which you will use to test your adaptive controller.


Have a go and see if you can see if your group can get the Adaptive Controller working!




The figure above is an actual Adaptive Controller running on the Black Box with Plant Transition mid way
through (t = 270)

You might also like