LabVIEW MathScript
LabVIEW MathScript
LABVIEW MATHSCRIPT
HANS-PETTER HALVORSEN, 2010.05.25
Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01
PREFACE
What is LabVIEW?
LabVIEW (short for Laboratory Virtual Instrumentation Engineering Workbench) is a platform and development
environment for a visual programming language from National Instruments. The graphical language is named
"G".
What is MATLAB?
MATLAB is a tool for technical computing, computation and visualization in an integrated environment.
MATLAB is an abbreviation for MATrix LABoratory, so it is well suited for matrix manipulation and problem
solving related to Linear Algebra.
MATLAB offers lots of additional Toolboxes for different areas such as Control Design, Image Processing, Digital
Signal Processing, etc.
What is MathScript?
MathScript is a high-level, text- based programming language. MathScript includes more than 800 built-in
functions and the syntax is similar to MATLAB. You may also create custom-made m-file like you do in MATLAB.
MathScript is an add-on module to LabVIEW but you don’t need to know LabVIEW programming in order to use
MathScript. If you want to integrate MathScript functions (built-in or custom-made m-files) as part of a
LabVIEW application and combine graphical and textual programming, you can work with the MathScript
Node.
In addition to the MathScript built-in functions, different add-on modules and toolkits installs additional
functions. The LabVIEW Control Design and Simulation Module and LabVIEW Digital Filter Design Toolkit
install lots of additional functions.
You need to install LabVIEW and the LabVIEW MathScript RT Module. When necessary software is installed,
start MathScript by open LabVIEW:
ii
In the Getting Started window, select Tools -> MathScript Window...:
TABLE OF CONTENTS
Preface .....................................................................................................................................................................ii
3.2 Help........................................................................................................................................................ 6
Scripts ............................................................................................................................................................... 11
iv
v Table of Contents
LabVIEW (short for Laboratory Virtual Instrumentation Engineering Workbench) is a platform and development
environment for a visual programming language from National Instruments. The graphical language is named
"G". Originally released for the Apple Macintosh in 1986, LabVIEW is commonly used for data acquisition,
instrument control, and industrial automation on a variety of platforms including Microsoft Windows, various
flavors of UNIX, Linux, and Mac OS X. The latest version of LabVIEW is version LabVIEW 2009, released in
August 2009. Visit National Instruments at www.ni.com.
The code files have the extension “.vi”, which is an abbreviation for “Virtual Instrument”. LabVIEW offers lots of
additional Add-Ons and Toolkits.
The programming language used in LabVIEW, also referred to as G, is a dataflow programming language.
Execution is determined by the structure of a graphical block diagram (the LV-source code) on which the
programmer connects different function-nodes by drawing wires. These wires propagate variables and any
node can execute as soon as all its input data become available. Since this might be the case for multiple nodes
simultaneously, G is inherently capable of parallel execution. Multi-processing and multi-threading hardware is
automatically exploited by the built-in scheduler, which multiplexes multiple OS threads over the nodes ready
for execution.
LabVIEW ties the creation of user interfaces (called front panels) into the development cycle. LabVIEW
programs/subroutines are called virtual instruments (VIs). Each VI has three components: a block diagram, a
front panel, and a connector panel. The last is used to represent the VI in the block diagrams of other, calling
VIs. Controls and indicators on the front panel allow an operator to input data into or extract data from a
running virtual instrument. However, the front panel can also serve as a programmatic interface. Thus a virtual
instrument can either be run as a program, with the front panel serving as a user interface, or, when dropped
as a node onto the block diagram, the front panel defines the inputs and outputs for the given node through
the connector pane. This implies each VI can be easily tested before being embedded as a subroutine into a
larger program.
The graphical approach also allows non-programmers to build programs simply by dragging and dropping
virtual representations of lab equipment with which they are already familiar. The LabVIEW programming
environment, with the included examples and the documentation, makes it simple to create small applications.
This is a benefit on one side, but there is also a certain danger of underestimating the expertise needed for
good quality "G" programming. For complex algorithms or large-scale code, it is important that the
programmer possess an extensive knowledge of the special LabVIEW syntax and the topology of its memory
management. The most advanced LabVIEW development systems offer the possibility of building stand-alone
applications. Furthermore, it is possible to create distributed applications, which communicate by a
client/server scheme, and are therefore easier to implement due to the inherently parallel nature of G-code.
1.3 BENEFITS
One benefit of LabVIEW over other development environments is the extensive support for accessing
instrumentation hardware. Drivers and abstraction layers for many different types of instruments and buses
1
2 Introduction to LabVIEW
are included or are available for inclusion. These present themselves as graphical nodes. The abstraction layers
offer standard software interfaces to communicate with hardware devices. The provided driver interfaces save
program development time. The sales pitch of National Instruments is, therefore, that even people with limited
coding experience can write programs and deploy test solutions in a reduced time frame when compared to
more conventional or competing systems. A new hardware driver topology (DAQmxBase), which consists
mainly of G-coded components with only a few register calls through NI Measurement Hardware DDK (Driver
Development Kit) functions, provides platform independent hardware access to numerous data acquisition and
instrumentation devices. The DAQmxBase driver is available for LabVIEW on Windows, Mac OS X and Linux
platforms.
The LabVIEW MathScript RT Module is an add-on module to LabVIEW. With LabVIEW MathScript RT Module
you can:
You can work with LabVIEW MathScript through either of two interfaces: the “LabVIEW MathScript Interactive
Window” or the “MathScript Node”.
You can work with LabVIEW MathScript RT Module through both interactive and programmatic interfaces. For
an interactive interface in which you can load, save, design, and execute your .m file scripts, you can work with
the “MathScript Interactive Window”. To deploy your .m file scripts as part of a LabVIEW application and
combine graphical and textual programming, you can work with the “MathScript Node”.
The LabVIEW MathScript RT Module complements traditional LabVIEW graphical programming for such tasks
as algorithm development, signal processing, and analysis. The LabVIEW MathScript RT Module speeds up
these and other tasks by giving users a single environment in which they can choose the most effective syntax,
whether textual, graphical, or a combination of the two. In addition, you can exploit the best of LabVIEW and
thousands of publicly available .m file scripts from the web, textbooks, or your own existing m-script
applications. LabVIEW MathScript RT Module is able to process your files created using the current MathScript
syntax and, for backwards compatibility, files created using legacy MathScript syntaxes. LabVIEW MathScript RT
Module can also process certain of your files utilizing other text-based syntaxes, such as files you created using
MATLAB software. Because the MathScript RT engine is used to process scripts contained in a MathScript
Windows or MathScript Node, and because the MathScript RT engine does not support all syntaxes, not all
existing text-based scripts are supported.
LabVIEW MathScript RT Module supports most of the functionality available in MATLAB, the syntax is also
similar.
3
3 LABVIEW MATHSCRIPT
3.1 INTRODUCTION
How do you start using MathScript? You need to install LabVIEW and the LabVIEW MathScript RT Module.
When necessary software is installed, start MathScript by open LabVIEW:
The “LabVIEW MathScript Window” is an interactive interface in which you can enter .m file script commands
and see immediate results, variables and commands history. The window includes a command-line interface
where you can enter commands one-by-one for quick calculations, script debugging or learning. Alternatively,
you can enter and execute groups of commands through a script editor window.
4
5 LabVIEW MathScript
As you work, a variable display updates to show the graphical / textual results and a history window tracks your
commands. The history view facilitates algorithm development by allowing you to use the clipboard to reuse
your previously executed commands.
You can use the “LabVIEW MathScript Window” to enter commands one at time. You also can enter batch
scripts in a simple text editor window, loaded from a text file, or imported from a separate text editor. The
“LabVIEW MathScript Window” provides immediate feedback in a variety of forms, such as graphs and text.
Example:
[End of Example]
3.2 HELP
>>help
>>help plot
3.3 EXAMPLES
I advise you to test all the examples in this text in LabVIEW MathScript in order to get familiar with the program
and its syntax. All examples in the text are outlined in a frame like this:
>>
You type all your commands in the Command Window. I will use the symbol “>>” to illustrate that the
commands should be written in the Command Window.
Example: Matrices
>> A = [1 2;0 3]
Or
>> A = [1,2;0,3]
>>a=4
>>b=3
>>a+b
ans =
7
MathScript provides a simple way to define simple arrays using the syntax: “init:increment:terminator”. For
instance:
array =
1 3 5 7 9
The code defines a variable named array (or assigns a new value to an existing variable with the name array)
which is an array consisting of the values 1, 3, 5, 7, and 9. That is, the array starts at 1 (the init value),
increments with each step from the previous value by 2 (the increment value), and stops once it reaches (or to
avoid exceeding) 9 (the terminator value).
The increment value can actually be left out of this syntax (along with one of the colons), to use a default value
of 1.
ari =
1 2 3 4 5
The code assigns to the variable named ari an array with the values 1, 2, 3, 4, and 5, since the default value of 1
is used as the incrementer.
Note that the indexing is one-based, which is the usual convention for matrices in mathematics. This is atypical
for programming languages, whose arrays more often start with zero.
Matrices can be defined by separating the elements of a row with blank space or comma and using a semicolon
to terminate each row. The list of elements should be surrounded by square brackets: []. Parentheses: () are
used to access elements and subarrays (they are also used to denote a function argument list).
A =
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
>> A(2,3)
ans =
11
Sets of indices can be specified by expressions such as "2:4", which evaluates to [2, 3, 4]. For example, a
submatrix taken from rows 2 through 4 and columns 3 through 4 can be written as:
>> A(2:4,3:4)
ans =
11 8
7 12
14 1
A square identity matrix of size n can be generated using the function eye, and matrices of any size with zeros
or ones can be generated with the functions zeros and ones, respectively.
>> eye(3)
ans =
1 0 0
0 1 0
0 0 1
>> zeros(2,3)
ans =
0 0 0
0 0 0
>> ones(2,3)
ans =
1 1 1
1 1 1
Command Description
A’ Inverse of matrix A
MathScript includes more than 800 built-in functions that you can use, e.g., in a previous task you used the plot
function.
>>x=[1 2 5 6 8 9 3]
x=[1 2 5 6 8 9 3]
mean(x)
min(x)
max(x)
[End of Example]
MathScript includes more than 800 built-in functions that you can use but sometimes you need to create your
own functions.
SCRIPTS
A script is a sequence of MathScript commands that you want to perform to accomplish a task. When you have
created the script you may save it as a m-file for later use.
You may also have multiple Script Windows open at the same time by selecting “New Script Editor” in the File
menu:
This gives:
• If-else statement
• Switch and case statement
• For loop
• While loop
The if statement evaluates a logical expression and executes a group of statements when the expression is
true. The optional elseif and else keywords provide for the execution of alternate groups of statements. An end
keyword, which matches the if, terminates the last group of statements. The groups of statements are
delineated by the four keywords—no braces or brackets are involved.
n=5
if n > 2
M = eye(n)
elseif n < 2
M = zeros(n)
else
M = ones(n)
end
[End of Example]
The switch statement executes groups of statements based on the value of a variable or expression. The
keywords case and otherwise delineate the groups. Only the first matching case is executed. There must always
be an end to match the switch.
n=2
switch(n)
case 1
M = eye(n)
case 2
M = zeros(n)
case 3
M = ones(n)
end
[End of Example]
The for loop repeats a group of statements a fixed, predetermined number of times. A matching end delineates
the statements.
m=5
for n = 1:m
r(n) = rank(magic(n));
end
r
[End of Example]
The while loop repeats a group of statements an indefinite number of times under control of a logical
condition. A matching end delineates the statements.
m=5;
while m > 1
m = m - 1;
zeros(m)
end
[End of Example]
3.6 PLOTTING
Topics:
Example: Plotting
Function plot can be used to produce a graph from two vectors x and y. The code:
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
[End of Example]
Example: Plotting
Three-dimensional graphics can be produced using the functions surf, plot3 or mesh.
[X,Y] = meshgrid(-10:0.25:10,-10:0.25:10);
f = sinc(sqrt((X/pi).^2+(Y/pi).^2));
mesh(X,Y,f);
xlabel('{\bfx}')
ylabel('{\bfy}')
zlabel('{\bfsinc} ({\bfR})')
hidden off
[End of Example]
Linear algebra is a branch of mathematics concerned with the study of matrices, vectors, vector spaces (also
called linear spaces), linear maps (also called linear transformations), and systems of linear equations.
4.1 VECTORS
Given a vector x
Example: Vectors
>> x=[1; 2; 3]
x =
1
>> x'
ans =
1 2 3
[End of Example]
Orthogonality:
17
18 Linear Algebra Examples
4.2 MATRICES
Given a matrix A:
Example: Matrices
-2 -3
[End of Example]
4.2.1 TRANSPOSE
Example: Transpose
>> A'
ans =
0 -2
1 -3
[End of Example]
4.2.2 DIAGONAL
Example: Diagonal
>> diag(A)
ans =
0
-3
[End of Example]
>> eye(3)
ans =
1 0 0
0 1 0
0 0 1
[End of Example]
4.2.3 TRIANGULAR
where
Matrix multiplication:
A =
0 1
-2 -3
3 -2
>> A*B
ans =
3 -2
-11 6
[End of Example]
Note!
Matrix addition:
1 -5
[End of Example]
4.2.6 DETERMINANT
Then
Example: Determinant
A =
0 1
-2 -3
>> det(A)
ans =
2
Notice that
and
[End of Example]
Example: Determinant
Determinants:
>> det(A*B)
ans =
-4
>> det(A)*det(B)
ans =
-4
>> det(A')
ans =
2
>> det(A)
ans =
2
[End of Example]
if
Inverse matrix:
A =
0 1
-2 -3
>> inv(A)
ans =
-1.5000 -0.5000
1.0000 0
[End of Example]
Notice that:
4.3 EIGENVALUES
Example: Eigenvalues
A =
0 1
-2 -3
>> eig(A)
ans =
-1
-2
[End of Example]
The equations
may be written
where
A =
1 2
3 4
>> b=[5;6]
b =
5
>> x=inv(A)*b
x =
-4.0000
4.5000
In MathScript you could also write “x=A\b”, which should give the same answer. This syntax can also be used
when the inverse of A don’t exists.
[End of Example]
Illegal operation:
[End of Example]
4.5 LU FACTORIZATION
LU factorization of is given by
where
Example: LU Factorization
Find L and U:
>> [L,U]=lu(A)
L =
0.3333 1.0000
1.0000 0
U =
3.0000 4.0000
0 0.6667
[End of Example]
where
D is a diagonal matrix
Example: LU Factorization
Find L, U and P:
A =
1 2
3 4
>> [L,U,P]=lu(A)
L =
1.0000 0
0.3333 1.0000
U =
3.0000 4.0000
0 0.6667
P =
0 1
1 0
[End of Example]
where
U is a orthogonal matrix
V is a orthogonal matrix
Find S, V and D:
U =
-0.4046 -0.9145
-0.9145 0.4046
S =
5.4650 0
0 0.3660
V =
-0.5760 0.8174
-0.8174 -0.5760
[End of Example]
4.7 COMMANDS
Command Description
[L,U]=lu(A) LU Factorization
[L,U,P]=lu(A)
Using LabVIEW MathScript for Control Design purposes you need to install the “Control Design and Simulation
Module” in addition to the “MathScript RT Module” itself.
Use the Control Design MathScript RT Module functions to design, analyze, and simulate linear controller
models using a text-based language. The following is a list of Control Design MathScript RT Module classes of
functions and commands that LabVIEW MathScript supports.
Getting help about MathScript functions regarding the Control Design Toolkit (CDT), type “help cdt” in the
Command Window in the MathScript environment.
MathScript offers lots of functions for defining and manipulate state-space models and transfer functions.
Class: contruct
Description:
Use functions in the construct class to construct linear time-invariant system models and to convert between
model forms.
28
29 Control Design and Simulation
Below we will give some examples of how to use the most import functions in this class.
5.1.1 PID
Currently, the Proportional-Integral-Derivative (PID) algorithm is the most common control algorithm used in
industry.
In PID control, you must specify a process variable and a setpoint. The process variable is the system parameter
you want to control, such as temperature, pressure, or flow rate, and the setpoint is the desired value for the
parameter you are controlling.
A PID controller determines a controller output value, such as the heater power or valve position. The
controller applies the controller output value to the system, which in turn drives the process variable toward
the setpoint value.
Where
Controller gain
Integral time
Derivative time
SP – Setpoint
PV – Process Variable
Function: pid
Description:
Constructs a proportional-integral-derivative (PID) controller model in either parallel, series, or academic form.
Examples:
Kc = 0.5;
Ti = 0.25;
SysOutTF = pid(Kc, Ti, 'academic');
[End of Example]
A state-space model is just a structured form or representation of the differential equations for a system.
where x is the state vector and u is the input vector. A is called the system-matrix, and is square in all cases.
Example:
Function: ss
Description:
This function constructs a continuous or discrete linear system model in state-space form. You also can use this
function to convert transfer function and zero-pole-gain models to state-space form.
Examples:
B = [0; 1]
C = B'
SysOutSS = ss(A, B, C)
[End of Example]
The transfer function of a linear system is defined as the ratio of the Laplace transform of the output variable
to the Laplace transform of the input variable.
Function tf
Description:
This function creates a continuous or discrete linear system model in transfer function form. You also can use
this function to convert zero-pole-gain and state-space models to transfer function form.
Examples:
>>s = tf('s')
This specifies that you want to create the continuous transfer function s / 1. After you enter this command, you
can use LabVIEW MathScript operands on this transfer function to define a zero-pole-gain or transfer function
model.
SysOutZPK = 4*(s + 2) / (s + 1)
This example constructs a zero-pole-gain model with a gain of 4, a zero at -2, and a pole at -1.
[End of Example]
Where
is the gain
Function sys_order1
Description:
This function constructs the components of a first-order system model based on a gain, time constant, and
delay that you specify. You can use this function to create either a state-space model or a transfer function
model, depending on the output parameters you specify.
Inputs:
tau Specifies the time constant, in seconds, which is the time required for the model output to reach 63% of its
final value. The default value is 0.
delay Specifies the response delay of the model, in seconds. The default value is 0.
Examples:
K = 0.5;
tau = 1.5;
SysOutTF = sys_order1(K, tau);
[End of Example]
A standard second order transfer function model may be written like this:
Where
is the gain
Function sys_order2
Description:
This function constructs the components of a second-order system model based on a damping ratio and
natural frequency you specify. You can use this function to create either a state-space model or a transfer
function model, depending on the output parameters you specify.
Example:
dr = 0.5
wn = 20
[num, den] = sys_order2(wn, dr)
SysTF = tf(num, den)
[A, B, C, D] = sys_order2(wn, dr)
SysSS = ss(A, B, C, D)
[End of Example]
Class: connect
Description:
Use members of the connect class to connect systems models together in various configurations.
Function series
Description:
This function connects two system models in series to produce a model SysSer with input and output
connections you specify. The input models must be either continuous models or discrete models with identical
sampling times.
Example:
[End of Example]
Class: convert
Description:
Use members of the convert class to convert a continuous system model to a discrete model, convert a discrete
model to a continuous model, and resample a discrete model. You also can use members of this class to
incorporate delays into a system model.
5.1.6 PADÉ-APPROXIMATION
Function: pade
Description:
This function incorporates time delays into a system model using the Pade approximation method, which
converts all residuals. You must specify the delay using the set function. You also can use this function to
calculate coefficients of numerator and denominator polynomial functions with a specified delay.
Example:
delay = 1.2
order = 3
[num, den] = pade(delay, order)
[End of Example]
The frequency response of a system is a frequency dependent function which expresses how a sinusoidal signal
of a given frequency on the system input is transferred through the system. Each frequency component is a
sinusoidal signal having a certain amplitude and a certain frequency.
The frequency response is an important tool for analysis and design of signal filters and for analysis and design
of control systems.
The frequency response can found experimentally or from a transfer function model.
The frequency response of a system is defined as the steady-state response of the system to a sinusoidal input
signal. When the system is in steady-state it differs from the input signal only in amplitude (A) and phase angle
(ω).
We have:
Where is the frequency response of the system, i.e., we may find the frequency response by setting
in the transfer function.
Bode diagrams are useful in frequency response analysis. The Bode diagram consists of 2 diagrams, the Bode
magnitude diagram, and the Bode phase diagram, .
Function: bode
Description:
This function creates the Bode magnitude and Bode phase plots of a system model. You also can use this
function to return the magnitude and phase values of a model at frequencies you specify. If you do not specify
an output, this function creates a plot.
Examples:
num=[1];
den=[1,1];
H1=tf(num,den)
bode(H1)
[End of Example]
Function: margin
Description:
This function calculates and/or plots the smallest gain and phase margins of a single-input single-output (SISO)
system model.
The gain margin indicates where the frequency response crosses at 0 decibels (“crossover frequency”, ).
The phase margin indicates where the frequency response crosses -180 degrees (“crossover frequency”, ).
Examples:
num = [1]
den = [1, 5, 6]
H = tf(num, den)
margin(H)
[End of Example]
Example:
We want to plot the Bode diagram and find the crossover-frequencies for the system using MathScript.
• gmf is the gain margin frequencies, in radians/second. A gain margin frequency indicates where the
model phase crosses -180 degrees.
• gm Returns the gain margins of the system.
• pmf Returns the phase margin frequencies, in radians/second. A phase margin frequency indicates
where the model magnitude crosses 0 decibels.
• pm Returns the phase margins of the system.
• We get:
Below we see the Bode diagram with the crossover-frequency and the gain margin and phase margin for the
system plotted in:
[End of Example]
TIME RESPONSE
Class: timeresp
Description:
Use members of the timeresp class to create generic linear simulations and time domain plots for step inputs,
impulse inputs, and initial condition responses.
Function: step
Description:
This function creates a step response plot of the system model. You also can use this function to return the
step response of the model outputs. If the model is in state-space form, you also can use this function to return
the step response of the model states. This function assumes the initial model states are zero. If you do not
specify an output, this function creates a plot.
Example:
We will plot the time response for the transfer function using the step function
step(H)
[End of Example]
The “MathScript Node” offers an intuitive means of combining graphical and textual code within LabVIEW. The
figure below shows the “MathScript Node” on the block diagram, represented by the blue rectangle. Using
“MathScript Nodes”, you can enter .m file script text directly or import it from a text file.
You can define named inputs and outputs on the MathScript Node border to specify the data to transfer
between the graphical LabVIEW environment and the textual MathScript code.
You can associate .m file script variables with LabVIEW graphical programming, by wiring Node inputs and
outputs. Then you can transfer data between .m file scripts with your graphical LabVIEW programming. The
textual .m file scripts can now access features from traditional LabVIEW graphical programming.
The MathScript Node is available from LabVIEW from the Functions Palette: Mathematics → Scripts & Formulas
42
43 MathScript Node
If you click Ctrl+H you get help about the MathScript Node:
Click “Detailed help” in order to get more information about the MathScript Node.
If a script in a MathScript Node calls a user-defined function, LabVIEW uses the default search path list to link
the function call to the specified .m file. After you configure the default search path list and save the VI that
contains the MathScript Node, you do not need to reconfigure the MathScript search path list when you open
the VI on a different computer because LabVIEW looks for the .m file in the directory where the .m file was
located when you last saved the VI. However, you must maintain the same relative path between the VI and
the .m file.
6.2 EXAMPLES
Here is an example of how you use the MathScript Node. On the left border you connect input variables to the
script, on the right border you have output variables. Right-click on the border and select “Add Input” or “Add
Output”.
[End of Example]
[End of Example]
Use the LabVIEW MathScript to create a m-file script (or you may use MATLAB to create the same script):
Right-click on the border of the MathScript Node and select “Import”, and then select the m-file you want to
import into the Node.
Right-click on the right border and select “Add Output”. Then right-click on the output variable and select
“Create Indicator”.
Block Diagram:
If you, e.g., add the following command in the MathScript Node: plot(x), the following window appears:
[End of Example]
6.3 EXERCISES
Use the MathScript Node and test the same examples you did in the previous chapter (Chapter 4 - “Linear
Algebra Examples”)
The MATLAB Script calls the MATLAB software to execute scripts. You must have a licensed copy of the
MATLAB software version 6.5 or later installed on your computer to use MATLAB script nodes because the
script nodes invoke the MATLAB software script server to execute scripts written in the MATLAB language
syntax. Because LabVIEW uses ActiveX technology to implement MATLAB script nodes, they are available only
on Windows.
48
APPENDIX A – MATHSCRIPT FUNCTIONS FOR CONTROL AND SIMULATION
Here are some descriptions for the most used MathScript functions used in this Lab Work.
plot Generates a plot. plot(y) plots the columns of y against the >X = [0:0.01:1];
>Y = X.*X;
indexes of the columns. >plot(X, Y)
tf Creates system model in transfer function form. You also can >num=[1];
model. >den=[1,1]
>H=tf(num,den)
>poles(H)
tfinfo Returns information about a transfer function system model. >[num, den, delay, Ts] =
tfinfo(SysInTF)
step Creates a step response plot of the system model. You also can >num=[1,1];
use this function to return the step response of the model >den=[1,-1,3];
outputs. If the model is in state-space form, you also can use this >H=tf(num,den);
function to return the step response of the model states. This >t=[0:0.01:10];
function assumes the initial model states are zero. If you do not >step(H,t);
specify an output, this function creates a plot.
lsim Creates the linear simulation plot of a system model. This >t = [0:0.1:10]
function calculates the output of a system model when a set of >u = sin(0.1*pi*t)'
inputs excite the model, using discrete simulation. If you do not >lsim(SysIn, u, t)
on a gain, time constant, and delay that you specify. You can use >tau = 1;
this function to create either a state-space model or a transfer >H = sys_order1(K, tau)
based on a damping ratio and natural frequency you specify. You >wn = 20
can use this function to create either a state-space model or a >[num, den] = sys_order2(wn, dr)
transfer function model, depending on the output parameters >SysTF = tf(num, den)
you specify. >[A, B, C, D] = sys_order2(wn, dr)
>SysSS = ss(A, B, C, D)
damp Returns the damping ratios and natural frequencies of the poles >[dr, wn, p] = damp(SysIn)
of a system model.
model in either parallel, series, or academic form. Refer to the >Ti = 0.25;
LabVIEW Control Design User Manual for information about >SysOutTF = pid(Kc, Ti,
'academic');
these three forms.
conv Computes the convolution of two vectors or matrices. >C1 = [1, 2, 3];
>C2 = [3, 4];
49
50 Error! Reference source not found.
series Connects two system models in series to produce a model >Hseries = series(H1,H2)
feedback Connects two system models together to produce a closed-loop >SysClosed = feedback(SysIn_1,
SysIn_2)
model using negative or positive feedback connections
ss Constructs a model in state-space form. You also can use this >A = eye(2)
ssinfo Returns information about a state-space system model. >A = [1, 1; -1, 2]
>B = [1, 2]'
>C = [2, 1]
>D = 0
>SysInSS = ss(A, B, C, D)
>[A, B, C, D, Ts] = ssinfo(SysInSS)
pade Incorporates time delays into a system model using the Pade >[num, den] = pade(delay, order)
approximation method, which converts all residuals. You must >[A, B, C, D] = pade(delay, order)
specify the delay using the set function. You also can use this
function to calculate coefficients of numerator and denominator
polynomial functions with a specified delay.
bode Creates the Bode magnitude and Bode phase plots of a system >num=[4];
model. You also can use this function to return the magnitude >den=[2, 1];
and phase values of a model at frequencies you specify. If you >H = tf(num, den)
bodemag Creates the Bode magnitude plot of a system model. If you do >[mag, wout] = bodemag(SysIn)
not specify an output, this function creates a plot. >[mag, wout] = bodemag(SysIn, [wmin
wmax])
>[mag, wout] = bodemag(SysIn,
wlist)
margin Calculates and/or plots the smallest gain and phase margins of a >num = [1]
single-input single-output (SISO) system model. The gain margin >den = [1, 5, 6]
indicates where the frequency response crosses at 0 decibels. >H = tf(num, den)
margins Calculates all gain and phase margins of a single-input >[gmf, gm, pmf, pm] = margins(H)
For more details about these functions, type “help cdt” to get an overview of all the functions used for Control
Design and Simulation. For detailed help about one specific function, type “help <function_name>”.
Plots functions: Here are some useful functions for creating plots: plot, figure, subplot, grid, axis, title, xlabel,
ylabel, semilogx – for more information about the plots function, type “help plots”.
Faculty of Technology
Kjølnes Ring 56
www.hit.no
E-mail: hans.p.halvorsen@hit.no
Blog: http://home.hit.no/~hansha/
Room: B-237a