Output absolute value of input
Simulink / Math Operations
HDL Coder / HDL Floating Point Operations
HDL Coder / Math Operations
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 box | Saturates to the most positive value of the integer data type |
|
| Do not select this check box | Wraps to the most negative value of the integer data type |
|
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.
Port_1 — Input signalInput signal to the absolute value block.
Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Port_1 — Absolute value output signalAbsolute value of the input signal.
Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Enable zero-crossing detection — Enable zero-crossing detectionon (default) | BooleanSelect to enable zero-crossing detection. For more information, see Zero-Crossing Detection.
Block Parameter:
ZeroCross |
| Type: character vector, string |
Values: 'off' |
'on' |
Default: 'on' |
Sample time — Specify sample time as a value other than -1-1 (default) | scalar | vectorSpecify the sample time as a value other than -1. For more information, see Specify Sample Time.
This parameter is not visible unless it is explicitly set to a value other than
-1. To learn more, see Blocks for Which Sample Time Is Not Recommended.
Block Parameter:
SampleTime |
| Type: character vector |
| Values: scalar or vector |
Default:
'-1' |
Click the Show data type assistant
button
to display the Data Type Assistant,
which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.
Output minimum — Minimum output value for range checking[] (default) | scalarLower value of the output range that Simulink® checks.
Simulink uses the minimum to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters) for some blocks.
Simulation range checking (see Specify Signal Ranges and Enable Simulation Range Checking).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Note
Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead.
Block Parameter:
OutMin |
| Type: character vector |
Values: '[ ]'|
scalar |
Default: '[ ]' |
Output maximum — Maximum output value for range checking[] (default) | scalarUpper value of the output range that Simulink checks.
Simulink uses the maximum value to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters) for some blocks.
Simulation range checking (see Specify Signal Ranges and Enable Simulation Range Checking).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Note
Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead.
Block Parameter:
OutMax |
| Type: character vector |
Values: '[ ]'|
scalar |
Default: '[ ]' |
Output data type — Specify the output data typeInherit: Same as
input (default) | Inherit: Inherit via internal
ruleInherit: Inherit via back
propagation | | double | single | half | int8 | int32 | uint32 | int64 | uint64 | fixdt(1,16,2^0,0) | <data type expression> | ...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.
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.
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' |
Lock output data type setting against changes by the fixed-point tools — Prevent fixed-point tools from overriding Output data typeoff (default) | onSelect 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).
Block Parameter:
LockScale |
| Type: character vector |
Values:
'off' | 'on' |
Default:
'off' |
Integer rounding mode — Rounding mode for fixed-point operationsFloor (default) | Ceiling | Convergent | Nearest | Round | Simplest | ZeroSpecify 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.
Block Parameter:
RndMeth |
| Type: character vector |
Values:
'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' |
'Zero' |
Default:
'Floor' |
Saturate on integer overflow — Choose the behavior when integer overflow occursoff (default) | onWhen 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.
| Action | Reason for Taking This Action | What Happens | Example |
|---|---|---|---|
| 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. |
Block Parameter:
SaturateOnIntegerOverflow |
| Type: character vector |
Value:
'off' | 'on' |
Default:
'off' |
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
This block has a single, default HDL architecture.
| General | |
|---|---|
| ConstrainedOutputPipeline | Number of registers to place at
the outputs by moving existing delays within your design. Distributed
pipelining does not redistribute these registers. The default is
|
| InputPipeline | Number of input pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
| OutputPipeline | Number of output pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
| Native Floating Point | |
|---|---|
| LatencyStrategy | Specify whether to map the blocks in your design to
|
This block supports code generation for complex signals with floating-point
types in Native Floating Point mode.
Code generation for the block with complex signals that use fixed-point types is not supported. To calculate the magnitude of a complex number, use the Complex to Magnitude-Angle HDL Optimized (DSP System Toolbox) block instead.

