Multiply input by constant
Math Operations
The Gain block multiplies the input by a constant value (gain). The input and the gain can each be a scalar, vector, or matrix.
You specify the value of the gain in the Gain parameter. The Multiplication parameter lets you specify element-wise or matrix multiplication. For matrix multiplication, this parameter also lets you indicate the order of the multiplicands.
The gain is converted from doubles to the data specified in the block mask offline using round-to-nearest and saturation. The input and gain are then multiplied, and the result is converted to the output data type using the specified rounding and overflow modes.
The Gain block accepts a real or complex scalar, vector, or matrix of any numeric data type that Simulink^{®} supports. The Gain block supports fixed-point data types. If the input of the Gain block is real and the gain is complex, the output is complex.
For more information, see Data Types Supported by Simulink in the Simulink documentation.
The Main pane of the Gain block dialog box appears as follows:
The Signal Attributes pane of the Gain block dialog box appears as follows:
The Parameter Attributes pane of the Gain block dialog box appears as follows:
Specify the value by which to multiply the input.
Default: 1 |
Minimum: value of Parameter minimum parameter |
Maximum: value of Parameter maximum parameter |
The gain can be a scalar, vector, or matrix.
See Block-Specific Parameters for the command-line information.
Specify the multiplication mode.
Default: Element-wise(K.*u)
Element-wise(K.*u)
Each element of the input is multiplied by each element of the gain. The block performs expansions, if necessary, so that the input and gain have the same dimensions.
Matrix(K*u)
The input and gain are matrix multiplied with the input as the second operand.
Matrix(u*K)
The input and gain are matrix multiplied with the input as the first operand.
Matrix(K*u)(u vector)
The input and gain are matrix multiplied with the input as the
second operand. This mode is identical to Matrix(K*u)
,
except for how dimensions are determined.
Suppose that K
is an m-by-n
matrix. Matrix(K*u)(u
vector)
sets the input to a vector of length n
and
the output to a vector of length m
. In contrast, Matrix(K*u)
uses
propagation to determine dimensions for the input and output. For
an m-by-n
gain matrix, the input can propagate
to an n-by-q
matrix, and the output becomes an m-by-q
matrix.
See Block-Specific Parameters for the command-line information.
Note:
This parameter is not visible in the block dialog box unless
it is explicitly set to a value other than |
Lower value of the output range that Simulink checks.
Default: []
(unspecified)
Specify this number as a finite, real, double, scalar value.
Note:
If you specify a bus object as the data type for this block,
do not set the minimum value for bus data on the block. Simulink ignores
this setting. Instead, set the minimum values for bus elements of
the bus object specified as the data type. For information on the
Minimum parameter for a bus element, see |
Simulink uses the minimum to perform:
Parameter range checking (see Check Parameter Values) for some blocks
Simulation range checking (see Signal Ranges and Enabling Simulation Range Checking)
Automatic scaling of fixed-point data types
Note: Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead. |
Parameter: OutMin |
Type: string |
Value: '[ ]' |
Default: '[ ]' |
Upper value of the output range that Simulink checks.
Default: []
(unspecified)
Specify this number as a finite, real, double, scalar value.
Note:
If you specify a bus object as the data type for this block,
do not set the maximum value for bus data on the block. Simulink ignores
this setting. Instead, set the maximum values for bus elements of
the bus object specified as the data type. For information on the
Maximum parameter for a bus element, see |
Simulink uses the maximum value to perform:
Parameter range checking (see Check Parameter Values) for some blocks
Simulation range checking (see Signal Ranges and Enabling Simulation Range Checking)
Automatic scaling of fixed-point data types
Note: Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead. |
Parameter: OutMax |
Type: string |
Value: '[ ]' |
Default: '[ ]' |
Specify the output data type.
Default: Inherit:
Inherit via internal rule
Inherit: Inherit via internal rule
Simulink chooses a data type to balance numerical accuracy,
performance, and generated code size, while taking into account the
properties of the embedded target hardware. If you change the embedded
target settings, the data type selected by the internal rule might
change. For example, if the block multiplies an input of type int8
by
a gain of int16
and ASIC/FPGA
is
specified as the targeted hardware type, the output data type is sfix24
.
If Unspecified (assume 32-bit Generic)
,
i.e., a generic 32-bit microprocessor, is specified as the target
hardware, the output data type is int32
. If none
of the word lengths provided by the target microprocessor can accommodate
the output range, Simulink software displays an error in the
Diagnostic Viewer.
It is not always possible for the software to optimize code efficiency and numerical accuracy at the same time. If the internal rule doesn't meet your specific needs for numerical accuracy or performance, use one of the following options:
Specify the output data type explicitly.
Use the simple choice of Inherit: Same
as input
.
Explicitly specify a default data type such as fixdt(1,32,16)
and
then use the Fixed-Point Tool to propose data types for your model.
For more information, see fxptdlg
.
To specify your own inheritance rule, use Inherit:
Inherit via back propagation
and then use a Data Type Propagation block. Examples
of how to use this block are available in the Signal Attributes library Data
Type Propagation Examples block.
Inherit: Inherit via back propagation
Use data type of the driving block.
Inherit: Same as input
Use data type of input signal.
double
Output data type is double
.
single
Output data type is single
.
int8
Output data type is int8
.
uint8
Output data type is uint8
.
int16
Output data type is int16
.
uint16
Output data type is uint16
.
int32
Output data type is int32
.
uint32
Output data type is uint32
.
fixdt(1,16,0)
Output data type is fixed point fixdt(1,16,0)
.
fixdt(1,16,2^0,0)
Output data type is fixed point fixdt(1,16,2^0,0)
.
<data type expression>
Use a data type object, for example, Simulink.NumericType
.
See Block-Specific Parameters for the command-line information.
See Specify Block Output Data Types for more information.
Select the category of data to specify.
Default: Inherit
Inherit
Inheritance rules for data types. Selecting Inherit
enables
a second menu/text box to the right. Select one of the following choices:
Inherit via internal rule
(default)
Inherit via back propagation
Same as input
Built in
Built-in data types. Selecting Built in
enables
a second menu/text box to the right. Select one of the following choices:
double
(default)
single
int8
uint8
int16
uint16
int32
uint32
Fixed point
Fixed-point data types.
Expression
Expressions that evaluate to data types. Selecting Expression
enables
a second menu/text box to the right, where you can enter the expression.
Clicking the Show data type assistant button enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specify Data Types Using Data Type Assistant.
Specify data type override mode for this signal.
Default: Inherit
Inherit
Inherits the data type override setting from its context, that
is, from the block, Simulink.Signal
object or Stateflow^{®} chart
in Simulink that is using the signal.
Off
Ignores the data type override setting of its context and uses the fixed-point data type specified for the signal.
The ability to turn off data type override for an individual data type provides greater control over the data types in your model when you apply data type override. For example, you can use this option to ensure that data types meet the requirements of downstream blocks regardless of the data type override setting.
This parameter appears only when the Mode is Built
in
or Fixed point
.
Specify whether you want the fixed-point data as signed or unsigned.
Default: Signed
Signed
Specify the fixed-point data as signed.
Unsigned
Specify the fixed-point data as unsigned.
Selecting Mode > Fixed
point
enables this parameter.
For more information, see Specifying a Fixed-Point Data Type.
Specify the bit size of the word that holds the quantized integer.
Default: 16
Minimum: 0
Maximum: 32
Selecting Mode > Fixed
point
enables this parameter.
For more information, see Specifying a Fixed-Point Data Type.
Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.
Default: Binary
point
Binary point
Specify binary point location.
Slope and bias
Enter slope and bias.
Selecting Mode > Fixed
point
enables this parameter.
Selecting Binary point
enables:
Fraction length
Calculate Best-Precision Scaling
Selecting Slope and bias
enables:
Slope
Bias
Calculate Best-Precision Scaling
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type.
Specify fraction length for fixed-point data type.
Default: 0
Binary points can be positive or negative integers.
Selecting Scaling > Binary
point
enables this parameter.
For more information, see Specifying a Fixed-Point Data Type.
Specify slope for the fixed-point data type.
Default: 2^0
Specify any positive real number.
Selecting Scaling > Slope
and bias
enables this parameter.
For more information, see Specifying a Fixed-Point Data Type.
Specify bias for the fixed-point data type.
Default: 0
Specify any real number.
Selecting Scaling > Slope
and bias
enables this parameter.
For more information, see Specifying a Fixed-Point Data Type.
Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor.
Default: Off
Locks the output data type setting for this block.
Allows the Fixed-Point Tool and the Fixed-Point Advisor to change the output data type setting for this block.
Parameter: LockScale |
Type: string |
Value: 'off' | 'on' |
Default: 'off' |
For more information, see Use Lock Output Data Type Setting.
Specify the rounding mode for fixed-point operations.
Default: Floor
Ceiling
Rounds both positive and negative numbers toward positive infinity.
Equivalent to the MATLAB^{®} ceil
function.
Convergent
Rounds number to the nearest representable value. If a tie occurs,
rounds to the nearest even integer. Equivalent to the Fixed-Point Designer™ convergent
function.
Floor
Rounds both positive and negative numbers toward negative infinity.
Equivalent to the MATLAB floor
function.
Nearest
Rounds number to the nearest representable value. If a tie occurs,
rounds toward positive infinity. Equivalent to the Fixed-Point Designer nearest
function.
Round
Rounds number to the nearest representable value. If a tie occurs,
rounds positive numbers toward positive infinity and rounds negative
numbers toward negative infinity. Equivalent to the Fixed-Point Designer round
function.
Simplest
Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.
Zero
Rounds number toward zero. Equivalent to the MATLAB fix
function.
Parameter: RndMeth |
Type: string |
Value: 'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero' |
Default: 'Floor' |
For more information, see Rounding in the Fixed-Point Designer documentation.
Specify whether overflows saturate.
Default: Off
Overflows saturate to either the minimum or maximum value that the data type can represent.
For example, an overflow associated with a signed 8-bit integer can saturate to -128 or 127.
Overflows wrap to the appropriate value that is representable by the data type.
For example, the number 130 does not fit in a signed 8-bit integer and wraps to -126.
Consider selecting this check box when your model has possible overflow and you want explicit saturation protection in the generated code.
Consider clearing this check box when you want to optimize efficiency of your generated code.
Clearing this check box also helps you avoid overspecifying how a block handles out-of-range signals. For more information, see Checking for Signal Range Errors.
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.
Parameter: SaturateOnIntegerOverflow |
Type: string |
Value: 'off' | 'on' |
Default: 'off' |
Specify the minimum value of the gain.
Default: [] |
The default value is []
(unspecified). Simulink software
uses this value to perform:
Parameter range checking (see Check Parameter Values)
Automatic scaling of fixed-point data types
See Block-Specific Parameters for the command-line information.
Specify the maximum value of the gain.
Default: [] |
The default value is []
(unspecified). Simulink software
uses this value to perform:
Parameter range checking (see Check Parameter Values)
Automatic scaling of fixed-point data types
See Block-Specific Parameters for the command-line information.
Specify the data type of the Gain parameter.
Default: Inherit:
Inherit via internal rule
Inherit: Inherit via internal rule
Use an internal rule to inherit the data type.
Inherit: Same as input
Use data type of sole input signal.
Inherit: Inherit from 'Gain'
Use data type of the Gain value. For example:
If you set Gain to... | The parameter data type inherits... |
---|---|
2 | double |
single(2) | single |
int8(2) | int8 |
double
Data type is double
.
single
Data type is single
.
int8
Data type is int8
.
uint8
Data type is uint8
.
int16
Data type is int16
.
uint16
Data type is uint16
.
int32
Data type is int32
.
uint32
Data type is uint32
.
fixdt(1,16)
Data type is fixdt(1,16)
.
fixdt(1,16,0)
Data type is fixdt(1,16,0)
.
fixdt(1,16,2^0,0)
Data type is fixdt(1,16,2^0,0)
.
<data type expression>
Use a data type object, for example, Simulink.NumericType
.
See Block-Specific Parameters for the command-line information.
Select the category of data to specify.
Default: Inherit
Inherit
Inheritance rules for data types. Selecting Inherit
enables
a second menu/text box to the right. Select one of the following choices:
Inherit via internal rule
(default)
Same as input
Inherit from 'Gain'
Built in
Built-in data types. Selecting Built in
enables
a second menu/text box to the right. Select one of the following choices:
double
(default)
single
int8
uint8
int16
uint16
int32
uint32
Fixed point
Fixed-point data types.
Expression
Expressions that evaluate to data types. Selecting Expression
enables
a second menu/text box to the right, where you can enter the expression.
Clicking the Show data type assistant button enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specify Data Types Using Data Type Assistant in the Simulink documentation.
Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.
Default: Best
precision
Binary point
Specify binary point location.
Slope and bias
Enter slope and bias.
Best precision
Specify best-precision values.
Selecting Mode > Fixed
point
enables this parameter.
Selecting Binary point
enables:
Fraction length
Calculate Best-Precision Scaling
Selecting Slope and bias
enables:
Slope
Bias
Calculate Best-Precision Scaling
For more information, see Specifying a Fixed-Point Data Type.
The following Simulink examples show how to use the Gain block:
Direct Feedthrough | Yes |
Sample Time | Inherited from driving block |
Scalar Expansion | Yes, of input and Gain parameter
for |
Dimensionalized | Yes |
Multidimensionalized | Yes, only if the Multiplication parameter
specifies |
Zero-Crossing Detection | No |