Application ToolBox II: Digital Filter Design

0010 1011 1100 Speech Processing CHAPTER 6 Coding AC Coupling Clipping Quadrature Signal Processing Application ToolBox II: Digital Filter Desig...
Author: Margery Chase
2 downloads 0 Views 2MB Size
0010 1011 1100

Speech Processing

CHAPTER

6

Coding

AC Coupling Clipping Quadrature Signal Processing

Application ToolBox II: Digital Filter Design

Envelope Detection Correlation Audio Processing Equalisation Control

6.1

Introduction

00

6.6

Digital filter algorithms

00

Wavelet Transform

6.2

General filter design options

00

6.7

Filter design summary

00

Anti Aliasing

6.3

Digital filter methods

00

6.8

Filter design packages

00

Analogue to Digital Conversion

6.4

Digital filter design options

00

6.9

Specialist filter types

00

Linear Scaling

6.5

Digital filter structures and

00

Digital Filtering

quantization effects

6.10 Questions 00

Waveform Generation

A hands-on guide to designing and implementing digital filters, with emphasis on

Image Processing

CAD based techniques, and real world applications.

Modulation Demodulation Sample Rate Conversion Frequency Translation Time-Frequency Transfomation

fx

Non-Linear Function Adaptive Processing Digital to Analogue Conversion

General filter design options

Introduction

6.1

You will be hard pressed to find a DSP engineer who designs a digital filter by any means other than firing up the filter design package on a work station, clicking on a few menu tabs, entering the filter response required, and then waiting about 10 seconds for the design to be completed. Multi-coloured graphs showing gain, phase, group delay, impulse response, number of days shopping left until Christmas, etc, all appear, together with the filter coefficients, and indeed C or assembler code for your favourite processor (assuming you have paid for this option!) ready to link into your program. So, you may well ask, why devote a whole toolbox to digital filter design, if the process is so straightforward? The answer is that the small number of menu clicks and design parameters to be entered in the CAD package, are laden with choice. These choices can have a very significant impact on the performance of the resulting filter as well as influencing how much program and data memory it requires, how many processing cycles it needs, how stable it is, how accurate it is, and a few other things besides. This ToolBox thus begins by explaining as briefly as possible what these options are and how to choose between them. We then make the assumption that you will be rushing out to buy (well, acquire) a top of the range filter design package to try all this out for yourself, and therefore give a quick run through the current options in the market. We could of course be wrong, and you have a burning desire to design filters by hand. Don’t despair, all the theory you need is in Chapter 9. (Students who are obliged to learn the theory should not despair – it is bound to come in handy sometime.) In the final section, we take a look at some specialist filters that have become favourites of DSP designers all over the world. They allow clever things to be done with less memory, fewer cycles, or better response than the standard approaches.

General filter design options Basic filter types Whether designing a conventional analogue or state-of-the-art digital filter, the first decision is which type of filter is needed – lowpass, bandpass, highpass, etc. Usually this is self evident from the application, but with the added flexibility of digital filtering, it is worth giving this process a little more thought. For example, suppose you are designing a voice scrambler for covert operations, and you need to limit the high frequency content to below 3 kHz in order to keep the sampling rate below 8 kHz. Simple you say, a low pass filter with 3 kHz cut off is needed. However, there is DC offset on the input sampled signal arising in the A/D converter, which must be removed as you will be using a mixing process to achieve the scrambling and any DC component will result in an annoying tone in the audio. OK, so a bandpass filter, say from

6.2 6.2.1

339

340

Chapter 6 ❚ Applications toolbox II: digital filter design

300 Hz to 3 kHz is needed. Maybe, but in order to simplify the mixing process, you want to make use of some of the quadrature frequency shift algorithms described in ToolBox I. These require that the input signal is in a quadrature form, which suggests a Hilbert transform filter should be used. But Hilbert transforms filters are best designed as bandpass filters with symmetry about 1/4 of the sampling frequency. Now the filter we need is a Hilbert transform filter with 300 Hz to 3700 Hz passband. Figure 6.1 illustrates the basic filter types that should be considered.

6.2.2 Filter parameters Having chosen the filter type, it is then necessary to define a few basic filter parameters as outlined in Table 6.1.

Filter gain transfer function Figure 6.2 shows the transfer function for a generic lowpass filter. This clearly shows the passband (minimum or zero attenuation) extending from 0 to f1, the stopband extending from f2 to 0.5fs (maximum attenuation) and the transition band (the bit in between). The passband has a ripple associated with it (no filter has a perfectly flat gain response) which is usually specified in dB, and the stopband has an attenuation associated with it – again usually expressed in dB. Figure 6.1 Basic filter types

Lowpass

Standard Average Raised/root raised cosine SINC equalizer Halfband

Highpass

Standard AC coupling Differentiator Hilbert transform

Bandpass

Standard Hilbert transform

Bandstop

Standard Notch Comb

Multiband

General filter design options

341

Filter Parameter

Notes

Passband(s)

Each passband is defined by a start and stop frequency. In the case of lowpass or highpass filters, some design packages assume a start frequency of 0 Hz (lowpass) or a stop frequency of fs/2 (highpass).

Stopband(s)

As for the passband, the stopband is defined by a start and stop frequency. In the case of low pass or highpass filters some design packages assume a start frequency of 0 Hz (highpass) or a stop frequency of fs/2 (lowpass).

Passband ripple

This is usually defined as the maximum acceptable deviation in the gain response of the passband from unity, expressed in dB (sometimes it is expressed as a percentage).

Stopband attenuation

This is defined as the minimum attenuation required in the stopband, expressed in dB.

Transition band

Any practical filter must have a finite transition region between passband and stopband where the attenuation changes with frequency.

Phase response

Filters can either have a phase response that changes linearly with frequency (most FIR filter designs), or non-linearly (most IIR filter designs).

Group delay

Group delay is the rate of change of phase with frequency. A linear phase filter will exhibit constant group delay which ensures minimum distortion of the filtered waveform.

Coefficient length

The accuracy with which a digital filter can be implemented is dependent on the precision with which the filter coefficients (equivalent to component tolerance in analogue filters) and the data samples are represented. Most CAD packages allow the designer to evaluate the effects of finite precision sample representation on the filter response.

Implementation method

There are a number of algorithms for implementing the same digital filter, each having a greater or lesser sensitivity to parameters such as word length, quantization noise, stability and algorithm complexity.

Table 6.1 Filter design parameters Figure 6.2 Generic Lowpass Filter Specification

Passband ripple = 20log10(1–δ) 1 (1–δ)

Transition band

α f1 Passband edge = f1 Stopband edge = f2

f2

0 Stopband attenuation = 20log10(α)

342

Chapter 6 ❚ Applications toolbox II: digital filter design

Thus, a possible set of data defining this filter for entry into a filter design package is: Comments Filter type

Lowpass

Sampling frequency

8000 Hz

Most filter design packages allow the user to specify a sample rate

Passband edge (1)

0

For a low pass filter, most sensible packages infer that the lower passband edge is 0 for a low pass filter, but some do not!

Passband edge (2)

2000 Hz

0.25fs

Passband ripple

0.1 dB

Deviation from unity gain

Stopband edge (1)

3200 Hz

0.4fs

Stopband edge (2)

4000 Hz

0.5fs Again, for a low pass filter, most sensible packages infer that the upper stopband edge is fs/2 for a low pass filter, but some do not!

Stopband attenuation

40 dB

Minimum attenuation required

Filter phase/group delay transfer function The next properties of a filter that must be considered are the phase and group delay response. Group delay is simply the rate of change of phase with frequency, and is a measure of how much a given frequency component within a signal will be delayed as it passes through the filter (Figure 6.3). Ideally, a filter would have zero delay, but this is not physically possible, and so the delay needs to be taken into account. A constant group delay through a filter requires that the filter phase response decreases linearly with frequency (i.e. the rate of change of phase is constant) (Figure 6.4). Such a filter is known as a linear phase filter. Constant group delay (linear phase) is particularly important in applications where the signal wave shape needs to be preserved, such as in high speed data transmission, or in high fidelity audio or video applications. The effect of non-constant group delay on a data signal is clearly illustrated in Figure 6.5, and should be avoided if at all possible. Whilst with analog filters, it is not possible to design a filter with perfectly linear phase and constant group delay, it is remarkably simple to do so with a digital filter. Usually, this type of filter goes under the heading of a Finite Impulse Response Filter (FIR) and is discussed in the next section.

Gain

Gain

General filter design options

Frequency

Phase

Phase

Frequency





df

df

Frequency

Group delay = –dφ/df

Group delay = –dφ/df

Frequency

Frequency Figure 6.3 Phase/Group Delay Response of a Simple Filter

Frequency Figure 6.4 Phase and Group Delay of a Linear Phase Filter

Digital filter imperfections Just as analog filters are subject to imperfections such as component tolerance, cross-talk, instability, etc, so digital filters are affected by parameters such as data word length and coefficient length, order of commands in the algorithm, overflow in the accumulator, and round-off/truncation noise. Again, the effect of each of these imperfections can be minimised by choosing the correct set of options from the filter design menu as outlined in the following sections.

343

Chapter 6 ❚ Applications toolbox II: digital filter design

Group delay = –dφ/df

344

Frequency

Figure 6.5 Effect of non-linear phase (variable group delay) on digital waveform

6.3 Digital filter methods There are two main classes of digital filter, FIR and IIR. They have very different properties as described below, and next to the selection of whether your filter is lowpass, bandpass, etc, this is the most important decision of the filter design process.

6.3.1 Finite impulse response As the name suggests, FIR filters, unlike all analog filters, have a finite length impulse response. So, if you apply an impulse to the input of an FIR filter, the output will change only for a finite number of samples, corresponding to the filter length (Figure 6.6). (Note the term filter length, which is often used as an alternative expression to filter order for digital FIR filters.) The main attraction of an FIR filter is that it can provide a perfect linear phase response and hence constant group delay across the frequency band. Just what is needed for distortion-free signal processing. It also can be implemented using very simple algorithms (Section 6.6) – in fact the algorithm can be the same regardless of filter length. With these two major benefits, FIR filters are the first choice for any sensible design engineer, unless they are strapped for data memory or processing cycles. At the end of this section, we give a simple comparison between an FIR and IIR filter in terms of filter properties and implementation complexity to help you make the crucial FIR/IIR choice. Other benefits of FIR implementations are a reduced sensitivity of the algorithm to finite precision arithmetic, round-off errors and a guaranteed stability (they do not mysteriously turn into oscillators!).

