Accelerate fixed-point code and convert floating-point MATLAB code to fixed-point MATLAB code
fiaccel -options fcn
fiaccel -float2fixed fcn
fiaccel - translates
the MATLAB® file options fcnfcn.m to
a MEX function, which accelerates fixed-point code. To use fiaccel,
your code must meet one of these requirements:
The top-level function has no inputs or outputs, and
the code uses fi
The top-level function has an output or a non-constant
input, and at least one output or input is a fi.
The top-level function has at least one input or output
containing a built-in integer class (int8, uint8, int16, uint16, int32, uint32, int64,
or uint64), and the code uses fi.
Note
If your top-level file is on a path that contains Unicode characters, code generation might not be able to find the file.
fiaccel -float2fixed converts
the floating-point MATLAB function, fcnfcn to
fixed-point MATLAB code.
|
MATLAB function from which to generate a MEX function. |
|
Choice of compiler options.
|
Create a test file and compute the moving average. Then, use fiaccel to
accelerate the code and compare.
function avg = test_moving_average(x)
%#codegen
if nargin < 1,
x = fi(rand(100,1),1,16,15);
end
z = fi(zeros(10,1),1,16,15);
avg = x;
for k = 1:length(x)
[avg(k),z] = moving_average(x(k),z);
end
function [avg,z] = moving_average(x,z)
%#codegen
if nargin < 2,
z = fi(zeros(10,1),1,16,15);
end
z(2:end) = z(1:end-1); % Update buffer
z(1) = x; % Add new value
avg = mean(z); % Compute moving average
% Use fiaccel to create a MEX function and
% accelerate the code
x = fi(rand(100,1),1,16,15);
fiaccel test_moving_average -args {x} -report
% Compare the non-accelerated and accelerated code.
x = fi(rand(100,1),1,16,15);
% Non-compiled version
tic,avg = test_moving_average(x);toc
% Compiled version
tic,avg = test_moving_average_mex(x);toc
Create a coder.FixptConfig object, fixptcfg,
with default settings.
fixptcfg = coder.config('fixpt');Set the test bench name. In this example, the test bench
function name is dti_test.
fixptcfg.TestBenchName = 'dti_test';Convert a floating-point MATLAB function to fixed-point MATLAB code.
In this example, the MATLAB function name is dti.
fiaccel -float2fixed fixptcfg dti
coder.ArrayType | coder.config | coder.Constant | coder.EnumType | coder.FiType | coder.FixPtConfig | coder.mexconfig | coder.mexconfig | coder.newtype | coder.PrimitiveType | coder.resize | coder.StructType | coder.Type | coder.typeof