Realtime Digital Filtering Using The LPC1768 ARM Cortex-M3

27 downloads 0 Views 4MB Size Report
Feb 3, 2017 - ARM mbed Cortex M3 micro-controller along with pin functionality [1] .... their mbed microcontroller. ... The filter, in theory, should have greatly attenuated the frequency at 0.2, .... but is by no means a complete replacement to analog systems. ...... this reason, the value at n = M/2, based on l'Hopital's rule [48] ...
Realtime Digital Filtering Using The LPC1768 ARM Cortex-M3 Microcontroller Student: Osama Ashaikh Supervisor: Dr Ali Al Ataby

Dissertation submitted to the University of Liverpool in partial fulfilment of the requirements for the degree of Master of Science in Engineering in Energy and Power Systems.

Acknowledgements I would like to first and foremost and with all humility, thank Allah for helping me reach my current stage in life; for without his guidance, I would have easily lost my way. I would like to extend gratitude to my beloved parents for their continuous love; moral and material support throughout my academic journey. I would like to thank my friend Maximillian Emenike who has always found time to help me. I would like to thank my supervisor Dr Ali Al Ataby for giving me the opportunity to undertake this project under his guidance. Finally, I would like to thank my assessor Dr Waleed Al-Nuaimy for the critical feedback and constructive criticism he has provided. It has greatly assisted me in improving report writing skills.

Abstract Digital Signal Processing has been made popular with the extensive use of digital filters. Their capabilities at mitigating error in signals that are created by passive components have made them a popular choice among hobbyists and professionals in industries, which rely on the processing of important signals. An issue however is that for every use-case, a different filter design is required. Generally, expensive software packages are used to generate reliable filter coefficients, which can then be used to create or update existing digital filters; the alternative to solve complex mathematical problems. This dissertation documents the steps necessary to design and implement digital filters in real-time; that is, the ability to change or update filter specifications on the fly, without the need to worry about cumbersome mathematical derivations or calculations. A desktop application written in C# has been built to aid in the design of filters and with the click of a button, the specifications are sent to a micro-controller. The microcontroller generates, in real-time, a set of coefficients for the given design that can be used instantly. The micro-controller in question is the LPC1768 by ARM, which features a Cortex-M3 processor. In this project, the ability to generate coefficients of various filters in real-time including: Butterworth, Chebyshev Type I; Hamming, Hanning, Bartlett, Rectangular and Blackman has been achieved, for various frequency responses including: low-pass, high-pass, band-pass and band-stop. The code mbed code in its entirety is available online at the link or the QR code. https : //developer.mbed.org/users/oashaikh/code/M SC part2/

Contents 1 Introduction

1

2 Literature Review 2.1 Common Implementation Methods . . . . . . . . . . . . . . . . . . . . . . 2.2 Review of Analog Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.1 Time & Frequency Domains and Converting Between Them . . . . . 2.3 IIR Digital Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.1 Basic Low-pass Filter . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.2 Basic High-pass Filter . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.3 Basic Band-pass Filter . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.4 Basic Band-Stop Filter . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.5 The Bilinear Transform . . . . . . . . . . . . . . . . . . . . . . . . 2.3.6 Converting Analog Prototypes Into Digital Filters - Obtaining Filter Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.6.1 Butterworth Approximation . . . . . . . . . . . . . . . . . 2.3.6.2 Chebyshev Approximation . . . . . . . . . . . . . . . . . . 2.4 FIR Digital Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4.1 FIR Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4.1.1 FIR Filter Responses . . . . . . . . . . . . . . . . . . . . . 2.4.1.2 FIR Windows . . . . . . . . . . . . . . . . . . . . . . . .

27 27 34 38 38 40 41

3 Methodology 3.1 User Friendly Graphical User Interface 3.2 Materials Used . . . . . . . . . . . . 3.3 Signal Conditioning Circuits . . . . . 3.4 Validity and Reliability of Results . . 3.5 Analysis of Filter Performance . . . . 3.6 Software Implementation Model . . . 3.6.1 mbed Application . . . . . . 3.6.2 Windows GUI Application . .

. . . . . . . .

44 44 45 46 48 48 49 49 50

. . . . . .

51 51 56 56 57 58 62

(GUI) . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4 Results and Discussion 4.1 GUI Application . . . . . . . . . . . . 4.2 Filter Coefficients . . . . . . . . . . . 4.3 Filter Results . . . . . . . . . . . . . . 4.4 IIR Filter Results . . . . . . . . . . . . 4.4.1 Butterworth Low-pass Response 4.4.2 Chebyshev I Low-pass Response

. . . . . .

. . . . . .

. . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

3 4 6 6 15 15 19 22 24 26

4.5

4.4.3 Chebyshev I High-pass Response 4.4.4 Chebyshev I Band-pass Response 4.4.5 Chebyshev I Band-stop Response FIR Filter Results . . . . . . . . . . . . 4.5.1 Rectangular Window FIR Filter .

. . . . .

. . . . .

. . . . .

. . . . .

5 Conclusions and Recommendations 5.1 Project Deliverables and Difficulties Encountered 5.2 Limitiations . . . . . . . . . . . . . . . . . . . . 5.3 Further Development . . . . . . . . . . . . . . . 5.4 Conclusions . . . . . . . . . . . . . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . .

64 65 66 67 68

. . . .

71 71 71 72 72

References

76

Appendices

77

A Specification Report

78

B ARM mbed Cortex M3 Features

80

C Code Listings

84

List of Figures 2.1.1 2.2.1

2.2.2

2.2.3

2.2.4 2.2.5

2.3.1

2.3.2

2.3.3 2.3.4

2.4.1 2.4.2

