Skip to Main Content Skip to Search
Product Documentation

Linearize at Simulation Snapshots and Triggered Events

Linearize at Simulation Snapshot

This example shows how to use the Linear Analysis Tool to linearize a model by simulating the model and extracting the state and input levels of the system at specified simulation times.

 Code Alternative

  1. Open Simulink model.

    sys = 'watertank';
    open_system(sys)

  2. In the Simulink model window, select Tools > Control Design > Linear Analysis.

    This action opens the Linear Analysis Tool for the model.

  3. In the Simulink model window, define the portion of the model to linearize:

    • Right-click the PID Controller block output signal (input signal to the plant model). Select Linearization Points > Input Point.

    • Right-click the Water-Tank System output signal, and select Linearization Points > Output Point.

    • Right-click the Water-Tank System output signal, and select Linearization Points > Open Loop.

    In the Exact Linearization tab of the Linear Analysis Too, click for the Analysis I/Os list to see the selected linearization input and output points.

  4. In the Operating Point list, select Take simulation snapshot....

  5. Enter 10 in the Simulation Snapshot Times field to extract the operating point at this simulation time.

    Click Take Snapshots.

    This action takes a snapshot of the system at the specified time. The operating point op_snapshot1 appears in the Linear Analysis Workspace.

      Note   To linearize the model at several operating points, specify a vector of simulation times in the Simulation Snapshot Times field. For example, [1 10] results in two linear model at 1 and 10 time units.

  6. In the Exact Linearization tab, select op_snapshot1 in the Operating Point drop-down list.

  7. Select New Bode in the Plot Result list.

  8. Click to linearize the model.

    The Bode plot of the linearized system appears. This Bode plot looks like a stable first-order response, as expected.

  9. Double click linsys1 in Linear Analysis Workspace to see the state space representation of the linear model.

  10. Close Simulink model.

    bdclose(sys);

 Related Examples

Linearize at Triggered Simulation Events

This example shows how to use the Linear Analysis Tool to linearize a model at specific events in time. Linearization events can be trigger-based events or function-call events. Specifically, the model will be linearized at the steady-state operating points 2500, 3000, and 3500 rpm.

  1. Open Simulink model.

    sys = 'scdspeedtrigger';
    open_system(sys)

    To help identify when the system is at steady state, the Generate settling time events block generates settling events. This block sends rising edge trigger signals to the Operating Point Snapshot block when the engine speed settles near 2500, 3000, and 3500 rpm for a minimum of 5 seconds.

    The model already includes the Trigger-Based Operating Point Snapshot block from the Simulink Control Design library. This block linearizes the model when it receives rising edge trigger signals from the Generate settling time events block.

  2. Compute the steady-state operating point at 60 time units.

    op = findop(sys,60);

    This command simulates the model for 60 time units, and extracts the operating points at each simulation event that occurs during this time interval.

  3. Define the portion of the model to linearize.

    io(1) = linio('scdspeedtrigger/Reference Steps',1,'in');
    io(2) = linio('scdspeedtrigger/rad//s to rpm',1,'out');
  4. Linearize the model.

    linsys = linearize(sys,op(1:3),io);
  5. Compare linearized models at 500, 3000, and 3500 rpm using Bode plots of the closed-loop transfer functions.

    bode(linsys);

 Related Examples

 More About

Visualize Linear System Characteristics at Multiple Simulation Snapshots

