This example shows how to augment the linearization of a block with additional time delay dynamics, using a block linearization specification function.
Open Simulink® model.
mdl = 'scdFcnCall';
open_system(mdl)
This model includes a continuous time plant, Plant
, and a
discrete-time controller, Controller
. The D/A
block
discretizes the plant output with a sampling time of 0.1 s. The External
Scheduler
block triggers the controller to execute with the same period, 0.1
s. However, the trigger has an offset of 0.05 s relative to the discretized plant output.
For that reason, the controller does not process a change in the reference signal until
0.05 s after the change occurs. This offset introduces a time delay of 0.05 s into the
model.
(Optional) Linearize the closed-loop model at the model operating point without
specifying a linearization for the Controller
block.
io = getlinio(mdl); sys_nd = linearize(mdl,io);
The getlinio
function returns the linearization
input and output points that are already defined in the model.
(Optional) Check the linearization result by frequency response estimation.
input = frest.Sinestream(sys_nd); sysest = frestimate(mdl,io,input); bode(sys_nd,'g',sysest,'r*',{input.Frequency(1),input.Frequency(end)}) legend('Linearization without delay',... 'Frequency Response Estimation','Location','SouthWest')
The exact linearization does not account for the time delay introduced by the controller execution offset. A discrepancy results between the linearized model and the estimated model, especially at higher frequencies.
Write a function to specify the linearization of the Controller
block that includes the time delay.
The following configuration function defines a linear system that equals the default
block linearization multiplied by a time delay. Save this configuration function to a
location on your MATLAB® path. (For this example, the function is already saved as
scdAddDelayFcn.m
.)
function sys = scdAddDelayFcn(BlockData)
sys = BlockData.BlockLinearization*thiran(0.05,0.1);
The input to the function, BlockData
, is a structure that the
software creates automatically each time it linearizes the block. When you specify a block
linearization configuration function, the software automatically passes
BlockData
to the function. The field
BlockData.BlockLinearization
contains the current linearization of
the block.
This configuration function approximates the time delay as a thiran
filter. The filter indicates a discrete-time approximation of the
fractional time delay of 0.5 sampling periods. (The 0.05 s delay has a sampling time of
0.1 s).
Specify the configuration function scdAddDelayFcn
as the
linearization for the Controller
block.
Right-click the Controller
block, and select Linear Analysis > Specify Selected Block Linearization.
Select the Specify block linearization using one of the following check box. Then, select Configuration Function from the drop-down list.
Enter the function name scdAddDelayFcn
in the text box.
scdAddDelayFcn
has no parameters, so leave the parameter table
blank.
Click OK.
Linearize the model using the specified block linearization.
sys_d = linearize(mdl,io);
The linear model sys_d
is a linearization of the closed-loop model
that accounts for the time delay.
(Optional) Compare the linearization that includes the delay with the estimated frequency response.
bode(sys_d,'b',sys_nd,'g',sysest,'r*',... {input.Frequency(1),input.Frequency(end)}) legend('Linearization with delay','Linearization without delay',... 'Frequency Response Estimation','Location','SouthWest')
The linear model obtained with the specified block linearization now accounts for the time delay. This linear model is therefore a much better match to the real frequency response of the Simulink model.