SignalUtils::ExpAverageFilter Function

Overload List

#SignatureDescription
1void ExpAverageFilter(TVec *Data, double &State, double Decay = 50);Filter data with an exponential average filter.
2double ExpAverageFilter(const double Data, double &State, double Decay = 50);Filter data with an exponential averaging filter.
3void ExpAverageFilter(TVec *Data, TCplx &State, double Decay = 50);Filter data with an exponential average filter.
4void 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).

Overload 1: void ExpAverageFilter(TVec *Data, double &State, double Decay = 50);

Filter data with an exponential average filter.

#NameTypeDescription
1DataTVec *
2Statedouble &
3Decay = 50double
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
#include "MtxExpr.h"
#include "Units.MtxExpr.h"
#include "Units.SignalUtils.h"

using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units::MtxExpr;
using namespace Dew::Signal;
using namespace Dew::Signal::Units::SignalUtils;

void Example()
{
    Vector b, c, num, den;
    int n, i;
    TIirState IirState;
    double State;

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

    //Alternative 2: Gaussian noise
    b = RandGauss(300, TMtxFloatPrecision::mvDouble);
    c.Copy(b);
    n = 10;
    State = 0;
    int bLength = b.Length;
    for (i = 0; i <= (bLength / n) - 1; i++) //streaming test 1
    {
        b.SetSubRange(i*n, n);
        ExpAverageFilter(b, State, 10); //set to 10%
    }
    b.SetFullRange();

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

    IirInit(num, den, IirState);
    bLength = b.Length;
    for (i = 0; i <= (bLength / n) - 1; i++) //streaming test 2
    {
        b.SetSubRange(i*n, n);
        c.SetSubRange(i*n, n);
        IirFilter(b, c, IirState);
    }
    IirFree(IirState);
    b.SetFullRange();
    c.SetFullRange();
}
Declared in Dew::Signal::Units::SignalUtils · Dew.Signal/Units.SignalUtils.h · Cross-compiler

Overload 2: double ExpAverageFilter(const double Data, double &State, double Decay = 50);

Filter data with an exponential averaging filter.

#NameTypeDescription
1Dataconst double
2Statedouble &
3Decay = 50double
Remarks:

Single sample non-vectorized variant of the exponential averaging.

Declared in Dew::Signal::Units::SignalUtils · Dew.Signal/Units.SignalUtils.h · Cross-compiler

Overload 3: void ExpAverageFilter(TVec *Data, TCplx &State, double Decay = 50);

Filter data with an exponential average filter.

#NameTypeDescription
1DataTVec *
2StateTCplx &
3Decay = 50double
Remarks:

Exponential average filter without the TIirState structure for complex data.

Declared in Dew::Signal::Units::SignalUtils · Dew.Signal/Units.SignalUtils.h · Cross-compiler

Overload 4: 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
1Decaydouble
2NumTVec *
3DenTVec *
Remarks:

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

Examples
#include "MtxExpr.h"
#include "Units.MtxExpr.h"
#include "Units.SignalUtils.h"

using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units::MtxExpr;
using namespace Dew::Signal;
using namespace Dew::Signal::Units::SignalUtils;

void Example()
{
    Vector b;
    Vector c(0);
    Vector num(0);
    Vector den(0);

    int n;
    int i;

    TIirState IirState;
    double state;

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

    //Alternative 2: Gaussian noise
    b = RandGauss(300, TMtxFloatPrecision::mvDouble);
    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);
        ExpAverageFilter(b, state, 10); //set to 10%
    }
    b.SetFullRange();

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

    IirInit(num, den, 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);
        IirFilter(b, c, IirState);
    }
    IirFree(IirState);

    b.SetFullRange();
    c.SetFullRange();
}
See Also: SignalUtils::MovingAverageImpulse, SignalUtils::FirFilter, SignalUtils::KaiserImpulse, OptimalFir::RemezImpulse
Declared in Dew::Signal::Units::SignalUtils · Dew.Signal/Units.SignalUtils.h · Cross-compiler