LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

mean vs average

Solved!
Go to solution
Solution
Accepted by david_jenkinson

While there are ways to minimize the problem (e.g.successive decimation by adding adjacent points until only one point remains, etc.), the solution is to simply convert to DBL. SGL is just not appropriate here if you need precision.

 


QUOTE: The difference in measurement is:

 

Averaging using total/#samples = 79.88

using Mean vi = 81.72


 

 

 

How precise does the average need to be? Mabe all you need to know that it is ~ 80?

0 Kudos
Message 11 of 15
(2,094 Views)

Hmm, I just looked up Single and Double Precision formats.  Single is 24 bits (about 7 decimal digits), Dbl is 53 bits (about 16 decimal digits), so I'm not sure what tst means when he says that 280 million the resolution would be 32.  Your resolution should be more like 0.000001 (or better), I would think.

 

Bottom line -- use Dbl.  I've actually standardized on Dbl for my code, only using Sgl when dealing with old equipment that wants this format (even then, I usually use a Conversion function or accept a Coercion dot).  There is a "cost" in memory (8 bytes instead of 4) and disk space, but both are fairly inexpensive now.  

 

What about speed?  I tried the following -- generate a million random numbers and save as an array.  Copy the (Dbl) Array, converting it to Sgl.  Create one more random number (in both Dbl and Sgl formats) and do a "Multiply Array by scalar" operation, and time it.  I expected the times to be close (not thinking of the time spent loading 8 bytes instead of 4) -- to my surprise, the Sgl operation took 2.3 msec, the Dbl took 17.3, a factor of 5.

 

I then summed the two arrays using the "Add Array Element" function.  Here, the times were comparable -- 1.66 msec for Sgl, 1.98 msec for Dbl.  As you might expect, the two sums agreed to six significant figures, but differed on the 7th.

 

Bob (when in doubt, do an Experiment) Schor

 

 

 

 

0 Kudos
Message 12 of 15
(2,077 Views)

@Bob_Schor wrote:

Hmm, I just looked up Single and Double Precision formats. Single is 24 bits (about 7 decimal digits), Dbl is 53 bits (about 16 decimal digits), so I'm not sure what tst means when he says that 280 million the resolution would be 32. Your resolution should be more like 0.000001 (or better), I would think.

[snip]

What about speed? I tried the following -- generate a million random numbers and save as an array. Copy the (Dbl) Array, converting it to Sgl. Create one more random number (in both Dbl and Sgl formats) and do a "Multiply Array by scalar" operation, and time it. I expected the times to be close (not thinking of the time spent loading 8 bytes instead of 4) -- to my surprise, the Sgl operation took 2.3 msec, the Dbl took 17.3, a factor of 5.

 


280M with 7 digits is e.g. 0,2800000*10^9 (which is basically how a float is represented), to get any change to the 7th digit you'd need to increase the value by 100. That's what Tst meant (but with more correct values).

Sgl can usually fit and be performed as a single operation in the FPU, a dbl needs to do 2 sgl multiplications and merge the result. (depending on the FPU capabilities.)

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 13 of 15
(2,038 Views)

Since all value have the same weigth, you can 'divide and conquer' ...   at some point you may run out of memory otherways

Take bunches of about 1000 values and calculate the mean and keep them in an array.  (decimation with mean) , do that with the mean values again until you have one value.

if all bunches have the same size, you get the same result. Only the standarddeviation will be different ...

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 14 of 15
(2,031 Views)

@Bob_Schor wrote:

...so I'm not sure what tst means when he says that 280 million the resolution would be 32.  Your resolution should be more like 0.000001 (or better), I would think.


The resolution is the difference between two adjacent values. In floating point this is not constant across the range, and like I said, at that point it's 32, so if you can put in 280,000,000, then the next valid value is 280,000,032 and the next one is 280,000,064. If you try taking 280M and adding 10 to it you will still get 280M because it will round to the nearest valid value. Like you said, when in doubt, experiment.

 

But I agree that simply using DBL is better most of the time and should be the default.


___________________
Try to take over the world!
0 Kudos
Message 15 of 15
(2,000 Views)