Filter Design with MATLAB

6.5.5 Filter Design with MATLAB

The design of filters, analog and discrete, is simplified by the functions that MATLAB provides. Func- tions 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

C H A P T E R 6: Application to Control and Communications

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

■ Example 6.11

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

α( 0) = 0, α max = 0.1, α min = 60 dB  p = 10,  s = 15 rad/sec

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.

FIGURE 6.26 (a) Elliptic and (b) Chebyshev2 low-pass filter designs using analogfil function. Clockwise: magnitude, phase,