Overload List
| # | Signature | Description |
|---|---|---|
| 1 | void ExpAverageFilter(TVec Data, ref TCplx State, Double Decay) | Filter data with an exponential average filter. |
| 2 | void ExpAverageFilter(TVec Data, ref Double State, Double Decay) | Filter data with an exponential average filter. |
| 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). |
| 4 | Double 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.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Data | TVec | source TVec |
| 2 | State | TCplx (ref) | output |
| 3 | Decay | Double | scalar |
Result: stored in self (calling object)
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.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Data | TVec | source TVec |
| 2 | State | Double (ref) | output |
| 3 | Decay | Double | scalar |
Result: stored in self (calling object)
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).
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Decay | Double | scalar |
| 2 | Num | TVec | source TVec |
| 3 | Den | TVec | source TVec |
Result: stored in self (calling object)
Transfer function can be used to initialize an IIR filter by passing num and den to the IirInit routine.
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);
}
Overload 4: Double ExpAverageFilter(Double Data, ref Double State, Double Decay)
Filter data with an exponential averaging filter.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Data | Double | scalar |
| 2 | State | Double (ref) | output |
| 3 | Decay | Double | scalar |
Returns: Double
Single sample non-vectorized variant of the exponential averaging.