03-07-2012 01:49 PM - edited 03-07-2012 01:50 PM
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.
Solved! Go to Solution.
03-07-2012 07:51 PM
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
03-08-2012 04:05 AM
03-08-2012 09:01 AM
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.
03-08-2012 09:05 AM
With the slow data rate and small numbers of samples everything should be fairly easy.
Lynn
03-08-2012 12:06 PM
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....
03-08-2012 12:14 PM
03-16-2012 08:23 PM
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.
03-23-2012 11:14 AM
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
03-28-2012 04:26 PM
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.
Lynn