FixPt Gateway In
Convert a Simulink data type to a Fixed-Point Blockset data type.
Description
The FixPt Gateway In block is a masked S-function that converts a built-in Simulink data type to a Fixed-Point Blockset data type.
The Treat input as parameter list controls how the input is processed. The possible values are Real World Value and Stored Integer. In terms of the general encoding scheme described in Scaling, Real World Value treats the input as V = SQ + B where S is the slope and B is the bias. V is used to produce Q = (V - B)/S, which is stored in the output. Stored Integer treats the input as a stored integer, Q. The value of Q is directly used to produce the output. In this mode, the input and output are identical except that the input is a raw integer lacking proper scaling information. In both modes, the output data type includes the scaling information needed to correctly interpret the signal as a real-world value.
For a detailed description of all other block parameters, refer to Block Parameters.
Parameters and Dialog Box
Treat input as - Treat the input as a real-world value or as an integer.
Output data type and scaling - Specify the output data type and scaling via the dialog box, or inherit the data type and scaling by back propagation.
Output data type - Any data type supported by the Fixed-Point Blockset.
Output scaling - Radix point-only or slope/bias scaling. These scaling modes are available only for generalized fixed-point data types.
Lock output scaling so autoscaling tool can't change it - If checked, Output scaling is locked. This feature is available only for generalized fixed-point output.
Round toward - Rounding mode for fixed-point output.
Saturate to max or min when overflows occur - If checked, fixed-point overflows saturate. Otherwise, they wrap.
Override data type(s) with doubles - If checked, Output data type is overridden with doubles.
Log minimums and maximums - If checked, minimum and maximum simulation values are logged to the workspace.
Example
This example uses the FixPt Gateway In block to help you understand the difference between a real-world value and a stored integer. Consider the two fixed-point models shown below.
In the top model, the FixPt Gateway In block treats the input as a real-world value, and maps that value to an 8-bit signed generalized fixed-point data type with a scaling of 2-2. If the value is output from the FixPt Gateway Out block as a real-world value, then the scaling and data type information is retained and the output value is 001111.00, or 15. If the value is output from the FixPt Gateway Out block as a stored integer, then the scaling and data type information is not retained and the stored integer is interpreted as 00111100, or 60.
In the bottom model, the The FixPt Gateway In block treats the input as a stored integer, and the data type and scaling information is not applied. If the value is output from the FixPt Gateway Out block as a real-world value, then the scaling and data type information is applied to the stored integer, and the output value is 000011.11, or 3.75. If the value is output from the FixPt Gateway Out block as a stored integer, then you get back the original input value of 15.
The model shown below illustrates how a summation operation applies to real-world values and stored integers, and how scaling information is dealt with in generated code.
Note that the summation operation produces the correct result when the FixPt Gateway Out block outputs a real-world value. This is because the specified scaling information is applied to the stored integer value. However, when the FixPt Gateway Out block outputs a stored integer value, then the summation operation produces an unexpected result due to the absence of scaling information.
If you generate code for the above model, then the code captures the appropriate scaling information. The code for the FixPt Sum block is shown below. The inputs to this block are tagged with the specified scaling information so that the necessary shifts are performed for the summation operation.
/* Fixed-Point Sum Block: <Root>/FixPt Sum
*
* y = u0 + u1
*
* Input0 Data Type: Fixed Point S16 2^-2
* Input1 Data Type: Fixed Point S16 2^-4
* Output0 Data Type: Fixed Point S16 2^-5
*
* Round Mode: Floor
* Saturation Mode: Wrap
*
*/
sum = ((in1) << 3);
sum += ((in2) << 1);
Characteristics
Input Port | Any built-in Simulink data type |
Output Port | Any data type supported by the blockset |
Direct Feedthrough | Yes |
Sample Time | Inherited |
Scalar Expansion | No |
States | 0 |
Vectorized | Yes |