News:

  • October 10, 2026, 03:34:28 PM

Login with username, password and session length

Author Topic: AVGR of Array  (Read 7187 times)

Bolt

  • Hero Member
  • *****
  • Posts: 598
AVGR of Array
« on: June 24, 2020, 11:43:08 AM »
Is there a way to do a AVGR (or SUMR) of an array with a pointer that wraps around?

For example:
Array of R0-R511
Pointer V0, incremented via (V0+1) & 0x1FF
Sample Size of V1

AVGR(R[V0], V1) should work, until the pointer wraps around.  Any easy work arounds?

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: AVGR of Array
« Reply #1 on: June 24, 2020, 11:45:35 AM »
Perhaps move the values in question to another array, and then do the AVGR on it?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3848
    • Host Engineering
Re: AVGR of Array
« Reply #2 on: June 24, 2020, 01:06:18 PM »
Just do 1 or optionally 2 SUMRs, then divide by the count (does not handle the case of 0 data points, gotta have at least 1)
Code: [Select]
STRLE Start End  // normal non-wrap-around case, Start <= End
MATH Count "End+1-Start"  // e.g. Start of 5 and End of 6 yields Count of 2
MATH Avg "SUMR(R[Start], Count) / Count"  // you could just do AVGR here since this is the non-wrap case
NOT // else, Start > End, hence data is wrapping
MATH TempCountTop "End+1"  // if End is 0, TempCountTop will be 1, which is what we want
MATH SumTop "SUMR(R0, TempCountTop)"  // summation of top part of wrap
MATH TempCountBottom "DataSize-Start"  // DataSize would be 512, so wrap-around Start of 511 (R511, last one) would result in TempCountBottom equaling 1, which is what we want
MATH SumBottom "SUMR(R[Start], TempCountBottom)"  // summation of bottom part of wrap
MATH Avg "(SumTop + SumBottom) / (TempCountTop + TempCountBottom)"
« Last Edit: June 24, 2020, 01:15:56 PM by franji1 »

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: AVGR of Array
« Reply #3 on: June 24, 2020, 01:59:44 PM »
Very nice, thank you sir!