Skip to Main Content Skip to Search
Product Documentation

Controlling Block Linearization

Why Specify Block Linearization Behavior?

Simulink blocks with sharp discontinuities produce poor linearization results. Typically, you must specify a custom linearization for such blocks.

When your model operates in a region away from the point of discontinuity, the linearization is zero. A block with discontinuity linearizing to zero can cause the linearization of the system to be zero when this block multiplies other blocks.

For other types of blocks, you can specify the block linearization as a:

Specify Linear System for Block Linearization Using MATLAB Expression

This example shows how to specify the linearization of any block, subsystem, or model reference without having to replace this block in your Simulink model.

  1. Right-click the block in the model, and select Linear Analysis > Specify Linearization.

    The Block Linearization Specification dialog box opens.

  2. In the Specify block linearization using a list, select MATLAB Expression.

  3. In the text field, enter an expression that specifies the linearization.

    For example, specify the linearization as an integrator with a gain of k, G(s) = k/s.

    In state-space form, this transfer function corresponds to ss(0,1,k,0).

    Click OK.

  4. Linearize the model.

Specify D-Matrix System for Block Linearization Using Function

This example shows how to specify custom linearization for a saturation block using a function.

  1. Open Simulink model.

    sys = 'scdConfigBlockFcn';
    open_system(sys)

  2. Linearize the model at the model operating point.

    io = getlinio(sys);
    linsys = linearize(sys,io)

    The presence of the saturation blocks causes the model to linearize to zero.

    d = 
                     Desired  Wat
       Water-Tank S             0
     
    Static gain.
  3. Write a function that defines the saturation block linearization.

    For example, the next configuration function defines the saturation block linearization based on the level of the block input signal. Your configuration function must be on the MATLAB path during linearization.

     Linearization Configuration Function

  4. In the Simulink model, right-click the Saturation block, and select Linear Analysis > Specify Linearization.

    The Block Linearization Specification dialog box opens.

  5. Select the Specify block linearization using one of the following check box, and choose Configuration Function from the list.

    Configure the linearization function:

    • Enter the function name. In this example, the function name is mySaturationLinearizationFcn.

    • Specify the function parameters. mySaturationLinearizationFcn requires the saturation limit value, which the user must specify before linearization.

      Enter the variable name satlimit in Parameter Value. Enter the corresponding descriptive name in the Parameter Name column, SaturationLimit.

    • Click OK.

    Configuring the Block Linearization Specification dialog box updates the model to use the specified linearization function for linearizing the Saturation Block. Specifically, this configuration automatically populates the Parameters field of the BlockData structure, which is the input argument to the configuration function.

      Note   You can add function parameters by clicking . Use to delete selected parameters.

     Code Alternative

  6. Define the saturation limit, which is a parameter required by the linearization function of the Saturation block.

    satlimit = 10;
  7. Linearize the model using the custom linearization of the Saturation block.

    linsys_cust = linearize(sys,io)

    The system linearized to:

    d = 
                     Desired  Wat
       Water-Tank S           0.5
     
    Static gain.

Augmenting the Linearization of a Block

