Product Support
1813 - How Do I Use Time-varying Transfer Functions in Simulink?
Information on Time-Varying blocks, such as Time-Varying Transfer Functions and Time-Varying State blocks, is often requested by Simulink users. All Time-Varying blocks accept coefficients that determine the blocks' behavior, as well as the signal values that propagate through the system. Time-varying Transfer Functions, which can be either continuous or discrete, are the topic of this Technical Note.
Why would you use a Time-Varying Transfer Functions? A good example would be to implement an adaptive controller. Previously, if you wanted to set the values of a Transfer Function block, there were two options:
- Double-click on the block and enter the values manually
- Use SET_PARAM
Double-clicking is not very useful for doing adaptive control, and SET_PARAM is difficult to implement. An S-function must first be written to read in values from the plant output and perform the necessary calculations for updating the controller, before SET_PARAM can be used on the block(s)to make the change dynamically.
The Time-Varying Transfer Function block provides a way to work around this issue. An example of how to use the Time-Varying Transfer Function block is shown in the model rlsest.mdl in $matlab\toolbox\simulink\simdemos, where $matlab refers to your MATLAB root directory.
The simulation illustrates how Simulink can be used for adaptive control of a second order transfer function. A recursive Least-Squares Estimator block is used to estimate the plant parameters. The output of this block, the plant parameters, are fed to a Pole Placement block. Both the Least-Squares Estimator block and the Pole Placement block are implemented using S-functions. With the previous version of this model, the Pole Placement block modified the compensator transfer function by using the set_param function; the output of the S-function has no physical connection to the controller.
In this model, the output of the Pole Placement block is used to drive the time-varying discrete transfer function. The Time-Varying Discrete Transfer Function block takes three inputs: the input signal, the numerator coefficients, and the denominator coefficients. The overall operation of the model has not changed; however, all versions of the system show both the control and parameter feedback loops explicitly.
The Time-Varying Discrete Transfer Function block is also available in its continuous-time counterpart, with its operation being identical. Both blocks require initial numerator and denominator coefficients and a parameter sample time that specifies how often the coefficients are updated. The discrete-time version of this block also requires a sample time for the block.
The included code shows how Work Vectors and the SimStruct are used to implement the Time-Varying Discrete Transfer Function block. The filenames for these two blocks are stvctf.c (continuous) and stvdtf.c (discrete). These files are located in $matlab\simulink\src.
Store