Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Abs

Output absolute value of input

Library

Math Operations

Description

The Abs block outputs the absolute value of the input.

For signed-integer data types, the absolute value of the most negative value is not representable by the data type. In this case, the Saturate on integer overflow check box controls the behavior of the block:

If you...The block...And...
Select this check boxSaturates to the most positive value of the integer data type
  • For 8-bit signed integers, -128 maps to 127.

  • For 16-bit signed integers, -32768 maps to 32767.

  • For 32-bit signed integers, -2147483648 maps to 2147483647.

Do not select this check boxWraps to the most negative value of the integer data type
  • For 8-bit signed integers, -128 remains -128.

  • For 16-bit signed integers, -32768 remains -32768.

  • For 32-bit signed integers, -2147483648 remains -2147483648.

The Abs block supports zero-crossing detection. However, when you select Enable zero-crossing detection on the dialog box, the block does not report the simulation minimum or maximum in the Fixed-Point Tool. If you want to use the Fixed-Point Tool to analyze a model, disable zero-crossing detection for all Abs blocks in the model first.

Data Type Support

The Abs block accepts real signals of the following data types:

  • Floating point

  • Built-in integer

  • Fixed point

The block also accepts complex floating-point inputs. For more information, see Data Types Supported by Simulink in the Simulink® documentation.

Parameters and Dialog Box

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

Enable zero-crossing detection

Select to enable zero-crossing detection. For more information, see Zero-Crossing Detection.

Sample time (-1 for inherited)

Enter the time interval between sample time hits or specify another appropriate sample time such as continuous. By default, the block inherits its sample time based upon its context within the model. For more information, see Sample Time.

The Signal Attributes pane of the Abs 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 on integer overflow
ActionReason for Taking This ActionWhat HappensExample
Select this check box.Your model has possible overflow and you want explicit saturation protection in the generated code.Overflows saturate to the maximum value that the data type can represent.The number 130 does not fit in a signed 8-bit integer and saturates to 127.
Do not select this check box.You want to optimize efficiency of your generated code.Overflows wrap to the appropriate value that is representable by the data type.The number 130 does not fit in a signed 8-bit integer and wraps to -126.

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.

Examples

Usage as an Input to a MinMax Block

The sldemo_hardstopsldemo_hardstop model shows how you can use the Abs block as an input to the MinMax block.

In the sldemo_hardstop model, the Abs block is in the Friction Model subsystem.

Usage as an Input to a Switch Block

The sldemo_zeroxingsldemo_zeroxing model shows how you can use the Abs block as an input to the Switch block.

Characteristics

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Dimensionalized

Yes

Multidimensionalized

Yes

Zero-Crossing Detection

Yes, if enabled

Was this topic helpful?