ARM mbed Cortex M3 micro-controller along with pin functionality [1] . . . Top: An illustration of a continuous time 100Hz. The signal is continuous i.e. there are no gaps between points. Bottom: A discrete time signal. The signal is a discrete time waveform of the above continuous signal i.e. it is sampled at intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . shows three cosine waveforms, 50Hz, 150Hz, 300Hz and combination of all three frequencies in the time domain that will be converted into the frequency domain through a DTFT. . . . . . . . . . . . . . . . . . . . . . . . . . . . shows three frequencies 50Hz, 150Hz and 300Hz in the frequency domain after a DTFT. The transform and plots where were obtained with the aid of MATLAB. It is clear from the plots that DTFT separates the time domain signal into its individual frequency components. . . . . . . . . . . . . . . . A simple analog RC low-pass filter circuit that is used as an example in deriving its transfer function to be used in the digital domain . . . . . . . . . . . . . Pole-zero plot for the transfer function in equation 2.2.13. The Poles are marked by an ’x’. There is only one pole and it is in the left half of the s-plane, therefore the system is stable . . . . . . . . . . . . . . . . . . . . . Typical frequency response magnitude of a low-pass IIR filter. It is clear that when r is near 1, the pole draws closer to the unit circle and so the response’s rate of roll-off drastically increases. . . . . . . . . . . . . . . . . . . . . . . Typical frequency response magnitude of a high-pass IIR filter. Similar to its low-pass counterpart, the rate at which higher frequencies are attentuated, greatly depends on the how close the poles are to the unit circle. . . . . . . Typical frequency response magnitude of a band-pass IIR filter. The pass-band bandwidth in this example was set to π/5. . . . . . . . . . . . . . . . . . . Typical frequency response magnitude of a band-stop IIR filter. The passband bandwidth in this example was also set to π/5. As r approaches 1, the response becomes steeper and better attenuates unwanted frequencies. . . . Sinc function that is used to approximate an FIR window to obtain an ideal response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sinc function with rectangular window. No change compared to original signal except truncation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1

5

7

9

9 10

12

16

20 23

25 39 41

2.4.3

2.4.4

3.3.1 3.3.2 3.3.3

3.3.4 3.3.5 3.6.1 4.1.1

4.1.2

4.1.3 4.1.4 4.1.5

4.1.6

Frequency response of a rectangular window [2]. fs = 2000, fc = 460, n = 21 The blue line represents the transition between the pass-band and stop-band, which is the ideal cut-off point. This happens at the -3dB point. It is clear that this window does not have the response of the ideal filter due to the large ripples in the stop-band. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Shows how various windows can be used to influence the response of a lowpass filter. A common feature among the windows shown is that they all have severe ripple in the stop-band; although for some windows, i.e. the Blackman window, this is compensated for, by attenuating higher frequencies more aggressively [2]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Signal offset circuit to ensure that the signal entering the ADC of the mbed is within 0 and 3.3V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Blue: This is the signal before the offsetting circuit.Yellow: This is the signal after the offsetting circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . Circuit to remove stepping effect from output signal while simultaneously removing the DC offset that was introduced to the input signal. The components where select such that the cut-off frequency was higher than the frequency range of the input. In this case 150kHz . . . . . . . . . . . . . . . . . . . Shows the stepping nature of the output signal before being reconstructed by the circuit in figure 3.3.3.Blue: Output signal. Yellow: Input signal. . . . . Shows how the DC offset in the output signal Blue, was removed and at the same time mitigating the stepping effect of the DAC . . . . . . . . . . . . . Left: Main program loop to run the desired filter. Middle: ISR routine to check if serial data is available. Right: Thread to check if serial data was valid. Upon launch, the user is greeted with a screen that allows then to connect to their mbed microcontroller. If no port is selected, the connect button will be disabled. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . When the connect button is clicked, the user is given a choice of Basic or Advanced mode. The basic mode is shown by default. The basic mode allow inexperiences users to send predefined filters to the mbed at the click of a button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Switching to advanced mode in the application . . . . . . . . . . . . . . . . Sending the filter specification to the mbed . . . . . . . . . . . . . . . . . The application does not allow invalid specifications. For example, if the user selects a cut-off above the Nyquist frequency, an error message is issued and sending is canceled. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Shows how selecting an invalid order gives the user an error message. . . . .

2

41

43 46 46

47 47 48 49

51

52 53 54

55 55

4.4.1

4.4.2

4.4.3

4.4.4

4.4.5

4.4.6

4.4.7

4.4.8

4.5.1

Compared to the original signal, the high frequencies have clearly been attenuated. The frequency spectrum clearly shows that the low frequency component at 0.04 has not been attenuated. This shows that the filter was successful at mitigating high frequencies. . . . . . . . . . . . . . . . . . . . . . . . . . . The cut-off point was set to 0.24. It is clear that the filter successfully attenuated the low frequency component by 20dB, while high frequency components where allows to pass. The means the high-pass implementation of this filter was correct. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The filter attenuated a large portion of the frequencies significantly; up to 60dB for high frequency components. The cut-off points where set to 0.16 and 0.24, which means that ideally, the frequency at 0.2 should have been left unattenuated. It is possible that the loop governing the filter was implemented incorrectly. The stepping in the time-domain plot is due to the zooming of the waveform, since the voltage of the output signal was greatly reduced. . . The filter, in theory, should have greatly attenuated the frequency at 0.2, but that is not the case from the frequency spectrum; although, from the time-domain plot, this is not very obvious. . . . . . . . . . . . . . . . . . . From the spectral plot, it is clear that the higher frequency components where attenuated. However, there are new harmonics introduced into the signal after filtering. This could be from two causes: The implementation of the filter loop is using the wrong feedback variable; or the mbed itself is producing noise on the DAC output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The filter has successfully attenuated the low frequency component (0.04) of the signal by 20dB. The high frequency components have been left alone up to 0.4, where they start to become attenuated. This could be due to an incorrect gain value of the filter. . . . . . . . . . . . . . . . . . . . . . . . In this case, the filter was supposed to pass the central signal, corresponding to 0.2. This is not the case however as seen from the spectral plot. The generated coefficients where similar to that of MATLAB so the cause for the incorrect response is due to the implementation of the recursive loop. . . . . The frequency corresponding to 0.2, should have ideally been attenuated. Instead, its power has increased by 10dB, which means that the band-stop recursive loop code is faulty. Another reason could be due to . . . . . . . . The signal shown will be used as the input to the mbed’s ADC . . . . . . .

3

58

59

60

61

62

64

65

66 67

4.5.2

4.5.3

4.5.4

4.5.5

FIR low-pass rectangular window. When compared to the original signal, it is clear that only the low frequency component was allows through the filter. This goes to show that the implementation of this filter was successful. The frequency spectrum shows that the higher frequencies have been attenuated significantly, however, the low-frequency component has also been reduced by nearly 20dB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FIR high-pass rectangular window. It is clear from the frequency spectrum than the filter did not perform very will. The low-frequency components are still dominant although slightly attenuated. The frequencies above the cutoff point remain visible, although also attenuated significantly. The excessive noise that appears in the spectrum may be due to noise in the DAC . . . . . FIR band-pass rectangular window. The case is similar with the high-pass filter, were the low frequency component is still dominant in the signal. The cut-off regions for the filter where 0.16 and 0.24, which gives it a theoretical bandwidth of 0.08 however the frequency at 0.2 seems to have been attenuated rather than allowed to pass through. This may be due to incorrect implementation of the filter loop in the code. . . . . . . . . . . . . . . . . . FIR band-pass rectangular window. Ideally, the frequency at 0.2 should have been attenuated. The opposite effect is the case and this seems to be a trend in the remainder of the filter windows. It is suspected that code responsible for filtering the signal is incorrectly written and therefore the output signals yield an incorrect result. . . . . . . . . . . . . . . . . . . . . . . . . . . . .

