Skip to Main Content Skip to Search
Home |   United Kingdom  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Industries Academia Support User Community Company

 

Product Support

1811 - How Do I Create Time Varying Matrix Gain and State-space Blocks as C MEX S-functions?


Using Simulink 2, you can create Time-Varying Matrix Gain and Time-Varying State-Space blocks as CMEX S-functions. This is possible, in part, by the addition of work vectors, which allow for local storage of data in an S-function. Time-Varying blocks have parameters which can be updated "on the fly." This means the gain matrix can be automatically changed during simulation. This gain matrix can be the output of another block in vectorized form, or an array of stored values in a file or workspace.

The Time-Varying Matrix Gain block takes two inputs of varying width; the gain matrix (in vector form) and the system input. To perform the matrix multiplication, the width of the input signal must match the number of columns of the gain matrix. A gain matrix of the appropriate size must be used to initialize the block. This initial value determines how the block handles the incoming gain vector, since Simulink can only transmit vectors or scalars. The number of rows and columns of the incoming vectorized matrix can be determined from the size of the initial gain matrix.

The block also takes another input argument, a sample time, which determines how often the block is updated.

The block, after being initialized, uses two main functions; mdlOutputs, which performs the matrix multiplication, and mdlUpdate, which reads in the new gain values. The file stvmgain.c is well commented to show the block's operation. The block is demonstrated using a constant matrix input in the file tvgte.mdl.

The Time-Varying Matrix Gain block is the basis for the Time-Varying State-Space block. The following diagram shows how the Time-Varying State Space Block is implemented.

This implements the state-space equations

x' = Ax + Bu
        y = Cx + Du 

and is the underlying structure of the Time-Varying State-Space block. This block, which is saved as stvss.mdl, can be unmasked to see this model. A discrete version of this block is also available, which replaces the integrator in the above model with a unit delay. The discrete version accepts two sample times, one for the delay and one for the block update. This block is demonstrated as dtvss.mdl.

Time-Varying Transfer Function blocks are also available in both continuous and discrete forms.

The source code for stvmgain and the two .mdl files can be donwloaded below:

Contact support
E-mail this page
Print this page