From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running Average of waveform signal

Solved!
Go to solution

Hi,

 

I am testing a product that is to be cycled between being pressurized and depressurized with water.  During the depressurized portions of the test, a valve is open to relieve the product and I am suppose to measure the flow rate of water coming out of the product and record the average flow rate during that cycle.  I have been banging my head on this for a while so hopefully some one can offer some help.

 

I created a functional global variable that takes the pressure waveform as an input and there is a case for setting the flow and average flow rate, getting and resetting the values.  

 

I am calling this FGV during the time the valve is open. So far, the value I get does not equate to the running average of the flow.

 

Thanks for the help!

0 Kudos
Message 1 of 4
(2,806 Views)

I'm not entirely sure what you're trying to do, but your FGV is only returning the average of the Waveform input each time it's called. It's not keeping track of previous calls.

 

I think your issue is that you keep using Index Array for reasons I don't follow. That just takes the first element out of the array. This means your Avg Flow output will always return the first value of your Mean function. You COULD get the *last* value of the array, but that's still just going to be the average for that particular waveform sample.

 

Notice in your code you're never using the data you're storing in the topmost shift register- you add stuff to it, but it's never read. The Index Array function returns just the first value every time, and the rest is never used.

0 Kudos
Message 2 of 4
(2,785 Views)

I should have been more clear in my original post.  All I that is going to happen is a valve is going to open and close.  When the valve opens, water will start flowing until the valve closes again.  I just want to take the average flow between the time the water starts flowing to when it stops flowing.

0 Kudos
Message 3 of 4
(2,763 Views)
Solution
Accepted by topic author ANON12345

Averages look backward in time -- you need to have the data "in hand" before you can average it.  If you have a finite sample of data and want to know its average, as soon as you have all the data, average it (add it all up and divide by the number of points, or if the data are in an array, call the "Mean" function to return the average).  If you want a "running average" (as mentioned in the title of this Message), figure out over how many points you want to average (let's say 10, for example), then once you have that many points, start the following algorithm:

  1. Take the average of the N points.  This is the first point of your running average, which is "delayed" by N samples (because you need to wait until you have N points).
  2. When you take the next point, throw out the "oldest" point and add the new point so you have the "latest N Points", and return to step 1.

If you've done signal averaging and know about digital filters, you might recognized that the Moving Average is a type of Low Pass filter (it's an interesting exercise to compute its Frequency Response and to determine its corner frequency, not surprisingly related to both the Sampling Frequency and N, the number of points in the average).

 

You can implement the Running Average using a Circular Buffer (a finite array where the input index is computed Modulo N) or a Finite Lossy Queue.  There's also possibly a Point-by-Point function in LabVIEW that does this (I don't use them much, but other Forum Readers know about them ...).

 

Bob Schor

Message 4 of 4
(2,739 Views)