You are here: Symbol Reference > SignalUtils Namespace > Functions > SignalUtils.Integrate Function
DSP Master VCL
ContentsIndex
Example

Single block and streaming application example: 

 

uses MtxExpr, Math387, MtxVec, SignalUtils, MtxVecTee, MtxVecEdit;

procedure TForm1.Button1Click(Sender: TObject);
var b,c,h: Vector;
    n,i: integer;
    FS: double;
    State2: TIntegrateState;
    State: TDiffState;
begin
    h := Ramp(30, mvDouble, 0,1);
    b.Size(h);
    c.Size(h);
    FS := 1; //sampling frequency

//single block

    FillChar(State,sizeOf(State),0); //initial conditions to zero
    FillChar(State2,sizeOf(State2),0);
    Integrate(h, b, State2, 1/FS);
    Differentiate(b, c, State, 1/FS);
    Drawit(c);

//streaming

    FillChar(State,sizeOf(State),0);  //initial conditions to zero
    FillChar(State2,sizeOf(State2),0);
    n := h.Length div 10;
    for i := 0 to 10-1 do
    begin
        h.SetSubRange(i*n,n);
        b.SetSubRange(i*n,n);
        c.SetSubRange(i*n,n);
        Integrate(h,b, State2, 1/FS);

//            Should be:  b = [0 , 1 , 3, 6, 10, 15, 21,... ]
//            But becomes: b = [0, 0.1666, 1.1666, 3.166, 6.166, 10.166, 15.166, 21.166,... ]
//            because of Simpson

        Differentiate(b,c,State,1/FS);

//            Should be: c = [0,1,2,3,4,5,6....]
//            But becomes: c = [0, 0.08333, 0.5833, 1.5, 2.5, 3.5, 4.5....]

    end;
    c.SetFullRange;
    DrawIt(c);
end;

 

    #include "MtxExpr.hpp"
    #include "MtxVecEdit.hpp"
    #include "MtxVecTee.hpp"
    #include "SignalUtils.hpp"
    #include <string.h>

    void __fastcall TForm41::BitBtn1Click(TObject *Sender)
    {
      int n,i;
      double FS;
      TIntegrateState State2;
      TDiffState State;
      sVector b,c,h;

      h = Ramp(30,mvDouble,0,1);
      b.Size(h);
      c.Size(h);
      FS = 1; //sampling frequency

    //single block
      memset(&State,0,sizeof(State)); //initial conditions to zero
      memset(&State2,0,sizeof(State2));

      Integrate(h, b, State2, 1/FS);
      Differentiate(b, c, State, 1/FS);

      DrawIt(c);

    //streaming

      memset(&State,0,sizeof(State)); //initial conditions to zero
      memset(&State2,0,sizeof(State2));

        n = h.Length/10;
      for (i = 0; i < 10; i++)
      {
    //      h.SetSubRange(i*n,n);
    //      b.SetSubRange(i*n,n);
    //      c.SetSubRange(i*n,n);

        Integrate(h(i*n,i*n+n-1),b(i*n,i*n+n-1), State2, 1/FS);

    //            Should be:  b = [0 , 1 , 3, 6, 10, 15, 21,... ]
    //            But becomes: b = [0, 0.1666, 1.1666, 3.166, 6.166, 10.166, 15.166, 21.166,... ]
    //            because of Simpson

        Differentiate(b(i*n,i*n+n-1),c(i*n,i*n+n-1),State,1/FS);

    //            Should be: c = [0,1,2,3,4,5,6....]
    //            But becomes: c = [0, 0.08333, 0.5833, 1.5, 2.5, 3.5, 4.5....]

      }
      c.SetFullRange(); //subranges were passed by reference!!
      DrawIt(c);
    }
Copyright (c) 1999-2025 by Dew Research. All rights reserved.