Colon operation in fixed-point
4 vues (au cours des 30 derniers jours)
I am writing a function in 2020b that I then want to convert into fixed-point using the tool. I am defining some arrays by the colon operation, however when i use variables in the colon it does not like it. Yet using the exactly same numbers as numbers and not variables the tool says no and that it must be a fi or constant object. Why is this and how can i fix it?
Kiran Kintali le 10 Fév 2022
MATLAB HDL Coder workflow does support colon operator during fixed-point conversion and code generation. Please share a sample design file dut.m, testbench.m (caling dut) and a project file with fixed-point conversion settings.
Kiran Kintali le 11 Fév 2022
Support for colon exists with fixed-point types according to documentation. https://www.mathworks.com/help/fixedpoint/ref/colon.html
Please reach out to https://www.mathworks.com/support.html for additional help specific to your usecase.
Andy Bartlett le 15 Fév 2022
Modifié(e) : Andy Bartlett le 15 Fév 2022
fi colon integer values only
As the fi colon documention mentions, all colon operands must have integer values.
Strategy to generalize fi colon
The following function shows a strategy for getting colon behavior that will work with fi objects.
The key idea is create an integer valued vector [0, 1, 2, ... n-1].
Then multiply by a scalar and add a scalar to produce the desired colon-style vector.
function y = colonAlternative(uLo,uSpacing,uHi)
%colonAlternative alternative to colon due to fi restrictions with colon
% fi colon operator
% requires the all three arguments
% to have integer values
% To work around this create an integer valued vector
% then multiply by the desired spacing
% and add the desired starting point if it is not zero
% fiIntegerVec = (0:(nPts-1));
% finalVec = fiAnchor + fiIntegerVec.*fiSpacing
uDelta = uHi - uLo;
nPtsMinusOne = round( uDelta/uSpacing );
integerVec = 0:nPtsMinusOne;
y = uLo + (uSpacing .* integerVec);
Compatible Example for Fixed-Point Converter
The attached design file fiColonLookupV2.m and its associated testbench file test_fiColonLookupV2.m are compatible with Fixed-Point Converter. Use of the strategy shown makes sure that only integer valued fi objects are fed to the colon operator's operands.
Code Generation Fixed-Point Designer Data Type Exploration Fixed-Point Specification Fixed-Point Specification in MATLAB Create Fixed-Point Objects in MATLAB