gusucode.com > 信号处理工具箱 - signal源码程序 > signal\signal\signal\bscost.m

    function n = bscost(wp,ind,WP,WS,rs,rp,type)
%BSCOST  Band Stop Cost function for order minimization w.r.t passband edge.
%   BSCOST(wp,ind,WP,WS,rs,rp,type) returns the order (non-integer in general)
%   for an analog band stop filter.  This is used by the order estimation
%   routines in minimizing the filter order.
%   Inputs:
%     wp - varying passband edge.
%     ind - index specifying which passband edge is being varied (1 == lower,
%           2 == upper).
%     WP - two element vector of fixed passband edges.
%     WS - two element vector of fixed stopband edges.
%     rs - amount in dB of attenuation in the stopband.
%     rp - amount in dB of ripple in the passband.
%     type - can be 'butter', 'cheby', or 'ellip'.
%   Output:
%     n - filter order (fractional).
%
%   See also BUTTORD, CHEB1ORD, CHEB2ORD, ELLIPORD.

%   Author(s): T. Krauss, 2-20-96
%   Copyright (c) 1988-98 by The MathWorks, Inc.
%       $Revision: 1.1 $
%   $Revision: 1.1 $  $Date: 1998/06/03 14:42:02 $

WP(ind) = wp;
WA=([ WS(1) -WS(2) ] *(WP(1)-WP(2)))./([WS(1) -WS(2)].^2 - WP(1)*WP(2));
WA=(WS*(WP(1)-WP(2)))./(WS.^2 - WP(1)*WP(2));

% find the minimum order filter to meet the more demanding spec:
WA=min(abs(WA));
switch type

case 'butter'
    n = ( log10( (10 .^ (0.1*abs(rs)) - 1)./ ...
        (10 .^ (0.1*abs(rp)) - 1) ) / (2*log10(WA)) );
case 'cheby'
    n=(acosh(sqrt((10^(.1*abs(rs))-1)/(10^(.1*abs(rp))-1)))/acosh(WA));
case 'ellip'
    epsilon = sqrt(10^(0.1*rp)-1);
    k1 = epsilon/sqrt(10^(0.1*rs)-1);
    k = 1/WA;
    capk = ellipke([k^2 1-k^2]);
    capk1 = ellipke([(k1^2) 1-(k1^2)]);
    n = (capk(1)*capk1(2)/(capk(2)*capk1(1)));
end