fp = 1.0e5; wp = 2*pi*fp; fs = 1.0e6; ws = 2*pi*fs; rp = 3; rs = 80; rmin = -1.5*rs; fmin = 10e3; fmax = 10e6; % filter prototype [Nb, Wb] = buttord(wp, ws, rp, rs, 's'); [b, a] = butter(Nb, Wb, 's'); Hb = tf(b, a); [Nc, Wc] = cheb2ord(wp, ws, rp, rs, 's'); [b, a] = cheby2(Nc, rs, Wc, 's'); Hc = tf(b, a); [Ne, We] = ellipord(wp, ws, rp, rs, 's'); [b, a] = ellip(Ne, rp, rs, We, 's'); He = tf(b, a); % frequency response f = logspace(log10(fmin), log10(fmax), 801); w = 2*pi*f; m = bode(Hb, w); semilogx(f, 20*log10(m(1,:)), 'b'); hold on; m = bode(Hc, w); semilogx(f, 20*log10(m(1,:)), 'g'); m = bode(He, w); semilogx(f, 20*log10(m(1,:)), 'r'); % draw template semilogx([ fmin fs fs fmax ] , [ 0 0 -rs -rs ], 'k--'); semilogx([ fmin fp fp ] , [ -rp -rp -2*rs], 'k--'); h = text(fmin, -rp, sprintf('Rp = %.0f dB ', rp), 'HorizontalAlignment', 'right'); h = text(fmax, -rs, sprintf(' Rs = %.0f dB', rs), 'HorizontalAlignment', 'left'); h = text(fp, rmin-6, sprintf('fp = %.0fkHz', fp/1e3), 'HorizontalAlignment', 'center', 'VerticalAlignment', 'top'); h = text(fs, rmin-6, sprintf('fs = %.0fMHz', fs/1e6), 'HorizontalAlignment', 'center', 'VerticalAlignment', 'top'); get(h) axis([fmin fmax rmin 2*rp]); legend(... sprintf('Butterworth (N = %d)', Nb), ... sprintf('Chebychev 2 (N = %d)', Nc), ... sprintf('Elliptic (N = %d)', Ne)); xlabel('Frequency [Hz]'); ylabel('Magnitude [dB]'); fixfig; hold off;