function [out1,out2] = arpred(A,n,rank)

if rank == 0
%    [rank d q] = arimacoeff(A,n)
    rank = min(n,floor(length(A)/2));
end;

c=-arcov(A,rank);
c=c(2:rank+1);

s = length(A);

for i = s +1:s+n
    A(i) = sum(c'.*A(i-1:-1:i-rank));
end

out1 = A;
out2 = rank;