定点 MATLAB DSP 算法
我有一个关于在 MATLAB 中为 Texas Instruments TMS320C64xx DSP 编写算法的问题:
我在 MATLAB 中得到了一个可以正常工作的滤波器实现。我的目标是使用 MATLAB Embedded Coder 将此算法转换为 C,然后将其导入到 Code Composer Studio 并加载到 DSP 上。
为此,我知道需要对 MATLAB 代码执行某些操作。例如,我需要为矩阵预先分配空间,以便它知道要制作它们的大小(除非我想使用可变大小的数据)。我或多或少理解所有将 MATLAB 代码转换为 C'ish 代码以便 MATLAB 编码器可以将其转换的过程。但是,我不知道如何确保我的数据类型(例如滤波器的系数)是定点而不是浮点,以便 MATLAB Embedded Coder 将我的代码转换为仅涉及定点数据类型的 C。
所以我想我的总体问题是:
1)如果C64xx被指定为32位定点DSP,这意味着如果我尝试使用浮点数据类型,它的编译器将抛出错误?
2) 有没有办法确保 MATLAB Embedded Coder 不会创建浮点数据类型?
3) 我需要使用MATLAB定点工具箱吗?
谢谢大家,如果还有必要的信息来回答我的问题,请告诉我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用浮点数据类型,但正如前面的答案指出的那样,DSP 将模拟浮点数,并且执行速度会慢得多。这种类型的执行对于某些数值运算是可以的,其中
a)你需要浮点数的精度
b) 和/或转换为定点通常很痛苦(例如平方根)或并不总是可行,
c) 和/或这些操作在您的程序中不会经常发生,从而占用大部分 CPU 周期。
是的。 MATLAB Coder 配置设置对话框中的“界面”窗格下有一个复选框,显示“仅支持纯整数”。检查此项将确保您不会在生成的代码中获得任何浮点数据类型。但是,您首先需要确保在代码中仅使用整数/定点数据类型。此选项只是确保不生成浮点 - 它不会自动从浮点 MATLAB 代码生成代码的定点或纯整数版本。
要真正创建定点 C 代码,您首先必须将浮点 MATLAB 代码转换为定点代码。您需要使用定点工具箱来将变量指定为 FI 对象,并使用 FIMATH 设置定义定点运算规则。一旦为所有变量和运算定义了 16/32 位定点数据类型,您就可以对其进行仿真、分析结果并对其进行迭代以调整设置,以最大限度地减少溢出和舍入误差。然后,您可以生成真正的纯整数 C 代码,其行为与定点 MATLAB 行为相同(或非常接近)。您在定点 MATLAB 代码和定点 C 代码之间可能看到的任何差异主要是由目标编译器引入的差异造成的。
以下链接指向有关此主题的录制网络研讨会,应该很好地介绍了使用定点工具箱的过程:
http://www.mathworks.com/wbnr38838
HTH。
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.
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.
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.
我只能回答你的第一个问题:
C64xx是32位定点DSP,但如果你使用浮点,编译器不会抱怨。生成的代码将运行良好,但会(很多)慢,因为将模拟浮点运算。
C64xx DSP 还可以执行 16 位定点和混合 32x16 位定点。您使用的数据类型越小,生成的代码运行得越快。
I can only answer to your first question:
The C64xx is a 32 bit fixed point DSP, but the compiler will not complain if you use floating point. The resulting code will run fine but will be (a lot) slower because the floating point operations will be emulated.
The C64xx DSP also can do 16 bit fixed point and mixed 32x16 bit fixed point. The smaller the data-types are that you use, the faster the resulting code will run.