Function File: n = buttord (wp, ws, rp, rs)
Function File: n = buttord ([wp1, wp2], [ws1, ws2], rp, rs)
Function File: n = buttord ([wp1, wp2], [ws1, ws2], rp, rs, "s")
Function File: [n, wc_p] = buttord (…)
Function File: [n, wc_p, wc_s] = buttord (…)

Compute the minimum filter order of a Butterworth filter with the desired response characteristics. The filter frequency band edges are specified by the passband frequency wp and stopband frequency ws. Frequencies are normalized to the Nyquist frequency in the range [0,1]. rp is the allowable passband ripple measured in decibels, and rs is the minimum attenuation in the stop band, also in decibels.

The output arguments n and wc_p (or n and wc_n) can be given as inputs to butter. Using wc_p makes the filter characteristic touch at least one pass band corner and using wc_s makes the characteristic touch at least one stop band corner.

If wp and ws are scalars, then wp is the passband cutoff frequency and ws is the stopband edge frequency. If ws is greater than wp, the filter is a low-pass filter. If wp is greater than ws, the filter is a high-pass filter.

If wp and ws are vectors of length 2, then wp defines the passband interval and ws defines the stopband interval. If wp is contained within ws (ws1 < wp1 < wp2 < ws2), the filter is a band-pass filter. If ws is contained within wp (wp1 < ws1 < ws2 < wp2), the filter is a band-stop or band-reject filter.

If the optional argument "s" is given, the minimum order for an analog elliptic filter is computed. All frequencies wp and ws are specified in radians per second.

Theory: For Low pass filters, |H(W)|^2 = 1/[1+(W/Wc)^(2N)] = 10^(-R/10). With some algebra, you can solve simultaneously for Wc and N given Ws,Rs and Wp,Rp. Rounding N to the next greater integer, one can recalculate the allowable range for Wc (filter caracteristic touching the pass band edge or the stop band edge).

For other types of filter, before making the above calculation, the requirements must be transformed to LP requirements. After calculation, Wc must be transformed back to original filter type.

See also: butter, cheb1ord, cheb2ord, ellipord.

Demonstration 1

