Colon operation in fixed-point

2 ビュー (過去 30 日間)
Joshua Ford
Joshua Ford 2022 年 2 月 10 日
編集済み: Andy Bartlett 2022 年 2 月 15 日
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?
  3 件のコメント
Joshua Ford
Joshua Ford 2022 年 2 月 11 日
f0 = fi(-20000000); %Initial Frequency
f1 = fi(20000000); %Target Frequency
T = fi(4e-6); %Pulse Duration
fs = 50000000; %Sampling rate = 50MHz
Ts = fi(1/fs); %Sampling time
NoPulses = 512; %Number of Pulses
Signal_Duration = 12e-6; %Time Duration of Signal
k = uint64((f1-f0)/5e-6); %Bandwidth = 40MHz
t = fi(0:Ts:T); %Time Samples
theta1 = fi(f0.*t + (k/2)*t.^2, 1, 16, 7);
theta2 = fi(2*pi, 1, 16, 7);
theta = theta1*theta2; %Phase
Chirp = cos(theta) + 1i*sin(theta) ; %Reference Chirp
Joshua Ford
Joshua Ford 2022 年 2 月 11 日
I have tried multiple variation of this and I am either getting an error stating that 'colon operation aren't supported for fiex-point operation' or that 'invalid v - value must be fi or constant'

サインインしてコメントする。

回答 (3 件)

Kiran Kintali
Kiran Kintali 2022 年 2 月 10 日
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.
  2 件のコメント
Joshua Ford
Joshua Ford 2022 年 2 月 11 日
f0 = fi(-20000000); %Initial Frequency
f1 = fi(20000000); %Target Frequency
T = fi(4e-6); %Pulse Duration
fs = 50000000; %Sampling rate = 50MHz
Ts = fi(1/fs); %Sampling time
NoPulses = 512; %Number of Pulses
Signal_Duration = 12e-6; %Time Duration of Signal
k = uint64((f1-f0)/5e-6); %Bandwidth = 40MHz
t = fi(0:Ts:T); %Time Samples
theta1 = fi(f0.*t + (k/2)*t.^2, 1, 16, 7);
theta2 = fi(2*pi, 1, 16, 7);
theta = theta1*theta2; %Phase
Chirp = cos(theta) + 1i*sin(theta) ; %Reference Chirp
Joshua Ford
Joshua Ford 2022 年 2 月 11 日
I have tried multiple variation of this and I am either getting an error stating that 'colon operation aren't supported for fiex-point operation' or that 'invalid v - value must be fi or constant'

サインインしてコメントする。


Kiran Kintali
Kiran Kintali 2022 年 2 月 11 日
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
Andy Bartlett 2022 年 2 月 15 日
編集済み: Andy Bartlett 2022 年 2 月 15 日
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
% lo:spacing:hi
% requires the all three arguments
% lo
% spacing
% hi
% 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
% Conceptually
% fiIntegerVec = (0:(nPts-1));
% finalVec = fiAnchor + fiIntegerVec.*fiSpacing
%
uDelta = uHi - uLo;
nPtsMinusOne = round( uDelta/uSpacing );
integerVec = 0:nPtsMinusOne;
y = uLo + (uSpacing .* integerVec);
end
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.

カテゴリ

Help Center および File ExchangeFixed-Point Designer についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by