LFRT and Simulink tutorial


Jean-Marc Biannic, July 2006, version 1.1.

TOOLBOXES TUTORIAL


Introduction

This module of the LFR Toolbox is for simulation and modelling of LFR-objects using Simulink.

This new version is unfortunately not fully compatible with the previous one (version 1.0). Consequently, it is strongly recommended to update the simulink diagrams which have been constructed with objects from LFRbuild-v1.0 or LFRsim-v1.0 and to replace those by the new objects.

If the user is familiar with the LFR Toolbox, then it is very easy to get started with these complementary Simulink tools.

The quickest way to get started is to take a look at following files :

  • slk/demo/ex_buildLFR.m : building an interconnected LFR object
  • slk/demo/ex_RL.m : building and simulating a amplitude/rate limited actuator in LFR format
  • slk/demo/ex_simLFRa.m : simulating LFR objects, case with constant block
  • slk/demo/ex_simLFRb.m : simulating LFR objects, a nonlinear blocks
  • slk/demo/ex_simLFRc.m : simulating LFR objects, mixed cases

TOP


Simulink libraries

Type LFRsim (simulation) or LFRbuild (modelling) in a Matlab command window, then, "drag and drop" objects from one library (images below) into a Simulink window. You can click on some Simulink boxes.

LFRsim

LFRbuild

TOP


Simulation of a dynamic system.

An LFR-object has the following form:

kdelta

It can be implemented with on-line inversion as in the above formula or using a fixed point algorithm as shown below (iter will denote the number of iterations of this fixed point algorithm performed within each Simulink sampling period).

fixedpoint

Let us consider the first illustrative example of ex_simLFRa.m

First is defined an LFR-object:

% Definition of the LFR-object :
% y = ((x2^2)/x1)*u (constant block because of inversion 1/x1)

   lfrs x1 x2;
   sysLFR1=x2^2/x1;
   size(sysLFR1)

   LFR-object with 1 output(s), 1 input(s) and 0 state(s).
   Dimension of constant block in uncertainty matrix: 1
   Uncertainty blocks (globally (3 x 3)):
    Name  Dims  Type   Real/Cplx   Full/Scal   Bounds
    x1    1x1   LTI       r           s        [-1,1]
    x2    2x2   LTI       r           s        [-1,1]

simLFRa11

Simulation using different options for precision. Option iter = 0 corresponds to the exact computation of LFR-objects (on-line inversion), iter = -1 to a simple delays to avoid on-line matrix inversion, iter = 1 to iter = 10 are the number of iterations of a fixed point algorithm which replaces the on-line inversion.

% call Simulink diagram and compare with a direct implementation
% standard approach (iter=0) (on-line matrix inversion at each step) 

   iter=0;
   demo_simLFRa1;
   sim('demo_simLFRa1');

% loop delay to avoid on-line matrix inversion

   iter=-1;
   demo_simLFRa1;
   sim('demo_simLFRa1');  % small problem at t=1s

% fast simulation with 3 iterations / step

   iter=3;
   demo_simLFRa1;
   sim('demo_simLFRa1'); % small problem has disappeared !
The results are given below for iter=-1 (left) and iter=3 (right) (results are almost similar for iter=-1 and iter=1). With 3 iterations, it is not possible to distinguish between the direct implementation and the LFR-object implementation. The fixed point algorithm is much faster than the on-line inversion.

demo_simLFRa13   demo_simLFRa14

TOP


Simulation of a dynamic system with nonlinear components.

The following example illustrates the use on nonlinear components. First is defined an LFR-object with two scalar nonlinear blocks which will be defined in Simulink as saturations:

% scalar nonlinearity for rate-limitation
   NL_satr=lfr('NL_satr','nlms',1);
% scalar nonlinearity for amplitude-limitation
   NL_sata=lfr('NL_sata','nlms',1);

   lfrs Int x1 x2
   sysLFR_NL=feedback(Int*NL_satr*10,1)*NL_sata;
   sys0=x1/(1+0.5*x2*x2);
   sysLFR_del=sys0^12 + ss(-2,1,1,0);

   sysLFR_mixed = sysLFR_del*sysLFR_NL;
   size(sysLFR_mixed)

   LFR-object with 1 output(s), 1 input(s) and 2 state(s).
   Uncertainty blocks (globally (38 x 38)):
    Name    Dims  Type   Real/Cplx   Full/Scal   Bounds
    NL_sata 1x1   NLM       r           s        ...
    NL_satr 1x1   NLM       r           s        ...
    x1      12x12 LTI       r           s        [-1,1]
    x2      24x24 LTI       r           s        [-1,1]

   demo_simLFRc;

symLFRcbis

Simulation using different options for precision. Option iter = 0 corresponds to the exact computation of LFR-objects (on-line inversion), iter = 1 to iter = 10 are the number of iterations of a fixed point algorithm which replaces the on-line inversion.

   iter=0;
   tic; sim('demo_simLFRc'); toc

   Elapsed time is 32.465063 seconds.

   iter=2;
   tic; sim('demo_simLFRc'); toc

   Elapsed time is 2.139248 seconds

   iter=10;
   tic; sim('demo_simLFRc'); toc

   Elapsed time is 2.357034 seconds

The results are given below for iter=1 (left) and iter=10 (right). In both cases, it is not possible to distinguish between the direct implementation and the LFR-object implementation. The fixed point algorithm is 14 times faster than the on-line inversion.

simLFRcresult1       simLFRcresult10

TOP


Building an interconnected LFR object.

The function slk2lfr is used in order to build the LFR-object corresponding to LFR-objects interconnected in a Simulink diagram. First, two systems sys1 and sys2 are generated in the Matlab workspace:

   x3 = lfr('x3','ltifc',[3 2],pck(-1,1,1,0),'freq');
   lfrs x1
   sys1 = x1*x3;           % Contains a full complex block
   sys2 = rlfr(2,4,3,2,2); % Random dynamic system

   demo_buildLFR1;

slk2lfr2

% Computation of the interconnected object
   sys = slk2lfr('demo_buildLFR1');
   size(sys)

   LFR-object with 4 output(s), 2 input(s) and 5 state(s).
   Uncertainty blocks (globally (10 x 9)):
    Name  Dims  Type   Real/Cplx   Full/Scal   Bounds
    x1    5x5   LTI       r           s        [-1,1]
    x2    2x2   LTI       r           s        [-1,1]
    x3    3x2   LTI       c           f        freq. dependent

% Comparison
    lfrs Int;
    sysInt = append(Int,Int,Int);
    sysa=sys2*sysInt*sys1;
    sysb=eye(2,4);
    sysc = feedback(sysa,sysb,+1);
    distlfr(sys,sysc)

   ans =

   1.4050e-14

TOP


Installation

  • This Toolbox is a comlement of the LFR Toolbox LFRT V2.0.
  • Then, download and unzip the following file: LFRTv2_slkv11.zip (Matlab 6.x and higher/ Simulink 5.x and higher)
  • This will generate a directory slk which should be placed in the main directory LFRTv20pre1 (for example) of the LFR Toolbox.
  • LFRTv20pre1 /...
                /slk
                /slk/demo
                /slk/sub
    
  • As a final point, you must update your Matlab path as follows :
    path('.../toolbox/LFRTv20pre1/slk',path);
    path('.../toolbox/LFRTv20pre1/slk/demo',path);
    path('.../toolbox/LFRT_v20pre1/slk/demo',path);
    

TOP