floating-pointmatlabfixed-pointti-dsp

Fixed Point MATLAB DSP Algorithm


I've got a question about coding an algorithm for a Texas Instruments TMS320C64xx DSP in MATLAB:

I've got a working sloppy implementation of my filter in MATLAB. My goal is to use MATLAB Embedded Coder to convert this algorithm to C which I can then import to Code Composer Studio and load onto the DSP.

To do this, I know there are certain things I need to do to my MATLAB code. For example, I need to pre-allocate space for matrices so it knows what size to make them (unless I want to fuss around with variable sized data). All that massaging of MATLAB code into C'ish code so that MATLAB coder can convert it I more or less understand. However, I have no idea how to make sure that my data types (for example the coefficients of my filter) are fixed point rather than floating point so that MATLAB Embedded Coder will convert my code to C which only involves fixed point data types.

So I guess my overall questions are:

1) If the C64xx is specified as a 32-bit Fixed Point DSP, that means a compiler for it will throw an error if I try to use the float data type?

2) Is there a way to ensure that MATLAB Embedded Coder does not create float data types?

3) Do I need to use the MATLAB Fixed Point Toolbox?

Thank you all, let me know if there is anymore information necessary to answer my question.


Solution

    1. You can use floating point data types but, as the previous answer points out, the DSP will be emulating floats and the execution will be much slower. This type of execution is OK for certain numerical operations where a) you need the precision of floats b) and/or conversion to fixed-point is typically a pain (e.g. square roots) or not feasible always, c) and/or these operations don't occur that often in your program to hog most of the CPU cycles.

    2. Yes. There's a checkbox in the MATLAB Coder configuration setting dialog, under Interface pane, that says "Support only purely-integer numbers". Checking this will ensure that you don't get any floating point data types in the generated code. However, you first need to make sure you use only integer/fixed-point data types in your code. This option just ensures there are not floats generated - it doesn't automatically generate a fixed-point or integer only version of the code from your floating point MATLAB Code.

    3. To truly create a fixed-point C-code, you'd first have to convert your floating point MATLAB code to a fixed-point one. You would need the Fixed-Point Toolbox that let's you specify your variables as a FI object, and define the fixed-point rules of operations using the FIMATH setting. Once you define a 16/32 bit fixed-point data types for all your variables and operations, you can simulate it, analyze the results, and iterate upon it to tweak your settings to minimize your overflows and rounding errors. Then you can generate a truly integer only C code that will behave just as (or very close to) your fixed-point MATLAB behavior. Any differences you may see between your fixed-point MATLAB code and fixed-point C code will primarily be due to those introduced by your target compiler.

    The following link to a recorded webinar on this topic should provide a good introduction to this process of using the Fixed-Point Toolbox: http://www.mathworks.com/wbnr38838

    HTH.