The design of filters, analog and discrete, is simplified by the functions that MATLAB provides. Functions to find the filter parameters from magnitude specifications, as well as functions to find the filter poles/zeros and to plot the designed filter magnitude and phase responses, are available.
Low-Pass Filter Design
The design procedure is similar for all of the approximation methods (Butterworth, Chebyshev, elliptic) and consists of both
■ Finding the filter parameters from loss specifications.
■ Obtaining the filter coefficients from these parameters.
Thus, to design an analog low-pass filter using the Butterworth approximation, the loss specifications αmax and αmin, and the frequency specifications, Ωp and Ωs are first used by the function buttord to determine the minimum order N and the half-power frequency Ωhp of the filter that satisfies the specifications. Then the function butter uses these two values to determine the coefficients of the numerator and the denominator of the designed filter. We can then use the function freqs to plot the designed filter magnitude and phase. Similarly, this applies for the design of low-pass filters using the Chebyshev or the elliptic design methods. To include the design of low-pass filters using the Butterworth, Chebyshev (two versions), and the elliptic methods we wrote the function analogfil.
function [b, a] = analogfil(Wp, Ws, alphamax, alphamin, Wmax, ind)
%%
%Analog filter design
%Parameters
%Input: loss specifications (alphamax, alphamin), corresponding
%frequencies (Wp,Ws), frequency range [0,Wmax] and indicator ind (1 for
%Butterworth, 2 for Chebyshev1, 3 for Chebyshev2 and 4 for elliptic).
%Output: coefficients of designed filter.
%Function plots magnitude, phase responses, poles and zeros of filter, and
%loss specifications
%%%
if ind == 1,% Butterworth low-pass
[N, Wn] = buttord(Wp, Ws, alphamax, alphamin, 's')
[b, a] = butter(N, Wn, 's')
elseif ind == 2, % Chebyshev low-pass
[N, Wn] = cheb1ord(Wp, Ws, alphamax, alphamin, 's')
[b, a] = cheby1(N, alphamax, Wn, 's')
elseif ind == 3, % Chebyshev2 low-pass
[N, Wn] = cheb2ord(Wp, Ws, alphamax, alphamin, 's')
[b, a] = cheby2(N, alphamin, Wn, 's')
else % Elliptic low-pass
[N, Wn] = ellipord(Wp, Ws, alphamax, alphamin, 's')
[b, a] = ellip(N, alphamax, alphamin, Wn, 's')
end
W = 0:0.001:Wmax; % frequency range for plotting H = freqs(b, a, W); Hm = abs(H); Ha = unwrap(angle(H)) % magnitude (Hm) and phase (Ha)
N = length(W); alpha1 = alphamax ∗ ones(1, N); alpha2 = alphamin ∗ ones(1, N); % loss specs
subplot(221)
plot(W, Hm); grid; axis([0 Wmax 0 1.1 ∗ max(Hm)])
subplot(222)
plot(W, Ha); grid; axis([0 Wmax 1.1 ∗ min(Ha) 1.1 ∗ max(Ha)])
subplot(223)
splane(b, a)
subplot(224)
plot(W, −20 ∗ log10(abs(H))); hold on
plot(W, alpha1, 'r', W, alpha2, 'r'), grid; axis([0 max(W) −0.1 100])
hold off
To illustrate the use of analogfil consider the design of low-pass filters using the Chebyshev2 and the Elliptic design methods. The specifications for the designs are
We wish to find the coefficients of the designed filters, plot their magnitude and phase, and plot the loss function for each of the filters and verify that the specifications have been met. The results are shown in
Figure 6.26.
% Example 6.11 -- Filter design using analogfil
%%%%%%%%%%%%%%%%%%%
clear all; clf
alphamax = 0.1;
alphamin = 60;
Wp =10; Ws = 15;
Wmax = 25;
ind = 4 % elliptic design
% ind = 3 % chebyshev2 design
[b, a] = analogfil(Wp, Ws, alphamax, alphamin, Wmax, ind)
The elliptic design is illustrated above. To obtain the Chebyshev2 design get rid of the comment symbol % in front of the corresponding indicator and put it in front of the one for the elliptic design.
General comments on the design of low-pass filters using Butterworth, Chebyshev (1 and 2), and Elliptic methods are:
■ The Butterworth and the Chebyshev2 designs are flat in the passband, while the others display ripples in that band.
■ For identical specifications, the obtained order of the Butterworth filter is much greater than the order of the other filters.
■ The phase of all of these filters is approximately linear in the passband, but not outside it. Because of the rational transfer functions for these filters, it is not possible to have linear phase over all frequencies. However, the phase response is less significant in the stopband where the magnitude response is very small.
■ The filter design functions provided by MATLAB can be used for analog or discrete filters. When designing an analog filter there is no constrain in the values of the frequency specifications and an 's' indicates that the filter being designed is analog.