68

68

69

69

List of Tables 2.1 4.1

Comparison between analogue and digital filters. . . . . . . . . . . . . . . . FIR rectangular window coefficients generated by the mbed and MATLAB. A side-by-side comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . .

List of Abbreviations

3 70

Acronym Description FPGA CPLD ASIC ARM DSP FIR IIR RAM FM AM ECG ADC DAC RC RCL GUI DC

Field Programmable Gate Array Complex Programmable Logic Device Application Specific Integrated Circuit Advanced RISC Machines Digital Signal Processing Finite Impulse Response Infinite Impulse Response Random Access Memory Frequency Modulation Amplitude Modulation Electrocardiogram Analogue to Digital Converted Digital to Analogue Converter Resistor-Capacitor Resistor-Capacitor-Inductor Graphical User Interface Direct Current

5

1

Introduction

The word filter is commonly used in applications where something must be removed from something else. For example, an air filter removes dust or debris from a vehicles air conditioning system; photographers user filters to block certain wavelength of light from entering the lens. Electric filters are used in similar ways but are designed to allow certain electrical frequencies to pass, while attenuating or completely blocking others [3]. An electric filter is best describes as 4-terminal network [4, 5] that transforms an electrical signal applied to its inputs, such that the output signal has specified characteristics, which may be stated in either the time or frequency domain [6]. An analog electric filter, or just, analog filter, is any filter that operates on continuous variables and is said to be continuous time [7]. Examples of continuous time signals include: ECG’s, music recordings; voltage and current waveforms; speech, acceleration etc [8]. Analog filters are difficult to duplicate and require matched components with tight tolerances; also with time, analog components tend to drift [9] away from their designed specification due to heat or excessive straining [10]. Analog filters, once designed and constructed are difficult to physically modify. Changing a single component could have an adverse effect on its output signal characteristics.. Some filters are bulky by design and could therefore become costly if design changes are necessary in order to change their characteristics. The drawbacks of analog filters call for alternative solutions that are cheaper to implement; have low power consumption; are re-programmable, i.e. can be redesigned, and most importantly produce output signals with desired characteristics. The alternative is digital filtering, but is by no means a complete replacement to analog systems. Digital filters come in two distinct categories: non-recursive and recursive. Non-recursive filters consist of constant coefficients that multiply present and past samples of a signal [11]. A recursive system is a system whose output at any instant depends on a set of values of the input as well as a set of values of the output [12] i.e. it has a feedback loop that send the output signal back into the input signal. There are many names associated with non-recursive filters but the most common is the Finite Impulse Response (FIR) (section: 2.4). The most common name associated with recursive filters is the Infinite Impulse Response (IIR) (section: 2.3) The objective of this project is to implement both IIR and FIR digital filters, but the main challenge is the implementation of these filters in real-time. Real-time in this perspective implies that the characteristics of a filter’s output must be able to change at an instant, when

1

the user so desires. The filters will be divided into four sub-categories called filter responses namely: low-pass, high-pass, band-pass and band-stop. Each response type has its own challenges, all of which will be addressed sections (2.3) and (2.4) for IIR and FIR filters respectively. Each of the different filters will be tested based on the methods discussed in section 3. In this project, these filters will be implemented on the ARM mbed Cortex M3 micro-controller. This micro-controller is deigned with DSP in mind and is therefore a suitable candidate. Its main features include 512KB flash memory, 32KB RAM, up to 100M Hz clock speed, a 3stage pipeline and uses the Harvard architecture with separate instruction/data buses for high speed processing. A feature of importance is the onboard 12 bit analog to digital converter (ADC), which allows for a theoretical maximum sampling rate of 200kHz; this sampling rate is excellent for fast changing signals in real time applications. The micro-controller is programmed using a high level programming language namely C/C++, which gives it an edge over other micro-controllers with regard to ease of use. A list of other features is included in Appendix B. The interface between the user and the mbed will be a simple Windows Forms Application written in C#. The application will serve as a design tool that sends filter specifications to the mbed via a serial port upon the user’s request

2

2

Literature Review

The growth of DSP began in the 19600 s when researchers discovered how to use recursive digital filters to simulate analogue filters [13]. A recursive system is a system whose output at any instant depends on a set of values of the input as well as a set of values of the output [12]. In general, filters are systems that transform the wave shape, amplitude, frequency or phase response of a signal in a required manner. Their main application is to improve signal quality by removing as much much noise as possible, while maintaining signal integrity. Another application is to extract information from combined signals such as frequency modulated (FM) and amplitude modulated (AM) signals and as a result, filters play an important role is DSP. Table 2.1 shows a comparison between analogue and digital filters [14].

Table 2.1: Comparison between analogue and digital filters. Digital Filters High Accuracy Linear Phase (FIR Filters) No Drift Due to Component Variations Flexible, Adaptive Filtering Possible Easy to Simulate and Design Computation Must be Completed in Sampling Period - Limits Real Time Operation Requires High Performance ADC, DAC & DSP

Analogue Filters Less Accuracy - Component Tolerances Non-Linear Phase Drift Due to Component Variations Adaptive Filters Difficult Difficult to Simulate and Design Analog Filters Required at High Frequencies and for Anti-Aliasing Filters No ADC, DAC, or DSP Required

Analogue filters are constructed using a combination of passive components such ResistorCapacitor (RC) and Resistor-Capacitor-Inductor (RCL) networks arranged in either a series or parallel configuration. In this digital age, microprocessors have been employed to perform similar and in some cases better filtering tasks using known filtering algorithms with much higher speeds, accuracy, simplicity of design and reduced overall costs. Digital filter algorithms can perform processes that are difficult or impossible using analogue techniques [15]. Digital filters can be split into two distinct categories Infinite Impulse Response and Finite Impulse Response, each with their own advantages and drawbacks. An issue with analogue techniques is the introduction of phase shifts in the output signal due to memory is passive 3

devices such as capacitors. This means the output value of the signal will be dependent on time as well as the previous value and thus the output will be a moving average of the current and past values. This problem can be mitigated using the FIR filter. The FIR filter is characterised by a unit-sample response that has a finite duration and can be designed with exactly linear phase. Linear phase response is important in applications where degradation in signal quality and integrity occurs due to a nonlinear phase distortion [16]. The most common methods of implementing digital filters are by using general purpose DSP chips for audio applications such as Texas Instruments TMS320, Motorola 56000 and and Analog Devices ADSP-2100 families. These devices are extremely flexible but limited in performance especially at higher operating frequencies [17]. Special purpose Application Specific Integrated Circuits (ASIC) are also used for digital filtering but come at a much higher cost.

