This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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 Advisor from Fixed-Point Designer™.

Required MathWorks™ products:


  • Signal Processing Toolbox™

  • DSP System Toolbox™

  • Simulink®

  • MATLAB® Coder™

  • Simulink® Coder™

  • Embedded Coder™

  • Fixed-Point Designer™


This tutorial is designed to show you some of the capabilities of the Fixed-Point Tool and the Fixed-Point Advisor 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 Advisor automates most of the tasks that are necessary to convert a floating-point model to fixed point. By working together with the Fixed-Point Tool, the Advisor is able to suggest 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 and the Fixed-Point Advisor 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, or in the Fixed-Point Advisor. To allow the Advisor 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 Advisor 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.)

Getting Started

From the model menu, select Analysis>Data Type Design>Fixed-Point Tool. The Fixed-Point Tool opens. In the Model Hierarchy pane, select the Equalizer subsystem.

Set the 'Fixed-point instrumentation mode' parameter to 'Minimums, maximums and overflows'. This allows the Fixed-Point Tool to collect the data needed to recommend fixed-point scaling. Apply the change. Next, open the Fixed-Point Advisor by clicking the button in the 'Fixed-point preparation for selected system' group box.

The Fixed-Point Advisor opens. In the pane on the left, there is a series of tasks beginning with 'Prepare Model for Conversion'. In the pane on the right, the Advisor gives an explanation of the tasks it will perform and provides a legend of the icons it uses.

To begin the conversion, click the first task 'Prepare Model for Conversion' in the pane on the left. Next, click the 'Run All' button on the pane on the right. As you go through the steps, each successfully completed task displays a green check mark. Tasks that succeed, but have recommended changes, show a yellow warning icon. Tasks that fail show a red 'X'.

Using the Fixed-Point Advisor to Convert the Equalizer Subsystem to Fixed Point

Perform the following steps to convert the Equalizer subsystem to fixed point.

1. Prepare Model for Conversion. This task validates model-wide settings and creates simulation data. It consists of a number of sub tasks.

1.1 Verify model simulation settings. This task as well as tasks 1.2 and 1.3 pass. However, there is a warning at task 1.4.

1.4 Set up signal logging. To remove the warning, right-click on the output signal line of the Equalizer subsystem and select 'Properties'. When the Properties dialog opens, select the 'Log signal data' check box. After doing so, rerun task 1.4.

1.5 Create simulation reference data. Run this task next. It will fail. The task fails because the model stop time is set to INF. Click the link 'Specify a finite Stop time'. The Solver pane of the Configuration parameter dialog opens. Change the 'Stop time' to a finite time such as 1, click OK and then rerun the task. The model runs to collect reference data.

1.6 Verify Fixed-Point Conversion Guidelines. Right-click and execute 'Run all'. All sub tasks pass. However, there are some warnings that must be examined. The Advisor recommends that you change some of the Data Validity Parameter settings to 'warning'. To do so, follow the links provided and set the appropriate parameters to 'warning'. You can follow the same procedure for the 'Simulation range checking' warning. For the purposes of this example, you can skip these changes. It is not possible to check bus usage since this check only works from the top-level model. You can ignore this warning as well.

2. Prepare for Data Typing and Scaling. This task is used to avoid data type propagation failures by properly configuring blocks with data type inheritance or other constraints. Select this task and click 'Run all'.

3. Return to Fixed-Point Tool to Perform Data Typing and Scaling When you run this task, the Fixed-Point Advisor will close and the Fixed-Point Tool will reopen.

In the 'Automatic data typing' group box on the right, select Propose fraction lengths , and click the 'Propose data types' button.

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 accepted data types' button.

The Equalizer subsystem is now fixed point, but the Excitation subsystem is still floating point. You must put a Data Type Conversion block between the Excitation subsystem and the Equalizer subsystem. This block serves as an analog to digital converter in the model. Right-click on the Equalizer subsystem and select 'Insert Data Type Conversion block'>'All Inports'.

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.

Depending on your hardware platform, the generated code may need additional code steps to handle the 40 bit Biquad accumulator word size that was selected for this example. To examine the generated C-code for a processor with a 40 bit word length, you can do the following:

1) Open the Hardware Implementation pane of the Configuration Parameters dialog.

2) For Device vendor, select Texas Instruments. For Device Type, select C6000 This processor has a 40 bit long data type.

3) Generate code and compare the difference.

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

Additional Information

For more information on using the Fixed-Point Advisor 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.

Was this topic helpful?