LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

while loop time?

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

0 Kudos
Message 1 of 12
(3,711 Views)

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

0 Kudos
Message 2 of 12
(3,703 Views)

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

0 Kudos
Message 3 of 12
(3,684 Views)

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.


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 12
(3,666 Views)

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

0 Kudos
Message 5 of 12
(3,663 Views)

Hi Mike,

 

The VI is in the attachment.

The highest speed I ever used is 20KS/s.

 

Jude

0 Kudos
Message 6 of 12
(3,622 Views)

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

 

0 Kudos
Message 7 of 12
(3,619 Views)

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.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 12
(3,596 Views)

Sorry, could you please post a graphical picture of the attachment? It seems my labview's version is a little bit old.

0 Kudos
Message 9 of 12
(3,579 Views)

Sorry, I didn't save it back far enough.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 12
(3,570 Views)