SignalUtils.ExpAverageFilter Method

Overload List

#SignatureDescription
1procedure ExpAverageFilter(Data: TVec; var State: TCplx; Decay: Double);Filter data with an exponential average filter.
2procedure ExpAverageFilter(Data: TVec; var State: Double; Decay: Double);Filter data with an exponential average filter.
3procedure ExpAverageFilter(Decay: Double; Num: TVec; Den: TVec);Design an exponential filter with Decay parameter and place the transfer function in Num (numerator) and Den (denominator).
4function ExpAverageFilter(const Data: Double; var State: Double; Decay: Double): Double;Filter data with an exponential averaging filter.

Overload 1: procedure ExpAverageFilter(Data: TVec; var State: TCplx; Decay: Double);

Filter data with an exponential average filter.

#NameTypeDescription
1DataTVecsource TVec
2StateTCplx
3DecayDoublescalar

Result: stored in self (calling object)

Remarks:

Exponential average filter without the TIirState structure for complex data.

Overload 2: procedure ExpAverageFilter(Data: TVec; var State: Double; Decay: Double);

Filter data with an exponential average filter.

#NameTypeDescription
1DataTVecsource TVec
2StateDouble
3DecayDoublescalar

Result: stored in self (calling object)

Remarks:

Exponential average filter without the TIirState structure. The function can be called to filter sample by sample. Initialize the State to 0 on the first call. Decay defines the decay from sample to sample and is initialized to 50% by default. With each new sample, the filter will take average from the 50% of the new sample and 50% of the previous average. The exponential average filter implements the following difference equation:

y[i] = 1/d * x[i] + (d-1)/d * y[i-1]

x.. input signal
y.. output signal
d.. Decay factor

In terms of percentage:

y[i] = a * x[i] + b * y[i-1] ,   a + b = 1

a*100 ... percent of the new data used.
b*100 ... percent of the old average used to compute the new average.
Examples
uses MtxExpr, Math387, MtxVec, SignalUtils, MtxVecTee, MtxVecEdit,OptimalFir;

procedure TForm1.Button1Click(Sender: TObject);
var b,c,num,den: Vector;
n,i: integer;
IirState: TIirState;
State: double;
begin
    //Alternative 1: Tone with 5 periods
    //      b := Math387.Sin(Ramp(300,mvDouble, 0,2*Pi*5/300));

    //Alternative 2: Gaussian noise
    b := RandGauss(300);
    c.Copy(b);
    n := 10;
    State := 0;
    for i := 0 to (b.Length div n) - 1 do //streaming test 1
begin
    b.SetSubRange(i*n,n);
    ExpAverageFilter(b,State,10); //set to 10%
end;
b.SetFullRange;
DrawIt([c,b],['Unfiltered','Filtered']);

b.Copy(c);
ExpAverageFilter(10,num,den); //set to 10x, (1/10 = 0.1, => 10%)
FillChar(IirState,SizeOf(IirState),0);

IirInit(Num,Den,IirState);
for i := 0 to (b.Length div n) - 1 do //streaming test 2
begin
    b.SetSubRange(i*n,n);
    c.SetSubRange(i*n,n);
    IirFilter(b,c,IirState);
end;
IirFree(IirState);
b.SetFullRange;
c.SetFullRange;
DrawIt([b,c],['Unfiltered','Filtered']);
end;

Overload 3: procedure ExpAverageFilter(Decay: Double; Num: TVec; Den: TVec);

Design an exponential filter with Decay parameter and place the transfer function in Num (numerator) and Den (denominator).

#NameTypeDescription
1DecayDoublescalar
2NumTVecsource TVec
3DenTVecsource TVec

Result: stored in self (calling object)

Remarks:

Transfer function can be used to initialize an IIR filter by passing num and den to the IirInit routine.

See Also: SignalUtils.MovingAverageImpulse, SignalUtils.FirFilter, SignalUtils.KaiserImpulse, OptimalFir.RemezImpulse

Overload 4: function ExpAverageFilter(const Data: Double; var State: Double; Decay: Double): Double;

Filter data with an exponential averaging filter.

#NameTypeDescription
1DataDouble
2StateDouble
3DecayDoublescalar

Returns: Double

Remarks:

Single sample non-vectorized variant of the exponential averaging.