This post was originally published at Walking the Wires
This blog post should be filed under the Public Service Announcement category. Recently, a customer contacted me with an issue he was observing when averaging a voltage measurement. He insisted that mean.vi  was calculating the mean incorrectly!
The code we were using was:

Array of waveforms to Mean.vi

Array of waveforms to Mean.vi


 
The symptom was that the result of the mean operation seemed to always be the last value of the signal acquired.
After the denial phase of “there is no possible way that mean.vi is not calculating the average correctly” we did further investigation.
 
Waveforms Array Further Inspection

Adding code to further inspect how the array of waveforms was converted into a 1D DBL array.


Wait! Say what? … yes, as you can see in the image, when an array of waveforms is converted into a 1D DBL array, only the last element of each waveform is taken to form the resulting array.
Since the DAQmx task in the original code was configured to a single channel, we fixed the issue by just changing from reading multiple samples from multiple channels to reading multiple samples from a single channel. Another option would have been to configure the DAQmx Read selector to output an array of doubles instead of an array of waveforms.
This little episode reminded me why I only use the waveform datatype when wiring directly to a graph or when using the waveform palette functions.
Happy wiring and beware of mean waveform data type coercions 😉
Fab