AlphaBetaGammaFilter ​
Alpha-beta-gamma tracker: position, rate and acceleration estimates for a scalar measurement.
A third-order extension of AlphaBetaFilter. An alpha-beta tracker predicts with a locally constant rate, so on an accelerating signal its rate estimate lags by an amount proportional to the acceleration. This filter predicts with the acceleration as well, removing the bias and the gains may be reduced.
This filter is particularly useful when the measurement is oversampled relative to the signal: a longer effective memory then introduces little lag but improves noise rejection.
Stability constraint: beta is the same Kalata steady-state relation AlphaBetaFilter uses,
Those defaults are not critically damped – the Kalata triple has a complex pole pair for every alpha, so the estimation error decays with an oscillatory mode. To put all three error poles on the real axis at a common radius
,
Setting alpha alone is not enough: beta and gamma would keep their Kalata defaults and move the poles back off the axis. At alpha = 0.271 on its own gives
is the tuning parameter that sets the speed of the estimator, in place of alpha. The pole is triple, so the error decays as alpha does for the default tuning.
The rate and acceleration state variables initialize to zero under every initialization variant; the enum selects only the position state, and does so through the same expressions as AlphaBetaFilter – with both rates starting at zero the first prediction is the previous position alone, exactly as in the second-order filter.
Usage ​
DiscreteComponents.AlphaBetaGammaFilter(alpha=0.5, beta=2 * (2 - alpha) - 4 * sqrt(1 - alpha), gamma=beta ^ 2 / (2 * alpha))
Parameters: ​
| Name | Description | Units | Default value |
|---|---|---|---|
Ts | Sample interval [s] | – | SampleTime() |
initialization | – | DiscreteCom...t(; y0=0.0) | |
alpha | Position correction gain, in (0, 1) | – | 0.5 |
beta | Rate correction gain; the default is the steady-state Kalman value for alpha, the same relation AlphaBetaFilter uses | – | 2 * (2 - al...(1 - alpha) |
gamma | Acceleration correction gain; the default completes the steady-state Kalman triple for alpha and beta | – | beta ^ 2 / (2 * alpha) |
Connectors ​
u- This connector represents a real signal as an input to a component (RealInput)y- This connector represents a real signal as an output from a component (RealOutput)rate- This connector represents a real signal as an output from a component (RealOutput)accel- This connector represents a real signal as an output from a component (RealOutput)
Variables ​
| Name | Description | Units |
|---|---|---|
pred | This sample's position prediction from the previous state | – |
predrate | This sample's rate prediction from the previous state | – |
resid | Innovation: measurement minus prediction | – |
Behavior ​
Source ​
"""
Alpha-beta-gamma tracker: position, rate and acceleration estimates for a scalar measurement.
A third-order extension of [`AlphaBetaFilter`](@ref). An alpha-beta tracker predicts with a locally constant rate,
so on an accelerating signal its rate estimate lags by an amount proportional to the acceleration.
This filter predicts with the acceleration as well, removing the bias and the gains may be reduced.
This filter is particularly useful when the measurement is oversampled relative to the signal:
a longer effective memory then introduces little lag but improves noise rejection.
Stability constraint: ``0 < \alpha < 1``. The default `beta` is the same Kalata steady-state relation [`AlphaBetaFilter`](@ref) uses,
``\beta = 2(2 - \alpha) - 4\sqrt{1 - \alpha}``, and the default ``\gamma = \beta^2 / (2\alpha)`` completes it,
so the defaults make this the steady-state Kalman filter for a triple-integrator (constant-acceleration) target.
With the default ``\alpha = 0.5`` they are ``\beta \approx 0.1716`` and ``\gamma \approx 0.0294``.
Those defaults are not critically damped -- the Kalata triple has a complex pole pair for every `alpha`, so the
estimation error decays with an oscillatory mode. To put all three error poles on the real axis at a common
radius ``s \in (0, 1)`` instead, set all three gains together:
``\alpha = 1 - s^3``, ``\beta = \frac{3}{2}(1 - s)^2(1 + s)``, ``\gamma = (1 - s)^3``.
Setting `alpha` alone is not enough: `beta` and `gamma` would keep their Kalata defaults and move the poles back
off the axis. At ``s = 0.9`` the critically damped triple is ``\alpha = 0.271``, ``\beta = 0.0285``,
``\gamma = 0.001``, whereas `alpha = 0.271` on its own gives ``\beta = 0.0427`` and ``\gamma = 0.0034``.
``s`` is the tuning parameter that sets the speed of the estimator, in place of `alpha`. The pole is triple, so the error decays as ``k^2 s^k`` and settles
somewhat slower than the radius alone suggests, but ``-T_s / \ln s`` is the useful estimate: about 9.5 samples
at ``s = 0.9`` and 50 at ``s = 0.98``. A smaller ``s`` tracks faster and passes more measurement noise, exactly
as a larger `alpha` does for the default tuning.
The rate and acceleration state variables initialize to zero under every `initialization` variant; the enum selects only the position state,
and does so through the same expressions as [`AlphaBetaFilter`](@ref) -- with both rates starting at zero the first prediction is the previous position alone,
exactly as in the second-order filter.
"""
component AlphaBetaGammaFilter@[input clk extends Discrete]
"Measured value"
u = RealInput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": -100, "y1": 450, "x2": 0, "y2": 550, "rot": 0}
},
"tags": []
}
}
"Position estimate"
y = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 100, "x2": 1100, "y2": 200, "rot": 0}
},
"tags": []
}
}
"Rate estimate [units of u per second]"
rate = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
},
"tags": []
}
}
"Acceleration estimate [units of u per second squared]"
accel = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 800, "x2": 1100, "y2": 900, "rot": 0}
},
"tags": []
}
}
"Position correction gain, in (0, 1)"
parameter alpha::Real = 0.5
"Rate correction gain; the default is the steady-state Kalman value for alpha, the same relation `AlphaBetaFilter` uses"
parameter beta::Real = 2 * (2 - alpha) - 4 * sqrt(1 - alpha)
"Acceleration correction gain; the default completes the steady-state Kalman triple for alpha and beta"
parameter gamma::Real = beta ^ 2 / (2 * alpha)
"Sample interval [s]"
structural parameter Ts::Real = SampleTime()
structural parameter initialization::InitialCondition = DiscreteComponents.InitialCondition.InitialOutput(y0 = 0.0)
"This sample's position prediction from the previous state"
variable pred::Real
"This sample's rate prediction from the previous state"
variable predrate::Real
"Innovation: measurement minus prediction"
variable resid::Real
relations
pred@clk = y@(clk-1) + Ts * rate@(clk-1) + (Ts ^ 2 / 2) * accel@(clk-1)
predrate@clk = rate@(clk-1) + Ts * accel@(clk-1)
resid@clk = u@clk - pred@clk
y@clk = pred@clk + alpha * resid@clk
rate@clk = predrate@clk + (beta / Ts) * resid@clk
accel@clk = accel@(clk-1) + (gamma / Ts ^ 2) * resid@clk
initial rate@(clk-1) = 0
initial accel@(clk-1) = 0
switch initialization
case InitialOutput
initial y@(clk-1) = (initialization.y0 - alpha * u@clk) / (1 - alpha)
case SteadyState
initial y@(clk-1) = u@clk
case InitialState
initial y@(clk-1) = initialization.x0
end
metadata {
"Dyad": {"icons": {"default": "dyad://DiscreteComponents/AlphaBetaGammaFilter.svg"}}
}
endFlattened Source
"""
Alpha-beta-gamma tracker: position, rate and acceleration estimates for a scalar measurement.
A third-order extension of [`AlphaBetaFilter`](@ref). An alpha-beta tracker predicts with a locally constant rate,
so on an accelerating signal its rate estimate lags by an amount proportional to the acceleration.
This filter predicts with the acceleration as well, removing the bias and the gains may be reduced.
This filter is particularly useful when the measurement is oversampled relative to the signal:
a longer effective memory then introduces little lag but improves noise rejection.
Stability constraint: ``0 < \alpha < 1``. The default `beta` is the same Kalata steady-state relation [`AlphaBetaFilter`](@ref) uses,
``\beta = 2(2 - \alpha) - 4\sqrt{1 - \alpha}``, and the default ``\gamma = \beta^2 / (2\alpha)`` completes it,
so the defaults make this the steady-state Kalman filter for a triple-integrator (constant-acceleration) target.
With the default ``\alpha = 0.5`` they are ``\beta \approx 0.1716`` and ``\gamma \approx 0.0294``.
Those defaults are not critically damped -- the Kalata triple has a complex pole pair for every `alpha`, so the
estimation error decays with an oscillatory mode. To put all three error poles on the real axis at a common
radius ``s \in (0, 1)`` instead, set all three gains together:
``\alpha = 1 - s^3``, ``\beta = \frac{3}{2}(1 - s)^2(1 + s)``, ``\gamma = (1 - s)^3``.
Setting `alpha` alone is not enough: `beta` and `gamma` would keep their Kalata defaults and move the poles back
off the axis. At ``s = 0.9`` the critically damped triple is ``\alpha = 0.271``, ``\beta = 0.0285``,
``\gamma = 0.001``, whereas `alpha = 0.271` on its own gives ``\beta = 0.0427`` and ``\gamma = 0.0034``.
``s`` is the tuning parameter that sets the speed of the estimator, in place of `alpha`. The pole is triple, so the error decays as ``k^2 s^k`` and settles
somewhat slower than the radius alone suggests, but ``-T_s / \ln s`` is the useful estimate: about 9.5 samples
at ``s = 0.9`` and 50 at ``s = 0.98``. A smaller ``s`` tracks faster and passes more measurement noise, exactly
as a larger `alpha` does for the default tuning.
The rate and acceleration state variables initialize to zero under every `initialization` variant; the enum selects only the position state,
and does so through the same expressions as [`AlphaBetaFilter`](@ref) -- with both rates starting at zero the first prediction is the previous position alone,
exactly as in the second-order filter.
"""
component AlphaBetaGammaFilter
"Measured value"
u = RealInput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": -100, "y1": 450, "x2": 0, "y2": 550, "rot": 0}
},
"tags": []
}
}
"Position estimate"
y = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 100, "x2": 1100, "y2": 200, "rot": 0}
},
"tags": []
}
}
"Rate estimate [units of u per second]"
rate = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
},
"tags": []
}
}
"Acceleration estimate [units of u per second squared]"
accel = RealOutput@[clk]() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 1000, "y1": 800, "x2": 1100, "y2": 900, "rot": 0}
},
"tags": []
}
}
"Position correction gain, in (0, 1)"
parameter alpha::Real = 0.5
"Rate correction gain; the default is the steady-state Kalman value for alpha, the same relation `AlphaBetaFilter` uses"
parameter beta::Real = 2 * (2 - alpha) - 4 * sqrt(1 - alpha)
"Acceleration correction gain; the default completes the steady-state Kalman triple for alpha and beta"
parameter gamma::Real = beta ^ 2 / (2 * alpha)
"Sample interval [s]"
structural parameter Ts::Real = SampleTime()
structural parameter initialization::InitialCondition = DiscreteComponents.InitialCondition.InitialOutput(y0 = 0.0)
"This sample's position prediction from the previous state"
variable pred::Real
"This sample's rate prediction from the previous state"
variable predrate::Real
"Innovation: measurement minus prediction"
variable resid::Real
relations
pred@clk = y@(clk-1) + Ts * rate@(clk-1) + (Ts ^ 2 / 2) * accel@(clk-1)
predrate@clk = rate@(clk-1) + Ts * accel@(clk-1)
resid@clk = u@clk - pred@clk
y@clk = pred@clk + alpha * resid@clk
rate@clk = predrate@clk + (beta / Ts) * resid@clk
accel@clk = accel@(clk-1) + (gamma / Ts ^ 2) * resid@clk
initial rate@(clk-1) = 0
initial accel@(clk-1) = 0
switch initialization
case InitialOutput
initial y@(clk-1) = (initialization.y0 - alpha * u@clk) / (1 - alpha)
case SteadyState
initial y@(clk-1) = u@clk
case InitialState
initial y@(clk-1) = initialization.x0
end
metadata {
"Dyad": {"icons": {"default": "dyad://DiscreteComponents/AlphaBetaGammaFilter.svg"}}
}
endTest Cases ​
No test cases defined.
Related ​
Examples
Experiments
Analyses