function period=testperiod(x,epsilon,maxper)

%   PERIOD = TESTPER(X,EPSILON,MAXPER) determines if there
%   is a periodic orbit in the sequence given by the vector X whose
%   period is less than or equal to MAXPER.
%   The convergence criterion is that the difference is less than EPSILON.
%   
%   If no period is detected then PERIOD =-1.
%   
%   Note: if PERIOD =-1 test if period is smaller or equal to MAXPER.

%   Copyright 2003
%   Centre for Nonlinear Dynamics in Physiology and Medicine

period=-1;
for jper=1:maxper
%tests for period length up to maxper
if abs(x(length(x))-x(length(x)-jper)) < epsilon
period=jper;
break;
end;
end;
