function [ahat, bhat, L] = batirpi(y, U, N, D, T) 
%
% BATLRPI Gives estimated parametersof a model of the type
% Ay=Bu+Der.
% Function Call:
%   [ahat, bhat, L] = batlrpi(y, U, N, D, T)
% Inputs :
% y and U are vectors of sequential output and input
% respectively assumed t o be of the same length.
%   N(1) = na number of estimated A parameters
%   N(2) = nb number of estimated B parameters
%   N(3) = k the assumed time-delay in samples(>=1) 
%   N(4) = N1 Initial Costing Horizon
%   N(5) = N2 Final Costing Horizon
% D, T are D and T in the above model
% Outputs:
% ahat, bhat are A and B in the above model
% L is the converged filter for LRPI.
%
%
na=N(l);nb=N(2); k=N(3);N1 =N(4); N2=N(5); y=y(:); u=u(:);
to1 = l e - 3 ;
err = 1;
Nmax = length(y);
theta = zeros(na + nb, 1); while err > tol,
if na > 0,
L-eqivl([l theta(nb+l:na+nb)‘], D,T, N1, N2); else
L=eqivl([l 01, D, N1, N2); end ;
y6= filter(conv(L, D), T, y);
uf = filter(conv(L, D), T, U); n=max(na, nb+k-1); X=uf(n-k+l:Nmax-1 -k+l); for i= 2: nb,
X=[Xuf(n-i+1 -k+l:Nmax-i-k+l)]; end
for i = 1: na,
X=[X-yf(n -i+1:Nmax-i)];
end
Y=yf(n+l:Nmax);
thetanew = X\Y;
err = norm(theta - thetanew, l)/max(norm(theta, 1). 1e theta = thetanew;
end
bhat = [zeros(l, k) theta(1 : nb)’];
ahat= [ltheta(nb+1:na+nb)’];
return
function [L] = eqivl(a, D, T, N1, N2)
O/o
% EQlVL Computes the equivalent L prefilter as
“U/
YO L(q)L(q-’) =sum over j {Ni + N2) of Ej(q)Ej(q-’) % Function Call:
Yo L=eqivl(A,D,T,N1,N2)
Oh Inputs:
% A, D.Tarepolynomialsintheequation:
O/o
