function [g,p]=peflt(x,istart,n,mmax);

% C	BOTTERO'S SUBROUTINE BASED ON ANDERSON'S EQUATIONS IN
% C	VOL 39 NO 1 OF Geophysics 1974, p69-72.

% Modified from a FORTRAN program by jpx on 7-15-99

iend=istart+n-1;
sum1=sum(x(istart:iend).^2);
p=sum1/n;

m=1;
nmm=n-m;
b(1:nmm)=x(istart:istart+nmm-1);
bp(1:nmm)=x(istart+1:istart+nmm);

while m<=mmax
	if m>1
		nmm=n-m;
		for i=1:nmm
			b(i)=b(i)-aold(m-1)*bp(i);
			bp(i)=bp(i+1)-aold(m-1)*b(i+1);
		end;
	end;
	
	sum1=sum(b(1:nmm).*bp(1:nmm));
	sum2=sum(b(1:nmm).^2 + bp(1:nmm).^2);
	if sum2~=0
		a(m)=2*sum1/sum2;
	else
		a(m)=0;
	end;
	p=p*(1-a(m)^2);
	if m>1
		mm1=m-1;
		for k=1:mm1
			mmk=m-k;
			a(k)=aold(k)-a(m)*aold(mmk);
		end;
	end;
	aold(1:m)=a(1:m);
	
	m=m+1;
end;

g=a;

return;
