This example shows how to detect fixed-point constant precision loss.
To open the model, at the MATLAB® command line, enter:
cd(fullfile(docroot,'toolbox','fixpoint','examples')) ex_fixed_point_constant_precision_loss
For the Data Type Conversion block in this model:
Input slope, SU = 1
Output slope, SY = 1.000001
Net slope, SU/SY = 1/1.000001
To set up the model and run the simulation:
For the Inport block, set the Data
type to int16
.
For the Data Type Conversion block, set the
Output data type to
fixdt(1,16,1.000001,0)
.
In the Configuration Parameters dialog box, set the Diagnostics > Type Conversion > Detect precision loss configuration parameter to
error
.
In your Simulink® model window, in the Simulation tab, click Run.
When you simulate the model, a net slope quantization error occurs.
The Fixed-Point Designer™ software generates an error informing you that net scaling quantization caused precision loss. The message provides the following information:
The block that introduced the error.
The original value of the net slope.
The quantized value of the net slope.
The error in the value of the net slope.