# Discrete Derivative

Compute discrete-time derivative

Discrete

## Description

The Discrete Derivative block computes an optionally scaled discrete time derivative as follows

`$y\left({t}_{n}\right)=\frac{Ku\left({t}_{n}\right)}{{T}_{s}}-\frac{Ku\left({t}_{n-1}\right)}{{T}_{s}}$`

where

• $u\left({t}_{n}\right)$ and $y\left({t}_{n}\right)$ are the block's input and output at the current time step, respectively.

• $u\left({t}_{n-1}\right)$ is the block's input at the previous time step.

• $K$ is a scaling factor.

• ${T}_{s}$ is the simulation's discrete step size, which must be fixed.

 Note:   Do not use this block in subsystems with a non-periodic trigger (for example, non-periodic function-call subsystems). This configuration will produce inaccurate results.

## Data Type Support

The Discrete Derivative block supports all numeric Simulink® data types, including fixed-point data types.

## Parameters

Gain value

Scaling factor used to weight the block's input at the current time step.

Initial condition for previous weighted input K*u/Ts

Set the initial condition for the previous scaled 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.

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.

• 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.

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.

• 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.

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.

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

 Data Types Double | Single | Base Integer | Fixed-Point Direct Feedthrough Yes Multidimensional Signals No Variable-Size Signals Yes Code Generation Yes