function [zpred, Qpred] = kalman_predict(A, C, U, V, z, Q, T)
% KALMAN_PREDICT Do a T step predict of the Kalman filter
% [zpred, Qpred, xpred] = kalman_predict(A, C, V, U, z, Q, T)
%
% Given
%  z(:) =   E[ z | x(1:t-1) ] and
%  Q(:,:) = var[ z(t-1) | x(1:t-1) ],
% compute for all t (1 <= t <= T)
%  zpred(:,t) =  E[ z(t) | z(t-1) ] and
%  Qpred(:,:,t) = var[ z(t) | z(t-1) ] and
% using
%  A(:,:) - the system matrix
%  C(:,:) - the observation matrix
%  U(:,:) - the system covariance
%  V(:,:) - the observation covariance

zdim = size(z,1);
xdim = size(C,1);
zpred = zeros(zdim,T);
Qpred = zeros(zdim,zdim,T);

zpred(:,1)   = z;    % initial value
Qpred(:,:,1) = Q;    % initial value

% timewise update
for t=2:T,
  zpred(:,t)   = A*zpred(:,t-1);          %(62)Ž®
  Qpred(:,:,t) = A*Qpred(:,:,t-1)*A' + U; %(61b)Ž®
end
