1## Copyright (C) 2001 Paulo Neis 2## Copyright (C) 2018 Charles Praplan 3## 4## This program is free software: you can redistribute it and/or modify 5## it under the terms of the GNU General Public License as published by 6## the Free Software Foundation, either version 3 of the License, or 7## (at your option) any later version. 8## 9## This program is distributed in the hope that it will be useful, 10## but WITHOUT ANY WARRANTY; without even the implied warranty of 11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12## GNU General Public License for more details. 13## 14## You should have received a copy of the GNU General Public License 15## along with this program; see the file COPYING. If not, see 16## <https://www.gnu.org/licenses/>. 17 18## -*- texinfo -*- 19## @deftypefn {Function File} {@var{n} =} ellipord (@var{wp}, @var{ws}, @var{rp}, @var{rs}) 20## @deftypefnx {Function File} {@var{n} =} ellipord ([@var{wp1}, @var{wp2}], [@var{ws1}, @var{ws2}], @var{rp}, @var{rs}) 21## @deftypefnx {Function File} {@var{n} =} ellipord ([@var{wp1}, @var{wp2}], [@var{ws1}, @var{ws2}], @var{rp}, @var{rs}, "s") 22## @deftypefnx {Function File} {[@var{n}, @var{wc}] =} ellipord (@dots{}) 23## Compute the minimum filter order of an elliptic filter with the desired 24## response characteristics. The filter frequency band edges are specified 25## by the passband frequency @var{wp} and stopband frequency @var{ws}. 26## Frequencies are normalized to the Nyquist frequency in the range [0,1]. 27## @var{rp} is the allowable passband ripple measured in decibels, and @var{rs} 28## is the minimum attenuation in the stop band, also in decibels. The output 29## arguments @var{n} and @var{wc} can be given as inputs to @code{ellip}. 30## 31## If @var{wp} and @var{ws} are scalars, then @var{wp} is the passband cutoff 32## frequency and @var{ws} is the stopband edge frequency. If @var{ws} is 33## greater than @var{wp}, the filter is a low-pass filter. If @var{wp} is 34## greater than @var{ws}, the filter is a high-pass filter. 35## 36## If @var{wp} and @var{ws} are vectors of length 2, then @var{wp} defines the 37## passband interval and @var{ws} defines the stopband interval. If @var{wp} 38## is contained within @var{ws} (@var{ws1} < @var{wp1} < @var{wp2} < @var{ws2}), 39## the filter is a band-pass filter. If @var{ws} is contained within @var{wp} 40## (@var{wp1} < @var{ws1} < @var{ws2} < @var{wp2}), the filter is a band-stop 41## or band-reject filter. 42## 43## If the optional argument @code{"s"} is given, the minimum order for an analog 44## elliptic filter is computed. All frequencies @var{wp} and @var{ws} are 45## specified in radians per second. 46## 47## Reference: Lamar, Marcus Vinicius, @cite{Notas de aula da disciplina TE 456 - 48## Circuitos Analogicos II}, UFPR, 2001/2002. 49## @seealso{buttord, cheb1ord, cheb2ord, ellip} 50## @end deftypefn 51 52function [n, Wp] = ellipord (Wp, Ws, Rp, Rs, opt) 53 54 if (nargin < 4 || nargin > 5) 55 print_usage (); 56 elseif (nargin == 5 && ! strcmp (opt, "s")) 57 error ("ellipord: OPT must be the string \"s\""); 58 endif 59 60 if (nargin == 5 && strcmp (opt, "s")) 61 s_domain = true; 62 else 63 s_domain = false; 64 endif 65 66 if (s_domain) 67 validate_filter_bands ("ellipord", Wp, Ws, "s"); 68 else 69 validate_filter_bands ("ellipord", Wp, Ws); 70 endif 71 72 if (s_domain) 73 # No prewarp in case of analog filter 74 Wpw = Wp; 75 Wsw = Ws; 76 else 77 ## sampling frequency of 2 Hz 78 T = 2; 79 80 Wpw = (2 / T) .* tan (pi .* Wp ./ T); # prewarp 81 Wsw = (2 / T) .* tan (pi .* Ws ./ T); # prewarp 82 endif 83 84 ## pass/stop band to low pass filter transform: 85 if (length (Wpw) == 2 && length (Wsw) == 2) 86 87 ## Band-pass filter 88 if (Wpw(1) > Wsw(1)) 89 90 ## Modify band edges if not symmetrical. For a band-pass filter, 91 ## the lower or upper stopband limit is moved, resulting in a smaller 92 ## stopband than the caller requested. 93 if ((Wpw(1) * Wpw(2)) < (Wsw(1) * Wsw(2))) 94 Wsw(2) = Wpw(1) * Wpw(2) / Wsw(1); 95 else 96 Wsw(1) = Wpw(1) * Wpw(2) / Wsw(2); 97 endif 98 99 wp = Wpw(2) - Wpw(1); 100 ws = Wsw(2) - Wsw(1); 101 102 ## Band-stop / band-reject / notch filter 103 else 104 105 ## Modify band edges if not symmetrical. For a band-stop filter, 106 ## the lower or upper passband limit is moved, resulting in a smaller 107 ## rejection band than the caller requested. 108 if ((Wpw(1) * Wpw(2)) > (Wsw(1) * Wsw(2))) 109 Wpw(2) = Wsw(1) * Wsw(2) / Wpw(1); 110 else 111 Wpw(1) = Wsw(1) * Wsw(2) / Wpw(2); 112 endif 113 114 w02 = Wpw(1) * Wpw(2); 115 wp = w02 / (Wpw(2) - Wpw(1)); 116 ws = w02 / (Wsw(2) - Wsw(1)); 117 118 endif 119 ws = ws / wp; 120 wp = 1; 121 122 ## High-pass filter 123 elseif (Wpw > Wsw) 124 wp = Wsw; 125 ws = Wpw; 126 127 ## Low-pass filter 128 else 129 wp = Wpw; 130 ws = Wsw; 131 endif 132 133 k = wp / ws; 134 k1 = sqrt (1 - k^2); 135 q0 = (1/2) * ((1 - sqrt (k1)) / (1 + sqrt (k1))); 136 q = q0 + 2 * q0^5 + 15 * q0^9 + 150 * q0^13; #(....) 137 D = (10 ^ (0.1 * Rs) - 1) / (10 ^ (0.1 * Rp) - 1); 138 139 n = ceil (log10 (16 * D) / log10 (1 / q)); 140 141 if (s_domain) 142 # No prewarp in case of analog filter 143 Wp = Wpw; 144 else 145 # Inverse frequency warping for discrete-time filter 146 Wp = atan (Wpw .* (T / 2)) .* (T / pi); 147 endif 148 149endfunction 150 151%!demo 152%! fs = 44100; 153%! Npts = fs; 154%! fpass = 4000; 155%! fstop = 13713; 156%! Rpass = 3; 157%! Rstop = 40; 158%! Wpass = 2/fs * fpass; 159%! Wstop = 2/fs * fstop; 160%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 161%! [b, a] = ellip (n, Rpass, Rstop, Wn); 162%! f = 0:fs/2; 163%! W = f * (2 * pi / fs); 164%! H = freqz (b, a, W); 165%! plot (f, 20 * log10 (abs (H))); 166%! outline_lp_pass_x = [f(2) , fpass(1), fpass(1)]; 167%! outline_lp_pass_y = [-Rpass, -Rpass , -80]; 168%! outline_lp_stop_x = [f(2) , fstop(1), fstop(1), max(f)]; 169%! outline_lp_stop_y = [0 , 0 , -Rstop , -Rstop]; 170%! hold on 171%! plot (outline_lp_pass_x, outline_lp_pass_y, "m", outline_lp_stop_x, outline_lp_stop_y, "m"); 172%! ylim ([-80, 0]); 173%! grid on 174%! xlabel ("Frequency (Hz)"); 175%! ylabel ("Attenuation (dB)"); 176%! title ("2nd order digital elliptical low-pass (without margin)"); 177 178%!demo 179%! fs = 44100; 180%! Npts = fs; 181%! fpass = 4000; 182%! fstop = 13712; 183%! Rpass = 3; 184%! Rstop = 40; 185%! Wpass = 2/fs * fpass; 186%! Wstop = 2/fs * fstop; 187%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 188%! [b, a] = ellip (n, Rpass, Rstop, Wn); 189%! f = 0:fs/2; 190%! W = f * (2 * pi / fs); 191%! H = freqz (b, a, W); 192%! plot (f, 20 * log10 (abs (H))); 193%! outline_lp_pass_x = [f(2) , fpass(1), fpass(1)]; 194%! outline_lp_pass_y = [-Rpass, -Rpass , -80]; 195%! outline_lp_stop_x = [f(2) , fstop(1), fstop(1), max(f)]; 196%! outline_lp_stop_y = [0 , 0 , -Rstop , -Rstop]; 197%! hold on 198%! plot (outline_lp_pass_x, outline_lp_pass_y, "m", outline_lp_stop_x, outline_lp_stop_y, "m"); 199%! ylim ([-80, 0]); 200%! grid on 201%! xlabel ("Frequency (Hz)"); 202%! ylabel ("Attenuation (dB)"); 203%! title ("3rd order digital elliptical low-pass (just exceeds 2nd order i.e. large margin)"); 204 205%!demo 206%! fs = 44100; 207%! Npts = fs; 208%! fstop = 4000; 209%! fpass = 13713; 210%! Rpass = 3; 211%! Rstop = 40; 212%! Wpass = 2/fs * fpass; 213%! Wstop = 2/fs * fstop; 214%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 215%! [b, a] = ellip (n, Rpass, Rstop, Wn, "high"); 216%! f = 0:fs/2; 217%! W = f * (2 * pi / fs); 218%! H = freqz (b, a, W); 219%! plot (f, 20 * log10 (abs (H))); 220%! outline_hp_pass_x = [fpass(1), fpass(1), max(f)]; 221%! outline_hp_pass_y = [-80 , -Rpass , -Rpass]; 222%! outline_hp_stop_x = [min(f) , fstop(1), fstop(1), max(f)]; 223%! outline_hp_stop_y = [-Rstop , -Rstop , 0 , 0 ]; 224%! hold on 225%! plot (outline_hp_pass_x, outline_hp_pass_y, "m", outline_hp_stop_x, outline_hp_stop_y, "m"); 226%! ylim ([-80, 0]); 227%! grid on 228%! xlabel ("Frequency (Hz)"); 229%! ylabel ("Attenuation (dB)"); 230%! title ("2nd order digital elliptical high-pass (without margin)"); 231 232%!demo 233%! fs = 44100; 234%! Npts = fs; 235%! fstop = 4000; 236%! fpass = 13712; 237%! Rpass = 3; 238%! Rstop = 40; 239%! Wpass = 2/fs * fpass; 240%! Wstop = 2/fs * fstop; 241%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 242%! [b, a] = ellip (n, Rpass, Rstop, Wn, "high"); 243%! f = 0:fs/2; 244%! W = f * (2 * pi / fs); 245%! H = freqz (b, a, W); 246%! plot (f, 20 * log10 (abs (H))); 247%! outline_hp_pass_x = [fpass(1), fpass(1), max(f)]; 248%! outline_hp_pass_y = [-80 , -Rpass , -Rpass]; 249%! outline_hp_stop_x = [min(f) , fstop(1), fstop(1), max(f)]; 250%! outline_hp_stop_y = [-Rstop , -Rstop , 0 , 0 ]; 251%! hold on 252%! plot (outline_hp_pass_x, outline_hp_pass_y, "m", outline_hp_stop_x, outline_hp_stop_y, "m"); 253%! ylim ([-80, 0]); 254%! grid on 255%! xlabel ("Frequency (Hz)"); 256%! ylabel ("Attenuation (dB)"); 257%! title ("3rd order digital elliptical high-pass (just exceeds 2nd order i.e. large margin)"); 258 259%!demo 260%! fs = 44100; 261%! Npts = fs; 262%! fpass = [9500 9750]; 263%! fstop = [8500 10261]; 264%! Rpass = 3; 265%! Rstop = 40; 266%! Wpass = 2/fs * fpass; 267%! Wstop = 2/fs * fstop; 268%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 269%! [b, a] = ellip (n, Rpass, Rstop, Wn); 270%! f = 5000:15000; 271%! W = f * (2 * pi / fs); 272%! H = freqz (b, a, W); 273%! plot (f, 20 * log10 (abs (H))) 274%! outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)]; 275%! outline_bp_pass_y = [-80 , -Rpass , -Rpass , -80]; 276%! outline_bp_stop_x = [min(f) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 277%! outline_bp_stop_y = [-Rstop , -Rstop , 0 , 0 , -Rstop , -Rstop]; 278%! hold on 279%! plot (outline_bp_pass_x, outline_bp_pass_y, "m", outline_bp_stop_x, outline_bp_stop_y, "m") 280%! xlim ([f(1), f(end)]); 281%! ylim ([-80, 0]); 282%! grid on 283%! xlabel ("Frequency (Hz)"); 284%! ylabel ("Attenuation (dB)"); 285%! title ("4th order digital elliptical band-pass (without margin) limitation on upper freq"); 286 287%!demo 288%! fs = 44100; 289%! Npts = fs; 290%! fpass = [9500 9750]; 291%! fstop = [9000 10700]; 292%! Rpass = 3; 293%! Rstop = 40; 294%! Wpass = 2/fs * fpass; 295%! Wstop = 2/fs * fstop; 296%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 297%! [b, a] = ellip (n, Rpass, Rstop, Wn); 298%! f = 5000:15000; 299%! W = f * (2 * pi / fs); 300%! H = freqz (b, a, W); 301%! plot (f, 20 * log10 (abs (H))) 302%! outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)]; 303%! outline_bp_pass_y = [-80 , -Rpass , -Rpass , -80]; 304%! outline_bp_stop_x = [min(f) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 305%! outline_bp_stop_y = [-Rstop , -Rstop , 0 , 0 , -Rstop , -Rstop]; 306%! hold on 307%! plot (outline_bp_pass_x, outline_bp_pass_y, "m", outline_bp_stop_x, outline_bp_stop_y, "m") 308%! xlim ([f(1), f(end)]); 309%! ylim ([-80, 0]); 310%! grid on 311%! xlabel ("Frequency (Hz)"); 312%! ylabel ("Attenuation (dB)"); 313%! title ("4th order digital elliptical band-pass (without margin) limitation on lower freq"); 314 315%!demo 316%! fs = 44100; 317%! Npts = fs; 318%! fpass = [9500 9750]; 319%! fstop = [8500 10260]; 320%! Rpass = 3; 321%! Rstop = 40; 322%! Wpass = 2/fs * fpass; 323%! Wstop = 2/fs * fstop; 324%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 325%! [b, a] = ellip (n, Rpass, Rstop, Wn); 326%! f = 5000:15000; 327%! W = f * (2 * pi / fs); 328%! H = freqz (b, a, W); 329%! plot (f, 20 * log10 (abs (H))) 330%! outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)]; 331%! outline_bp_pass_y = [-80 , -Rpass , -Rpass , -80]; 332%! outline_bp_stop_x = [min(f) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 333%! outline_bp_stop_y = [-Rstop , -Rstop , 0 , 0 , -Rstop , -Rstop]; 334%! hold on 335%! plot (outline_bp_pass_x, outline_bp_pass_y, "m", outline_bp_stop_x, outline_bp_stop_y, "m") 336%! xlim ([f(1), f(end)]); 337%! ylim ([-80, 0]); 338%! grid on 339%! xlabel ("Frequency (Hz)"); 340%! ylabel ("Attenuation (dB)"); 341%! title ("6th order digital elliptical band-pass (just exceeds 4th order i.e. large margin) limitation on upper freq"); 342 343%!demo 344%! fs = 44100; 345%! Npts = fs; 346%! fpass = [9500 9750]; 347%! fstop = [9001 10700]; 348%! Rpass = 3; 349%! Rstop = 40; 350%! Wpass = 2/fs * fpass; 351%! Wstop = 2/fs * fstop; 352%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 353%! [b, a] = ellip (n, Rpass, Rstop, Wn); 354%! f = 5000:15000; 355%! W = f * (2 * pi / fs); 356%! H = freqz (b, a, W); 357%! plot (f, 20 * log10 (abs (H))) 358%! outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)]; 359%! outline_bp_pass_y = [-80 , -Rpass , -Rpass , -80]; 360%! outline_bp_stop_x = [min(f) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 361%! outline_bp_stop_y = [-Rstop , -Rstop , 0 , 0 , -Rstop , -Rstop]; 362%! hold on 363%! plot (outline_bp_pass_x, outline_bp_pass_y, "m", outline_bp_stop_x, outline_bp_stop_y, "m") 364%! xlim ([f(1), f(end)]); 365%! ylim ([-80, 0]); 366%! grid on 367%! xlabel ("Frequency (Hz)"); 368%! ylabel ("Attenuation (dB)"); 369%! title ("6th order digital elliptical band-pass (just exceeds 4th order i.e. large margin) limitation on lower freq"); 370 371%!demo 372%! fs = 44100; 373%! Npts = fs; 374%! fstop = [9875 10126.5823]; 375%! fpass = [8500 11073]; 376%! Rpass = 0.5; 377%! Rstop = 40; 378%! Wpass = 2/fs * fpass; 379%! Wstop = 2/fs * fstop; 380%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 381%! [b, a] = ellip (n, Rpass, Rstop, Wn, "stop"); 382%! f = 5000:15000; 383%! W = f * (2 * pi / fs); 384%! H = freqz (b, a, W); 385%! plot (f, 20 * log10 (abs (H))) 386%! outline_notch_pass_x_a = [min(f) , fpass(1), fpass(1)]; 387%! outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)]; 388%! outline_notch_pass_y_a = [-Rpass , -Rpass , -80]; 389%! outline_notch_pass_y_b = [-80 , -Rpass , -Rpass]; 390%! outline_notch_stop_x = [min(f) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 391%! outline_notch_stop_y = [0 , 0 , -Rstop , -Rstop , 0 , 0 ]; 392%! hold on 393%! plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m", outline_notch_pass_x_b, outline_notch_pass_y_b, "m", outline_notch_stop_x, outline_notch_stop_y, "m") 394%! xlim ([f(1), f(end)]); 395%! ylim ([-80, 0]); 396%! grid on 397%! xlabel ("Frequency (Hz)"); 398%! ylabel ("Attenuation (dB)"); 399%! title ("4th order digital elliptical notch (without margin) limit on upper freq"); 400 401%!demo 402%! fs = 44100; 403%! Npts = fs; 404%! fstop = [9875 10126.5823]; 405%! fpass = [8952 12000]; 406%! Rpass = 0.5; 407%! Rstop = 40; 408%! Wpass = 2/fs * fpass; 409%! Wstop = 2/fs * fstop; 410%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 411%! [b, a] = ellip (n, Rpass, Rstop, Wn, "stop"); 412%! f = 5000:15000; 413%! W = f * (2 * pi / fs); 414%! H = freqz (b, a, W); 415%! plot (f, 20 * log10 (abs (H))) 416%! outline_notch_pass_x_a = [min(f) , fpass(1), fpass(1)]; 417%! outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)]; 418%! outline_notch_pass_y_a = [-Rpass , -Rpass , -80]; 419%! outline_notch_pass_y_b = [-80 , -Rpass , -Rpass]; 420%! outline_notch_stop_x = [min(f) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 421%! outline_notch_stop_y = [0 , 0 , -Rstop , -Rstop , 0 , 0 ]; 422%! hold on 423%! plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m", outline_notch_pass_x_b, outline_notch_pass_y_b, "m", outline_notch_stop_x, outline_notch_stop_y, "m") 424%! xlim ([f(1), f(end)]); 425%! ylim ([-80, 0]); 426%! grid on 427%! xlabel ("Frequency (Hz)"); 428%! ylabel ("Attenuation (dB)"); 429%! title ("4th order digital elliptical notch (without margin) limit on lower freq"); 430 431%!demo 432%! fs = 44100; 433%! Npts = fs; 434%! fstop = [9875 10126.5823]; 435%! fpass = [8500 11072]; 436%! Rpass = 0.5; 437%! Rstop = 40; 438%! Wpass = 2/fs * fpass; 439%! Wstop = 2/fs * fstop; 440%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 441%! [b, a] = ellip (n, Rpass, Rstop, Wn, "stop"); 442%! f = 5000:15000; 443%! W = f * (2 * pi / fs); 444%! H = freqz (b, a, W); 445%! plot (f, 20 * log10 (abs (H))) 446%! outline_notch_pass_x_a = [min(f) , fpass(1), fpass(1)]; 447%! outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)]; 448%! outline_notch_pass_y_a = [-Rpass , -Rpass , -80]; 449%! outline_notch_pass_y_b = [-80 , -Rpass , -Rpass]; 450%! outline_notch_stop_x = [min(f) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 451%! outline_notch_stop_y = [0 , 0 , -Rstop , -Rstop , 0 , 0 ]; 452%! hold on 453%! plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m", outline_notch_pass_x_b, outline_notch_pass_y_b, "m", outline_notch_stop_x, outline_notch_stop_y, "m") 454%! xlim ([f(1), f(end)]); 455%! ylim ([-80, 0]); 456%! grid on 457%! xlabel ("Frequency (Hz)"); 458%! ylabel ("Attenuation (dB)"); 459%! title ("6th order digital elliptical notch (just exceeds 4th order) limit on upper freq"); 460 461%!demo 462%! fs = 44100; 463%! Npts = fs; 464%! fstop = [9875 10126.5823]; 465%! fpass = [8953 12000]; 466%! Rpass = 0.5; 467%! Rstop = 40; 468%! Wpass = 2/fs * fpass; 469%! Wstop = 2/fs * fstop; 470%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop) 471%! [b, a] = ellip (n, Rpass, Rstop, Wn, "stop"); 472%! f = 5000:15000; 473%! W = f * (2 * pi / fs); 474%! H = freqz (b, a, W); 475%! plot (f, 20 * log10 (abs (H))) 476%! outline_notch_pass_x_a = [min(f) , fpass(1), fpass(1)]; 477%! outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)]; 478%! outline_notch_pass_y_a = [-Rpass , -Rpass , -80]; 479%! outline_notch_pass_y_b = [-80 , -Rpass , -Rpass]; 480%! outline_notch_stop_x = [min(f) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 481%! outline_notch_stop_y = [0 , 0 , -Rstop , -Rstop , 0 , 0 ]; 482%! hold on 483%! plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m", outline_notch_pass_x_b, outline_notch_pass_y_b, "m", outline_notch_stop_x, outline_notch_stop_y, "m") 484%! xlim ([f(1), f(end)]); 485%! ylim ([-80, 0]); 486%! grid on 487%! xlabel ("Frequency (Hz)"); 488%! ylabel ("Attenuation (dB)"); 489%! title ("6th order digital elliptical notch (just exceeds 4th order) limit on lower freq"); 490 491%!demo 492%! fpass = 4000; 493%! fstop = 20224; 494%! Rpass = 3; 495%! Rstop = 40; 496%! Wpass = 2*pi * fpass; 497%! Wstop = 2*pi * fstop; 498%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 499%! [b, a] = ellip (n, Rpass, Rstop, Wn, "s"); 500%! f = 1000:10:100000; 501%! W = 2*pi * f; 502%! H = freqs (b, a, W); 503%! semilogx(f, 20 * log10 (abs (H))) 504%! outline_lp_pass_x = [f(2) , fpass(1), fpass(1)]; 505%! outline_lp_pass_y = [-Rpass, -Rpass , -80]; 506%! outline_lp_stop_x = [f(2) , fstop(1), fstop(1), max(f)]; 507%! outline_lp_stop_y = [0 , 0 , -Rstop , -Rstop]; 508%! hold on 509%! plot (outline_lp_pass_x, outline_lp_pass_y, "m", outline_lp_stop_x, outline_lp_stop_y, "m") 510%! ylim ([-80, 0]); 511%! grid on 512%! xlabel ("Frequency (Hz)"); 513%! ylabel ("Attenuation (dB)"); 514%! title ("2nd order analog elliptical low-pass (without margin)"); 515 516%!demo 517%! fpass = 4000; 518%! fstop = 20223; 519%! Rpass = 3; 520%! Rstop = 40; 521%! Wpass = 2*pi * fpass; 522%! Wstop = 2*pi * fstop; 523%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 524%! [b, a] = ellip (n, Rpass, Rstop, Wn, "s"); 525%! f = 1000:10:100000; 526%! W = 2*pi * f; 527%! H = freqs (b, a, W); 528%! semilogx (f, 20 * log10 (abs (H))) 529%! outline_lp_pass_x = [f(2) , fpass(1), fpass(1)]; 530%! outline_lp_pass_y = [-Rpass, -Rpass , -80]; 531%! outline_lp_stop_x = [f(2) , fstop(1), fstop(1), max(f)]; 532%! outline_lp_stop_y = [0 , 0 , -Rstop , -Rstop]; 533%! hold on 534%! plot (outline_lp_pass_x, outline_lp_pass_y, "m", outline_lp_stop_x, outline_lp_stop_y, "m") 535%! ylim ([-80, 0]); 536%! grid on 537%! xlabel ("Frequency (Hz)"); 538%! ylabel ("Attenuation (dB)"); 539%! title ("3rd order analog elliptical low-pass (just exceeds 2nd order i.e. large margin)"); 540 541%!demo 542%! fstop = 4000; 543%! fpass = 20224; 544%! Rpass = 3; 545%! Rstop = 40; 546%! Wpass = 2*pi * fpass; 547%! Wstop = 2*pi * fstop; 548%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 549%! [b, a] = ellip (n, Rpass, Rstop, Wn, "high", "s"); 550%! f = 1000:10:100000; 551%! W = 2*pi * f; 552%! H = freqs (b, a, W); 553%! semilogx (f, 20 * log10 (abs (H))) 554%! outline_hp_pass_x = [fpass(1), fpass(1), max(f)]; 555%! outline_hp_pass_y = [-80 , -Rpass , -Rpass]; 556%! outline_hp_stop_x = [f(2) , fstop(1), fstop(1), max(f)]; 557%! outline_hp_stop_y = [-Rstop , -Rstop , 0 , 0 ]; 558%! hold on 559%! plot (outline_hp_pass_x, outline_hp_pass_y, "m", outline_hp_stop_x, outline_hp_stop_y, "m") 560%! ylim ([-80, 0]); 561%! grid on 562%! xlabel ("Frequency (Hz)"); 563%! ylabel ("Attenuation (dB)"); 564%! title ("2nd order analog elliptical high-pass (without margin)"); 565 566%!demo 567%! fstop = 4000; 568%! fpass = 20223; 569%! Rpass = 3; 570%! Rstop = 40; 571%! Wpass = 2*pi * fpass; 572%! Wstop = 2*pi * fstop; 573%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 574%! [b, a] = ellip (n, Rpass, Rstop, Wn, "high", "s"); 575%! f = 1000:10:100000; 576%! W = 2*pi * f; 577%! H = freqs (b, a, W); 578%! semilogx (f, 20 * log10 (abs (H))) 579%! outline_hp_pass_x = [fpass(1), fpass(1), max(f)]; 580%! outline_hp_pass_y = [-80 , -Rpass , -Rpass]; 581%! outline_hp_stop_x = [f(2) , fstop(1), fstop(1), max(f)]; 582%! outline_hp_stop_y = [-Rstop , -Rstop , 0 , 0 ]; 583%! hold on 584%! plot (outline_hp_pass_x, outline_hp_pass_y, "m", outline_hp_stop_x, outline_hp_stop_y, "m") 585%! ylim ([-80, 0]); 586%! grid on 587%! xlabel ("Frequency (Hz)"); 588%! ylabel ("Attenuation (dB)"); 589%! title ("3rd order analog elliptical high-pass (just exceeds 2nd order i.e. large margin)"); 590 591%!demo 592%! fpass = [9875 10126.5823]; 593%! fstop = [9000 10657]; 594%! Rpass = 3; 595%! Rstop = 40; 596%! fcenter = sqrt (fpass(1) * fpass(2)); 597%! Wpass = 2*pi * fpass; 598%! Wstop = 2*pi * fstop; 599%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 600%! [b, a] = ellip (n, Rpass, Rstop, Wn, "s"); 601%! f = 5000:15000; 602%! W = 2*pi * f; 603%! H = freqs (b, a, W); 604%! plot (f, 20 * log10 (abs (H))) 605%! outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)]; 606%! outline_bp_pass_y = [-80 , -Rpass , -Rpass , -80]; 607%! outline_bp_stop_x = [f(2) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 608%! outline_bp_stop_y = [-Rstop , -Rstop , 0 , 0 , -Rstop , -Rstop]; 609%! hold on 610%! plot (outline_bp_pass_x, outline_bp_pass_y, "m", outline_bp_stop_x, outline_bp_stop_y, "m") 611%! xlim ([f(1), f(end)]); 612%! ylim ([-80, 0]); 613%! grid on 614%! xlabel ("Frequency (Hz)"); 615%! ylabel ("Attenuation (dB)"); 616%! title ("4th order analog elliptical band-pass (without margin) limitation on upper freq"); 617 618%!demo 619%! fpass = [9875 10126.5823]; 620%! fstop = [9384 12000]; 621%! Rpass = 3; 622%! Rstop = 40; 623%! fcenter = sqrt (fpass(1) * fpass(2)); 624%! Wpass = 2*pi * fpass; 625%! Wstop = 2*pi * fstop; 626%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 627%! [b, a] = ellip (n, Rpass, Rstop, Wn, "s"); 628%! f = 5000:15000; 629%! W = 2*pi * f; 630%! H = freqs (b, a, W); 631%! plot (f, 20 * log10 (abs (H))) 632%! outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)]; 633%! outline_bp_pass_y = [-80 , -Rpass , -Rpass , -80]; 634%! outline_bp_stop_x = [f(2) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 635%! outline_bp_stop_y = [-Rstop , -Rstop , 0 , 0 , -Rstop , -Rstop]; 636%! hold on 637%! plot (outline_bp_pass_x, outline_bp_pass_y, "m", outline_bp_stop_x, outline_bp_stop_y, "m") 638%! xlim ([f(1), f(end)]); 639%! ylim ([-80, 0]); 640%! grid on 641%! xlabel ("Frequency (Hz)"); 642%! ylabel ("Attenuation (dB)"); 643%! title ("4th order analog elliptical band-pass (without margin) limitation on lower freq"); 644 645%!demo 646%! fpass = [9875 10126.5823]; 647%! fstop = [9000 10656]; 648%! Rpass = 3; 649%! Rstop = 40; 650%! fcenter = sqrt (fpass(1) * fpass(2)); 651%! Wpass = 2*pi * fpass; 652%! Wstop = 2*pi * fstop; 653%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 654%! [b, a] = ellip (n, Rpass, Rstop, Wn, "s"); 655%! f = 5000:15000; 656%! W = 2*pi * f; 657%! H = freqs (b, a, W); 658%! plot (f, 20 * log10 (abs (H))) 659%! outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)]; 660%! outline_bp_pass_y = [-80 , -Rpass , -Rpass , -80]; 661%! outline_bp_stop_x = [f(2) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 662%! outline_bp_stop_y = [-Rstop , -Rstop , 0 , 0 , -Rstop , -Rstop]; 663%! hold on 664%! plot (outline_bp_pass_x, outline_bp_pass_y, "m", outline_bp_stop_x, outline_bp_stop_y, "m") 665%! xlim ([f(1), f(end)]); 666%! ylim ([-80, 0]); 667%! grid on 668%! xlabel ("Frequency (Hz)"); 669%! ylabel ("Attenuation (dB)"); 670%! title ("6th order analog elliptical band-pass (just exceeds 4th order i.e. large margin) limitation on upper freq"); 671 672%!demo 673%! fpass = [9875 10126.5823]; 674%! fstop = [9385 12000]; 675%! Rpass = 3; 676%! Rstop = 40; 677%! fcenter = sqrt (fpass(1) * fpass(2)); 678%! Wpass = 2*pi * fpass; 679%! Wstop = 2*pi * fstop; 680%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 681%! [b, a] = ellip (n, Rpass, Rstop, Wn, "s"); 682%! f = 5000:15000; 683%! W = 2*pi * f; 684%! H = freqs (b, a, W); 685%! plot (f, 20 * log10 (abs (H))) 686%! outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)]; 687%! outline_bp_pass_y = [-80 , -Rpass , -Rpass , -80]; 688%! outline_bp_stop_x = [f(2) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 689%! outline_bp_stop_y = [-Rstop , -Rstop , 0 , 0 , -Rstop , -Rstop]; 690%! hold on 691%! plot (outline_bp_pass_x, outline_bp_pass_y, "m", outline_bp_stop_x, outline_bp_stop_y, "m") 692%! xlim ([f(1), f(end)]); 693%! ylim ([-80, 0]); 694%! grid on 695%! xlabel ("Frequency (Hz)"); 696%! ylabel ("Attenuation (dB)"); 697%! title ("6th order analog elliptical band-pass (just exceeds 4th order i.e. large margin) limitation on lower freq"); 698 699%!demo 700%! fstop = [9875 10126.5823]; 701%! fpass = [9000 10657]; 702%! Rpass = 3; 703%! Rstop = 40; 704%! fcenter = sqrt (fpass(1) * fpass(2)); 705%! Wpass = 2*pi * fpass; 706%! Wstop = 2*pi * fstop; 707%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 708%! [b, a] = ellip (n, Rpass, Rstop, Wn, "stop", "s"); 709%! f = 5000:15000; 710%! W = 2*pi * f; 711%! H = freqs (b, a, W); 712%! plot (f, 20 * log10 (abs (H))) 713%! outline_notch_pass_x_a = [f(2) , fpass(1), fpass(1)]; 714%! outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)]; 715%! outline_notch_pass_y_a = [-Rpass , -Rpass , -80]; 716%! outline_notch_pass_y_b = [-80 , -Rpass , -Rpass]; 717%! outline_notch_stop_x = [f(2) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 718%! outline_notch_stop_y = [0 , 0 , -Rstop , -Rstop , 0 , 0 ]; 719%! hold on 720%! plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m", outline_notch_pass_x_b, outline_notch_pass_y_b, "m", outline_notch_stop_x, outline_notch_stop_y, "m") 721%! xlim ([f(1), f(end)]); 722%! ylim ([-80, 0]); 723%! grid on 724%! xlabel ("Frequency (Hz)"); 725%! ylabel ("Attenuation (dB)"); 726%! title ("4th order analog elliptical notch (without margin) limit on upper freq"); 727 728%!demo 729%! fstop = [9875 10126.5823]; 730%! fpass = [9384 12000]; 731%! Rpass = 3; 732%! Rstop = 40; 733%! fcenter = sqrt (fpass(1) * fpass(2)); 734%! Wpass = 2*pi * fpass; 735%! Wstop = 2*pi * fstop; 736%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 737%! [b, a] = ellip (n, Rpass, Rstop, Wn, "stop", "s"); 738%! f = 5000:15000; 739%! W = 2*pi * f; 740%! H = freqs (b, a, W); 741%! plot (f, 20 * log10 (abs (H))) 742%! outline_notch_pass_x_a = [f(2) , fpass(1), fpass(1)]; 743%! outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)]; 744%! outline_notch_pass_y_a = [-Rpass , -Rpass , -80]; 745%! outline_notch_pass_y_b = [-80 , -Rpass , -Rpass]; 746%! outline_notch_stop_x = [f(2) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 747%! outline_notch_stop_y = [0 , 0 , -Rstop , -Rstop , 0 , 0 ]; 748%! hold on 749%! plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m", outline_notch_pass_x_b, outline_notch_pass_y_b, "m", outline_notch_stop_x, outline_notch_stop_y, "m") 750%! xlim ([f(1), f(end)]); 751%! ylim ([-80, 0]); 752%! grid on 753%! xlabel ("Frequency (Hz)"); 754%! ylabel ("Attenuation (dB)"); 755%! title ("4th order analog elliptical notch (without margin) limit on lower freq"); 756 757%!demo 758%! fstop = [9875 10126.5823]; 759%! fpass = [9000 10656]; 760%! Rpass = 3; 761%! Rstop = 40; 762%! fcenter = sqrt (fpass(1) * fpass(2)); 763%! Wpass = 2*pi * fpass; 764%! Wstop = 2*pi * fstop; 765%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 766%! [b, a] = ellip (n, Rpass, Rstop, Wn, "stop", "s"); 767%! f = 5000:15000; 768%! W = 2*pi * f; 769%! H = freqs (b, a, W); 770%! plot (f, 20 * log10 (abs (H))) 771%! outline_notch_pass_x_a = [f(2) , fpass(1), fpass(1)]; 772%! outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)]; 773%! outline_notch_pass_y_a = [-Rpass , -Rpass , -80]; 774%! outline_notch_pass_y_b = [-80 , -Rpass , -Rpass]; 775%! outline_notch_stop_x = [f(2) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 776%! outline_notch_stop_y = [0 , 0 , -Rstop , -Rstop , 0 , 0 ]; 777%! hold on 778%! plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m", outline_notch_pass_x_b, outline_notch_pass_y_b, "m", outline_notch_stop_x, outline_notch_stop_y, "m") 779%! xlim ([f(1), f(end)]); 780%! ylim ([-80, 0]); 781%! grid on 782%! xlabel ("Frequency (Hz)"); 783%! ylabel ("Attenuation (dB)"); 784%! title ("6th order analog elliptical notch (just exceeds 4th order) limit on upper freq"); 785 786%!demo 787%! fstop = [9875 10126.5823]; 788%! fpass = [9385 12000]; 789%! Rpass = 3; 790%! Rstop = 40; 791%! fcenter = sqrt (fpass(1) * fpass(2)); 792%! Wpass = 2*pi * fpass; 793%! Wstop = 2*pi * fstop; 794%! [n, Wn] = ellipord (Wpass, Wstop, Rpass, Rstop, "s") 795%! [b, a] = ellip (n, Rpass, Rstop, Wn, "stop", "s"); 796%! f = 5000:15000; 797%! W = 2*pi * f; 798%! H = freqs (b, a, W); 799%! plot (f, 20 * log10 (abs (H))) 800%! outline_notch_pass_x_a = [f(2) , fpass(1), fpass(1)]; 801%! outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)]; 802%! outline_notch_pass_y_a = [-Rpass , -Rpass , -80]; 803%! outline_notch_pass_y_b = [-80 , -Rpass , -Rpass]; 804%! outline_notch_stop_x = [f(2) , fstop(1), fstop(1), fstop(2), fstop(2), max(f)]; 805%! outline_notch_stop_y = [0 , 0 , -Rstop , -Rstop , 0 , 0 ]; 806%! hold on 807%! plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m", outline_notch_pass_x_b, outline_notch_pass_y_b, "m", outline_notch_stop_x, outline_notch_stop_y, "m") 808%! xlim ([f(1), f(end)]); 809%! ylim ([-80, 0]); 810%! grid on 811%! xlabel ("Frequency (Hz)"); 812%! ylabel ("Attenuation (dB)"); 813%! title ("6th order analog elliptical notch (just exceeds 4th order) limit on lower freq"); 814 815 816%!test 817%! # Analog band-pass 818%! [n, Wn] = ellipord (2 * pi * [9875, 10126.5823], ... 819%! 2 * pi * [9000, 10657], 3, 40, "s"); 820%! assert (n, 2); 821%! assert (round (Wn), [62046, 63627]); 822 823%!test 824%! # Analog band-pass 825%! [n, Wn] = ellipord (2 * pi * [9875, 10126.5823], ... 826%! 2 * pi * [9384, 12000], 3, 40, "s"); 827%! assert (n, 2); 828%! assert (round (Wn), [62046, 63627]); 829 830%!test 831%! # Analog band-pass 832%! [n, Wn] = ellipord (2 * pi * [9875, 10126.5823], ... 833%! 2 * pi * [9000, 10656], 3, 40, "s"); 834%! assert (n, 3); 835%! assert (round (Wn), [62046, 63627]); 836 837%!test 838%! # Analog band-pass 839%! [n, Wn] = ellipord (2 * pi * [9875, 10126.5823], ... 840%! 2 * pi * [9385, 12000], 3, 40, "s"); 841%! assert (n, 3); 842%! assert (round (Wn), [62046, 63627]); 843 844%!test 845%! # Analog high-pass 846%! [n, Wn] = ellipord (2 * pi * 20224, 2 * pi * 4000, 3, 40, "s"); 847%! assert (n, 2); 848%! assert (round (Wn), 127071); 849 850%!test 851%! # Analog high-pass 852%! [n, Wn] = ellipord (2 * pi * 20223, 2 * pi * 4000, 3, 40, "s"); 853%! assert (n, 3); 854%! assert (round (Wn), 127065); 855 856%!test 857%! # Analog low-pass 858%! [n, Wn] = ellipord (2 * pi * 4000, 2 * pi * 20224, 3, 40, "s"); 859%! assert (n, 2); 860%! assert (round (Wn), 25133); 861 862%!test 863%! # Analog low-pass 864%! [n, Wn] = ellipord (2 * pi * 4000, 2 * pi * 20223, 3, 40, "s"); 865%! assert (n, 3); 866%! assert (round (Wn), 25133); 867 868%!test 869%! # Analog notch (narrow band-stop) 870%! [n, Wn] = ellipord (2 * pi * [9000, 10657], ... 871%! 2 * pi * [9875, 10126.5823], 3, 40, "s"); 872%! assert (n, 2); 873%! assert (round (Wn), [58958, 66960]); 874 875%!test 876%! # Analog notch (narrow band-stop) 877%! [n, Wn] = ellipord (2 * pi * [9384, 12000], ... 878%! 2 * pi * [9875, 10126.5823], 3, 40, "s"); 879%! assert (n, 2); 880%! assert (round (Wn), [58961 , 66956]); 881 882%!test 883%! # Analog notch (narrow band-stop) 884%! [n, Wn] = ellipord (2 * pi * [9000, 10656], ... 885%! 2 * pi * [9875, 10126.5823], 3, 40, "s"); 886%! assert (n, 3); 887%! assert (round (Wn), [58964, 66954]); 888 889%!test 890%! # Analog notch (narrow band-stop) 891%! [n, Wn] = ellipord (2 * pi * [9385, 12000], ... 892%! 2 * pi * [9875, 10126.5823], 3, 40, "s"); 893%! assert (n, 3); 894%! assert (round (Wn), [58968, 66949]); 895 896%!test 897%! # Digital band-pass 898%! fs = 44100; 899%! [n, Wn] = ellipord (2 / fs * [9500, 9750], 2 / fs * [8500, 10261], 3, 40); 900%! Wn = Wn * fs / 2; 901%! assert (n, 2); 902%! assert (round (Wn), [9500, 9750]); 903 904%!test 905%! # Digital band-pass 906%! fs = 44100; 907%! [n, Wn] = ellipord (2 / fs * [9500, 9750], 2 / fs * [9000, 10700], 3, 40); 908%! Wn = Wn * fs / 2; 909%! assert (n, 2); 910%! assert (round (Wn), [9500, 9750]); 911 912%!test 913%! # Digital band-pass 914%! fs = 44100; 915%! [n, Wn] = ellipord (2 / fs * [9500, 9750], 2 / fs * [8500, 10260], 3, 40); 916%! Wn = Wn * fs / 2; 917%! assert (n, 3); 918%! assert (round (Wn), [9500, 9750]); 919 920%!test 921%! # Digital band-pass 922%! fs = 44100; 923%! [n, Wn] = ellipord (2 / fs * [9500, 9750], 2 / fs * [9001, 10700], 3, 40); 924%! Wn = Wn * fs / 2; 925%! assert (n, 3); 926%! assert (round (Wn), [9500, 9750]); 927 928%!test 929%! # Digital high-pass 930%! fs = 44100; 931%! [n, Wn] = ellipord (2 / fs * 13713, 2 / fs * 4000, 3, 40); 932%! Wn = Wn * fs / 2; 933%! assert (n, 2); 934%! assert (round (Wn), 13713); 935 936%!test 937%! # Digital high-pass 938%! fs = 44100; 939%! [n, Wn] = ellipord (2 / fs * 13712, 2 / fs * 4000, 3, 40); 940%! Wn = Wn * fs / 2; 941%! assert (n, 3); 942%! assert (round (Wn), 13712); 943 944%!test 945%! # Digital low-pass 946%! fs = 44100; 947%! [n, Wn] = ellipord (2 / fs * 4000, 2 / fs * 13713, 3, 40); 948%! Wn = Wn * fs / 2; 949%! assert (n, 2); 950%! assert (round (Wn), 4000); 951 952%!test 953%! # Digital low-pass 954%! fs = 44100; 955%! [n, Wn] = ellipord (2 / fs * 4000, 2 / fs * 13712, 3, 40); 956%! Wn = Wn * fs / 2; 957%! assert (n, 3); 958%! assert (round (Wn), 4000); 959 960%!test 961%! # Digital notch (narrow band-stop) 962%! fs = 44100; 963%! [n, Wn] = ellipord (2 / fs * [8500, 11073], 2 / fs * [9875, 10126.5823], 0.5, 40); 964%! Wn = Wn * fs / 2; 965%! assert (n, 2); 966%! assert (round (Wn), [8952, 11073]); 967 968%!test 969%! # Digital notch (narrow band-stop) 970%! fs = 44100; 971%! [n, Wn] = ellipord (2 / fs * [8952, 12000], 2 / fs * [9875, 10126.5823], 0.5, 40); 972%! Wn = Wn * fs / 2; 973%! assert (n, 2); 974%! assert (round (Wn), [8952, 11073]); 975 976%!test 977%! # Digital notch (narrow band-stop) 978%! fs = 44100; 979%! [n, Wn] = ellipord (2 / fs * [8500, 11072], 2 / fs * [9875, 10126.5823], 0.5, 40); 980%! Wn = Wn * fs / 2; 981%! assert (n, 3); 982%! assert (round (Wn), [8953, 11072]); 983 984%!test 985%! # Digital notch (narrow band-stop) 986%! fs = 44100; 987%! [n, Wn] = ellipord (2 / fs * [8953, 12000], 2 / fs * [9875, 10126.5823], 0.5, 40); 988%! Wn = Wn * fs / 2; 989%! assert (n, 3); 990%! assert (round (Wn), [8953, 11072]); 991 992## Test input validation 993%!error ellipord () 994%!error ellipord (.1) 995%!error ellipord (.1, .2) 996%!error ellipord (.1, .2, 3) 997%!error ellipord ([.1 .1], [.2 .2], 3, 4) 998%!error ellipord ([.1 .2], [.5 .6], 3, 4) 999%!error ellipord ([.1 .5], [.2 .6], 3, 4) 1000