From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

How do I plot an exponential average of a 1D array?

I'm capturing a 32,768 point array of data from a digitizer in my PC, and I want to be able to average n number of these arrays with a exponential average. (e.g. if n=30, I would plot the average of the previous 30 arrays of data, and then continue to average excepts now applies a weight to "old" arrays which would gradually tend to zero.) I had this function in an old Lecroy 9350 oscilloscope, and it's referred to there as  a "Continuous" Average. 

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

You would keep a 32768 x 30 2D array in a shift register and replace the olders row with the newest data (keeping track of the insert point) Also keep a 1D array (size 30) containing the weighting. Muliply the entire weighting array by e.g. 0.9 (or some other factor <1) and then replace the oldest value by 1 at the insert point. Multiply each row of the 2D array the the weighting array then take the average.

 

...or similar. 😄

 

(For performance reasons, make sure to operate in-place, so don't use delete from array/insert into array and such, even if the code seems simpler)

 

Message 2 of 10
(3,199 Views)

What I consider to be an exponential average does not require you to hold on to n arrays (that is the advantage of an exponential average over a running average).

 

What you do instead is choose the weight by the number of averages you have taken so far with a limit set by n.

 

for example:

 

degree = 1

loop over new values

 new average = [(degree - 1) * old average + new value]/degree

 degree = min(++degree,n)

 

first time : new average = new value

next time : new aveage = 1/2(old average + new value)

...

eventually

new average = [(n-1)*old average + new value]/n

 

This way the exponential average builds up to the limit of n.

Message 3 of 10
(3,190 Views)

Hello devriesucsb,

 

Since you are looking to duplicate the continuous averaging math function on the older scope, I have attached an image from the TeledyenLeCroy Oscilloscope manual for the newer models that explains the function.

 

I have to say, I like "altenbach's" solution as well. He seems to have a grasp on what you are doing.

 

I am not sure I would call this "exponential" averaging, but it does have a weight that decays exponentially.

 

That said, here is the "formula" from the manual (more details are in the image)

 

new average = (new data + weight * old average)/(weight +1)

 

I hope this helps!

 

Cheers,

 

Leonard Brown
Applications Engineer
Teledyne LeCroy
1-800-553-2769

 

Message 4 of 10
(3,117 Views)

Sorry about the delay, and thanks for the great advice.

 

I've attached a screenshot here of my block diagram. I have two problems now:

 

1) there are multiple traces on my plot when there should only by one(see attached screenshot #2)

 

2) it still doesn't seem to be doing continuous averaging correctly. I'm running this experiment and triggering my scope at 10Hz, but the data I'm seeing plotted is only updating every second or two.In addition, there seems to be no memory of the old shots. Say for example I set the # of averages to 50, and then block the signal to the scope-I don't see the trace gradually trent back to zero. Instead, it immediately drops to zero. Hopefully this all makes sense, and thanks again for the help. 

Download All
0 Kudos
Message 5 of 10
(3,023 Views)

Use the loop output from the right shift register, not an autoindexing output tunnel. Still, your code makes very little sense.

 

(Pleasre attach your VI instead of pictures. Thanks.)

0 Kudos
Message 6 of 10
(3,007 Views)

Here is the VI. When I try to use the loop output from the right shift register, I can't get anything to show up in my plots. Thanks again for the help. 

0 Kudos
Message 7 of 10
(2,974 Views)

You only get anything out of the FOR loop once 1000000 iterations have passed. Did you wait that long?

0 Kudos
Message 8 of 10
(2,956 Views)

Are you serious? I obviously change the number of averages to something much more reasonable. 

0 Kudos
Message 9 of 10
(2,915 Views)
Well, if controls have a non-default default value, I typically take it seriously :D.
0 Kudos
Message 10 of 10
(2,909 Views)