• No results found

SOFTWARE IMPLEMENTATION OF DIGITAL FILTERS

N/A
N/A
Protected

Academic year: 2021

Share "SOFTWARE IMPLEMENTATION OF DIGITAL FILTERS"

Copied!
29
0
0

Loading.... (view fulltext now)

Full text

(1)

MEE 0828

SOFTWARE IMPLEMENTATION

OF DIGITAL FILTERS

Satish kumar Are

Manoranjan Reddy Thangalla

Saikrishna Gajjala

This thesis is presented as part of Degree of

Master of Science in Electrical Engineering

Blekinge Institute of Technology

August 2008

Blekinge Institute of Technology School of Engineering

Department of Signal Processing Supervisors: Nedelko Grbic

(2)
(3)

3

ABSTRACT

This thesis proposes to create a MATLAB GUI (Graphical User Interface) to replace an existing laboration exercise in signal processing at Blekinge Institute of Technology. MATLAB is a matrix-based technical computing language widely used throughout the scientific, engineering and mathematical communities. A GUI provides a graphical interface between the program and the user, facilitating ease and frequency of use. Development of a MATLAB GUI for this laboration exercise will benefit the students and increase the awareness towards designing of digital filters.

(4)
(5)

5

ACKNOWLEDGMENTS

(6)

6

Table of Contents

Introduction ... 7

Chapter 1: DIGITAL FILTERS ... 8

1.1 Background ... 8 1.2 FIR filters ... 9 1.3 Types of windows ... 10 1.3.1 Rectangular window ... 10 1.3.2 Bartlett window ... 11 1.3.3 Hanning window ... 12 1.3.4 Hamming window... 13 1.3.5 Blackman window ... 14 1.4 Design considerations ... 15 1.5 Observations ... 16 1.6 IIR filters... 17 1.6.1 Bilinear transformation ... 17 1.6.2 Butterworth approximation ... 17 1.6.3 Chebyshev approximation ... 18 1.7 Design considerations ... 19 1.8 Observations ... 20

Chapter 2 : Developed Software ... 21

2.1 Digital filter software GUI ... 21

2.1.1 Filter selection panel ... 22

2.1.2 Input Selection panel ... 22

2.1.3 Filter specifications panel ... 23

2.2 Digital filter analysis ... 24

2.2.1 Plot panel ... 24

2.2.2 Pole/zero plot ... 25

Conclusion ... 26

Appendix ... 27

(7)

7

Introduction

Existing problem

For analysis of digital filters, DOS based software was developed years back at Blekinge Institute of Technology for students of signal processing. However, this software have drawbacks such as portability, inefficient use of computer resources, less accessibility and bulk hardware system due to floating point DSP which requires extra hardware for floating point operations. The developed software has some constraints as it is not user friendly.

Possible solution

(8)

8

Chapter 1: Digital Filters

1.1

Background

The term ‘filter’ is frequently used in signal processing. A filter is a frequency selective device that removes unwanted information from the original message signal. Unwanted signals can be noise or other undesired information. Digital filters are more versatile when compared to the analog filters in their characteristics such as programming flexibility, ability to handle both low as well as high frequency signals accurately. Also the hardware requirement is relatively simple and compact. In real world signals are analog in nature. A simple signal flow block diagram that explains how the signal is processed to acquire desired output signal is shown in figure 1.1.

unfiltered sampled digitally filtered analog digitised filtered analog signal signal signal signal

Figure 1.1: Signal flow block diagram.

Analog to digital conversion is an engineering process that enables digital processor to interact with real world signals. The input to the processor should be properly sampled and quantized. Sampling and quantization restrict the amount of information a digital signal contain. In the figure 1.1 an interface is provided between analog signal and the digital signal processor called analog to digital converter (ADC). The output from ADC is input to the processor. In applications output from the processor is to be given to user in analog form such as speech communications, for this an interface is provided from digital domain to the analog domain. This interface is called digital to analog converter (DAC). Thus the signal is provided in analog for to the user as shown in figure 1.1. The processor in figure 1.1 can be anywhere from a large programmable digital computer to a small microprocessor which contains digital filters.

(9)

9

The digital filters are two types based on their impulse response; finite impulse response (FIR) and infinite impulse response (IIR) filters. FIR filters have same time delay for all frequencies (linear phase), relatively insensitive to quantization and are always stable. FIR filters can be designed in different ways, for example window method, frequency sampling method, weighted least squares method, minimax method and equiripple method. Out of these methods, the window technique is most conventional method for designing FIR filters.

