Weighted Sample Time Math

Support calculations involving sample time

  • Library:
  • Simulink / Math Operations

Description

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. The block can output just a weighted sample time (Ts Only) or a weighted sample rate (1/Ts Only).

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.

Tip

You can use the Weighted Sample Time and Weighted Sample Time Math blocks to extract the sample time from a Simulink signal. To do so, set the Operation parameter to Ts and the Weight value to 1.0. In this configuration, the block outputs the sample time of the input signal.

The block computes its output using the precedence rules for MATLAB® operators. See Operator Precedence (MATLAB) for information. 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

Ports

Input

expand all

Specify the input signal, u, as a scalar, vector, or matrix. Depending on the value of the Operation parameter, the block can add, subtract, multiply, or divide the input signal by weighted sample time or just output the weighted sample time or weighted sample rate.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean | fixed point

Output

expand all

Output the weighted sample time or sample rate of the input signal, or output the input signal adjusted by the 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. When the input signal is constant, Simulink assigns a finite sample time to the block based on its connectivity and context.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean | fixed point

Parameters

expand all

Main

Specify the operation to use for adjusting the input signal. You can select: +, -, *, /, Ts Only, or 1/Ts Only.

Programmatic Use

Block Parameter: TsamMathOp
Type: character vector
Values: '+' | '-' | '*' | '/' | 'Ts Only' | '1/Ts Only'
Default: '+'

Enter the weight of the sample time as a real-valued scalar.

Programmatic Use

Block Parameter: weightValue
Type: character vector
Values: real-valued scalar
Default: '1.0'

Select one of two modes: online calculations or offline scaling adjustment.

Result of (Ts * w)Output Data Type of Two ModesBlock 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 valueDifferentMore efficient for the offline scaling mode

Note

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

Dependencies

To enable this parameter, set Operation to * or /.

Programmatic Use

Block Parameter: TsampMathImp
Type: character vector
Values: 'Online Calculations' | 'Offline Scaling Adjustment'
Default: 'Online Calculations'

Signal Attributes

Specify the data type for the output.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule | 'Inherit: Inherit via back propagation' | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

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.

Dependencies

To enable this parameter, set Operation to +, -, *, or /. If you set the Operation parameter to * or /, you must also set Implement using to Online Calculations.

Programmatic Use

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

Specify whether overflows saturate or wrap.

ActionRationaleImpact on OverflowsExample

Select this check box (on).

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 (off).

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.

Dependencies

To enable this parameter, set Operation to +, -, *, or /. If you set the Operation parameter to * or /, you must also set Implement using to Online Calculations.

Programmatic Use

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

Block Characteristics

Data Types

Boolean | double | fixed point | integer | single

Direct Feedthrough

yes

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

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

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

Introduced before R2006a