after converting the model into fixed point the rms value outside the sub system and after conversion are different even after using the fixed point tool iterative method

1 回表示 (過去 30 日間)
the input given is instantaneous current which goes to a subsystem then throught a demux and a RMS block , after which the current value i am getting is gretater than the original value, i got a warning of quantization and precision loss but , i dont no how to fix it wat should i do?

回答 (1 件)

Andy Bartlett
Andy Bartlett 2024 年 3 月 27 日
編集済み: Andy Bartlett 2024 年 3 月 27 日
Behavioral Requirements are Key
The key question is whether the system meets its behavioral requirements.
I applied Data Type Override to your model
set_param(bdroot,'DataTypeOverride','Double')
to see the "luxury" simulation behavior using double precision floating point.
I then turned off Data Type Override
set_param(bdroot,'DataTypeOverride','UseLocalSettings')
to see the current fixed-point behavior.
Just from glancing at your Scope blocks, the responses looked pretty similar. But that's superficial.
I suggest you create tests to exercise your model and prove that it meets behavior constraints in doubles.
Write scripts that test the simulation response to show that behavior requirements are met.
The scripts could be informal or use the MATLAB unit testing tools. Key thing is that running the script should clearly indicate if the model meets the behavior requirements.
Then turn on the fixed-point data types and re-run your scripts on the model. Does it still pass the behavioral requirements? If yes, you're done. If not, you could explore where the model is most numerically sensitive and explore using bigger fixed-point data types there.
Precision Loss is Expected
Parameter precison loss messages like the following are to be expected.
"The original value of the parameter, 0.7071067811865475, cannot be represented exactly using the run-time data type sfix16_En15. The value is quantized to 0.70709228515625. Quantization error occurred with an absolute difference of 1.4496030297461715e-5 and a relative difference of 0.00205004826472416%."
It looks like the "ideal" value being used is sqrt(2)/2.
Representing that value even double precision floating-point will involve precision loss.
format long g
valIdeal = sqrt( sym(2) ) / 2
valIdeal = 
valDouble = double(valIdeal)
valDouble =
0.707106781186548
errDouble = double( sym(valDouble,'f') - valIdeal )
errDouble =
4.83364665672646e-17
Here are several fixed-point example using best precision scaling with various word lengths.
valFi64 = fi([],0,64,'Value',char(vpa(valIdeal,50)));
wlv = [inf, 64, 53, 32, 24, 16, 8:-1:1];
for wl = wlv
if isinf(wl)
fprintf("valIdeal = %s...\n",char(vpa(valIdeal,80)))
continue
end
fiCurrent = fi(valFi64,0,wl);
if wl == 53
s2 = " Same accuracy as double";
elseif wl == 24
s2 = " Same accuracy as single";
else
s2 = "";
end
fprintf("valFi%02d = %-51s %s\n",wl,fiCurrent.Value,s2)
end
valIdeal = 0.70710678118654752440084436210484903928483593768847403658833986899536623923105352...
valFi64 = 0.70710678118654752438189403651591646848828531801700592041015625 valFi53 = 0.70710678118654757273731092936941422522068023681640625 Same accuracy as double valFi32 = 0.707106781192123889923095703125 valFi24 = 0.707106769084930419921875 Same accuracy as single valFi16 = 0.7071075439453125 valFi08 = 0.70703125 valFi07 = 0.7109375 valFi06 = 0.703125 valFi05 = 0.71875 valFi04 = 0.6875 valFi03 = 0.75 valFi02 = 0.75 valFi01 = 0.5
The accuracy at 16 bits is pretty good. It's unlikely something you need to worry about. You could set the parameter precision loss diagnostic to None, or you could review each warning, and if OK, then click the suppress link in the Diagnostic Viewer.

カテゴリ

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

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by