Overload List
| # | Signature | Description |
|---|---|---|
| 1 | void SavGolayImpulse(TMtx H, TMtx Diff, Int32 FrameSize, Int32 Order, TVec Weights) | Design a Savitzky-Golay polynomial smoothing filter. |
| 2 | void SavGolayImpulse(TVec H, Int32 FrameSize, Int32 Order, TVec Weights) | The resulting H vector contains FIR type impulse response, which can be passed to the FirInit routine. |
Overload 1: void SavGolayImpulse(TMtx H, TMtx Diff, Int32 FrameSize, Int32 Order, TVec Weights)
Design a Savitzky-Golay polynomial smoothing filter.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | H | TMtx | source TMtx |
| 2 | Diff | TMtx | source TMtx |
| 3 | FrameSize | Int32 | |
| 4 | Order | Int32 | |
| 5 | Weights | TVec | source TVec |
Result: stored in self (calling object)
Compute a Savitzky-Golay polynomial smoothing filter: a polynomial of degree Order is least-squares fitted to each FrameSize-long window of the signal. H is sized FrameSize x FrameSize; row i holds the filter producing the fitted value at window position i. Only the center row of H is used for filtering the signal interior, the upper and lower rows of H are applied to the transition regions where the signal starts and stops (see Dew.Signal.Units.SignalUtils.SavGolayFilter). Diff is sized (Order+1) x FrameSize; row k recovers the coefficient of x^k of the fitted polynomial, with x counted in samples relative to the window center, so row 1 is the first-derivative filter.
Weights, when assigned, must hold FrameSize strictly positive values and the fit minimizes the weighted sum of squares; H is then not symmetric. An exception is raised if FrameSize is not odd, if Order is not in [0, FrameSize-1], or if Weights are present with wrong length, non-positive values or a precision different from H. The computation runs in the precision of H.
Overload 2: void SavGolayImpulse(TVec H, Int32 FrameSize, Int32 Order, TVec Weights)
The resulting H vector contains FIR type impulse response, which can be passed to the FirInit routine.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | H | TVec | source TVec |
| 2 | FrameSize | Int32 | |
| 3 | Order | Int32 | |
| 4 | Weights | TVec | source TVec |
Result: stored in self (calling object)
Returns the center row of the Savitzky-Golay smoothing matrix: the FIR filter fitting a polynomial of degree Order to each FrameSize-long window and evaluating it at the window center. Optional Weights (FrameSize strictly positive values, same precision as H) select a weighted least-squares fit.
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 h = new Vector(0);
Vector b = MtxExpr.Ramp(300, TMtxFloatPrecision.mvDouble, 0, 0.1);
Vector c = new Vector(b.Length);
TFirState state = new TFirState();
int n = 10;
int i;
SignalUtils.SavGolayImpulse(h,15,7,null);
SignalUtils.FirInit(h,ref state,1,0,1,0);
try
{
c.Size(b);
n = 10;
int bLength = b.Length; //must be outside of the "for" to prevent reevaluation
for (i = 0; i < (bLength/n); i++)
{
b.SetSubRange(i * n, n); //select only a small subvector of the vector
c.SetSubRange(i * n, n);
SignalUtils.FirFilter(b,c,ref state);
}
MtxVecTee.DrawIt(new TVec[2] { b, c }, new string[2] { "Filtered data", "Original data" }, "Savitzky Golay", false);
}
finally
{
SignalUtils.FirFree(ref state);
}
}