08-02-2019 06:46 AM
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
Solved! Go to Solution.
08-02-2019 07:01 AM
08-02-2019 08:38 AM
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.
08-02-2019 08:50 AM
Would "rolling" the index work? IE a circular buffer.
Something like this.
08-02-2019 08:51 AM
Weibe,
What function are you referring to when you mention "rem( )"?
08-02-2019 09:02 AM
08-02-2019 09:10 AM - edited 08-02-2019 09:13 AM
@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.
08-02-2019 09:28 AM
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.
08-02-2019 09:32 AM
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).
08-02-2019 09:42 AM
Yep... that is what I said (but not with as much details. 🙂 )