LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

rolling 2D array with a max size

Solved!
Go to solution

HI,

 

I have some equipment that continuously spits out data at 100Hz, it is 24bit ADC values across 32 channels.  This needs to be shown on a graph with a button to click to capture some of the data and perform some statistics.  The spec given to me  says i need to collect 64 data samples and then perform calculations on them. I  can feed the raw data straight to a graph that is fine but i don't want to continuously filling up an array with this data as i guess it wont take long before the memory if affected.  So i was thinking of using a rolling array with a max size of 64 rows by 32 columns, the first 64 loops will be filling the array up.  After that it will delete the first row and add the next sample of data to the end, this way the array never grows.  i thought this should be a simple task but i am really struggling to get it work.  i have created an example of what want to do with a 1D array. just need to change it to a 2D?

 

does anyone know how to do this? or suggest a simpler way, i may have just chosen the wrong method.

Regards        

0 Kudos
Message 1 of 18
(3,214 Views)

Hi Dave,

 

instead of constantly adding and deleting columns from the 2D array you might also initialize the array as 64×32 elements and replace columns. (Handling the array all "in place"…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 18
(3,196 Views)

Pretty much want a circular buffer does.

 

Allocate the data, keep a pointer to the data to replace. When you get the data, get the part before and if it 'rotated' at least once, the part after the pointer, and concatenate them (after part before the before part).

 

This is fast for adding, slow for getting the data.

 

There's an alternative that is more memory hungry but faster for reading. Allocate twice the size you want, and when you insert data, insert it twice. Once at rem(count, size) and once at rem(count,size)+size. Then when reading the data, get the data from rem(count, size) - size to rem(count, size).

 

This is faster to read, slower when adding, and more memory hungry.

Message 3 of 18
(3,152 Views)

Would "rolling" the index work? IE a circular buffer.

Something like this.

image.png

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
0 Kudos
Message 4 of 18
(3,140 Views)

Weibe,

 

What function are you referring to when you mention "rem( )"?

0 Kudos
Message 5 of 18
(3,135 Views)

Hi RavensFan,

 

it's remainder(), the upper output of Q&R…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 18
(3,127 Views)

@GerdW wrote:

Hi RavensFan,

 

it's remainder(), the upper output of Q&R…


It is. AKA %, as in "remainder = iteration % size". Not sure if rem() is used at all, sorry about that.

 

When using Quotient & Remainder, the R will give the pointer conveniently, and if you store the iteration in a U64, the Q will indicate if there has been a wrap, if it's >0. Easier that maintaining a Boolean in a shift register.

0 Kudos
Message 7 of 18
(3,123 Views)

Thanks.  I don't know if rem() is something from C or another text based language.  It got me thinking of REM as in remark in BASIC days.

0 Kudos
Message 8 of 18
(3,111 Views)
Solution
Accepted by Dave76

Here's what I would do (you can also use a transposed array depending on the calculations needed later, just replace rows instead of columns. Whatever fits best).

 

2Dbuffer.png

 

 

0 Kudos
Message 9 of 18
(3,108 Views)

Yep... that is what I said (but not with as much details. 🙂 )

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
0 Kudos
Message 10 of 18
(3,104 Views)