//exec('optiir1.ex')
//design of a low-pass filter with normalized discrete frequency .25
// ripple in the passband 0.1, ripple in the stopband 0.01, 
// transition bandwidth .1
[ce0,f0,ze0,po0]=eqiir('lp','ellip',%pi*[.5;.65;0;0],.1,.01);
//
// transfer function of the original filter.
hz0=f0*prod(ce0(2))./prod(ce0(3));
//
//initialization of the parameter vector(zeros and poles in polar coord.)
//poles and zeros (discarding the conjugates)
//of the original filter have been retained as initial values, 
//leading to a filter with the same degree than the previous.
//the last value (10) is the initial value of the gain factor.
ze0=ze0(1:2:4);po0=po0(1:2:4);
x0=[abs([ze0 po0])';atan(imag([ze0 po0]),real([ze0 po0]))';10];
x=x0;
//
//grid of frequencies for the analysis
omega=%pi/100:%pi/100:%pi;
//
//choice of the power for the criterion (mean-square here)
p=1;
//
//setting the weighting function (one in the passband, 0.5 in the stopband)
wa(1:52)=ones(1,52);
wa(53:100)=.5*ones([53:100]);
//
//magnitude response of the original elliptic filter
rp0=abs(freq(hz0(2),hz0(3),exp(%i*omega)));
//
//setting the desired magnitude ad (ad(omega)*rp0(omega)=1 in the 
//passband, ad having the same attenuation than the original 
//filter in the stopband)
ad(1:49)=ones(1,49)./rp0(1:49);
ad(50:100)=rp0(50:100);
//
//starting an unconstrained optimization
//[cout,x,grad,to]=optim(iirmod,x);
