How to decrease the precision of an arithmetic operation
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all.
I have a question about the precision used by Matlab in arithmetic operations. I have an array of data acquired by my acquisition system, with an ADC on 12 bit. When i load the data in Matlab, all the values are loaded as "short", that is to say on 16 bit, and the nonzero digits are only the first 8 decimal numbers, then there are zeros to fill all the 16 bits. The problem is that i want to do some operations on these values, like removing the mean and filter them; when i remove the mean, calculating it with the function "mean" and then subctracting it from the array, i get 15 nonzero decimal numbers, because the mean i get from the function is expressed on 15 decimal digits. This makes all the variables from this step on, bigger. How can i get ALL the operations like mean removal, filtering and everything else take only 8 decimal digits, since i don't need higher precision and i prefer to save space? Thanks in advance.
댓글 수: 0
답변 (1개)
Walter Roberson
2017년 1월 26일
When you call mean() you can pass the option 'native' to have the mean be the same datatype as the input.
Some of the filtering routines only work on floating point; it would depend on which one you used.
댓글 수: 2
Walter Roberson
2017년 1월 27일
filtfilt() only accepts doubles.
If the values you get back are in the range 0 to 65535, then you can divide them by 16 to get values in the range 0 to 4095.
Once you have values in the range 0 to 4095, if you want to keep them in that range after filtering, you can use floor() on the results of the filtering.
(Depending on the filtering you do, you could potentially end up with a little gain, so the values might not remain strictly in that range.)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!