Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
( )
Other methods are Zero Order Hold (ZOH), Tustins method, etc.
is the sampling time, and (
Where
), ( ) and (
= ( ), (
), (
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 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:
(
( )
( )
( )
( )
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:
As you see we get the same results here as in the other examples.
[End of Example]
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.1
Find the continuous differential equation.
Task 2.2
Find the discrete difference equation. Use the Euler backward method.
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.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:
( )
( )
( )
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