02-22-2012 04:26 AM
Hi~ I am very new in this area,, and need help with visual C#
I have a usb connected daqmx, which measures voltage type signals continuously.
I managed to view the signal in visual C#, using NI Daq window application template.
My current objective is to compute the mean of the signal in real time, and post it to a gauge.
So, I opened inside the code of signal template to update it., then I have trouble.
what it says is,
NationalInstruments.AnalogWaveform<double>[] acquiredData = daqTaskComponent1.Read();
waveformGraph1.PlotWaveforms(acquiredData);
What I want to do is to compute average of acquired data, and post it to a gauge real time ( such as gauge1.value=meanValue)
Anyone knows how to convert acquiredData into double data format and make a mean of the data, so that I can set as gauge input?
It seems that statistics.mean library isn't included as default in the template, either..so I need help with how to make a average of data.
Anyway, a picture is included to explain the situation better ...Thanks.
Edwin
02-23-2012 02:35 PM
I believe the following code will work well.
double Average = (double)acquiredData.GetValue(0);
int SamplesAcquired = 1;
for (long i = 1; i < acquiredData.LongLength; i++)
{
SamplesAcquired++;
Average = Average + ((double)acquiredData.GetValue(i) - Average)/ SamplesAcquired) ;
}