home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 8.ddi / SIGNAL.DI$ / CHEB1ORD.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  2.1 KB  |  69 lines

  1. function [order,wn] = cheb1ord(wp,ws,rp,rs,opt)
  2. %CHEB1ORD Chebyshev type I filter order selection.
  3. %    [N, Wn] = CHEB1ORD(Wp, Ws, Rp, Rs) returns the order N of the
  4. %    lowest order digital Chebyshev type I filter that loses no
  5. %    more than Rp dB in the passband and has at least Rs dB of
  6. %    attenuation in the stopband.  The passband runs from 0 to
  7. %    Wp and the stopband extends from Ws to 1.0, the Nyquist
  8. %    frequency.  CHEB1ORD also returns Wn, the Chebyshev
  9. %    natural frequency to use with CHEBY1 to achieve the 
  10. %    specifications.
  11. %    [N, Wn] = CHEB1ORD(Wp, Ws, Rp, Rs, 's') does the computation
  12. %    for an analog filter.
  13. %    See also CHEBY1, BUTTORD, ELLIPORD, and CHEB2ORD.
  14.  
  15. %    References: Rabiner and Gold, p 241.
  16.  
  17. %    L. Shure 6-9-88
  18. %    Updated, 11-13-92 T. Krauss
  19. %    Copyright (c) 1988, 1992 by the MathWorks, Inc.
  20.  
  21. if nargin == 4
  22.     opt = 'z';
  23. elseif nargin == 5
  24.     if ~strcmp(opt,'z') & ~strcmp(opt,'s')
  25.         error('Invalid option for final argument.');
  26.     end
  27. end
  28. np1 = length(wp);
  29. ns1 = length(ws);
  30. if (np1 ~= ns1)
  31.     error('The frequency vectors must both be the same length.')
  32. end
  33. ftype = 2*(np1 - 1);
  34. if wp(1) < ws(1)
  35.     ftype = ftype + 1;    % low (1) or reject (3)
  36. else
  37.     ftype = ftype + 2;    % high (2) or pass (4)
  38. end
  39.  
  40. % first, prewarp frequencies from digital (unit circle) to analog (imag. axis):
  41. if strcmp(opt,'z')    % digital
  42.     WPA=tan(pi*wp/2);
  43.     WSA=tan(pi*ws/2);
  44. else  % don't have to if analog already
  45.     WPA=wp;
  46.     WSA=ws;
  47. end
  48.  
  49. % next, transform to low pass prototype with passband edge of 1 and stopband
  50. % edges determined by the following: (see Rabiner and Gold, p.258)
  51. if ftype == 1    % low
  52.     WA=WSA/WPA;
  53. elseif ftype == 2    % high
  54.     WA=WPA/WSA;
  55. elseif ftype == 3    % stop
  56.     WA=(WSA*(WPA(1)-WPA(2)))./(WSA.^2 - WPA(1)*WPA(2));
  57. elseif ftype == 4    % pass
  58.     WA=(WSA.^2 - WPA(1)*WPA(2))./(WSA*(WPA(1)-WPA(2)));
  59. end
  60.  
  61. % find the minimum order cheby. type 1 filter to meet the more demanding spec:
  62. WA=min(abs(WA));
  63. order=ceil(acosh(sqrt((10^(.1*abs(rs))-1)/(10^(.1*abs(rp))-1)))/acosh(WA));
  64. % ref: M.E. Van Valkenburg, "Analog Filter Design", p.232, eqn 8.39
  65.  
  66. % natural frequencies are simply the given band-edges:
  67. wn=wp;
  68.  
  69.