Implementing a 1-D Kalman Filter Regression, Missing the smoothing action (getting the opposite)
So let's try to piece the signal model together first.

The state vector, $\mathbf{x}_k$ is just
$$
\mathbf{x}_k = [ x_{k-1}\ x_{k-2}\ x_{k-3} ]^T
$$
and the state update equation is just
$$
\mathbf{x}_k = \left[
\begin{array}{ccc}
3 &amp; -3 &amp; 1 \\
1 &amp; 0 &amp; 0 \\
0 &amp; 1 &amp; 0 \\
\end{array}
\right] \mathbf{x}_{k-1} + 
\left[
\begin{array}{c}
1 \\
0 \\
0 \\
\end{array}
\right] v_k
$$
where $v_k$ is some driving noise which is Gaussian, zero mean, with variance $\sigma_v^2$.

Then the output equation is just
$$
x_k = \left[\begin{array}{ccc}
1 &amp; 0 &amp; 0
\end{array}
\right] \mathbf{x}_k + w_k
$$
where $w_k$ is Gaussian, zero mean, with variance $\sigma_w^2$.

If I set $\sigma_v$ to be $1$ and $\sigma_w$ to be 0.01 and generate one realization of the signal then I get the plot below (blue line)



This seems to be similar to the measurements you're graphing.

And the red line is what happens when I try to apply the Kalman filter to the signal model above.

Bottom line: I seem to get similar results to what you are seeing.

I suspect part of the problem is that the signal model is not stable, as the state transition matrix has eigenvalues:


  1.0000055+0.0000000i 0.9999973+0.0000048i 0.9999973-0.0000048i


the first of which is definitely outside the unit circle.



R Code Below

#27879

T &lt;- 100

#H = [3 -3 1]
H &lt;- matrix(c(1,0,0),c(1,3)) 

#F is just a tapped delay line
alpha &lt;- matrix(c(0.9,0,0,0,0.9,0,0,0,0.9),3,3)
A &lt;- matrix(c(3,1,0,-3,0,1,1,0,0),3,3)
B &lt;- matrix(c(1,0,0),c(3,1))

sigma_v &lt;- 1
v &lt;- rnorm(T,0,sigma_v)
sigma_w &lt;- 0.01
w &lt;- rnorm(T,0,sigma_w)

x &lt;- matrix(c(0,0,0),c(3,1))
z &lt;- rep(0,T)

for (t in 1:T)
{
  z[t] &lt;- H %*% x + w[t]
  x &lt;- A %*% x +v[t]
}
par(mfrow=c(1,1))
plot(z,type="l", col="blue", lwd=5)

Q &lt;- matrix(c(0,0,0,0,0,0,0,0,sigma_v^2),3,3)
R &lt;- sigma_w^2


library("MASS") # For pseudo inverse ginv()

xkm1km1 &lt;- matrix(rep(0,3*T+3),3,T+1)
xkkm1 &lt;- matrix(rep(0,3*T),3,T)
K &lt;- matrix(rep(0,3*T),3,T)
Pkm1km1 &lt;- matrix(c(1000,0,0 ,0,1000,0, 0,0,1000),3,3)
zhat &lt;- matrix(rep(0,T),c(T,1))

for (k in 1:T)
{
  xkkm1[,k] &lt;- A %*% xkm1km1[,k]
  Pkkm1 &lt;- A %*% Pkm1km1 %*% t(A) + Q
  K[,k] &lt;- Pkkm1 %*% t(H) %*% ginv( H %*% Pkkm1 %*% t(H) + R)
  xkm1km1[,k+1] &lt;- xkkm1[,k] + K[,k] %*% (z[k] - H %*% xkkm1[,k])
  Pkm1km1 &lt;- (matrix(c(1,0,0,0,1,0,0,0,1),3,3) - K[,k] %*% H) %*% Pkkm1  
  zhat[k] &lt;- as.numeric(H %*% xkkm1[,k])
}
lines(zhat, col="red")