This example shows how to visualize linear system characteristics of a nonlinear Simulink model at multiple simulation snapshots.

  1. Open Simulink model.

    For example:

    watertank
  2. Open the Simulink Library Browser by selecting View > Library Browser in the model window.

  3. Add a plot block to the Simulink model.

    1. In the Simulink Control Design library, select Linear Analysis Plots.

    2. Drag and drop a block, such as the Gain and Phase Margin Plot block, into the Simulink model window.

      The model now resembles the following figure.

      For more information on the blocks, see the Linear Analysis Plots block reference pages.

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

    To learn more about the block parameters, see the block reference pages.

  5. Specify the linearization I/O points.

      Tip   If your model already contains I/O points, the block automatically detects these points and displays them.

    1. To specify an input:

      1. Click adjacent to the Linearization inputs/outputs table.

        The Block Parameters dialog expands to display a Click a signal in the model to select it area.

      2. In the Simulink model, click the output signal of the PID Controller block to select it.

        The Click a signal in the model to select it area updates to display the selected signal.

      3. Click to add the signal to the Linearization inputs/outputs table.

    2. To specify an output:

      1. In the Simulink model, click the output signal of the Water-Tank System block to select it.

        The Click a signal in the model to select it area updates to display the selected signal.

      2. Click to add the signal to the Linearization inputs/outputs table.

      3. In the Configuration drop-down list of the Linearization inputs/outputs table, select Output for watertank/Water-Tank System : 1.

      4. Select the Open Loop option for watertank/Water-Tank System : 1.

      The Linearization inputs/outputs table now resembles the following figure.

    3. Click to collapse the Click a signal in the model to select it area.

      Tip   Alternatively, before you add the Linear Analysis Plots block, right-click the signals in the Simulink model and select Linearization Points > Input Points and Linearization Points > Output Points. Linearization I/O annotations appear in the model and the selected signals appear in the Linearization inputs/outputs table.

  6. Specify simulation snapshot times.

    1. In the Linearizations tab, verify that Simulation snapshots is selected in Linearize on.

    2. In the Snapshot times field, type [0 1 5].

  7. Specify a plot type to plot the gain and phase margins. The plot type is Bode by default.

    1. Select Nichols in Plot type

    2. Click Show Plot to open an empty Nichols plot.

  8. Save the linear system.

    1. Select the Logging tab.

    2. Select the Save data to workspace option and specify a variable name in the Variable name field.

      The Logging tab now resembles the following figure.

  9. Plot the gain and phase margins by clicking in the plot window.

    The software linearizes the portion of the model between the linearization input and output at the simulation times of 0, 1 and 5 and plots gain and phase margins.

    After the simulation completes, the plot window resembles the following figure.

      Tip   Click to view the legend.

The computed linear system is saved as sys in the MATLAB workspace. sys is a structure with time and values fields. To view the structure, type:

sys

This command returns the following results:

sys = 

         time: [3x1 double]
       values: [4-D ss]
    blockName: 'watertank/Gain and Phase Margin Plot'

 Examples and How To

Visualize Linear System Characteristics of a Continuous-Time Model Discretized During Simulation

This example shows how to discretize a continuous-time model during simulation and plot the model's discretized linear behavior.

  1. Open the Simulink model:

    scdcstr

    In this model, the Bode Plot block has already been configured with:

    • Input point at the coolant temperature input Coolant Temp

    • Output point at the residual concentration output CA

    • Settings to linearize the model on a rising edge of an external trigger. The trigger signal is modeled in the Linearization trigger signal block in the model.

    • Saving the computed linear system in the MATLAB workspace as LinearReactor.

    To view these configurations, double-click the block.

    To learn more about the block parameters, see the block reference pages.

  2. Specify the sample time to compute the discrete-time linear system.

    1. Click adjacent to Algorithm Options.

      The option expands to display the linearization algorithm options.

    2. Specify a sample time of 2 in the Linear system sample time field.

    To learn more about this option, see the block reference page.

  3. Click Show Plot to open an empty Bode plot window.

  4. Plot the Bode magnitude and phase by clicking in the plot window.

    During simulation, the software:

    • Linearizes the model on encountering a rising edge.

    • Converts the continuous-time model into a discrete-time linear model with a sample time of 2. This conversion uses the default Zero-Order Hold method to perform the sample time conversion.

      The software plots the discrete-time linear behavior in the Bode plot window. After the simulation completes, the plot window resembles the following figure.

    The plot shows the Bode magnitude and phase up to the Nyquist frequency, which is computed using the specified sample time. The vertical line on the plot represents the Nyquist frequency.

 Examples and How To

Visualize Linear System Characteristics at Trigger-Based Simulation Events

The Plotting Linear System Characteristics of a Chemical Reactor demo shows how to plot the Bode magnitude and phase of a reactor. The reactor transitions through different operating points corresponding to trigger-based simulation events.

 Examples and How To

  


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