1.2

FIR filters

A finite impulse response filter of length  with input  and output  is described by the difference equation

 =   +   −  + ⋯ +   −  +  =  

 

 − 

where  is the set of filter coefficients. The transfer function of this filter in  domain can be represented as

 =   





A window in filter design provides trade off between resolution that is the width of the peak and spectral leakage that is the amplitude of the tails of desired impulse response. The desired frequency response specification for linear phase filter is the Fourier transform of the desired impulse response, and this can be represented as

 =   



 and the inverse as

 =    

 

 

(10)

10

performed by multiplying desired sample response with a window function in time domain which gives sample response of filter represented as

 = 

where  is a window function. Various types of windows were used when designing the FIR filters.

1.3

Types of Windows

1.3.1 Rectangular window

The rectangular window has excellent resolution characteristics for signals of comparable strength. The rectangular window is defined as

 =  , , !"# $ = 0,1,2, … ) − 1*+,*-ℎ*#* /

The frequency response of the window function is the Fourier transform which, is defined as

0 =   



 The amplitude response of the rectangular window function is

|0| = |234/||234/| , − ≤  ≤  and the phase response is

7 = 8− 9  −

 :, 234 9 : ≥ − 9 −  : + , 234 9 : < 0 /

(11)

11 Figure 1.2: Frequency response for Rectangular window.

Figure 1.3: Lowpass FIR filter designed with Rectangular Window.

1.3.2 Bartlett window

A Bartlett window is a triangular shaped window function. The Bartlett window has higher side lobe attenuation than the rectangular window. The Bartlett window is defined as

 = − = −  −  −  = 

The frequency response for Bartlett window is shown in figure 1.4 and figure 1.5 shows the frequency response of a lowpass FIR filter designed using Bartlett window.

(12)

12 Figure 1.4: Frequency response for Bartlett window.

Figure 1.5: Lowpass FIR filter designed with Bartlett Window.

1.3.3 Hanning window

The Hanning window is a raised cosine window and can be used to reduce the side lobes while preserving a good frequency resolution compared to the rectangular window. It is commonly used as general purpose window for the analysis of continuous signals. The Hanning window is defined as

(13)

13

The frequency response for Hanning window is shown in figure 1.6 and figure 1.7 shows the frequency response of a lowpass FIR filter designed using Hanning window.

Figure 1.6: Frequency response for Hanning window.

Figure 1.7: Lowpass FIR filter designed with Hanning Window.

1.3.4 Hamming window

The Hamming window is, like the Hanning window, also a raised cosine window. The Hamming window exhibits similar characteristics to the Hanning window but further suppress the first side lobe. The Hamming window is defined as

(14)

14

The frequency response for Hamming window is shown in figure 1.8 and figure 1.9 shows the frequency response of a lowpass FIR filter designed using Hamming window.

Figure 1.8: Frequency response for Hamming window.

Figure 1.9: Lowpass FIR filter designed with Hamming Window.

1.3.5 Blackman window

The Blackman window is similar to the Hanning and the Hamming windows. An advantage with the Blackman window over other windows is that it has better stopband attenuation and with less passband ripple. The Blackman window is defined as

(15)

15

 = . B − . ? @A2 − + . D @A2  − B

The frequency response for Blackman window is shown in figure 1.10 and figure 1.11 shows the frequency response of a lowpass FIR filter designed using Blackman window.

Figure 1.10: Frequency response for Blackman window.

Figure 1.11: Lowpass FIR filter designed with Blackman Window.

1.4

Design considerations

A design consideration when designing digital FIR filter is selecting a window. This can be done with the help of frequency specifications of the required filter. In general, the frequency

(16)

16

specification consists of pass and stopband cutoff frequencies and attenuations. The length of the filter can be determined by the main lobe width.

Table 1 shows the side lobe attenuation and main lobe width for different windows. Table 2 shows the desired impulse response functions for various filters. Specifically, stopband attenuation provides for a user to select an appropriate window.

Window Side lobe attenuation Approximate Main lobe width

Rectangular -20dB 4F )⁄

Bartlett -27dB 8F )⁄

Hanning -40dB 8F )⁄

Hamming -50dB 8F )⁄

Blackman -70dB 12F )⁄

