valIdeal =
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
Show older comments
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?
Answers (1)
Andy Bartlett
on 27 Mar 2024
Edited: Andy Bartlett
on 27 Mar 2024
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
valDouble = double(valIdeal)
errDouble = double( sym(valDouble,'f') - valIdeal )
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
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.
Categories
Find more on Fixed-Point Matrix Operations in Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!