Converting a Parametric Audio Equalizer to Fixed Point

This example shows how to convert a floating-point system to fixed point using the Fixed-Point Tool from Fixed-Point Designer™.

Required MathWorks™ products:

  • MATLAB®

  • Signal Processing Toolbox™

  • DSP System Toolbox™

  • Simulink®

  • MATLAB® Coder™

  • Simulink® Coder™

  • Embedded Coder™

  • Fixed-Point Designer™

Introduction

This tutorial is designed to show you some of the capabilities of the Fixed-Point Tool and to provide you with an understanding of the steps that are necessary to convert a floating-point system to fixed point. The Fixed-Point Tool automates most of the tasks that are necessary to convert a floating-point model to fixed point. In the first step of the workflow, the Fixed-Point Tool suggests appropriate fixed-point settings for your system.

This example uses the same floating-point model that is discussed in the dspparameqcodegen example. The discussion and work flow described in that example also apply here.

In this example, you use the Fixed-Point Tool to convert the Equalizer subsystem of the dspparameqflt2fix model from floating point to fixed point. After using these tools to do this conversion, you will be able to generate and examine the fixed-point C-code produced by the Equalizer subsystem.

Examining the Equalizer Subsystem

The Equalizer subsystem consists of three second-order biquadratic filters whose coefficients can be adjusted to achieve a desired frequency response.

The following user interface (UI) can be used in simulation to dynamically adjust the filter coefficients.

The filters are implemented using multiple DSP System Toolbox™ Biquad Filter blocks. By default, the fixed-point parameters on these blocks inherit their word and fraction lengths from the block input. You can see these settings on the block dialog. To allow the Fixed-Point Tool to adjust the word and fraction lengths of the fixed-point parameters, you must set them to 'Binary point scaling'. When you do so, the block sets the word and fraction lengths to initial values which you can modify at any time. The Fixed-Point Tool can then recommend new fraction length settings that improve precision and prevent overflow, based on the minimum and maximum values logged during simulation.

This example provides a script that changes the fixed-point parameters of the three Biquad blocks to 'Binary point scaling'. The script also sets the accumulator word length of these blocks to 40 bits, a length that is used in some DSP hardware processors.

Open the model and run the script by clicking on the following hyperlink: Prepare Biquad fixed-point parameters. To view the script, click Examine the script.

If you do not have a script to change the fixed-point parameter settings in a model, you must do so manually. To do so, open the block dialog, click the ''Data types'' tab and select the appropriate fixed-point parameter setting. Alternatively, you can write your own script and use the set_param function to change the fixed-point parameter settings.)

Set Up the Model

Before converting a model to fixed point, it is a best practice to set up signal logging and to specify your target hardware. Logging signals allows you to compare the behavior of the floating-point model with the behavior of the fixed-point model after conversion.

The Fixed-Point Tool uses the specified target hardware information when proposing data types for the model. In the Hardware Implementation pane of the Configuration Parameters dialog, set the Device vendor, to Texas Instruments. Set Device Type, to C6000. This processor has a 40 bit long data type.

Use the Fixed-Point Tool to Convert the Equalizer Subsystem to Fixed Point

To open the Fixed-Point Tool, from the model menu, select Analysis>Data Type Design>Fixed-Point Tool. In the Prepare System section of the toolstrip, set the System Under Design to the Equalizer subsystem.

1. In the *Collect Ranges section of the toolstrip, set the range collection method to Simulation Ranges, and then click Prepare. The Fixed-Point Tool checks the system under design for compatibility with the conversion process and reports any issues found in the model. When possible, the Fixed-Point Tool automatically changes settings that are not compatible. In cases where the tool is not able to automatically change the settings, the tool notifies you of the changes you must make manually to help the conversion process be successful.

2. Click *Collect Ranges to run a simulation and have the Fixed-Point Tool log minimum and maximum values that occur during the simulation. You can see in the Visualization of Simulation Data that the current data types on the model result in several overflows during simulation.

3. Click the *Propose Data Types button. The Fixed-Point Tool uses the ranges collected in the previous step to propose data types that avoid overflows while maintaining as much precision as possible.

The proposed fraction length changes are shown in table column 'ProposeDT'. The fields are editable so you can modify any proposed value. The boxes to the left of each proposed data type will be checked. Uncheck any to refuse the proposed change. When you are done, click the Apply data types button.

4. To compare the behavior after conversion to the behavior before using the Fixed-Point Tool, click *Simulate with Embedded Types. You can use Simulation Data Inspector to compare the behavior of the signals that you logged before and after conversion. To open Simulation Data Inspector, click Compare Signals.

The Equalizer subsystem has now been converted to fixed point. Set the 'Stop time' to 'inf' and run the model. You should see a fixed-point frequency response that is visually identical to the floating-point frequency response. The two responses are shown here for comparison.

Generating C-Code for the Equalizer Subsystem

To generate C-code, click the 'Generate Code for Equalizer Subsystem' block. You can also generate code by clicking the following hyperlink: Generate Code for the Equalizer Subsystem. The model is configured to generate an HTML report that can be used to navigate the generated source code and header files.

A more detailed discussion of other code generation options can be found in dspparameqcodegen.

Additional Information

For more information on using the Fixed-Point Tool from Fixed-Point Designer, see Fixed-Point Advisor.

For more information on working with fixed-point data in the DSP System Toolbox, see Fixed-Point Signal Processing Development.