1 ## Copyright (C) 2001 Paulo Neis <p_neis@yahoo.com.br>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
16 ## usage: [Zz, Zp, Zg] = ncauer(Rp, Rs, n)
18 ## Analog prototype for Cauer filter.
19 ## [z, p, g]=ncauer(Rp, Rs, ws)
20 ## Rp = Passband ripple
21 ## Rs = Stopband ripple
26 ## - Serra, Celso Penteado, Teoria e Projeto de Filtros, Campinas: CARTGRAF,
28 ## - Lamar, Marcus Vinicius, Notas de aula da disciplina TE 456 - Circuitos
29 ## Analogicos II, UFPR, 2001/2002.
31 function [zer, pol, T0]=ncauer(Rp, Rs, n)
33 ## Cutoff frequency = 1:
37 ws=__ellip_ws(n, Rp, Rs);
41 q0=(1/2)*((1-sqrt(k1))/(1+sqrt(k1)));
42 q= q0 + 2*q0^5 + 15*q0^9 + 150*q0^13; %(....)
43 D=(10^(0.1*Rs)-1)/(10^(0.1*Rp)-1);
45 ##Filter order maybe this, but not used now:
46 ##n=ceil(log10(16*D)/log10(1/q))
48 l=(1/(2*n))*log((10^(0.05*Rp)+1)/(10^(0.05*Rp)-1));
51 sig01=sig01+(-1)^m * q^(m*(m+1)) * sinh((2*m+1)*l);
54 sig02=sig02+(-1)^m * q^(m^2) * cosh(2*m*l);
56 sig0=abs((2*q^(1/4)*sig01)/(1+2*sig02));
58 w=sqrt((1+k*sig0^2)*(1+sig0^2/k));
75 soma1 = soma1 + 2*q^(1/4) * ((-1)^m * q^(m*(m+1)) * sin(((2*m+1)*pi*mu)/n));
79 soma2 = soma2 + 2*((-1)^m * q^(m^2) * cos((2*m*pi*mu)/n));
81 wi(ii)=(soma1/(1+soma2));
84 Vi=sqrt((1-(k.*(wi.^2))).*(1-(wi.^2)/k));
87 B0i=((sig0.*Vi).^2 + (w.*wi).^2)./((1+sig0^2.*wi.^2).^2);
88 B1i=(2 * sig0.*Vi)./(1 + sig0^2 * wi.^2);
92 T0=sig0*prod(B0i./A0i)*sqrt(ws);
94 T0=10^(-0.05*Rp)*prod(B0i./A0i);
98 zer=[i*sqrA0i, -i*sqrA0i];
101 pol=[(-2*sig0*Vi+2*i*wi.*w)./(2*(1+sig0^2*wi.^2)), (-2*sig0*Vi-2*i*wi.*w)./(2*(1+sig0^2*wi.^2))];
103 ##If n odd, there is a real pole -sig0:
114 ## usage: ws = __ellip_ws(n, rp, rs)
115 ## Calculate the stop band edge for the Cauer filter.
116 function ws=__ellip_ws(n, rp, rs)
117 kl0 = ((10^(0.1*rp)-1)/(10^(0.1*rs)-1));
119 int = ellipke([kl0 ; k0]);
123 kl = fminbnd(@(y) __ellip_ws_min(y,x) ,eps, 1-eps);
127 ## usage: err = __ellip_ws_min(kl, x)
128 function err=__ellip_ws_min(kl, x)
129 int=ellipke([kl; 1-kl]);