function [F, G, H, P] = modelKalman(AR, Q, R)
% function call from kalmanFilter.m function
%
% function to construct transition model, observation model, noise model
% input parameters
% 1. AR --> AR coefficients
% 2. Q --> process noise
% 3. R --> observation noise
% output parameters
% 1. F --> transition model
% 2. G --> observation model
% 3. H --> noise model
% 4. P --> error covariance matrix

% F = [ AR(order) AR(order-1) .. AR(1); 0 1 0 ..0; 0 0 1 0...0;0 ... 1 0;]
% G = [ 1 0 0 0 ... 0]
% H = G' transpose of G

% to find the dimension of AR
order = length(AR);
F = zeros(order, order);
p = order;
% The a(i)'s are then used to generate the state-transition matrix
% representing state evolution in that frame
F_ = eye(p-1, p-1);
F = zeros(p, p);
F(:,1) = zeros(p, 1);
F(p,:) = AR';

% F is now the state-transition matrix for the Kalman Filter
F(1:p-1, 2:p) = eye(p-1, p-1);

% Defining G (Process noise gain) and H (observation matrix)
G = zeros(p, 1);
G(p, 1) = 1;
H = G';


% process error covariance 
% assumed to be trice the process covariance
% 
P = 3 * Q * eye(p, p);

% disp('all parameters found out line 42, modelKalman function');