function [ Yp ] = ArxPred( U,Y, theta, xo )
% ARXPRED realizes the one-step prediction for the ARX model 
% y(k+1) = a1*y(k) + a2*y(k-1) + b1*u(k) + b2*u(k-1) + e(k+1)
% 
%       [ Yp ] = ArxPred( U,Y, theta, xo )
%  
%  Input parameters
%   U,Y         : column vectors of system input and output (having same
%                 dimension)
%   theta       : parameter vector in the form [a1, a2, b1 b2]
%   x0          : intial state for simulation  [y(0), y(-1), u(0), u(-1)]

N = length(Y);
Y = [xo(2);xo(1);Y];
U = [xo(4);xo(3);U];
Yp= NaN * ones(N+2,1);
% simulation cycle
for i = 2+(1:N)
    % modello arx
    phi = [Y(i-1) Y(i-2) U(i-1) U(i-2)]; % regressors are a selection of Z = subset of {Y,Y}
    Yp(i,1) = phi*theta;                 % ARX one-step prediction
end
Yp(1:2) = [];