Signal Ranges

About Signal Ranges

Many Simulink® blocks allow you to specify a range of valid values for their output signals. Simulink provides a diagnostic that you can enable to detect when blocks generate signals that exceed their specified ranges during simulation. See the sections that follow for more information.

Specifying Ranges for Signals

In general, use the Output minimum and Output maximum parameters that appear on a block parameter dialog box to specify a range of valid values for the block output signal. Exceptions include the Data Store Memory, Inport, Outport, and Signal Specification blocks, for which you use their Minimum and Maximum parameters to specify a signal range. See Blocks That Allow Signal Range Specification for a list of applicable blocks.

When specifying minimum and maximum values that constitute a range, enter only expressions that evaluate to a scalar, real number with double data type. The default values for the minimum and maximum are [] (unspecified). The scalar values that you specify are subject to expansion, for example, when the block inputs are nonscalar or bus signals (see Scalar Expansion of Inputs and Parameters).

    Note:   You cannot specify the minimum or maximum value as NaN, inf, or -inf.

Specifying Ranges for Complex Numbers

When you specify an Output minimum and/or Output maximum for a signal that is a complex number, the specified minimum and maximum values apply separately to the real part and to the imaginary part of the complex number. If the value of either part of the number is less than the minimum, or greater than the maximum, the complex number is outside the specified range. No range checking occurs against any combination of the real and imaginary parts, such as (sqrt(a^2+b^2))

Checking for Signal Range Errors

Simulink provides a diagnostic named Simulation range checking, which you can enable to detect when signals exceed their specified ranges during simulation. When enabled, Simulink compares the signal values that a block outputs with both the specified range (see Specifying Ranges for Signals) and the block data type. That is, Simulink performs the following check:

DataTypeMin ≤ MinValue ≤ VALUE ≤ MaxValue ≤ DataTypeMax

where

  • DataTypeMin is the minimum value representable by the block data type.

  • MinValue is the minimum value the block should output, specified by, e.g., Output minimum.

  • VALUE is the signal value that the block outputs.

  • MaxValue is the maximum value the block should output, specified by, e.g., Output maximum.

  • DataTypeMax is the maximum value representable by the block data type.

    Note:   It is possible to overspecify how a block handles signals that exceed particular ranges. For example, you can specify values (other than the default values) for both signal range parameters and enable the Saturate on integer overflow parameter. In this case, Simulink displays a warning message that advises you to disable the Saturate on integer overflow parameter.

Enabling Simulation Range Checking

To enable the Simulation range checking diagnostic:

  1. In your model window, select Simulation > Model Configuration Parameters.

    Simulink displays the Configuration Parameters dialog box.

  2. In the Select tree on the left side of the Configuration Parameters dialog box, click the Diagnostics > Data Validity category. On the right side under Signals, set the Simulation range checking diagnostic to error or warning.

  3. Click OK to apply your changes and close the Configuration Parameters dialog box.

See Simulation range checking for more information.

Simulating Models with Simulation Range Checking

To check for signal range errors or warnings:

  1. Enable the Simulation range checking diagnostic for your model (see Enabling Simulation Range Checking).

  2. In your model window, select Simulation > Run to simulate the model.

    Simulink simulates your model and performs signal range checking. If a signal exceeds its specified range when the Simulation range checking diagnostic specifies error, Simulink stops the simulation and displays an error message:

    Otherwise, if a signal exceeds its specified range when the Simulation range checking diagnostic specifies warning, Simulink displays a warning message in the MATLAB® Command Window:

    Warning: Inconsistent numeric values for port 1 
    of 'example/Gain': Output value (21) at major
    time step 4.2 is greater than maximum (20) from
    'example/Gain'.

    Each message identifies the block whose output signal exceeds its specified range, and the time step at which this violation occurs.

Signal Range Propagation for Virtual Blocks

Some virtual blocks (see Virtual Blocks) allow you to specify ranges for their output signals, for example, the Inport and Outport blocks. When the Simulation range checking diagnostic is enabled for a model that contains such blocks, the signal range of the virtual block propagates backward to the first instance of a nonvirtual block whose output signal it receives. If the nonvirtual block specifies different values for its own range, Simulink performs signal range checking with the tightest range possible. That is, Simulink checks the signal using the larger minimum value and the smaller maximum value.

For example, consider the following model:

In this model, the Constant block specifies its Output maximum parameter as 300, and that of the Inport block is set to 100. Suppose you enable the Simulation range checking diagnostic and simulate the model. The Inport block back propagates its maximum value to the nonvirtual block that precedes it, i.e., the Constant block. Simulink then uses the smaller of the two maximum values to check the signal that the Constant block outputs. Because the Constant block outputs a signal whose value (200) exceeds the tightest range, Simulink displays the following error message:

Was this topic helpful?