This example shows how to use derived range analysis to generate minimum and maximum range data that then can be used by the Fixed-Point Tool to propose fixed-point scaling.
To run this example, you need Fixed-Point Designer™, Computer Vision System Toolbox™ and their required products.
The Fixed-Point Tool can collect minimum and maximum range data either by performing simulation and logging range information or by running derived range analysis. Range information obtained from simulation is completely dependent on the input to the simulation and accurate range information can be obtained only if the inputs exercise the system over its full operating range. Unlike simulation logging, derived range analysis does not depend on sample inputs and instead uses formal methods to generate range information.
The benefits of derived range analysis over simulation logging are:
Accurate results, regardless of quality of input data
Faster Analysis times
Open the model fxpdemo_corner_detection.
This model implements a corner detection algorithm based on the Harris corner detection method. The top level of the model includes blocks required to run the simulation. Note that input to the simulation is a checker board image and that output is 2 by n workspace matrix variable, "cornerMarks", that contains locations on all found corners. The "Corner Detector" subsystem implements the algorithm. Within the "Corner Detector" subsystem, the "Sobel Edge" block applies Sobel operator to the input data and the "Corner Metric" subsystem calculates the Harris corner metric. This example concentrates on analyzing ranges of the "Corner Metric" subsystem.
Note: Design Ranges on inputs to the "Corner Metric" subsystem have been explicitly specified by the user prior to running the analysis. Those design ranges can be obtained either from running derived range analysis or simulation logging on the whole system, or they can be inferred from the model.
An attempt was made to manually set fixed-point types on some of the blocks inside of the "Corner Metric" subsystem. However, some of the types were chosen poorly, and the model fails to detect corners correctly. Simulate the model by clicking the Run button. Observe that numerous overflows occur and that most of the corners are not marked.
To open the Fixed-Point Tool, right click on the "Corner Metric" subsystem and select the Fixed-Point Tool.
The Fixed-Point Tool derives ranges by analyzing the generated code. Complicated data types, such as fixed-point ones, generate a lot more code and make it much harder for the analysis to derive accurate ranges. To improve the accuracy of the results, set Data Type Override to double.
To start derived range analysis click the "Derive Min/Max Values for Selected Model" button. After Analysis finishes, the Fixed-Point Tool will display collected range information and fixed-point scaling will work exactly the same as when range information is obtained from the simulation logging.
Range information obtained from derived range analysis can be used by the Fixed-Point Tool to propose fixed-point data types for blocks in the model. This can be done by clicking "Propose" button in the Fixed-Point Tool menu.
To apply the proposed data types, click the "Apply Proposed Data Types" button. By default, the Fixed-Point Tool applies all of the proposed data types. To apply a subset of the proposals, use the Accept check box to specify the proposals that you want to apply.
Proposed types should handle all possible inputs correctly. Set the model to use proposed types, simulate the model again and observe that all of the corners are now detected.