Table 1: Comparison of main lobe width and side lobe attenuation for different window

types.

Filter Type Desired impulse response I

Lowpass JK F ∙ sin JKP$ − Q) − 12 RS JKP$ − Q) − 12 RS Highpass T P$ − 9) − 1 2 :S −JF ∙K sin JKP$ − Q) − 12 RS JKP$ − Q) − 12 RS Bandpass 2 cos WJKP$ − 9) − 1 2 :SX ∙JF ∙K sin JKP$ − Q) − 12 RS JKP$ − Q) − 12 RS Bandstop T P$ − 9) − 1 2 :S − 2 cos WJKP$ − 9) − 12 :SX ∙JF ∙K sin JKP$ − Q) − 12 RS JKP$ − Q) − 12 RS

Table 2: Desired impulse responses for filter types.

1.5

Observations

(17)

17

sidelobes, thereby increase in the width of the transition band of the lowpass FIR filter as shown in Figures 1.3, 1.5, 1.7, 1.9 and 1.11.

1.6

IIR filters

Impulse response functions of IIR filters are non-zero over an infinite length of time. IIR filters can be described using a difference equation as

 =  Y  Y  − Y −  Z [   − 

where Y and Z are the filter coefficients. The transfer function of IIR filters can be expressed as

 =

+ ∑ Z

∑ 

Y Y



Y

 [







These filters can be designed by the bilinear transformation method. These filters are designed using their analog counterparts rather than discrete time analysis.

1.6.1 Bilinear transformation

The bilinear transformation method is commonly used in designing digital IIR filters to obtain filter coefficients. As mentioned in section 1.6, digital filters are designed with their analog counterparts, so it must be transformed into discrete time domain. This transformation can be done with the bilinear transform.

] = ^ P −  +   S

1.6.2 Butterworth approximation

The amplitude response of a Butterworth filter is given as

|Ω| = _

` + 9 Ω a:

[

(18)

18 Figure 1.12

Ω] is the stopband frequency shown in the figure 1.12.The filter order [ can be approximated as [ = bAc de` f  − g /hi bAc 9Ω] Ωa:

where h is the filter parameter which determines the band edge value of |kΩ| and f is the maximum allowed value for the amplitude function at the stopband edge.