The following code

 fs    = 44100;
 Npts  = fs / 2;
 fpass = 4000;
 fstop = 10987;
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_p);
 f = 8000:12000;
 W = 2 * pi * f;
 [H, f] = freqz (b, a, Npts, fs);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth low-pass : matching pass band");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_lp_pass_x = [f(2)  , fpass(1), fpass(1)];
 outline_lp_pass_y = [-Rpass, -Rpass  , -80];
 outline_lp_stop_x = [f(2)  , fstop(1), fstop(1), max(f)];
 outline_lp_stop_y = [0     , 0       , -Rstop  , -Rstop];
 hold on;
 plot (outline_lp_pass_x, outline_lp_pass_y, "m");
 plot (outline_lp_stop_x, outline_lp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p = 0.2125
Wn_s = 0.2801

and the following figure

Figure 1

Demonstration 2

The following code

 fs    = 44100;
 Npts  = fs / 2;
 fpass = 4000;
 fstop = 10987;
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_s);
 f = 8000:12000;
 W = 2 * pi * f;
 [H, f] = freqz (b, a, Npts, fs);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth low-pass : matching stop band");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_lp_pass_x = [f(2)  , fpass(1), fpass(1)];
 outline_lp_pass_y = [-Rpass, -Rpass  , -80];
 outline_lp_stop_x = [f(2)  , fstop(1), fstop(1), max(f)];
 outline_lp_stop_y = [0     , 0       , -Rstop  , -Rstop];
 hold on;
 plot (outline_lp_pass_x, outline_lp_pass_y, "m");
 plot (outline_lp_stop_x, outline_lp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p = 0.2125
Wn_s = 0.2801

and the following figure

Figure 1

Demonstration 3

The following code

 fs    = 44100;
 Npts  = fs / 2;
 fstop = 4000;
 fpass = 10987;
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_p, "high");
 f = 8000:12000;
 W = 2 * pi * f;
 [H, f] = freqz (b, a, Npts, fs);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth high-pass : matching pass band");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_hp_pass_x = [fpass(1), fpass(1), max(f)];
 outline_hp_pass_y = [-80     , -Rpass  , -Rpass];
 outline_hp_stop_x = [min(f)  , fstop(1), fstop(1), max(f)];
 outline_hp_stop_y = [-Rstop  , -Rstop  , 0       , 0     ];
 hold on;
 plot (outline_hp_pass_x, outline_hp_pass_y, "m");
 plot (outline_hp_stop_x, outline_hp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p = 0.4448
Wn_s = 0.3528

and the following figure

Figure 1

Demonstration 4

The following code

 fs    = 44100;
 Npts  = fs / 2;
 fstop = 4000;
 fpass = 10987;
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_s, "high");
 f = 8000:12000;
 W = 2 * pi * f;
 [H, f] = freqz (b, a, Npts, fs);
 plot (f, 20 * log10 (abs (H)))
 title ("Digital Butterworth high-pass : matching stop band");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_hp_pass_x = [fpass(1), fpass(1), max(f)];
 outline_hp_pass_y = [-80     , -Rpass  , -Rpass];
 outline_hp_stop_x = [min(f)  , fstop(1), fstop(1), max(f)];
 outline_hp_stop_y = [-Rstop  , -Rstop  , 0       , 0     ];
 hold on;
 plot (outline_hp_pass_x, outline_hp_pass_y, "m");
 plot (outline_hp_stop_x, outline_hp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p = 0.4448
Wn_s = 0.3528

and the following figure

Figure 1

Demonstration 5

The following code

 fs    = 44100;
 fpass = [9500 9750];
 fstop = [8500 10051];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_p);
 f = (8000:12000)';
 W = f * (2 * pi / fs);
 H = freqz (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth band-pass : matching pass band, limit on upper freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)];
 outline_bp_pass_y = [-80     , -Rpass  , -Rpass  , -80];
 outline_bp_stop_x = [min(f)  , fstop(1), fstop(1), fstop(2), ...
                                                    fstop(2), max(f)];
 outline_bp_stop_y = [-Rstop  , -Rstop  , 0       , 0       , ...
                                                    -Rstop  , -Rstop];
 hold on;
 plot (outline_bp_pass_x, outline_bp_pass_y, "m");
 plot (outline_bp_stop_x, outline_bp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   0.4298   0.4432

Wn_s =

   0.4274   0.4456

and the following figure

Figure 1

Demonstration 6

The following code

 fs    = 44100;
 fpass = [9500 9750];
 fstop = [8500 10051];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_s);
 f = (8000:12000)';
 W = f * (2 * pi / fs);
 H = freqz (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth band-pass : matching stop band, limit on upper freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)];
 outline_bp_pass_y = [-80     , -Rpass  , -Rpass  , -80];
 outline_bp_stop_x = [min(f)  , fstop(1), fstop(1), fstop(2), ...
                                                    fstop(2), max(f)];
 outline_bp_stop_y = [-Rstop  , -Rstop  , 0       , 0       , ...
                                                    -Rstop  , -Rstop];
 hold on;
 plot (outline_bp_pass_x, outline_bp_pass_y, "m");
 plot (outline_bp_stop_x, outline_bp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   0.4298   0.4432

Wn_s =

   0.4274   0.4456

and the following figure

Figure 1

Demonstration 7

The following code

 fs    = 44100;
 fpass = [9500 9750];
 fstop = [9204 10700];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_p);
 f = (8000:12000)';
 W = f * (2 * pi / fs);
 H = freqz (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth band-pass : matching pass band, limit on lower freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)];
 outline_bp_pass_y = [-80     , -Rpass  , -Rpass  , -80];
 outline_bp_stop_x = [min(f)  , fstop(1), fstop(1), fstop(2), ...
                                                    fstop(2), max(f)];
 outline_bp_stop_y = [-Rstop  , -Rstop  , 0       , 0       , ...
                                                    -Rstop  , -Rstop];
 hold on;
 plot (outline_bp_pass_x, outline_bp_pass_y, "m");
 plot (outline_bp_stop_x, outline_bp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   0.4298   0.4432

Wn_s =

   0.4274   0.4456

and the following figure

Figure 1

Demonstration 8

The following code

 fs    = 44100;
 fpass = [9500 9750];
 fstop = [9204 10700];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_s);
 f = (8000:12000)';
 W = f * (2 * pi / fs);
 H = freqz (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth band-pass : matching stop band, limit on lower freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)];
 outline_bp_pass_y = [-80     , -Rpass  , -Rpass  , -80];
 outline_bp_stop_x = [min(f)  , fstop(1), fstop(1), fstop(2), ...
                                                    fstop(2), max(f)];
 outline_bp_stop_y = [-Rstop  , -Rstop  , 0       , 0       , ...
                                                    -Rstop  , -Rstop];
 hold on;
 plot (outline_bp_pass_x, outline_bp_pass_y, "m");
 plot (outline_bp_stop_x, outline_bp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   0.4298   0.4432

Wn_s =

   0.4274   0.4456

and the following figure

Figure 1

Demonstration 9

The following code

 fs    = 44100;
 fstop = [9875, 10126.5823];
 fpass = [8500 10833];
 Rpass = 0.5;
 Rstop = 40;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_p, "stop");
 f = (8000:12000)';
 W = f * (2 * pi / fs);
 H = freqz (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth notch : matching pass band, limit on upper freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_notch_pass_x_a = [min(f)  , fpass(1), fpass(1)];
 outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)];
 outline_notch_pass_y_a = [-Rpass  , -Rpass  , -80];
 outline_notch_pass_y_b = [-80     , -Rpass  , -Rpass];
 outline_notch_stop_x   = [min(f)  , fstop(1), fstop(1), fstop(2), ...
                                                         fstop(2), max(f)];
 outline_notch_stop_y   = [0       , 0       , -Rstop  , -Rstop  , ...
                                                         0       , 0 ];
 hold on;
 plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m");
 plot (outline_notch_pass_x_b, outline_notch_pass_y_b, "m");
 plot (outline_notch_stop_x, outline_notch_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   0.4249   0.4826

Wn_s =

   0.4356   0.4716

and the following figure

Figure 1

Demonstration 10

The following code

 fs    = 44100;
 fstop = [9875, 10126.5823];
 fpass = [8500 10833];
 Rpass = 0.5;
 Rstop = 40;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_s, "stop");
 f = (8000:12000)';
 W = f * (2 * pi / fs);
 H = freqz (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth notch : matching stop band, limit on upper freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_notch_pass_x_a = [min(f)  , fpass(1), fpass(1)];
 outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)];
 outline_notch_pass_y_a = [-Rpass  , -Rpass  , -80];
 outline_notch_pass_y_b = [-80     , -Rpass  , -Rpass];
 outline_notch_stop_x   = [min(f)  , fstop(1), fstop(1), fstop(2), ...
                                                         fstop(2), max(f)];
 outline_notch_stop_y   = [0       , 0       , -Rstop  , -Rstop  , ...
                                                         0       , 0 ];
 hold on;
 plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m");
 plot (outline_notch_pass_x_b, outline_notch_pass_y_b, "m");
 plot (outline_notch_stop_x, outline_notch_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   0.4249   0.4826

Wn_s =

   0.4356   0.4716

and the following figure

Figure 1

Demonstration 11

The following code

 fs    = 44100;
 fstop = [9875, 10126.5823];
 fpass = [9183 11000];
 Rpass = 0.5;
 Rstop = 40;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_p, "stop");
 f = (8000:12000)';
 W = f * (2 * pi / fs);
 H = freqz (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth notch : matching pass band, limit on lower freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_notch_pass_x_a = [min(f)  , fpass(1), fpass(1)];
 outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)];
 outline_notch_pass_y_a = [-Rpass  , -Rpass  , -80];
 outline_notch_pass_y_b = [-80     , -Rpass  , -Rpass];
 outline_notch_stop_x   = [min(f)  , fstop(1), fstop(1), fstop(2), ...
                                                         fstop(2), max(f)];
 outline_notch_stop_y   = [0       , 0       , -Rstop  , -Rstop  , ...
                                                         0       , 0 ];
 hold on;
 plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m");
 plot (outline_notch_pass_x_b, outline_notch_pass_y_b, "m");
 plot (outline_notch_stop_x, outline_notch_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   0.4249   0.4825

Wn_s =

   0.4356   0.4716

and the following figure

Figure 1

Demonstration 12

The following code

 fs    = 44100;
 fstop = [9875, 10126.5823];
 fpass = [9183 11000];
 Rpass = 0.5;
 Rstop = 40;
 Wpass = 2 / fs * fpass;
 Wstop = 2 / fs * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop)
 [b, a] = butter (n, Wn_s, "stop");
 f = (8000:12000)';
 W = f * (2 * pi / fs);
 H = freqz (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Digital Butterworth notch : matching stop band, limit on lower freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_notch_pass_x_a = [min(f)  , fpass(1), fpass(1)];
 outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)];
 outline_notch_pass_y_a = [-Rpass  , -Rpass  , -80];
 outline_notch_pass_y_b = [-80     , -Rpass  , -Rpass];
 outline_notch_stop_x   = [min(f)  , fstop(1), fstop(1), fstop(2), ...
                                                         fstop(2), max(f)];
 outline_notch_stop_y   = [0       , 0       , -Rstop  , -Rstop  , ...
                                                         0       , 0 ];
 hold on;
 plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m");
 plot (outline_notch_pass_x_b, outline_notch_pass_y_b, "m");
 plot (outline_notch_stop_x, outline_notch_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   0.4249   0.4825

Wn_s =

   0.4356   0.4716

and the following figure

Figure 1

Demonstration 13

The following code

 fpass = 4000;
 fstop = 13583;
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_p, "s");
 f = 1000:10:100000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 semilogx (f, 20 * log10 (abs (H)))
 title ("Analog Butterworth low-pass : matching pass band");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_lp_pass_x = [f(2)  , fpass(1), fpass(1)];
 outline_lp_pass_y = [-Rpass, -Rpass  , -80];
 outline_lp_stop_x = [f(2)  , fstop(1), fstop(1), max(f)];
 outline_lp_stop_y = [0     , 0       , -Rstop  , -Rstop];
 hold on;
 plot (outline_lp_pass_x, outline_lp_pass_y, "m");
 plot (outline_lp_stop_x, outline_lp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p = 2.9757e+04
Wn_s = 4.0394e+04

and the following figure

Figure 1

Demonstration 14

The following code

 fpass = 4000;
 fstop = 13583;
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_s, "s");
 f = 1000:10:100000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 semilogx (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth low-pass : matching stop band");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_lp_pass_x = [f(2)  , fpass(1), fpass(1)];
 outline_lp_pass_y = [-Rpass, -Rpass  , -80];
 outline_lp_stop_x = [f(2)  , fstop(1), fstop(1), max(f)];
 outline_lp_stop_y = [0     , 0       , -Rstop  , -Rstop];
 hold on;
 plot (outline_lp_pass_x, outline_lp_pass_y, "m");
 plot (outline_lp_stop_x, outline_lp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p = 2.9757e+04
Wn_s = 4.0394e+04

and the following figure

Figure 1

Demonstration 15

The following code

 fstop = 4000;
 fpass = 13583;
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_p, "high", "s");
 f = 1000:10:100000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 semilogx (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth high-pass : matching pass band");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_hp_pass_x = [fpass(1), fpass(1), max(f)];
 outline_hp_pass_y = [-80     , -Rpass  , -Rpass];
 outline_hp_stop_x = [f(2)    , fstop(1), fstop(1), max(f)];
 outline_hp_stop_y = [-Rstop  , -Rstop  , 0       , 0     ];
 hold on;
 plot (outline_hp_pass_x, outline_hp_pass_y, "m");
 plot (outline_hp_stop_x, outline_hp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p = 7.2081e+04
Wn_s = 5.3101e+04

and the following figure

Figure 1

Demonstration 16

The following code

 fstop = 4000;
 fpass = 13583;
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_s, "high", "s");
 f = 1000:10:100000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 semilogx (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth high-pass : matching stop band");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_hp_pass_x = [fpass(1), fpass(1), max(f)];
 outline_hp_pass_y = [-80     , -Rpass  , -Rpass];
 outline_hp_stop_x = [f(2)    , fstop(1), fstop(1), max(f)];
 outline_hp_stop_y = [-Rstop  , -Rstop  , 0       , 0     ];
 hold on;
 plot (outline_hp_pass_x, outline_hp_pass_y, "m");
 plot (outline_hp_stop_x, outline_hp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p = 7.2081e+04
Wn_s = 5.3101e+04

and the following figure

Figure 1

Demonstration 17

The following code

 fpass = [9875, 10126.5823];
 fstop = [9000, 10436];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_p, "s");
 f = 8000:12000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth band-pass : matching pass band, limit on upper freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)];
 outline_bp_pass_y = [-80     , -Rpass  , -Rpass  , -80];
 outline_bp_stop_x = [f(2)    , fstop(1), fstop(1), fstop(2), ...
                                                    fstop(2), max(f)];
 outline_bp_stop_y = [-Rstop  , -Rstop  , 0       , 0       , ...
                                                    -Rstop  , -Rstop];
 hold on;
 plot (outline_bp_pass_x, outline_bp_pass_y, "m");
 plot (outline_bp_stop_x, outline_bp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   6.1903e+04   6.3775e+04

Wn_s =

   6.1575e+04   6.4114e+04

and the following figure

Figure 1

Demonstration 18

The following code

 fpass = [9875, 10126.5823];
 fstop = [9000, 10436];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_s, "s");
 f = 8000:12000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth band-pass : matching stop band, limit on upper freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)];
 outline_bp_pass_y = [-80     , -Rpass  , -Rpass  , -80];
 outline_bp_stop_x = [f(2)    , fstop(1), fstop(1), fstop(2), ...
                                                    fstop(2), max(f)];
 outline_bp_stop_y = [-Rstop  , -Rstop  , 0       , 0       , ...
                                                    -Rstop  , -Rstop];
 hold on;
 plot (outline_bp_pass_x, outline_bp_pass_y, "m");
 plot (outline_bp_stop_x, outline_bp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   6.1903e+04   6.3775e+04

Wn_s =

   6.1575e+04   6.4114e+04

and the following figure

Figure 1

Demonstration 19

The following code

 fpass = [9875, 10126.5823];
 fstop = [9582, 11000];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_p, "s");
 f = 8000:12000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth band-pass : matching pass band, limit on lower freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)];
 outline_bp_pass_y = [-80     , -Rpass  , -Rpass  , -80];
 outline_bp_stop_x = [f(2)    , fstop(1), fstop(1), fstop(2), ...
                                                    fstop(2), max(f)];
 outline_bp_stop_y = [-Rstop  , -Rstop  , 0       , 0       , ...
                                                    -Rstop  , -Rstop];
 hold on;
 plot (outline_bp_pass_x, outline_bp_pass_y, "m");
 plot (outline_bp_stop_x, outline_bp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   6.1903e+04   6.3775e+04

Wn_s =

   6.1575e+04   6.4115e+04

and the following figure

Figure 1

Demonstration 20

The following code

 fpass = [9875, 10126.5823];
 fstop = [9582, 11000];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_s, "s");
 f = 8000:12000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth band-pass : matching stop band, limit on lower freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_bp_pass_x = [fpass(1), fpass(1), fpass(2), fpass(2)];
 outline_bp_pass_y = [-80     , -Rpass  , -Rpass  , -80];
 outline_bp_stop_x = [f(2)    , fstop(1), fstop(1), fstop(2), ...
                                                    fstop(2), max(f)];
 outline_bp_stop_y = [-Rstop  , -Rstop  , 0       , 0       , ...
                                                    -Rstop  , -Rstop];
 hold on;
 plot (outline_bp_pass_x, outline_bp_pass_y, "m");
 plot (outline_bp_stop_x, outline_bp_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   6.1903e+04   6.3775e+04

Wn_s =

   6.1575e+04   6.4115e+04

and the following figure

Figure 1

Demonstration 21

The following code

 fstop = [9875 10126.5823];
 fpass = [9000 10436];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_p, "stop", "s");
 f = 8000:12000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth notch : matching pass band, limit on upper freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_notch_pass_x_a = [f(2)    , fpass(1), fpass(1)];
 outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)];
 outline_notch_pass_y_a = [-Rpass  , -Rpass  , -80];
 outline_notch_pass_y_b = [-80     , -Rpass  , -Rpass];
 outline_notch_stop_x   = [f(2)    , fstop(1), fstop(1), fstop(2), ...
                                                         fstop(2), max(f)];
 outline_notch_stop_y   = [0       , 0       , -Rstop  , -Rstop  , ...
                                                         0       , 0 ];
 hold on;
 plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m");
 plot (outline_notch_pass_x_b, outline_notch_pass_y_b, "m");
 plot (outline_notch_stop_x, outline_notch_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   6.0607e+04   6.5138e+04

Wn_s =

   6.1184e+04   6.4524e+04

and the following figure

Figure 1

Demonstration 22

The following code

 fstop = [9875 10126.5823];
 fpass = [9000 10436];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_s, "stop", "s");
 f = 8000:12000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth notch : matching stop band, limit on upper freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_notch_pass_x_a = [f(2)    , fpass(1), fpass(1)];
 outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)];
 outline_notch_pass_y_a = [-Rpass  , -Rpass  , -80];
 outline_notch_pass_y_b = [-80     , -Rpass  , -Rpass];
 outline_notch_stop_x   = [f(2)    , fstop(1), fstop(1), fstop(2), ...
                                                         fstop(2), max(f)];
 outline_notch_stop_y   = [0       , 0       , -Rstop  , -Rstop  , ...
                                                         0       , 0 ];
 hold on;
 plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m");
 plot (outline_notch_pass_x_b, outline_notch_pass_y_b, "m");
 plot (outline_notch_stop_x, outline_notch_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   6.0607e+04   6.5138e+04

Wn_s =

   6.1184e+04   6.4524e+04

and the following figure

Figure 1

Demonstration 23

The following code

 fstop = [9875 10126.5823];
 fpass = [9582 11000];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_p, "stop", "s");
 f = 8000:12000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth notch : matching pass band, limit on lower freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_notch_pass_x_a = [f(2)    , fpass(1), fpass(1)];
 outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)];
 outline_notch_pass_y_a = [-Rpass  , -Rpass  , -80];
 outline_notch_pass_y_b = [-80     , -Rpass  , -Rpass];
 outline_notch_stop_x   = [f(2)    , fstop(1), fstop(1), fstop(2), ...
                                                         fstop(2), max(f)];
 outline_notch_stop_y   = [0       , 0       , -Rstop  , -Rstop  , ...
                                                         0       , 0 ];
 hold on;
 plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m");
 plot (outline_notch_pass_x_b, outline_notch_pass_y_b, "m");
 plot (outline_notch_stop_x, outline_notch_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   6.0606e+04   6.5139e+04

Wn_s =

   6.1184e+04   6.4524e+04

and the following figure

Figure 1

Demonstration 24

The following code

 fstop = [9875 10126.5823];
 fpass = [9582 11000];
 Rpass = 1;
 Rstop = 26;
 Wpass = 2 * pi * fpass;
 Wstop = 2 * pi * fstop;
 [n, Wn_p, Wn_s] = buttord (Wpass, Wstop, Rpass, Rstop, "s")
 [b, a] = butter (n, Wn_s, "stop", "s");
 f = 8000:12000;
 W = 2 * pi * f;
 H = freqs (b, a, W);
 plot (f, 20 * log10 (abs (H)));
 title ("Analog Butterworth notch : matching stop band, limit on lower freq");
 xlabel ("Frequency (Hz)");
 ylabel ("Attenuation (dB)");
 grid on;
 outline_notch_pass_x_a = [f(2)    , fpass(1), fpass(1)];
 outline_notch_pass_x_b = [fpass(2), fpass(2), max(f)];
 outline_notch_pass_y_a = [-Rpass  , -Rpass  , -80];
 outline_notch_pass_y_b = [-80     , -Rpass  , -Rpass];
 outline_notch_stop_x   = [f(2)    , fstop(1), fstop(1), fstop(2), ...
                                                         fstop(2), max(f)];
 outline_notch_stop_y   = [0       , 0       , -Rstop  , -Rstop  , ...
                                                         0       , 0 ];
 hold on;
 plot (outline_notch_pass_x_a, outline_notch_pass_y_a, "m");
 plot (outline_notch_pass_x_b, outline_notch_pass_y_b, "m");
 plot (outline_notch_stop_x, outline_notch_stop_y, "m");
 ylim ([-80, 0]);

Produces the following output

n = 4
Wn_p =

   6.0606e+04   6.5139e+04

Wn_s =

   6.1184e+04   6.4524e+04

and the following figure

Figure 1

Package: signal