SignalUtils.SavGolayImpulse Method

Overload List

#SignatureDescription
1procedure SavGolayImpulse(const H: TMtx; const Diff: TMtx; FrameSize: Integer; Order: Integer; const Weights: TVec);Design a Savitzky-Golay polynomial smoothing filter.
2procedure SavGolayImpulse(const H: TVec; FrameSize: Integer; Order: Integer; const Weights: TVec);The resulting H vector contains FIR type impulse response, which can be passed to the FirInit routine.

Overload 1: procedure SavGolayImpulse(const H: TMtx; const Diff: TMtx; FrameSize: Integer; Order: Integer; const Weights: TVec);

Design a Savitzky-Golay polynomial smoothing filter.

#NameTypeDescription
1HTMtx
2DiffTMtx
3FrameSizeInteger
4OrderInteger
5WeightsTVec

Result: stored in self (calling object)

Remarks:

Compute a Savitzky-Golay polynomial smoothing filter: a polynomial of degree Order is least-squares fitted to each FrameSize-long window of the signal. H is sized FrameSize x FrameSize; row i holds the filter producing the fitted value at window position i. Only the center row of H is used for filtering the signal interior, the upper and lower rows of H are applied to the transition regions where the signal starts and stops (see SignalUtils.SavGolayFilter). Diff is sized (Order+1) x FrameSize; row k recovers the coefficient of x^k of the fitted polynomial, with x counted in samples relative to the window center, so row 1 is the first-derivative filter.

Weights, when assigned, must hold FrameSize strictly positive values and the fit minimizes the weighted sum of squares; H is then not symmetric. An exception is raised if FrameSize is not odd, if Order is not in [0, FrameSize-1], or if Weights are present with wrong length, non-positive values or a precision different from H. The computation runs in the precision of H.

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

procedure TForm1.Button1Click(Sender: TObject);
var H,D: Matrix;
Data, Data1: Vector;
Frs,Ord: integer;
begin
    Data.Size(100);
    Data.RandGauss;
    Data1.Copy(Data);
    Frs := 10;
    if not Odd(Frs) then Inc(Frs);
    Ord := 5;
    SavGolayImpulse(H,D,Frs,Ord,nil);   //single block processing
    SavGolayFilter(Data,H);
    DrawIt([Data,Data1],['Filtered data','Original data']);
end;

Overload 2: procedure SavGolayImpulse(const H: TVec; FrameSize: Integer; Order: Integer; const Weights: TVec);

The resulting H vector contains FIR type impulse response, which can be passed to the FirInit routine.

#NameTypeDescription
1HTVec
2FrameSizeInteger
3OrderInteger
4WeightsTVec

Result: stored in self (calling object)

Remarks:

Returns the center row of the Savitzky-Golay smoothing matrix: the FIR filter fitting a polynomial of degree Order to each FrameSize-long window and evaluating it at the window center. Optional Weights (FrameSize strictly positive values, same precision as H) select a weighted least-squares fit.

Examples
procedure TForm1.Button1Click(Sender: TObject);
var h,b,c: Vector;
n,i: integer;
State: TFirState;
begin
    SavGolayImpulse(h,15,7);
    FirInit(h,State);
    try
        b := Ramp(300, mvDouble, 0,0.1);
        c.Size(b);
        n := 10;
        for i := 0 to (b.Length div n) - 1 do
    begin
        b.SetSubRange(i*n,n);
        c.SetSubRange(i*n,n);
        FirFilter(b,c,State);
    end;
    b.SetFullRange;
    c.SetFullRange;
    DrawIt([b,c],['Filtered data','Original data']);
finally
    FirFree(State);
end;
end;
See Also: SignalUtils.FirFilter, SignalUtils.FirFree, SignalUtils.FirInit, SignalUtils.SavGolayFilter