Main Content

Abs

Output absolute value of input

  • Abs block

Libraries:
Simulink / Math Operations
HDL Coder / HDL Floating Point Operations
HDL Coder / 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.

Ports

Input

expand all

Input signal to the absolute value block.

Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Output

expand all

Absolute value of the input signal.

Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Parameters

expand all

Main

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

Programmatic Use

Block Parameter: ZeroCross
Type: character vector | string
Values: 'off' | 'on'
Default: 'on'

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. For more information, see Specify Sample Time.

Dependencies

This parameter is visible only if you set it to a value other than -1. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Programmatic Use

Block Parameter: SampleTime
Type: string scalar or character vector
Default: "-1"

Signal Attributes

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Lower value of the output range that Simulink® checks.

Simulink uses the minimum to perform:

Note

Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead.

Programmatic Use

Block Parameter: OutMin
Type: character vector
Values: '[ ]'| scalar
Default: '[ ]'

Upper value of the output range that Simulink checks.

Simulink uses the maximum value to perform:

Note

Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead.

Programmatic Use

Block Parameter: OutMax
Type: character vector
Values: '[ ]'| scalar
Default: '[ ]'

Choose the data type for the output. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

Dependencies

When input is a floating-point data type smaller than single precision, the Inherit: Inherit via internal rule output data type depends on the setting of the Inherit floating-point output type smaller than single precision configuration parameter. Data types are smaller than single precision when the number of bits needed to encode the data type is less than the 32 bits needed to encode the single-precision data type. For example, half and int16 are smaller than single precision.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: Same as input' | 'Inherit: Inherit via internal rule'| 'Inherit: Inherit via back propagation' | 'single' | 'half' | 'int8' | 'uint8' | int16 | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | fixdt(1,16,0) | fixdt(1,16,2^0,0) | fixdt(1,16,2^0,0) | '<data type expression>'
Default: 'Inherit: Same as input'

Select this parameter to prevent the fixed-point tools from overriding the Output data type you specify on the block. For more information, see Use Lock Output Data Type Setting (Fixed-Point Designer).

Programmatic Use

Block Parameter: LockScale
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Specify the rounding mode for fixed-point operations. For more information, see Rounding (Fixed-Point Designer).

Block parameters always round to the nearest representable value. To control the rounding of a block parameter, enter an expression using a MATLAB® rounding function into the mask field.

Programmatic Use

Block Parameter: RndMeth
Type: character vector
Values: 'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero'
Default: 'Floor'

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.

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.

Programmatic Use

Block Parameter: SaturateOnIntegerOverflow
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Block Characteristics

Data Types

double | fixed point | half | integer | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

yes

Zero-Crossing Detection

yes

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced before R2006a

See Also

|