Digital filter methods

FIR

Figure 6.6 Typical FIR and IIR filter impulse response

IIR

Filter delay The group delay through an FIR filter is directly related to the number of coefficients (taps), N, in the filter and the sampling period Ts, and is given by: FIR Filter Delay = (N – 1)Ts/2

Infinite impulse response

6.3.2

Not surprisingly, an IIR filter has an infinite impulse response (in theory). So, if we apply an impulse to the input of an IIR filter (just like an analog filter), the output will change indefinitely, see Figure 6.6. These changes become so small after a while that for all practical purposes the filter has settled to a finite state. Theoretically, however, they are still there (see Chapter 9), and so IIR is the chosen name. An IIR filter does not have perfect linear phase response, but, at the expense of some complexity can be made to exhibit a near-linear phase response. Usually this complexity is far greater than the equivalent FIR filter realization making IIR the firm second choice for most low waveform distortion applications. There are two big benefits of IIR filters which save them from oblivion. Firstly they can be used to mimic the response of most analog filters. Thus, if you really must have a fourth-order Butterworth filter response you can realise this pretty accurately using an IIR filter (with one or two sampling considerations as discussed in Chapter 9). Secondly, they usually require much less data memory and a lot less execution cycles for a given gain response (note: not an equivalent phase response) than the FIR implementation. On the negative side, the algorithms to realize IIR filters are more complex (but we give you examples so this should not be a problem), they are more sensitive to finite word lengths in fixed-point processors, they exhibit more round-off noise, and they can, on the odd occasion, exhibit annoying instability if the design is not quite right.

FIR/IIR comparison To highlight the differences between an FIR and IIR digital filter, we will look at the results of using these two methods to realize the simple low pass filter shown in Figure 6.7

345

6.3.3

346

Chapter 6 ❚ Applications toolbox II: digital filter design

Figure 6.7 Example Lowpass Filter Specification

Passband ripple = 0.3 dB 1

–30 dB 200 250 Stopband attenuation = 30 dB

Filter class

Filter order

Data memory needed

Approx. no. of program cycles

(coefficients & samples) FIR (Kaiser Window Method)

32 (33 taps)

66

36

FIR (Equiripple)

26 (27 taps)

54

30

IIR (Elliptic)

4

11

25

IIR (Butterworth)

15

39

81

Table 6.2 Comparison of FIR and IIR filter algorithm requirements

This filter is specified only in terms of its gain transfer function (i.e. no mention of linear phase, group delay, etc) and so both IIR and FIR solutions are applicable. Using one of the standard design packages, Table 6.2 gives the headline parameters of filters meeting the mask. The differences between the response of each of these filters which will influence the choice of which one you should use is covered in the following sections.

6.4 Digital filter design options Having made the fundamental choice of FIR vs IIR filter, the next step in the decision making process must be taken. The choices again vary for each filter method and are described below. They are the ‘fine tuning’ of the filter. If you are desperate to get on and build the filter, you can pick any one of the options discussed here, and a reasonable filter design will appear. HOT TIP

Equi-ripple FIR filters are a good candidate for a basic reliable and efficient filter implementation. Example code is given in Section 6.6 and on the web site.

Digital filter design options

Figure 6.8 Ideal Brick-wall Filter Response and Effect of Truncation

1

0

(a)

fc

t (b)

t (c)

1

(d)

347

0

348

Chapter 6 ❚ Applications toolbox II: digital filter design

6.4.1 FIR There are three main design methods by which the parameters of an FIR filter meeting a given specification can be calculated. Each method gives a slightly different result – perhaps faster roll-off for a given filter order, less passband ripple, or greater control of the stopband attenuation.

Window method The term ‘windowing’ is a common term in digital signal processing, but if you have jumped straight into this ToolBox, you may not have come across it before. In the context of FIR filter design, the main purpose of specifying a window function is to control the degree of ripple in the passband, attenuation in the stopband, and the rate of roll-off in the transition region, whilst still complying with a given mask. Windowing works as follows. Suppose we wish to implement a perfect low pass filter (Figure 6.8(a)) with a ‘brick-wall’-like roll off characteristic. The impulse response of such a filter would need to be of the form shown in Figure 6.8(b), which extends to infinity. We know, however, that an FIR filter cannot replicate an infinite impulse response, only managing to implement a truncated version (Figure 6.8(c)). The effect of truncating the impulse response is to degrade the filter frequency response from the ideal as shown in Figure 6.8(d). This crude truncation of the impulse response is like viewing the infinite impulse response through a rectangular window and selecting only that part of the impulse response visible though the window. So what happens if a different shape of window is used to truncate (view) the impulse response? Figure 6.9 shows the effect of different Figure 6.9 Effect of Window Functions on FIR Filter Response

Hanning

Rectangular t

Kaiser

1

Kaiser Hanning Rectangular

0

Digital filter design options

349

window functions on the resulting filter transfer function. Even though each filter has the same length of impulse response after windowing, the filter characteristics (ripple, stopband attenuation, transition band) are all slightly different. A window that gives a smoother truncation of the impulse response, e.g. Hanning window, generates less passband and stopband ripple, but the transition band gets wider (for the same filter length). This then is the ‘fine tuning’ that you can achieve by using the window method and selecting from one of a growing number of favourite window shapes. (You can of course create your own!). There is nothing for it but to experiment with these windows when designing your filter to see if they bring any tangible benefit to your design. Most people opt for a Hanning or Kaiser window when they have had a brief play, as these seems a good compromise in most applications. Table 6.3 gives the transfer function for many of the common window functions used in digital filter design, together with their characteristic shape.

Equi-ripple method One feature that is common with all window-based FIR filter designs is that the passband and stopband ripple is not at a constant level throughout the band. This implies that the filter is exceeding the specification for much of the passband or stopband. The question then arises – is it possible to design an FIR filter that has an equal level of ripple throughout the passband and stopband and which will be of shorter length (lower order) as a result? Figure 6.10 shows the response for an equi-ripple FIR filter design (also a standard option on most filter design packages) and compares the response with the Kaiser window design seen earlier. Both filters meet the same specification, and are of equal length. The equi-ripple approach does not therefore automatically lead to any saving in filter complexity. A major attraction of the equi-ripple design method is that is gives independent and precise control of the degree of ripple in passband and stopband.

Frequency sampling (IFFT) method As the name suggests, an FIR filter can be designed by simply sampling the frequency response of the filter you wish to create (Figure 6.11(b)) and then performing the inverse discrete Fourier transform on the samples (see ToolBox III) to give the corresponding sampled time impulse response, i.e. the coefficients (taps) for the filter (Figure 6.11(c)). This gives rise to a filter that will have a frequency response that exactly matches the template at the sampling points, but will in fact differ in between the sample points (Figure 6.11(d)). With this method, an approximation to any spectral filter shape is possible. This approach has been used to generate matched filters, such as raised cosine and root raised cosine filters (Section 6.9.7). One of the other properties of the filter sampling method is that it can lead to a more efficient algorithm implementation of an FIR filter, by using feedback as part of the design. It is also possible to design filters with integer coefficients using this approach, or

HOT TIP

350

Chapter 6 ❚ Applications toolbox II: digital filter design

Table 6.3 Common Window Functions

Window Type

Window Function (Window Length=M-1) 0 ≤ n ≤ M-1 2πn 0.54 – 0.46 cos ––––– M–1

Hamming

1 2

Hanning

2πn M–1

(

–– 1 – cos –––––

)

2

2

