Overload List
| # | Signature | Description |
|---|---|---|
| 1 | procedure ExpAverageFilter(Data: TVec; var State: TCplx; Decay: Double); | Filter data with an exponential average filter. |
| 2 | procedure ExpAverageFilter(Data: TVec; var State: Double; Decay: Double); | Filter data with an exponential average filter. |
| 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). |
| 4 | function 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.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Data | TVec | source TVec |
| 2 | State | TCplx | |
| 3 | Decay | Double | scalar |
Result: stored in self (calling object)
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.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Data | TVec | source TVec |
| 2 | State | Double | |
| 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.
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).
| # | 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.
Overload 4: function ExpAverageFilter(const Data: Double; var State: Double; Decay: Double): Double;
Filter data with an exponential averaging filter.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Data | Double | |
| 2 | State | Double | |
| 3 | Decay | Double | scalar |
Returns: Double
Single sample non-vectorized variant of the exponential averaging.