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

Filter data with a sample-and-hold filter.

Pascal
procedure SampleAndHoldFilter(Data: TVec; var State: TSampleAndHoldState; Hold: integer);

Filter Data with a non-linear sample-and-hold filter. The current value is held until a bigger is found or time-out occurs. Time out is defined in samples with Hold parameter. The filter features streaming support via the State variable. Data can be real or complex. The State variable has to be initialized with zeros before it is passed to the routine for the first time.

SampleAndHoldFilter example on a sine. 

 

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

    procedure TForm1.Button1Click(Sender: TObject);
    var b,c: Vector;
        n,i: integer;
        State: TSampleAndHoldState;
    begin
        Tone(b,300,5.0/300,0,1);
        c.Copy(b);
        n := 10;
        for i := 0 to b.Length div n-1 do
        begin
            b.SetSubRange(i*n,n);
            SampleAndHoldFilter(b,State,7);
        end;
        b.SetFullRange;
        DrawIt([c,b],['Unfiltered','Filtered']);
    end;

 

    #include "MtxExpr.hpp"
    #include "MtxVecEdit.hpp"
    #include "MtxVecTee.hpp"
    #include "SignalUtils.hpp"

    void __fastcall TForm1::BitBtn1Click(TObject *Sender)
    {
        sVector b,c;
        int n,i;
        TSampleAndHoldState State;

        Tone(b,300,5.0/300,0,1); //generate sine with 5 periods in 300 samples

        c = b;
        n = 10;
        for (i = 0; i < (b.Length/n); i++)  //Streaming test 1
        {
          SampleAndHoldFilter(b(i*n,i*n+n-1),State,7);
        }

        DrawIt(OPENARRAY(TVec*,(c,b)),OPENARRAY(AnsiString,("Unfiltered","Filtered")));
    }
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!