Documentation Center

  • Trials
  • Product Updates

Difference

Calculate change in signal over one time step

Library

Discrete

Description

The Difference block outputs the current input value minus the previous input value.

Data Type Support

The Difference block accepts signals of any numeric data type that Simulink® supports, including fixed-point data types. For more information, see Data Types Supported by Simulink in the Simulink documentation.

Parameters and Dialog Box

The Main pane of the Difference block dialog box appears as follows:

Initial condition for previous input

Set the initial condition for the previous input.

Input processing

Specify whether the block performs sample- or frame-based processing. You can select one of the following options:

  • Elements as channels (sample based) — Treat each element of the input as a separate channel (sample-based processing).

  • Columns as channels (frame based) — Treat each column of the input as a separate channel (frame-based processing).

      Note:   Frame-based processing requires a DSP System Toolbox™ license.

      For more information, see Sample- and Frame-Based Concepts in the DSP System Toolbox documentation.

  • Inherited — Inherit the processing mode from the input signal and delay the input accordingly. You can identify whether the input signal is sample or frame based by looking at the signal line. Simulink represents sample-based signals with a single line and frame-based signals with a double line.

      Note:   When you choose the Inherited option for the Input processing parameter, and the input signal is frame-based, Simulink will generate a warning or error in future releases.

Use Input processing to specify whether the block performs sample- or frame-based processing. The block accepts frame-based signals for the input u. All other input signals must be sample based.

Input Signal uInput Processing ModeBlock Works?
Sample basedSample basedYes
Frame basedNo, produces an error
Sample basedFrame basedYes
Frame basedYes
Sample basedInheritedYes
Frame basedYes

For more information about these two processing modes, see Sample- and Frame-Based Concepts in the DSP System Toolbox documentation.

The Signal Attributes pane of the Difference block dialog box appears as follows:

Output minimum

Specify the minimum value that the block should output. The default value is [] (unspecified). Simulink software uses this value to perform:

  • Simulation range checking (see Signal Ranges)

  • Automatic scaling of fixed-point data types

Output maximum

Specify the maximum value that the block should output. The default value is[] (unspecified). Simulink software uses this value to perform:

  • Simulation range checking (see Signal Ranges)

  • Automatic scaling of fixed-point data types

Output data type

Specify the output data type. You can set it to:

  • A rule that inherits a data type, for example, Inherit: Inherit via back propagation

  • The name of a built-in data type, for example, single

  • The name of a data type object, for example, a Simulink.NumericType object

  • An expression that evaluates to a data type, for example, fixdt(1,16,0)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Output data type parameter.

See Specify Block Output Data Types for more information.

Lock output data type setting against changes by the fixed-point tools

Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor. For more information, see Use Lock Output Data Type Setting.

Integer rounding mode

Specify the rounding mode for fixed-point operations. For more information, see Rounding. in the Fixed-Point Designer™ documentation.

Saturate to max or min when overflows occur

Select to have overflows saturate to the maximum or minimum value that the data type can represent. Otherwise, overflows wrap.

When you select this check box, saturation applies to every internal operation on the block, not just the output or result. In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.

Characteristics

Direct Feedthrough

Yes

Scalar Expansion

Yes, of inputs and gain

Was this topic helpful?