title: Is it possible that kalman-filter algorithm result in a singular variance matrix?
body: <p>Is it possible that in a Kalman Filter implementation the 'Predicted estimate covariance', P(k|k-1), (<a href="http://en.wikipedia.org/wiki/Kalman_filter" rel="nofollow noreferrer">see the wiki here</a>) could be a singular matrix? If not, is something is wrong with my code?</p>
  
  <p>This is the state-space model</p>
  
  <pre><code>%    y{t}=Z{t} b{t} +  eps{t},                  eps{t} ~ N(0,H{t})
  %              b{t} = Pi{t} b{t-1} + tao{t}     tao{t} ~ N(0,Q{t})
  %                                               b{1} ~ N(b0,P0)
  %                                               t=1,...,T
  </code></pre>
  
  <p>and this is the backward recursion as the main part of the kalman-filter algorithm:</p>
  
  <pre><code>for t=1:T
  
      v{t} = y{t} - Z{t} * b_tt_1{t};
      M{t} = P_tt_1{t} * Z{t}';
      F{t} = Z{t} * M{t} + H{t};
  
         F_{t}= inv(F{t});
         MF_{t}= M{t} * F_{t};
  
      b_tt{t}=b_tt_1{t} + MF_{t} * v{t};
      P_tt{t}=P_tt_1{t} - MF_{t} * M{t}';
  
      b_tt_1{t+1} = Pi{t} * b_tt{t};
      P_tt_1{t+1} = Pi{t} * P_tt{t} * Pi{t}' + Q{t};
  
  end
  </code></pre>
  
  <p>This happened when I used actual data. To see where the problem might be, I wrote some code to generate random state-space models (I can provide the code, if it is needed).</p>
  
  <p>When T is large, After some t0, P_tt_1{t0} is singular and the states (b{t0}) diverge.</p>
  
  <p>Edit:
  I used "Joseph form" of the covariance update equation (see Wikipedia). It helped, but the result still diverges when the state-space model is Large (in sense of number of equations or states). I think this means the problem is related to numerical stability. Is there a way to solve this?</p>