Вы находитесь на странице: 1из 9

Filter Butterworth memiliki respon yang memberikan efek datar sangat maksimal pada passband

monoton. Tahap smoothing ini menurunkan rolloff steepness. Butterworth bekerja dengan cara
mengubah filter analog menjadi filter digital dengan menjadikan keduanya memiliki respon frekuensi
yang sama.

BANDPASS FILTER DESIGN EXAMPLE

The Matlab code below designs a bandpass filter which passes frequencies
between 4kHz and 6kHz, allowing transition bands from 3-4 kHz and 6-8 kHz
(i.e., the stopbands are 0-3 kHz and 8-10 kHz, when the sampling rate is 20
kHz). The desired stop-band attenuation is 80 dB, and the passband ripple is
required to be no greater than 0.1 dB. For these specifications, the
function kaiserord returns a beta value of and a window length of . These
values are passed to the function kaiser which computes the window function
itself. The ideal bandpass-filter impulse response is computed in fir1, and the
supplied Kaiser windowis applied to shorten it to length .

MATLAB CODE
fs=20000; % sampling rate
F=[3000 4000 6000 8000]; % band limits
A=[0 1 0]; % band type: 0='stop', 1='pass'
dev=[0.0001 10^(0.1/20)-1 0.0001]; % ripple/attenuation spec
[M,Wn,beta,typ]= kaiserord(F,A,dev,fs); % window parameters
b=fir1(M,Wn,typ,kaiser(M+1,beta),'noscale'); % filter design

Note the conciseness of the Matlab code thanks to the use


of kaiserord and fir1 from theSignal Processing Toolbox.

RESULTS

Figure E.5 shows the magnitude frequency response of the resulting FIR
filter . Note that the upper passband edge has been moved to 6500 Hz
instead of 6000 Hz, and the stop-band begins at 7500 Hz instead of 8000 Hz
as requested. While this may look like a bug at first, it's actually a perfectly
fine solution. As discussed earlier in §E.4, all transition widths in filters
designed by the window method must be equal to the window-transform's
main-lobe width. Therefore, the only way to achieve specs when there are
multiple transition regions specified is to set the main-lobe width to
the minimum transition width. For the others, it makes sense to center the
transition within the requested transition region.

Figure E.5: Amplitude response of the FIR bandpass filterdesigned by the window method.

IN CASE YOU DON'T HAVE THE MATLAB SIGNAL PROCESSING TOOLBOX

Without kaiserord, we would need to implement Kaiser's formula [110,66] for


estimating theKaiser-window required to achieve the given filter specs:

(E.3)

where is the desired stop-band attenuation in dB (typical values in audio work


are to ). Note that this estimate for becomes too small when the
filter passband width approaches zero. In the limit of a zero-width pass-band,
the frequency response becomes that of the Kaiser window transform itself. A
non-zero passband width acts as a ``moving average'' lowpass filter on the
sidelobes of the window transform, which brings them down in level.
The kaiserord estimate assumes some of this sidelobe smoothing is present.

A similar function from [187] for window design (as opposed to filter design) is
(E.4)

where now is the desired side-lobe attenuation in dB (as opposed to stop-


band attenuation). A plot showing Kaiser window sidelobe level for various
values of is given in Fig.3.22.

Similarly, the filter order is estimated from stop-band attenuation and desired
transition width using the empirical formula

where is in radians between 0 and .

Without the function fir1, we would have to manually implement the window
method of filter design by (1) constructing the impulse response of the
ideal bandpass filter (a cosine modulated sinc function), (2) computing the
Kaiser window using the estimated length and from above, then finally (3)
windowing the ideal impulse response with the Kaiser window to obtain
the FIR filter coefficients . A manual design of this nature will be illustrated in
the Hilbert transform example of §E.5.

COMPARISON TO THE OPTIMAL CHEBYSHEV FIR BANDPASS FILTER

To provide some perspective on the results, we will compare the results for
the window method to the optimal Chebyshev FIR filter having the same
length and design specs as used for the window method above.

An optimal Chebyshev FIR filter is optimal in the minimax sense. That is,
the worst-case error(maximum ripple) is minimized. It is also called optimal in
the `` '' sense, since the norm of a frequency response error is the maximum
magnitude over all frequencies:

