SignalUtils.ExpAverageFilter Method

Overload List

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

Overload 1: void ExpAverageFilter(TVec Data, ref TCplx State, Double Decay)

Filter data with an exponential average filter.

#NameTypeDescription
1DataTVecsource TVec
2StateTCplx (ref)output
3DecayDoublescalar

Result: stored in self (calling object)

Remarks:

Exponential average filter without the TIirState structure for complex data.

Overload 2: void ExpAverageFilter(TVec Data, ref Double State, Double Decay)

Filter data with an exponential average filter.

#NameTypeDescription
1DataTVecsource TVec
2StateDouble (ref)output
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.

Overload 3: void ExpAverageFilter(Double Decay, TVec Num, TVec Den)

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.

Examples
using Dew.Math;
    using Dew.Math.Editors;
    using Dew.Math.Units;
    using Dew.Signal;
    using Dew.Signal.Units;
    using Dew.Math.Tee;
    using Dew.Signal.Tee;


    private void button1_Click(object sender, EventArgs e)
    {
        Vector b;
        Vector c = new Vector(0);
        Vector num = new Vector(0);
        Vector den = new Vector(0);

        int n;
        int i;

        TIirState IirState = new TIirState();
        double state;

//Alternative 1: Tone with 5 periods
//      b := Math387.Sin(Ramp(300, mvDouble, 0,2*Pi*5/300));

//Alternative 2: Gaussian noise
    b = MtxExpr.RandGauss(300,false);
    c.Copy(b);
    n = 10;
    state = 0;
    int bLength = b.Length;
    for (i = 0; i < (bLength / n); i ++) //streaming test 1
    {
        b.SetSubRange(i*n,n);
        SignalUtils.ExpAverageFilter(b,ref state, 10); //set to 10%
    }
    b.SetFullRange();
    MtxVecTee.DrawIt(new TVec[2] {c,b}, new string[2] {"Unfiltered","Filtered"},"Exponential averaging",false);

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

    SignalUtils.IirInit(num,den,ref IirState,false);
    bLength = b.Length;
    for (i = 0; i < (bLength / n); i ++) //streaming test 2
    {
        b.SetSubRange(i*n,n);
        c.SetSubRange(i*n,n);
        SignalUtils.IirFilter(b,c,ref IirState);
    }
    SignalUtils.IirFree(ref IirState);

    b.SetFullRange();
    c.SetFullRange();
    MtxVecTee.DrawIt(new TVec[2] { b, c }, new string[2] { "Unfiltered", "Filtered" }, "Exponential averaging with IirFilter", false);
    }
See Also: SignalUtils.MovingAverageImpulse, SignalUtils.FirFilter, SignalUtils.KaiserImpulse, OptimalFir.RemezImpulse

Overload 4: Double ExpAverageFilter(Double Data, ref Double State, Double Decay)

Filter data with an exponential averaging filter.

#NameTypeDescription
1DataDoublescalar
2StateDouble (ref)output
3DecayDoublescalar

Returns: Double

Remarks:

Single sample non-vectorized variant of the exponential averaging.