2.1

Common Implementation Methods

Field Programmable Gate Arrays (FPGA) have advanced to enable digital filtering implementations at higher sampling rates compared to general purpose DSP chips, lower costs than ASIC for moderate volume and more design flexibility; this does however come at the cost of design complexity [17]. Advanced RISC Machines (ARM) processors are used in many DSP applications including televisions, mobile phones, computers, watches, household appliances, radio equipment, electrochemical sensors [18] and many more. The abundant existence of ARM processors is due to their low cost, high processing power, flexibility and ease of use [19]. Recently, the ARM Cortex M3 processor was combined with an mbed micro-controller to enable applications such as DSP in real time and the implementation of complex control systems. This is the micro-controller that will be used in this project and is shown in figure 2.1.1

4

Figure 2.1.1: ARM mbed Cortex M3 micro-controller along with pin functionality [1]

5

2.2

Review of Analog Filters

This section covers the basics of analog filters used in this project, however before this is done, a basic overview of what the time and frequency domains represent is given followed by the process to convert between them as they play a major role in the design and analysis of filters. 2.2.1

Time & Frequency Domains and Converting Between Them

The time domain is a representation of how the amplitude of a signal changes over time. There a four common ways to define signals in the time domain, two of which are continuous while the other two are discrete. Continuous time signals can be represented by continuous data or differential equations, while discrete time signals are represented by sampled data [20]. It should be noted that continuous time signals are functions of time and as such, have the notation x(t); while discrete time signals are a function of samples and have the notation x[n]. 1. Continuous time Ω with units rads/s x(t) = Acos(Ωt + φ0 ) 2. Continuous time f with units Hz x(t) = Acos(2πf t + φ0 ) 3. Discrete time ω with units rads x[n] = Acos(ωn + φ0 ) 4. Discrete timeas an index  k 2π x[n] = Acos k n + φ0 N The parameter A is the amplitude of a signal at a given point in time and the parameter N determines the interval between possible frequencies [21]. Figures 2.2.1 depicts how these equations are represented visually for simple sine wave.

6

Figure 2.2.1: Top: An illustration of a continuous time 100Hz. The signal is continuous i.e. there are no gaps between points. Bottom: A discrete time signal. The signal is a discrete time waveform of the above continuous signal i.e. it is sampled at intervals The frequency domain is a representation of the range frequency components that a signal is comprised of. Where a time domain signal represents the magnitude of a signal as a function of time, the frequency domain represents the magnitude of a signal as a function of frequency. The conversion between the time domain and frequency domain is performed using the Fourier Transform, formulated by Joseph Fourier in 1822 [22] and is given as follows [23]: Z



x(t)ejΩt dt

X(Ω) =

(2.2.1)

−∞

where ejΩt represents a complex periodic function for a given given frequency and can be represented in the form of sines and cosines using trigonometric identities as follows: ejΩt = cos(Ωt) + jsin(Ωt) Z ∞ therefore, X(Ω) = x(t)(cos(Ωt) + jsin(Ωt))dt −∞

7

(2.2.2) (2.2.3)

Sine is an odd function so integrating it from −∞ to ∞ yields zero [24] and as such, equation 2.2.3 is reduced to Z ∞ Z ∞ jΩt x(t)cos(Ωt)dt (2.2.4) x(t)e dt = X(Ω) = −∞

−∞

To convert back to the time domain, the inverse fourier transform is used as follows: Z ∞ 1 x(t) = X(Ω)ejΩt dΩ (2.2.5) 2π −∞ The fourier transform is applicable to continuous time signals and so for discrete time signals; Discrete Time Fourier Transform (DTFT) used, which is a function of frequency that produces a sum of a continuous fourier transform over a certain period; usually 2π: ∞ X

X(Ω) =

x[n]e−jΩn

(2.2.6)

X(Ω)ejΩn dΩ

(2.2.7)

−∞

and its inverse: 1 x[n] = 2π

Z

8

An example of the DTFT in use is shown in figures 2.2.2 and 2.2.2 below.

Figure 2.2.2: shows three cosine waveforms, 50Hz, 150Hz, 300Hz and combination of all three frequencies in the time domain that will be converted into the frequency domain through a DTFT.

Figure 2.2.3: shows three frequencies 50Hz, 150Hz and 300Hz in the frequency domain after a DTFT. The transform and plots where were obtained with the aid of MATLAB. It is clear from the plots that DTFT separates the time domain signal into its individual frequency components. 9

Although the DTFT is good at converting between time and frequency domains, its inverse is computationally intensive and the performance of a small scale embedded micro-controller will be greatly diminished [25]. An alternative to the DTFT is the Z-Transform, however before exploring the Z-Transform, the Laplace Transform must first by explained and the reason from this is as follows. Recursive filters are usually designed using established analog prototype filters that will be discussed later in this section. As previously mentioned, analog signals are continuous-time based are need to be sampled are regular intervals in order for to be filtered digitally. Analog filters are described using differential equations, while digital filters are described using difference equations, again, the difference being that the former is continuous while the latter is discrete. To better explain the relationship between the time-domain, laplace domain (s-plane) and z-domain (z-plane), the following example is given. A first order analog filter is shown in figure 2.2.4. A first order filter simply means that there is one real component and one reactive component; in this case, a resistor and capacitor for each respective case. In order to avoid going off topic, the laplace transform allows the substitution of s for derivatives and 1/s for integrals, where is is a parameter in the s-plane corresponding to s = jΩ [26].

Figure 2.2.4: A simple analog RC low-pass filter circuit that is used as an example in deriving its transfer function to be used in the digital domain The circuit in figure 2.2.4 is a voltage divider and so the output voltage vo is given by the voltage divider equation: vo = vi

C R+C

(2.2.8)

The time-varying current through a capacitor is proportional to the rate of change of the

10

d voltage across its terminals, thus ic (t) = C vc (t) and the voltage across is given as dt 1 R vc (t) = ic dt. These relationships can be converted to the laplace domain to give: C ic (s) = sCvc (s) 1 and vc (s) = ic (s) sC The reactance of the capacitor is Xc =

(2.2.9) (2.2.10)

vc (s) 1 1 = = . Using the voltage divider in ic (s) sC jΩC

equation above: vo (s) 1/sC = vi (s) R + 1/sC 1 = 1 + sRC

H(s) =

and RC is the time constant τ and a = 1 1 + s/a a = s+a

