System Identification and Estimation in LabVIEW
System Identification and Estimation in LabVIEW
Faculty of Technology, Postboks 203, Kjlnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01
Preface
This Tutorial will go through the basic principles of System identification and Estimation and how to implement these techniques in LabVIEW and LabVIEW MathScript. LabVIEW is a graphical programming language created by National Instruments, while LabVIEW MathScript is an add-on to LabVIEW. LabVIEW MathScript has similar syntax as, e.g., MATLAB. LabVIEW MathScript may be used as a separate part (and can be considered as a miniature version of MATLAB) or be integrated into the graphical LabVIEW code using the MathScript Node. The following methods will be discussed: State Estimation: Kalman Filter Observers
System Identification Sub-space methods/Black-Box methods Polynomial Model Estimation: ARX/ARMAX model Estimation
Software You need the following software in this Tutorial: LabVIEW LabVIEW MathScript RT Module (LabVIEW MathScript) LabVIEW Control Design and Simulation Module LabVIEW System Identification Toolkit
LabVIEW Control Design and Simulation Module has functionality for creating Kalman Filters and Observers, while LabVIEW System Identification Toolkit has functionality for System identification.
Table of Contents
Preface ................................................................................................................................................ i Table of Contents................................................................................................................................ ii 1 Introduction to LabVIEW and LabVIEW MathScript ..................................................................... 5 1.1 1.2 2 3 LabVIEW .............................................................................................................................. 5 LabVIEW MathScript............................................................................................................ 6
LabVIEW Control and Simulation Module ................................................................................... 9 Model Creation in LabVIEW ...................................................................................................... 11 3.1 3.2 State-space Models ........................................................................................................... 12 Transfer functions ............................................................................................................. 15 commonly used transfer functions ............................................................................. 17
3.2.1 4 5
Introduction to System identification and Estimation ............................................................... 24 State Estimation with Kalman Filter in LabVIEW........................................................................ 26 5.1 5.2 5.3 5.4 5.5 State-Space model ............................................................................................................. 27 Observability ..................................................................................................................... 29 Introduction to the State Estimator ................................................................................... 31 State Estimation ................................................................................................................ 37 LabVIEW Kalman Filter Implementations ........................................................................... 38
Create your own Kalman Filter from Scratch............................................................................. 44 6.1 6.2 The Kalman Filter Algorithm .............................................................................................. 44 Examples ........................................................................................................................... 45
Overview of Kalman Filter functions in LabVIEW ....................................................................... 49 7.1 Control Design palette ....................................................................................................... 49 State Feedback Design subpalette.............................................................................. 49 Implementation subpalette........................................................................................ 50
7.1.1 7.1.2
ii
iii 7.2
7.2.1 8
State Estimation with Observers in LabVIEW ............................................................................ 54 8.1 8.2 8.3 8.4 8.5 State-Space model ............................................................................................................. 54 Eigenvalues ....................................................................................................................... 56 Observer Gain ................................................................................................................... 57 Observability ..................................................................................................................... 58 Examples ........................................................................................................................... 59
Overview of Observer functions ............................................................................................... 64 9.1 Control Design palette ....................................................................................................... 64 State Feedback Design subpalette.............................................................................. 64 Implementation subpalette........................................................................................ 65
9.2.1 10
System Identification in LabVIEW ............................................................................................. 69 10.1 10.2 10.3 10.4 Parameter Estimation with Least Square Method (LS)........................................................ 70 System Identification using Sub-space methods/Black-Box methods ................................. 73 System Identification using Polynomial Model Estimation: ARX/ARMAX model Estimation 74 Generate model Data ........................................................................................................ 75 Excitation signals........................................................................................................ 77
10.4.1 11 12
Part I: Introduction
1.1 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". LabVIEW is commonly used for data acquisition, instrument control, and industrial automation. The code files have the extension .vi, which is an abbreviation for Virtual Instrument. LabVIEW offers lots of additional Add-ons and Toolkits.
For more information about LabVIEW, please read the Tutorial Introduction to LabVIEW.
6 Introduction to LabVIEW and LabVIEW MathScript I also recommend you visit my Blog: http://home.hit.no/~hansha/ and visit National Instruments at www.ni.com.
For more information about MathScript, please read the Tutorial LabVIEW MathScript. 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. In the Getting Started window, select Tools -> MathScript Window...:
For more information about MathScript, please read the Tutorial LabVIEW MathScript. MathScript Node: You may also use MathScript Code directly inside and combined with you graphical LabVIEW code, for this you use the MathScript Node. With the MathScript Node you can combine 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 Tutorial: System Identification and Estimation in LabVIEW
8 Introduction to LabVIEW and LabVIEW MathScript 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
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.
In this Tutorial we will focus on the VIs used for Parameter and State estimation and especially the use of Observers and Kalman Filter for State estimation. If you want to learn more about Simulation, Simulation Loop, block diagrams and PID control, etc., I refer to the Tutorial Control and Simulation in LabVIEW This Tutorial is available from http://home.hit.no/~hansha/ . In this Tutorial we will need the following sub palettes in the Control Design and Simulation palette: Control Design System Identification Simulation
10
In the next chapters we will go in detail and describe the different sub palettes in these palettes and explain the functions/Sub VIs we will need for System identification and Estimation.
Below we go through the different subpalettes and the most used VIs in these palettes.
11
12
Use the Model Construction VIs to create linear system models and modify the properties of a system model. You also can use the Model Construction VIs to save a system model to a file, read a system model from a file, or obtain a visual representation of a model. Some of the most used VIs would be:
CD Construct Transfer Function Model.vi These VIs and some others are explained below.
13
You may use numeric values in the matrices A,B,C and D or symbolic values by selecting ether Numeric or Symbolic: Numeric Symbolic
Front Panel:
14
The CD Draw State-Space Equation.vi can be used to see a graphical representation of the State-space model. Example: Create SISO/MIMO State-Space models SISO Model (Single Input, Single Output):
15
[End of Example]
16
Front Panel:
[End of Example]
17 Block Diagram:
Front Panel:
[End of Example]
Select the
2.order system: The transfer function for a 2.order system is as follows: ( ) . Where is the gain zeta is the relative damping factor [rad/s] is the undamped resonance frequency. /
Select the
19
Time delay as a Pade approximation: Time-delays are very common in control systems. The Transfer function of a time-delay is: ( ) In some situations it is necessary to substitute Pad-approximation: with an approximation, e.g., the
Select the
20
Use the Model Information VIs to obtain or set parameters, data, and names of a system model. Model information includes properties such as the system delay, system dimensions, sampling time, and names of inputs, outputs, and states.
Use the Model Conversion VIs to convert a system model from one representation to another, from a continuous-time to a discrete-time model, or from a discrete-time to a continuous-time model. You also can use the Model Conversion VIs to convert a control design model into a simulation model or a simulation model into a control design model. Some of the most used VIs in the Model Conversion subpalette are:
CD Convert to Transfer Function Model.vi CD Convert Continuous to Discrete.vi These VIs and some others are explained below. Convert to State-Space Models:
21
Front Panel:
Front Panel:
Example: Convert from Continuous State-Space model to Discrete State-Space model Block Diagram:
23
Front Panel:
[End of Example]
Use the Model Interconnection VIs to perform different types of linear system interconnections. You can build a large system model by connecting smaller system models together.
System Identification: Parameter Estimation and the Least Square Method (LS) Sub-space methods/Black-Box methods Polynomial Model Estimation: ARX/ARMAX model Estimation
The next chapters will go through the basic theory and show how it could be implemented in LabVIEW and MathScript.
24
25
The estimator (model of the system) runs in parallel with the system (real system or model). The measurement(s) is used to update the estimator. LabVIEW Control Design and Simulation Module have lots of functionality for State Estimation using Kalman Filters. The functionality will be explained in detail in the next chapters. Below we see the Discrete Kalman Filter implementation in LabVIEW:
26
27
The Kalman Filter for nonlinear models is called the Extended Kalman Filter.
LabVIEW: In LabVIEW we may use the CD Construct State-Space Model.vi to create a State-space model:
Note! If you specify a discrete State-space model you have to specify the Sampling Time. LabVIEW Example: Create a State-space model Block Diagram:
28
The matrices ,
and
[End of Example] Discretization: If you have a continuous model and want to convert it to the discrete model, you may use the VI CD Convert Continuous to Discrete.vi in LabVIEW:
LabVIEW Functions Palette: Control Design & Simulation Control Design Model Conversion CD Convert Continuous to Discrete.vi LabVIEW Example: Convert from Continuous to Discrete model
Note! We have to specify the Sampling Time. Tutorial: System Identification and Estimation in LabVIEW
29 [End of Example]
MathScript: Use the ss function in MathScript to define your model (or tf if you have a transfer function). Use the c_to_d function to convert a continuous model to a discrete model. MathScript Example: Given the following State-space model: [ ] [ , The following MathScript Code creates this model:
c=1; m=1; k=1; A = [0 1; -k/m -c/m]; B = [0; 1/m]; C = [1 0]; ssmodel = ss(A, B, C)
]0 1
[ ]
-0 1
If you want to find the discrete model use the c_to_d function:
Ts=0.1 % Sampling Time discretemodel = c_to_d(ssmodel, Ts)
[End of Example]
5.2 Observability
A necessary condition for the Kalman Filter to work correctly is that the system for which the states are to be estimated, is observable. Therefore, you should check for Observability before applying the Kalman Filter. The Observability matrix is defined as:
Where n is the system order (number of states in the State-space model). Tutorial: System Identification and Estimation in LabVIEW
State Estimation with Kalman Filter in LabVIEW is full rank, meaning the rank of is equal to n.
The LabVIEW Control Design and Simulation Module have a VI (Observability Matrix.vi) for finding the Observability matrix and check if a states-pace model is Observable. LabVIEW Functions Palette: Control Design & Simulation Control Design State-Space Model Analysis CD Observability Matrix.vi
Note! In LabVIEW
[End of Example]
MathScript: In MathScript you may use the obsvmx function to find the Observability matrix. You may then use the rank function in order to find the rank of the Observability matrix. MathScript Example: The following MathScript Code check for Observability:
% Check for Observability: O = obsvmx (discretemodel) r = rank(O)
31 [End of Example]
or in general: ( ( Discrete Model: Given the discrete linear state space model: ) )
or in general: ( ( ) )
Where is uncorrelated white process noise with zero mean and covariance matrix and w is uncorrelated white measurements noise with zero mean and covariance matrix , i.e. such that * * + +
* + is the expected value or mean of the process noise vector. * + is the expected value or mean of the measurement noise vector. It is normal to let and be diagonal matrices:
32
State Estimator: The state estimator is given by: Where is the Kalman Filter Gain ( )
Where is the solution to the Riccati equation. It is common to use the steady state solution of the Riccati equation (Algebraic Riccati Equation), i.e., . Note! and is used as tuning/weighting matrices when designing the Kalman Filter Gain .
33
LabVIEW: In LabVIEW Design and Simulation Module we use the CD Kalman Gain.vi in order to find K: LabVIEW Functions Palette: Control Design & Simulation Control Design State Feedback Design CD Kalman Gain.vi
Note! In LabVIEW
Note! The Kalman Filter Gain.vi is polymorphic, depending on what kind of model (deterministic/stochastic or continuous/discrete) you wire to this VI, the inputs changes automatically or you may use the polymorphic selector below the VI:
34
Front Panel:
35
[End of Example]
MathScript: Use the functions kalman, kalman_d or lqe to find the Kalman gain matrix. Function kalman Description Calculates the optimal steady-state Kalman gain K that minimizes the covariance of the state estimation error. You can use this function to calculate K for continuous and discrete system models. Calculates the optimal steady-state Kalman gain K that minimizes the covariance of the state estimation error. The input system and noise covariance are based on a continuous system. All outputs are based on a discretized system, which is based on the sample rate Ts. Calculates the optimal steady-state estimator gain matrix K for a continuous state-space model defined by matrices A and C. Example
>>[SysKal, K]=kalman(ssmodel, Q, R)
kalman_d
lqe
K=lqe(A,G,C,Q,R)
MathScript Example: Find Kalman Gain using the Kalman function MathScript Code for finding the steady state Kalman Gain:
% Define the State-space model: c=1;
36
m=1; k=1; A = [0 1; -k/m -c/m]; B = [0; 1/m]; C = [1 0]; ssmodel = ss(A, B, C); % Discrete model: Ts=0.1; % Sampling Time discretemodel = c_to_d(ssmodel, Ts); % Check for Observability: O = obsvmx(discretemodel); r = rank(O); % Find Kalman Gain Q=[0.01 0; 0 0.01]; R=[0.01]; [SysKal, K]=kalman(discretemodel, Q, R); K
MathScript Example: Find Kalman Gain using the Kalman function MathScript Code for finding the steady state Kalman Gain:
% Define the State-space model: c=1; m=1; k=1; A = [0 1; -k/m -c/m]; B = [0; 1/m]; G=[1 0 ; 0 1]; C = [1 0]; % Find Kalman Gain Q=[0.01 0; 0 0.01]; R=[0.01]; K=lqe(A,G,C,Q,R)
37
Below we show an example of how to use the CD State Estimator.vi in LabVIEW. LabVIEW Example: State Estimator Simulation Given the following model: [ ] 0 , 10 1 0 1
-0 1
We will use the CD State Estimator.vi in LabVIEW. Block Diagram becomes as follows:
38
Note! We have used CD Initial Response.vi for plotting the response. The VI is located in the LabVIEW Functions Palette: Control Design & Simulation Control Design Time Response CD Initial Response.vi The result becomes as follows:
We see the estimates are good. MathScript: In MathScript we may use the built-in estimator function.
39
Here we have the CD Discrete Kalman Filter. Simulation Estimation palette in LabVIEW:
Here we have implementations for: Continuous Kalman Filter Continuous Extended Kalman Filter Discrete Kalman Filter Discrete Extended Kalman Filter
We will go through the Discrete Kalman Filter in detail and show some examples. Discrete Kalman Filter: LabVIEW Functions Palette: Control Design & Simulation Simulation Estimation Discrete Kalman Filter
40
41
If you select Terminal in the Parameter source you may create your model in LabVIEW code like this:
LabVIEW Example: Discrete Kalman Filter Given the following linear state-space model of a water tank: [ ] 0 10 1 0 1
42 , Where is the level in the tank, while measured. Step 1: First we create the model:
Note! The Discrete Kalman Filter function in LabVIEW requires a stochastic state-space model, so we have to create a stochastic state-space model or convert our state-space model into a stochastic state-space model as done in the LabVIEW code above. Step 2: Then we use the Discrete Kalman Filter function in LabVIEW on our model:
43
The Discrete Kalman Filter function also requires a Noise model, so we create a noise model from our and matrices as done in the LabVIEW code above. The results are as follows:
Where K is the Kalman Filter Gain. Use the steady state Kalman Gain or calculate the time-varying Kalman Gain. Step 4: Find the Apriori (Predicted) state estimate update ( )
44
45 For Linear State-space model: Step 1-4 goes inside a loop in your program.
6.2 Examples
LabVIEW Example: Kalman Filter algorithm Given the following linear state-space model of a water tank: [ ] 0 , Where is the level in the tank, while measured. 10 1 0 , is 1
-0 1
First we have to find the steady state Kalman Filter Gain and check for Observability:
Then we run the real process (or simulated model) in parallel with the Kalman Filter in order to find estimates for and :
46
In this case we have used a Simulation Loop, but a While Loop will do the same. Blocks/SubVIs: Real process/Simulated process:
Here we either have a model of the system or read/write data from the real process using a DAQ card, e.g., USB-6008 from National Instruments. Implementation of the Kalman Filter Algorithm:
47
This is a general implementation and will work for all linear discrete systems. The results are as follows:
48
[End of Example]
49
50
Use the State Feedback Design VIs to calculate controller and observer gains for closed-loop state feedback control or to estimate a state-space model. You also can use State Feedback Design VIs to configure and test state-space controllers and state estimators in time domains. Kalman Filter Gain VI:
Use the Implementation VIs and functions to simulate the dynamic response of a discrete system model, deploy a discrete model to a real-time target, implement a discrete Kalman filter, and implement current and predictive observers. Discrete Kalman Filter:
51
52
Use the Estimation functions to estimate the states of a state-space system. The state-space system can be deterministic or stochastic, continuous or discrete, linear or nonlinear, and completely or partially observable.
53
LabVIEW Control Design and Simulation Module have lots of functionality for State Estimation using Observers. The functionality will be explained in detail in the next chapters.
54
55 LabVIEW:
In LabVIEW we may use the CD Construct State-Space Model.vi to create a State-space model:
Note! If you specify a discrete State-space model you have to specify the Sampling Time. LabVIEW Example: Create a State-space model Block Diagram:
The matrices ,
and
[End of Example]
56
8.2 Eigenvalues
One simple way to find the eigenvalues is to use the Butterworth eigenvalues from the Butterworth polynomial. Butterwort Polynomial: The Butterworth Polynomial is defined as: ( ) where are the coefficients in the Butterworth Polynomial.
Here we will use a 2.order Butterworth Polynomial, which is defined as: ( ) where This gives: ( ) where the parameter .
where is defined as the Observer response time where the step response reach 63% of the steady state value of the response. So we will use as the tuning parameter for the Observer.
LabVIEW: In LabVIEW we can use the Polynomial Roots.vi to find the roots based on the Butterworth Polynomial LabVIEW Functions Palette: Mathematics Polynomial Polynomial Roots.vi
57
MathScript: In MathScript we can use the roots function in order to find the eigenvalues based on a given polynomial.
58
MathScript: In MathScript we can use the acker function in order to find the Observer gain based on some given eigenvalues (found from the Butterwort Polynomial).
8.4 Observability
A necessary condition for the Observer to work correctly is that the system for which the states are to be estimated, is observable. Therefore, you should check for Observability before applying the Observer. The Observability matrix is defined as:
Where n is the system order (number of states in the State-space model). A system of order n is observable if LabVIEW: The LabVIEW Control Design and Simulation Module have a VI (Observability Matrix.vi) for finding the Observability matrix and check if a states-pace model is Observable. LabVIEW Functions Palette: Control Design & Simulation Control Design State-Space Model Analysis CD Observability Matrix.vi is full rank, meaning the rank of is equal to n.
59 Note! In LabVIEW
State Estimation with Observers in LabVIEW is used as a symbol for the Observability matrix.
[End of Example]
MathScript: In MathScript you may use the obsvmx function to find the Observability matrix. You may then use the rank function in order to find the rank of the Observability matrix. MathScript Example: The following MathScript Code check for Observability: % Check for Observability: O = obsvmx (discretemodel) r = rank(O) [End of Example]
8.5 Examples
Here we will show implementations of an Observer in LabVIEW and MathScript. Given the following linear state-space model of a water tank: [ ] 0 , Where is the level in the tank, while measured. 10 1 0 , is 1
-0 1
60
LabVIEW Example: Observer Gain Below we see the Block Diagram in LabVIEW for calculating the Observer gain:
We used the Polynomial Roots.vi in order to find the poles as specified in the Butterworth Polynomial. We use a 2.order Butterworth Polynomial: ( ) where the parameter
and
in the example.
Then we have used the CD Akerman.vi to find the Observer gain. The result becomes:
61
[End of Example]
LabVIEW Example: Observer Estimator LabVIEW have several built-in Observer functions, e.g., the CD Continuous Observer.vi we will use in this example. Below we see the Block Diagram for the Observer:
62
[End of Example]
MathScript Example: Observer Gain Here we will use MathScript in order to find the Observer gain for the same system as above. The Code is as follows:
% Define the State-space model: A = [0 -10; 0 0]; B = [0.02; 0]; C = [1 0]; D=[0]; ssmodel = ss(A, B, C,D); % Check for Observability: O = obsvmx (ssmodel); r = rank(O); %Butterwort Polynomial: B2=[1, 1.41, 1]; p=roots(B2); % Find Observer Gain K = ackermann(ssmodel, p, 'L')
64
65
Use the State Feedback Design VIs to calculate controller and observer gains for closed-loop state feedback control or to estimate a state-space model. You also can use State Feedback Design VIs to configure and test state-space controllers and state estimators in time domains. Ackermann VI:
Use the Implementation VIs and functions to simulate the dynamic response of a discrete system model, deploy a discrete model to a real-time target, implement a discrete Kalman filter, and implement current and predictive observers. Tutorial: System Identification and Estimation in LabVIEW
66 Discrete Observer:
67
Use the Estimation functions to estimate the states of a state-space system. The state-space system can be deterministic or stochastic, continuous or discrete, linear or nonlinear, and completely or partially observable. Continuous Observer VI:
68
69
70
In the next chapters we will use the different functionality available in the System Identification Toolkit.
10.1
Method (LS)
Parameter Estimation using the Least Square Method (LS) is used to find a model with unknown physical parameters in a mathematical model. The Least square method can be written as:
Where is the unknown parameter vector is the known measurement vector is the known regression matrix The solution for may be found as:
It can be found that the least square solution for ( Implementation in MathScript/MATLAB: theta=inv(phi*phi)* phi*Y or simply: theta=phi\Y )
is:
In LabVIEW we can use the blocks (AxB.vi, Transpose Matrix.vi, Inverse Matrix.vi) in the Linear Algebra (located in the Mathematics palette) palette in order to fin the Least Square solution:
71
Example: Given the following model: ( ) The following values are found from experiments: ( ) ( ) ( ) We will find the unknowns and using the Least Square (LS) method in MathScript/LabVIEW.
We have that:
Where is the unknown parameter vector is the known measurement vector is the known regression matrix Tutorial: System Identification and Estimation in LabVIEW
is:
phi = [1 1; 2 1; 3 1]; Y = [0.8 3.0 4.0]'; theta = inv(phi'*phi)* phi'*Y %or simply by theta=phi\Y
This gives: ( )
Front Panel:
[End of Example]
10.2
methods/Black-Box methods
Sub-space methods/Black-Box methods is used to find a model with non-physical parameters. A sub-space methods/Black-Box method estimates a linear discrete State-space model on the form:
74
LabVIEW offers functionality for this. In the Parametric Model Estimation palette we find the SI Estimate State-Space Model.vi which can be used for sub-space identification. Parametric Model Estimation palette:
10.3
75
10.4
In order to find a model we need to generate data based on the real process. The stimulus (exitation) signal and the response signal will then be input to the functions/VIs (algorithms) in LabVIEW that you will use to model your process. Below we explain how we do this in LabVIEW. Tutorial: System Identification and Estimation in LabVIEW
76 Datalogging:
Use LabVIEW for exciting the process and logging signals. Use open-loop experiments (no feedback control system). You can use the Write to Measurement File function on the File I/O palette in LabVIEW for writing data to text files (use the LVM data file format, not the TDMS file format which give binary files). In the File I/O palette in LabVIEW we have lots of functionality for writing and reading files. Below we see the File I/O palette in LabVIEW:
In this Tutorial we will focus on the Write To Measurement File and Read From Measurement File.
The Write To Measurement File and Read From Measurement File is so-called Express VIs. When you drag these VIs to the Block Diagram, a configuration dialog pops-up immediately, like this:
77
In this configuration dialog you set file name, file type, etc. Note that these Express VIs have no Block Diagram.
10.4.1
Excitation signals
It is important to have a good excitation signal, you can use different excitation signals, such as: A PRBS signal (Pseudo Random Binary Signal) A Chirp Signal A Up-down signal
LabVIEW: In LabVIEW you can use some of the functions in the Signal Generation palette:
78
LabVIEW: In LabVIEW you can use the SI Generate Pseudo-Random Binary Sequence.vi function. LabVIEW Functions Palette: Control Design & Simulation System identification Utilities SI Generate Pseudo-Random Binary Sequence.vi
79
LabVIEW: In LabVIEW you can use the Chirp Pattern.vi function. LabVIEW Functions Palette: Signal Processing Signal Generation Chirp Pattern.vi
Use the System Identification VIs to create and estimate mathematical models of dynamic systems. You can use the VIs to estimate accurate models of systems based on observed input-output data. The System Identification palette in LabVIEW has the following subpalettes: Icon Name Data Preprocessing Preprocessing Description Use the Data Preprocessing VIs to preprocess the raw data that you acquired from an unknown system.
80
Overview of System Identification functions Use the Parametric Model Estimation VIs to estimate a parametric mathematical model for an unknown, linear, time-invariant system. Use the Frequency-Domain Model Estimation VIs to estimate the frequency response function (FRF) and to identify a transfer function (TF) or a state-space (SS) model of an unknown system. Use the Partially Known Model Estimation VIs to create and estimate partially known models for the plant in a system. Use the Recursive Model Estimation VIs to recursively estimate the parametric mathematical model for an unknown system. Use the Nonparametric Model Estimation VIs to estimate the impulse response or frequency response of an unknown, linear, time-invariant system from an input and corresponding output signal. Use the Model Validation VIs to analyze and validate a system model. Use the Model Analysis VIs to perform a Bode, Nyquist, or pole-zero analysis of a system model and to compute the standard deviation of the results. Use the Model Conversion VIs to convert models created in the LabVIEW System Identification Toolkit into models you can use with the LabVIEW Control Design and Simulation Module. You can convert an AR, ARX, ARMAX, output-error, Box-Jenkins, general-linear, or state-space model into a transfer function, zero-pole-gain, or state-space model. You also can convert a continuous model to a discrete model or convert a discrete model to a continuous model. Use the Model Management VIs to access information about the system model. Model
Partially Known Model Estimation Grey-Box Recursive Model Estimation Recursive Nonparametric Model Estimation Nonparametri c
Model Management
82 Management
Overview of System Identification functions information includes properties such as the system type, sampling rate, system dimensions, noise covariance, and so on. Utilities Utilities Use the Utilities VIs to perform miscellaneous tasks on data or the system model, including producing data samples, displaying model equations, merging models, and so on.
83
The Parametric Model Estimation palette in LabVIEW has subpalette for Polynomial Model Estimation:
84
Use the Polynomial Model Estimation VIs to estimate an AR, ARX,ARMAX, Box-Jenkins, or output-error model for an unknown, linear, time-invariant system. Some important functions in the Polynomial Model Estimation palette are:
i.e. [ ]
In order to find using the Least Square method we need to log input and output data. This means we need to discretize the system. We use a simple Euler forward method: is the sampling time.
85
86 This gives: [ ][ ]
Lets assume (which can be found from a simple step response on the real system), we then get (with sampling time ): , -[ ]
!!!
Given the following logging data (the data is just for illustration and not realistic):
3 4 5 6 7 8 9
87 Using the given data set we can set on the form [ i.e.: [ ] [ ][ ] ] [ : ][ ]
MathScript responds with the following answers: theta = -0.3333 3.3333 T = 3 K = 3.3333 i.e., the model parameters become:
88
Implement the model in LabVIEW. Use , , simulate the system. Plot the step response for the system.
Model: Where , , ( )
and
Solutions:
We implement the model using a Simulation Subsystem and use the available blocks in the Control and Design Module. The model may be implemented as follows:
We simulate the system using the following program: Block Diagram: Tutorial: System Identification and Estimation in LabVIEW
89
90
Plot the step response for the transfer function in MathScript. Compare and discuss the results from previous task.
Solutions:
We use the differential equation: Laplace transformation gives: ( ) ( ) ( ) ( )
Note! We use the following Laplace transformation: ( ) ( ) Then we get: ( ) and: ( )( and: ( ) ( ) Finally: ) ( ) ( ) ( ) ( ( ) )
We implement the transfer function in MathScript and perform a step response. We use the step() function.
clear, clc s=tf('s'); K=2; T=5; H1=tf(K*T/(T*s+1)); delay=3; H2=set(H1,'inputdelay',delay); step(H2) % You may also use: figure(2) H = sys_order1(K*T, T, delay) step(H)
92
We see that the step response is the same as in the previous task.
Solutions:
We save the data using Write To Measurement File in LabVIEW. Based on a simple step response we can find the time-delay We use the same application as in a previous task: .
93
Find the model parameters data. Note! The answers should be Model:
og
and
Where , ,
Solutions:
It is a good idea to split your program into different logical parts using, e.g., SubVIs in LabVIEW.
The different parts/steps could, e.g., be: 1. Get Logged Data from File a. Input: File Name b. Outputs: and ( ) 2. Transform the data and stack data into a. Inputs: and ( )
and
94 b. Outputs: and 3. Find the Least Square solution a. Input: and b. Output: ( )
Front Panel:
95
and
(as expected).
The different SubVIs do the following: 1. Open Measurement Data from File.vi This SubVI opens the logged data from file (created in a previous task). Block Diagram:
96
2. Create LS Matrices from Logged Data with Time Delay.vi This SubVI stack data on the form: [ ][ ]
Block Diagram:
3. Find LS Solution.vi This SubVI find the LS solution: ( Block Diagram: Tutorial: System Identification and Estimation in LabVIEW )
97
Telemark University College Faculty of Technology Kjlnes Ring 56 N-3914 Porsgrunn, Norway www.hit.no
Hans-Petter Halvorsen, M.Sc. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics
Phone: +47 3557 5158 E-mail: [email protected] Blog: http://home.hit.no/~hansha/ Room: B-237a