The norm is also sometimes called the uniform norm. While the optimal
Chebyshev FIR filter is unique, in principle, there is no guarantee that any
particular numerical algorithm can find it.
The optimal Chebyshev FIR filter can often be effectively found using
the Remez multiple exchange algorithm [166,212,65]. The window method
and the Remez method together span most practical FIR filter design needs,
from ``quick and dirty'' to essentially perfect FIR filters. However, another
versatile, effective, and often-used case not covered here is the weightedleast
squares method, which is implemented in the Matlab function firls (also in
the SignalProcessing Toolbox). A good reference for further study is [193].

MATLAB CODE

The following Matlab code computes the optimal Chebyshev FIR


bandpass filter:
M = 101;
%normF = [0 0.3 0.4 0.6 0.8 1.0]; % transition bands different
normF = [0 0.3 0.4 0.6 0.7 1.0]; % transition bands the same
amp = [0 0 1 1 0 0]; % desired amplitude in each band

[b2,err2] = remez(M-1,normF,amp); % optimal filter of length M

% REMEZ Parks-McClellan optimal equiripple FIR filter design.


% B=REMEZ(N,F,A) returns a length N+1 linear phase (real, symmetric
% coefficients) FIR filter which has the best approximation to the
% desired frequency response described by F and A in the minimax
% sense. ... REMEZ treats the bands between F(k+1) and F(k+2) for odd
% k as "transition bands" or "don't care" regions.

figure(2);
[H2,freq]=freqz(b2,[1],512);
subplot(2,1,1); plot(freq*10000/pi,20*log10(abs(H2))); grid;
xlabel('Hz'); ylabel('dB'); axis([0 10000 -110 30]);
subplot(2,1,2); plot(freq*10000/pi,20*log10(abs(H2))); grid;
xlabel('Hz'); ylabel('dB'); axis([3500 7000 -0.02 0.02]);

RESULTS
Figure E.6 presents the frequency response of the optimal Chebyshev FIR
filter corresponding to the window-method FIR filter shown in Fig.E.5. Note
that the upper transition band ``blows up''. This is a well known failure mode
in FIR filter design using the Remez exchange algorithm. It can be eliminated
by narrowing the transition band, as shown in Fig.E.7. There is no error
penalty in the transition region, so it is necessary that each one be
``sufficiently narrow'' to avoid this phenomenon.

Figure E.6: Amplitude response of the optimal Chebyshev FIR bandpass filter designed by the
Remez exchange method.
Figure E.7: Amplitude response of the optimal Chebyshev FIRbandpass filter as in Fig.E.6 with
the upper transition band narrowed from 2 kHz down to 1 kHz in width.

THE WINDOW METHOD

The window method for digital filter design is fast, convenient, and robust, but
generally suboptimal. It is easily understood in terms of the convolution
theorem for Fourier transforms, making it instructive to study after the Fourier
theorems and windows forspectrum analysis. It can be effectively combined with
the frequency sampling method, as we will see in §E.5 below.
The window method consists of simply ``windowing'' a
theoretically ideal filter impulse response by some suitably chosen window
function , yielding

For example, as derived in Eq. (E.1), the impulse response of


the ideal lowpass filter is the well known sinc function

sinc
where is the total normalized bandwidth of the lowpass filter in Hz (counting both
negative and positive frequencies), and denotes the cut-off frequency in Hz. As
noted earlier, we cannot implement this filter in practice because it is noncausal
and of infinite duration.

Since sinc decays away from time 0 as , we would expect to be able to


truncate it to the interval , for some sufficiently large , and obtain a pretty
good FIR filter which approximates the ideal filter. This would be an example of
using the window method with the rectangular window. We saw in §E.2 that such
a choice is optimal in theleast-squares sense, but it designs relatively poor audio
filters. Choosing other windowscorresponds to tapering the ideal impulse
response to zero instead of truncating it. Tapering better preserves the shape of
the desired frequency response, as we will see. By choosing the window
carefully, we can manage various trade-offs so as to maximize the filter-
designquality in a given application.

Window functions are always time limited. This means there is always a finite
integer such that for all . The final windowed impulse response is thus always
time-limited, as needed for practical implementation. The window method always
designs a finite-impulse-response (FIR) digital filter (as opposed to an infinite-
impulse-response (IIR) digital filter).

By the dual of the convolution theorem, pointwise multiplication in the time


