Matlab Coder: Generate code for 'main' function for fixed-point code

3 次查看(过去 30 天)
I am trying to generate fixed-point C code for a Matlab program using Matlab Coder and the Fixed-Point Toolbox. Using the Matlab Coder I was able to generate the C code under the setting: static library on the host computer. I see that the generated code also contains a dummy main function which invokes the function. This would be sufficient in the general case but not when using the Fixed-Point Toolbox, because I also require code to convert my input arguments to fixed-point, which is non-trivial. This task requires knowing the fraction length of each input argument and the quantization code to convert the float variable to fixed written in C.
Can anyone tell me how to generate C code for the main script which invokes the Matlab function?

采纳的回答

Ji Lee
Ji Lee 2018-4-16

One of the outputs of the automated fixed-point conversion workflow in either Fixed-Point Converter or MATLAB Coder is a "wrapper" function that can help take care of type conversions. You can take this function and run it through MATLAB Coder either separately or as an additional entry-point.

As an example, let’s say you’ve generated fixed-point MATLAB code for a single function “foo” using the automated workflow in either the Fixed-Point Converter app or MATLAB Coder app. By default, you’ll probably wind up with a new folder named something like “codegen/foo/fixpt”. In this folder, you’ll find three files of note for the task at hand. Specficially, these will be foo_fixpt.m (the converted fixed-point MATLAB code), foo_wrapper_fixpt.m (the wrapper function mentioned above), and foo_fixpt_args.mat (auxiliary information). Assuming such an example setup, the code below would demonstrate a workflow that may be of help to you.

% Either move/copy the files in 
% Set up your config however you'd like
cfg = coder.config('lib');
cfg.GenerateExampleMain = 'GenerateCodeOnly';
values = load('foo_fixpt_args');
fiInputTypes = values.values.inputArgs;
% Generate code using either one or both entry points (unwrapped foo_fixpt and wrapped foo_fixpt).
% Replace the input types of the wrapper function below with your original floating-point input types.
codegen foo_fixpt -args fiInputTypes foo_wrapper_fixpt -args {0,0} -config cfg -report
  1 个评论
Sridhar Gopinath
Sridhar Gopinath 2018-4-17
Thank you for your answer. I will test your suggestions on my project and will get back to you.
Can you please also address a performance issue I am facing while executing the fixed-point code? In the Fixed-Point Designer tool, there is a very nice option to test the generated fixed-point Matlab code. This is very useful to directly compare the performance of the original floating-point code with the fixed-point code. When I run this test, the output dialog shows that it completed the execution in a couple of seconds (5s). Now, I want to execute the same script outside the app. To do this, I modify my script to call the wrapper function (to convert the arguments to fixed-point) which then invokes the generated fixed-point code (files present in codegen\foo\fixpt). When I do this, the execution is surprisingly very very slow. The total time taken is in the order of minutes (on the same data) which is not in line with the performance when executed inside the app. Can you let me know how the app executes the fixed-point code and how to replicate the same outside the app?
Thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fixed-Point Conversion 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by