Guest User

Untitled

a guest
Mar 18th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. % Lowpass digital filter with Chebyshev-I analog prototype
  2. %
  3.  
  4. function lowpass
  5. % Digital Filter Specifications:
  6. wp = 0.125*2*pi; % digital passband frequency in Hz (normalized)
  7. ws = 0.1375*2*pi; % digital stopband frequency in Hz (normalized)
  8. Rp = 0.5; % passband ripple in dB
  9. As = 20; % stopband attenuation in dB
  10. % Analog Prototype Specifications:
  11. Fs = 1; T = 1/Fs;
  12. OmegaP = (2/T)*tan(wp/2); % prewarp prototype passband frequency
  13. OmegaS = (2/T)*tan(ws/2); % prewarp prototype stopband frequency
  14. % Analog Chebyshev-1 Prototype Filter Calculation:
  15. [c, d] = chb1(OmegaP, OmegaS, Rp, As);
  16. % Bilinear Transformation:
  17. [b, a] = bilinear(cs, ds, Fs);
  18. %
  19. [db,mag,pha,grd,w] = freqz(b,a);
  20. plot(w*8000/2/pi,db);
  21. xlabel('frequency (Hz)'); ylabel('decibels'); title('Magnitude in dB');
  22.  
  23. endfunction
  24.  
  25. function [b,a] = chb1(Wp, Ws, Rp, As);
  26. % Analog Lowpass Filter Design: Chebyshev-1
  27. %
  28. % [b,a] = chb1(Wp, Ws, Rp, As);
  29. % b = Numerator coefficients of Ha(s)
  30. % a = Denominator coefficients of Ha(s)
  31. % Wp = Passband edge frequency in rad/sec
  32. % Ws = Stopband edge frequency in rad/sec
  33. % Rp = Passband ripple in dB
  34. % As = Stopband attenuation in dB
  35. %
  36. if Wp <= 0
  37. error('Passband edge must be larger than 0')
  38. end
  39. if Ws <= Wp
  40. error('Stopband edge must be larger than Passband edge')
  41. end
  42. if (Rp <= 0) | (As < 0)
  43. error('PB ripple and/or SB attenuation must be larger than 0')
  44. end
  45. ep = sqrt(10^(Rp/10)-1);
  46. A = 10^(As/20);
  47. OmegaC = Wp;
  48. OmegaR = Ws/Wp;
  49. g = sqrt(A*A-1)/ep;
  50. N = ceil(log10(g+sqrt(g*g-1))/log10(OmegaR+sqrt(OmegaR*OmegaR-1)));
  51. fprintf('\n*** Chebyshev-1 Filter Order = %2.0f \n',N);
  52. [b,a] = ap_chb1(N, Rp, OmegaC);
  53. endfunction
  54.  
  55.  
  56. function [b,a] = ap_chb1(N, Rp, Omegac);
  57. % Chebyshev-1 Analog Lowpass Filter Prototype
  58. %
  59. % [b,a] = ap_chb1(N, Rp, Omegac);
  60. % b = nemerator polynomial coefficients
  61. % a = denominator polynomial coefficients
  62. % N = Order of the elliptical filter
  63. % Rp = Passband Ripple in dB
  64. % Omegac = cutoff frequency in rad/sec
  65. %
  66. [z,p,k] = cheb1ap(N,Rp);
  67. a = real(poly(p));
  68. aNn = a(N+1);
  69. p = p*Omegac;
  70. a = real(poly(p));
  71. aNu = a(N+1);
  72. k = k*aNu/aNn;
  73. b0 = k;
  74. B = real(poly(z));
  75. b = k*B;
  76.  
  77. endfunction
Add Comment
Please, Sign In to add comment