f= |Ω]|lmn The system transfer function in polynomial form is given by

] = _ 9 ] a: [ + Z[ 9 ]a: [ + ⋯ + Z 9 ]a: + The Butterworth filter coefficients Zo are provided in appendix table A.

1.6.3 Chebyshev approximation

The amplitude response of a Chebyshev filter is given by

|Ω| = _

(19)

19 Figure 1.13

Figure 1.13 gives us the specifications for order of the Chebyshev filter, where the ripple is defined as pYaaq = ∙ bAc + h dB and _ is the maximum value of the amplitude function, ^[9Ω

Ωa: is the Chebyshev polynomial. The required filter order can be

approximated as [ = tu] v w w x y z z z z {` f  − h | } } } } ~  € €  tu] 9Ω] Ωa:

where h is the filter parameter related to ripple in the passband and f is the maximum allowed stopband ripple. The system transfer function in polynomial form is given by

] = _ ∙ Z ∙ ‚ [ u √ + h [ „ / 9 ] a: [ + Z[ 9 ]a: [ + ⋯ + Z

The Chebyshev filter coefficients Zo are provided in appendix tables B1, B2, B3 and B4.

1.7

Design considerations

(20)

20

technique called “pre-warping” is used to map digital frequencies into analog frequencies. The warping frequencies are given by

a=  …m4 Q Ra Ω] =  …m4 Q R]

where a and ] angular frequencies of pass and stop bands of digital filters. After “pre warping” frequency transformation is needed for highpass, bandpass and bandelimination filters shown in table 3.

Filter Frequency Transformation

Highpass ‡ˆ= ‰ Š‹ and ‡Œ= ‰ Š Bandpass ‡ˆ= Ωˆ Ž− Ωˆ and ‡Œ = ΩŒŽ− ΩŒ , ΩˆŽ∙ Ωˆ= ΩŒŽ∙ ΩŒ = ِ‘ Bandelimination ‡ ˆ= Š’ Ž Š‹Ž‹ and ‡Œ= Š’Ž ŠŽ , ΩˆŽ∙ Ωˆ = ΩŒŽ∙ ΩŒ= ِ‘ Table 3: Transform to frequencies of lowpass filter.

After the frequency transformation, the designed lowpass filter is transformed into the desired filter type according to the table 4.

LP HP BP BS ] ] ] +Ω“  ] Ω“  ] + Ω“ ]

Table 4: Transform back to original filter (HP, BP, BS) from lowpass filter.

1.8

Observations

(21)

21

Chapter 2: Developed software

2.1

Digital Filter Software GUI

A digital filter software GUI is shown in figure 2.1 for design and analysis of digital filters. The developed filter software GUI consists of the following parts.

 Filter selection panel  Input selection panel  Filter specifications panel

 A panel for different plots for analysis  A button to display the pole/zero  A button to exit the GUI

(22)

22

2.1.1 Filter Selection Panel

The user can choose to design and analyze a FIR or IIR digital filter.

2.1.2 Input Selection Panel

The input selection panel consists of settings for the input signal to the digital filter. These specifications are input signal type, sampling rate and frequency of the signal which are essential to the analysis of the digital filters.

I. Input

In the Input dropdown list, different types of input signal types can be selected. The signal types are sine wave, square wave, sawtooth wave and white Gaussian noise. The different signal types are shown in figure 2.2.

(23)

23

II. Sampling Frequency

The sampling rate is the rate at which the input signal for the filter is sampled. For perfect reconstruction of a signal the sampling rate should be greater than twice the maximum frequency of the signal being sampled.

III. Frequency

The frequency determines the number of cycles per unit time of a signal. As the frequency increases the number of cycles of the input wave also increases. The range of the frequency is from 0 to Q”‹

‘R − 1 which can be adjusted with the help of a slider and edit box where the user can directly enter the desired frequency.

2.1.3 Filter specifications panel I. Filter Type

The user can create lowpass, highpass, bandpass and bandstop. These filters types can be selected from the dropdown list in the Input selection panel.

II. Filter Order

The filter order mainly determines the width of the transition band. The higher the order, the narrower is the transition between the passband and stopband, giving a sharper cutoff in the frequency response. This can be clearly observed in figure 2.3 for orders of 9, 15 and 31.The transition bandwidth can be improved by increasing the order of the filter. The filter order can be adjusted between 0 to 31. The filter order can be adjusted by setting the slider or entering the value in edit box.

(24)

24

III. Cut off frequencies

Cutoff frequency is the frequency where the filter is designed to cross over from the passband to the stopband. The cutoff frequency can be adjusted by setting the values of sliders or entering the values in the edit box. The cutoff frequencies are in the range from 0 to Q•,

2R− 1 .

A single cutoff frequency is available for lowpass and highpass filters where as for bandpass and bandstop two cutoff frequencies are available.

2.2

Digital filter analysis

After designing a digital filter, the filters can be analyzed by selecting different input signals and examining the filter and filter response in different plots.

2.2.1 Plot Panel

The plot panel consists of three dropdown lists. The dropdown lists presents options for displaying input and output signals in time domain, linear and logarithmic FFT plots, and linear and logarithmic filter amplitude responses.

Dropdown list

 Time x: shows the input signal in time domain  Time y: shows the filtered signal in time domain

 Time x+y: shows the input and output on top of each other in time domain  FFT linear x: shows the amplitude of the FFT of the input signal in linear scale.  FFT linear y: shows the amplitude of the FFT of the output signal in linear scale.  FFT linear x+y: shows the amplitude of the FFT of the input and output signal on top

of each other in linear scale.

 FFT logarithmic x: shows the amplitude of the FFT of the input signal in logarithmic scale.

 FFT logarithmic y: shows the amplitude of the FFT of the output signal in logarithmic scale.

 FFT logarithmic x+y: shows the amplitude of the FFT of the input and output signal on top of each other in logarithmic scale.

 FFT linear h: shows the FFT of impulse response in linear scale.

 FFT logarithmic h: shows the FFT of impulse response in logarithmic scale.

(25)

25

frequency response function, completely characterizes the system. Once the system frequency response is known, one can predict how that system will react to any waveform.

2.2.2 Pole/zero Plot

A pole/zero plot is the graphical representation of the transfer function in the complex Z plane which helps to convey properties of the system such as stability, causality, minimum phase and region of convergence.

A linear time invariant system is said to be minimum phase if the system and its inverse are stable and casual. For a system to be minimum phase all its poles and zeros must be inside the unit circle. The user can determine whether a digital filter is stable that is output of digital filter is bounded for all possible bounded inputs. It is known that for IIR filters to be stable is that all its poles lie inside unit circle where as for FIR filters all its poles lie inside unit circle.

Figure 2.4: A simple pole/zero plot.

(26)

26

Conclusion

This Master thesis report presents a software implementation of digital filters using Matlab GUI in a user friendly environment. The developed software is useful for aspirant students in designing and analysis of the digital filters. The software consists of radio buttons, pop-up menus, sliders, edit boxes, axes, push buttons and list boxes all these are placed in different panels and all are working properly. The evaluated performance using the specific theoretical filter parameters match the performance with the software. The software is working properly towards accurate results upon manual testing.

(27)

27

Appendix

Table A: Coefficients Zo in Butterworth polynomials.

[ Z Z Z– ZB Z? ZC Z—  √2 – 2 2 B 2.613 3.141 2.613 ? 3.236 5.236 5.236 3.236 C 3.864 7.464 9.141 7.464 3.864 — 4.494 10.103 14.606 14.606 10.103 4.494 D 5.126 13.138 21.848 25.691 21.848 13.138 5.126

Table B1: Chebyshev filter coefficients Zo.

0.5ž #Ÿ  +*¡ = 0.349, ¡‘ = 0.122. [ Z Z Z Z– ZB Z? ZC Z— 2.863  1.516 1.426 – 0.716 1.535 1.253 B 0.379 1.025 1.717 1.197 ? 0.179 0.752 1.309 1.937 1.172 C 0.095 0.432 1.172 1.589 2.172 1.159 — 0.045 0.282 0.756 1.648 1.869 2.413 1.151 D 0.024 0.152 0.573 1.148 2.184 2.149 2.657 1.146

Table B2: Chebyshev filter coefficients Zo.

(28)

28 Table B3: Chebyshev filter coefficients Zo.

2ž #Ÿ  +*¡ = 0.765, ¡‘ = 0.585. [ Z Z Z Z– ZB Z? ZC Z— 1.307  0.823 0.804 – 0.327 1.022 0.738 B 0.206 0.517 1.256 0.716 ? 0.082 0.459 0.693 1.499 0.705 C 0.051 0.210 0.771 0.867 1.745 0.701 — 0.020 0.166 0.383 1.144 1.039 1.994 0.698 D 0.013 0.073 0.359 0.598 1.579 1.212 2.242 0.696

Table B4: Chebyshev filter coefficients Zo.

(29)

29

References

Proakis, J.G. and Manolakis, D.G., Digital signal processing: principles, algorithms

and applications, Third Edition,(1996), ISBN -81-203-1129-9.

Signal Processing 2 Lecture Notes by Nedelko.G and Collection of formulas by M.Dahl, S.Johansson, M.Winberg (Department of Telecommunication and Signal Processing, BTH).

Stephen J. Chapman, MATLAB® Programming for Engineers, Third Edition,(2005), ISBN:981-254-893-9.

Vinay K. Ingle, John G. Proakis, Digital Signal Processing Using MATLAB®, (2003),Fourth Reprint, ISBN:981-240-215-2.

References

Related documents

Rather, I am simply interested in how Sweden understands climate change as a political problem (that is, what ‘is’ climate change to relevant policy actors in Swe-

In order to establish the performances of the blind identification technique, the frequency response function of the exact channel and identified channel using

The study includes a comparative analysis of an office building model with conventional windows and motorized awnings, versus electrochromic windows with different control

The “BanaVäg” project comprised of various significant infrastructure investments aiming to improve the capacity and quality of both the road and rail infrastructure including –

Den praktiska implikationen av den här rapporten är att den vill hävda att det behövs ett skifte i utvecklingen inom ambulanssjukvården mot att även utveckla och öka

Enligt Dryzek (2013) finns det plats för både bredd och djup inom miljödiskurser och fokus borde vara på helheten snarare än detaljer. Därför grundar den här uppsatsen sig på

The portfolios show scattered values, but one portfolio separates from the others: F6/H6 has a positive insignificant alpha and a Sharpe ratio that is higher than the market

För att kunna underlätta en övergång från barn- och ungdomshabiliteringen till vuxenhabiliteringen behövs tydligare information, tidigare förberedelse i tonåren för de unga