function amdf=amdf_tr(xtr, sammin, sammax)
% Syntax: amdf=amdf_tr(xtr, sammin, sammax)
%     or: amdf=amdf_tr(xtr)
% 
% AMDF function for one frame of signal. 
% xtr - one frame of signal (should have length > sammax)
% sammin - minimal pitch period in samples - default 20
% sammax - maximal pitch period in samples - default 160
% amdf - array of amdf, length sammax, first sammin-1 values dummy.

if nargin==1,
  sammin=20;
  sammax=160;
else 
  if (nargin ~= 3)
    error ('Bad no. of arguments');
  end
end
      
lx=length(xtr);
if lx <= sammax
  error ('bad length of xtr');
end  

amdf=zeros(1,sammax);

for dec=sammin:sammax
  amdf(dec)=mean(abs(xtr(1:lx-dec+1)-xtr(dec:lx)));
end
