LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Breaking up continuous data

Solved!
Go to solution

Hi, I'm trying to use labview to work with data in a very specific way.  I'm using a USB-6009 in import a continuous analog signal into labview.  I then want to take that signal and breaked it down to perform calculations on.  Essentially break it into a 5 second segment, average all that data, then store the average, then repeat for seconds 5-10, 10-15, and so on, storing all these averages(all while still inputting the continuous signal).  I initially tried using the moving average smoothing function, but that was more of a sliding average then taking blocks.  I'm just starting to learn labview, and I know my data is aquired in a while loop, and I'm fairly certain I will need to write another loop inside this to segment and average the data. I'm just struggling to put it all together.

 

Any help is much appreciated.

0 Kudos
Message 1 of 10
(3,327 Views)

You may be able to do it on one loop or two parallel loops, but nested loops will likely be more complicated.  Hint: Shift register.

 

Do you need to keep the original data after it has been segmented and averaged? How fast are you sampling? Or, equivalently, how much data do you accumulate in 5 seconds?

 

Please post what you have tried so far so someone can suggest improvements.

 

Lynn

0 Kudos
Message 2 of 10
(3,306 Views)
As Lynn pointed out you may be able to do the whole thing in one loop -- it all depends on how fast you're sampling. For example, say you are sampling at a 1kHz rate, 5 seconds of data is 5000 samples. Set up your DAQ process to sample continuously and read 5000 samples at a time. Each time you get a chunk of data from the DAQ read, average it and there's your datapoint.
Of course that technique also means that the software will be unable to do anything else (like respond to the user interface) for 5 seconds at a time.
To fix that you could only read 500 samples (1/2 second of data) at a time, buffer the data in a shift register and then do your average every 10 iterations of the loop.
Which brings us to a new question: what do you need your user interface to be doing while all of this is going on?

Mike ...

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 3 of 10
(3,291 Views)

Right now I'm sampling at 10Hz, and I wanted to be able to take say collect data for 5 seconds (50 data points) take those 50 data points, average them, and store that average somewhere so that I could use it for later calculations (such as finding the difference between each average later on). Currently my user interface needs to be displaying this as a numerical output, as well as a few other numerical outputs, so it doesnt need to be interactive and if say the user was to click a button it would be ok if that didnt register for 5 seconds.  I tried to do something that sounds similar to what you are suggesting, I'll attach the vi later.

0 Kudos
Message 4 of 10
(3,281 Views)

With the slow data rate and small numbers of samples everything should be fairly easy.

 

Lynn

0 Kudos
Message 5 of 10
(3,276 Views)

So I attached a picture of one of my first attempts to write a vi to do this.  This is supposed to control how many points are averaged by the iteration number on the loop, but I dont think I did it right as it doesn't appear to be working the way I'd like.  Like I said in my first post, I'm new to labbview and although I have a handle on inputting data and data types, I'm new to arrays and how they work and the indexing.  I'd really ultimately like to be able to save all of my block averages in an array and then reuse certain values (such as setting the first average I take to be a constant used for later calculations, as well as performing calculations on the averages as they are calculated).  Let me know if something I'm saying doesn't make sense....

0 Kudos
Message 6 of 10
(3,265 Views)
The biggest problem right off is the express VI. Look up the example Cont Acq&Graph Voltage-Int CLk.vi to get you started.

Mike...

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 7 of 10
(3,260 Views)

Sorry for the long time between replys.  I've been unable to work for a bit.  So I see what I am doing wrong with the express, I now have it so there is: 

physical channel--> creat channel voltage-->sample clock-->start task--> while loop containing analog read how would I attach this to later code to accomplish what I want.  Sorry I am relatively new to labview.

0 Kudos
Message 8 of 10
(3,235 Views)

Mike,

 

You had talked before about buffering in a shift register. I was wondering if you could give me just a basic outline of how that would be done and added to the DAQ process I'm using, I'm new to labview and still learning shift registers.  I looked at the example you suggested and I have attached my current DAQ process. Right now I'm sampling at 10 Hz and reading 10 samples at a time.  I want to be averaging 50 samples at a time (5 seconds worth of data), so using a shift register to buffer the data until 50 samples have been collected, average all 50 and discard all those points, and repeat. If you could at least point me in the right direction with where to put the shift register ie. do I need a new loop? Can I add it onto my data collection loop? I would really really appreciate it.

 

Kim

0 Kudos
Message 9 of 10
(3,197 Views)
Solution
Accepted by topic author Kim29290

Kim,

 

The simple, straightforward way is to put the shift register on the while loop with the read. Use the Analog Read with Array output rather than Waveform output.  Append the new data array to the old data array and wire it to the shift register.  This works but requires LV to frequently re-allocate memory space for the array.  The allocation process can cause programs to slow down or even crash as the array gets very large.

 

A better way is to use Initialize Array to allocate space for the largest array you will use and then use Replace Array subset inside the loop to put the data into the array.  The image below shows both methods. I used a Sine Pattern VI rather than the DAQmx Read because I do not have DAQmx available.

 

Shift registers.png

 

Lynn

0 Kudos
Message 10 of 10
(3,165 Views)