Determine fixed-point data type
NumericTypeScope object provides information about the
dynamic range of your data. The scope provides a visual representation of the dynamic range of
your data in the form of a
NumericTypeScope window visualizes the dynamic range of a
fi object in a
log2 histogram. Bit weights appear
along the x-axis of the histogram and the percentage of occurrences
along the y-axis. Each bin of the histogram corresponds to a bit in the
binary word. For example, 20 corresponds to the first integer bit in the binary word, and 2-1 corresponds to the first fractional bit in the binary word.
NumericTypeScope identifies potential overflows and underflows
based on the current data type. The scope indicates values that may cause overflow or
underflow, or are in range of the data type by color-coding the histogram bars as
Blue — Histogram bin contains values that are in range of the current data type.
Red — Histogram bin contains values that may cause overflow.
Yellow — Histogram bin contains values that may cause underflow.
The table below the histogram breaks down each category of values by their signed value.
The Data Browser pane displays the current fixed-point data type as the Proposed Data Type. You can change the data type by entering a value directly in this box.
View the Dynamic Range of a
NumericTypeScope to view the dynamic range of a
fi object and set the
a = fi(magic(10),1,8,2); b = fi([a; 2.^(-5:4)],1,8,3); fp = fipref; initialDTOSetting = fp.DataTypeOverride; fp.DataTypeOverride = 'ScaledDoubles';
NumericTypeScope object. You can use the
reset method to ensure that all stored information is cleared from the
h = NumericTypeScope; reset(h)
step method to process your data and visualize the dynamic range of the
NumericTypeScope window does not delete the object from your workspace. Close the
NumericTypeScope window and reopen it using the
NumericTypeScope displays a
log2 histogram which shows that the values appear both outside of the range and below the precision of the data type of the variable. Pause on one bar of the histogram to view the percentage of the total values that are represented by that bar.
In this case, the data type of
numerictype(1,8,3) data type provides 5 integer bits, including the signed bit, and 3 fractional bits. Thus, this data type can represent only values between -2^4 and 2^4 - 2^-3 (from -16 to 15.8750). Given the range and precision of this data type, values greater than 2^4 fall outside the range and values less than 2^-3 fall below the precision of the data type.
NumericTypeScope shows that values requiring bits 5, 6, and 7 are outside the range and values requiring fractional bits 4 and 5 are below precision. Given this information, you can prevent values that are outside range and below precision by changing the data type of the variable
Given this information, you can prevent values that are outside range and below precision by changing the data type of the variable
numerictype(0,13,5). In the
numerictype(0,13,5) in the Proposed Data Type box.
Return to the original data type override setting.
fp.DataTypeOverride = initialDTOSetting;
Determine Numeric Type For
View the dynamic range and determine an appropriate numeric type for a
fi object with a
Scaled double: binary point scaling.
numerictype object with a
Scaled double: binary point scaling. Then, use that
numerictype object to construct your
T = numerictype; T.DataTypeMode = 'Scaled double: binary point scaling'; T.WordLength = 8; T.FractionLength = 6; a = fi(sin(0:100)*3.5, T); b = fi(cos(0:100)*1.75,T); acc = fi(0,T);
h. Then, use the
step function in a
for loop to view the dynamic range of the accumulator object,
h = NumericTypeScope; for i = 1:length(a) acc(:) = a(i)*0.7+b(i); step(h,acc) end
This dynamic range analysis shows that you can represent the entire range of data in the accumulator with 5 bits, two to the left of the binary point (integer bits) and three to the right of it (fractional bits). You can verify that this data type is able to represent all the values by changing the
FractionLength properties of the
T. Then, use
T to redefine the accumulator.
T.WordLength = 5; T.FractionLength = 2; acc = fi(0,T);
To view the dynamic range analysis based on this new data type, reset the
h, and rerun the loop.
reset(h) for i = 1:length(a) acc(:) = a(i)*0.7 + b(i); step(h,acc) end
Clear the information stored in the
Version HistoryIntroduced in R2010a
R2023a: Updated Programmatic Interface
R2022b: Updated Numeric Type Scope Interface
The NumericTypeScope has a new interface when you launch the scope from the
Instrumentation Report Viewer. For an example, see
functions will be updated in a future release to launch the updated interface.