Calculate change in signal over one time step
Simulink / Discrete
The Difference block outputs the current input value minus the previous input value.
Port_1
— Input signalInput signal, specified as a scalar, vector, matrix, or N-D array.
When you set Input processing to
Columns as channels (frame based)
,
the input signal must have two dimensions or less.
Data Types: half
| single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Port_1
— Current input minus previous inputCurrent input minus previous input, specified as a scalar, vector, matrix, or N-D array.
Data Types: half
| single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Initial condition for previous input
— Initial condition0.0
(default) | scalar | vector | matrix | N-D arraySet the initial condition for the previous input.
Parameter:
ICPrevInput
|
Type: character vector |
Values: scalar | vector | matrix | N-D array |
Default:
'0.0'
|
Input processing
— Specify sample- or frame-based processingElements as channels (sample based)
(default) | Columns as channels (frame based)
Specify whether the block performs sample- or frame-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 (DSP System Toolbox).
Elements as channels (sample based)
— Treat
each element of the input as a separate channel (sample-based
processing).
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 u | Input Processing Mode | Block Works? |
---|---|---|
Sample based | Sample based | Yes |
Frame based | No, produces an error | |
Sample based | Frame based | Yes |
Frame based | Yes |
For more information about these two processing modes, see Sample- and Frame-Based Concepts (DSP System Toolbox).
Block Parameter:
InputProcessing |
Type: character vector |
Values: 'Columns as channels
(frame based)' | 'Elements as channels (sample
based)' |
Default: 'Elements as channels
(sample based)' |
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
— Output data typeInherit: Inherit via internal
rule
(default) | Inherit via back propagation
| double
| single
| int8
| uint8
| int16
| uint16
| int32
| uint32
| int64
| uint64
| fixdt(1,16)
| fixdt(1,16,0)
| fixdt(1,16,2^0,0)
| <data type expression>
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 data type attributes. For more information, see Specify Data Types Using Data Type Assistant.
Parameter:
OutDataTypeStr
|
Type: character vector |
Values:
'Inherit: Inherit via internal rule' | 'Inherit:
Inherit via back propagation' | 'double' | 'single' | 'int8'
| 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' |
'int64' | 'uint64' | 'boolean' | 'fixdt(1,16)' |
'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | '<data type
expression>' |
Default:
'Inherit: Inherit via internal rule'
|
Lock output data type setting against changes by the fixed-point tools
— Prevent fixed-point tools from overriding Output data typeoff
(default) | on
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).
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
| Zero
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.
Block Parameter:
RndMeth |
Type: character vector |
Values:
'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' |
'Zero' |
Default:
'Floor' |
Saturate to max or min when overflows occur
— Method of overflow actionoff
(default) | on
When you select this check box, 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.
Block Parameter:
DoSatur |
Type: character vector |
Values:
'off' | 'on' |
Default:
'off' |
The code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit option.