LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Averaging waveforms with dynamic data and express VIs

Hello masters and gurus of Labview 2012,

I am asking a common question that I know everyone loves to read about, however, I am having some issues with it despite reading the existing literature in the developer zone.

What I am trying to do is average N waveforms that are being collected by a PXI-5152 digitizer. My setup is that I receive 20 waveforms per second with 4000 samples per waveform.

I decided to use the express VIs to do this since it was easier than trying to code everything up from scratch. I have the dynamic waveform data coming into a graph which is displaying single waveforms correctly. I want to average N incoming waveforms acquired by the digitizer and then send that data to a second graph which displays it alongside the first graph. I would like to be able to change the number of averages I have by using a control like in my uploaded program.

My current program does take an average based upon how many averages I set, unfortunately, the graph only updates when the for loop finishes. If I set the graph inside the for loop, I get a similarly undesirable situation where it averages, but then when the for loop ends it repeats and starts the graph over again. (which also makes sense)

What I would like is to be able to have functionality like a hardware oscilloscope where I can set 16 averages (or an arbitrary number) and the waveform will show up averaging the last sixteen waveforms. In a typical hardware scope when the graph has not acquired sixteen averages the graph shows up anyway and updates every time a new waveform is added to the queue until it gets to sixteen and then adds waveforms one at a time to update the waveform average.

I've read lots of information about shift registers, circular buffers, arrays, case structures and the like, but I'm new to labview, so I'm a bit confused as to how to accomplish this goal with the previous components.

Help me Ni-wan Kenobi, you're my only hope.

If you need any other information feel free to ask me for it and I'll provide it as soon as possible.

0 Kudos
Message 1 of 6
(5,125 Views)

You should be dividing by i, not N.  Then you can put the average graph inside of the FOR loop.


GCentral
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 2 of 6
(5,103 Views)

Crossrulz,

I tried that (file attached), but the problem is that the waveform refreshes everytime the loop ends (I understand why this happens, I just don't want it to happen) still remains. Any idea how to do this program differently so that I could get the last N waveforms averaged together without having the graph restart the average since it's in a for loop? I would guess that I shouldn't be using a for loop to do this. I tried to do a case structure where when the loop ended I could change the case structure from the inside to a new loop that would add one waveform, but apparently I cannot do that from the inside of the structure.

0 Kudos
Message 3 of 6
(5,089 Views)

Hi bravedonxiote,

 

There may be many ways to accomplish this task. If you plan to keep using for loops, you can use auto indexing with the loop. More information about auto indexing can be found at the Auto-Indexing Array Inputs section in the Data Types and Structures Developer Zone article. An example of how I used auto indexing to get the average of 16 one dimensional arrays is shown below.

 

averaging

 

The attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject to the Sample Code License Terms which can be found at:

http://ni.com/samplecodelicense 

Tunde S.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 6
(5,058 Views)

Tunde_S, I tried the algorithm you suggest, however, I don't think this is what I'm looking for. Your program seems to simply display a waveform so that when I change the values it displays them on a waveform graph. (Not exactly sure what the "averaging" does in this case)

What I'm looking for is this:

I would like to acquire an arbitrary number of waveforms from my PXI-5152. The waveforms will be obtained one at a time by the PXI every time the laser fires and creates an acoustic wave which is detected by my ultrasonic microphone. I would like to average, let's say 16 waveforms, together from the last 16 laser pulses/acoustic wave detections. So essentially I need to average 16 1-dimensional Y waveforms together and form that into one signal.
  
I have had some "limited" success with this using shift registers as in the attachment below. The drawback to my program is that it relies on shift registers which although does indeed average the last four waveforms together, I cannot change the number of averages without programmatically changing the number of shift registers. How can I change the attached program to average an arbitrary number of 1-dimensional Y valued waveforms together?

0 Kudos
Message 5 of 6
(5,024 Views)

You can use a shift register to store a 2-dimensional array of the last 16 1-dimensional arrays that you want to average. The code snippet below shows how I initialized an array to store N records, how I updated the index to the column that contains the oldest record, how I replaced the oldest record with the new record, and how I averaged each row of the 2D array.

 

average_example2.png

 

The attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject to the Sample Code License Terms which can be found at:

http://ni.com/samplecodelicense 

Tunde S.
Applications Engineer
National Instruments
0 Kudos
Message 6 of 6
(5,002 Views)