LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

running average of histogram

I am generating a new 1000 point histogram with each iteration of a loop.  I need to figure out the running average at each point in the histogram over 200 iterations without a 200 shift registers.  There are a few posts in this direction, but I can't seem to get the indexing right.  Can someone help me out?  thanks.  Jonathan
0 Kudos
Message 1 of 9
(3,888 Views)
All you need is a single shift register containing an 2D array of 200x1000 elements. Try it! 🙂


Message Edited by altenbach on 03-10-2008 05:23 PM
Message 2 of 9
(3,883 Views)
Thx, Altenbach. I guess I am having trouble creating and then maintaining the array (bump one out, put a new one in at each iteration).... what function do I need in the array tools? J
0 Kudos
Message 3 of 9
(3,877 Views)
What is your LabVIEW version?
 
Here's a quick&dirty draft for LabVIEW 8.5. It should give you some useful  ideas. 🙂
 
 
I can easily make you an 8.0 version. It's just a matter or replacing the "in place" structure with some other stuff.
Most likely, you are using the stock histogram tools, so you only need to look at the upper part of the diagram anyway. 🙂
 
 
 


Message Edited by altenbach on 03-10-2008 06:15 PM
Download All
Message 4 of 9
(3,871 Views)
Hi Altenbach,
even though I am not the one wiho asked i'd like to thank for the great example. Thats really helpful. One think I do not get is the sum, it seems you are adding over all rows and columns (i.e. all elements). How does the loop know just to sum up over one dimension of the 2-D array?
Cheers
Thomas
0 Kudos
Message 5 of 9
(3,841 Views)
You are probably talking about the small FOR loop.
 
If you autoindex a 2D array, you always get a row (1D) array in each iteration, starting with the first row until you run out of rows. Since we actually want to sum each column, we transpose the 2D array first and everything falls into place. 🙂
0 Kudos
Message 6 of 9
(3,837 Views)
Likewise, thanks.  Hopefully, your explanation will keep me off of the forum the next time I need to play with multidimensional data.  JonathanSmiley Happy
0 Kudos
Message 7 of 9
(3,830 Views)
Also the transposition is not needed, because you could e.g. add each of the histograms inside a shift register. There are many other ways to do this.
 
Note that with a bit more coding there are much smarter ways to do all that and in this case the task could be done with significanly less CPU effort. For example it is NOT necessary to add all spectra with each iteration, it is sufficient to add the newest and subtract the oldest trace from the sum of all histograms, which is probably 100x less work in this particular case. 🙂
 
Try it!
 
0 Kudos
Message 8 of 9
(3,821 Views)


altenbach wrote:
Note that with a bit more coding there are much smarter ways to do all that ...
Well, here it does not really matter, because both complete in well under 1ms, but here's a quick implementation of the above idea. Could be useful with larger datasets. We keep the sum of all rows in a second shift register and at each iteration we read the current histogram at that location (the oldest in the history!) before we overwrite it with the newest. Now we add the newest and subtract the oldest from the sum of all histograms and divide by the total number of histograms currently in it.
 
I am sure many improvements are possible. 🙂
 
I have not done any benchmarks.
 


Message Edited by altenbach on 03-11-2008 12:39 PM
Message 9 of 9
(3,817 Views)