Differentiation Buffer with Delphi

I periodically get a data buffer that contains a series of values ​​that are a fixed distance in time. I need to distinguish them. This is a very long time since I was calculating at school ....

I came up with the following:

function DifferentiateBuffer(
  ABuffer: TDoubleDynArray; AVPS: integer): TDoubleDynArray;
var
  i: integer;
  dt, dy: double;
begin
  if (AVPS = 0) then exit;

  // calc the delta time
  dt := 1 / AVPS;

  // run through the whole buffer
  for i := 0 to high(ABuffer) do begin
    if (i = 0) then
      if (IsNan(FLastDiffValue) = false) then
        dy := ABuffer[0] - FLastDiffValue
      else
        dy := ABuffer[0]
    else
      dy := Abuffer[i] - ABuffer[i -1];

    result[i] := dy / dt
  end;

  // remember the last value for next time
  FLastDiffValue := ABuffer[high(ABuffer)];
end;

AVPS are values ​​per second. A typical value for this should be from 10 to 100. The length of the buffers is usually from 500 to 1000 values.

I call the buffer from time to time with new data that is continuous with the previous data block, therefore saving the last value of the block the next time. This last value is set in the NAN in the constructor.

Is this what I did right? those. will it differentiate values ​​correctly?

I also need to integrate similar data ... what might it look like?

+4
1

.

, (ABuffer[0] - 0.0) / dt, , . , , .

, , . , . , DUnitX. , . , y = x 2 y = sin (x).

, . . , , - . , , .

, = false = true. if , . :

if not IsNan(FLastDiffValue) then
  dy := ABuffer[0] - FLastDiffValue
else
  dy := ABuffer[0]

:

if IsNan(FLastDiffValue) then
  dy := ABuffer[0]
else
  dy := ABuffer[0] - FLastDiffValue
+4

All Articles