01-12-2015 01:53 PM - edited 01-12-2015 01:59 PM
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.
01-12-2015 02:05 PM - edited 01-12-2015 02:05 PM
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)
01-12-2015 02:19 PM - edited 01-12-2015 02:23 PM
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.
01-14-2015 03:59 PM
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
01-26-2015 11:51 AM - edited 01-26-2015 11:52 AM
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.
01-26-2015 12:00 PM - edited 01-26-2015 12:06 PM
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.)
01-26-2015 04:38 PM
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.
01-26-2015 06:30 PM
You only get anything out of the FOR loop once 1000000 iterations have passed. Did you wait that long?
01-28-2015 12:06 PM
Are you serious? I obviously change the number of averages to something much more reasonable.
01-28-2015 12:39 PM