(2.2.11) (2.2.12) 1 τ (2.2.13)

=

(2.2.14)

Equation 2.2.13 is a transfer function that describes the first order circuit in the s-plane. It is clear that, for differential equations, solving in the laplace-domain is easily done as compared to solving in the time-domain.

As a note, the denominator of a transfer function represent the poles of the system, while the numerator represents the zeros. For a system to be stable, the poles must all be on the left half of the s-plane pole-zero plot [27]. The pole-zero plot for equation 2.2.13 is shown in figure 2.2.5.

11

Figure 2.2.5: Pole-zero plot for the transfer function in equation 2.2.13. The Poles are marked by an ’x’. There is only one pole and it is in the left half of the s-plane, therefore the system is stable

12

The problem remains that this function is still a representation of a continuous time signal. This is where the Z-Transform becomes applicable. The z-plane is related to the s-place by z = eaT , where T is a sampling period [28]. Since there is a pole at s = −a, the digital filter will have a pole at z = e−aT substituting this into equation 2.2.13: 1 z − e−aT 1 =A z−r

H(z) = A

(2.2.15) (2.2.16)

where r = e−aT and A is the gain constant, which can be determined by finding the limit as H(ejΩ ) approaches zero [29]: A − e−aT A = 1 − e−aT A = 1 − e−aT

lim H(ejΩ ) =

Ω→0

therefore H(z) =

ej0

1 − e−aT z − e−aT

(2.2.17) (2.2.18) (2.2.19) (2.2.20)

H(z) is a representation of Y(z)/X(z), where Y(z) is the output of the filter and X(z) is the input of the filter, thus: H(z) =

Y (z) 1 − e−aT = X(z) z − e−aT

(2.2.21)

Y (z)(z − e−aT ) = X(z)(1 − e−aT )

(2.2.22)

Y (z)z − Y (z)e−aT = X(z) − X(z)e−aT

(2.2.23)

Y (z) = Y (z)e−aT z −1 + X(z)z −1 − X(z)e−aT z −1

(2.2.24)

Equation 2.2.24 can now be converted into a difference equation for use in the time-domain as follows: Y (z) = Y (z)e−aT z −1 + X(z)z −1 − X(z)e−aT z −1

(2.2.25)

y[n] = y[n − 1]e−aT + x[n − 1] − x[n − 1]e−aT

(2.2.26)

y[n] = ry[n − 1] − rx[n − 1] + x[n − 1]

(2.2.27)

The final difference equation does not use the input x[n] therefore adding an optional zero at

13

the origin gives: y[n] = ry[n − 1] − x[n](1 − r)

(2.2.28)

in terms of the circuits parameters: vo [n] = rvo [n − 1] − vi [n](1 − r)

(2.2.29)

as the completed conversion of the filter from continuous-time analog domain to discrete-time digital domain.

14

2.3

IIR Digital Filters

IIR filters have a much simpler structure to FIR filters, occupying less storage space, employ high speed DSP with accuracy and better stability at lower orders [30]. An IIR digital filter takes a series of of numbers x(0), x(1), x(2), . . . x(n) as inputs a produces a second series of numbers y(0), y(1), y(2), . . . y(n) as an output. This is what is called a linear time invariant filter [31]. An IIR filter’s outputs depend on the inputs as well as the previous outputs, i.e. it has feedback. The output y(n) at time n does not only depend on the current input x(n) at time n and on previous inputs x(n − 1), x(n − 2), . . . x(n − N ), but also on past outputs y(n − 1), y(n − 2), . . . y(n − M ) [32]. This relationship can be expressed as follows: y(n) = c0 xn + c1 xn−1 + c2 xn−2 + · · · + cN xn−N + d1 yn−1 + d2 yn−2 + · · · + dM yn−M ,

(2.3.1)

where y(n) is the weighted sum of the current input x(n); the N previous inputs and the M previous outputs. ck is the weighted constant of the k th previous input x(n − k). dk is the weighted constant of the k th previous output y(n − k). This can also be written as:

y(n) =

N X

ck xn−k +

k=0

N X

dk yn−k

(2.3.2)

k=1

Equation 2.3.2 is the basic form of a recursive IIR function that will be used in the coming sections to implement recursive functions for various filter types. 2.3.1

Basic Low-pass Filter

A low pass filter allows frequencies below a given cut-off frequency to pass through it, while attenuating the higher frequencies. Given a cut-off frequency Ωc , the pass-band of a low-pass filter will be |Ω| 6 Ωc [23]. A low pass filter, as with other types of filters, can be designed to be an nth order filter. The focus here will be on a first order filter, which means that there is only one pole in the real axis at z = r and one zero at z = −1. The filter of a first order low-pass filter can be expressed as follows: H(z) = A

1 + z −1 z+1 =A , z−r 1 − rz −1

15

(2.3.3)

where A is the normalisation factor chosen such that |H(1)| = 1 and therefore: A=

1−r , 2

(2.3.4)

and r is the normalised value between 0 and 1, representing the location of the pole in a unit circle. For any filter, the frequency response, that is how a filter responds to various frequencies, is the magnitude of H(z) along this unit circle. For a low-pass filter, the frequency response is at a maximum when z = 1 and a minimum when z = −1, which corresponds to a frequency that is half of the sampling frequency, namely the Nyquist Frequency. Using this information, it becomes relatively simple to estimate the frequency response magnitude of a filter by substituting z = ejθ into equation 2.3.3. The substitution is solved to give:   θ (1 − r)cos 2 H(ejθ ) = p 1 − 2rcos(θ) + r2

(2.3.5)

An example of a low-pass frequency magnitude response shown in figure 2.3.1 illustrates that the closer the poles are to the unit circle, the higher the roll-off rate becomes. The parameter θ is a dimensionless frequency representing the size of an angular step along the unit circle.

Figure 2.3.1: Typical frequency response magnitude of a low-pass IIR filter. It is clear that when r is near 1, the pole draws closer to the unit circle and so the response’s rate of roll-off drastically increases.

16

Designing a filter not only requires frequency response characteristics, but also phase and impulse response characteristics. For phase response, an ideal filter will have linear phase in the passband to avoid phase distortion of the signal. The phase response for a low-pass filter is given by equation 2.3.3, which is written in polar form as: H(ejθ ) = H(ejθ ) ejφ ,

(2.3.6)

solving for φ yields: −1

φ = tan



sin(θ) cos(θ) + 1



−1



− tan

sin(θ) cos(θ) − r

 (2.3.7)

