%%% Matlab script to generate some "true" data for later assessment
%%% Generates:
%%%     x: the state history which evolves according to x(k+1) = Fx(k) + w(k)
%%%     w: the process noise history (randomly generated)
%%%     z: a set of observations on the state corrupted by noise
%%%     v: the noise on each observation (randomly generated)

N = 500;

delT = 1;
F = [ 1 delT
      0   1  ];
H = [ 1 0 ];
sigma2Q = 0.01;
sigma2R = 0.1;
Q = sigma2Q *  [ delT^3/3  delT^2/2
                 delT^2/2  delT ];
P = 10*Q;
R = sigma2R * [ 1 ];

x = zeros(2,N);
w = zeros(2,N);
z = zeros(1,N);
v = zeros(1,N);
for i=2:N
   w(:,i) = gennormal([0;0], Q);          % generate process noise
   x(:,i) = F*x(:,i-1) + w(:,i);          % update state
   v(:,i) = gennormal([0], R);            % generate measurement noise
   z(:,i) = H * x(:,i) + v(:,i);           % get "true" measurement
end

plot(x(1,:));
