Sei sulla pagina 1di 9

EE4107 - Cybernetics Advanced

Exercise 11: Discretization


Introduction
We will use different discretization methods using pen and paper exercises and in practical
implementation in MathScript/LabVIEW along with built-in discretization methods.
Euler:
Two commonly used methods for discretization are as follows:
Euler forward method:
(

( )

Euler backward method:


( )

Other methods are Zero Order Hold (ZOH), Tustins method, etc.
is the sampling time, and (

Where

), ( ) and (

Note! Different notations may be used: ( )


(
), etc.

= ( ), (

) are discrete values.


)

), (

Example:
Given the following system:

We will use the Euler forward method to create a discrete version of this system.
We get as follows:
(

( )

( )

( )

Further:
(

( )

( )

( )

Faculty of Technology, Postboks 203, Kjlnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01

2
This gives:
(

( )

( )

( )

) ( )

( )

Finally:
(
If we use

and

(
, we get:

( )

( )

[End of Example]

Discretization in MathScript
In MathScript we can simulate a discrete system using a For Loop or a While Loop.
We can also use some of the built-in functions to convert a continuous state-space model to a
discrete state-space model. In MathScript we can use the function c2d() to convert from a
continuous system to a discrete system.
Example:
We will simulate the following discrete system in MathScript using a For Loop:
(
We will set

) ( )

( )

and

MathScript code:
% Simulation of discrete model
clear
clc
% Model Parameters
a = 0.25;
b = 2;
% Simulation Parameters
Ts = 0.1; %s
Tstop = 20; %s
uk = 1;
x(1) = 0;
% Simulation
for k=1:(Tstop/Ts)
x(k+1) = (1-a*Ts).*x(k) + Ts*b*uk;
end
% Plot the Simulation Results
k=0:Ts:Tstop;
EE4107 - Cybernetics Advanced

3
plot (k, x)
grid on
We use

as the sampling time.

This gives the following results:

As you may notice, we get the same result as we get in the previous Exercise (10b) when we used
LabVIEW.
[End of Example]
Example:
Given the following system:

We will set

and

We will use the built-in function c2d() in order to find the discrete system:
% Find Discrete model
clear
clc
% Model Parameters
a = 0.25;
b = 2;
Ts = 0.1; %s
% State-space model
A = [-a];
EE4107 - Cybernetics Advanced

4
B = [b];
C = [1];
D = [0];
model = ss(A,B,C,D)
model_discrete = c2d(model, Ts, 'forward')
This gives the following results:
a

b
0.975

c
0.2

d
1

or:
(

( )
( )

( )

( )

As you see this is the same result as in the example above.


[End of Example]

Discretization in LabVIEW
There are several ways we can make a discrete model in LabVIEW as well. In this exercise we will use
the Formula Node. A Formula Node in LabVIEW evaluates mathematical formulas and expressions
similar to C on the block diagram. In this way you may use existing C code directly inside your
LabVIEW code. It is also useful when you have complex mathematical expressions.

Example:
We use the same discrete system as in previous examples:
(
With

) ( )

( )

and

We will use the Formula Node and a For Loop in LabVIEW in order to simulate this discrete model.
The LabVIEW code is as follows:

EE4107 - Cybernetics Advanced

The simulation results are as follows:

As you see we get the same results here as in the other examples.
[End of Example]

Task 1: Discrete system


Given the following system:

EE4107 - Cybernetics Advanced

Task 1.1
Find the discrete system and set it on state-space form (using pen and paper).
Use Euler forward:
(

( )

Task 1.2
Define the continuous state-space model (pen and paper) and then implement the continuous
state-space model in MathScript. Then use MathScript to find the discrete state-space model.
Compare the result from the previous task.
Set

and

Task 2: Discrete Controller


A controller is given by the following transfer function:
( )
( )

( )

Task 2.1
Find the continuous differential equation.

Task 2.2
Find the discrete difference equation. Use the Euler backward method.

Task 3: Discrete State-space model


Given the following system:

Task 3.1
Find the discrete state-space model
EE4107 - Cybernetics Advanced

Task 3.2
Define the continuous state-space model (pen and paper) and then implement the continuous
state-space model in MathScript. Then use MathScript to find the discrete state-space model.
Compare the result from the previous subtask.
Use values

and

Task 4: Discrete Low-pass Filter


Transfer function for a first-order low-pass filter may be written:
( )
Where

is the time-constant of the filter.

Task 4.1
Create the discrete low-pass filter algorithm using pen and paper.
Use the Euler Backward method.

Task 4.2
Create a discrete low-pass filter in LabVIEW using the Formula Node in LabVIEW.
Create a SubVI of the code. You will use this subVI in your project later. The user needs to be able to
set the time constant of the filter from the outside, i.e., it should be an input to the SubVI. The
simulation Time-step needs also to be set from the outside.
Test and make sure your filter works!
Note! A golden rule is that:

You may, e.g., use the Uniform White Noise PtByPt.vi. Example:

EE4107 - Cybernetics Advanced

Task 5: Discrete PI controller


A continuous-time PI controller may be written:
( )

( )

Where u is the controller output and is the control error:


( )

( )

( )

Below we see a block diagram of a simple control system:

EE4107 - Cybernetics Advanced

Task 5.1
Create the discrete PI Controller algorithm using pen and paper. Use the Euler Backward method.

Task 5.2
Create a discrete PI controller in LabVIEW using the Formula Node. Create a SubVI of the code. You
will use this subVI in your project later.

Task 6: Simulation
Implement your PI controller and Low-pass filter in a simulation. You may, e.g., use the example
General PID Simulator.vi as a base for your simulation. Use the NI Example Finder (Help Find
Examples) in order to find the VI in LabVIEW.
Note! You will need the LabVIEW PID and Fuzzy Logic Toolkit in order to fulfill this Task.
Run the example and see how it is implemented and how it works.
Note! Save the VI with a new name and replace the controller used in the example with the
controller you created in the previous task.

Additional Resources

http://home.hit.no/~hansha/?lab=mathscript

Here you will find tutorials, additional exercises, etc.

EE4107 - Cybernetics Advanced

Potrebbero piacerti anche