Impulse response is how a filter responds to changes in the input signal that contains all possible frequencies; it use allows for an extreme idea of how the system will cope under various frequencies. To obtain the impulse response equation of a filter, a Taylor Series Expansion is performed on H(z) in equation 2.3.3 with z −1 as the variable. Using MATLAB’s Symbolic Math Toolbox, the following expansion is obtained: A + Az(r + 1) + Az 2 (r2 + r) + Az 3 (r3 + r2 ) + . . . ,

(2.3.8)

Substituting z = z −1 yields: A + A(1 + r)(z −1 + rz −2 + r2 z −3 ) . . .

(2.3.9)

From this expansion, the impulse response is determined to be:

hn =

 A,

n=0

A(1 + r)rn−1 , n > 0

(2.3.10)

Now that the frequency response, phase response and impulse response has been determined, all that remains for the low-pass filter is the determination of its recursive function. Recall that H(z) = Y (z)/X(z); Using equation 2.3.3: H(z) =

Y (z) A(1 + z −1 ) = H(z) 1 − rz −1

(1 − rz −1 )Y (z) = A(1 + z −1 )X(z) yn − ryn−1 = A(xn + xn−1 ) yn = ryn−1 + A(xn + xn−1 )

17

(2.3.11) (2.3.12) (2.3.13) (2.3.14)

The recursive function can easily be converted to C code for implementation on the LPC1768 Finally, in order for the filter to remain stable, the location of the pole r must remain inside the unit circle. This can be accomplished by using equation 2.3.5 for a given value of θ. Substituting H(ejθ ) = α and solving for r gives:   √ θ + α 1 − α2 sin(θ) α cos(θ) − cos 2   r= θ 2 2 α − cos 2 2

2

When the cut-off frequency is θ, α = 1/2 and so r = This completes the design of an IIR low-pass filter

18

1 − sin(θ) . cos(θ)

(2.3.15)

2.3.2

Basic High-pass Filter

A high-pass filter allow frequencies above a certain frequency to pass, while attenuating lower frequencies. Given a cut-off frequency Ωc , the pass-band of a high-pass filter will be |Ω| > Ωc [23]. Its design is similar to a low-pass filter but now the location of the zeros and poles have changed in the unit circle. The location of the zero is at z = 1 i.e. θ = 0 and the location of the pole is at z = r. The process for determining the frequency response for the high-pass filter is the same as the low-pass filter. The transfer function is given by: H(z) =

A(1 − z −1 ) A(z − 1) = z−r 1 − rz −1

(2.3.16)

where A is a constant chosen such that |H(−1)| = 1, therefore: A=

1+r 2

(2.3.17)

Substituting z = ejθ into equation 2.3.16 gives the frequency response of:   θ (1 + r)sin 2 H(ejθ ) = p 1 − 2rcos(θ) + r2

(2.3.18)

It can be seen from figure 2.3.2 that as the poles become closer to the unit circle, the rate at which the lower frequencies are attenuated increases.

19

Figure 2.3.2: Typical frequency response magnitude of a high-pass IIR filter. Similar to its low-pass counterpart, the rate at which higher frequencies are attentuated, greatly depends on the how close the poles are to the unit circle. Converting equation 2.3.18 to polar form to find the phase response as shown in equation 2.3.6 yields: −1

φ = tan



sin(θ) cos(θ) + 1



−1

− tan



sin(θ) cos(θ) − r

 (2.3.19)

The impulse response of the filter can be determined by taking the Taylor Expansion Series of equation 2.3.16, which is found to be: A + Az(r − 1) − Az 2 (r2 − r) − Az 3 (r3 − r2 ) + . . . ,

(2.3.20)

Substituting z = z −1 gives: A + A(1 + r)(z −1 + rz −2 + r2 z −3 ) . . . ,

(2.3.21)

and finally the impulse response becomes:  A, n=0 hn = A(1 − r)rn−1 , n > 0

(2.3.22)

From the impulse response and using equation 2.3.16, the recursive equation for the high-pass 20

filter becomes: yn = ryn−1 + A(xn − xn−1 )

(2.3.23)

For a magnitude H(ejθ ) = α, solving for r yields:   √ θ α cos(θ) + sin − α 1 − α2 sin(θ) 2   r= , θ 2 2 α − sin 2 2

2

(2.3.24)

and at a cut-off frequency θ, α = 1/2, reducing r to: r=

1 − sin(θ) cos(θ)

This completes the design of an IIR high-pass filter.

21

(2.3.25)

2.3.3

Basic Band-pass Filter