M–1 M–1 –––––)–(–––––) ] [ ( 2 2 –––––––––––––––––––– M–1 I [α(–––––)] 2 M–1 2(n – –––––) 2 1 – ––––––––––– I0 α

Kaiser

0

Triangular

M–1

2πn 4πn 0.42 – 0.5 cos ––––– + 0.08 cos ––––– M–1 M–1

Blackman

M–1 M–1 1, n – ––––– ≤ α ––––– 0 < α < 1 2 2 1 n – (1 + a)(M – 1)/2 –– 1 + cos ––––––––––––––––– π 2 (1 – α)(M – 1)/2 M–1 M–1 α(M – 1)/2 ≤ n – ––––– ≤ ––––– 2 2

|

[

Tukey

|

(

)]

|

|

Rectangular

Tukey Kaiser Triangular

Hanning

Hamming Blackman

Digital filter design options

351

Figure 6.10 Comparison of Equi-ripple vs Kaiser Window Filter Design

1

Kaiser Equiripple

0

Figure 6.11 Filter design using the frequency sampling method

Desired frequency response

(a)

Frequency Samples of frequency response

(b)

Frequency

Samples generated by inverse DFT

Time

(c)

Actual filter response

(d)

Frequency

352

Chapter 6 ❚ Applications toolbox II: digital filter design

coefficients that are powers of 2, making them well suited to implementation on less sophisticated microprocessors of gate arrays.

6.4.2 IIR We have already seen that the IIR filter can realize a given gain transfer function with using less processor memory and faster execution time than the FIR equivalent, albeit sacrificing a linear phase response in the process. Many signals, especially voice, are very tolerant to non-linear phase effects, and IIR filters can be used in this context without the user noticing any appreciable degradation in subjective voice quality. Where code space and memory space is tight, it is always worth looking to see if an IIR filter can be squeezed in where an FIR filter cannot. Additionally, if it is necessary to mimic a particular analog filter response (e.g. Butterworth, Chebychev) using DSP, then IIR filtering is the answer. The following covers the three key design methods for IIR filters.

Bi-linear transform The bi-linear transform can be used to take a transfer function H(s) for an analog filter (assuming that you know it!), and converting it into a discrete transfer function H(z) which is amenable to digital filter realisation. It uses a simple mapping from the analog s plane to the digital z plane of: s = k(z – 1)/(z + 1) where k = 1 or 2/T More about the theory and implementation of this mapping can be found in Chapter 9. For the moment, we shall simply acknowledge that this bi-linear transform is a valid and effective way of designing filters and take advantage of it in our quest to generate an analog equivalent filter response. There are five classic analog filter types, with different gain and phase transfer function properties. These are listed in Table 6.4 and illustrated in Figure 6.12. Most filter design packages allow you to select which of these five filter responses you wish to mimic with the digital design, and the transforming, frequency warping, coefficient calculation, etc, is all done for you without an equation in sight. Table 6.4 Classic Analog Filter Types

Analogue Filter Type Filter Properties Bessel

Near linear phase, minimal group delay distortion

Butterworth

Smooth passband/stopband gain response. Modest group delay variation

Chebychev (Type I)

Gain ripple confined to passband, smooth stopband attenuation response

Chebychev (Type II)* Gain ripple confined to stopband, smooth passband attenuation response Elliptic

Ripple in both passband and stopband. Gives lowest-order filter design (minimum filter complexity) for a given filter mask

* Sometimes called inverse Chebychev

Digital filter design options

Elliptic

Chebychev type I

Butterworth

Chebychev type II

Bessel

Because the bi-linear transform is based on a mapping of the frequency domain transfer function of the analog filter, the frequency response of the digital equivalent can be very close to the original. However, the time domain (impulse response) may be less accurate. This brings us nicely on to the impulse response invariant design method.

Impulse invariant With the impulse invariant design method, the impulse response h(t) of the analog filter is mapped into the Z domain, rather than the frequency domain transfer function H(s). The result is that the resulting digital filters will have matching impulse response to the analog equivalent (at the points where is it sampled), but may have a less accurate match in the frequency response. Again, the detail of the impulse invariance design method is given in Chapter 9. The impulse invariant design method is not suitable for high pass filter designs and is best used for low pass filters where the passband is a small percentage of the sampling frequency.

Matched Z transform A third IIR design method involves matching the pole-zero locations in the s plane of the analog filter with pole-zero locations in the z plane for the digital filter. This is a sort of halfway house between the bi-linear transform which strives to match the frequency response and the impulse invariant which strives to match the time response for a given filter. Clearly, this method wins out if precise matching of pole-zero locations is your design goal.

Comparison of IIR filter design methods Of the three main IIR filter design methods outlined, the bi-linear transform is the most commonly used, simply because most filters are intended to achieve a given frequency

353

Figure 6.12 Transfer function of classic analog filter types

354

Chapter 6 ❚ Applications toolbox II: digital filter design

Table 6.5 Summary of IIR filter design options

IIR Filter Design Method Key Features Bi-linear transform

Achieves good frequency response match between analog template and digital realization. Impulse response may differ slightly. (recommended for most applications)

Impulse invariant

Achieves accurate impulse response match with analog template at the sampling points, but poor frequency response match. Best suited to lowpass filter implementation

Matched Z transform

Achieve a match of the pole-zero locations of s-plane analog filter with z-plane digital filter.

response and frankly we do not care about the corresponding impulse response or polezero placement. Table 6.5 summarises the features of these three design choices.

6.4.3 Direct pole-zero placement As the gain and phase response of all digital filters is ultimately determined by the location of the poles and zeros in the z domain, one method of filter design that lends itself to CAD packages with nice graphical interfaces is the direct placement of poles and zeros onto the z plane diagram, and moving them around until the desired gain and phase response is achieved. This approach is particularly useful for designing simple notch filters or gain compensation filters, but becomes impractical for filters requiring more than a handful of poles or zeros. It is also great fun and very revealing to have a play with a direct pole-zero design tool – in fact, so much so that we have included a free graphical design tool on the CD and web site. To get you started, here are some basic rules about pole-zero placement and the filter response that results. Again, more discussion can be found in Chapter 9.

Using zeros ■







A zero placed within the unit circle of the z plane will cause a reduction in filter gain at the frequency corresponding to the location of the zero (Figure 6.13(a)). The closer the zero is to the unit circle, the greater the attenuation at that frequency, with maximum attenuation occurring when the zero is on the unit circle (Figure 6.13(b)). If a zero is placed anywhere other than on the ‘x axis’, then zeros must be used in pairs (complex conjugate), (Figure 6.13(c)) assuming that a real impulse response is desired. Adding additional zeros simply increases the number of frequencies at which attenuation can be achieved, or reinforces the attenuation at a given point if they are co-located (Figure 6.13(d)).

Digital filter design options

Figure 6.13 Zero-based filter designs (a)

(b)

(c)

(d)

Using poles ■



■ ■



A pole placed within the unit circle creates a peak at the corresponding frequency (Figure 6.14(a)). Poles close to the unit circle give larger peaks than those near the center (Figure 6.14(b)). Poles also must be in pairs when not located on the ‘x axis’ (Figure 6.14(c)). Adding poles increases the number of peaks realized or increases the selectivity of a given peak (Figure 6.14(d)). Poles placed very close to the unit circle result in filters with very long impulse responses close to instability (Figure 6.14(e)).

355

356

Chapter 6 ❚ Applications toolbox II: digital filter design

(a)

(b)

(e)

(c) (f)

(d)

Figure 6.14 Pole based filter designs





Poles placed on the unit circle will result in the design of an oscillator! (can be very useful if you are looking to design an oscillator (see Toolbox I) (Figure 6.14(f)). Poles placed outside the unit circle result in unstable feedback loops!

Poles & zeros Poles and zeros together can create magnificent filters (Figure 6.15). Have fun! Figure 6.15 Combined pole-zero filter design

Digital filter structures and quantization effects

Digital filter structures and quantization effects

357

6.5

We are almost at the end of the design options on the filter menu list, and have reached a topic that can impact significantly on the success of your filter implementation, particularly if you have chosen an IIR solution. There are a number of different ways (algorithms) in which a digital filter can be constructed, some leading to smaller program size, some having greater tolerance to coefficient and sample word length restrictions, some generating less quantization noise, and some simply less likely to go unstable. The options for FIR and IIR filters are discussed below. Again, if you are in a hurry, use the direct form for FIR and the cascade form for IIR and you will most likely get the result you are looking for.

FIR

6.5.1

There are four key structures for implementing an FIR filter, which are introduced briefly here. One method, the direct form, stands out above all the others due to its simplicity and effectiveness, and will be the designer’s choice in most applications. The other methods have benefit in specialist areas such as speech processing, realizing extremely long filters, or working with integer coefficients.

Direct form Figure 6.16 gives the structure for the direct form FIR filter. This is by far the most commonly used structure for FIR filter implementation, being both simple and foolproof. The implementation involves multiplying delayed samples of the input signal with the filter coefficients (taps) and summing the results together to form the filtered output samples. The filter coefficients in this case are simply the values of the sampled impulse response for the filter, albeit scaled to maximize the word length available in the DSP.

For linear phase FIR filters, the filter coefficients h(0) and h(n), h(1) and h(n–1), h(2) and h(n–2), etc., are identical. The filter structure can therefore be simplified by adding the outputs of the corresponding delay element pairs followed by multiplication by a single tap (i.e. either h(1) or h(n), etc.).

To illustrate the operation of the direct form filter, consider the following simple example of an FIR highpass filter.

HOT TIP

358

Chapter 6 ❚ Applications toolbox II: digital filter design

Figure 6.16 Direct Form FIR Filter Structure

x(n)

Z–1

Z–1

h(0)

Z–1

h(1)

Z–1

h(2)

h(n)

y(n)

Example FIR filter calculation

x(n)

A simple high pass FIR filter uses three taps, with coefficient values of

Z–1

Z–1

h(0) = –0.25 h(1) = 0.5

–0.25

0.5

–0.25

h(2) = –0.25 The high pass nature of the filter is easy to determine by making the input to the filter, x(n), equal to a constant value of unity. As this sample value is propagated through the filter, the output of the filter is as follows:

y(n)

y(0) = 1 × (–0.25) = –0.25 y(1) = 1 × (–0.25) + 1 × (0.5) = 0.25 y(2) = 1 × (–0.25) + 1 × (0.5) + 1 × (–0.25) = 0 y(3) = 1 × (–0.25) + 1 × (0.5) + 1 × (–0.25) = 0 y(4) = 0, etc with zero output (high pass filter for DC input) is the steady state. Consider now the output of the filter for an input signal at half the sampling rate (fs/2) such that it oscillates between sample values of x(n) = 0.5 and x(n + 1) = –0.5. The output of the filter in this case is: y(0) = 0.5 × (–0.25) = –0.125 y(1) = –0.5 × (–0.25) + 0.5 × (0.5) = 0.325 y(2) = 0.5 × (–0.25) + –0.5 × (0.5) + 0.5 × (–0.25) = –0.5 y(3) = –0.5 × (–0.25) + 0.5 × (0.5) + –0.5 × (–0.25) = 0.5 y(4) = –0.5 y(5) = 0.5, etc. and passes the input signal with no attenuation.

Digital filter structures and quantization effects

359

Now try applying the filter yourself to a sampled signal at fs/4, where the input sample values are x(n) = 0, x(n + 1) = 0.5, x(n + 2) = 0, x(n + 3) = –0.5, etc. You should find that the output signal reaches a steady state value of y(n) = 0, y(n + 1) = 0.25, y(n + 2) = 0, y(n + 3) = –0.25, etc. The filter thus has an attenuation of 0.5 or 6dB at this frequency.

Frequency sampling A second filter FIR filter structure is shown in Figure 6.17. This is known as the frequency sampling form, and can lead to a modest saving in the number of filter coefficients needed to realize a given filter mask. It is also possible to implement FIR filters with integer coefficients, or coefficients that are simple powers of two, using this structure, making it attractive for use with less sophisticated processors or simple gate arrays. Unfortunately, many design packages do not support this structure.

Lattice structure The lattice filter is a structure used almost exclusively in speech compression algorithms. It provides two outputs, one corresponding to the filtered signal, and the other being a measure of the autocorrelation which is used to drive the compression algorithm. The structure is shown in Figure 6.18. The implementation is more complex than the direct form FIR, which accounts for its restricted use. It is also not supported by the CAD packages, although the lattice coefficients can be calculated from the direct form coefficients. H(0)

x(n)

Z–1

Figure 6.17 Frequency Sampling FIR Filter Structure

Z–1 –1 H(1) y(n) Z–1 ej2π/N H(n)

Z–1

Figure 6.18 Lattice FIR Filter Structure

j2π(N–1)/N

e

y(n)

p

p

p

p

p

p

1

x(n)

2

1

Z–1

Z–1

n

2

n

Z–1

360

Chapter 6 ❚ Applications toolbox II: digital filter design

FFT based One further method of FIR filter implementation is to use a time–frequency transform, such as the DFT or FFT (see ToolBox III) to convert the time samples into frequency samples. The desired filter mask (which is of course specified in the frequency domain) can then be overlaid onto the frequency domain samples (Figure 6.19) to give the filtered frequency domain samples. An inverse frequency–time transform then generates the time samples of the desired filtered output. This may seem a very long-winded method compared to the direct form FIR structure, and indeed it is. The attraction of the FFT approach however is that for long filter lengths (e.g. above about 160 coefficients), the processing time involved becomes significantly less than the direct form method. Further discussion on how to implement filters using the frequency domain approach is given in Chapters 7 and 9, where the whole topic of convolution is examined.

6.5.2 IIR As with FIR filter structures, there is one commonly used form, the cascade form, which will serve most applications. The other two forms discussed, parallel and direct, each have disadvantages compared to the cascade form as described below.

Cascade form The cascade IIR filter structure is shown in Figure 6.20 and consists of a sequence of second-order filter sections, with each additional section operating on the output of the previous section(s). As each of these sections can have gain or loss at a particular frequency, care is needed in the scaling of inputs and outputs to avoid overload, or signal quantization if the level is too low. An attraction of the cascade form from the designer’s perspective is that the filter can be easily debugged by observing the output between filter stages, checking for overload, noise or instability. A further benefit of the cascade form is that it is relatively insensitive to coefficient quantization and round-off noise (see Section 6.5.3). Most filter design packages support the cascade form as a default, and will predict the inter section gain scaling needed to maximize signal to noise performance throughout the entire filter. Figure 6.19 FFT based FIR filter implementation

x(n)

FFT Inverse FFT

h(n)

FFT

y(n)

Digital filter structures and quantization effects

a(01)

a(02) a(11)

x(n)

361

Z–1

a(12)

Z–1

Z–1

y(n)

Z–1

a(21)

a(22)

b(11)

b(12) b(21)

b(22)

To illustrate the operation of the cascade form filter, consider the following simple example of an IIR highpass filter. 1

Example IIR filter calculation A simple high pass IIR filter uses a single feedback tap, with a coefficient value of

x(n)

y(n)

Z–1

b(11) = –0.9

–1

a(01) = 1 a(11) = –1

–0.9

(this represents a first-order IIR filter). With a constant sample value x(n) of unity at the input, the output becomes: y(0) = 0 (initial value) y(1) = 1 × [1 + 0 × (–0.9)] + –1 × [0] = 1 y(2) = 1 × [1 + 0.1 × (–0.9)] + –1 × [0.1] = 0.9 y(3) = 1 × [1 + 0.91 × (–0.9)] + –1 × [0.91] = –0.81 y(4) = 1 × [1 + 0.181 × (–0.9)] + –1 × [0.181] = 0.729 ....... y(48) = –0.00768, y(49) = 0.00707, y(50) = 0.00636 Eventually, the output approaches zero, implying a true AC-coupling or highpass filter response. If we now apply a sampled input at fs/2, with x(n) = 0.5, x(n + 1) = –0.5, etc, the output becomes: y(0) = 0 (initial value) y(1) = 1 × [0.5 + 0 × (–0.9)] + –1 × [0] = 0.5

Figure 6.20 Cascade IIR Filter Structure

362

Chapter 6 ❚ Applications toolbox II: digital filter design

y(2) = 1 × [–0.5 + 0.5 × (–0.9)] + –1 × [0.5] = –1.45 y(3) = 1 × [0.5 + –0.95 × (–0.9)] + –1 × [–0.95] = 2.305 y(4) = 1 × [–0.5 + 1.355 × (–0.9)] + –1 × [1.355] = –3.0745 ....... y(48) = 9.925, y(49) = –9.932, y(50) = 9.939 Eventually, the output reaches a steady state response with values alternating between y(n) = 10.0 and y(n + 1) = –10.0. The filter thus passes high frequencies with a gain of 20.

Parallel form The parallel IIR filter structure (Figure 6.21) implements the sum of a number of secondorder filter sections and is again a good design choice, having low sensitivity to quantizaa(00)

Figure 6.21 Parallel IIR Filter Structure

a(01) a(11)

x(n)

Z–1

Z–1 y(n)

b(11) b(21)

a(02) a(12)

Z–1

Z–1

b(12) b(22)

Digital filter structures and quantization effects

363

tion effects. Unlike the cascade form, however, it does not allow ease of debugging on a stage by stage basis, and for this reason tends to be less popular.

Direct form The direct form IIR filter is included more for completeness than for its value (Figure 6.22). It is rarely used, having very high sensitivity to coefficient quantization and of no help when it comes to debugging.

Quantization effects

6.5.3

The issues of coefficient quantization, sample quantization and round-off noise have been mentioned a number of times in this chapter, usually in connection with sensitivity of a given filter type, IIR/FIR, or filter structure, to these types of errors.

Coefficient quantization Starting with coefficient quantization, Figure 6.23 shows the response for an FIR filter for the case of 24-bit precision on the filter coefficients, and the case where the coefficients are restricted to 16 bits, 12 bits and 8 bits. The effect of coefficient quantization is clear, the stopband attenuation degrades significantly, and also the passband ripple begins to increase. These results indicate that 16-bit coefficient quantization (typical of most fixed point DSPs) will give a limit on stopband attenuation of about –75 dB to –80 dB. Filter design packages will usually allow the designer to define the coefficient word length as one of the input parameters. This provides an opportunity to adjust the filter x(n)

Z–1

a(0)

Z–1

Z–1

Figure 6.22 Direct Form IIR Filter Structure

Z–1

a(1)

a(2)

a(3)

a(n)

b(1)

b(2)

b(3)

b(n)

y(n)

Z–1

Z–1

Z–1

Z–1

364

Chapter 6 ❚ Applications toolbox II: digital filter design

Figure 6.23 Effect of filter coefficient quantization on FIR filter frequency response

0 dB

8-bit –50 dB

12-bit 16-bit 24-bit

–100 dB

specification slightly in order to mitigate some of the effects of quantization. A number of design packages provide a coefficient optimization routine to try and get a better match to the desired frequency response for a given coefficient word length. The effect of quantization error on an IIR filter depends on the filter structure. For the cascade implementation, quantization error has little effect on the filter response, as demonstrated in Figure 6.24. This is because the stopband attenuation is the composite effect of cascaded second order sections, and errors in one stage may be compensated for in subsequent stages. The parallel form on the other hand, shows a much greater sensitivity to quantization error (Figure 6.25) with similar degradation to the FIR filter case. Here, degradation in filter stopband on any section appears directly at the output. Figure 6.24 Effect of filter coefficient quantization of IIR cascade structure

0 dB

–50 dB 24-bit –100 dB 8-bit Figure 6.25 Effect of filter coefficient quantization of IIR cascade structure

0 dB

8-bit –50 dB 12-bit

–100 dB

16-bit

Digital filter algorithms

Round-off errors Round-off errors occur when the result of multiplications or additions have to be moved from the accumulator and stored in data memory. In fixed-point processors, the accumulator is usually double the data word length, i.e. 32 bits for a 16-bit processor, and so on saving the accumulator, the lower 16 bits are discarded, either by simply truncating them, or by rounding the sample to the nearest 16-bit value. The result of this process is termed round-off error, and leads to a degradation of the signal to noise ratio through the filter. The only way to minimize this problem, other than using double memory locations to store data samples, is to always ensure that the signals at each stage in the filter are scaled to their maximum whilst avoiding overload. The problem is most severe in IIR filters, where the data samples need to be stored for each section as part of the feedback (recursive) process. With the direct form of FIR filter on the other hand, the accumulator output need not be stored until all of the calculations (sample × coefficient) have been added in the double word-length accumulator, with the result that round-off noise is kept to a minimum. It is usually much better to round the data than truncate it.

Overload (overflow) errors One of the key challenges with IIR filter design, particularly for higher-order filters, is to ensure that the signal level at each stage is maximized to reduce quantization and roundoff effects, whilst not causing overflow in the accumulator and hence distortion of the filter output. As each second-order section will have different gain or attenuation, the scaling must be done on a section by section basis. Fortunately, the better CAD packages undertake this scaling process as part of the design, but there is usually room for manual optimization after the event. A detailed worked example of scaling in an IIR filter is given in Section 13.1.6.

Digital filter algorithms Because filtering is such a common part of digital signal processing, and may account for most of the data memory and program memory usage in a typical application, it is worth spending the time and effort to optimize the filter algorithm and coding for efficiency, both in execution time, storage and program cycles. It is for this reason that many designers code the filters within an application directly in assembler, rather than the more convenient high-level C offered by most compilers, which is usually less efficient. This requires a good knowledge of the assembler instructions set for the processor in question. Fortunately, the majority of DSP manufacturers supply the kernel of FIR and IIR filter algorithms in both assembler and C for their processors within the user documentation, recognizing that it is such an important part of the DSP portfolio. Also, some CAD packages provide C and assembler code directly as an output from the design process, which in most cases has been optimized for the platform in question. Algorithms for the common IIR and FIR filter designs are also available on the web site together with optimized assembler versions for the C54xx/C6xxx processor family.

6.6

365

366

Chapter 6 ❚ Applications toolbox II: digital filter design

6.7 Filter design summary Table 6.6 summarizes some of the key parameters of a filter that can influence the starting point in a design – all of these are discussed in more detail in the previous sections. The order of the digital filter needed to approximate a given response can depend in quite subtle ways on the nature of the specification. The most important general rule is that the filter order will be set by the sharpest transition, measured in terms of the ratio width of transition region in Hz/sampling rate. It is important to realize the influence of the sampling frequency on the order of digital filter required. A modest analog filter characteristic can well involve a very high-order digital filter realization if the cut-off frequency is small compared with the sampling rate. If this is the case, a reduction in the sampling rate should be considered. Section 6.9.9 describes how different filters can be implemented with different sampling rates yet make use of the same DSP device, by using the process of discrete sub-sampling and re-sampling known as decimation and interpolation. High-pass and bandstop FIR filters, where the passband includes fs/2, can only be realized using an odd number of taps, whereas Hilbert transform filters and differentiators, Section 6.9.1, which have a high-pass frequency response must have an even number of taps. The number of non-zero coefficients needed to realize a given-order FIR filter can be cut in half by the simple expedient of arranging the mask to have even symmetry about fs/4. For bandpass and bandstop filters this means that the filter must be centered on fs/4 and have equal weighting of the passband and stopband ripple. For low-pass and high-pass filters, the transition region must be centered on fs/4. This results in every second sample of the impulse response being zero. The technique is only applicable for filters with odd numbers of taps. These filter characteristics are summarised in Table 6.7. Table 6.6 Summary of FIR and IIR filter characteristics

Filter properties

Filter type IIR

FIR

Linear phase

NO (improved with equalization)

YES

Hilbert transform

YES (approximation only)

YES

Differentiator

YES (approximation only)

YES

Filter order for given gain response LOW

HIGH

Memory requirement

LOW*

HIGH*

Execution time

LOW*

HIGH*

Algorithm complexity

HIGH

LOW

Stability

GOOD (with careful design)

EXCELLENT

Sensitivity to word length

HIGH (satisfactory in most cases with 16-bit coefficients)

LOW

* Assumes identical gain response specification.

Filter design summary

Filter type

Filter property for linear phase

Low-pass

Odd or even filter lengths allowed. Impulse response exhibits even symmetry.

High-pass

Odd filter lengths only if passband includes fs/2. Impulse response exhibits even symmetry.

Bandpass

Odd and even filter lengths allowed. Impulse response exhibits even symmetry.

Bandstop

Odd filter lengths only if passband includes fs/2. Impulse response exhibits even symmetry.

Hilbert transform

Odd and even filter lengths allowed; even lengths only if passband includes fs/2. Gain must fall to zero at DC. Impulse response exhibits odd symmetry.

Differentiator

Odd and even filter lengths allowed; even lengths only if passband includes fs/2. Gain must fall to zero at DC. Impulse response exhibits odd symmetry.

367

Table 6.7 Digital Filter Design Rules

For all linear phase FIR filters, making the gain response symmetrical about fs/4 forces every second coefficient to zero (passband and stopband ripple must be identical). Such filters are called ‘half-band’ filters. Group delay x = (N – 1) Ts/2 (N is filter length)

The main options in selecting between FIR and IIR filter realisations are summarized in Table 6.8. Step 1

Determine transfer function Hd(z) to meet filter specification

IIR

FIR

Bilinear transform Impulse invariant Least squares Direct method

Window method Equi-ripple Frequency Sampling Least squares FFT

Step 2

Choose appropriate filter structure

IIR

FIR

Parallel Cascade Lattice Direct form

Direct form

Step 3

Perform gain scaling where necessary

IIR

FIR

Essential Often complex process

Usually unnecessary Very simple process

Table 6.8 Summary of Design Steps for IIR and FIR Filters Types

368

Chapter 6 ❚ Applications toolbox II: digital filter design

Table 6.8 (Continued)

Step 4

Define processing algorithm

IIR

FIR

Difficult to optimize

Very straightforward

Step 5

Code generation

IIR

FIR

Average complexity

Very simple

6.8 Filter design packages For anything but the most basic first- and second-order filter realizations, the acquisition of a digital filter design package is to be recommended. Not only does it trivialize the task of filter coefficient derivation, but provides the flexibility and speed to select the appropriate filter type almost by trial and error. This is particularly useful when faced with limited DSP processing time for a given filtering task, and, perhaps more importantly, limited development time. Filter design software packages will appeal immediately to all those engineers who have attempted to derive the transfer function Hd(z) for a filter requirement by hand. Frequency selective filters, i.e. filters where the band from zero to fs/2 Hz can be divided into passbands and stopbands, are far simpler to design with packages. All the user has to do is input the desired filter characteristics, and press the button! Gain characteristics are usually entered in the form of a mask, see Section 6.2. Most packages also contain routines for housekeeping tasks such as the evaluation and display of magnitude and phase characteristics, impulse response, step response and polezero positions. Given the importance of digital filters within DSP applications, there are surprisingly few good digital filter design packages on the market. Those that are available are listed below, some of which are standalone filter design packages, e.g. FilterShop from Linear Systems Inc. and QEDesign from Momentum Data Systems. Others are part of more general simulation packages such as MATLAB, SPW, or COSSAP. There are also a selection of free or shareware design tools, often targeted at specific filter types, e.g. equi-ripple FIR filters. Prices range from $80 to $2000 for stand-alone packages. A full list of digital filter design software suppliers, shareware tools and links is available on the web site.

6.8.1 QEDesign from momentum data systems

Filter design packages

369

The QEDesign software now an established benchmark for digital filter design. All of the QEDesign family have a good intuitive user interface (see Figure 6.26), easy navigation and you can get up and running very quickly. Perhaps more importantly, you can download demo versions of the software FREE, from the MDS web site at www.mds.com. These demo versions give you almost full functionality, but without the option to save the filter coefficient information generated. QEDesign comes in three flavors: ■





QEDesign Lite is a basic so-called student edition allowing design of the most common FIR and IIR digital filters. As a starting point for implementing your first DSP filter, this will provide all you need. Price (approx. at time of going to press) $150 QEDesign 1000 is a more advanced edition, offering a larger range of filter types, and with the ability to generate target code for a selection of popular DSPs (albeit in a somewhat cumbersome manner) and to interface to other system simulation packages such as MATLAB, SPW and COSSAP. Price (approx. at time of going to press) $1000 QEDesign 2000 is the top end package, aimed at the workstation market. It offers greater analysis of filter response, design trade-offs, etc, which may or may not come in handy. You should certainly give the Demo a trial before purchasing this package to find out whether the extra bits are worth the money. Price (approx. at time of going to press) $3500

In addition to the three standard filter design packages, MDS currently offer two further system filter design tools: Figure 6.26 Screen shot of QEDesign Graphical Interface

370

Chapter 6 ❚ Applications toolbox II: digital filter design ■



Sample Rate Conversion System provides fully automatic design of multi-stage polyphase filter networks for sample rate conversion systems. These filter networks provide optimized structures that will convert the sampling rate of signals within a specified distortion level. Multirate Filter Design System allows the design of very narrow lowpass or bandpass FIR filters (see section 6.9.10). Provides fully automatic design of multi-stage polyphase filters. A multirate filter provides computational efficiencies that are not possible in a single fixed sample rate. The automation provided by the Multirate Filter Design System eliminates the possibility of mathematical calculation error and reduces the overall filter design time. Also designs narrowband high-pass, wideband low-pass, and wideband high-pass filters.

Again, demo versions of these packages are available for download from the MDS web site.

6.8.2 FilterShop from linear systems inc.

FilterShop is positioned as the Rolls Royce of filter design packages, and is certainly a comprehensive filter design tool. Covering analog filter design, circuit simulation and synthesis as well as digital filter design, it requires some getting used to in order to successfully navigate around the many options available. Compared to QEDesign, it has the feel of a more professional (serious) package, but is also far less intuitive. In short, FilterShop is very comprehensive, and you need to be seriously into highly optimized filter design to appreciate its power. The list of features below will explain why. Price (approx. at time of going to press) $1500. FilterShop features include: ■ ■



■ ■



■ ■

Proprietary AC circuit simulator with full graphical schematic entry/editing. Three powerful target/circuit optimization engines with weighting and curve/constraint based optimization. True circuit synthesis with over 500 predefined circuit templates with built-in design equations. Elegant AC circuit design and modelling without the clutter of DC biasing circuitry. Efficient op-amp model for fast analysis including accurate noise with over 1200 models in libraries. Specialized mixed signal circuit components including FDNRs, FIR/IIR filters, Z-impedance, and potentiometers. Target generation system for creating complex ideal mixed analog/digital transfer functions. Extensive analog filter design wizards for virtually any all-pole or elliptic filter up to 32 poles/zeros.

Filter design packages ■







371

Two dozen FIR/IIR digital filter design wizards and approximation methods for linear or min/max phase. Extensive processing features for Monte Carlo, thermal, noise, and potentiometer analysis. Powerful utilities for curve import/export, graphics, curve capture, and graphical curve editing/entry. Three volume manual set comprising 1200 pages of documentation.

Example screen shots for FilterShop are given below showing the wealth of filter options available (Figures 6.27 and 6.28). Because FilterShop is such a large program, there is no demo option. More information on the features is provided on the Linear Systems Inc. web site at www.linearx.com.

The SPTOOL filter design package for MATLAB

6.8.3

The Signal Processing Toolbox which is available for MATLAB includes an interactive graphical user interface, GUI, called SPTool which is used for performing various digital signal processing tasks including filter design. SPTool allows the user to import signals and spectra, filter or process them and then analyze the resulting data. Figure 6.27 Graphical Interface for FilterShop

372

Chapter 6 ❚ Applications toolbox II: digital filter design

Figure 6.28 Comprehensive Digital Filter Window Design Options for FilterShop

Within SPTool, it is possible to import signals, filters, and spectra either from the MATLAB workspace or as MAT files. Through SPTool, the user can access four additional GUI tools that provide an integrated environment for signal browsing, filter design, analysis, and implementation. The four components of the interactive signal processing environment include: ■

The Signal Browser, which provides a graphical view of the signal objects currently selected in SPTool and enables the user to display, measure, analyze, and print these signals interactively.



The Filter Designer, which allows the user to create and edit low-pass, high-pass, bandpass, and bandstop FIR and IIR digital filters of various lengths and types using the filter design functions of the Signal Processing Toolbox.



The Filter Viewer, which allows the user to view various characteristics of a filter that has been imported or designed, including its magnitude and phase responses, group delay, zero-pole plot, and impulse and step responses.



The Spectrum Viewer, is used to create, view, modify, and print spectra interactively, and to perform graphical analysis of frequency domain data using a variety of common methods of spectral estimation.

Although SPTool does not have the ability to generate filter coefficients in a specific DSP ready format, it is a very simple matter to write a MATLAB routine which will convert an SPTool filter design into any format required. This is one of the benefits of using MATLAB since it is a powerful programming language and it can be modified to suit specific applications. The screen shot in Figure 6.29 shows various SPTool GUI windows in use whilst a filter is designed.

Specialist filter types

373

Figure 6.29 Screen shot of SPTool within the MATLAB programming environment

Free/shareware design packages

6.8.4

In addition to the professional filter design packages described above, there is a wealth of shareware filter design tools available on the web. Most are tailored to a specific type of filter and lack the user interface finesse of the options above. A list of the links to the most popular shareware tools is available on the DSPStore.com™ web site.

Specialist filter types

6.9

Having gone through the ‘pocket guide’ to basic digital filter design and got you enthused about the flexibility and ease of design, implementation and execution, we now turn our attention to some special filter types within these general filter families. These specialist filters exploit key properties of IIR and FIR filters to achieve additional value than simple filtering, or to further reduce complexity or execution time for a given filter process.

Hilbert transform filter To emphasise the importance of the Hilbert transform filter in nearly all aspects of digital signal processing, let us consider a musical example. Your band, ‘the Digitizers’ has just

6.9.1

374

Chapter 6 ❚ Applications toolbox II: digital filter design

landed your first gig in the local pub and you are determined to woo the audience with your amazing guitar playing, aided by your special effects box – the one you have designed, built and programmed yourself using a $99 DSP starter kit. The effect you really want to achieve is an automated wah-wah pedal (does this date me?) which can alter the frequency of your guitar in sympathy with the frequency of your bass string. You sketch the idea out on the back of an envelope (see opposite), and quickly realize that you need a filter to select the base string signal (simple!) and then a mixer process to somehow change the frequency of the composite signal. Just mixing the base string note and composite signals together does not work as the output will contain the signal shifted up by the bass note and also down by the bass note and these two signals will overlap in frequency and so cannot be separated. Hmm – stuck! Only 5 h left before the gig. Enter the Hilbert transform filter ... You quickly sketch out a new design (see opposite) in which you pass the composite signal through an FIR bandpass filter and also through a delay element (to compensate for the FIR filter delay). You then mix each of these signals with the bass note and sum the outputs. Problem solved! How? The answer lies in the FIR filter – it is in fact a Hilbert transform filter. (The Hilbert transform of a signal generates a version of the signal with identical gain properties and a +90° phase shift for negative frequencies and –90° phase shift for positive frequencies.) The effect of using the Hilbert transform filter and compensating delay is that you now have two representations of the guitar signal, let’s say cos (guitar signal) and sin (guitar signal) due to the 90° phase shift introduced by the Hilbert filter. You then extract the base note giving you cos (bass note) and sin (bass note). Now you mix them together giving: cos (guitar signal) × cos (bass note) = 0.5 cos (guitar signal – bass note) + 0.5 cos (guitar signal + bass note) and sin (guitar signal) × sin (bass note) = 0.5 cos (guitar signal – bass note) – 0.5 cos (guitar signal + bass note) Summing these two signals generates the output you want, i.e. cos(guitar signal – bass note). (Note: subtracting the two signals gives you cos(guitar signal + bass note) – two effects in one!) Even though this example may only appeal to a few of us, it clearly demonstrated the power and significance of the Hilbert transform in DSP. Many of the uses of the Hilbert

Specialist filter types

375

transform, such as frequency translation, are described in ToolBox I in the context of quadrature signal processing. The real to complex transform can be achieved in a number of ways, but the Hilbert transform filter is one of the better methods. Essentially, a Hilbert transform filter can be generated from an FIR filter (either bandpass of high-pass) that has an impulse response with negative symmetry (Figure 6.30). (This negative symmetry guarantees the 90° phase shift.) If the filter has an odd number of coefficients, then the gain must fall to zero at 0 Hz and fs/2, i.e. the Hilbert transform filter must also be a bandpass filter. If the filter has an even number of coefficients, then the gain need only be zero a 0 Hz and a high-pass filter can be realized. The frequency and phase response for a bandpass Hilbert transform FIR filter is shown in Figure 6.31. Note that the magnitude response is only an approximation to the ideal, i.e. it has ripple, whilst the phase response is exactly correct (apart from the delay-induced linear phase variation). This condition is entirely controlled by the odd symmetry of the FIR filter coefficients. The passband ripple in the FIR Hilbert transform must be watched carefully as too much ripple can seriously degrade subsequent quadrature processing algorithms. The only way to reduce passband ripple is to increase filter length, or increase the filter transition region(s), i.e. make the filter less selective. We shall see in the section on half-band filters that if the filter mask is made symmetrical about fs/4, the resulting FIR filter will have every second coefficient zero, reducing the implementation complexity by a factor of two. This is true for all FIR filters. We have already identified that an FIR filter has a constant group delay, given by the formula: FIR Filter Delay = (N – 1)Ts/2 In order to generate an I/Q pair of data signals using the Hilbert transform FIR filter, it is thus necessary to compensate for this delay in the signal path that does not pass through the filter (Figure 6.32(b)). This is easily achieved for odd order length filters as the delay is a whole number of sample intervals, Ts, and a simple delay routine (ToolBox I, Section 5.4), can be used. Figure 6.30 Negative symmetry required for Hilbert Transform Filter (N odd)

(N even)

376

Chapter 6 ❚ Applications toolbox II: digital filter design

Figure 6.31 Frequency and Phase response of Hilbert Transform Filter

(a)

(b)

fs/2

f

π 2 0

f

–π 2 (c)

If an even number of coefficients is used in the filter, the resulting delay is not an integer number of samples. In this case, the solution is to replace the simple delay with a basic FIR filter having the same passband as the Hilbert filter and of equal length such that they both introduce the same delay. Hilbert transform filters are amenable to either window or equi-ripple design techniques, and are supported by most CAD design packages. A Hilbert transform can also be realized by a pair of filters (Figure 6.33), the output of one being the Hilbert transform of the other. A very simple design procedure for an FIR Hilbert transform filter pair implementations is the sin/cos transform of a low-pass filter prototype. The coefficients h(nTs) of a standard FIR low-pass filter are transformed into coefficients h1(nTs) and h2(nTs) of a pair of Hilbert bandpass filters, using the following simple procedure: h1(nTs) = 2h(nTs) sin(2rf0nTs) h2(nTs) = 2h(nTs) cos(2rf0nTs) This results in a bandpass filter pair as illustrated in Figure 6.33, centered on a frequency f0, and with a bandwidth equal to twice that of the low-pass filter prototype.

Specialist filter types

Filter phase characteristic

Filter gain characteristic

(a)

0

fs/2

H(m)

m(t)

Figure 6.32 Hilbert Transform Filter based Quadrature Signal Generation (Odd number of Coefficients)

Phase characteristic of delay line

90°

m(t – τ)

FIR filter (delay τ)

Time delay τ

m(t – τ)

(b)

If f0 is equal to fs/4, then every other term in the sin/cos transform goes to zero and consequently every alternate filter coefficient is zero. This is hardly surprising since the resulting bandpass filter response is symmetrical about a quarter of the sampling frequency, i.e. a half-band filter.

Differentiator A differentiator exhibits a gain that increases linearly with frequency, and provides a 90° phase shift. As with the Hilbert transform, the differentiator function can be realized using an FIR filter, which can provide exact 90° phase shift, but will have some error in the gain response (Figure 6.34). The higher the order of filter, the smaller the gain ripple and the more accurate the differentiator.

377

6.9.2

378

Chapter 6 ❚ Applications toolbox II: digital filter design FIA

FIA

10

10 0 H1(s)

–10 –20

N(s)

–30

SIN COS

H2(s)

–40

Attenuation (dB)

Attenuation (dB)

0

–10 –20

H1(s) H2(s)

–30 –40

–50 –60

–50

f0 y(t)

H1(s)

x(t)

^

y(t)

H2(s)

Figure 6.33 Hilbert Transform Filter Pair

The FIR differentiator must exhibit negative symmetry and must have an even number of coefficients if the differentiator response needs to extend to fs/2. If an odd number of coefficients is used, the gain must fall to zero at fs/2.

6.9.3 Comb filters Sometimes it is desirable to realize a filter with a series of notches equi-spaced along the frequency axis as would be required, for example, to remove mains harmonics. This type of filter is called a comb filter. From the discussion of filter design using direct pole-zero placement, Section 6.4.3, we know that this type of response can be achieved simply by placing zeros on the unit circle, spaced with an angular increment of 2r/k rad, where fs/k is the frequency of the fundamental to be notched out. This will give infinite attenuation at the fundamental and subsequent harmonics. The width of the notches can now be controlled with poles at the same angle, but with magnitudes slightly less than unity. The transfer function of the comb filter is thus Hd(z) =

zk – 1 zk – ak

where a is the magnitude of the poles. Figure 6.35 gives an example. It is evident that although k delay sections are needed to realize the filter, there is only one feed-forward and one feedback coefficient.

Specialist filter types

379

Figure 6.34 FIR Differentiator. (a) Even number of taps, (b) odd number of taps (N odd)

(N even)

1

+

Z–1

Z–1

Z–1

Figure 6.35 Comb Notch Filter Realization Z–1

Z–1

+ –1

αk

fs/2

f

380

Chapter 6 ❚ Applications toolbox II: digital filter design 1

Figure 6.36 Comb Resonator Filter Realization +

Z–1

Z–1

Z–1

Z–1

Z–1

+ –1

αk

fs/2

f

An example of a comb filter being used for removal of mains hum is available in the audio library on the web site. A comb resonator, capable of selecting any periodic signal with fundamental fs/k, can likewise be obtained if the zeros are all located at z = 0. This is illustrated in Figure 6.36.

6.9.4 Halfband filters A halfband FIR filter has the property that every alternate coefficient is zero, with the exception of halfband low-pass or high-pass filters where the center coefficient is 0.5 (assuming unity gain for the filter). To realize such a filter, the required filter mask must be symmetrical about fs/4, and the filter must have an odd number of coefficients. Lowpass, high-pass, bandpass, bandstop and Hilbert transform filters can all be designed as halfband filters, but not differentiators, as they cannot have symmetry about fs/4. As an example, Table 6.9 gives the coefficients for a 15-tap halfband bandpass filter. Note that the coefficients are also symmetrical about the center coefficient. HOT TIP

The great attraction of halfband filters is the 50% reduction in the number of multiplications needed and the 50% reduction in the program memory required to store the coefficients

Specialist filter types

381

Table 6.9 Filter Coefficients for Halfband Bandpass Filter

0

fs/4

fs/3

Gain Response

Impulse Response

Coefficient (Tap) No

Value

1

0

2

0.0339

3

0

4

–0.0256

5

0

6

–0.2828

7

0

8

0.5356

9

0

10

–0.2828

11

0

12

–0.0256

13

0

14

0.0339

15

0

Mth band filters The property of a so-called Mth band filter is that one out of every M samples in the impulse response is zero. In other words, for linear phase FIR filters, every Mth coefficient is zero. The most obvious example of this is the halfband filter (M = 2) described above. To realize an Mth-band filter, the filter transition region(s) must be symmetrical about fs/2M, as one might expect, and the passband ripple dp and stopband ripple ds satisfy the following condition: dp ≤ (M – 1)ds Mth-band filters, of order greater than two, generally find application as Mth-degree decimation and interpolation filters. Design of Mth band filters (M > 2) which meet the above

6.9.5

382

Chapter 6 ❚ Applications toolbox II: digital filter design

constraints is not straightforward. The Parks–McClellan program can be used; however the design is sub-optimal.

6.9.6 Quadrature mirror filters One particular class of sub-band filters which has dominated this area is the quadrature mirror filter. The quadrature mirror filter structure is shown in Figure 6.37 and incorporates both transmit (analysis) filtering and receive (synthesis) filtering. The transfer functions of the various filters are such that the combined gain response is unity and the two transmit filters are power complementary, i.e.

|H0(ejs)|2 + |H1(ejs)|2 = 1 In the configuration given, H0 and H1 are a low-pass and high-pass mirror filter pair. (It is also possible to implement a quadrature mirror filter using quadrature processing techniques, cf ToolBox I. In this case, the filters have an identical low-pass response.) Having divided the input spectrum into two sub-bands it is sensible to decimate the two bands to obtain the minimum sampling rate, before encoding. A similar interpolation stage is therefore needed in the receiver prior to recombination. The conventional quadrature mirror filter bank is thus configured as in Figure 6.38, with frequency mapping occurring as shown.

1 1/N2 H1(z)

H0(z)

fs/4

H0(z)

fs/2

f

H0(z) Channel

Figure 6.37 Quadrature Mirror Filter Structure

+

H1(z)

H1(z)

Analysis filter

Synthesis filter

383

Specialist filter types

A f's/2 f's

A

A fs/2

fs/2 H1(z) A

2

2

A H1(z)

fs/2

B

A fs/2

B fs/2

+

H1(–z)

2

2

–H1(–z) B B

B fs/2

B

fs/2

fs/2

f's/2 f's Figure 6.38 Interpolation/Decimation Based Quadrature Mirror Filter Process

To subdivide the spectrum further, quadrature mirror filters can be cascaded in a tree structure (Figure 6.39), each stage increasing the number of sub-bands by a factor of two.

Raised/root raised cosine filters (matched filters)

6.9.7

Raised cosine and root raised cosine filters are frequently used in data communications to shape the data pulses prior to transmission/modulation and on reception/demodulation. A pair of root raised cosine filters have the property of being matched filters, which allows data detection with zero inter-symbol interference. A matched filter must exhibit negative gain symmetry about the centre of the transition region (Figure 6.40). These filters are usually specified in terms of a roll-off factor a, a symbol rate, and a sampling rate. Cosine filters can be designed using any of the FIR design techniques, with the window method proving the most popular (Figure 6.41). (More information on matched filtering and raised cosine filter applications is available in Digital Communications – Design for the Real World, by the authors. See the web site for details.)

Adaptive filters Adaptive filters, as the name suggests, are filters whose gain and/or phase response can be adapted with time. The most common application of adaptive filters is in channel equaliz-

6.9.8

384

Chapter 6 ❚ Applications toolbox II: digital filter design

H2(z)

H1(z)

2

2

H2(z)

2

2

+

2

H2(–z)

2

H1(z)

–H2(–z)

+

2

H2(z)

H1(–z)

2

H2(z)

2

+

2

H2(–z)

1

0

2

2

fs/8

4

3fs/8

Figure 6.39 Quadrature Mirror Filter Bank

Figure 6.40 Transfer characteristic for matched filter

Area of symmetry

–H1(–z)

–H2(–z)

3

fs/4

2

fs/2

f

Specialist filter types

Root raised cosine

Figure 6.41 Root Raised Cosine and Raised Cosine Filter Response for FIR Window Design

Raised cosine α = 0.3 3 samples/symbol

ers for communications systems, to compensate for time-varying gain and phase distortion on a channel. In a fixed line telephone channel, the adaptation may be performed only periodically as the variations in channel response are pseudo stationary in nature. With a mobile radio channel on the other hand, adaptation must be continuous, as the channel characteristics change dynamically with mobile position. The most common form of adaptive filter is based on an FIR structure, whereby the coefficients (tap weights) are updated to realize the new gain and phase response. We have already seen that an FIR filter can be use to approximate an arbitrary gain and phase characteristic, the accuracy of the match being governed primarily by the order of the FIR filter used. Probably the most difficult task in the design of adaptive filters is the algorithm used to determine the coefficients. The first difficulty lies in obtaining a measure of the gain and phase distortion of the channel. The second problem is how to make use of the information to adapt the filter (equalizer). There are in fact several techniques for achieving both operations. One conceptually simple approach is to sound the channel using a series of equally spaced tones, the received magnitude and phase of which form the basis of a sampled frequency response of the channel. By computing the inverse of this response, and then performing the inverse discrete Fourier transform on the frequency samples, the sampled impulse response of the channel equalizer is obtained, yielding directly the FIR filter coefficients as outlined in Section 6.5. The example is rather trivial in that no feedback control path is employed and the adaptation is discrete, requiring the sounding sequence to be transmitted before each coefficient update. The more advanced equalizer filters are designed to operate continuously, deriving a control (error) signal from the incoming information stream itself. Detailed information on adaptive filter algorithms can be found in the open literature. (Note: IIR filters can also be used in an adaptive sense, giving in most cases a more efficient implementation, but requiring considerably greater sophistication in the control algorithms.) Needless to say, the advent of DSP has opened up the whole field of adaptive filtering in commercial applications

Multi-rate processing (interpolation/decimation) Although not strictly a filtering operation, the processes of interpolation and decimation almost invariably involve filtering and are thus addressed in this ToolBox. It is one of the

385

6.9.9

386

Chapter 6 ❚ Applications toolbox II: digital filter design

most powerful signal processing concepts, having a major bearing on system sampling rate, algorithm efficiency, anti-aliasing filter specifications and digital filter realizations.

Decimation Decimation is the term used to describe the ordered discarding of waveform samples, with the effect of reducing the effective sampling rate of the waveform. For example, if every other sample is discarded, the effective sampling rate is reduced by a factor of two. Provided that the new sampling rate still satisfies the Nyquist sampling criterion for the waveform, no aliasing will occur and the integrity of the digital representation remains intact. What is the purpose of decimation? One significant application is that of over-sampling (see Chapter 4). When sampling an analog waveform, it is essential that the sampling rate is greater than twice the maximum input signal frequency to avoid aliasing (unless aliasing is deliberately intended, cf Chapter 4). This criterion is usually met by placing an ‘analog’ anti-aliasing filter prior to the sampling circuitry to attenuate all components greater than fs/2. Clearly, by adopting a sampling rate much greater than twice the maximum input component frequency, the specification on the anti-aliasing filter becomes less stringent (Figure 6.42). In terms of the subsequent digital processing however, the sampling rate should be minimized, whilst still satisfying the Nyquist constraint, thereby maximizing program execution time and minimizing relative filter complexity. The solution to this apparent dilemma between internal and external sampling rates is to ‘decimate’ the deliberately ‘over-sampled’ input signal to achieve the minimum sampling rate for internal processing. The decimation process is illustrated graphically in Figure 6.43. Whilst it is possible to relax the specification of external, anti-aliasing filters, thereby achieving cheaper designs with better gain and phase characteristics, additional filtering now has to be performed digitally within the DSP as part of the decimation process. At each decimation stage, it is essential to ensure that the signal to be decimated occupies a bandwidth no greater than fs/M, where M is the sampling rate reduction factor (or at least contains no components that will be aliased into the band of interest). For the most common decimation factor of M = 2, this requires that the signal prior to decimation be subject to a low-pass filter that Figure 6.42 Effect of sampling rate on alias filter specification. (a) Low sampling rate, (b) High sampling rate (over-sampling)

Anti-alias filter response

(a)

fs/2

fs

f

Anti-alias filter response

(b)

fs/2

fs

f

Specialist filter types

fs/2

fs

f

M=2 f's/2

f's

f M=2

f''s/2

f''s

f M=2

(a)

f'''s/2 f'''s

f

f's/2

fs

f

M=8

(b)

f'''s/2 f'''s

f Desimation filter

ideally attenuates all components greater than fs/4. By making the filter transition region symmetrical about fs/4, and using a halfband FIR realization, alternate filter coefficients become zero (cf Section 6.9.4), and very efficient decimation filters can be implemented. For large orders of decimation, it is usually more efficient to cascade an appropriate number of second-order stages than to implement one Mth-order decimation, as the order and complexity of the decimation filter become excessive. By using symmetrical filtering techniques, the same decimation filter coefficients can be used for each of the cascaded second-order stages. These factors are emphasized in the narrow bandpass filter design application, Section 6.9.10. Whenever processing is to be performed on a waveform which occupies a bandwidth much smaller than fs/2, then decimation will usually result in a more efficient algorithm. For bandpass signals, the decimation process is often coupled with quadrature demodulation to obtain low-pass equivalent waveforms. Quadrature demodulation techniques are discussed in ToolBox I.

Interpolation Having minimized the sampling frequency for optimum digital processing efficiency, it is often desirable to increase the sampling rate before D/A conversion to permit relaxation of the analog reconstruction filter specification. The process is termed interpolation, and is achieved by interposing new samples between the existing samples. As for decimation,

387

Figure 6.43 Decimation process. (a) Three stages of decimation by two, (b) one stage of decimation by eight

388

Chapter 6 ❚ Applications toolbox II: digital filter design

Figure 6.44 Interpolation in the time domain. (i) Equal-sample insertion, (ii) zerosample insertion

(i) t

(ii) t (a) L = 2

(i) t

(ii) t (b) L = 4

interpolation almost always involves subsequent filtering. There are two obvious choices of sample values to insert: sample values equal to the most recent existing sample, or sample values of zero. Both methods of interpolation are illustrated in Figure 6.44. It is most common to use zero-value samples as this simplifies the digital filtering process considerably. Equal-value samples, on the other hand, result in a greater signal energy in the interpolated signal. Simply inserting samples does not in itself achieve a true increase in sampling rate since this would require the sample values to correspond with those of the actual waveform at the new sampling points. To achieve this result, the desired sample values are found by interpolating between the original waveform samples, using a filter. Figure 6.45 gives an illustration of interpolation in the frequency domain, from which it can be seen that this filter, like that used for decimation, must attenuate the ‘alias’ components about fs/2, and for simplicity should be an FIR filter with symmetry about fs/4, where fs is the new sampling rate. A degree of interpolation L is typically achieved using an appropriate number of second-order stages as for decimation, although a single interpolation stage can be entertained. Sampling rate changes by a non-integer ratio are possible by cascading a rate L interpolator with a rate M decimator. In this configuration, the interpolator output filter can also be used as the first-stage decimation filter. When interpolation is used to increase the sampling rate prior to outputting the signal, it is essential that the samples are fed to the D/A at evenly spaced time intervals within the main processing loop. If this is not the case, imperfect suppression of alias components will result.

Specialist filter types

f

f'''s L=2 f''s

Figure 6.45 Interpolation process. (a) Three stages of interpolation by two, (b) one stage of interpolation by eight

f L=2 f's

f L=2 fs

(a)

f'''s

f

f L=8

(b)

Interpolation filter

fs

f

Ultra narrowband filters To further illustrate the potential of decimation and interpolation consider the design of a narrow, linear phase bandpass filter satisfying the mask specification as shown in Figure 6.46. This calls for a passband ripple of less than 0.15 dB and a stopband attenuation of greater than 50 dB. To implement this filter directly would require 231 taps assuming an FIR equiripple design technique – a time and memory intensive task. It will become apparent that this filter can be realized far more efficiently using decimation and interpolation techniques. In order to benefit from decimation, it is first necessary to convert the bandpass signal into its baseband equivalent. This involves quadrature demodulation about the centre of the bandpass signal spectrum as illustrated in Figure 6.47 (cf. ToolBox I, Section 5.10). The process of decimation can now be used to reduce the sampling rate, in this example by a factor of 8. The decimation filters must satisfy the mask given in Figure 6.48, the most stringent specification arising from the last filter stage. In the example given, a 3-tap FIR filter can satisfy the mask for each decimation stage with identical filter coefficients. The mask for the low-pass equivalent of the bandpass filter after decimation is given in Figure 6.49 and requires 25 taps. (This is also assuming on an equi-ripple design procedure.)

389

6.9.10

390

Chapter 6 ❚ Applications toolbox II: digital filter design

Figure 6.46 Filter mask for narrow bandpass response

Park-McClellan FIR 203 taps 1.2 1.0

Magnitude

0.8 0.6 0.4 0.3

0

0.1

0.2

0.3

0.4

0.5

Fraction of sampling frequency Figure 6.47 Quadrature demodulation and remodulation process

Decimate

Interpolate

cos 2xf0t

cos 2xf0t

Decimate

sin 2xf0t

+

Interpolate

f0 = centre of bandpass filter response

sin 2xf0t

Park-McClellan FIR 3 taps

Figure 6.48 Mask for interpolation/ decimation filter

1.2 1.0

Magnitude

0.8 0.6 0.4 0.3

0

0.1

0.2

0.3

Fraction of sampling frequency

0.4

0.5

Specialist filter types

391

Figure 6.49 Mask for low-pass equivalent of bandpass filter

Park-McClellan FIR 25 taps 1.2 1.0

Magnitude

0.8 0.6 0.4 0.3

0

0.1

0.2

0.3

0.4

0.5

Fraction of sampling frequency

In order to restore the filtered signals to the original spectral band, the converse of the quadrature demodulation process must be applied. Before this is undertaken, however, the sampling rate must first be raised to the original value to avoid aliasing. By virtue of the symmetry of the decimation and interpolation process, the interpolation filters can be identical to those used for decimation, i.e. 3-tap FIR realizations. In all, three interpolation stages are required. The total number of multiply–accumulate operations (effective taps) involved in the new bandpass filter realization is 3 + 3 + 3 + 25 + 3 + 3 + 3 per filter chain, i.e. a total of 86 effective taps. The number of coefficients required for realization, however, is only 3 + 25 = 28. Table 6.10 gives a comparison of the filter parameters for both methods of filter implementation. Clearly the decimation/interpolation approach is considerably more efficient. The effective delay introduced by the bandpass filter is found by summing the delays of each individual filter in the process, referenced to the original sampling rate. For example, the delay introduced by an N-tap filter operating at 1/M times the original sampling rate is Delay = (MN – 1)/2 cycles In the above example, the total delay is thus

Table 6.10 Comparison of direct and indirect bandpass filter realizations

1 1 1 1 1 Dtotal = 1 + 2 + 5 + 99 + 5 + 2 + 1 2 2 2 2 2 1 = 117 cycles 2 Direct filter realization

Decimation/Interpolation filter realization

Effective no. of multiply/accumulates

231

86

Data memory for coefficients

116

28

Delay

115

392

Chapter 6 ❚ Applications toolbox II: digital filter design

(Note: this does not equate to the delay expected from the number of taps for the equivalent bandpass filter.) If it is required to compensate for the filter delay in a second processing path, then the total filter delay can be made a whole number of samples by replacing either the first decimation filter or the last interpolation filter with one having an even number of taps. By using a 4-tap interpolating filter in the last stage of the above example, the total delay now becomes 118 cycles.

6.9.11 Filter transformations If, for some reason, you have been lucky enough to scrounge time on a great filter design package, but have only managed to rush off a quick low-pass FIR filter design, then this section is for you. Using simple operations on the low-pass filter coefficients, it is possible to quickly synthesize high-pass, bandpass and stopband filters. Filter transformations for IIR filters are covered in the theoretical filter section of Chapter 9.

High pass from low pass A low-pass filter realized using DSP techniques, and thus exhibiting well defined and time-invariant gain characteristics, can be transformed into a high-pass filter by simply subtracting the filtered output from the delayed input. For linear phase FIR filters, this process can be exact, since perfect delay matching is possible. For IIR filters, the performance depends on the group delay characteristics of the low-pass filter source. (The same technique is equally applicable to bandpass and bandstop transformations.) Examples of this transformation are given in Figure 6.50. For an FIR filter, a low-pass to high-pass transformation can also be achieved simply by reversing the sign of alternate filter coefficients, i.e. h1(n) = (–1)nh2(n) In this case, the transformed filter response is the mirror image of the original, mirrored about fs/2 (Figure 6.51). The same technique applies to bandpass and bandstop filters. An example of a bandpass mirror transformation is given in Figure 6.52. This particular transform is widely used in sub-band coders in the form of a ‘quadrature mirror’ filter bank.

Bandpass from low-pass As has been demonstrated in connection with the Hilbert transform filter (Section 6.9.1), a bandpass filter can be derived from a low-pass prototype by using a simple sin or cos transformation. This involves multiplying the filter coefficients (FIR filters only) by either 2 cos(2rf0nTs) or 2 sin(2rf0nTs) where f0 is the center frequency of the desired bandpass response, having a width twice that of the low-pass prototype (Figure 6.53). This technique is particularly useful in data modem design for realizing matched filters with a well defined low-pass characteristic, e.g. raised cosine, in a bandpass form. Using both cos and sin transforms together gives rise to a Hilbert transform filter pair.

393

Specialist filter types

FIR 10

0

0

–10

–10

–20

1 – H(z)

H(z)

–30 –40

Attenuation (dB)

Attenuation (dB)

FIR 10

–50 –60

–20 –30 –40 –50

0

100

200

300

400

–60

500

0

100

Frequency

200

400

500

400

500

FIR 10

0

0

–10

–10

–20

1 – H(z)

H(z)

–30 –40

Attenuation (dB)

Attenuation (dB)

FIR 10

–50 –60

300

Frequency

–20 –30 –40 –50

0

100

200

300

400

–60

500

0

100

Frequency

200

300

Frequency

Figure 6.50 Complementary low-pass/high-pass and bandpass/bandstop filter transformation FIR 10

0

0

–10

–10

–20

H(z) (–1) h(n)

–30 –40 –50 –60

H(–z) n

Attenuation (dB)

Attenuation (dB)

FIR 10

–20 –30 –40 –50

0

100

200

300

400

500

Frequency

Figure 6.51 Mirror low-pass/high-pass filter transformations

–60

0

100

200

300

Frequency

400

500

Chapter 6 ❚ Applications toolbox II: digital filter design

394

FIR 10

0

0

–10

–10

–20

H(z)

H(–z) (–1)n h(n)

–30 –40 –50 –60

Attenuation (dB)

Attenuation (dB)

FIR 10

–20 –30 –40 –50

0

100

200

300

400

–60

500

0

100

200

Frequency

300

Frequency

Figure 6.52 Mirror bandpass/bandpass filter transformations FIA

FIA

10

10 0 H1(s)

–10 –20

N(s)

–30

SIN COS

H2(s)

–40

Attenuation (dB)

Attenuation (dB)

0

–10 –20

H1(s) H2(s)

–30 –40

–50 –60

–50

f0 y(t)

H1(s)

x(t)

^

y(t)

H2(s)

Figure 6.53 Lowpass/bandpass filter transformations

400

500

Questions

Tuneable filters

395

6.9.12

A tuneable filter is defined here as a filter whose gain response can be varied according to some suitable control signal, in a real time or pseudo-real time sense. An example in the analog world is the switched capacitor filter, with frequency response determined by the clock rate. This technique can be carried over to the DSP environment by dynamically altering the sampling rate. This can be achieved by varying the program execution time where this does not conflict with other signal processing functions, or by interpolation/ decimation techniques. A second trivial realization of semi-tuneable filters is to modify the filter coefficients by accessing a data set held in (program) memory. This technique can only accommodate a predefined set of filter characteristics, but is nonetheless a valid and often-used process. This is not to be confused with adaptive filtering, Section 6.9.8. Where it is required to implement a filter with constant bandwidth, but variable center frequency, such as a tuned bandpass selection filter, a frequency translation technique is usually optimal. Such a technique has already been outlined in Section 6.9.10, whereby a narrow bandpass filter is implemented by two low-pass filters, sandwiched between a quadrature frequency translation system. Tuneability of the design presented can be achieved by varying the frequency of the local reference. An alternative mechanism is to ‘slide’ the signal to be filtered past the ‘fixed’ filter, using one of the frequency translation techniques discussed in ToolBox I. One further technique involves the fast Fourier transform and its corresponding inverse Fourier transform. The FFT of a signal will yield its frequency components, making filtering a simple task of discarding unwanted component samples prior to the inverse FFT. This process, however, only results in an approximation to the filtered waveform. The technique is computational intensive but has significant attraction for dynamic filtering of signals, where the bandwidth of the information to be selected is varying rapidly with time. A particular example is the filtering of reference signals subject to Doppler shift caused by variable platform velocity.

Questions 1. What are the criteria needed to ensure that a digital filter will have a perfect linear phase response? 2. A low pass filter needs to have a passband from 0–1 kHz and a stopband from 2–5 kHz. What type of IIR filter will give the lowest order? What type of IIR filter will give the most linear phase? 3. An FIR filter has a length of 63 taps, and the sample rate is 48 kSPS. What is the delay introduced by the filter? 4. Explain the term ‘halfband filter’. What are the key properties of a halfband filter?

6.10 5. Sketch the pole-zero diagram and frequency response for a simple notch filter. What happens as the poles are moved further inwards from the unit circle? 6. Describe what is meant by a Hilbert transform filter and explain why these filters are usually implemented in FIR form. Give an application of a Hilbert transform filter. Solutions to these questions and additional questions can be found on the DSPStore.com™ web site.

Suggest Documents