Why does simulink generate warnings about quantization error when running my simulation?
19 次查看(过去 30 天)
显示 更早的评论
In simulink I am making a filter using single precision coefficients. When I simulate the design I receive the following warning:
"The parameter's value cannot be represented exactly using the run-time data type. A small quantization error has occurred."
I am entering the coefficients into gain blocks, with the data type set to single precision. I believe that everything in my design is set to single precision. Is there a setting that I am missing that is causing the quantization error?
0 个评论
回答(1 个)
Andy Bartlett
2018-2-9
Hi, I assume the coefficients have been entered using with MATLAB code like this
coef = [0.05 0.15]
Since MATLAB defaults to double, these coefficients will be the most accurate representation of 0.05 and 0.15 that a double can hold. To see how close, you could do
mat2str(coef,18)
ans =
'[0.0500000000000000028 0.149999999999999994]'
If you've constructed your model to use coef with single precision run-time parameters, then the original doubles will need to be quantized to singles. Under the hood, the Simulink model is doing the equivalent of
runTimeCoef = single(coef)
To see what this produces, you could do
mat2str(runTimeCoef,18)
ans =
'[0.0500000007450580597 0.150000005960464478]'
As you can see, the before and after values are difference.
'[0.0500000000000000028 0.149999999999999994]'
'[0.0500000007450580597 0.150000005960464478]'
Hence, the warning about precision loss.
One way to avoid this is to pre-quantized the coefficients before supplying them to Simulink
coef = single([0.05 0.15])
The parameter value used by the Simulink model will still be identical
'[0.0500000007450580597 0.150000005960464478]'
but the warning would go away.
As of R2016b, you can also suppress individual warnings after you've reviewed them and determined the warning to be benign.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!