how can I know which data types I need precisely?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have simulated a PI controller in simulink in double precision format, as the showed picture:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/663425/image.png)
and then when I change the addition and multiplication to single precision 32bit, I got a slight error around 100mv difference between the target and the output.
again, I have implemented the controller in DSP in C code and the there I used single precision. so my question is how to know if the single precision is enough or the double precision is needed? I meanfor me when I look at the single precision seems enough in term of precision but the outcome is slighlty difference also in DSP compared to double precision in Simulink.
I know it is a stupid question, I looked on the net the difference and it shows not so much on which one to choose.
댓글 수: 0
답변 (1개)
vidyesh
2024년 4월 12일
Hi SimTec,
Your question touches on the trade off between accuracy and computational cost of a system. Single precision, with its 7 decimal digits of precision, generally suffices for applications where slight errors (like a few hundred millivolts difference) are acceptable. It's faster and more resource-efficient, making it a good fit for real-time or embedded systems. Double precision, offering about 15 decimal digits of precision, is better suited for scenarios demanding high accuracy or where errors can accumulate. Ultimately, the choice hinges on the system's specific error tolerance, performance requirements, and resource constraints.
Depending on the required level of accuracy, the precision of the variables can be decided mathematically or through trial and error, depending on the system's complexity.
Refer to the below pages for more information on how to control the precision of variables:
Hope this helps.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!