Support calculations involving sample time

Math Operations

The Weighted Sample Time Math block adds, subtracts, multiplies,
or divides its input signal, `u`

, by a weighted sample
time, `Ts`

. If the input signal is continuous, `Ts`

is
the sample time of the Simulink^{®} model. Otherwise, `Ts`

is
the sample time of the discrete input signal. If the input signal
is constant, Simulink assigns a finite sample time to the block
based on its connectivity and context.

You specify the math operation with the **Operation** parameter.
Additionally, you can specify to use only the weight with either the
sample time or its inverse.

Enter the weighting factor in the **Weight value** parameter.
If the weight, `w`

, is `1`

, that
value does not appear in the equation on the block icon.

The block computes its output using the precedence rules for MATLAB^{®} operators
(see Operator Precedence (MATLAB)).
For example, if the **Operation** parameter specifies `+`

,
the block calculates output using this equation:

u + (Ts * w)

However, if the **Operation** parameter specifies `/`

,
the block calculates output using this equation:

(u / Ts) / w

The Weighted Sample Time Math block accepts signals of the following data types:

Floating point

Built-in integer

Fixed point

Boolean

For more information, see Data Types Supported by Simulink in the Simulink documentation.

**Operation**Specify operation to use:

`+`

,`-`

,`*`

,`/`

,`Ts Only`

, or`1/Ts Only`

.**Weight value**Enter the weight of sample time.

**Implement using**Select one of two modes: online calculations or offline scaling adjustment. This parameter is visible only when you set

**Operation**to`*`

or`/`

.Result of (Ts * w) Output Data Type of Two Modes Block Execution A power of 2, or an integer value The same, when **Output data type**is`Inherit: Inherit via internal rule`

Equally efficient in both modes Not power of 2 and not an integer value Different More efficient for the offline scaling mode ### Note

When the

**Implement using**parameter is not visible, operations default to online calculations.

The **Saturate on integer overflow** parameter
is visible only if:

The

**Operation**parameter specifies`+`

or`-`

.The

**Operation**parameter specifies`*`

or`/`

and the**Implement using**parameter specifies`Online Calculations`

.

**Output data type**Specify whether the block inherits the output data type by an internal rule or back propagation.

### Tip

If you enter an expression in the edit field, the expression must evaluate to one of the two inherit rules.

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

**Saturate on integer overflow**-
Action Reasons for Taking This Action What Happens for Overflows Example Select this check box.

Your model has possible overflow, and you want explicit saturation protection in the generated code.

Overflows saturate to either the minimum or maximum value that the data type can represent.

The maximum value that the

`int8`

(signed, 8-bit integer) data type can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer. With the check box selected, the block output saturates at 127. Similarly, the block output saturates at a minimum output value of -128.Do not select this check box.

You want to optimize efficiency of your generated code.

You want to avoid overspecifying how a block handles out-of-range signals. For more information, see Check for Signal Range Errors.

Overflows wrap to the appropriate value that is representable by the data type.

The maximum value that the

`int8`

(signed, 8-bit integer) data type can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer. With the check box cleared, the software interprets the overflow-causing value as`int8`

, which can produce an unintended result. For example, a block result of 130 (binary 1000 0010) expressed as`int8`

, is -126.When you select this check box, saturation applies to every internal operation on the block, not just the output or result. Usually, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.

Data Types | Double | Single | Boolean | Base Integer | Fixed-Point |

Direct Feedthrough | For all math operations except |

Multidimensional Signals | No |

Variable-Size Signals | No |

Zero-Crossing Detection | No |

Code Generation | Yes |

Was this topic helpful?