domain corresponds to convolution in the frequency domain. Thus, the designed
filter has a frequency response given by

where is the ideal frequency response and is the window transform. For the
ideal lowpass filter, is a rectangular window in the frequency domain. The
frequency response is thus obtained by convolving the rectangular window with
the window transform . This implies several points which can be immediately
seen in terms of this convolution operation:

 The passband gain is primarily the area under the main lobe of the window
transform, provided the main lobe ``fits'' inside the passband (i.e., the total
lowpass bandwidth is greater than or equal to the main-lobe width).
 The stopband gain is given by an integral over a portion of the sidelobes of
the window transform. Since sidelobes oscillate about zero, a finite integral
over them is normally much smaller than the sidelobes themselves, due to
adjacent sidelobe cancellation under the integral.
 The best stop-band performance occurs when the cut-off frequency is set
so that the stopband sidelobe integral traverses a whole number of
sidelobes.
 The transition bandwidth is equal to the bandwidth of the main lobe of the
window transform, again provided the main lobe ``fits'' inside the
passband.
 For very small lowpass bandwidths , approaches an impulse function in
the frequency domain. Since the impulse function is the identity operator
under convolution, the resulting lowpass filter approaches the window
transform for small . In particular, the stopband gain approaches the
window sidelobe level, and the transition width approaches half the main-
lobe width. Thus, for good results, the lowpass cut-off frequency should be
set no lower than half the window's main lobe width.

MATLAB SUPPORT FOR THE WINDOW METHOD

The Matlab Signal Processing Toolbox has two functions which implement the
window method for FIR filter design:

 fir1 designs lowpass, highpass, bandpass, and multi-bandpass filters.


 fir2 takes an arbitrary magnitude frequency response specification.

The default window type is Hamming, but any window can be passed in as an
argument. In addition, there is a function kaiserord for estimating the parameters
of a Kaiser window which will achieve the desired filter specifications.

GENERALIZED WINDOW METHOD

Often we need a filter with a frequency response that is not analytically


known. An example is a graphic equalizer in which a user may manipulate
sliders in a graphical user interface to control the gain in each of several
frequency bands. From the foregoing, the following procedure, based in spirit
on the window method (§E.4), can yield good results:

1. Synthesize the desired frequency response as the smoothest possible


interpolation of the desired frequency-response points. For example, in
a graphical equalizer, cubic splines could be used to connect the
desired band gains.E.2
2. If the desired frequency response is real (as in simple band gains),
either plan for a zero-phase filter in the end, or synthesize a desired
phase, such as linear phase or minimum phase [247].
3. Perform the inverse Fourier transform (FFT) of the (sampled) desired
frequency response to obtain the desired impulse response.
4. Plot an overlay of the desired impulse response and the window to be
applied, ensuring that the great majority of the signal energy in the
desired impulse response lies under the window to be used.
5. Multiply by the window.
6. Take an FFT (now with zero padding introduced by the window).
7. Plot an overlay of the original desired response and the response
retained after time-domain windowing, and verify that the specifications
are within an acceptable range.

In summary, FIR filters can be designed non-parametrically, directly in


the frequency domain, followed by a final smoothing (windowing in the time
domain) which guarantees that the FIR length will be precisely limited. It is
necessary to precisely limit the FIR filter length to avoid time-aliasing in an
FFT convolution implementation.

FILTER SPECIFICATIONS
Figure E.25: Illustration of typical filter specifications in thefrequency domain.

Let us first consider the design of a lowpass filter. The first task is to specify our
design criteria. Referring to Fig.E.25, we define the following design parameters:

 : stopband ripple ( dB typical)


 : passband ripple ( dB typical)
 : stopband edge frequency
 : passband edge frequency
 TW: transition width
 SBA: stop-band attenuation

The passband ripple is larger than the stopband ripple for a couple of reasons:
First, it is a deviation about 1 instead of 0. A passband ripple of dB, for example,
translates to on a linear scale. A stopband ripple of dB, on the other hand,
equals on a linear scale. Thus, a typical passband ripple specification may be 10
times larger than a typical stopband ripple specification, on a linear scale. For a
stop-band gain down around dB, keeping the passband ripple at dB, the
passband ripple becomes around 100 times larger than the stopband ripple, on a
linear scale.

Вам также может понравиться