Table of Contents Table of Contents ............................................................................................................... 2 Table of Figures ................................................................................................................. 4 List of Tables ...................................................................................................................... 5 1
FIR Filters..................................................................................................................7
3.2
Designing FIR Filters using the Fourier Series Method..........................................7
3.2.1 Use of a window function..................................................................................................... 10 Rectangular window ........................................................................................................................... 10 Hann window...................................................................................................................................... 11 Hamming window............................................................................................................................... 11 Blackman window .............................................................................................................................. 11 3.2.2 Kaiser window...................................................................................................................... 11
3.3
Designing FIR Filters using the Frequency Sampling Method .............................12
3.4
Transformation of FIR filters transfer function....................................................14
Bilinear Transformation........................................................................................................ 15 Frequency Warping.......................................................................................................... 16 Design of Digital Filters using the bilinear transform .......................................................... 18 Analog IIR Filters Types ...................................................................................................... 18 Butterworth Filters........................................................................................................... 18 Chebyshev Filters ............................................................................................................ 20 Transformation of analog filters transfer function................................................................ 22 Other families of Analog filters [Ref-3] ............................................................................... 23
3.6
Filtering using Fast Fourier Transform.................................................................23
3.7
Comparison of IIR and FIR filters ........................................................................24
Implementation methodology:................................................................................. 24 4.1.1 FIR Filtering ......................................................................................................................... 24 4.1.1.1 FIR Using the Fourier series ............................................................................................ 24 4.1.1.2 FIR Using the Frequency Sampling Method ................................................................... 25 4.1.2 IIR Filtering using Butterworth and Chebyshev Type I ....................................................... 25 4.1.3 Filtering using Fast Fourier Transform................................................................................. 25
5
Computer Simulation............................................................................................... 25 5.1.1 The Input biomedical signals................................................................................................ 25 5.1.2 The Generated noise signals ................................................................................................. 28 5.1.3 Adding the noise and then filtering it out ............................................................................. 29 5.1.3.1 Filters specs...................................................................................................................... 30 5.1.3.2 Filtering using Fourier series (Dolph-Chebyshev Window) ............................................ 30 5.1.3.3 Filtering using Fourier series (Kaiser window )............................................................... 32 5.1.3.4 Filtering using the Frequency sampling method (Using the Kaiser window order) ........ 35 5.1.3.5 Filtering using the IIR Butterworth filter ......................................................................... 36 5.1.3.6 Filtering using the IIR Chebyshev Type I filter ............................................................... 38 5.1.3.7 Filtering using the FFT method ....................................................................................... 39 5.1.3.8 Results comparison Table ................................................................................................ 41
Read the Biomedical signals .....................................................................................65
7.11
Filtering using FFT filter kernel function..............................................................67
7.12
Radix-2 FFT used by the FFT Filter......................................................................69
7.13 Add 60 Hz noise to the ECG Signal and then use all of the developed filters to remove it..............................................................................................................................72 7.14
Add white noise to the ECG signal and use all of the developed filters to remove it 82
7.15
Radix-2 IFFT used by the FFT Filter ....................................................................90
7.16
Test the FFT Filter (LP, HP, BP & BS) .................................................................90
7.17
Test the developed Filters.......................................................................................98
3
Table of Figures Figure 1: Ideal FIR Filter Implementation [Ref-3] ............................................................. 7 Figure 2: Ideal low pass filter response .............................................................................. 8 Figure 3: Sinc Function....................................................................................................... 8 Figure 4: - Frequency response of length 25 filter using rectangular window [Ref-3] ...... 9 Figure 5: Fig 4 re-plotted using dB gain [Ref-3] ................................................................ 9 Figure 6: Frequency response of length 25 filter using Hanning window [Ref-3]........... 10 Figure 7: Basic windows including a rectangular, Hamming, Hann, Blackman, and Kaiser (β=2.0, 5.0) along with their magnitude frequency responses. [Ref-5].................... 12 Figure 8: FIR design objective. [Ref-5]........................................................................... 13 Figure 9: Direct Synthesis Methodology [Ref-5] ............................................................. 13 Figure 10: Typical mirror and complement FIR filter’s relationship to a parent FIR [Ref5] ............................................................................................................................... 14 Figure 11: Relationship between the continuous- and discrete-frequency axes under the bi-linear z-transform, [Ref-5].................................................................................... 17 Figure 12: Design of a discrete-time IIR from an analog model using a bilinear ztransform. .................................................................................................................. 18 Figure 13: Ideal Lowpass Filter Frequency response [Ref-2] .......................................... 19 Figure 14: Butterworth Lowpass Filter Frequency response for n=1 -6 [Ref-2].............. 20 Figure 15: Chebyshev type I Lowpass Filter Frequency response for n=1 -6 [Ref-2] ..... 21 Figure 16: Chebychev type II Lowpass Filter Frequency response [Ref-2]..................... 22 Figure 17: MCL signal...................................................................................................... 26 Figure 18: Respiratory System signal ............................................................................... 26 Figure 19: Original Blood Pressure signal........................................................................ 27 Figure 20: Original ECG signal ........................................................................................ 27 Figure 21: White Noise signal .......................................................................................... 28 Figure 22: 60 Hz Noise signal .......................................................................................... 29 Figure 23: Noisy ECG signal (60 Hz noise added)........................................................... 30 Figure 24: FIR by Fourier Series (Dolph-Chebyshev window) Filter coefficients (N=375)..................................................................................................................... 31 Figure 25: FIR by Fourier Series (Dolph-Chebyshev window) Freq Response (N=375)31 Figure 26: FIR by Fourier Series (Dolph-Chebyshev window) filtering results (N=375) ................................................................................................................................... 32 Figure 27: FIR by Fourier Series (Kaiser Window) Filters Coefficients (N=229)........... 33 Figure 28: FIR by Fourier Series (Kaiser Window) Freq response (N=229) ................... 33 Figure 29: FIR by Fourier Series (Kaiser Window) Freq response (N=229) ................... 34 Figure 30: FIR by Fourier Series (Kaiser Window) filtering results (N=229) ................. 34 Figure 31: FIR by Freq Sampling Filter Freq response (N=229) ..................................... 35 Figure 32: FIR by Freq Sampling Filtering results (N=229) ............................................ 36 Figure 33: Butterworth Filter Freq response (N=25)........................................................ 37 Figure 34: Butterworth Filtering results (N=25)............................................................... 37 Figure 35: Chebyshev Filter Freq response (N=10) ......................................................... 38 Figure 36: Chebyshev Filtering result (N=10).................................................................. 39 Figure 36: FFT Filtering Results ...................................................................................... 40 Figure 36: FFT Filter Kernel............................................................................................. 40
4
List of Tables Table 1 –Windows effect of FIR filters designed by the Fourier series method [Ref-4] . 11 Table 2 - Transformations of a unit cutoff frequency lowpass filter to other specifications [Ref-3]....................................................................................................................... 23 Table 3 – Analog Filters response comparison................................................................. 23 Table 4 – All filters results comparison table ................................................................... 41
5
1 Abstract The main objective of this project is to study and design FIR and IIR filters; to achieve this goal FIR and IIR filters are designed and used to remove various types of noise from few biomedical signals obtained from the MIT database for biomedical signals.
2 Introduction The Digital Filter Design problem involves the determination of a set of filter coefficients to meet a set of design specifications. These specifications typically consist of the width of the passband and the corresponding gain, the width of the stopband(s) and the attenuation therein; the band edge frequencies (which give an indication of the transition band) and the peak ripple tolerable in the passband and stopband(s). Two types of digital filters exist according to their impulse response: • •
The FIR (Finite Impulse Response). The IIR (Infinite Impulse Response)
FIR filters possess certain properties, which make them the preferred design choices in numerous situations over IIR filters. Most notably, FIR filters (all zero system function) are always stable, with a realization existing for each FIR filter. Another feature exclusive to FIR filters is that of a linear phase response. The design of IIR filters is closely related to the design of analog filters, which is a widely studied topic. An analog filter is usually designed and a transformation is carried out into the digital domain. Two transformations exist – the impulse invariant transformation and the bilinear transformation. This project addresses the following topics: 1. Noise generation 2. FIR filters 3. FIR Filtering Using FFT 4. Butterworth and Chebyshev filters Matlab programs were developed to perform filtering on a real life biomedical signal from the MIT database. The filtration results were analyzed and then the analysis results are summarized in this report.
3 Technical Background A filter is a device which passes some signals 'more' than others. In this chapter a short background is given about designing FIR and IIR Digital filters.
6
3.1 FIR Filters The difference equation corresponding to the following block diagram x(n)
= unit delay
b(0)
b(M) y(n)
Figure 1: Ideal FIR Filter Implementation [Ref-3] is M
y (n ) = ∑ b(k )x(n − k ) k =0
This is called a feedforward or non-recursive, or transversal, or FIR filter, because it has a Finite Impulse Response (h (n) =0 for n>M). Such an Mth order FIR filter, has M+1 coefficients b(k), k=0,...,M. One of the M+1 degrees of freedom provided by M+ 1 coefficient is the overall filter gain. The other M determines the variation of gain with frequency. 3.2 Designing FIR Filters using the Fourier Series Method Given the desired frequency response H(Ω) of a filter, we can compute an appropriate inverse Fourier transform to obtain its ideal impulse response. Since the coefficients of an FIR filter equate to its impulse response, this would produce an “ideal” FIR filter. However, this “ideal” impulse is not actually constrained to be of finite length, and it may be non-causal (i.e. have non-zero response at negative time). Somehow we must generate an impulse response which is of limited duration, and causal. In more detail, H(Ω) (which is periodic in Ω with period 2π) can be represented using a Fourier series representation
H (Ω ) =
∞
∑ h(k )exp(− jkΩ)
k = −∞
in which the h(k) are computed from H(Ω) using the standard formula for Fourier series coefficients: π 1 h(k ) = H (Ω ) exp( jkΩ )dΩ 2π −∫π If the "ideal" filter coefficients h(k) are to be real-valued, then H(Ω) must be conjugate symmetric, i.e. H(-Ω) = H*(Ω) . We will consider the simplest case, a frequency response which is pure real (zero phase), and therefore symmetric about zero frequency.
These specifications typically consist of the width of the passband and the .... Their discrete-time window specifications are summarized below. ...... %stem(t3,s3);.