This example shows how to augment the linearization of a block with additional time delay dynamics, using a block linearization specification function.

  1. 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.

  2. (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.

  3. (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.

  4. 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).

  5. Specify the configuration function scdAddDelayFcn as the linearization for the Controller block.

    1. Right-click the Controller block, and select Linear Analysis > Specify Linearization.

    2. Select the Specify block linearization using one of the following check box. Then, select Configuration Function from the drop-down list.

    3. Enter the function name scdAddDelayFcn in the text box. scdAddDelayFcn has no parameters, so leave the parameter table blank.

    4. Click OK.

  6. 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.

  7. (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.

Models With Time Delays

Choosing Approximate Versus Exact Time Delays

Simulink Control Design lets you choose whether to linearize models using exact representation or Pade approximation of continuous time delays. How you treat time delays during linearization depends on your nonlinear model.

Simulink blocks that model time delays are:

Linearization uses Pade approximation for representing time delays in your linear mode, by default.

Use Pade approximation to represent time delays when:

Specify to linearize models with exact time delays for:

Specifying Exact Representation of Time Delays

Before linearizing your model:

 Related Examples

 More About

Perturbation Level of Blocks Perturbed During Linearization

Blocks that do not have preprogrammed analytic Jacobians linearize using numerical perturbation.

Change Block Perturbation Level

This example shows how to change the perturbation level to the Magnetic Ball Plant block in the magball model. Changing the perturbations level changes the linearization results.

The default perturbation size is 10-5(1+|x|), where x is the operating point value of the perturbed state or the input.

Open the model before changing the perturbation level.

To change the perturbation level of the states to , where x is the state value, type:

blockname='magball/Magnetic Ball Plant'
set_param(blockname,'StatePerturbationForJacobian','1e-7')

To change the perturbation level of the input to , where x is the input signal value:

  1. Open the system and get the block port handles.

    sys = 'magball';
    open_system(sys);
    blockname = 'magball/Magnetic Ball Plant';
    ph = get_param(blockname,'PortHandles')
    
  2. Get the handle to the inport value.

    p_in = ph.Inport(1)
    
  3. Set the inport perturbation level.

    set_param(p_in,'PerturbationForJacobian','1e-7')

Perturbation Levels of Integer Valued Blocks

A custom block that requires integer input ports for indexing might have linearization issues when this block:

To fix the problem, try setting the perturbation level of such a block to zero (which sets the block linearization to a gain of 1).

Blocks with Nondouble Precision Data Type Signals

You can linearize blocks that have nondouble precision data type signals as either inputs or outputs, and have no preprogrammed exact linearization. Without additional configuration, such blocks automatically linearize to zero. For example, logical operator blocks have Boolean outputs and linearize to 0.

Linearizing blocks that have nondouble precision data type signals requires converting all signals to double precision. This approach only works when your model can run correctly in full double precision.

When you have only a few blocks impacted by the nondouble precision data types, use a Data Type Conversion block to fix this issue.

When you have many nondouble precision signals, you can override all data types with double precision using the Fixed-Point Tool.

Overriding Data Types Using Data Type Conversion Block

Convert individual signals to double precision before linearizing the model by inserting a Data Type Conversion block. This approach works well for model that have only a few affected blocks.

After linearizing the model, remove the Data Type Conversion block from your model.

For example, consider the model configured to linearize the Square block at an operating point where the input is 1. The resulting linearized model should be 2, but the input to the Square block is Boolean. This signal of nondouble precision date type results in linearization of zero.

In this case, inserting a Data Type Conversion block converts the input signal to the Square block to double precision.

Overriding Data Types Using Fixed-Point Tool

When you linearize a model that contains nondouble data types but still runs correctly in full double precision, you can override all data types with doubles using the Fixed-Point Tool. Use this approach when you have many nondouble precision signals.

After linearizing the model, restore your original settings.

  1. In the Simulink model, select Tools > Fixed-Point > Fixed-Point Tool.

    The Fixed-Point Tool opens.

  2. In the Data type override menu, select Double.

    This setting uses double precision values for all signals during linearization.

  3. Restore settings when linearization completes.

Event-Based Subsystems (Externally Scheduled Subsystems)

Linearizing Event-Based Subsystems

Event-based subsystems (triggered subsystems) and other event-based models require special handling during linearization.

Executing a triggered subsystem depends on previous signal events, such as zero crossings. However, because linearization occurs at a specific moment in time, the trigger event never happens.

An example of an event-based subsystem is an internal combustion (IC) engine. When an engine piston approaches the top of a compression stroke, a spark causes combustion. The timing of the spark for combustion is dependent on the speed and the position of the engine crankshaft.

In engine.mdl, triggered subsystems generate events when the pistons reach both the top and bottom of the compression stroke. Linearization in the presence of such triggered subsystems is not meaningful.

Approaches for Linearizing Event-Based Subsystems

You can obtain a meaningful linearization of triggered subsystems, while still preserving the simulation behavior, by recasting the event-based dynamics as one of the following:

If recasting event-based dynamics does not produce good linearization results, try frequency response estimation. See Estimating Frequency Response.

Periodic Function Call Subsystems for Modeling Event-Based Subsystems

This example shows how to use periodic function call subsystems to approximate event-based dynamics for linearization.

  1. Open Simulink model.

    sys = 'scdPeriodicFcnCall';
    open_system(sys)
  2. Linearize model at the model operating point.

    io = getlinio(sys);
    linsys = linearize(sys,io)

    The linearization is zero because the subsystem is not a periodic function call.

    d = 
                     Desired  Wat
       Water-Tank S             0
     Static gain.

    Now, specify the Externally Scheduled Controller block as a Periodic Function Call Subsystem.

  3. Double-click the Externally Scheduled Controller (Function-Call Subsystem) block.

    Double-click the function block to open the Block Parameters dialog box.

  4. Set Sample time type to be periodic.

    Leave the Sample time value as 0.01, which represents the sample time of the function call.

  5. Linearize the model.

    linsys2 = linearize(sys,io)
     
    a = 
                            H  Integrator
       H               0.9956    0.002499
       Integrator  -0.0007774           1
     
    b = 
                   Desired  Wat
       H               0.003886
       Integrator     0.0007774
     
    c = 
                              H  Integrator
       Water-Tank S           1           0
     
    d = 
                     Desired  Wat
       Water-Tank S             0
     
    Sampling time: 0.01
    Discrete-time model.
  6. Plot step response.

    step(linsys2)

  7. Close the model.

    bdclose(sys);

Approximating Event-Based Subsystems Using Curve Fitting (Lump-Average Model)

This example shows how to use curve fitting to approximate event-based dynamics of an engine.

The scdspeed.mdl model linearizes to zero because scdspeed/Throttle & Manifold/Intake Manifold is an event-triggered subsystem.

You can approximate the event-based dynamics of the scdspeed/Throttle & Manifold/Intake Manifold subsystem by adding the Convert to mass charge block inside the subsystem.

The Convert to mass charge block approximates the relationship between Air Charge, Manifold Pressure, and Engine Speed as a quadratic polynomial.

If measured data for internal signals is not available, use simulation data from the original model to compute the unknown parameters p1, p2, p3, p4, and p5 using a least squares fitting technique.

When you have measured data for internal signals, you can use the Simulink® Design Optimization™ software to compute the unknown parameters. See Engine Speed Model Parameter Estimation to learn more about computing model parameters, linearizing this approximated model, and designing a feedback controlled for the linear model.

The next figure compares the simulations of the original event-based model and the approximated model. Each of the pulses corresponds to a step change in the engine speed. The size of the step change is between 1500 and 5500. Thus, you can use the approximated model to accurately simulate and linearize the engine between 1500 RPM and 5500 RPM.

  


Free Control Systems Interactive Kit

Learn more about resources for designing, testing, and implementing control systems.

Get free kit

Trials Available

Try the latest control systems products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS