07-28-2013 12:33 PM
Hey guys,
I was using NI-USB-6009 to measure voltages from multiple channels by building virtual channels. To deal with the noise of the signal source, I want to average the data before plotting them. Like, take 5 or 10 samples and average them, and then take another 5 or 10 samples...... and plot the mean values. So I built a while loop and created a control on "samples to read" of the DAQmx Read and take the average value of samples, and append it to previous mean values by shift register.
The question is that when I tried it on a sine wave, in the plot there was a phase shift between every loop. Is it due to the while loop time? Is there any way to improve it?
Best regards,
Jude
07-28-2013 01:01 PM
Jude,
Any averaging or filtering process tends to generate phase shifts. Think about it this way: Suppose your sample rate is 1000 samples per second. An average calculated over ten samples cannot be perfmored until those ten samples have been taken. That requires 10 milliseconds. So the plot of the averages will lag 10 milliseconds behind the first of the samples averaged.
An average will have a fixed delay (phase shift). Some kinds of filters have delays which vary with frequency.
So, to answer your question about "improvemnt," we need to know what you are doing with the data and about the frequency characteristics of the signal (and any noise or interfering signals also). How do you define improve? Please be as specific as possible.
Lynn
07-28-2013 03:05 PM
Hi Lynn,
Thanks for replying.
Sorry I just realize that I described it incorrectly. And I probably shouldn't have used the word "phase shift".
The issue is not closely related to taking averages.
I actually constructed a case loop in the while loop so that I could control whether taking average or not. The problem is that when there was no average taking and the "samples to read" of the DAQmx Read function was set to be 10 (or 50, or other positive numbers), which means It was just normally reading data using while loop, the graph turned out to be that every loop was a piece of sine curve but these pieces were not smoothly connected. It was like they belong to sine waves with "phase shift" to each other. And when I set the "samples to read" to be -1, then the graph just shows one coherent sine wave.
So I was wondering was it due to the while loop time? Like, in every loop the device take 10 samples, and time between the last sample in the 1st loop and the first sample in the 2nd loop is exceedingly large?
The "improvement" means that is there any other way of taking data and calculate the average, instead of using a while loop?
Regards,
Jude
07-28-2013 04:39 PM
Could you perhaps post a typical plot of what you are seeing. Also, as was asked before, what is the frequency of the signal you are measuring and how fast are you sampling it?
Mike...
PS: instead of reading one point at a time you can read several and average them to get your output data point.
07-28-2013 04:41 PM
Jude,
It would help if you post your code with some data taken at 10 samples per iteration. That way we could see what you are seeing.
When you set samples to read = -1, it reads all available samples. When you are reading a specific number of samples it almost sounds as though you might be starting and stopping the task on each iteration. The restart of the task may occur at a random time with respect to the last previously acquired sample. This might produce the disconnected appearance.
Lynn
07-29-2013 09:12 AM
Hi Mike,
The VI is in the attachment.
The highest speed I ever used is 20KS/s.
Jude
07-29-2013 09:17 AM
Hi Lynn,
I have added my VI in the attachment.
So if it's -1, the DAQmx Read is actually reading continuously?
I was wondering, is it possible that I could just continuously taking data without a while loop and do the average simultaneously?
Jude
07-29-2013 10:42 AM
The chart keeps a history. And you are appending the current waveform to the what was previously captured. So you are duplicating data in your chart. The chart should be wired directly to your DAQ output.
You task only has a single input. So why are you trying to get 2 waveforms out of it?
If you are reading a waveform, why are you setting the T0 and dt? That information is already there. Use the data already in the waveform outputs.
If you are really capturing multiple channels, you should do you averaging with a FOR loop to iterate over your channels. The output of the DAQ Read is an array of waveforms. Autoindex this and your data will come out just fine.
There's a build in VI for calculating the average (mean) for a VI. Use that to make your life a lot easier.
07-29-2013 01:29 PM
Sorry, could you please post a graphical picture of the attachment? It seems my labview's version is a little bit old.
07-29-2013 02:30 PM
Sorry, I didn't save it back far enough.