Sep 10, 2012 - The Fourier series (FS) is useful way for expressing a periodic waveform (which ...... Rpass = str2num(answer{4}); % Passband ripple in dB.
School of Engineering
Design of Finite Impulse Response Digital Filters using Optimal Methods
By Mohammed Salah Hamza Al-Radhi This Project is Submitted in Partial Submission for the Degree of Master of Science In Communication Systems Engineering
Supervisor : Dr. Branislav Vuksanovic Moderator : Mr. Hassan Parchizadeh
September 2012 Portsmouth, England
Design of FIR Digital Filters using Optimal Methods
ABSTRACT
The design of digital filters is an important process in the framework of digital signal processing (DSP). Being principal building blocks, digital filters are used in various fields ranging from speech through image to video and audio processing. The two main types of digital filters used in many different applications are FIR (Finite Impulse Response) and IIR (Infinite Impulse Response) filters. FIR digital filters have a number of significant characteristics that make them preferred for a number of cases than IIR filters, such as phase linearity, stability, and finite precision. Adders, multipliers, and shift registers are the fundamental building block components for FIR digital filters, and can be implemented in hardware, software or combination between them. By analysing the definition and basic principles of the FIR filters, the purpose of this project is to investigate design of FIR digital filters using different methods. Some books have been pointed out to this subject, but a distinguishing feature in this project is to introduce a full MATLAB code that combines all FIR design methods in order to design the four standard types of filter; namely low pass, high pass, band pass, and band stop filters, depending on the specifications defined by the user. Direct form realization of FIR digital filter is considered because it provides a good performance in terms of requiring a minimum of components and best operating speed than the other FIR filter structures (like cascade and transpose structures). The design methods can be classified into three main groups. The simplest and earliest design method is windowing, which is widely used for designing standard filter types. It has many different window functions, each of which has unique advantages and disadvantages that make them best-suited for a specific kind of applications. The second method is frequency sampling design method, which is used to design filters with arbitrary responses. The last design method is the optimal methods, it includes an equiripple design method (based on minimizes the maximum ripple in each band) and least-squares design method (based on minimizes the integral of square error). In general, most of these methods are compromise between computational complexity and how closely the designed filter satisfies the desired
i
Design of FIR Digital Filters using Optimal Methods
requirements. Furthermore, each method has properties that distinguish them from other in terms of magnitude response in the passband, stopband and transition band areas. The experimental results based on the MATLAB code show that the optimal methods are powerful, efficient, and very high precision for minimizing the difference between the designed and desired ideal filters frequency response. Also, it offers lower filter order which can meet the design specifications, especially with optimal equiripple design than the other methods.
ii
Design of FIR Digital Filters using Optimal Methods
ACKNOWLEDGMENTS
First and foremost, I want to thank Allah Almighty for giving me the strength to complete this research work. I would like to extend my appreciation and my sincere thanks to my supervisor Dr. Branislav Vuksanovic, School of Engineering. I honestly thank for his continuous guidance, encouragement, and timely advice to me. Also, I would like to thank my moderator Mr. Hassan Parchizadeh for his necessary support and useful discussions. Moreover, I want to thank my course leader Dr. Khalil Alkadhimi for providing a solid background in his unit (Project Research and Planning), and for his valuable advice. I also have to acknowledge all the members of staff at Portsmouth University. Additionally, I would like to thank my Government, HCED (the Higher Committee for Education development in Iraq) for giving me this opportunity to complete the master's study in communication systems engineering. Special thanks to all my friends for their kindness and support. Thanks also go to my classmates who made such a helpful atmosphere in the lab; I loved a lot friendship with them during my stay at Portsmouth, England. I must express my gratitude to my father and mother (may Allah have mercy on her soul), who taught me the value of hard work by their own experience and for their moral support and prayers. I dedicate this work to my parents. Many thanks to my brother and sisters for their attention (may Allah bless them all). Last but not least, I would like to give special thanks to my wonderful wife, for her continued support me throughout my studies; and for her devotion and patience have motivated and encouraged me to work hard and do the best I can. Special thanks for my baby Ruqaiya that made my life joyful.
Mohammed Al-Radhi September 2012
iii
Design of FIR Digital Filters using Optimal Methods
TABLE OF CONTENTS ABSTRACT ............................................................................................................................................. i ACKNOWLEDGMENTS...................................................................................................................... iii LIST OF FIGURES ............................................................................................................................. vii LIST OF TABLES ................................................................................................................................. x CHAPTER I (Introduction) ................................................................................................................... 1 1.1 Introduction ....................................................................................................................................... 1 1.2 Main Objective.................................................................................................................................. 3 1.3 Project Organization ......................................................................................................................... 4 CHAPTER II (Fundamental Concepts in Filtering) ............................................................................ 5 2.1 Introduction ....................................................................................................................................... 5 2.2 The Fourier Transform ...................................................................................................................... 5 2.3 The z-Transform ............................................................................................................................... 7 2.4 Filtering Concept ............................................................................................................................ 10 2.5 Ideal characteristics of standard filters............................................................................................ 10 2.5.1 Ideal Low Pass Filter ............................................................................................................... 12 2.5.2 Ideal High Pass Filter ............................................................................................................... 13 2.5.3 Ideal Band-Pass Filter .............................................................................................................. 15 2.5.4 Ideal Band-Stop Filter .............................................................................................................. 16 CHAPTER III (Digital Filters) ........................................................................................................... 18 3.1 Introduction ..................................................................................................................................... 18 3.2 Digital Filters .................................................................................................................................. 18 3.3 Difference Equation ........................................................................................................................ 20 3.4 Digital Filters Representation ......................................................................................................... 22 3.5 IIR Digital Filters ............................................................................................................................ 25 3.5.1 The basic concept ..................................................................................................................... 25 3.5.2 Transfer Function ..................................................................................................................... 25
iv
Design of FIR Digital Filters using Optimal Methods
3.5.3 Realisation of IIR filters........................................................................................................... 26 3.6 FIR Digital Filters ........................................................................................................................... 27 3.6.1 The basic concept ..................................................................................................................... 27 3.6.2 Transfer Function ..................................................................................................................... 28 3.6.3 Realisation of FIR filters .......................................................................................................... 29 3.7 FIR versus IIR Filters...................................................................................................................... 30 3.8 Practical Filter Specifications ......................................................................................................... 31 3.5.1 Low Pass Filter Specifications ................................................................................................. 33 3.5.2 High Pass Filter Specifications ................................................................................................ 34 3.5.3 Band-Pass Filter Specifications ............................................................................................... 35 3.5.4 Band-Stop Filter Specifications ............................................................................................... 36 CHAPTER IV (Design of FIR Digital Filters) ................................................................................... 37 4.1 Introduction ..................................................................................................................................... 37 4.2 FIR Filter Design Procedure ........................................................................................................... 37 4.3 FIR coefficient calculation methods ............................................................................................... 39 4.4 Window Design Methods ............................................................................................................... 39 4.4.1 Rectangular Window ............................................................................................................... 42 4.4.2 Triangular Window .................................................................................................................. 45 4.4.3 Bartlett Window ....................................................................................................................... 46 4.4.4 Hanning Window ..................................................................................................................... 48 4.4.5 Bartlett-Hanning Window ........................................................................................................ 49 4.4.6 Hamming Window ................................................................................................................... 51 4.4.7 Blackman Window................................................................................................................... 52 4.4.8 Gaussian Window .................................................................................................................... 54 4.4.9 Flat Top weighted window ...................................................................................................... 55 4.4.10 Dolph–Chebyshev window .................................................................................................... 57 4.4.11 Kaiser Window ...................................................................................................................... 59 4.5 Comparison of Window Functions ................................................................................................. 61 4.6 Frequency Sampling Method .......................................................................................................... 65 4.7 Optimization Methods .................................................................................................................... 68 4.7.1 Optimal Equiripple Design method ......................................................................................... 68 4.7.2 Least-Squares Method ............................................................................................................. 74 4.8 Comparison of Design FIR Methods .............................................................................................. 77 v
Design of FIR Digital Filters using Optimal Methods
4.9 Estimation of the Filter Order ......................................................................................................... 77 CHAPTER V (Results and Discussion) .............................................................................................. 79 5.1 Introduction ..................................................................................................................................... 79 5.2 FIR Filter Code ............................................................................................................................... 79 5.3 FIR Filter Implementation .............................................................................................................. 82 5.3.1 Implementation of Window functions ..................................................................................... 83 5.3.2 Implementation of Frequency Sampling method ..................................................................... 97 5.3.3 Implementation of Optimal Equiripple method ....................................................................... 99 5.3.4 Implementation of Least-Squares method ............................................................................. 101 5.4 Performance comparison of FIR filter design methods ................................................................ 104 5.5 FIR Filter realization (Simulink diagram) .................................................................................... 105 CHAPTER VI (Conclusion and Future Work) ................................................................................ 107 APPENDIX A (Design of HP, BP, and BS FIR Filter) ................................................................... 109 APPENDIX B (MATLAB Codes) ...................................................................................................... 112 B.1 MATLAB code for designing FIR filter .................................................................................. 112 B.2 MATLAB code for Window functions characteristics ............................................................ 137 B.3 MATLAB code for the Kaiser window with different values of β .......................................... 139 B.4 MATLAB code for comparing window functions ................................................................... 140 BIBLIOGRAPHY............................................................................................................................... 142
vi
Design of FIR Digital Filters using Optimal Methods
LIST OF FIGURES Figure 1: Linear system ....................................................................................................... 11 Figure 2: Ideal LPF response ............................................................................................... 12 Figure 3: Ideal LPF output .................................................................................................. 13 Figure 4: Ideal HPF response .............................................................................................. 14 Figure 5: Ideal HPF output .................................................................................................. 14 Figure 6: Ideal BPF response............................................................................................... 15 Figure 7: Ideal BPF output .................................................................................................. 16 Figure 8: Ideal BSF response............................................................................................... 17 Figure 9: Ideal BSF output .................................................................................................. 17 Figure 10: Block diagram of a simple digital filter............................................................... 23 Figure 11: Delay function.................................................................................................... 24 Figure 12: Adder function ................................................................................................... 24 Figure 13: Multiply function ............................................................................................... 24 Figure 14: Block diagram of IIR filter ................................................................................. 27 Figure 15: Block diagram of FIR filter ................................................................................ 30 Figure 16: Practical LPF specification ................................................................................. 34 Figure 17: Practical HPF specification ................................................................................ 34 Figure 18: Practical BPF specification................................................................................. 35 Figure 19: Practical BPF specification................................................................................. 36 Figure 20: FIR filter design steps (Ifeachor & Jervis, 1993, p. 286) ..................................... 38 Figure 21: Rectangular window function (N=32) ................................................................ 44 Figure 22: Triangular window function (N=32) ................................................................... 46 Figure 23: Bartlett window function (N=32) ....................................................................... 47 Figure 24: Hanning window function (N=32) ...................................................................... 49 Figure 25: Bartlett-Hann window function (N=32) .............................................................. 50 Figure 26: Hamming window function (N=32).................................................................... 52 Figure 27: Blackman window function (N=32) ................................................................... 54 Figure 28: Gaussian window function (N=32) ..................................................................... 55 Figure 29: Flat-Top window function (N=32) ..................................................................... 57 Figure 30: Dolph–Chebyshev window function (N=32) ...................................................... 58 Figure 31: Kaiser window function for β=0, 3 and 5 (N=32) ............................................... 61 Figure 32: Time and Frequency domain of commonly used window functions .................... 64 Figure 33: Illustration of the Parks-McClellan algorithm for equiripple approximation........ 72 Figure 34: Flowchart of Parks-McClellan (Remez exchange) algorithm (McClellan & Parks, March 1972) ....................................................................................................................... 73 Figure 35: FIR model based on LSM ................................................................................... 74 Figure 36: Flow chart of FIR MATLAB code ..................................................................... 80 vii
Design of FIR Digital Filters using Optimal Methods
Figure 37: FIR filter code: (a) Design methods; (b) Window functions; (c) Optimal methods; (d) Filter response type; (e) FIR filter specifications; (f) Filter order calculation; (g) FIR filter analysis ............................................................................................................................... 82 Figure 38: FIR filter specifications ...................................................................................... 83 Figure 39: The effect of the window function in the frequency domain ............................... 84 Figure 40: Frequency response of FIR LPF using Rectangular window ............................... 87 Figure 41: Frequency response of FIR LPF using Hanning window .................................... 88 Figure 42: Frequency response of FIR LPF using Hamming window .................................. 88 Figure 43: Frequency response of FIR LPF using Gaussian window ................................... 89 Figure 44: Frequency response of FIR LPF using Blackman window .................................. 89 Figure 45: Frequency response of FIR LPF using Flat-top window ..................................... 90 Figure 46: Frequency response of FIR LPF using Dolph–Chebyshev window ..................... 90 Figure 47: Frequency response of FIR LPF using Kaiser window........................................ 91 Figure 48: Frequency response of modified FIR LPF using Kaiser window ......................... 91 Figure 49: Frequency response of modified FIR LPF using Kaiser window ......................... 92 Figure 50: LPF designed by Rectangular window: (a) Impulse response; (b) Step response with overshoots (poor) ........................................................................................................ 93 Figure 51: LPF designed by Hamming window: (a) Impulse response; (b) Step response with overshoots (acceptable) ....................................................................................................... 93 Figure 52: LPF designed by Bartlet-Hanning window: (a) Impulse response; (b) Step response with overshoots (acceptable). ................................................................................ 94 Figure 53: LPF designed by Kaiser window N=60: (a) Impulse response; (b) Step response with very low overshoot (good). .......................................................................................... 94 Figure 54: LPF designed by Rectangular window: (a) Zero-pole plot; (b) Phase response ... 95 Figure 55: LPF designed by Hamming window: (a) Zero-pole plot; (b) Phase response....... 95 Figure 56: LPF designed by Bartlett-Hanning window: (a) Zero-pole plot; (b) Phase response ........................................................................................................................................... 96 Figure 57: LPF designed by Kaiser window: (a) Zero-pole plot; (b) Phase response ............ 96 Figure 58: Frequency response of FIR LPF using Frequency Sampling method (N=26) ...... 97 Figure 59: Frequency response of FIR LPF using Frequency Sampling method (N=60) ...... 98 Figure 60: LPF designed by Frequency Sampling (N=60): (a) Impulse response; (b) Step response with no overshoots ................................................................................................ 98 Figure 61: LPF designed by Frequency Sampling (N=60) : (a) Zero-pole plot; (b) Phase response .............................................................................................................................. 99 Figure 62: Frequency response of FIR LPF using Equiripple method (N=60) .................... 100 Figure 63: LPF designed by Equiripple method: (a) Impulse response; (b) Step response .. 100 Figure 64: LPF designed by Equiripple method: (a) Zero-pole plot; (b) Phase response..... 101 Figure 65: Frequency respon se of FIR LPF using LS method (without weights) ............... 102 Figure 66: Frequency response of FIR LPF using weighted LS method ............................. 102 Figure 67: LPF designed by weighted LS method (N=26): (a) Impulse response; (b) Step response ............................................................................................................................ 103 Figure 68: LPF designed by weighted LS method (N=26): (a) Zero-pole plot; (b) Phase response ............................................................................................................................ 103 viii
Design of FIR Digital Filters using Optimal Methods
Figure 69: FIR filter specifications for performance comparison ....................................... 104 Figure 70: Simulink subsystem block for FIR LPF ............................................................ 106 Figure 71: Frequency response of FIR HPF using: a) Kaiser window b) Frequency Sampling c) Least-Squares d) Equiripple design methods (N=26) ................................................... 109 Figure 72: Frequency response of FIR BPF using: a) Kaiser window b) Frequency Sampling c) Least-Squares d) Equiripple design methods (N=26) ................................................... 110 Figure 73: Frequency response of FIR BSF using: a) Kaiser window b) Frequency Sampling c) Least-Squares d) Equiripple design methods (N=26) ................................................... 111
ix
Design of FIR Digital Filters using Optimal Methods
LIST OF TABLES
Table 1: Flat-Top coefficient values .................................................................................... 56 Table 2: β versus window function ...................................................................................... 60 Table 3: Parameter values for the Kaiser function................................................................ 60 Table 4: Comparison of commonly used window function characteristics ........................... 63 Table 5: Weight functions and ideal magnitude responses for standard frequency-selective filters .................................................................................................................................. 71 Table 6: Summary of LPF design characteristics using different window functions ............. 92 Table 7: Performance Comparison of previous methods for FIR filter design .................... 104
x
Design of FIR Digital Filters using Optimal Methods
CHAPTER I Introduction 1.1 Introduction The term signal refers to any variable that includes some sort of information which can be transmitted, stored or processed, such as sound, video and image. Signals can be divided into two classes: continuous time signal and discrete time signal. A continuous (or analogue) signal is defined as a continuous function of time, and has a value at any given time; such as speech. A discrete time signal is defined at discrete instants of time, and has a discrete value at those time instances; such as logged measurements or the stock-market weekly financial indicators. Signal processing is defined as a system that performs a task on a signal like modifying, analysing, manipulating, or displaying signal information. It can be classified into two types: Analogue Signal Processing (ASP) and Digital Signal Processing (DSP). In addition, Signals may be processed using a combination of analogue and digital processors (it is called a Mixed Signal Processing (MSP)). Digital signal processing (DSP) is related with creation of digital signals and using digital processors to examine, control, filter or get information from that signal. Analogue systems in a communication network have increasingly been changed with digital systems. Growth of digital circuits and software technologies has made digital systems progressively more desirable and attracting more attention. The reason for this is that there are many advantages in using digital processing rather than analogue processing. For example and from a reliability viewpoint, DSP provides more flexibility, stability, good performance, low cost, more accuracy or a high degree of noise immunity, and higher transmission capacity. Also, the output of the digital systems does not alter as a result of environmental factors. Most importantly, digital signalling allows designers to generate all kinds of solutions to processing signals that are hard to perform with analogue designs like operations at very low frequencies.
1
Design of FIR Digital Filters using Optimal Methods
On the other hand, analogue processing is limited scope for achieving complex signal processing applications due to non-flexibility in processing and difficulty in system designs. Moreover, some components tend to be drift with changes in environmental conditions such as temperature, this can be inconvenient for large system which needs to be modified. Consequently, digital processing is now becoming the first choice in many applications and technologies, for instance in control systems and wireless communications. This is confirmed by the number of good books available in this subject, such as Proakis & Manolakis (1988), Hamming (1989), Ifeachor & Jervis (1993), and Diniz, Silva & Netto (2010). One of the main components in telecommunication systems and the most useful signal processing operations is Filtering. The filter function is to convert electrical signals from one form to another to manipulate signal shape, amplitude, frequency or phase in a desired manner. In communication applications, filters can be used to remove or filter out some frequencies in order to detect and choose the desired frequencies, and also it used to suppress noise and to correct signal. Filters can be classified into two main types: analogue filtering, and digital filtering. Unlike analogue filters, digital filters are flexible, high precision, stable, do not suffer from internal noise, and able to achieve good performance (in terms of selectivity and attenuation) which can be more difficult to implement with analogue filters. Moreover, digital filters can be implemented in hardware, software or combination between them. Digital filters are commonly used in various industrial applications such as: audio or video processing, satellite, cellular mobile phones, radar, or many other types. Digital filters are also classified into two main classes: finite impulse response (FIR), and infinite impulse response (IIR). The easiest and, in many instances, the most important of these filter types is the FIR, because FIR digital filters have many attractive properties that make them desirable in many applications. Among these properties are linear phase, stability, and flexible in implementation. When comparing an ideal filter to a practical filter, oscillations or ripples that appear in the practical filter frequency response, due to implementation processes, is a major concern of filter designers. For that reason, practical digital filter is hard to reach the ideal filter accuracy. Therefore, a number of methods have been proposed for designing FIR digital filters to approximate the characteristics of an ideal filter to that of a practicable filter. Each of the various methods has some advantages and disadvantages. Thus, the designer should choose the best method that will satisfy the desired specification. 2
Design of FIR Digital Filters using Optimal Methods
In general, the design process of a digital filter is a time-consuming and very hard if made by hand, but with the assistance of computer tools, this process can be done faster because of the computer technology provides much faster computationally operations, more memory, and quickest in the implementation of design algorithms. One of the most powerful tools used for planning, manipulating, and designing digital filters is MATLAB. MATLAB provides easiest solutions, simple analysis, and gives additional motivation to improve digital filters implementation.
1.2 Main Objective The principle objective of this project is to investigate design of finite impulse response (FIR) digital filters by providing the main concepts and methodologies for the FIR filter design. A secondary objective is to write a MATLAB program for that filter design depending on the user defined specifications. The design is based on using different methods that applied to the digital filters by giving main definitions and properties for each method in order to design the standard types of filter (low pass, high pass, band pass, and band stop filter). The aim of this work is to study, analyse and implement several methods for designing FIR digital filters, and also find the best method to design a linear phase FIR filters. The MATLAB code should be menu controlled and have the following characteristics: Input Menu: 1. Select design method. 2. Select filter type (LPF, HPF, BPF and BSF). 3. Enter sampling frequency in Hz. 4. Enter passband edge(s) and stopband edge(s) frequencies in Hz. 5. Enter passband ripple and stopband ripple in dB. 6. Filter Order (Optional).
3
Design of FIR Digital Filters using Optimal Methods
Output Menu: 1. Absolute magnitude response. 2. Decibel magnitude response. 3. Impulse response. 4. Step response. 5. Phase response. 6. Zero-pole plot. 7. Filter coefficients. 8. Filter information. 9. FIR filter realization (Simulink diagram).
1.3 Project Organization This project is structured with six chapters. Subsequent to the introduction, Chapter II describes the fundamental concepts in filtering with focus on the ideal filters. Theoretical background on digital filters is presented and outlined in chapter III. This chapter also describes the practical filters and how they differ from the ideal filters. The design of FIR digital filters using several approximation methods is explained in more detail in chapter IV. Also in this chapter, similarities and differences between various methods are discussed. Chapter V displays the results of the design FIR digital filters based on the MATLAB code and evaluates the efficiency for each method. The conclusion and recommendations for future work is given in chapter VI.
4
Design of FIR Digital Filters using Optimal Methods
CHAPTER II Fundamental Concepts in Filtering 2.1 Introduction The term filter normally used to describe a device that allows some kinds of information to pass while stops others, which is an important subsystem in many electronics devices. Therefore, the objective of this chapter is to provide a general concept on filtering. First of all, Fourier transform and z-transform should be discussed because they are the most convenient mathematical tools for representing and analysing most types of signals by breaking up signals into summations of sinusoidal components. The outline of this chapter is as follows: Section 2.2 presents important properties of the Fourier transform, particularly those that will be used in later chapters. Similarly, Section 2.3 introduces the z-transform. Section 2.4 gives an introduction to the filtering concept, including an overview of ideal low pass, high pass, band pass, and band stop filters.
2.2 The Fourier Transform The Fourier series (FS) is useful way for expressing a periodic waveform (which repeats itself over time) as the sum of an infinite number of sinusoidal and cosinusoidal terms, with repetition period
and fundamental frequency
= . But most signals of practical importance are not
periodic (such as speech signal or unit step and unit impulse); therefore, the Fourier series approach has to be modified to be able to analyse non-periodic signals. Thus, the Fourier transform (FT) is one of the most important approaches for analysing the frequency content of a signal (to go from time to frequency). Mathematically, the FT of a signal ( ) is defined as (Hussain, Sadik, & O’Shea, 2011, pp. 18-25)
5
Design of FIR Digital Filters using Optimal Methods
( )=
The complex exponential term = cos 2
(
− sin 2
( )
( ) =
(2.1)
is simply a short way of representing sine and cosine ). The inverse Fourier transform (IFT) (to go from frequency
to time) can be calculated as follows:
( )=
( )
( ) =
(2.2)
In addition to the above mentioned, some important properties of the FT are discribed briefly bellow:
Time and frequency variables are exchanged ( )
( ) ,
( ) ( )
Time shifting ( −
(− ), ( ),
( )
ℎ
( )
)
Frequency shifting ( −
( )
)
When a continuous signal ( ) is sampled at time instants, resulting an infinite-length discrete time signal ( ) in terms of the exponential sequence transform (DTFT) (
) can be determined as (Mitra, 2011, pp. 117-130) ( ) =
The DTFT
, then the discrete-time Fourier
( )
=
(2.3)
is a discrete in time but continuous in frequency, it can be called as either
the spectrum or the frequency domain representation of the signal ( ). Because it is a complex function, it can be expressed as a polar or rectangular form ∠
= =
+ 6
(2.4) (2.5)
Design of FIR Digital Filters using Optimal Methods
where
is the magnitude function, ∠
is the phase function, and defined
respectively by (
=
∠
)+ .(
= tan
(
.(
)
(2.6)
) )
(2.7)
Although DTFT is useful for analysing digital signals in theory, it is hard to apply from the numerical calculation standpoint (due to infinite-length sequences). Therefore, if the discrete time signal with
point duration ( ) = (0), (1), … , ( − 1) has been sampled at
(the
same number) point sequence of frequency domain values, then the DTFT known as the discrete Fourier transform (DFT). Unlike DTFT, DFT is a discrete in both time and frequency. The frequency samples ( ) can be viewed as a special case of the DTFT
as follows
(Milić, 2009, pp. 5-9): ( )=
|
( )=
( )
, 0≤
≤
−1
(2.8)
The Fourier coefficients ( ) can be determined using the inverse DFT, and given by
( )=
1
( )
(2.9)
To plot the Fourier transform spectrum, generally plots a magnitude spectrum (| ( )| against frequency ) and a phase spectrum (∠ ( ) against frequency ).
2.3 The z-Transform As discussed previously, the family of Fourier transform give a frequency domain representation of discrete time signals. But various signals, such as
( ) (where ( ) is the
unit step sequence) is difficult to find the discrete time Fourier transform of it; therefore, ztransform (ZT) has become a significant approach for representing, analysing and designing 7
Design of FIR Digital Filters using Optimal Methods
discrete signals that do not have Fourier transform. Also, the ZT is frequently more appropriate in analytical problems than the Fourier transform. For a given sequence for all , the ZT ( ) of the complex variable
( ) , which is valid
is expressed as (Proakis & Ingle, 2011, pp.
103-124) ( )=
( ) =
( )
(2.10)
For one-sided ZT, which is mean ( ) can be non-zero only in the range 0 ≤
≤ ∞; this leads
to reduce the equation (2.10) to ( )=
The complex variable
( )
(2.11)
can be written in polar form as | |
When the magnitude | | is equal to 1, then the DTFT (
, where
is the real frequency.
) can be regarded as a special case
of the ZT ( ) (Equation 2.10) as follows: ( )|
=
( )
=
(2.12)
To recover ( ), there are a number of methods may be used to determine the inverse ztransform (IZT), such as residue method, partial-fraction expansions, polynomial division, and series expansion. The IZT of a function ( ) is defined using the residue theorem (Diniz, Silva, & Netto, 2010, p. 83) ( )=
( ) =
1 2
( )
(2.13)
Put equation (2.10) in equation (2.13) ( )=
=
1 2
( )
( )
1 2
8
(2.14)
(2.15)
Design of FIR Digital Filters using Optimal Methods
If
is a counter-clockwise contour circles the origin, then the integral term in the brackets
can be evaluated by using the Cauchy integral theorem (Mathews, 1982): 1 2
= ( − )
(2.16)
= ℎ
(2.17)
and the discrete time impulse is equal to ( − )=
1, 0,
Consequently, ( ) ( − )= ( )
To avoid this contour integration and for simplicity, the most commonly used way to solve the inverse ZT is partial fraction or long division expansion. Likewise to the Fourier transform, the three important properties of the z-transform are summorized bellow: Sample shifting ( − )
( )
Multiplication by an exponential (
( )
)
Complex differentiation ( )
−
( )
Also, the z-transform can be used to solve difference equations, and then to characterize linear systems. This will be explained more in Chapter III.
9
Design of FIR Digital Filters using Optimal Methods
2.4 Filtering Concept Filters are extremely significant subsystem in many electronic systems and particularly in communications area. Filters can be found in everyday life from mobile phones to satellite receivers and Internet connections or in power supplies and almost in all modern electronic instrumentations. Also, they are used as a noise reduction, sound and image processing, multiplexing and signal detection. It is difficult to give a formal definition of the word filtering, but many engineers defined it as a signal processing operation that modifies or reshapes the frequency domain characteristics of a given signal. In general, a filter takes a signal from its input, and produces the required output according to its properties. In other words, filtering is the process of selectivity accepting a specified band of frequencies to pass and attenuating (or obstructing) frequencies outside that band. For instance, a radio receiver uses filtering to select one of the several AM (Amplitude Modulation) or FM (Frequency Modulation) broadcast stations that are obtainable in a specific geographical zone. In most cases, the objective of filtering is to improve the signal to noise ratio by removing the noise signal from the desired one. There are a number of ways to classify filters, some of these are: Passive and Active filters, Analogue and digital filters, software filters or by pass band characteristics (Paarmann, 2001, pp. 1-8). Passive filters are using various combinations of passive elements such as resisters, inductors and capacitors. Active filters, on the other hand, are using the active elements such as a transistor or an operational amplifier as well as passive elements. Analogue filtering is performed on continuous-time signals and the frequency range is infinite, while digital filtering is performed on discrete-time signals and the frequency range is finite. Software filtering can be applied by using computer programming to implement solutions for choosing desired frequencies. Finally, filters can be classified by their frequency response characteristics as a low pass, high pass, band pass and band stop filters.
2.5 Ideal characteristics of standard filters Filters split the coming signal into two parts, passband and stopband. The term passband refers to a range of frequencies over which the signal pass through a filter without being attenuated, and the range of frequencies over which the signal is attenuated is known as the stopband. The 10
Design of FIR Digital Filters using Optimal Methods
expression of ideal filter means that the magnitude of the wanted signal passing through the filter is not reduced over the desired passband frequencies. Simply, the output of an ideal filter is the same of part of the filter input (Dunn, 2010, p. 78). Mathematically, consider a simple system shown in Figure 1 whose input is ( ) and output is ( ).
Figure 1: Linear system
By using Fourier transform, the input and the output can be written as below: ( ) ( )
(
)
The transfer function of this system is =
(
=
(2.18)
) (
)
∠
When the amplitude response is constant and without any distortion (for example, H(e 1 in the passband and H(e
(2.19) ) =
) = 0 in the stopband), then the system is called an ideal filter.
In contrast, there are a number of differences between the ideal filters and the practical filters. In case of practical filters, the loss in the passband is not zero, the loss in the stopband is not infinite, and gradual transition from passband to stopband. Hence, practical filters use various methods which bring it closer to the ideal filter; this will be explained in more detail in Chapter III. According to the function that they are to perform, ideal filters can be classified into low pass, high pass, band pass and band stop filters.
11
Design of FIR Digital Filters using Optimal Methods
2.5.1 Ideal Low Pass Filter The frequency response of an ideal low pass filter (LPF) is shown in the Figure 2. The ideal LPF is a filter having linear phase characteristics which does not affect low frequencies and discards high frequencies. In other words, it perfectly passes all of the frequencies from 0 for example, to the cut-off frequency the frequencies above
,
without any attenuation, and completely eliminates all
. The term cut-off frequency refers to the frequency at which the
response begins to fall off significantly. Mathematically, an ideal low pass filter has a magnitude response given by: =
1, 0,
−
≤ ℎ
≤
(2.20)
Figure 2: Ideal LPF response
It is helpful to investigate the impulse response of such filter. The impulse response is the output of the system in the time domain when the input is provided. By using the inverse Fourier transform (IFT), the impulse response of the ideal LPF can be determined as below:
ℎ
( )=
=
= ℎ
( )=
1. 1
−
2 sin(2 12
)
≠0
(2.21)
Design of FIR Digital Filters using Optimal Methods
It can be solved the above equation (2.21) for = 0 by considering the limiting behavior and using L'Hopital's rule (Blank & Krantz, 2006, pp. 298-304), as follows
( )|
ℎ
= lim
sin(2
)
2
cos(2
= lim
sin(2
= lim )
=2
)
(2.22)
Hence, the impulse response of the ideal LPF is )
sin(2 ℎ
( )= 2
,
≠0
,
=0
To show how an ideal filters works, consider an input signal
(2.23)
( ) coming to the system shown
in the Figure 1: ( ) = cos 2
+ cos 2
+ cos 2
This signal contains a number of sinusoids, each one with a fixed frequency. Therefore, the ideal LPF frequency response and the output are shown in the figure below:
Figure 3: Ideal LPF output
2.5.2 Ideal High Pass Filter The frequency response of an ideal high pass filter (HPF) is shown in the Figure 4. It suppresses all frequency components from 0
, for example, to the cut-off frequency 13
, and passes all
Design of FIR Digital Filters using Optimal Methods
frequency components above
. Mathematically, an ideal high pass filter has a magnitude
response given by:
=
1, 0,
−
≥ ℎ
≥
(2.24)
Figure 4: Ideal HPF response
Similarly to the LPF, the impulse response for the ideal HPF is
ℎ
( )=
−
sin(2
)
,
≠0
1−2 ,
=0
Also, to show how this filter works, recall the input signal
(2.25)
( ) with the system shown in the
Figure 1. Therefore, the ideal HPF frequency response and the output are shown in the figure below:
Figure 5: Ideal HPF output
14
Design of FIR Digital Filters using Optimal Methods
2.5.3 Ideal Band-Pass Filter The frequency response of an ideal band-pass filter (BPF) is illustrated in the Figure 6. The ideal BPF having two cut-off frequencies
and
. According to the (Enderle & Bronzino,
2012, p. 709), this type of filters can be achieved by combining a HPF with cut-off LPF with cut-off
and a
. This means that the ideal BPF passes all frequency components between
those two cut-off frequencies (pass band) without any distortion, and attenuates completely all others frequency components outside that band. The magnitude response of the ideal BPF can be written as: ≤| |≤ ℎ
1, 0,
=
(2.26)
Figure 6: Ideal BPF response
The impulse response for the ideal BPF is ℎ
( )=
=
=
= ℎ
( )=
1.
+
1
− 2
1
− 2
sin(2
)
−
1. − 2
+
− 2
− sin(2
15
)
≠0
(2.27)
Design of FIR Digital Filters using Optimal Methods
It can be solved the above equation (2.27) for = 0 by considering the limiting behavior and using L'Hopital's rule, as follows ( )|
ℎ
= lim
2
cos (2
= lim )
−
2
sin(2
)
cos (2
)
−
sin(2
= 2(
)
−
)
(2.28)
Hence, the impulse response of the ideal BPF is
sin(2 ℎ
( )=
)
−
sin(2 2(
) −
,
≠0
),
=0
(2.29)
Band-pass filter is a good choice for an engineer who needs a specific frequency range. A very useful example to show how this filter works is shown in the figure below:
Figure 7: Ideal BPF output
2.5.4 Ideal Band-Stop Filter The frequency response of an ideal band-stop filter (BSF) is illustrated in the Figure 8. The ideal BSF is exactly opposite to the BPF. It has a band stop between two cut-off frequencies and
, and has two pass bands outside that band. More specifically, this filter will pass
some of the frequencies below
and some of the frequencies above 16
. Furthermore, this
Design of FIR Digital Filters using Optimal Methods
type of filters is used when one band (range of frequencies) is to be removed and everything else is to be passed. The magnitude response of the ideal BSF can be written as:
=
≥| |≥ ℎ
1, 0,
(2.30)
Figure 8: Ideal BSF response
Similarly to the BPF, the impulse response for the ideal BSF is sin(2 ℎ
( )=
)
−
sin(2
1 − 2(
) −
,
≠0
),
=0
(2.31)
Also, a very useful example to understand how this filter works is illustrated in the figure below:
Figure 9: Ideal BSF output
17
Design of FIR Digital Filters using Optimal Methods
CHAPTER III Digital Filters 3.1 Introduction Digital filtering is one of the most important and influential elements of digital signal processing, which are capable to eliminate or improve particular frequency components in the signal. As discussed in chapter I, digital filters have several benefits over analogue filters that make them desired in many applications. Depending on the impulse response, digital filters are generally divided into two classes, namely infinite impulse response (IIR) and finite impulse response (FIR). The purpose of this chapter is to introduce and cover the concepts of digital filtering in addition to discuss the differences between FIR and IIR filters. The outline of this chapter is as follows: Section 3.2 presents an introduction on the digital filters. The difference equation is given in Section 3.3, which is an important concept that used in the analysis and design digital filters. Three ways used to describe the digital filters are explained in Section 3.4. Sections 3.5 and 3.6 introduce IIR and FIR filters from specifications to filter realizations, respectively. A comparison between finite and infinite impulse response is discussed in Section 3.7. This chapter is concluded in Section 3.8, where the practical filter specifications for low pass, high pass, band pass, and band stop are explained.
3.2 Digital Filters Filters can be classified into analogue and digital depending on the signal processing or on the input and output format. Therefore, by given a particular set of desired filter specifications, the next option for the designer that must follow is to choose which method used to implement this filter in the analogue or digital form. Analogue filters differ
18
Design of FIR Digital Filters using Optimal Methods
totally from digital filters in the components and in their structure, even though they are equally aimed to do the same job, which are capable to allow a specific frequency range to pass while suppresses all the others. Analogue Filtering is performed on continuous-time signals and includes implementing the wanted frequency response as an analogue circuit usually be made of operational amplifiers and discrete components such as capacitors and resistors to give the needed filtering effect. Furthermore, analogue filters suffer from nonlinearities, lack of flexibility, inaccuracies caused by variations in component values, sensitivity to noise, and insufficient repeatability (Porat, 1997, p. 243). Digital filtering is one important function that can be implemented in the DSP. Compared with analogue filtering, digital filtering is performed on discrete-time signals, and it is preferred in a number of applications because of the following benefits (Shenoi, 2006, pp. 23-25):
Digital filters have linear phase response, and its frequency response can be modified if it is implemented using a programmable processor.
The performance of digital filters does not vary with environmental changes such as thermal variations because it is dependent on numerical calculations, not mechanical characteristics of the components.
Unlike analogue filters, digital filters can be used at very low frequencies.
It can be filtered a number of input signals by one digital filter without the need to replicate the hardware components. Therefore, it is perfectly repeatable from unit to unit.
Digital filters are flexible, high precision, stable and do not suffer from internal noise; therefore, they have lower failure rate.
Most significantly, digital filters can be implemented in two main techniques depending on applications: hardware and software. In the hardware approach, the principal elements are adders, multipliers, shift registers and delay that can be implemented some operations such as addition, multiplication and shift operation depending on the procedure determined by the transfer function of the digital filters. But in the software approach, digital filters are applied as a software program running in the memory of a digital signal processor, it is very beneficial because of the filter procedure can be simply adjusted by modifying the software program with distinct improvements.
19
Design of FIR Digital Filters using Optimal Methods
Digital filters can be categorized into two groups based on the nature of their impulse response and forms of realization. 1. Impulse Response Finite Impulse Response (FIR): This term means that the digital filters have finite number of samples in their impulse response, or the duration of the filter impulse response is finite. Infinite Impulse Response (IIR ): This term means that the digital filtes have infinte number of samples in their impulse response, or the duration of the filter impulse response is infinte. 2. Realization Recursive Realization: This term means that the current output of the digital filter ( ) is dependent on previous filter outputs current filter inputs
( − 1), … as well as the past and
( ), ( − 1), … .
Non-Recursive Realization: This term means that the current output of the digital filter ( ) is dependent only on current and past filter inputs
( ), ( − 1), … ,
but without using previous outputs.
3.3 Difference Equation The difference equation is an important concept that is used in the analysis and design digital filters. It can be defined as a formula for calculating an output sample based on, for example, past and present input samples and past output samples, in the time domain. In the same way that digital filters are described by a difference equation, analogue filters are described by a differential equation. Likewise to the differential equation that can be solved by using Laplace transform, difference equation can be solved by using z-transform. For example, the ztransform of the digital signal ( − ) is ( ) ( )
, which corresponds to the kth derivative
of an analogue filter signal ( ). Depending on the value of k, the signal
written as a (Chassaing, 2005, p. 123), (Reay, 2012, p. 111):
20
( ) can be
Design of FIR Digital Filters using Optimal Methods
( )=
( )
(3.1)
= (0) + (1)
+ (2)
+⋯
(3.2)
The z-transform of ( − 1), which equivalents to a first order derivative
[ ( − 1)] =
, is
( − 1)
(3.4)
= (−1) + (0) = (−1) +
+ (1)
+ (2)
[ (0) + (1)
= (−1) +
+ (2)
+⋯ + ⋯]
( )
(3.5)
Where (−1) represents the initial condition required to solve a first order difference equation. Also, The z-transform of x(n − 2), which corresponds to the second order derivative [ ( − 2)] =
( − 2)
, is (3.6)
= (−2) + (−1)
+ (0)
= (−2) + (−1)
+
= (−2) + (−1)
+
+ (1)
[ (0) + (1)
+⋯ +⋯]
( )
(3.7)
Where (−2) and (−1) represent the two initial conditions required to solve a second order difference equation. Generally,
(− )
[ ( − )] =
+
( )
(3.8)
Suppose that all the initial conditions are zero, then (− ) = 0. This leads to [ ( − )] =
( )
(3.9)
According to (Mulgrew, Grant, & Thompson, 2003, p. 106), the general form of the difference equation is given by:
21
Design of FIR Digital Filters using Optimal Methods
( )=
( − )−
( ) is the output sample,
Where
( − )
( − ) is the previous output, and
(3.10) ,
are system
coefficients. Taking z-transform of both sides of equation (3.10), and leads to the transfer function:
( )=
( )−
( )+ ( )
=
( )
(3.11)
( )
The transfer function is ( )= Similarly, if all denominator coefficients
( ) ∑ = ( ) 1+∑
are zero, equation (3.12) can be reduced to
( )=
(3.13)
Equation (3.12) can be analysed into: If
(3.12)
= 0 for all values of , then it is FIR filter (Equation 3.13);
If b ≠ 0, then it is IIR filter (Equation 3.12).
3.4 Digital Filters Representation There are three important methods that are used to describe a digital filter, which are:
1- Mathematical Algorithm For example: ( )= ( )+ 22
( − 1)
Design of FIR Digital Filters using Optimal Methods
In this example, and
is representing the properties of this digital filter, likewise the values of
define the properties of analogue filters. To produce the current output ( ), the previous
output ( − 1) is multiply by the constant value
and then added to the current input ( ).
2- Software Digital filters can be described with some lines of code. For example: 1
Read x y=a*y+x Write y Go to line 1
These lines can be explained as follows: read the next sample , take the previous output from the memory, multiply it by , add the product ( value of
∗
( − 1)) to the value of , replace the
with the result and return to the line 1; then wait for a new sample.
3- Block Diagram In the hardware implementation of the simple digital filter, as in the above example, there are three main elements (see Figure 10), which are:
Figure 10: Block diagram of a simple digital filter
a) Unit delay The idea from this unit is to hold the input before it is delivered to the output by sampling interval
(Leite, 2010, p. 178). It is also used to store the system parameters, past input, past
output and any intermediate calculated values. It performs the following operation: 23
Design of FIR Digital Filters using Optimal Methods
( ) = ( − 1) Sometimes the delay refers to the
(3.14)
which means that the delay operator in the z-domain (see
Figure 11). [ ( − 1)] =
( )
(3.15)
Figure 11: Delay function
b) Adder As seen from Figure 12, the idea from this unit is to add two or more signals at a particular time.
Figure 12: Adder function c) Multiplier The idea from this unit is to multiply the input signal by a constant number (see Figure 13).
Figure 13: Multiply function
24
Design of FIR Digital Filters using Optimal Methods
3.5 IIR Digital Filters 3.5.1 The basic concept An infinite impulse response digital filter has an impulse response with an infinite number of nonzero samples. In fact, with a finite duration of nonzero input values, the IIR filter could have an infinite duration of nonzero output values. The main reason for having infinite response characteristic is the presence of feedback, which means that IIR digital filters uses some of its previous output samples to calculate the current output sample; therefore, it called a recursive filter. Similar to other feedback forms, IIR filters having feedback can produce instability in the function of these filters and make it have nonlinear phase characteristics, especially when the feedback is too large. This will cause oscillations in the output of the IIR filter, and leads to inaccurate response which may be hard to detect and correct. But the main advantage of IIR filters is their capability to achieve tasks using a smaller amount of computational power and less memory (Oshana, 2006, p. 95).
3.5.2 Transfer Function The general formula for the input and output relations of an IIR digital filter is given by the following equation (Hussain, Sadik, & O’Shea, 2011, p. 108):
( )= −
( )+
( − 1) + ⋯ +
( − 1) −
( −
( − 2) − ⋯ −
)
( − )
(3.16)
Or more clearly, ( )=
( − )−
25
( − )
(3.17)
Design of FIR Digital Filters using Optimal Methods
Where ( ) and ( ) are the input and output of the filter, respectively; ,
feedback real value coefficients and is the number of poles,
,…,
,
,…,
are
are feed-forward real value coefficients.
is the number of zeros. Usually,
is larger than
, and the order of
the IIR filter is determined by the number of its poles or zeros, whichever is greater. Then, the number of delay elements that used in the filter structure can be determined from the filter order. Poles and zeros of the transfer function of the IIR filter can be represented in a diagram called pole-zero plot, which is used for checking stability of such filter. Therefore, for the IIR filter to be stable, all its poles must be inside the unit circle. Equation (3.17) explained that the present output sample ( ) is a function of past outputs ( − ) in addition to current and past input samples ( − ), this leads to the IIR filter is a feedback system. For both sides of the equation (3.16), taking the z-transform:
( )=
( )+
( ) + ⋯+
( )−
−
( ) − ⋯−
( ) ( )
(3.18)
Therefore, the transfer function of the IIR filter in the z-domain can be written as:
( )=
( ) = ( ) 1+ =
+ −
∑ 1+ ∑
+ ⋯+ − ⋯− (3.19)
3.5.3 Realisation of IIR filters Realisation requires converting a given transfer function into appropriate filter structure. Block diagrams are frequently used to describe filter structures and they show the computational procedure for implementing the digital filter. From equation (3.19) and as shown in Figure 14, a block diagram (functional diagram) of the IIR filter implementation can be constructed directly; it is called a direct form realization. 26
Design of FIR Digital Filters using Optimal Methods
Figure 14: Block diagram of IIR filter
3.6 FIR Digital Filters 3.6.1 The basic concept A finite impulse response digital filter has an impulse response with a finite number of nonzero samples. In fact, with a finite duration of nonzero input values, the FIR filter will have a finite duration of nonzero output values. To get a current output sample value, FIR filters use just present and past input samples without using previous output samples; therefore, FIR filters are called non-recursive filters.
27
Design of FIR Digital Filters using Optimal Methods
FIR filters have a number of advantages that make them easy to understand and implement. First of all, these filters are always stable due to no feedback between the output and the input which by definition ensures a finite response. Secondly, FIR filters can be designed with accurately linear phase. Linear phase FIR filter is desired in many applications (such as audio and video signal processing) because they can avoid phase distortion in the signal that passes through it, which causes degrade the system performance. Furthermore, FIR filters can be used to implement all kinds of frequency responses. On the other hand, the major disadvantages of the FIR filters, in some cases, are that they require more arithmetic operations, more hardware components (such as adders, multipliers and delay elements) and higher filter order for achieving a certain level of performance (Elali, 2005, p. 591).
3.6.2 Transfer Function The general equation for implementation of the FIR filter is represented by the discrete of a convolution equation between the input and the impulse response of the filter, which is a linear shift-invariant system given by (Hussain, Sadik, & O’Shea, 2011, p. 91): ( ) = ℎ( ) ∗ ( )
( ) =
(3.20)
( − )
ℎ
(3.21)
Or simply, ( ) = ℎ
( )+ ℎ
( − 1) + ℎ
( − 2) + ⋯ + ℎ
− ( − 1)
(3.22)
Where ( ) and ( ) are the input and output of the filter, respectively; ℎ is the impulse response,
− 1 is the order of the FIR filter and has
nonzero coefficients (or filter length).
Moreover, the unit sample response ℎ of the FIR digital filter is identical to the filter coefficients
, specifically: ℎ =
, 0,
0≤
≤
−1
ℎ
By taking the z-transform for both sides of the equation (3.22), gives: 28
(3.23)
Design of FIR Digital Filters using Optimal Methods
( )= ℎ
( )+ ℎ
( )+ ℎ
(
( ) + ⋯+ ℎ
=
ℎ
=
( )
)
( )
(3.24)
( )
ℎ
(3.25)
Hence, the transfer function of the FIR filter in the z-domain can be written as: ( )=
( ) = ( )
ℎ
(3.26)
Alternatively and equally important, some papers and textbooks use the equation (3.27) to represent the transfer function of the FIR digital filter
( )=
Thus,
( ) = ( )
is the order of the FIR filter and
ℎ
(3.27)
+ 1 is the number of coefficients (or filter length).
For example, the transfer function of the FIR filter is given by: (
)=ℎ +ℎ
+ℎ
+ℎ
+ℎ
This leads to the order of the filter is 4 and its length is 5.
3.6.3 Realisation of FIR filters From equation (3.21) and as shown in Figure 15, a block diagram of the FIR filter implementation can be constructed directly. This is also referred to as the direct form implementation scheme.
29
Design of FIR Digital Filters using Optimal Methods
Figure 15: Block diagram of FIR filter
At this point, the input signal ( ) is inputted to a series of delays, and the outputs from every delay are entered to the multipliers. Every multiplier has a coefficient adjusted by the desires filter. Then, the output from every multiplier is inputted to the adder; the adder’s output will be the output of the FIR filter.
3.7 FIR versus IIR Filters Although they have a few drawbacks, FIR filters have a number of useful properties that lead them to be desired over IIR filters for several applications. Following is a summary comparison between IIR and FIR digital filters (Kester, 2000, p. 149), (Lyons, 2004, p. 279):
To create every output value, FIR takes the input data and multiplies it by a series of coefficients, whereas IIR filter feeds the output data obtained back through another
30
Design of FIR Digital Filters using Optimal Methods
multiplies and coefficients. This feedback creates some undesired behaviour, and makes IIR filter more difficult to analyse.
FIR filters can obtain precise linear phase while IIR filters produce some phase distortion.
Unlike IIR, FIR filters have no poles in their z-plane transfer function and guaranteed to be stable.
Analogue filters can be easily transformed into IIR digital filters with similar specifications, but FIR filters does not have analogue history.
IIR filters usually have lower orders than FIR filters for the same design requirements, and consequently they require fewer elements of delays and multipliers for hardware implementations.
IIR filters are highly sensitive to coefficients errors. This is not the case with FIR filters.
FIR filters are simple to implement than IIR filters.
FIR filters can be designed with arbitrary frequency response.
3.8 Practical Filter Specifications Normally, frequency selective filters can be designed by beginning with a specification of their frequency response. Ideal filters, as discussed in Chapter II, whichever pass or reject a particular range of frequency completely and they have zero transitions band. The term transition band refers to the range of frequency over which a filter transitions from the passband to the stopband and defined by their cut-off frequencies. Although the ideal filters are preferred in many applications area, they cannot be implemented in practice. The reason for that is due to unstable because the impulse response ℎ( ) of ideal filters as shown in equations (2.23), (2.25), (2.29), and (2.31) have infinite time duration; consequently, their magnitude |ℎ( )| go to infinty. Also, their impulse response are noncausal because ℎ
( )≠
0 for < 0, and therefore incapable to implement in real time applications. For those reasons, ideal filters have to be approximated by practically filters. There are four major differences between practical filters and ideal filters which are: practical filters do not have flat passband response, cannot perfectly eliminate a range of frequencies, have a wide transition band, and do not have perfect linear phase. Passband ripple, stopband 31
Design of FIR Digital Filters using Optimal Methods
ripple and wider transition band are undesirable characteristics in the practical filters. The terms passband ripple and stopband ripple mean peak to peak fluctuations in the frequency magnitude response within the passband and stopband, respectively. For frequency selective digital filters, time response or frequency response specifications are used to decide the proximity of practical digital filter to the ideal one. First of all, the following parameters should be defined: Cut-off frequency Passband edge frequency Stoband edge frequency Sampling frequency Transition width
∆
Passband ripple Stopband ripple
The best filter is characterized by
Minimum passband ripple
Minimum transition band
Largest stopband attenuation
Mathematically, passband and stopband ripple can be expressed in decibels, as below (Ingle & Manolakis, 2011, p. 539) (Diniz, Silva, & Netto, 2010, p. 302): 1+ 1−
= 20
1+ (
= 20 Where
and
(3.28 ) ) ≈ −20
(3.28 )
is the passband and stopband attenuation in dB. Alternatively,
=
10
−1
10
+1
(3.29 )
= 10
(3.29 ) 32
Design of FIR Digital Filters using Optimal Methods
The transition band is given by ∆ =
−
(3.30)
and the cut-off frequency is defined by + 2
=
(3.31)
In some applications the specifications are given in terms of normalized frequencies rather than in Hertz. The following equation is used to convert absolute frequency in Hertz to normalized frequency: = Where and
is absolute frequency in
2
=
(3.32) ,
is the sampling frequency in
=
,
is normalized frequency in
3.5.1 Low Pass Filter Specifications A LPF is designed to pass low frequencies from zero to a specific cut-off frequency with approximately unity gain (or 0 dB). Figure 16 gives a graphical description of the specification of a LPF, the magnitude response of passband is 1−
≤
≤1+
0≤
≤
(3.33 )
Similarly, the magnitude response of stopband is 0 ≤
≤
≥
33
(3.33 )
Design of FIR Digital Filters using Optimal Methods
Figure 16: Practical LPF specification
3.5.2 High Pass Filter Specifications A HPF is designed to pass high frequencies from a specific cut-off frequency to above with approximately unity gain (or 0 dB).
Figure 17: Practical HPF specification 34
Design of FIR Digital Filters using Optimal Methods
Figure 17 gives a graphical description of the specification of a HPF, the magnitude response of stopband is 0≤
≤
0≤
≤
(3.34 )
Similarly, the magnitude response of passband is 1−
≤
≤1+
≥
(3.34 )
3.5.3 Band-Pass Filter Specifications A BPF is designed to pass a range of frequencies between two cut-off frequencies with unity gain (or 0 dB) and attenuate all others outside that range.
Figure 18: Practical BPF specification Figure 18 gives a graphical description of the specification of a BPF, the magnitude response of stopband is 0≤
≤
0≤
0≤
≤
≥
35
≤
(3.35 ) (3.35 )
Design of FIR Digital Filters using Optimal Methods
Similarly, the magnitude response of passband is 1−
≤
≤1+
≤
≤
(3.35 )
3.5.4 Band-Stop Filter Specifications A BSF is designed to attenuate a range of frequencies between two cut-off frequencies and pass all others outside that range with unity gain (or 0 dB). Figure 19 gives a graphical description of the specification of a BPF, the magnitude response of stopband is 0≤
≤
≤
≤
(3.36 )
Similarly, the magnitude response of passband is 1−
≤
≤1+
0≤
1−
≤
≤1+
≥
≤
Figure 19: Practical BPF specification
36
(3.36 ) (3.36 )
Design of FIR Digital Filters using Optimal Methods
CHAPTER IV Design of FIR Digital Filters 4.1 Introduction As discussed in preceding chapter, digital FIR filters have several desirable features in comparison with IIR filters, such as they can achieve linear phase, have a finite duration of nonzero output values, and cannot be unstable. Therefore, the objective of this chapter is to design and examine FIR digital filters from specifications to coefficient calculations. This chapter studies different design methods for FIR filters. The simplest design method is windowing, which is widely used for designing standard filter types. Because it has some unwanted characteristics in frequency domain, this method is not fully useful in some cases. The second one is frequency sampling design method, which is used to design filters with arbitrary responses. The last design method is the optimal methods, it includes equiripple design (based on minimizes the maximum ripple in each band) and least-squares design (based on minimizes the integral of square error) methods. The comparison is done in terms of mainlobe width and side-lobes attenuation for all of these methods. The outline of this chapter is as follows: Section 4.2 presents a procedure for designing FIR filter. A number of methods for FIR filter design are discussed from Section 4.3 to Section 4.7. A comparison between those methods is explained in Section 4.8. Finally, estimation of the filter order is investigated in Section 4.9.
4.2 FIR Filter Design Procedure In practice, design of frequency selective digital FIR filters involves five steps, which can be summarized as follows:
37
Design of FIR Digital Filters using Optimal Methods
1- Filter specification: As discussed in the previous chapter, this includes specify the filter type, such as LPF, HPF, BPF or BSF, with preferred amplitude and phase response, as well as passband, stopband and sampling frequency. 2- Coefficient calculation: The main goal here is to calculate the transfer function of a filter and then determining its coefficient by a proper method to satisfy the specifications in step (1) with a minimum of computational processes. 3- Realization: As discussed before, this includes converting the transfer function into appropriate filter structure. 4- Analysis: This includes analysing, simulating and testing with real data to examine whether the filter meets the performance requirements. If not, return to step 2 or reduce the performance requirements. 5- Implementation: This includes implementing the actual filter obtained in software form, hardware or both. In simple terms, Figure 20 shows these five interconnected steps.
Figure 20: FIR filter design steps (Ifeachor & Jervis, 1993, p. 286)
38
Design of FIR Digital Filters using Optimal Methods
4.3 FIR coefficient calculation methods According to the equation (3.21) and (3.26), the purpose of FIR coefficient calculation methods is to get values of ℎ that meet the design specifications. A number of methods have been proposed for the design FIR digital filters. Most of these methods are compromise between computational complexity and how closely the designed filter satisfies the desired requirements. The window, frequency sampling, and optimization methods are the most commonly used.
4.4 Window Design Methods Digital filters design can be long duration, which leads to increase the computational requirements for applying such FIR filters, and this is usually not feasible in DSP devices. The method which is used to limit the duration of the FIR filters without influencing the resulting performance of the filter is called the “Window”, which is also used to reduce the unwanted overshoots and ripples (the well-known Gibbs phenomenon that results from truncation of an infinite sequence) in the frequency response of the designed filter. The window method requires a minimum amount of computational work, straightforward implementation and effective ways of calculating FIR coefficients of such filter; which makes it more widely used for designing FIR filters. The basic notion of the window design is to select an appropriate ideal frequency selective filter, which has
A unity magnitude gain over its passband, and zero response over its stopband.
Non-causal and unstable characteristics.
Infinite time duration impulse response.
and then try to window (or truncate) its impulse response in order to produce a linear phase and causal FIR filter. By definition, the window method is a “… function that is zero-valued outside of a chosen interval” (Giurgiutiu, 2008, p. 592). This method can be explained in more detail below. Recall that FIR filter is described by the following equations (3.20) and (3.21): 39
Design of FIR Digital Filters using Optimal Methods
( ) = ℎ( ) ∗ ( ) ( )=
ℎ( )
This means that ( ) is equal to the discrete convolution between the input ( ) and the impulse response of the filter ℎ( ). It can be stated that the theory of convolution as follows: “the Fourier transform of a convolution of two functions in one domain is the product of their Fourier transforms in other doamin” (Hamming, 1989, p. 1989). In other words, the convolution in the time domain is equal to multiplication in the frequency domain and vice versa. Therefore, by taking the discrete Fourier transform (DFT) to the ℎ( ) ∗ ( ) , it will give
. (
); and by taking the inverse DFT of
. (
), it will give ℎ( ) ∗
( ). Clearly, ℎ( ) ∗ ( )
.
(4.1)
As shown above, the window method starts with selecting ideal desired frequency selective response
that can be represented by the DTFT relation:
=
ℎ ( )
(4.2)
The frequency response can be defined in terms of the transfer function as follows (Schilling & Harris, 2005, p. 434): ≜
( )|
=
ℎ( )
=
ℎ ( )
(4.3) |
and then by using inverse DTFT to get the desired impulse response of the filter:
40
Design of FIR Digital Filters using Optimal Methods
ℎ ( )=
1 2
(
)
(4.4)
The impulse response ℎ ( ) in the equation (4.4) is infinite duration; therefore, to obtain a finite impulse response and causal filter, one has to truncate ℎ ( ) on the positive and negative side to a length
− 1 samples as follows: ℎ( ) =
ℎ ( ), 0,
0≤ ℎ
≤
−1
(4.5)
This process is called “windowing”, and the equation (4.5) can be rewritten in another form as the product of the infinite desired impulse response ℎ ( ) and a finite window duration ℎ( ) = ℎ ( ). ( )
( ): (4.6)
Taking Fourier transform for one period to the equation (4.6) ℎ ( ) ( )
=
(4.7)
Putting equation (4.4) in (4.7) 1 2
=
( )
By interchanging the order of integration, =
1 2
( )
=
1 2
( )
(
)
Consequently, the truncated frequency response of the FIR digital filter is: =
1 2
(
)
(4.8)
Because the two functions in the integral are periodic, equation (4.8) is a periodic convolution of the desired ideal frequency response and Fourier transform of the window with the limits of the integration extending over one period; as 41
Design of FIR Digital Filters using Optimal Methods
= where
(
∗
) is the spectrum of the window function, that is
=
( )
(4.9)
Windows are always symmetric and should satisfy the condition (Ingle & Manolakis, 2011, p. 562):
( )=
( − ), 0,
0≤ ℎ
≤
−1
(4.10)
A large number of windows have been developed for various applications to limit the signal duration. Nearly all of them are taking the name of the person who first proposed them. Because of the shape of the spectrum of the window functions
(
) to some extent are similar of the
shape; therefore there is a main-lobe and side-lobes. The main-lobe width and side-lobe amplitudes are vary from window to another. A narrow main-lobe width (which leads to small transition width of
(
) and a low side-lobe level (which leads to small ripples in both
passband and stopband areas) are the main criteria for engineers when they want to design a FIR filter by window method. Hence, the importance in this method is on choosing a suitable windowing function and a suitable ideal filter that will satisfy the specification requirements.
4.4.1 Rectangular Window The first window called the rectangular window (also called boxcar window) and it is defined by values are 1 (within the window) or 0 (outside the window). More specifically (Udayashankara, 2010, p. 265), ( )=
1, 0,
0≤ ℎ
42
≤
−1
(4.11)
Design of FIR Digital Filters using Optimal Methods
where
is the length of the window. According to the equation (4.9), the frequency domain
of rectangular window (Fourier transform) can be calculated as follows:
( )
=
=
1.
= =
+ 1− 1−
=
sin sin
(
+ ⋯+
)
−
=
− 2
(
)
(4.12)
2
Then, the magnitude is
=
sin sin
2
(4.13)
2
Figure 21 shows that the time and frequency domain of the rectangular window function. It can be noticed that the amplitude and width of the main-lobe is large compared to the side-lobe. Also, when the number of sample points
increased significantly (longer window), the main-
lobe becomes narrower and side-lobe’s width decreases, but the amplitude of side-lobes will remain unchanged. As seen from the decibel magnitude response (Figure 21), the relative sidelobe attenuation (which is the difference in height from the main-lobe peak to the highest sidelobe peak) is around −13
. Mathematically, this number can be confirmed by (Najim, 2006,
p. 154):
43
Design of FIR Digital Filters using Optimal Methods
sin sin = 20 log
sin sin
2 2
≈ −13
(4.14)
2 2
which is not good enough value (impractical in several applications), and the main-lobe width (which is the bandwidth of the main-lobe at −3
20 log
√
below the main-lobe peak)
is around 0.05.
Figure 21: Rectangular window function (N=32) 44
Design of FIR Digital Filters using Optimal Methods
4.4.2 Triangular Window The triangular window is defined as (Oppenheim & Schafer, 1989, pp. 447-448) For
odd: 2 ( )=
For
2( − )
, ,
1≤
≤
1
(4.33)
This window and its frequency domain response are shown in Figure 30. It can be seen that the main-lobe width is 0.1, and the relative side-lobe attenuation is equal −100 dB. Also, as shown from Figure 30 that the side-lobes have equal level, this is very important when designing digital filters.
Figure 30: Dolph–Chebyshev window function (N=32) 58
Design of FIR Digital Filters using Optimal Methods
4.4.11 Kaiser Window Kaiser (Kaiser, April 1974) proposed a new window, now called as a Kaiser window. It is widely used in practice and one of the most convenient windows that try to be an ideal window in FIR filter design. Kaiser window can also be used for detecting two signals with frequencies very close to each other but with different amplitudes. It has a good parameter used to control the size of the side lobe comparative to the width of the main lobe. It is defined clearly by (Udayashankara, 2010, p. 270) (Diniz, Silva, & Netto, 2010, pp. 299-303):
( )=
(
1− ( )
2 −1
,
0≤
0, where
≤
(4.34)
−1
ℎ
is a ripple control parameter which allows the designer to adjustment the transition
width and peak level of the ripple, and it can be calculated by
= 0.5842( − 21)
where
0.1102( − 8.7), + 0.07886( − 21), 0,
.
is the stopband attenuation in
> 50 21 ≤ ≤ 50 < 21
, and it is given by = −20 log ( )
Where is the minimum value between the desired passband ripple ripple
(4.35)
(4.36) and the desired stopband
. = min(
,
)
(4.37)
is the zero order modified Bessel function, and it is given by
( )=1+
=1+
0.25 (1!)
2
(4.38)
!
+ 59
(0.25 ) (0.25 ) + +⋯ (2!) (3!)
Design of FIR Digital Filters using Optimal Methods
which is positive for all real values of , N is the number of filter coefficients and it is given by = where ∆ =
−
− 7.95 14.36 ∆
(4.39)
(Equation 3.30) is the normalized transition bandwidth. This window and
its frequency domain response are shown in Figure 31. It can be seen that the shape of the Kaiser window is controlled by the shape parameter . Most importantly, Kaiser function can be used to approximate the other windows. This means that when
= 0, the Kaiser window
corresponds to the rectangular window and when it is 5.67, the Kaiser window is very similar to the Hamming window (see Table 2). Also, this figure shows when
increased, the side-
lobes will be smaller (disappear) whereas the main-lobe will be slightly wider (see Table 3).
Parameter
Window Function
0
Rectangular
3.28
Bartlett
4.04
Hanning
5.67
Hamming
8
Blackman
Table 2: β versus window function
Parameter
Main-lobe width
Peak side-lobe level (dB)
0
0.05
−13
3
0.06
−25
5
0.07
−38
8
0.101
−58
10
0.109
−74
14
0.125
−106
Table 3: Parameter values for the Kaiser function 60
Design of FIR Digital Filters using Optimal Methods
Figure 31: Kaiser window function for β=0, 3 and 5 (N=32)
4.5 Comparison of Window Functions In practice, the windowing method provides useful digital filters design because it is straightforward to use and simple to understand; which makes it more widely used for 61
Design of FIR Digital Filters using Optimal Methods
designing FIR filters. The frequency responses of the window functions that discussed previously have different main-lobe width and different amplitude of their side-lobes. The main-lobe width, the relative side-lobe attenuation, and the transition bandwidth are listed in Table 4. Approximately, the transition bandwidth ∆ for the window can be obtained by ∆ ≈ where
(4.40)
is a constant value that depends on the window type and the value of the main-lobe
width (directly proportional). It is observed from the table below that the main-lobe width tends to be wider as the side-lobe level be lower. The non-rectangular windows have lower sidelobes and wider main-lobes than the rectangular window with a narrow main-lobe but higher side-lobe; this can be seen in Figure 32. Furthermore, Rectangular, Triangular, Bartlett, Hanning, Hamming, Blackman and Flat-Top can be called as a fixed window; because they do not have parameters that can be modified (with the exception of the transition band that can be adjusted by choosing a suitable length ). Also, Dolph-Chebyshev window and Kaiser window can be called as an adjustable windows; because they have control parameters that can be used to trade-off between the main-lobe width and the side-lobe attenuation. Window functions with lower and equally amplitude side-lobes yields better approximations in filtering design as in Dolph–Chebyshev window. Moreover, Blackman window has very low side-lobes level (almost zero) that makes it desirable in some applications, although it has wider main-lobe. The Kaiser window is more suitable than the other windows because its transition band is narrower as well as its side-lobes level is very smaller (it depends on the control parameter ). But all the other window functions have their own advantages and disadvantages for designing FIR filter.
In addition, Rectangular, Hanning, Hamming and Blackman windows can be combined all those functions in one equation:
62
Design of FIR Digital Filters using Optimal Methods
( )=
−
cos
2 −1
+
4
cos
0≤
−1
≤
−1
When = 1 = =0 = = 0.5 =0 = 0.54, = 0.46 =0 = 0.42, = 0.5 = 0.08
Rectangular window Hanning window Hamming window Blackman window
Window Function
Main-lobe width
Relative side-lobe level ( )
Rectangular
0.05
−13 (poor)
Triangular
0.07
−26 (weak)
Bartlett
0.08
−26.5 (weak)
Hanning
0.09
−31.5 (acceptable)
Hamming
0.08
−42 (correct)
Gaussian
0.09
−45 (correct)
Blackman
0.1
−58 (good)
Flat-Top
0.2
−83 (very good)
Chebyshev
0.1
−100 (very good)
Kaiser
Depends on
Table 4: Comparison of commonly used window function characteristics
63
(4.41)
Design of FIR Digital Filters using Optimal Methods
Figure 32: Time and Frequency domain of commonly used window functions
64
Design of FIR Digital Filters using Optimal Methods
Finally, it can be summarized the coefficients calculation by using window methods in four steps. At the first, the designer should specify the desired frequency response of the wanted filter
(
). Next, determine the impulse response ℎ ( ) of that filter by evaluating IDFT.
After that, select a desired window function that satisfies the passband and stopband attenuation and determine the values of
( ). Finally, calculate the actual FIR coefficients by ℎ( ) =
ℎ ( ). ( ) (Equation 4.6).
4.6 Frequency Sampling Method The window method is good for designing the simple ideal low pass, high pass, band-pass, and band-stop responses. But with arbitrary frequency response like designing a FIR LPF with a constant phase shift that applied to all frequencies or when several BPF filters are wanted at the same time (for example, with different amplitudes), then the window method will be unsuitable. As stated previously, the starting point for the windowing method was the desired frequency response
(
). Then applying IDFT to get the unit impulse response ℎ ( ), after that
ℎ ( ) was multiply with a specific window function to be sampled and given the filter coefficients. On the other hand, the frequency sampling method which is very similar to the window method but the difference is that the starting point is the sample frequency response ( ); which is done by taking equally spaced samples of the frequency domain specification to obtain
samples at intervals of
, then applying IDFT to get the filter impulse response
coefficients ℎ( ). Mathematically, the samples of the ideal frequency response is given by (Ifeachor & Jervis, 1993, pp. 317-333)
( )=
|
= 0, 1, … ,
−1 2
= 0, 1, … ,
−1
2
(4.42)
Then by using inverse DFT formula, the unit sample response ℎ( ) can be computed as follows: 65
Design of FIR Digital Filters using Optimal Methods
ℎ( ) =
1
( )
= 0, 1, … ,
−1
(4.43)
( ) can be written as ( ) = | ( )|
−1 2
=
(4.44)
Thus, ℎ( ) =
=
=
1
1
1
| ( )|
| ( )| −
| ( )| cos 2
+ sin 2
−
Then, since ℎ( ) is totally real (actual signal samples): ℎ( ) = Consequently, for
| ( )| cos 2
−
(4.45)
even
ℎ( ) =
and for
1
1
(0) +
2| ( )| cos 2
(0) +
2| ( )| cos 2
−
(4.46 )
odd
ℎ( ) =
1
−
(4.46 )
The resulting filter will have a frequency response that is very closely to the original response at the sampling instants. One technique to make the output of the specific filter more accurate
66
Design of FIR Digital Filters using Optimal Methods
is to increase the number of frequency samples. Recall the transfer function of the FIR filter which is
( )=
ℎ( )
Taking the z-transform of the equation (4.43) gives:
1
( )=
(
( )
)
(4.47)
Interchanging the order of the summations: ( )=
1
( )
(4.48)
The term between brackets can be written as (
) =
1−(
(
)
)
1− =
1−
(4.49)
1− When
= 1 (for
= 0) 1−
=
(4.50)
1− Putting (4.50) in (4.48) ( )=
1
1−
( )
(4.51)
1− Finally, the system function is ( )=
( )
1− 1−
67
(4.52)
Design of FIR Digital Filters using Optimal Methods
Proakis and Ingle (2011, p. 356) found that the window function is particularly important with the frequency sampling method to minimize ripples near the band edge frequencies, because the frequency sampling method does not provide a suitable control on the peak ripple and band edges. This means after computing FIR filter impulse response using the frequency sampling method, then applies a selected window (Equation 4.6) to increase stopband attenuation and smooth the effects of truncation.
4.7 Optimization Methods 4.7.1 Optimal Equiripple Design method Although the window and the frequency sampling design methods are simple to understand and implement, they have some disadvantages. Firstly, they cannot identify the band frequencies and
and
accurately in the design. Secondly, they cannot identify the ripple factors
at the same time. Either
=
in the window method, or it can adjust only
in
the frequency sampling design. Thirdly, the term approximation error (which is the difference between the ideal response and real response) is not uniformly distributed over the band intervals. In other words, it will be greater near the band edges and smaller in the areas far from band edges. For frequency sampling method, finally, the frequency response could be presented errors at the points where it is not sampled. Therefore, optimal equiripple method (also called Parks-McClellan algorithm) was introduced to remove these problems by making the approximation error equal in the passband and stopband edges. Also, this method is very powerful, very flexible and offers lower filter order which can meet the design specifications than the other methods. For these reasons, equiripple design method has become a desirable method in many applications. As seen from Figure 16, the practical response oscillates in the passband between 1 + 1−
, and oscillates in the stopband between 0 and
and
(see Equation 4.54). Therefore, the
difference between the actual response and the ideal response can be viewed as an error function (
) given by: =
−
68
(4.53)
Design of FIR Digital Filters using Optimal Methods
where
(
) is a non-negative weighting function that is used to weight the approximation
errors differently over different intervals, and
is the desired or ideal frequency response,
is the actual frequency response. The actual magnitude for normal FIR filter is
given as =
1± 0+
ℎ ℎ
(4.54)
and the weighting function can be chosen as (McClellan & Parks, March 1972), (Clements & Miao, 2002, p. 153) 1
ℎ
=
(4.55)
ℎ
McClellan and Parks was published an excellent paper in 1972, that deals with designing linear phase FIR filters with minimum weighted error in approximating a preferred ideal frequency response by incorporating the Remez exchange algorithm to calculate iteratively the extremal frequencies at which the maximum deviations (ripples) in the error function happen. Even though the mathematics included in the the Remez exchange method is complicated, ParksMcClellan algorithm (equiripple method) try to make the passband and stopband ripple as small as possible with ability for designing a suitable order of filter types as well as any desired magnitude response. The optimal equiripple method tries to minimize (obtained by varying the filter’s coefficients) the maximum magnitude of the error
(
) in the passband and stopband (between the
desired and actual frequency response). It can be expressed by a simple formula (which is called minimax problem) (McClellan & Parks, March 1972) (Cheney, 1966):
= min[max (
)]
where is called extremal error. Consequently, when max
(4.56)
(
) is minimized, the resulting
filter response will have equiripple in passband and stopband (peak-to-peak amplitude is the same). 69
Design of FIR Digital Filters using Optimal Methods
For an
th order equiripple FIR filter, the maximum error happens at discrete extremal
frequencies
. The locations of the maximum errors are obtained using the alteration theorem
(Ingle & Manolakis, 2011, p. 578): =−
,
= max
≜
(4.57)
Thus, =
= (−1)
−
,
1≤ ≤
+2
(4.58)
According to the (Parks & McClellan, March 2005), the algorithm steps are: 1- Initialization: Choose an extermal set of alternation frequencies 1, 2, … ,
+ 2, should include the frequencies
to the filter order ,
=
(even
= 0,
=
) and
(odd
,
, and . Where
( )
,
=
is related
).
2- Finite Set Approximation: Calculate the approximation error value on the present extremal set:
=
∑
,
(−1) ( )
∑
=
cos(
1 ) − cos(
)
(4.59)
By determining , then =
−
(−1) (
)
,
3- Interpolation: Determine the polynomial
= 1, 2, … ,
+1
(4.60)
using the Lagrange interpolation
formula: ∑
( −
=
=
(
∑ 1 −
) 70
( −
=
(
)
(4.61 )
)
−
)
(4.61 )
Design of FIR Digital Filters using Optimal Methods
where
= cos( ) and
= cos(
), and then calculate the error function (
) over the
entire set of frequencies using (2). ( )
4- Look for local maxima of 5- If max
( )
(
) >
frequencies where 6- If max
( )
(
( )
( )
) ≤
(
(
) on the set.
, then update the extremal set to
(
)
by picking new
) has its local maxima. Return to Step 2 and iterate.
( )
, then the algorithm is complete. Use the set
( )
and the
interpolation formula to compute an inverse discrete Fourier transform to obtain the filter coefficients.
For basic low pass, high pass, band pass, and band stop filters, the weighting function and the desired or ideal amplitude response
are summarized in Table 5.
Filter type 1 ,
ℎ
,
ℎ
,
ℎ
1 ,
ℎ
Low pass filter
High pass filter , Band pass filter
Band stop filter
1 ,
ℎ 1 ℎ
,
ℎ 2
1 ,
ℎ 1
, 1 ,
ℎ ℎ 2
1 , 0 ,
ℎ ℎ
0 , 1 ,
ℎ ℎ
0, 1, 0,
ℎ 1 ℎ ℎ 2
1, 0, 1,
ℎ 1 ℎ ℎ 2
Table 5: Weight functions and ideal magnitude responses for standard frequency-selective filters
71
Design of FIR Digital Filters using Optimal Methods
Figure 33 illustrates the initialization steps of Remez exchange algorithm before the optimum = 12. As
has been found for low pass filter with ( + 2 = 6 + 2 = 8)
= 0,
,
,
,
,
= ,
,
= 6, the set of initial frequencies used to obtain
(which is too
small for the chosen extremal frequencies), it is represented by small circles in the figure (o). By applying the Remez exchange steps using all equations shown above, there are local extrema of (
) in the open interval 0