Filter Design with MATLAB

Một phần của tài liệu Signals and systems using matlab (Trang 422 - 426)

CHAPTER 6 Application to Control and Communications

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

n Finding the filter parameters from loss specifications.

n 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 andsare first used by the functionbuttordto determine the minimum order Nand 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 functionfreqsto 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 functionanalogfil.

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

nExample 6.11

To illustrate the use ofanalogfilconsider 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.

0 5 10 15 20 25 0

0.2 0.4 0.6 0.8 1

Ω

|H(Ω)|

−4 −2 0 2

−20

−10 0 10 20

σ

jΩ

0 5 10 15 20 25

−10

−8

−6

−4

−2 0

Ω

<H(Ω)

0 5 10 15 20 25 0

20 40 60 80 100

Ω

α(Ω)

0 5 10 15 20 25 0

0.2 0.4 0.6 0.8 1

Ω

0 5 10 15 20 25

−10−8−6−4−2 0

Ω

|H(Ω)| <H(Ω)

−15 −10 −5 0

−50 0 50

σ

0 5 10 15 20 25 0

20 40 60 80 100

Ω

jΩ α(Ω)

(a) (b)

FIGURE 6.26

(a) Elliptic and (b) Chebyshev2 low-pass filter designs using analogfil function. Clockwise: magnitude, phase, loss function, and poles and zeros are shown for each design.

6.5 Analog Filtering 407

%%%%%%%%%%%%%%%%%%%

% 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. n

General comments on the design of low-pass filters using Butterworth, Chebyshev (1 and 2), and Elliptic methods are:

n The Butterworth and the Chebyshev2 designs are flat in the passband, while the others display ripples in that band.

n For identical specifications, the obtained order of the Butterworth filter is much greater than the order of the other filters.

n 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.

n 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.

General Filter Design

The filter design programsbutter, cheby1, cheby2, andellip allow the design of other filters besides low-pass filters. Conceptually, a prototype low-pass filter is designed and then transformed into the desired filter by means of the frequency transformations given before. The filter is specified by the order and cut-off frequencies. In the case of low-pass and high-pass filters the specified cut-off fre- quencies are scalar, while for band-pass and stopband filters the specified cut-off frequencies are given as a vector. Also recall that the frequency transformations double the order of the low-pass prototype for the band-pass and band-eliminating filters, so when designing these filters half of the desired order should be given.

nExample 6.12

To illustrate the general design consider:

(a) Using thecheby2method, design a band-pass filter with the following specifications:

n orderN=10

n α()=60 dB in the stopband

n passband frequencies [10, 20] rad/sec

n unit gain in the passband

(b) Using the ellip method, design a band-stop filter with unit gain in the passbands and the following specifications:

n orderN=20

n α()=0.1 dB in the passband

n α()=40 dB in the stopband

n passband frequencies [10, 11] rad/sec The following script is used.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Example 6.12 --- general filter design

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all;clf N = 10;

[b, a] = ellip(N/2, 0.1, 40, [10 11], ’stop’, ’s’) % elliptic band-stop

%[b, a] = cheby2(N, 60, [10 20], ’s’) % cheby2 bandpass W = 0:0.01:30;

H = freqs(b, a, W);

Notice that the order given toellipis 5 and 10 tocheby2since a quadratic transformation will be used to obtain the notch and the band-pass filters from a prototype low-pass filter. The magnitude and phase responses of the two designed filters are shown in Figure 6.27. n

0 5 10 15 20 25 30

0 0.2 0.4 0.6 0.8 1

Ω

|H(Ω)|

0 5 10 15 20 25 30

−10

−5 0 5 10

Ω

<H(Ω)

0 5 10 15 20 25 30

0 0.2 0.4 0.6 0.8 1

Ω

|H(Ω)|

0 5 10 15 20 25 30

−10

−5 0 5 10

Ω

<H(Ω)

(a) (b)

FIGURE 6.27

Design of (a) a notch filter using ellip and of (b) a band-pass filter using cheby2.

Problems 409

Một phần của tài liệu Signals and systems using matlab (Trang 422 - 426)

Tải bản đầy đủ (PDF)

(769 trang)