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.

回答(1 个)

Walter Roberson
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 个评论
Alessandro Russo
Alessandro Russo 2017-1-26
编辑:Alessandro Russo 2017-1-26
I use "filtfilt" to apply butterworth filtering. There is no other possibility? I mean something to "truncate" the significant digits?
Walter Roberson
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 CenterFile Exchange 中查找有关 Matched Filter and Ambiguity Function 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by