LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rolling average of 1D arrays

Solved!
Go to solution

  

0 Kudos
Message 11 of 25
(2,302 Views)

Hi crossrulz and altenabch, 

 

Sorry for the slow resopnse.  I have spent the day trying to get the VI you included to work with no luck.  I have a few questions that you can answer(I think!).

 

1.  Is there a need to go from a 1D array to 2D array?  When I run the VI as part of my main program, I don't get anything on my display.  I don't think I need to do a 2D array, since I don't need to average in time.  

 

2.  I noticed in the case structure that every element is initialzed to 0.  This doens't make sense to me, although that may be due to my own lack of understanding.  

 

3.  I think a point by point average could work, but I don't see how to, for example, take 4 scans, average them, then dump the first scan but use the fifth scan as my fouth point, and so on (if that makes sense).  What do you think?  

 

Any other helpful hints would be appreciated.  Thanks do much for your help.  I will be working o n this all weekend so I'll check this thread regularly.  

0 Kudos
Message 12 of 25
(2,290 Views)

You need the 2D array if you want to average the last few 1D traces. Now you say you don't want to average in time. So what is it?

 

How do you run your main VI? For example if you would use "continuous run" instead of using a proper outer while loop, the "first call?" primitive would always be true, resetting the history.

 

Please attach a simplified version of your VI (e.g. using simulated data) to show what you are doing.

 

Now you say that you want to average the last four scans. If a "scan" is a 1D array, you are averaging in time, right? The arrays arrive after each other.

 

Tim's code uses a fixed size 2D array with four rows to keep the last four scans, overwriting the oldest once more than four scans are acquired and averaging the four whenever the array changes. This keeps the last four scans in memory.

 

 

0 Kudos
Message 13 of 25
(2,282 Views)

Hi altenbach, 

 

The meaurement is a mass spectrum, so it is a voltage spike at a constant time.  I am in the early phases of this instruemnt, so my choice molecule only gives a single peak at one flight time, making it easier to write softrware for.  

 

My acquisition VI has many custom VI's from the digitial oscilloscope company (Pico Technology in the UK).  I use the PicoScope for data collection from my mass spectrometer, which is a simple voltage signal as a fuction of time.  The experiment runs at 10 Hz, and the voltage vs. time signal from the detector is displayed in real time on the VI's front panel, as you would see it on a physical oscilloscope.  There is an option to collect up to 32767 mass spectra and average them all into a single file, then write it to a spreadsheet.  The VI I wrote works perfectly as is, but I wanted to incorporate an averaging fesature akinm to that which you would find on a actual o-scope, which is a point-by-point average.  

 

There are two 1D array streams which are plotted in a waveform plot: the time values (which come from a custom VI) and the voltages, which are read in from the PicoScope's internal memory buffer.  I have tried (in vain the last few days) to write a for loop which takes the continuously acquired (10 Hz) mass spectrum, then use TIm's code to take 4 shot continuous averages.  

 

I have included the two most recent iterations of my VI (written in LV 14 and it includes variants of Tim's code) as well as the sub-VI which give the time values.  There are many manufacturer specific VIs, so you may not be able to use it.  The loop in question is at the bottom of the main stack sequence.  I have included pictures of the VI in various spots so you can see what I am talking about.  Thanks for all the help.  

 

 

Joe

0 Kudos
Message 14 of 25
(2,262 Views)

 And here are the photos of the VI so you can see the location of the manufacturer's VIs.  

0 Kudos
Message 15 of 25
(2,260 Views)

Hi altenbach and crossrulz,

 

Thanks very much for the help.  I struggled with this all weekend at home and was not able to come up with a solution which works.  If you get a change, could you please take a look at the VIs and pictures?  I am very appreciative for any suggestions/hints and help you can provide.  Thanks again.  

 

If I have any stroke of luck I'll post it here immediately.  

 

 

Joe

0 Kudos
Message 16 of 25
(2,196 Views)

The array shift regsiter belongs in the outer while loop, then use basically Tim's code. Remove the inner FOR loop.

 

Here's a very rough draft, replacing your acquisition with simulated data, because I don't have your hardware and missing subVIs.

 

If you want to be able to change the number of points and other acquisition parameters during the run, you need to add some logic to reset the array whenever that happens. Not shown.

0 Kudos
Message 17 of 25
(2,173 Views)

Look at "lossy queues" as a method to store the data.  They greatly simplify array storage.

CLA
0 Kudos
Message 18 of 25
(2,153 Views)
Can you be more specific?
0 Kudos
Message 19 of 25
(2,132 Views)

Hi Christian, 

 

First off, thank you for the modified VI  It is a nice tool for me to use and play with as work my way through this.  

 

I took your advice and I used a combination of the array shift register from your VI and bits of Tim's VI to make what I think I need.  I ran it using a constant square wave from the PicoScope, and it was displaying a waveform fine.  When I went toi adjust the array dimesins from the shift register from 1 (where I had put it for tesing with no averaging) to 10, I noticed that it simply divided the Y axis (voltage) by 10 and wasn't actually averaging!  I playted around for a while and I think it has something to do with the quotient and remainder being usedd in the feedback loop.  

 

I have inlcuded the current version of my VI.  I'm sure it's a dumb mistake, but if you could take a look and let me know what you think I'd be very appreciative.  Thanks again for helping me with this stubborn issue!

 

 

 

 

Joe

0 Kudos
Message 20 of 25
(2,110 Views)