A band-pass filter allows frequencies between two cut-off points to pass, while attenuating those outside that range. Given a lower cut-off frequency Ωc1 and an upper cut-off frequency Ωc2 the pass-band of a band-pass filter will be Ωc1 6 |Ω| 6 Ωc2 [23]. For a band-pass filter, two poles and zeros are needed. The location of the zeros is at z = 1 and z = −1, while the poles are given by: z = ±r(cos(θ) + jsin(θ), Using Euler’s Identity, this can be written as: z = re±jθ

(2.3.26)

From this information, the transfer function can be determined to be: H(z) =

=

A(z − 1)(z + 1) (z − rejθ )(z − re−jθ ) A(1 − z −2 ) 1 − 2rz −1 cos(θ) + r2 z −2

(2.3.27)

The filter is normalised such that the magnitude is 1 at θ: 2Asin(Ω) H(ejΩ ) = p (1 − 2rcos(Ω − θ) + r2 )(1 − 2rcos(Ω + θ) + r2 )

(2.3.28)

and, p (1 − r) 1 − 2rcos(2θ) + r2 A= 2sin(θ)

(2.3.29)

Figure 2.3.3 depicts the frequency response magnitude of the band-pass filter. Just like the low-pass and high-pass filters, the closer the poles are to the unit circle, the steeper the slope becomes

22

Figure 2.3.3: Typical frequency response magnitude of a band-pass IIR filter. The pass-band bandwidth in this example was set to π/5. Performing a Taylor Series Expansion on equation 2.3.27 gives the following impulse response:

hn =

  A,     A

n=0

rsin(2θ), n=1 sin(θ)    A   (rn sin(n + 1)θ − rn−2 sin(n − 1)θ), n > 2 sin(θ)

(2.3.30)

This produces the following recursive equation for the band-pass filter: yn = 2rcos(θyn−1 ) − r2 yn−2 + A(xn − xn−2 )

(2.3.31)

The location of the poles in a band-pass filter is r = (1 − B), where B = (Ω − θ). Ω and θ are the upper and lower cut-off frequencies respectively. This completes the design of an IIR band-pass filter

23

2.3.4

Basic Band-Stop Filter

A band-stop filter attenuated frequencies between two cut-off points and allows frequencies outside this range to pass. Given a lower cut-off frequency Ωc1 and an upper cut-off frequency Ωc2 the pass-band of a band-stop filter will be Ωc1 6 |Ω| 6 Ωc2 [23]. Similar to a band-pass filter two zeros at z = e±jθ and two poles at z = re±jθ . The transfer function is as follows: H(z) =

=

A(z − ejθ )(z − e−jθ ) (z − rejθ )(z − re−jθ ) A(1 − 2z −1 cos(θ) + z −2 ) 1 − 2rz −1 cos(θ) + 2r2 z −2

(2.3.32)

The filter is normalised such that the magnitude is 0 at θ thus:   sin Ω−θ sin Ω+θ 4A 2 2 H(ejΩ ) = p (1 − 2rcos(Ω − θ) + r2 )(1 − 2rcos(Ω + θ) + r2 )

(2.3.33)

Figure 2.3.4 depicts the frequency response magnitude of the band-pass filter. Just like the low-pass and high-pass filters, the closer the poles are to the unit circle, the steeper the slope becomes

24

Figure 2.3.4: Typical frequency response magnitude of a band-stop IIR filter. The pass-band bandwidth in this example was also set to π/5. As r approaches 1, the response becomes steeper and better attenuates unwanted frequencies. Using equation 2.3.32, the impulse response is given by: yn = 2rcos(θyn−1 ) − r2 yn−2 + A(an − 2cos(θxn−1 ) + xn−2 )

(2.3.34)

The location of the poles is similar to that of the band-pass filter, where r = (1 − B) and B = (Ω − θ), where Ω and θ are the upper and lower cut-off frequencies respectively. This completes the design of an IIR band-stop filter

25

2.3.5

The Bilinear Transform

The bilinear transform is a method of transforming an analog filter into a digital filter by providing 1-1 mapping from the analog s-plane to the digital z-plane. The definition of the bilinear transform is given as [32]: s=K

z−1 , z+1

(2.3.35)

where K = 2/T and T is the sampling period. Frequencies in the analog domain are represented by s = jΩ, while frequencies in the digital domain are represented by z = ejθ . In order the convert from analog to digital and vice versa, s and z are substituted into equation 2.3.35 to produce [33]: jΩ = K

ejθ − 1 ejθ + 1

(2.3.36)

With the aid of MATLAB’s Symbolic Math Toolbox, this reduces to:   θ jΩ = jKtan 2   θ Ω = Ktan 2

(2.3.37) (2.3.38)

With this equation, conversion between analog and digital is possible but due to a concept called frequency warping, the mapping becomes non-linear as frequencies approach the Nyquist Frequency. The compensate for this, a procedure known as pre-warping is performed. In the digital domain, the angle θ is related to the digital frequency ω by θ = ωT so equation 2.3.39 can be written as [34]:  ωT Ω = Ktan 2   ΩT −1 and ω = 2tan 2 

(2.3.39) (2.3.40)

With equation 2.3.39, the mapping between analog frequencies and digital frequencies can be done without worrying about frequency warping.it is now possible to convert analog frequencies into digital frequencies and vice versa without any frequency distortion.

26

2.3.6

Converting Analog Prototypes Into Digital Filters - Obtaining Filter Coefficients

In this project, only even order IIR filters are discussed because they are more practical to implement programmatically. For this reason, the following sections will focus only on the implementation of even order filters, in particular second order filter. Second order filters can be easily cascaded together to form high order filters. The order of an IIR filter determines the steepness of the frequency magnitude response. Using the bilinear transform method mentioned in the previous chapter, it is now possible to convert established analog filters into their respective digital form. This chapter will discuss the Butterworth and Chebyshev approximations. 2.3.6.1

Butterworth Approximation

The Butterworth filter is commonly known as a maximally flat filter [35]. This is because its frequency response is flat in the pass-band and stop-band regions i.e. there is no ripple. The pass-band is area on the magnitude frequency response where frequency can pass through a filter unattenuated. The process of converting an analog Butterworth filter into its digital form is relatively simple and will be discussed in this chapter. The Butterworth approximation filter was designed by Prof. Stephen Butterworth in 1930. The approximation, for a low-pass filer assumes that all zeros are at infinity and so the magnitude frequency response can be written as: A |H(s)| = p 1 + f (Ω2 )

(2.3.41)

where A is a the gain at when Ω = 0. The polynomial f (Ω2 ) is selected to give the desired  2n Ω 2 magnitude response, and it was suggested by Butterworth to select a value of f (Ω ) = , Ω0 where n is the filter order. Let K = 1 so: 1 

|H(s)| = s 1+

Ω Ω0

2n

(2.3.42)

The response was then normalised by assuming Ω0 = 1 thus: |H(s)| = √

27

1 1 + Ω2n

(2.3.43)

This function is called the nth order Butterworth response. Its properties include: 1. For any value n at Ω = 0, the magnitude response is given by: |H(j0)| =

1 = 1, for all n 1 + (0)2n

(2.3.44)

2. For any value n at Ω = 1, the magnitude response is given by 1 1 1 = √ = 0.707, for all n |H(j0)| = p =p 2 1 + (1)2n (1 + 1)

(2.3.45)

Thus the normalised cut-off frequency for any order filter was Ω = 1[36, 37]. This means that the cut-off frequency will always be at Ω = 1 with an attenuation of 0.707 of the input signal The first step of conversion is to obtain the analog transfer function of the filter and substitute it into the bilnear equation 2.3.35. The simplest even order filter is of second order and has the following transfer function that can be derived from the above equations [16, 37]:

1 1 + Ω2n 1 N (s) therefore |H(s)|2 = = 1 + Ω2n D(s) |H(s)| = √

(2.3.46) (2.3.47)

The poles are obtained by setting D(s) = 1 + Ω2n = 0: s = jΩ therefore Ω =

s j

(2.3.48)

Substituting back into the above equation:  2n 2 1+ =0 j

(2.3.49)

1 + (−s2 )n = 0,

(2.3.50)

then the pole locations for the magnitude response is found to be:  pk = −sin

π(2k + 1) 2n



28

 + jcos

π(2k + 1) 2n

 (2.3.51)

The Butterworth system function can then be written as: Gn (s) =

n Y

1 s − pk k=0

(2.3.52)

and since poles always come in complex conjugate pairs the above system function can be rewritten as: Hn (s) =

1 Gn (s)

(2.3.53)

where, Gn (s) =

((n−2)/2 Y

s2 + 2rk s + 1 n = 2, 4, 6, 8, . . .

k=0

29

(2.3.54)

With all the given information, it is now possible to produce a second order low-pass filter. To convert a low-pass filter with a cut-off Ω, s is substituted as s/Ω into equation 2.3.53 and the, bilinear transform is substituted into the result [38]: s→

s Ω

(2.3.55)

z−1 z+ 1  s= ωT Ktan 2 K

z−1  ωT tan (z + 1) 2 1z−1 s= γz+1

s=



(2.3.56)

(2.3.57)

(2.3.58)

where γ = tan(ωT /2). Substituting equation 2.3.58 into Hn (s) yields: γ 2 (z + 1)2 1 → 2 s2 + 2rs + 1 (γ + 2γr + 1)z 2 − 2(1 − γ)2 z + (γ 2 − 2γr + 1)

(2.3.59)

The coefficients of this filter can then be determined to be:

γ2 γ 2 + 2γr + 1

(2.3.60)

2(1 − γ)2 c0 = 2 γ + 2γr + 1

(2.3.61)

γ 2 − 2γr + 1 γ 2 + 2γr + 1

(2.3.62)

Gain =

c1 =

To obtain the high-pass digital filter, the substitution in equation 2.3.55 is flipped and the

30

same process is followed through. The produces the following second order high-pass filter: 1 (z − 1)2 → , s2 + 2rs + 1 (γ 2 + 2γr + 1)z 2 − 2(1 − γ)2 z + (γ 2 − 2γr + 1)

(2.3.63)

with the coefficients determined as: 1 + 2γr + 1

(2.3.64)

c0 =

2(1 − γ)2 γ 2 + 2γr + 1

(2.3.65)

c1 =

γ 2 − 2γr + 1 γ 2 + 2γr + 1

(2.3.66)

Gain =

γ2

For a band-pass filter, the upper and lower cut-off frequencies each require a set of second order filters. First, s is substituted as: s→

(s2 + ωu ωl ) (ωu − ωl )s

(2.3.67)

where ωu and ωl are the upper and lower cut-off frequencies respectively. The bilinear transform is then substituted into equation 2.3.67 to give: s=

z 2 − 2az + 1 b(z 2 − 1)

(2.3.68)

where, 

 θu + θl cos 2   γ1 = θu − θl cos 2   θu − θl γ2 = tan 2 with θu = ωu T and θl = ωl T [32].

31

(2.3.69)

(2.3.70)

Substituting equation 2.3.68 into Hn (s) for n = 2 (second order), yields:

s2

1 → + 2rs + 1

γ2 (z 2 − 1)2 (γ22 + 2γ2 r + 1)z 4 − 4γ1 (1 + γ2 r)z 3 − 2(γ22 − 2γ12 − 1)z 2 − 4γ1 (1 − γ2 r)z + γ22 − 2γ2 r + 1 (2.3.71) with the coefficients determined as: Gain = c0 = c1 = c2 = c3 =

γ2 + 2γ2 r + 1 4γ1 (1 + γ2 r) γ22 + 2γ2 r + 1 2(γ22 − 2γ12 − 1) γ22 + 2γ2 r + 1 4γ1 (1 − γ2 r) γ22 + 2γ2 r + 1 γ22 − 2γ2 r + 1 γ22 + 2γ2 r + 1 γ22

(2.3.72) (2.3.73) (2.3.74) (2.3.75) (2.3.76)

Finally for a band-stop filter, the substitution in equation 2.3.67 in flipped and the same process for the band-pass filter in followed to produce the band-stop filter:

s2

1 → + 2rs + 1

(z 2 − 2γ1 z + 1)2 (γ22 + 2γ2 r + 1)z 4 − 4γ1 (1 + γ2 r)z 3 − 2(γ22 − 2γ12 − 1)z 2 − 4γ1 (1 − γ2 r)z + γ22 − 2γ2 r + 1 (2.3.77)

32

with the coefficients determined as: Gain = c0 = c1 = c2 = c3 =

1 + 2γ2 r + 1 4γ1 (1 + γ2 r) γ22 + 2γ2 r + 1 2(γ22 − 2γ12 − 1) γ22 + 2γ2 r + 1 4γ1 (1 − γ2 r) γ22 + 2γ2 r + 1 γ22 − 2γ2 r + 1 γ22 + 2γ2 r + 1 γ22

(2.3.78) (2.3.79) (2.3.80) (2.3.81) (2.3.82)

This completes the Butterworth approximation for even order low-pass, high-pass, band-pass and band-stop IIR filters. Using the equations mentioned in this chapter, it is possible to compute the coefficients of the desired filter: given a response type; cut-off frequency and order. These equations will be the basis of the code that will be used to program the LPC1768 and since the equations of the coefficients are present, it allows for changes of the desired filter specifications in real-time.

33

2.3.6.2

Chebyshev Approximation

Chebyshev filters are derived in a similar way to Butterworth filters but their frequency responses greatly differ. Where a Butterworth filter has a maximally flat response in the passband region, the Chebyshev filter introduces some ripple to allow for a steeper roll-off at the cut-off frequency [39]. The frequency response of a Chebyshev is given by [40]: |Hn (jω)|2 =

1 1+

2 F

n (ω

2)

(2.3.83)

where  is the parameter that controls the ripple size and Fn is the order of the Chebyshev polynomial. These polynomials are defined using the recurrence equation as follows [41]: T0 (x) = 1 T1 (x) = x Tn (x) = 2xTn−1 (x) − Tn−2 (x)

(2.3.84)

This recurrence equation can be used to implement higher order polynomials and a table of these polynomials can be found in the (APPENDIX SECTION). From the table, it can be seen that, Tn (ω) is a polynomial of order n and when n is even, Tn (ω) is a polynomial of ω 2 . For this project, only even order polynomials are considered, which means the square of Tn (ω) must be used. Setting Fn (ω 2 ) = Tn2 (ω) results in the following equation for the frequency response: |Hn (jω)|2 =

1 1+

2 Tn2 (ω)

(2.3.85)

To obtain a digital Chebyshev filter, the poles must first be located. This is accomplished by substituting ω = −js into equation 2.3.85, which yields (REF2):  sk = −sin

   (2k − 1)π sinh−1 (1/) sinh + n n     (2k − 1)π sinh−1 (1/) + jcos cosh 2n n

(2.3.86)

for k = 1, 2, 3, . . . n. The system function can be written in terms of the poles: Gn (s) =

1 2n−1 

34

n Y

1 s − sk k=1

(2.3.87)

Grouping the complex conjugate pairs, the system function becomes: Hn (s) =

1 , n = 1, 2, 3, . . . n Gn (s)

(2.3.88)

and, Gn (s) =

( n/2 Y

s2 + 2rk s + ck

n = 2, 4, 6, 8, . . .

(2.3.89)

k=1

where, rk =