Documentation

MATLAB Test Bench Requirements and Best Practices

MATLAB Test Bench Requirements

You can use any MATLAB® data type and function in your test bench.

A MATLAB test bench has the following requirements:

  • For floating-point to fixed-point conversion, the test bench must be a script or a function with no inputs.

  • The inputs and outputs in your MATLAB design interface must use the same data types, sizes, and complexity in each call site in your test bench.

  • If you enable the Accelerate test bench for faster simulation option in the Float-to-Fixed Workflow, the MATLAB constructs in your test bench loop must be compilable.

MATLAB Test Bench Best Practices

Use the following MATLAB test bench best practices:

  • Design your test bench to cover the full numeric range of data that the design must handle. HDL Coder™ uses the data that it accumulates from running the test bench to infer fixed-point data types during floating-point to fixed-point conversion.

    If you call the design function multiple times from your test bench, the coder uses the accumulated data from each instance to infer fixed-point types. Both the design and the test bench can call local functions within the file or other functions on the MATLAB path. The call to the design function can be at any level of your test bench hierarchy.

  • Before trying to generate code, run your test bench in MATLAB . If simulation is slow, accelerate your test bench. To learn how to accelerate your simulation, see Accelerate MATLAB Algorithms.

  • If you have a loop that calls your design function, use only compilable MATLAB constructs within the loop and enable the Accelerate test bench for faster simulation option.

  • Before each test bench simulation run, use the clear variables command to reset your persistent variables.

To see an example of a test bench, enter this command:

showdemo mlhdlc_tutorial_float2fixed_files

Was this topic helpful?