function [p,gain] = cheb (ap,as,oms)
%CHEB	Chebyshev analog lowpass filter prototype.
%	[p,gain] = CHEB(ap,as,oms) returns poles and gain
%	of a normalized prototype Chebyshev analog lowpass filter
%	with ap decibels of ripple in the passband, as decibels is minimal
%	attenuation on the start of the stopband oms is normalized frequency 
%       of the start of the stopband.
%
%	See also BUTTER, BUTT, BUTTAPP, CHEB, INVCHEBY, INVCHEBY2, CHEB1AP, and CHEB2AP.
%
%	Author(s): J. Vrbata 15.9.2000
%	This is a version for GNU OCTAVE 2.0.14

% Secondary parameters

eps=sqrt(10^(0.1*ap)-1);
k=1/oms;
k1=1/sqrt((10^(0.1*as)-1)/(10^(0.1*ap)-1));

pom=acosh(1/k1)/acosh(oms);
if (pom-floor(pom)>0) n=floor(pom+1); else n=floor(pom); end

a=0.5*((sqrt(1/eps^2+1)+1/eps)^(1/n)-(sqrt(1/eps^2+1)-1/eps)^(1/n));
b=0.5*((sqrt(1/eps^2+1)+1/eps)^(1/n)+(sqrt(1/eps^2+1)-1/eps)^(1/n));

asnew=10*log10(1+(eps^2/k1^2));

if (ceil(n/2)==n/2) m=floor(n/2); else m=floor((n-1)/2); end

for f=1:n;
	alfa=-1*a*sin(((2*f-1)/n)*(pi/2));
	beta=b*cos(((2*f-1)/n)*(pi/2));
	p(f)=alfa+beta*i;
	%p(n-f+1)=alfa-beta*i;
end;

gain=1/(eps*2^(2*m-1));
