LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Single Precision Measures of Mean.vi?

Measures of Mean.vi only takes double precision float as input.  When I use single precision to save space, and where A/D resolution is the limiting factor anyhow, it is pretty annoying to have to promote a whole array of data to double just to get the median (or another of the functions in Measures of Mean.  Can't this thing be recompiled to be able to do both double and single?

 

Thanks

 

0 Kudos
Message 1 of 5
(3,365 Views)
Same question applies to Median.vi which is the underlying code for the median in Measures of Mean.  I presume it applies to the other functions in Measures of Mean, but haven't looked at those because I only needed median.
0 Kudos
Message 2 of 5
(3,354 Views)

You can easily dump Mean.vi and use Array Sum and divide by Array Length. You could dump Median.vi and use Sort 1D Array and then Interpolate 1D Array with a fractional index of (Array Length - 1)/2.  Change the controls to SGL and you should avoid the promotion.

 

This is easy-to-code version of Median may not work as well as you'd like.  Unless the folks at NI did something silly, the code to find the Median probably works in-place (no sorting).  The simple method I describe creates a sorted copy, so it not only is a bit slower than it needs to be, it also uses about the same memory since you have two SGL arrays instead of one DBL.  You could find a nice algorithm for the median and code it yourself (in LV or C).

 

My guess is your best bet is to minimize the number of coercions in your code.  For example, do everything in DBL until it comes time to write the data to disk.  At that point, convert to SGL and save.

0 Kudos
Message 3 of 5
(3,343 Views)
Now that I am back on my computer with LV, a simple check of the context help reveals that the array is sorted by Median.vi, so you could easily dump it for the solution I described above and avoid all coercions.
0 Kudos
Message 4 of 5
(3,336 Views)
I wrote a VI using Sort1DArray.  That is close to trivial given the usual definition of median.  I know there are much more efficient algorithms for median, but the descriptions of them I have found so far on line are beyond my limited ability to convert to LV.  The Sort1DArray approach will certainly make a buffer for the array and that will be expensive with a large array.  It does allow me to keep it single precision all the way through.
0 Kudos
Message 5 of 5
(3,314 Views)