function C = Clead(wm,phim,n)
%C = clead(wm,phim,n)
%
% Lead network of the form C=Clead^n, where
%
%        alpha*s+wm
% Clag = -----------
%        s+wm*alpha
%
% alpha=sqrt(sqrt((1+sin(phim/n))/(1-sin(phim/n)))), where phim is the
% maximal phase lead achievable by C.
%
% Inputs:
%  wm
%  phim, in degrees (0<phim<90)
%  n (default n=1)
%
% Output:
%  C  the transfer function of the lead network
%
 if nargin == 2
   n = 1;
 elseif nargin < 2
   error('Two parameters must be used')
 end;
 if (phim < 0) | (phim/n >= 90),
   error('phim must be between 0 and 90')
 end;
 %
 phim = phim*pi/180/n;
 alpha = sqrt((1+sin(phim))/(1-sin(phim)));
 C = tf([alpha wm],[1 alpha*wm])^n;
