Collab,
In the attached MC worksheet, there is BASIC code which implements a simple second order case of Kalman filtering applied to data smoothing.
In these equations, Xm is the measured value of the signal to be filtered; Xdelta is the difference between the measured value and the estimated value for the signal; Xp is the predicted value of the signal for the next iteration; dX is the change in the estimated signal value; Xs is the smoothed value of the input signal; and K1 and K2 are smoothing factors used by the filter.
This filter is recursive: the results of the previous iteration will be used in the next iteration.
MC To start the filter an estimate is required. For most cases, the first value from the data set or other reasonable value is used. Initially, Xp is set to this value.
dX is then set to zero. A value for K1 between zero and 0.5 is then selected. (zero is maximum filtering, 0.5 is no filtering)
The calulations are shown below:
K2 = sqrt(2.0 * K1)
Xdelta = Xm - Xp
dX = dX + Xdelta * K1
Xs = Xp + Xdelta * K2
Xp = Xs + dX
The last four equations are iterated for the next value of Xm and to get a new estimate for the next value (Xp) and a new value for the smoothed output (Xs).
With each iteration, the effect of the first data point is reduced. This effect approaches but never reaches zero.
Before trying this in Mathcad, I tried to implement these calculations in Excel. Seems that an XL worksheet should handle these calculations. However, due to the recursive (parent-child) nature of the calculation, I could not figure out how to get around the circular reference problem in XL. The Basic program listed did not have this problem.
I thought that Mathcad would also work without a problem, but it does not. Obviously, I must have either an initial condition or subscript specified incorrectly as my Mathcad results do no match the BASIC results which are shown in the table, BASIC results.
Does anyone have a suggestion to get the MC calculations to match original BASIC calculations?
Thanks,
Art
In the attached MC worksheet, there is BASIC code which implements a simple second order case of Kalman filtering applied to data smoothing.
In these equations, Xm is the measured value of the signal to be filtered; Xdelta is the difference between the measured value and the estimated value for the signal; Xp is the predicted value of the signal for the next iteration; dX is the change in the estimated signal value; Xs is the smoothed value of the input signal; and K1 and K2 are smoothing factors used by the filter.
This filter is recursive: the results of the previous iteration will be used in the next iteration.
MC To start the filter an estimate is required. For most cases, the first value from the data set or other reasonable value is used. Initially, Xp is set to this value.
dX is then set to zero. A value for K1 between zero and 0.5 is then selected. (zero is maximum filtering, 0.5 is no filtering)
The calulations are shown below:
K2 = sqrt(2.0 * K1)
Xdelta = Xm - Xp
dX = dX + Xdelta * K1
Xs = Xp + Xdelta * K2
Xp = Xs + dX
The last four equations are iterated for the next value of Xm and to get a new estimate for the next value (Xp) and a new value for the smoothed output (Xs).
With each iteration, the effect of the first data point is reduced. This effect approaches but never reaches zero.
Before trying this in Mathcad, I tried to implement these calculations in Excel. Seems that an XL worksheet should handle these calculations. However, due to the recursive (parent-child) nature of the calculation, I could not figure out how to get around the circular reference problem in XL. The Basic program listed did not have this problem.
I thought that Mathcad would also work without a problem, but it does not. Obviously, I must have either an initial condition or subscript specified incorrectly as my Mathcad results do no match the BASIC results which are shown in the table, BASIC results.
Does anyone have a suggestion to get the MC calculations to match original BASIC calculations?
Thanks,
Art