adaptive notch filter for single and multiple narrow-band

116
Edith Cowan University Edith Cowan University Research Online Research Online Theses : Honours Theses 2001 Adaptive notch filter for single and multiple narrow-band Adaptive notch filter for single and multiple narrow-band interference interference Selina Kuek Lin Mei Edith Cowan University Follow this and additional works at: https://ro.ecu.edu.au/theses_hons Part of the Signal Processing Commons Recommended Citation Recommended Citation Mei, S. K. (2001). Adaptive notch filter for single and multiple narrow-band interference. https://ro.ecu.edu.au/theses_hons/876 This Thesis is posted at Research Online. https://ro.ecu.edu.au/theses_hons/876

Upload: others

Post on 19-Apr-2022

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Adaptive notch filter for single and multiple narrow-band

Edith Cowan University Edith Cowan University

Research Online Research Online

Theses : Honours Theses

2001

Adaptive notch filter for single and multiple narrow-band Adaptive notch filter for single and multiple narrow-band

interference interference

Selina Kuek Lin Mei Edith Cowan University

Follow this and additional works at: https://ro.ecu.edu.au/theses_hons

Part of the Signal Processing Commons

Recommended Citation Recommended Citation Mei, S. K. (2001). Adaptive notch filter for single and multiple narrow-band interference. https://ro.ecu.edu.au/theses_hons/876

This Thesis is posted at Research Online. https://ro.ecu.edu.au/theses_hons/876

Page 2: Adaptive notch filter for single and multiple narrow-band

Edith Cowan University

Copyright Warning

You may print or download ONE copy of this document for the purpose

of your own research or study.

The University does not authorize you to copy, communicate or

otherwise make available electronically to any other person any

copyright material contained on this site.

You are reminded of the following:

Copyright owners are entitled to take legal action against persons

who infringe their copyright.

A reproduction of material that is protected by copyright may be a

copyright infringement.

A court may impose penalties and award damages in relation to

offences and infringements relating to copyright material. Higher

penalties may apply, and higher damages may be awarded, for

offences and infringements involving the conversion of material

into digital or electronic form.

Page 3: Adaptive notch filter for single and multiple narrow-band

USE OF THESIS

The Use of Thesis statement is not included in this version of the thesis.

Page 4: Adaptive notch filter for single and multiple narrow-band

DECLARATION

l certify thut this thesis does not, to the best of my knowledge und belief:

i incorporate without acknowledgment any material previously submitted for a

degree or diploma in any institution of higher education;

11 contain any material previously published or written by another person except

where due reference is made in the text; or

iii contain any defamatory material.

signature: '-------­- --/-.\'' J J/

Date: ~

Page 5: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

..... , .....

EDITH COWAN UNIVERSITY PERTH WESTERN AUSTRALIA

BACHELOR OF ENSINEERING IN

COMMUNICATION SYSTEM

ENS4241 Engineering Project 2

Adaptive Notch Filter for Single and Multiple Narrow-band Interference

Submitted by : KUEK LIN MEl, SELINA 3993120

SUPERVISOR : Dr Amine Bennak and Dr Ganesh LOCAL SUPERVISOR : Mr Ma Zongming

Page 6: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

ABSTRACT

In this project, the adaptive notch filter for single and Multiple narrow-band interference is

implemented using simplified LMS algorithm.

Perfom1ances of the LMS adaptive algorithms is evaluated and analysed through simulation

on the computer using Matlab. The algorithm are then written in C programme and

implemented using Texas Instrument Tool which consist of TMS320C54x EMV board and

Code Composer Studio.

2

Page 7: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

ACKNOWLEDGEMENT

The students would like to take I his opportunity to express their gratitude and appreciation

to the following persons who have helped in the project:

Dr Ganesh and Dr Amine Bermak, the project supervisor, for giving his advise and

support through out the project.

Mr Goi Sio Peng and Mr Heng Kwee Tong of Centre for Wireless Communications for

making efforts to share their knowledge. Their guidance and invaluable assistance were

timely and much appreciated.

Dr Ma Zhongming, the local project supervisor, for giving his advise and moral support.

Finally, to everyone, who has m one way or another contributed to the project.

3

Page 8: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

LIST OF FIGURES

Figure 1.1 Frequency Respome of a Notch Filter ........................................................................ 10 Figure 1.2 Project Phase I Schedule ............................................................................................. I I Figure 1.3 Project Phase II Schedule ........................................................................................... / 1 Figure 2.1 Ge/leral adaptive filter configuration ......................................................................... 13 Figure 2.2 Network structure representation of FIR filter ........................................................... 14 Figure 2.3 Network structure representation of a 211

d order l/Rfilter .......................................... 15 Figure 2.4 Block Diagram of adaptive noise chancellor .............................................................. 17 Figure 2.5 Weight adaptation, W.~: vs k ......................................................................................... 20 Figure 3./ Poles and zeros plot of notch filter ............................................................................. 21 Figure 3.2 Search for minimum with stepwise fashion ................................................................. 2.5 Figure 3.3 Initial state of adaptation ............................................................................................ 27 Figure 3.4 Final adaptation notch with parameter a & r ............................................................. 27 Figure 3.5 Cascade section of the adaptive filter ......................................................................... 28 Figure 3.6 Multiple interference adaptive Notchfilter ................................................................. 29 Figure 3.7 Frequency response of multiple interference adaptive notch filter ............................. 29 Figure 4.1 Frequency Response of the Basic Notch Filter ........................................................... 32 Figure 4.2 Output response of the notch filter with poles within the unit circle .......................... 33 Figure 4.3 Relation between a and nomwlised bandwidth .......................................................... 34 Figure 4.4 Frequency Response with r =0.95 ............................................................................... 35 Figure 4.5 Frequency Response with r =0.90 ............................................................................... 35 Figure 4.6 Frequency Response with r =0.80 ............................................................................... 36 Figure 4.7 Frequency Response with r =0. 75 ............................................................................... 36 Figure 4.8 Frequency Response with r =0. 70 ............................................................................... 37 Figure 4.9 Relation between parameter rand normalised bandwidth ........................................ 38 Figure 4.IO Output Response of Adaptive Notch Filter ................................................................ 40 Figure 4./1 Output Response of Adaptive Notch Filter with Frequency Drift ............................. 4I Figure 4.I2 Output Response of Adaptive Notch Filter with Multiple Frequency Input .............. 42 Figure 4.I3 Output Response of Adaptive Notch Filter with u=O.OI ........................................... 43 Figure 4.14 Output Response of Adaptive Notch Filter with u=0.05 ........................................... 44 Figure 4.I5 Output Response of Adaptive Notch Filter with u=O.I ............................................. 45 Figure 4.I6 Output Response of Adaptive Notch Filter with u=0.2 ............................................. 46 Figure 4.17 Output Response of Adaptive Notch Filter with u:;;:;0.35 ........................................... 47 Figure 4.I8 Cascade Notch Filter with Single Input Frequency .................................................. 48 Figure 4.I9 Cascade Notch Filter with Frequency Drift .............................................................. 49 Figure 4.20 Cascade Notch Filter with Multiple Input Frequency .............................................. 50 Figure 4.21 Multiple Notch Adaptive Filter ................................................................................. 51 Figure 4.22 Multiple Notch Adaptive Filter with frequency drift ................................................. 52 Figure 5.I Configuration and Imerconnection oJTMS320C54X EVM ........................................ 55 Figure 6.1 Software Develcpement Flow ...................................................................................... 62 Figure 6.2 Progranune Flo~v ......................................................................................................... 64 Figure 6.3 Basic Notch filter with Single input, r =0.9 ................................................................ 66 Figure 6.4 Basic Notch filter with Single input, r =0. 75 .............................................................. 66 Figure 6.5 Basic Notch filter with Multiple input, r =0.9 ............................................................. 67 Figure 6. 6 Basic Notch filter with Multiple input, r =0.75 ........................................................... 68 Figure 6.7 Adaptive Notch filter with single inplll, u =0.1 ........................................................... 69

4

Page 9: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2 _______ _

Fig11re 6.8 Adaptive Notch filter with single input, u =0. J 5 ......................................................... 69 Figure 6.9 Adaptive Notch filter with single input, u =0.2 ........................................................... 70 Figure 6./0 Adaptive Notch filter with single inplll, u =0.25 ....................................................... 70 Figure 6.11 Adaptive Notch filter with single input, u =0.1 ......................................................... 71 Figure 6./2 Adaptive Notch filter with multiple input, u =0.1 ..................................................... 72 Figure 6.13 Ad ptivc Notch filter with multiple input, u ;;::.Q.J ..................................................... 73 Figure 6.14 Cascade Notch filter with single input, u ;:::;0.25 ....................................................... 74 Figure 6.15 Cascade Notch filter with multiple input, u =0.25 .................................................... 75 Figure 6.16 Multiple Notch filter with single input ...................................................................... 76 Figure 6.17 MullliJle Notch filter with single input ...................................................................... 77 Figure 6.18 TMS320C5x EMV board connection ......................................................................... 79

5

Page 10: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

TABLE OF CONTENTS PAGE

ABS'I'RACrJ' ............................................................... 2

ACKNOWLEDGEMENT .............................................. 3

LIST 0 fi' li'l G URES ...................................................... 4

1 INTRODUCTION ooooooooouooouoooouooooooooouooooooooooooooooooooooooooouooooooooS

1.1 BACKGROUND ...................................................................................................... 8

1.2 OBJECTIVES .......................................................................................................... 9

1.3 PL.<\NING ............................................................................................................... 11 1.3.1 PHASE 1 ........................................................................................................... II 1.3.2 PHASE ll ......................................................................................................... 11

2 BASIC THEORY ...................................................................... 12 2.1 ADAPTIVE FILTER ............................................................................................. 12

2.1.1 APPLICATION ................................................................................................ 13 2.1.2 ADAPTIVE FILTER STRUCTURE ............................................................... 13 2.1.3 ALGORITHM .................................................................................................. 16

2.2 ADAPTIVE NOISE CANCELLATION .............................................................. 16

2.3 ADAPTIVE ALGORITHMS ................................................................................ 18 2.3.1 BASIC LEAST MEAN SQUARE (LMS) ADAPTIVE ALGORITHM ......... 18

3 PROJECT APPROACH .......................................................... 21 3.1 NOTCH FILTER TRANSFER FUNCTION ...................................................... 21

3.2 LMS ADAP1'IVE ALOGRITIJM ........................................................................ 23 3.2.1 ADAPTATION OF PARAMETER a .............................................................. 23 3.2.2 ADAPTATION OF PARAMETER r .............................................................. 26

3.3 CASCADE ADAPTIVE NOTCH FILTER ......................................................... 28

3.4 MULTIPLE CHA "'NEL ADAPTIVE NOTCH FILTER .................................. 28

3.5 IMPLEMENTATION APPROACH .................................................................... 30

4 SIMULATION AND DISCUSSION ....................................... 31 4.1 BASIC IIR NOTCH FILTER ............................................................................... 31

4.1.1 POLES AND ZEROS ...................................................................................... 32 4.1.2 RELATION BETWEEN a AND NORMALISED BANDWIDTH ................ 33 4.1.3 RELATION BETWEEN rAND NORMALISED BANDWIDTH ................. 34

4.2 ADAPTIVE IIR NOTCH FILTER ...................................................................... 39 4.2.1 PARAMETER u .............................................................................................. 43

4.3 CASACADE SECTION OF ADAPTIVE IIR NOTCH FILTER ..................... 48

6

Page 11: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

4.4 MULITPLE ADAPTIVE NOTCH FILTER ....................................................... 51

5 DEVELOPMEN1, TOOL ........................................................ 53 5.1 TMS320C54X EVALUATION NODULE ........................................................... 53

5.1.1 OVERVIEW .................................................................................................... 53 5.1.2 KEY FEATURES ............................................................................................ 54 5.1.3 FUNCTIONAL BLOCKS DESCRIPTION .................................................... 54

5.2 TMS320C5000 CODE COMPOSER STUDIOTM 1.2 ......................................... 55 5.2.1 INTRODUCTION ............................................................................................ 56 5.2.2 FEATURES AND BENEFITS ........................................................................ 56 5.2.3 PROJECT DEVELOPMENT CYCLE ............................................................ 57

6 IMPLEMENTATION .............................................................. 61 6.1 SOJ:i"TWARE IMPLEMENTATION .................................................................... 61

6.1.1 OVERVIEW .................................................................................................... 61 6.1.2 DATA REPRESENTATION ........................................................................... 62 6.1.3 PROGRAMME STRUCTURE ........................................................................ 63 6.1.4 RESULTS ........................................................................................................ 65

6.2 HARDWARE IMPLEMENTATION .................................................................. 78 6.2.1 OVERVIEW .................................................................................................... 78 6.2.2 CONFIGURATION ......................................................................................... 78

PROBLEMS AND RECOMMENDATIONS .............................. 80

CONCLUSION ............................................................................... 82

REFERENCES ................................................................................ 83

APPENDIX A - Matlab Simulation Programmes ...................... 84

APPENDIX B- C Language Programming .............................. 103

7

Page 12: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1 INTRODUCTION

1.1 BACKGROUND

Digital signal processing is one of the fastest growing fields in the last thirty years

and it plays a major role in many application areas. The resulting digital signal

processing systems ru-e attractive due to their reliability, accuracy, small physical

sizes, and flexibility.

One category of digital signal processing knows as adaptive signal processing which

applications arc increasing rapidly. Adaptive signal processing evolved from

techniques developed to enable the adaptive control of time-varying system. It has

gained a lot of popularity due to the advances in digital technology that have

increased the computing capacities and broadened the scope of digital signal

processing. The key difference between classical signal processing techniques and

adaptive signal processing method is that the latter deal with time varying digital

systems.

An adaptive system is a system whose coefficients could automatically adjust to

changing environment or input signal. The transition from implementing digital

filters with DSP microprocessors to implementing adaptive digital filters is a natural

extension. Adaptive t1lters are used to their greatest advantage when there is an

uncertainty about the characteristics of a signal or when the characteristics change

during filter's characteri-Stics no longer change.

8

Page 13: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

Adaptive filter theory could be found applications in such field as biomedical

engineering, seismology, astrology, navigation, communication, radar, sonar and

control systems. They arc used in the area of system identification, channel

equalization, signal enhancement, and prediction.

The project will focus on the techniques of using adaptive notch f1ltcr in the Noise

Cancellation Application.

1.2 OBJECTIVES

In many systems, noise interference is a major problem that could cause the whole

system to malfunction or inaccurate readings to be taken. Noise signals nonnally

reside in higher frequencies in the frequency spectrum. So to remove the noise signal,

the signal could be passed through a low pass filter so that the higher noise frequency

could be removed. However, by doing this, the bandwidth of the signal would be

effectively reduced. This is however not desirable as, if there are signals in the higher

frequency range that is wanted, then they will be lost.

To overcome this problem, a notch fiher could be implemented. The function of this

notch filter is to cancel out only the noise frequency. That is, it is simply a band stop

filter with a very narrow bandwidth with the notch frequency placed over the noise

signal. This is illustrated in Figure 1.1

9

Page 14: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

T

I 0 fo f

Figure 1.1 Adaptive Notch Filter

As can be seen from the frequency response plot of the filter in Figure 1.1, the whole

frequency spectrum of the signal is passed through except at the noise frequency. In

this way, the bandwidth of the signal is preserved and only the noise component is

being removed.

Also if the noise frequency shift up and down, the notch niter must be able to adapt

to the shift. That is, the filter must be able to track the noise and cancel it out. This is

important feature in noise cancellation as most noise signals arc not stationary at a

frequency.

The objective of this project is to implement this adaptive notch filter digitally to

cancel out single and multiple narrow-band noise in a wide-band signal. It will be

implemented on the TMS320C54XX board and demonstrated on audio signal.

10

Page 15: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1.3 PLANING

1.3.1 PHASE I

The schedule was planned base on weekly basis. The duration to complete a task

will ·,·ary from one to four weeks depends on its complexity.

The following schedule was planned before the project was started.

Figure 1.2 Project Phase II schedule

1.3.2 PHASE II

In project II, the schedule was planned according to project I on weekly basis. Due to

short time frame, the duration has slightly reduce from one to two weeks depend on

the complexity.

Here is the project II schedule:

I I

I i

Figure 1.3 Project Phase II schedule

"

Page 16: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

2 BASIC THEORY

2.1 ADAPTIVE FILTER

Adaptive filters arc considered non-linear systems, therefore their behaviour analysis

is more complicated than for fixed filters. On the other hand, because the adaptive

filter.~ are self designing filters, from the practitioner's point of view their deign can

be considered less involved than in the case of digital filters with fixed coefficients.

The general set up of adaptive filtering environment is illustrated in Figure 2. 1, where

k is the iteration number, x(k) denotes the input signal, y(k) is the adaptive filter

output signal, and d(k) defines the desired signal. The error signal e(k) is calculated as

d(k) - y(k). The error signal is then used to form a performance function that is

required by the adaptation algorithm in order to determine the appropriate updating of

the filter coefficients. The minimisation of the objective function implies that the

adaptive filter output signal is matching the desired signal in some sense.

12

Page 17: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

d(k)

! x(k

y(k) ·)

Adaptive filter /+ - '

I e(k)

Adaptive algorithm

Figure 2.1 General adaprive filter configuration

The specifications of an adaptive system consists of the following items:

2.1.1 APPLICATION

The type of application is defined by the choice of the signals acquired from the

environment to be the input and desired-output signals. Examples are echo

cancellation, channels equalization, system identification, signal enhancement,

adaptive beamfonning, noise canceling and control.

2.1.2 ADAPTIVE FILTER STRUCTURE

The adaptive filter can be implemented in a number of different structures or

realizations. The choice of structure can influence the computational complexity

(amount of arithmetic operations per iteration) of the process and also the necessary

number of iterations to achieve a desired performance level. Basically. there are two

major classes of adaptive digital realizations :

13

Page 18: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

For this realization, the output signal is a linear combination of the filter

coefficients, that yields a quadratic mean square error (MSE) function with <1 unique

optimal solution. FIR typically required large filter orders lO obtain satisfactory

sharp cutoff characteristics and hence increase in computational complexity.

2.1.2.1 Finite-duration Impulse Response (FIR) !iller

x(n)

The most widely used adaptive FIR filter structure is the transversal filler which

implements an all·zcro transfer function with a canonic direct from realization

without feedback. The output of the FIR filter can be described by the following

equation:

N

y(n) = 2: b, x(n-k) ............................. 2.1

·~

The above equation represents a weighted sum of the present and past input to

the Iiller with b, is the weight of the (N+l) order filter. The equation may also

be represented by the network structure as shown in Figure 2.2

z·' z·'

hn h, h, '· I lfi\J h,~~.,

y(n)

Figure 2.2 Network structure representation of FIR filter

14

Page 19: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

2.1.2.2 lnflnitc-duro1tion Impulse Response (IIR) Filter

The most widely used adaptive IlR filter structure is the canonic direct-form

realization, due to its simple implementation and analysis The output of the fiR

filter can be described by the following equation :

N M

y(n) = l: a, y(n-k) + l: b, x(n-k) ............................. 2.2 k=l

Equation {2,2) shows that the output of the filler is a weighted sum of the present

and pasl input of the filter, as well as past values of the output of the filter. The al

and bk arc the weights of the filler and N & M is the order of the filter. A network

structure representation

of a second order IIR filter is illustrated in Figure 2.3 :

x(n) ho y(n)

z·' a, h.

z·' a, h.

Figure 2.3 Network structure representation of a 2nd order 1/Rfi/ter

15

Page 20: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

Sharp culOff and constant magnitude response can bc obtained using second-order

filter sections. However, there arc some inherent problems related to recursive

adaptive filters which arc structured dependent, such as pole-stability monitoring

requirement and slow speed of convergence.

2.1.3 ALGORITHM

The algorithm is the pro.::cdurc used to adjust the adaptive filter coefficient in order

to minimize a prescribed criterion. The algorithm is dctcnnincd by defining the

search method (or minimization algorithm), the objective function, and the error

signal nature. The choice of algorithm determines several crucial aspects of the

overall adaptive process, such as existing of sub-optimal solutions, bia<;ed optimal

solution, and computational complexity.

2.2 ADAPTIVE NOISE CANCELLATION

The basic concept of adaptive noise canceHation reduces the level of undesired noise

by using adaptive filtering techniques with an auxiliary reference signal. This

technique takes advantage of the correlation between the noise contaminating the

desired signal and a noise-alone reference signal. Figure 2.4 shows the block diagram

of an adaptive noise cancellation system :

16

Page 21: Adaptive notch filter for single and multiple narrow-band

I

ENS4241 ENGINEERING PROJECT 2

u(n) + d(n)

I + c(n) + ,. P(z) (I_;

/ .-x(n) y(n) -

W(z)

LMS

Figure 2.4 Block Diagram of adaptive noise canceler

The canceler has two inputs, the primary input d(n) and the reference input x(n).

The primary input d(n) consists of desired signal u(n) plus noise, which is derived

from x(n) through the linear filter P(z). The reference input consist~ of noise x(n)

alone.

The objective of the adaptive filter is to use the reference input x(n) to estimate the

noise component of d(n) using adaptive filter W(z). The adaptive filter output y(n)

is then subtracted from the primary channel signal d(n), producing e(n) as the

desired signal plus a small amount of residual noise.

The area of focus for the project is to deduce a method on reducing sinusoidal

interference of an audio signal. The conventional mell10d of eliminating such

sinusoidal interference is through the usc of a notch filter tuned to the frequency of

17

Page 22: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

the interference. A very narrow notch is usually desired m order to filler out

interference without seriously dislorting the signal of interest.

An adaptive notch can be realised by using an adaptive noise canceler with a

sinusoidal reference signal. The advantages of adaptive notch filter arc that it offers

ca<>y control of bandwidth, an infinite null. and the capability to adaptivcly track the

exact frequency of interference.

2.3 ADAPTIVE ALGORITHMS

Adaptive algorithms arc used to adjust the coefficients of the digital filter such that

the error signal, c(k). is minimized according to some criterion. There arc varies of

algorithms used in digital filter applications, r.xamplcs, Least Mean Square Algorithm

(Ll\!S), Nonnalised LMS Algorithm (NLMS), Variable Step Size LMS Algorithm

(VSLMS) , Nonnalised Variable Step S Algorithm (VSNLMS) .Recursive Least

Sql!are Algorithm (RLS) and RLS-QR Algorithm (RLS-QR) etc. The most common

algorithms that have found widespread application arc the Least Mean Square

Algorithm (LMS) and Recursive Least Square Algorithm (RLS). In terms of

computation and storage requirements, the LMS algorithm is the most efficient.

Further, it docs not suffer from the numerical instability problem inherent in the other

two algorithms. For these reasons, the LMS algorithm has become the first choice in

many applications. A more detail infonnation of the basic LMS adaptive algorithm

was introduced.

2.3.1 BASIC LEAST MEAN SQUARE (LMS) ADAPTIVE ALGORITHM

In LMS algorithm, the coefficients arc adjusted from sample to sample in such a

way as to minimize the Mean Square Error (MSE).

18

Page 23: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

The LMS is b:.L-;cd on the steepest descent algorithm where the weight vector is

updated from sample to sample as follows:

w .,, = w,- ll • "'' ----------------------------------- (2.3)

where W~; and .6.~; arc the weight and the true gradient vectors, respectively, at the

kth sampling instant. fl. controls the stability and rate convergence.

The LMS algorithm is a practical method of obtaining estimates of the filter weights

W~; in real time. The widrow-hopf LMS algorithm for updating the weights from

sample to sample is given by

W ,., = W, + 2*J.l * e, * t., ---------------------------- (2.4)

Where:

e, = yk- I: w,(i)x,_,

Clearly, the LMS aigorilhm above does not require prior knowledge of 1he signal

statistics, but instead uses their instantaneous estimates. The weights obtained by

the LMS algorithm are only estimates, but these estimates improve gradually with

time as the weights arc adjusted and the filter learns the characteristics of the

signals. Eventually. the weights converge. The condition for convergence is:

O<!l> !lA.,.,.

19

Page 24: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

where Anl.l~ i.; tilt! maximum eigenvalue of the input data covariance matrix. In

practical, WL never reaches the theoretical optimum Wopcnnum , but fluctuates about

it. Sec the Figure 2.5 below.

\\'op1imum

k

Figure 2.5 Weight Adaprion, lV.t l'S k

20

r

Page 25: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

3 PROJECT APPROACH

3.1 NOTCH FILTER TRANSFER FUNCTION

We have decided to usc IIR filter structure and LMS algoritlun to design and

implement the adaptive notch filler after going through the literature studies. The initial

task is to obtain the transfer function of the notch filter.

With the constraints and characteristics of a notch filter lead to a direct realisation of

transfer function from the poles and zeros diagram. From the pole-zero plot of notch

filter shown in Figure 3.1, it converges to a polynomial transfer function with zeros on

the unit circle wb,<;c angular locations correspond to the signal frcqucncics(w). r is a

constant which is slightly Jess than I so that the poles lie in the stability domain. It also

determines !he relationship between the dislance of the pole from the unit circle and

the normalised bandwidth.

-I

lm

e Zero X Pole

Figure 3.1 Poles & Zero Plot of Notch filter

21

Page 26: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

With all the condition stated as above we could derive the transfer function of the

adaptive notch filter:

H(z) = Y(z) I X(z)

lrl< I

lrl< I

lrl< I

lrl <I --- (3.1)

where

a=2cosw

In measuring the performance of the filter, the stability of the filter is very important h

is critical thnt the position of the poles of the filter remains within the circle to ensure

stability of the output of the filter. If however the position of the poles were allowed to

drift out of the unit circle radius in the pole-zero plot, then the output of the filter will

become unstable.

By taking the inverse z-transfonn of the transfer function, it is easy to show that the

output of the filter is given by:

y(n) = x(n)- a(n)x(n-l) + x(n-2) + n(n)ry(n-1)- r2y(n-2) ------------- (3.2)

22

Page 27: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

Comparing equation (3.2) With equation (2.2) mentioned earlier, it could be noted

that they arc similar. That is, it is a summation of the weighted pasted and present

input values as well as weighted past output values. Thus it has the same structure

as IIR filter.

3.2 LMS ADAPTIVE ALOGRITHM

The Least Mean Square algorithm is chosen due to its simplicity and ease of

computation. In addition, it does not require repetition of data. Thus it is generally

the best for many different application of adaptive signal processing.

Generally, the LMS algorithm is applied in transversal tapped (FIR) filters with the

structure shown in Figure (2.2). But it can be extended to IIR filters with the

structure shown in Figure (2.3).

3.2.1 ADAPTATION OF PARAMETER a

In this project, we arc only concern with second order section with one weight. Thus

this will simplify the understanding of the algorithm. The algorithm is based on the

steepest-descent gradient search. The equation used here lvill be modified from the

one introduced by Widrow -hop f. Here we are trying to minimise the mean~squared

output energy level instead of minimizing the mean-squared error.

This is given by:

o(n+l) =o(n) -1.1 [ dy(n)2/da(n)] ------------ (3.3)

Differentiating the mean-squared output w.r.t a{n)

23

Page 28: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

a(n+l) =a(n)- 2 ~ y(n) [ dy(n)/da(n)] ------------- (3.4)

from equation (2)

[ dy(n)/da(n)] = -x(n-1) + ry(n-1)

Substituting into equation (3)

a(n+ I) =a(n)- 2 f1 y(n) [ -x(n-1) + ry(n-1) ] ------------- (3.5)

The above equation (3.5) is the LMS algorithm for this adaptive notch filter. Here Jl

is the gain constant that regulates the speed and stability of adaptation.

Since we are dealing with real time processing, we need a relatively fast way of

reaching the minimum. The way that the search is conducted is to set the weight of

the filter, that is a(n) in equation (3.2), to some initial arbitrary value. And it wil\ be

adjusted in a stepwise fashion until the minimum is reached. This is shown in

Figure 3.2

24

Page 29: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

' y(n)"

mm

Negative Slope

Positive Slope

a(n)

a(n+l)

a(n)

Figure 3.2 Search for minimwn with stepwisefashiml

When making a step, the size and direction must be considered. Each step will

consist of an increment to the weight. If the current value of the weight is to the

right of the minimum, then the step will be negative. If the current weight is to the

left of the minimum, then the step size will be positive.

Thus the negation of the derivation indicated the proper direction of increment

Since the derivative vanishes at the minimum, it can be used to adjust the step size.

And it can be observed that the step size and direction is proportional to the

negative of the derivative as in equation (3.3). And repeated iteration of equation

(3.3) will cause a(n) to move by steps from its initial value until it reaches the

minimum.

25

Page 30: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

And since the weight changes at each iteration arc based on imperfect gradient

estimates, it is expected that the adaptive process to be noisy, i.e it would not follow

the true line of steepest descent on the pcrfonnancc surface.

With the equation obtained in equation (3.5), we can see the simplicity and ease of

computation of LMS algorithm. It allows the weight of the filter to be updated

averaging, squaring or differentiating.

3.2.2 ADAPTATION OF PARAMETER r

The stability of the fitter is maintained by constraining the poles of the filter within

the unit circle. And to achieve a narrow notch, the poles are kept as close to the unit

I circle as possible. However, by doing so, because the LMS algorithm adapt by

searching the gradient of squared output, it would be less sensitive to noise signals

that are far away from the notch.

To be able to track noise signal that is far away from the notch, the parameter, r, has

to be adapted as well. The idea to start off with a wide notch so that the noise signal

can be detected and then to reduce the width of the notch to the narrow notch as l

before. This is depicted in Figure 3.3 and Figure 3.4.

!

26

Page 31: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

Initial fc Interference frequency

Figure 3.3 Initial state of adaptation

I Final nolch frequency

Figure 3.4 Final adaptation notch with parameter a & r

27

Frequency

?~~quency

Page 32: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

3.3 CASCADE ADAPTIVE NOTCH FILTER

The cascade section of the adaptive IIR notch filter is implemented by having two

section of the basic notch filter as shown in the following Figure 3.5 . The

adaptation is done at the end of the section.

( ) xn Programmable Programmable y(n) Filter Filter

t i a(n)

Adaptive Algorithm

Figure 3.5 Cascade section of the adaptive filter

This cascading of two sections together allows the filter to have a narrower notch

and yet retain its stability by constraining the poles in both sections well within the

unit circle.

3.4 MULTIPLE CHANNEL ADAPTIVE NOTCH FILTER

The multiple adaptive IIR Notch filter will be extended to cancel out multiple

sinusoidal interference. It is similar to cascade filter but with individual adaptive

algorithm as shown in the Figure 3.6.

28

Page 33: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

( ) xn Programmable Programmable y(n) Filter Filter

al(n) a2(n)

Adaptive f.-

Adaptive f-Algorithm Algorithm

Fig 3.6 Multiple interference Adaptive Notch filter

The frequency response of the mulliple notch has the fonn shown in Figure 3.7

fl f2 Frequency

Figure 3.7 Frequency response £,fmultiple imeiference adaptive notch filter

29

Page 34: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

3.5 IMPLEMENTATION AI'I'ROACH

The derived programmes will be simulalcd using Matlab for windows Version 5.3.1

for testing the feasibility of the adaptive algorithm. In the initial approach,

TMS320C5x DSK board was used as the development tool but it was replaced by

TMS320C54x EMV board and the Code Composer simulator in the later phase. The

brief description of the TMS320C54x EMV board and the Code Composer Studio

will be discussed in Chapter 5.

In order to demonstrate an real~time application, an analogue signal will be injected

to the analogue input connector of TMS320C54x EMV board and the analogue

output will be monitored.

30

Page 35: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

4 SIMULATION AND DISCUSSION

In this chapter, the theoretical approach of the adaptive notch filters, which had been

derived from previous chapter, will be investigated using MATLAD s0ftwarc. The

basic, adaptive, cascade and mulitplc notch filters will be analysed and discussed.

4.1 BASIC IIR NOTCH FILTER

The transfer function of the notch filter has been derived in the previous chapter as

shown in equation (3.1 ).

H(z) = 1-az·' + z"2/l-arz"1 + r"z·'

When=

a;::;2cos co and lrl <I

There are a few parameters which will effect the performance of the filter, there are

poles, zeros, parameter a, r and sampling frequency. Figure 4.1 shows the frequency

response of the transfer function with sampling frequency of 48KHz, notch frequency

of 4KHz and r=0.95

31

Page 36: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PUOJECT 2

• u E E ' 0

51 0

-5

·10

·15

-20

·25

·30 0 0.5

r..,o.os

1.5 Froquacny In Hz

2

Figure 4.1 Frequency Response of the Basic Notch Filter

4.J.l POLES AND ZEROS

I

1

In measuring the performance of the filter, the stability of the filter is very

important. It is critical that the positions of the poles remain within the unit circle to

ensure stability of the filter. If the position of the poles drift out of the circle radius,

the output will be unstable. It is illustrated in the following ligures.

32

Page 37: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

No. of steps

t

1\

.---

~ o.sr

v & 0 " (I)

s g- .Q.S

-1 0 50 100 150 200 250 300

Figure 4.2 Output response of the notc/lfilter with poles within the unit circle

4.1.2 RELATION BETWEEN a AND NORMALISED BANDWIDTH

The relation between the frequency varying parameter, a and the normalised

bandwidth is given in Figure 4.4

33

Page 38: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

.<: -'0

~ '0 c: .. m '0

" U) .. E ~

0 z

-0.5 - -- --- -- - ·--~ --- -~---· l

I ----0.45· --- ---------------i I

. ------ 0.4- --· -- ------------1 ----·- ·-- -·-··-----0.35 - ---------1 r--- ------- --0.3T --------- ~

r- -- ---- ----0:,2- --- -- -~=l -- 0.-15 -----1

~-----~~~-----~-~

l--------o.o5

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2

a

Figure 4.3 Relation between a and nonnalised bandwidth

4.1.3 RELATION BETWEEN rAND NORMALISED BANDWIDTH

The parameter, r determines both the distance of the pole from the unit circle and

the normalised bandwidth. The following figures are plots according the frequency

response of different values of r.

34

Page 39: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

5 --- --

0

·5

~a ·tO on ;n dB

·15

·20

t=0.95 '- -- ----- '-----------,~-~--

·25

·30~-~~~_j 0 0.5 1.5 2 2.5

5

D

·5

·00 m ~

= = ·15

• ~

·20

·25

·30

·35 D

Frequecny in H1: x 10 •

Figure 4.4 Frequency Response with r =0.95

0.5

r .. 0.90

0.5 Frequec:ny In Hz

2

Figure 4.5 Frequency Response with r =0.90

35

2.5

• • 00

I

Page 40: Adaptive notch filter for single and multiple narrow-band

I

ENS4241 ENGINEERING PROJECT 2

r:0.60 5 - ------, - ' ' - . -- .. - '-

j 0 ', /-/

I ' -5

·10

m -15 u ~

~ -20 • "

-25

-30

-35

-40 0 0.5 L5 2 2.5

Frequecny In Hz • '"

Figure 4.6 Frequency Response with r ;::0.80

r::0.75 5

0

-5

-10

-15 m u ~ -20 c • " ·25

·30

·35

-40

-45 0 0.5 1.5 2 2.5

Frequecny In Hz • '" Figure 4.7 Frequency Response with r =0.75

36

Page 41: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

f:Q 70

5 I ,.--- ,-.- ---, --- ---- --

01 "" /F ..

-...... , /~ -5 I ' \

I ' \ I

-to i

' I \ I

-t 5

\1/ "' u

-= -20 c

II -. " -25

I! j;

-30 i: " -35

-40

-45 0 0.5 \.5 2 2.5

Frequecny In Hz • ' t 0

Figure 4.8 Frequency Response with r =0. 70

37

Page 42: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

Figure 4.10 show a relation between r and the normalised bandwidth. f-rom the

figure:-;, it can be seen that the parameter, r is inversely proportional to the

bandwidth or the notch filter.

0.14

~ 0.12 "0

" .!!! 0.1

"' E ~ 0.08 0 c: -.c: 0.06 -"0 ;:

0.04 "0 c:

"' Ill 0.02

.........__, r----....,

"" ""' "" ----i "'-.· ~

'--., ("-,

""-._

~

0

0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95

r

Figure 4.9 Relation between parameter rand nonnalised bandwidth

Page 43: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

4.2 ADAPTIVE IIR NOTCH FILTER

This section will discussed the performance of the single interference adaptive notch

filter. The theoretical adaptive equation was implemented using MATLAB and the

results were simulated.

The following figures arc plotted according to difference input variables of

parameters. Figure 4.11 showed a single input frequency of 8KHz and with sampling

frequency of 48KHz. Figure 4.12 showed the same frequency input but wilh a

frequency drift of I OOHz. The result of Figure 4.12 showed that the ftltcr is able to

adapt the changed of frequency and response accordingly. Figure 4.13 showed the

same filter with multiple channel input. The result showed that the filter only

attenuated the notch frequency in the input signals.

39

Page 44: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

·1~-

0

g 0.5 • ,

50

Single Channel Adaptive Nolch Filler

-~1~oo--1~so~~~o-~~o-~3oo No. of Samples

'

! 0 ~~-~,~~-----------~ '5 -0.5 0

·1 ~---:":---c:-:------,-~--::-'-:,....-c-::-0:-----,:-0 50 100 150 200 250 300

Figure 4.10 Output Response of Adaptive Notch Filter

40

Page 45: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1,-----~-------~---.------.-----~----·

0.5

1l ~ 0 Ul

s g-e.s -1 '-------:''----~--~----"----'-----'

0 50 100 150 200 250 300

Figure 4.1 I Output Response of Adaptive Notch Filter with Frequency Drift

41

Page 46: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

·2 0

Single Channel Adapti..e Notch Fitter with Multiple Frequency Input ----~---·· ------T----·--- -----, --

------=--------___j-_____ ___j ____ ~---~---__j

50 100 150 200 250 300 No. of Samples

2,----.---,---.----.---.-----

0 1 u c § g 0 rn 5 s -1 0

\ -2L----L---L---~---J---~--__j

0 50 100 150 200 250 300

Figure 4.12 Output Response of Adaptive Notch Filter with Multiple Frequency Input

42

Page 47: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJPCT 2

4.2.1 PARAMETER u

The parameter u as shown in the adaptive algorithm equation is the step size

which determined the speed and stability of the adaptation. The following few

figures arc plotted according with same notch frequency and different step size.

The input is an 8KHz sine wave and shift to 8.1 KHz after 256 samples.

Single Channel Adap!ive Notch Filter

·1 0 50 100 150 200 250 300

No. of Samples

• u 0.5 < • , flA ~ • 0

"' lvv'""' "5 ~

"5 -0.5 0

·1 0 50 100 150 200 250 300

F

igure 4.13 Output Response of Adaptive Notch Filter with u=O.OJ

43

Page 48: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

-1 '-----------'- ----~-----~---------'-·

• g 0.5 • 0 u • 0

"' , 0. ;:; ·0.5 0

0 so 100 150 200 250 300

No. of Samples

-1~----~----~~--~~----~----~----~ 0 50 100 150 200 250 300

Figure 4.14 Output Response of Adaptive Notch Filter with u=0.05

44

Page 49: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

Single Channel Adaptive Notch Filler with Multiple Frequency Input

-2'---~- -~---~--~~-~~-~ 0 50 100 ISO 200 250 300

No. of Samples

2,-----~----~---~-----,------,-----,

• u 1 0 • , cr {~ 0

5 ~

"5 ·1 0

-2'---~--~---~---L--~~-~ 0 50 100 150 200 250 300

Figure 4.15 Output Response of Adaptive Notch Filter with u=O.l

45

Page 50: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

m ! o.: ~~1/1 \jv 11\fV'V\J'vv~------,1 ~ -o.s ' 0

-1L--~~-~~-~--~--~--~ 0 50 100 150 200 250 300

Figure 4.16 Output Response of Adaptive Notch Filter with u=0.2

46

Page 51: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

I

~ 0.5 II ~ 0" • 0 Vl

'5 c. '5 .().5 0

·1L-----~----~----~------~----~----~ 0 50 100 150 200 250 300

Figure 4.17 Ow put Response of Adaptive Notch Filter with u=0.35

47

Page 52: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

4.3 CASACADE SECTION OF ADAPTIVE IIR NOTCH FILTER

The following figures show the simulation results of the cascade filter with single

frequency,

frequency drifting and multiple frequency input sequence. From the simulation

rcsuhs, it showed that the filler is able to track on the drift frequency and

allcnuatc the frequency component in the region of notch frequency.

·1L-----~----~------~----~------~-----' 0 50 100 150 200 250 300

No. of Samples

1,-----~----~----~----~----.-----,

" g ~ 0.5 g en s c. s 0

~.5~----=-----~----~~--~~--~~----~ 0 50 100 150 200 250 300

Figure 4.18 Cascade Notch Filter with Single Input Frequency

48

Page 53: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1 r---~--~-------,---~--~

1! o.s/ ~ 0"

"' VJ s c. s -{).5 0

-1 '----~-~--~--....-L--~--_j 0 50 100 150 200 250 300

Figure 4.19 Cascade Notch Filter with Frequency Drift

49

Page 54: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

~ u 1

~ lif 0

<Jj

"5 a_ "5 ·1 0

·2L-----~----~----~----~~----~----~ 0 50 100 150 200 250 300

Figure 4.20 Cascade Notch Filter with Multiple Input Frequency

50

Page 55: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

4.4 MULITPLE ADAPTIVE NOTCH FILTER

The following [lgurcs showed the simulation output results of the multiple notch

adaptive filler with multiple frequencies and frequency drifting input sequence.

From the simulation results, it showed that the filter is able to tracl~ on the

frequency drift and attenuate the frequency component in the region of notch

frequency.

Multiple Channel Adapti\€ Notch Filter

-2~----~----~------~----~------~----~ 0 50 100 150 200 250 300

No. of Samples

1.5 r--------~----~------~----~------~----~

~

g ~ g 0.5

i 0 ~~~r---------------------------------6 .(),5

-1~----J------L----_J------~----J-----~ 0 50 100 150 200 250 300

Figure 4.21 Multiple Notch Adaptive Filter

51

Page 56: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

-2L---- -~---~----~---~--~----:-' 0 50 100 150 200 250 300

No. of Samples

3,---.----.--~---~--~--.

w ~ 2

g. (f) 1 s a. s 0 0

-1~--J_--~--~---L---~--~ 0 50 100 150 200 250 300

Figure 4.22 Multiple Notch Adaptive Filter with frequency drift

52

Page 57: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

5 DEVELOPMENTTOOL

TEXUS INSTRUMENTS products, the TMS320C54X Evaluation Module (EVM)

and the Code Composer Studio™ arc used to develop the notch filters.

TMS320C5X DSK was initially chosen for hardware implementation. In order to

reduce the development cycle, software simulation is essential and it is

accomplished by using Code Composer Studio. As the Code Compose• Studio

dose not support the TMS320C5X DSK board, it was replaced by the

TMS320C54X EVM.

5.1 TMS320C54X EVALUATION NODULE

5.1.1 OVERVIEW

The TMS320C54x evaluation module (EVM) is a PC/AT plug-in card that

aiiows user to evaluate the performance of the DSP algorithm using the 'C54x

digital signal processor (DSP). The software can be created and run on board or

expand the system in a variety of ways.

The 'C54x EVM carries a 'C54! DSP on board to allow full-speed verification

of 'C54x code. The 'C54! has 5K bytes of on-chip program/data RAM, 28K

bytes of on-chip ROM, two serial ports, a timer, access to 64K bytes each of

external program and data RAM, and an external analog interface for evaluation

of the 'C54x family of devices for a given application.

53

Page 58: Adaptive notch filter for single and multiple narrow-band

ENS424I ENGINEERING PROJECT 2

5.1.2 KEY FEATURES

The 'C54x EVM has the following features:

• 'C541 operating at 40 MIPS with 128K words of zero wait-state memory

• Voice-quality analog interface to line l/0 or speaker/microphone (user­

selectable)

via standard RCA connectors

• External serial port

• Parallel 110 expansion bus

• Two 16-bit bidirectional host/target communication channels~ one channel

contains 64 words of buffering

• Embedded emulation support based on the IEEE 1149.1 standard

• A single 16-bit !SA half card, mappable to one of four 110 locations

5.1.3 FUNCTIONAL BLOCKS DESCRIPTION

Figure 5.1 shows the basic configuration and interconnects of the 'C54x EVM,

including the host interface, target memory, analog interface, and emulation

interface.

The 'C54x EVM supports a 16-bit PC/ AT-host interface. The PC/AT interface

provides the buffering, host 110 decode, and access control. The PC/AT host

communicates to the 'C54x EVM via 38 16-bit 110 locations. Each 110 location

is defined by the 110 page 0 address described by an offset. The first 32 110

locations support emulation. The remaining six locations support host/target

communications and control.

54

Page 59: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

110 Expansion ~ L

'C54X Serial Pan

.... Serial

~ Control Port SRAM

4 ~ Data

Analog Program/data Address

--po Interface

Emulation Port

Hostffarrget ~ Emulation Interface Interface

I !SA Bus Interface

Figure 5.1 Configuration and Interconnection ofTMS320C54X EVM

The 'C54x interfaces to 64K words of zero wait-state program memory and 64K

words of zero wait-state data memory, in the ~otal of 128K. Host target interface

communicates through two independent channels, Channel A and Channel B.

An external l/0 interface supports 16 parallel l/0 ports, a serial port, and other

l/0 features. A single single channel of voice-band analog input and out-put was

~

provided by the EVM with programmable filtering, scaling, and sampling based

on the TLC320ACOI analog interface circuit. Two RCA connectors provide

analog input and output.

5.2 TMS320C5000 CODE COMPOSER STUDIOTM 1.2

.In this Chapter, a brief description of the Code Composer Studio will be

introduced. This includes the features, benefits and the project development cycle.

55

Page 60: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

5.2.1 INTRODUCTION

Code Composer Studio is a fully integrated suite of easy-to-use DSP software

development tools, incorporating TI's efficient 'C5000 C compiler with the Code

Composer Integrated Development Environment (IDE), DSP/BJQSTM and Real­

Time Data Exchange(RTDXTM )technologies. Code Composer Studio's real-time

analysis and data visualization capabilities, open architecture and advanced code

generation tools greatly reduce the complexity of DSP development, enabling

you to focus your resources and creativity on adding value to your applications.

5.2.2 FEATURES AND BENEFITS

Code Composer Studio has two kinds of tool features, compiler tools and debug

tools.

Compiler tools includes C Compiler, Linker and IDE Simulator and debug tools

includes Code Composer IDE C54x/C55x Emulation Debug Software, RTDX

and DSP BIOS II.

In this project, the Code Composer IDE Simulator is used for our software

development. The Code Composer Simulator could be used to simulate the

actual execution of DSP code without the presence of a DSP chip, in parallel

with hardware development. The advantages are the developers can also use the

simulator for concurrent and field development and the simulator reduces costs

by providing a team of developers access to the development environruent

through a software interface rather than through hardware.

56

Page 61: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

5.2.3 PROJECT DEVELOPMENT CYCLE

In this section, the initial set up of the system and the development cycle will be

discussed in brief.

5.2.3.1 INITIAL SET UP

After installing the TMS320C5000 Code Composer Studio, an initial import

configuration will prompt to add available system to the code composer setup.

The C54x simulator will be chosen and added to the system.

The Code Composer Setup allow you to chose the available board or simulator

types to add onto your system. In this case, the C54xx simulator type was chosen

for our software simulation. In the later stage, the C54xx parallel port will be

chosen to communicate with C54xx EMV board.

This above set up only need to be done once, hence the C54x simulator could be

used anytime.

5.2.3.2 DEVELOPMENT CYCLE

Step I. Project Management system - The C54x simulator provides the Visual

Project Management system which is a fast way of visualizing, accessing, and

manipulating all project files from the same window. In the project view, files

are organized into functional categories such as source files, include files,

libraries, config and GEL script files. All compile options are saved with the

project for easy retrieval.

57

Page 62: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

Step 2. Build and Compile - Once a project file is created, used the compiler and

builder to compile and build the programme. If the programme is successfully

build, a .out file will be created. Load the .out f11c and you could start to run

your programme.

Step 3. Edit within the IDE- Code Composer Studio's™ integrated development

environment (IDE) is similar to MS-Visual C++. The source code editor is tuned

specifically for writing C and DSP a<;sembly code to let you work more

efficiently. The editor is integrated with all other tools in Code Composer

Studio™ like the background build facility, the debugger, etc. This allows you

to easily edit your code and see source and disassembly while coding and

editing.

Step 4. Debug within IDE - Code Composer Studio's integrated debugger has

DSP-specific capabilities and advanced breakpoints to simplify development.

Conditional or hardware breakpoints are based on full C-expressions, local

variables or CPU register symbols. A Probe Point™, a unique feature in Code

Composer Studio™, is a sophisticated form of a breakpoint. It allows you to

define a point in the algorithm where you can perform an oscilloscope-type

function. Unlike a breakpoint, program execution resumes after hitting a Probe

PointTM and performs the connected activity (e.g. inject or extract signal data,

observe signals, execute GEL script). Probe Points TM may be easily set,

removed, or moved to other areas in the algorithm simply by clicking on the

icon in the toolbar.

Step 5. l/0 Data signal - Using Probe Points Execution reaches 1st Probe

Point™: Inject known signal values from a file into DSP target to simulate

58

Page 63: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

conditions. Execution reaches 2nd Probe Point™: Execute GEL function (e.g.

diagnostic test cases) and send a set of memory locations to disk. Execution

reaches Third Probe Point™: Take snap shot of memory and display graphically.

Step 6. Analyze - Profile interactive is a quick measurement of code

performance and how well the DSP target's resources are being used during your

debugging and development session. Profile Points are similar to breakpoints but

instead of halting the target processor, they accumulate hits and collect statistics

on the number of instruction cycles or other events that have elapsed since the

previous profile point was hit. This lets you target high usage areas in your

optimization to produce finely tuned code. Tightly integrated data visualization

also allows you to view data and signals in their native fonnat for easy

interpretation and analysis with many display types. As the program animates, a

snapshot of the signal is taken at each probe point connected to a data

visualization window allowing you to see the signal as it progresses through an

algorithm during debugging.

Step 7. Real time analysis using DSP/BIOS - Probe, trace, and monitor a DSP

application while it runs! These utilities are based on a real-time link and

awareness between the Code Composer Studio TM host environment and the

target. Even after the program has been halted, information already captured

through the real-time analysis tools can provide invaluable insight into the

sequence of events that led up to the current point of execution. Real-time

analysis tools are used later in the development cycle when transitioning from

the debug phase to the runtime phase of development.

59

Page 64: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

60

Page 65: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

6 IMPLEMENTATION

6.1 SOFTWARE IMPLEMENTATION

The simulation was done using Matlab for windows Version 5.3. I for testing the

feasibility of the adaptive algorithm and it had been discussed in Chapter 4. This

will enable verification before actual implementation on the TMS320C54xx

Digital Signal Processing

In this chapter, the software implementation on TMS320C54xx Digital Signal

Processing will be discussed. The sequence, description of the programs and the

graphical results of the simulation will also be discussed in the following section.

The programme listings are attached in Appendix X.

6.1.1 OVERVIEW

The software development system of TMS320C54xx is called Code Composer

Studio. It consists of a set of modules. Figure 6.1 shows the software

development flow diagram. The C compiler accepts C source code and

produces assembly language source code. The assembler translates assembly

language source files into machine language object files. The machine language

is based on common object file format (COFF). The linker combines object files

into a single executable object module. As it creates the executable module, it

performs relocation and resolves external references. The linker accepts

relocatable COFF object files and object libraries as input. While in the

simulation, all the progranunes we.re successfully generated. However, the

hardware interface is yet to be performed.

61

Page 66: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

START \

(

' / j_

C Compiler

• Assembler

• Linker

... Simulation

• Hardware Implementation

~ /

END \

' _/

Figure 6.1 Software Developement Flow

6.1.2 DATA REPRESENTATION

The data representation is in the QI5 format. That is, the dynmaic range- I to

+0.999 corresponds to hexadecimal range of 8000 to 7FFF. The hardware limits

the input range of the noise signals and the output range of the cancelling signals

to a certain range, therefore, a format conversion is needed to comply with the

Q15 format. This involves shifting the data by 8 bits to the left and, then

exclusive OR it with hexadecimal number 8000

62

Page 67: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

6.1.3 PROGRAMME STRUCTURE

In this project, the programme development is using the same sequence of flow

as the Matlab simulation. The sampling frequency is set to 48KHz (using audio

bandwidth of 22.1 KHz). The input signal frequency is fixed at 8KHz and the

number of sampling is limited to 200.

There are 4 different of programs being generated according to the different

signal input, step size and coefficient. The first programme is a Basic Notch

Filter where the coefficient "a" is fixed at a frequency. The second programme is

an Adaptive Notch Filter where the coefficient "a" is adapted according to drift

frequency. The programme also depends on the step size to generate a fast or

slow adaptation. The third programme is a Cascaded Notch Filter where it gives

a better performance than the basic notch filter. The fourth programme is a

Multiple Notch filter where the capability is to notch off two notch frequency.

The programme flow chart of the 4 programs is shown at Figure 6.2

63

Page 68: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

( START

J Initialisation

_± Input Signal Frequency

LMS adaptive alogrithm

+ Output results

... [ END )

Figure 6.2 Programme Flow

Loop for 200 Sample

The programme started with the initialisation of relevant parameters and

variables. and followed by adding an input noise signal to the file 110. Both

input data file and output results will be assigned to a probe point so that we

could view the simulation results in a graphical diagram. The programme will

enter a loop of 200 sample and within the loop, the equation (3.2) is generated

and all the input and output delay variables are assigned to the previous input.

For adaptive algorithm, the equation (3.5) will be used for adapting the input

notch frequency and it is insert immediately after the equation (3.5). Finally, the

output array of 200 sample will bo generated and output to equation (3.3).With

the sampling frequency of 48000Hz, that is, sampling period of 20us, the max

instruction cycle is approximated 1040.

64

Page 69: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

6.1.4 RESULTS

In this section, all the development rcsulls presented here arc generated using the

simulator program, C54x Code Composer Studio (Simulator/CPU).

6.1.4.1 Basic IIR Notch Filter

The basic notch filter is generated usmg equation (3.2). The input signal

frequency is at 8KHz and the radian, r is set to 0.9 or 0.75. In this case, the

coefficient, a is fixed. The graphical result is shown in Figure 6.3 and Figure

6.4.

From the graphs, the results showed that there is a different when r drops from

0.9 to 0.75. It showed that the smaller the value of r, it required lesser sample to

notch off the noise signal frequency but the disadvantages is as the r get smaller,

the notch will be wider.

65

Page 70: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

U.Ob9 ~n 0.521

O.H4

-0.174

-0.521

-0.869

0.656

0.520

0.173 1\

-0.173

-0.520

-0.866

0 222 44.4 66.7 88.9 111 133 156 178 19'3

(1 8, ·5. 71 e-4) [18. ·1. 427126e-4) ---1 "T~.,-:-, ----[Lin iAu<o Sco< ---

U.869

0.521

0.174

-0.174

-0.521

Figure 6.3 Basic Notch Filter with single input, r =0.9

-0.869'}-IWL...JJ...jL.Il..J\-I--.'J,.JI,....h-J.,.J!.---'--,!J..J'I....Il-.-ll..Jl-)J.,JW--.ll,Jl,-jL,JJ.,..Jj,.J-.JL...J,_JW.-1-...JL 0.866

0.520

0.173

·- IJV'fv· ~t------------0.173

-0.520

~.006,+-~~~~--CT~-c;--~~~~--r-~-~--~~-~~~---0 222 44.4 66.7 86.9 111 133 156 178 199

(48.,0.001527)(48,-3.349171e-4) [ITiT..,=---ILin 11\'-'oScole 'I ---

Figure 6.4 Basic Notch Filter with single input, r =0. 75

66

Page 71: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1.7J

1 D4

0.347

-0.347

-1 D4

0.957

0.319

.0.3HI

.0.957

The following figures show muhiplc sinusoidal input noise signal frequency of

4Khz and 8Khz and the radian r value at 0.9 and 0.75. The graphical results arc

shown at Figure 6.5 & Figure 6.6.

From the graphs, the results showed that the frequency input of 8KHz has been

notch off and left the 4KHz signal.

,(

Figure 6.5 Basic Notch Filter with Multiple input, r =0.9

67

Page 72: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1.73

1.041 0.347

-0.347

-1.04

-1.73+-.....L~-h_.ll.-.....,l.--h.,JI.l...-.l.,~.)_.....J~....l.-.L,-......1-..J,.~.L.-..-/-.-'.-~ 1.39

0.834

0.278

-0.278

-0.834

~~'-\-...---~~~--~~~~-----~~~---~""' 0 22.2 44.4 66.7 88.9 111 133 156 178 199

[73. 1.383861 [73, 0.19S06iii '-lr~.,,"--_:.:.:...li.i-> [AUto Scale

Figure 6.6 Basic Notch Filter with multiple input, r =0.75

6.1.4.2 Adaptive IIR Notch Filter

The adaptive notch filter is implemented using equation (3.2) and equation (3.3).

The following figures will show the adaptive notch filter output with the step

size varies from 0.1 to 0.3. A single input signal with a drift of 8Khz to 8.1 Khz

was generated. The r will set to 0.9.

From the figures, it shows that, the smaller the step size the more accurate the

notch frequency but at the expense of a large number of samples. That is, it takes

a longer time to adapt.

68

Page 73: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1:()00

0.600

0.200 . . . . ..

-0.200

-0.600

-1.000

1.65

0.993

~.::: ---Wvv A {W\f~A -

..0.993

-1.65 0 222 44.4 66.7 68.9 111 133 156 178 199

[93. 0.003144) (93. -7.570SS1 •·41 ]Tine lun !Auto S'-olo I

Figure 6. 7 Adatpive Notch Filter with Single input, u =0.1

1.000

ron 0£00

0.200 ---------- . - .. - - - - - - - - . - - - - - ... - - - ---.

-0.200

-0.600

-1000 105

0.99:l

0.331 II fl ~ n f II A

-0.331 IVV ~~v v

-o•93

-1.'.35 0 222 44.4 66.7 68.9 111 133 156 178 199

193.0.00314j) (93;,3.512{)26e·5J lrrn.· IL~ IAutP-S'-ole I

Figure 6.8 Adaptive Notch Filter with Single input, u =0.15

69

r

Page 74: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1.UOO

run 0.600

0.200 . - . - .

-0.200

-0.600

-1 .000

1.65

0.992

0.331

-~· . ·fA ·\(\ - v ..

-0.331

-0.992

-1.65 0 222 44.'1 66.7 68.9 111 133 156 178

~ls"s."u~oo~3~14~4l~IS~s~.-~1.6~~~~~--4'"1----------------riT~;m-,--------lun ~os~~

1.000

0.600

0.200

-011)0

Figure 6.9 Adatpive Notch Filter with Single input, u ==0.2

199

-0 .. 6Do­

·1.000:l---~~~-..-~~-~~~.l.-....:r.:......Wr+-...1.-Wl,-',...:....;.....~-.;..."-' 1.65

0.993

0~31

~.331

Figure 6.10 Adaptive Notch Filter with Single input, u =0.25

70

Page 75: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1.0(1()

l1 I ~ r ~I ~ I 11 I I I ~ 0.600

I J 0.200

. . . . . - . . ...

.0200

-0 600 I -1 DOO

1.65

0.992 I I

o33Hi

ifAA~A ·Vw~· .. ·- ..

-0.331

.0.992

-1.65 0 222 44.4 66.7 88.9 111 133 156 178 199

11 [!J.OJ(100, 0.8SOS42) ' :hne jln !Auto Scale

Figure 6.11 Adatpive Notch Filter with Single input, u ==0.3

71

Page 76: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1

The following figures will show the muhiplc input noise signal of 4Khz and

8Khz. The results of Figu;-c 6.11 and Figure 6.12 will showed that the step size

must be very small (u = 0.1) in order to notch off one of the no be sign<.~!

frequency.

-0.319

-0.957

~\ ~I I \

\ I

Figure 6.12 Adatpive Notch Filter with Multiple inptLI, u =0.1

72

\ r

\

v

Page 77: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

Figure 6.13 Adaptive Notch Filter with Multiple input, u =0. 15

73

Page 78: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

6.1.4.3 Cascade Adaptive IIR Notch Filler

The cascade Jiltcr is implemented by having two section of the basic notch filter

and adapting ut the end of the second section. Figure 6.13 and Figure 6.14 show

simulation result.

When compared this Figure 6.13 with the basic notch filler at Figure 6.3, the

results showed that the cascade notch filter has improved the amplitude as the

sample increase. This proved that the cascade managed to cancel the noise signal

at a faster rate.

0.869 J! " 0.521 )

0.174

-0 174

-0.521

-0.869

0.866

0.520

0.173

·"\!· v.Af\fv·· -0.173

-0.520

.0866 0 22.2 44.4 66.7 88.9 111 133 156 178

I

199

"IGS".'-o".86"'705"""7l""'IGS'."o."OOG'=50"'11"S"J --------I'"Tin"•:----~Li' ;Auto sc;le ·-----·-------------------'---'----'---

Figure 6.14 Cascade Notch Filter with Single input, u =0.25

74

Page 79: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1.00

0.600 ~I 0.~~0 -1

-0 ;l_l)

~ ~ -0.600

-1.00."'r-~.,.,-~r-T'"1~~..-~,.,.--.l--e_,-..-+-...,.J.,-,.....--.l,.-...+-r-r-'-r-.~ 1.63

0.977

o.326 -\~vvVvvv·~---J-· vJ\AAM;,A .. ~--0.326 v v v v

-0.977

-1£3·-t-.-~..,-.-~.,..,-~-r-r.,.,-r-r;~~,--.~..-~.,..-~.,..,-~~ 0 221 44.4 66.7 88.9 1l1 133 156 178 19S

(93,0.0031441(99, -6.157S4e-4J f'""Tin-e ---ir;;"WioScakl

Figure 6.15 Cascade Notch Filter with Multiple input, u =0.25

75

Page 80: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

6.1.4.4 Multiple Notch Filler

The cascaded notch filter is extended to cancel out the multiple sinusoidal

noise interference. It is implemented by having two different notch

frequencies. The simulated output result is shown in Figure 6.15 and Figure

6.16.

The graph showed that the multiple notch filter is able to cancel off multiple

signals.

1.73

1.04

0 .347 ( I - - - . .347

W4

1.73 137

0 B20

0 273 fk"

273 v

'B20

137 0 ~2 «A ~J OOE 111 1m 1~ 1ro 199

;,(99"';""1."'0031=4J'-.(S9"'.'3.'-32861=Je..4=1r--------,,.T"'ine----,u, Vi'ioScole

Figure 6./6 Multiple Notdl Filter with Multiple input

76

Page 81: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

1.93

II

11

11 I ~ i I

116! I

o.Js6 I ~~11/1 I --- -;-- ~·-- ·---I - - -

-0.386

-116 I I 1 \ -1.93

1.92

115

0.383 rv~~v . vvv~\-rArArA -

-0.383

-1.15

-1.92 0 22.2 44.4 66.7 88.9 111 133 156 178 199

11100. 0] [100. ·1100194962] [Troo IG\ ~uto Sc~e

Figure 6.17 Multiple Notch Filter with Multiple input

77

Page 82: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

6.2 HARDWARE IMPLEMENTATION

6.2.1 OVERVIEW

As mention in chapter 5, TMS320C54x EMV board was chosen for the hardware

implementation. The following section will mention the hardware configuration.

6.2.2 CONFIGURATION

The 'C54x EVM board is a PC/AT half-length board that installs in a vacant 16·bit

slot in the PC as shown in Figure 6.17. The C54x EMV board have an analogue

input and output connector at the end of the board. The input signal from the signal

generator will inject into ADC (input connector) and the output results will go

through the DAC(output connector) to display at the oscilloscope.

To communicate from the host to the target board, two things must be initial at the

beginning of the programme. The first initialisation is the sampling clock frequency

and second initialisation is the AIC interrupt routine. Once the initialisation is done,

compile and build the programme. Download the programme to the target board and

inject a single noise signal frequency into the ADC connector and the output from

the oscilloscope will the results.

78

Page 83: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

This will slot into the PC Debugger Tool

Signal Generator or Frequency

Generator Input to the ADC

Oscilloscope Get output from DAC

I

--·'

"'. . .. -~ ' I 1 •• "·•

": -· .. . 'I I

:~: ~: ~: _;_ ·~ ~ j ·:;~_:I·::· ;~ ·;. ;.···II''··. I ;,, ···---~--" ~-

L-"-,-_,-j •••· · .. ~.·-~.",·.,~'"'['. __ .. '"""_,

Figure 6.18 TMS320C54x EMV board connection

79

Page 84: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

PROBLEMS AND RECOMMENDATIONS

In this chapter, some problems and recommendations arc mentioned as below.

a) In phase I, the students encountered concept problem when deriving the

adaptive algorithm, and hence a lot of research have to be done before the

students derived this simplified LMS adaptive algorithm. Due to shortage of

time the students did not further explore on the RLS algorithm. Suggested the

next batch students could work on RLS algorithm.

b) In the inilial stage, the TMS320C5x was chosen as our hardware

implementation but due to some software problems, the students have decided

to source for alternative board. Finally, the students managed to get

TMS320C54x as the replacement. The reason why this board was replaced was,

the TMS320C54x EMV is the second available board in the company.

Suggested that MMC should provide the required board.

c) During the software simulation, the student encountered difficulty with the Code

Composer Studio interface. As this simulator is very new to the student, the

student have to struggle at least I to 2 weeks on the user guidebooks in order to

familiarise with the operation.

d) The auto-tracking effect was not successfully evaluated. The simulation result

did not produce the desired response as describe theoretically in Project

Approach.

80

Page 85: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

c) Due to host and target communication and programming problems, the

hardware communication part was not successfully implemented even the

project deadline is meet.

81

Page 86: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

CUNCLUSION In this project, the simplicily and ease of computation of the LMS algorithm was shown

using IIR structure. The effectiveness of the algorithm on different notch filters was

successfully demonstrated by means of using Matlab and Code Composer Simulator to

genetate the software simulation. The different notch filters consist of basic notch filter,

Adaptive notch filter, Cascade notch filter and Multiple notch filter.

In applying to the TMS320C54x EMV board, unfortunately due to the some hardware

communication and programming problems the students are not able demonstrate the real-

time application.

Though the students have not been able to successfully conclude the project, Much details

about the Code Composer simulators and theoretical hardware (TMS320C54x EMV board)

have been learnt which would otherwise be taken for granted.

82

Page 87: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

REFERENCES

[1] Adaptive Signal Processing

Bernard Widrow Samuel D. Stearns

[2] Digital Signal Processing- A Practical Approach

Emmanuel C. lfeachor Barrie W. Jervis

[3] Digital Filter Design

T.W. Parks C.S. Burrus

[4] An introduction to adaptive filters

DSP: Theory, Applications and Implementation, lEE Younger Members Tutorial Seminar on, 1996. Cowan, C.F.N.

[5] TMSC320C54x Evaluation Module- Technical Reference

Texas Instruments.

[6] PCffMS320C54x Evaluation Module Communication Interface

P. Geremia, Texas Instruments Europe

[7] PCffMS320C54x Evaluation Module Installation Guide

Texas Instruments.

[8] TMS320C54x Code Composer Studio Tutorial

Texas Instruments.

[9] Code Composer Studio User's Guide

Texas Instruments.

[ 10] TMS320C54x Optimizing C Compiler User's Guide

Texas Insuuments.

83

Page 88: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

APPENDIX A - Matlab Simulation Programmes

%Basic Notch filter %Filename :Frcq_RcspR70.m %Description : Plot frc<Juency response with different values of r

fs=48000; %sampling frequency in Hz fc=SOOO; %angular frequency of the notch in Hz w=2*pi*fc/fs;% a=2*cos(w); r=0.70; den::;[ l ,-a*r,r"2]; % Denominator of the response numc=[l,-a,l]; %Numerator fo the response [H,F]=freqz(nume,den,512,fs);% Compute Frequency response HdB=20*logiO(H); plot(F,HdB); xlabel ('Frcquccny in Hz');ylabcl('Gain in dB'); title ('r=O. 70');

%Basic Notch filter %Filename :Freq_RespR75.m %Description: Plot frequency response with different value.c;; of r

fs=48000; %sampling frequency in Hz fc=8000; %angular frequency of the notch in Hz w=2*pi*fc/fs; % a=2*cos(w); r=0.75; den=[l,-a*r,r"-2]; % Denominator of the response nume::::[l,-a,l]; %Numerator fo the response [H,F]=freqz(nume,den,512,fs);% Compute Frequency response HdB=20*1og!O(H); plot(F,HdB); xlabel ('Frequecny in Hz');ylabei('Gain in dB'); title ('r=0.75');

84

Page 89: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Basic Notch Filler %Filename ~Frcq_H.cspRSO.m %Description : Plot frequency response with different values of r

fs=48000; %sampling frequency in Hz fc=8000; %angular frequency of t"1c notch in Hz w=2*pi*fc/fs;% a=2*cos(w); r=0.80; den=[l,-a*r,rA2J;% Denominator of the response nume=[l,-a,l]; %Numerator fo the response [H,F]=frcqz(nume,den,512,fs);% Compute Frequency response HdB=20*log I O(H); plot(F,HdB); xlabel ('Frequecny in Hz');ylabel('Gain in dB'); title ('r=0.80');

%Basic Notch Filter %Filename :Freq_RcspR90.m %Description :Plot frequency response with different values of r

fs=48000; %sampling frequency in Hz fc=8000; %angular frequency of the notch in Hz w=2*pi*fc/fs; % a=2*cos(w); r=0.90; den=[ l,-a*r,r"2]; % Denominator of the response nume=[l,-a,l]; %Numerator fo the response [H,F]=freqz(nume,den,512,fs);% Compute Frequency response HdB=20*logiO(H); plot(F,HdB); xlabel ('Frequecny in Hz');ylabel('Gain in dB'); title ('r=0.90');

85

Page 90: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Basic Notch filter %Filename :Freq_RcspR9S.m %Description : Plot frequency response with different values of r

fs:;;:;48000; %sampling frequency in Hz fc;::;4QOO; %angular frequency of the notch in Hz w=2*pi*fc/fs: % a~2*cos(w);

r;0.95; den=[ I ,-a*r,r"2]; % Denominator of the response nume=[l,-a,IJ; %Numerator fa the response [H,F]~frcqz(nume,dcn,512,fs);% Compute Frequency response HdB~20*log I O(H); plot(F,HdB); xlabcl ("Frcquccny in Hz');ylabcl('Gain in dB'); title ('r;0.95');

86

Page 91: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filename :Singlc_adaptivc .nt %Description: The file plot the output response or the adaptive notch filter % with a single frequency input.

fs=48000; %sampling frequency in Hz fc=8000; %angular frequency of the notch in Hz fi=SOOO; %angular input frequency in Hz w=2*pi*fc/fs; a=2*cos(w); u=O.O I; %step size r=0.90; nT=0:255; x=sin(2 *pi* fi *nT /fs);%input sequence

xl=O; x2=0; yl=O; y2=0; al=O;

for i=l :255,

y(i)=x(i)-a *xI +x2+a *r*y 1-r'r' y2; al=a+2*u*y(i)*(x 1-r*y I);

a=al; y2=yl; yl=y(i); x2=xl; xl=x(i);

end

subplot (2, I, I), plot(x);title ('Single Channel Adaptive Notch Filter'); xlabel('No. of Samples');ylabel('lnput Sequence'); subplot (2,1,2), plot(y);ylabel('Output Sequence');

87

Page 92: Adaptive notch filter for single and multiple narrow-band

ENS424I ENGINEERING PROJECT 2

%Filename :Single_drift.m %Description : The file plot the output response of the adaptive notch iiltcr % with a single frequency input with frequency drift % after 128 samples.

fs=:48000; %sampling frequency in Hz fc==SOOO; %angular frequency of the notch in Hz fi=8000; %angular input frequency in Hz w=2*pi*fc/fs; a=2*cos(w); u=O.O 1; %step size r=0.90; nT=0:127; x=sin(2*pi*fi*nT/fs);%input sequence x(l28:255)=sin(2*pi*fi*nT/fs)% Frequency drift t,y lOOHz

xl=O; %Initialisation x2=0; yl=O; y2=0; al=O;

fori= I :255,

y(i)=x(i)-a* xl +x2+a*r*y 1-r*r*y2; al=a+2*u*y(i)*(x 1-r*y I);

a=al; y2=yl; yl=y(i); x2=xl; xl=x(i);

end

subplot (2,1,1), plot(x);title ('Single Channel Adaptive Notch Filter with Frequency Drift'); xlabei('No. of Samples');ylabel('lnput Sequence'); subplot (2,1,2), plot(y);ylabei('Output Sequence');

88

Page 93: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filename :Single_multi.m %Description :The file plot the output response of the adaptive notch filter % with multiple frc<1ucncy input

fs~8000; %sampling frequency in Hz fc:::::8000; %angular frequency of the notch in Hz fi 1:::::8000; %angular input frequency in Hz fi2:::4000;% Second input frequency in Hz w=2*pi*fc/fs; a=2*cos(w); u=O.O I; %step size r=0.90; nT=0:255; X::;;;sin(2*pi*fi l *nT/fs)+sin(2*pi *fi2*nT/fs);%input sequence

xl=O; %Initialisation x2=0; yl=O; y2=0; al=O;

fori=l:255,

y(i)=x(i)-a*x I +x2+a*r*y I ·r*r*y2; al=a+2*u*y(i)*(x I -r*yl);

a=al; y2=yl; yl=y(i); x2=xl; xl=x(i);

end

subplot (2,1,1), plot(x);title ('Single Channel Adaptive Notch Filter with Multiple ,?requency Input'); xlabel('No. of Samples');ylabel('lnput Sequence'); subplot (2,1,2), plot(y);ylabel('Output Sequence');

89

Page 94: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filename :Singlc_uOOl.m %Description : The file plot the output response of the adaptive notch filter % with a single frequency input and drift after 128 samples.

fs=48000; %sampling frequency in Hz fc=8000~ %angular frequency of the notch in Hz fi=8000; %angular input frequency in Hz W;:::;2*pi*fcifs: a::::2*cos(w); u=O.Ol ~%step size r=0.90; nT=0:127; x=sin(2*pi *fi*nT/fs); %input sequence x(J28:255)=sin(2*pi*fi*nT/fs)% Frequency drift by lOOHz

xl=O; %Initialisation x2=0; yl=O; y2=0; al=O;

for i=l:255,

y(i)=x(i)-a *xI +x2+a *r*y l-r*r*y2; al=a+2*u*y(i)*(x 1-r*yl );

a=al; y2=yl; yl=y(i); x2=xl; xl=x(i);

end

subplot (2, I,!), plot(x);title ('Single Channel Adaptive Notch Filter with u=O.O I'); xlabel('No. of Samples');ylabel('Input Sequence'); subplot (2, 1,2), plot(y);y!abel('Output Sequence');

90

Page 95: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filename :Singlc_uOOS.m %Description: The file plot the output response of the adaptive notch filter % with a single frequency input and drift after 128 samples.

fs=48000; %sampling frequency in Hz fc=8000; %angular frequency of the notch in Hz fi=8000; %angular input frequency in Hz w=2*pi*fc/fs; a=2*cos(w); u=0.05; %step size ~0.90;

nT=O: 127; x=sin(2*pi*fl *nT/fs);%input sequence x(l28:255)=sin(2*pi*ti*nT/fs)% Frequency drift by lOOHz

xl;::;;Q; %Initialisation x2=0; yi=O; y2=0; al=O;

for i=l:255,

y(i)=x(i)-a *xI +x2+a *r*y l-r*r*y2; al=a+2*u*y(i)*(x 1-r*yl);

a=al; y2=yl; yl=y(i); x2=xl; xl=x(i);

end

subplot (2,1,1), plot(x);title ('Single Channel Adaptive Notch Filter with u=0.05'); xlabel('No. of Samples');ylabel('lnput Sequence'); subplot (2, 1,2), plot(y);ylabel('Output Sequence');

91

Page 96: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filename :Single_uOl.m %Description: The file plot the output response of the adaptive notch filter % with a single frcqucnq input and drift after 128 samples.

fs;;48000; %sampling frequency in Hz fc=8000; %angular frequency of the notch in Hz fi=8000; %angular input frequency in Hz w=2*pi*fc/fs; a=2*cos(w); u=O.l; %step .size r=0.90; nT=O: 127; x=sin(2 *pi *fi * nT/fs );%input sequence x(l28:255)=sin(2*pi*fi*nT/fs)% Frequency drift by lOOHz

xI ;;:;Q; %Initialisation x2=0; y!=O; y2=0; al=O;

for i=l :255,

y(i)=x(i)-a*x I +x2+a*r*y l-r*r*y2; al=a+2*u*y(i)*(x 1-r*yl);

a=al; y2=yl; yl=y(i); x2=xl; xl=x(i);

end

subplot (2,1,1 ), plot(x);title ('Single Channel Adaptive Notch Filter with u=O.l '); xlabel('No. of Samples');ylabel('lnput Sequence'); subplot (2,1,2), plot(y);yJabel('Output Sequence');

Page 97: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filename :Singlc_u02.m %Description : The file plot the output response of the adaptive notch filter % with a single frequency input and drift after 128 samples.

fs=48000; %sampling frequency in Hz fc=8000; %angular frequency of the notch in Hz fi=8000; %angular input frequency in Hz w=2*pi*fc/fs; a=2*cos(w); u=0.2; %step size r=0.90; nT=0:127; x=sin(2*pi*fi *nT/fs);%input sequence x(l28:255)=sin(2*pi*fi*nT/fs)% Frequency drift by I OOHz

xI ;::;Q; %Initialisation x2=0; yi=O; y2=0; ai=O;

fori= l ;255,

y(i)=x(i)-a* x l +X2+a*r*y l-r*r*y2; a l=a+2*u*y(i)*(x 1-r*y l);

a=al; y2=yl; yl=y(i); x2=xl; xl=x(i);

end

subplot (2,1,1), plot(x);title ('Single Channel Adaptive Notch Filter with u=0.2'); xlabel('No. of Samples');ylabel('Input Sequence'); subplot (2,1,2), plot(y);ylabel('Output Sequence');

Page 98: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filename :Single_u03S.m %Description :The file plot the output response of the adaptive notch filter % with a single frc<Jucncy input and drift after 128 samples.

fs=48000; %sampling frequency in Hz fc=8000; %angular frequency of the notch in Hz ri=8000; %angular input frequency in Hz w=2*pi*fc/fs; a=2*cos(w); u=0.35; %step size r=0.90; nT=0:!27; x=sin(2*pi *fi*nT/fs);%input sequence x(128:255)=sin(2*pi*fi*nT/fs)% Frequency drift by I OOHz

xl~; %Initialisation x2=0; yl=O; y2=0; ai=O;

fori= I :255,

y(i)=x(i)-a*x I +x2+a *r*y 1-r*r*y2; al=a+2*u*y(i)*(x 1-r*y I);

a=al; y2=yl; yl=y(i); x2=xl; xl=x(i);

end

subplot (2,1,1), plot(x);title ('Single Channel Adaptive Notch Filter with u=0.35'); xlabe!('No. of Samples');ylabel('Input Sequence'); subplot (2, I ,2), plot(y);ylabe!('Output Sequence');

Page 99: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filename :cascadc_ad.m %Description : The fik plot the output response of the cascade adaptive notch filter % with a single frequency input.

f.s:;;48000; %sampling frequency in Hz fc==8000; %angular frequency of the notch in Hz fi=8000; %angular input frequency in Hz w=2*pi*fc/fs; a=2 *cos( w); u=0.25; %step size r=0.90; nT=0:255; x=sin(2 *pi* fi *nT /fs ); %input sequence

xl=O; x2=0; yl=O; y2=0; al=O; zl=O; z2=0;

for i=l:255,

y(i)=x(i)-a*x I +x2+a *r*y l-r*r*y2; z(i)=y(i)-a *y I +y2+a*r*zl-r*r*z2; al=a+2*u*z(i)*(yl-r*z I);

a=al; an(i)=al; y2=yl; yl=y(i); x2=xl; xl=x(i); z2=zl; zl=z(i);

end

subplot (2,1,1), plot(x); title ('Cascade Adaptive Notch Filter with Single Input Frequency'); xlabel('No. of Samples');ylabel('lnput Sequence'); subplot (2, 1,2), plot(z);ylabel('Output Sequence');

95

Page 100: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filename :cascadc_drift.m %Description : The file plot the output response of the cascade adaptive notch filter % with frequency drift.

fs=48000; %sampling frequency in Hz fc=SOOO; %angular frequency of the norch in Hz fi=8000; %angular input frequency in Hz w=2*pi*fc/fs; a=2*cos(w); u=0.25; %step size r=0.90; nT=:l:127; x=sin{2 *pi *fi *nT /fs ); %input sequence x(i28:255)=sin(2*pi*(fi+200)*nT/fs);%Frequency drift by 200Hz x1=0; x2=0; y1=0; y2=0; a1=0; z1=0; z2=0;

for i=1:255,

y(i)=x(i)-a* x 1 +x2+a*r*y 1-r*r*y2; z(i)=y(r)-a*y 1 +y2+a *r*z 1-r*r*z2; a1=a+2*u*z(i)*(y1-r*z 1 );

a=al; an(i)=a1; y2=y1; y1=y(i); x2=x1; x1=x(i); z2=z1; z1=z(i);

end

subp1or (2,1,1), p1ot(x); title ('Cascade Adaptive Notch Filter with Frequency Drift'); x1abe1('No. of Samples');y1abel('lnput Sequence'); subplot (2,1,2), plot(z);ylabel('Output Sequence');

Page 101: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filename :cascadc_multi.m %Description : The file plot the output response of the cascade adaptive notch filter % with mulitplc frequencies input.

fs==48000; %sampling frequency in liz fc;::;:8QOO; %angular frequency or the notch in Hz f1;:::;80QO; %angular input frequency in l-Iz w=2*pi*fc/fs; a=2*cos(w); u=0.25; %step size r=0.90; nT~0:255;

x=sin(2*pi*fi*nT/fs)+sin(2*pi *I OOO*nT/fs);%input sequence

xi~O:

xz~o:

yi~O;

yz~o:

al~O;

zi~O;

z2~;

for i~l:255,

y(i)~x(i)-a*x I +x2+a*r*y 1-r* r*y2; z(i)~y(i)-a *y I +y2+a*r*z l-r*r*z2; al~a+2*u*z(i)*(y 1-r*z I);

a;:al; an(i)~al;

y2~yl;

yl=y(i); x2=xl; xl=x(i); z2=zl; zl=z(i);

end

subplot (2,1,1), plot(x); title ('Cascade Adaptive Notch Filter with Multiple Frequency Input'); xlabei('No. of Samples');ylabel('lnput Sequence'); subplot (2,1,2), plot(z);ylabel('Output Sequence');

97

Page 102: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING I'ROJECT 2

%Filename :cascadc_na.m %Description :The file plot the output response of the cascade adaptive notch filter % with a single frequency input.

fs=48000; %sampling frequency in Hz fc::::SOOO; %angular frequency of tile notch in Hz fi=8000; %angular input frequency in Hz w=2 *pi *fc/fs; a=2*cos(w); u=O.O I; %step size r=0.90; nT=0:255; x=sin(2 *pi* fi *nT/fs); %input sequence

xl=O; x2=0; yl=O; y2=0; %al=O; zl=O; z2=0;

for i=l:255,

y(i)=x(i)-a*x I +x2+a *r*y l-r*r*y2; z(i)=y(i)-a*y I +y2+a *r*z l-r*r*z2; %a! =a+2*u*y(i)*(x 1-r*y l );

%a=al; %an(i)=al; y2=yl; yl=y(i); x2=xl; xl=x(i); %z(i)=y( i)-a*y l +y2+a *r*z l-r*r*z2; z2=zl; zl=z(i);

end

subplot (2,1,1), plot(x); subplot (2,1,2), plot(z);

98

Page 103: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

%Filen:tme :•nultiple_drift.m %Description : The file plot the output response of the multiple channel adaptive notch filter % with ffC(JUCUCY drift.

fs=48000; %sampling frequency in Hz fc I =8000; %angular frequency of the notch in Hz fc2=4000; fi f:;;:;4QOO; %angular input frequency in Hz fi2=8000; wl=2*pi*fcl/fs; w2=2*pi*fc2/fs; al=2*cos(wl); a2=2 *cos( w 2) u=O.OO 1; %step size r=0.90; nT=0:127; x=sin(2*pi*fi 1 *nT/fs)+sin(2*pi*fi2*nT/fs);%input sequence x( 128:255)=sin(2*pi*(fi I+ I OO)*nT/fs)+sin(2*pi*(fi2+ I OO)*nT/fs);%Frequcncy drift by lOOHz xi=O; x2=0; yi=O; y2=0; aii=O; a21=0; zi=O; z2=0;

for i=l:255,

y(i)=x(i)-al*x I +x2+al *r*yl-r*r*y2; all=al +2*u*y(i)*(x 1-r*y I); z(i)=y(i)-a2 *y I +y2+a2* r*z l-r*r*z2; a21=a2+2*u*z(i)*(yl-r*zl );

al=all; a2=a21;

y2=yl; yl=y(i); x2=xl; xl=x(i); z2=zl; zl=z(i);

end

99

Page 104: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

subplot (2, I, I), plot(x); title ('Multiple Channel Adaptive Notch Filter with Frequency Drifl'); xlubci('No. of Samplcs');ylabcl('lnput Sequence'); subplot (2, I ,2), plot(z);ylabci('Output Sequence');

%Filename :multiplc_frcq.m %Description: The file plot the output response of the cascade adapti't'C notch filter % with a single frequency input.

fs=48000; %.sampling frequency in Ht: fcl=SOOO; %nngular frequency of the notch in Hz fc2=4000; fi I =4000; %angulm input frequency in Hz fl2=8000; w 1=2*pi*fc 1/fs; w2=2*pi*fc2/fs; al=2*cos(wl); a2=2*cos(w2) u=O.OO I; %step size r-=0.90; nT=0:255; x=sin(2*pi*fi I *nT/fs)+sin(2*pi*fi2*nT/fs);%input sequence %x(l28:255)=sin(2*pi*(fi+200)*nT/fs);%Frequency drift by 200Hz xi=O; x2=0; yi=O; y2=0; all=O; a2l=O; zl=O; z2=0;

for i=l:255,

y(i)=x(i)-al *xi +x2+al *r*yl-r*r*y2; all=al +2*u*y(i)*(x 1-r*y !); z(i)=y(i)-a2 * yl +y2+a2* r*z 1-r* r*z2; a2l=a2+2*u *z(i)*(y 1-r*z I);

al=a!l; a2=a2l;

y2=yl; yl=y(i); x2=xl; xl=x(i);

!00

Page 105: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

z2=zl; z I =z(i);

end

subplot (2,1,1 ). plot(x); subplot (2,1,2), plot(z);

%Filename :Mulli[lc_nonad.m %Description :The rile plot the output response of the multiple channel adaptive notch filter % with a single frequency input.

fs=48000; %.sampling frequency in Hz fcl=8000; %angular frequency of the notch in Hz fc2=4000; fil=8000; Vrangular input frequency in Hz fi2=4000; w 1=2 *pi*fc 1/fs; w2=2*pi*fc2/fs; nl=2*cos(wl); a2=2*cos(w2) u:::;Q.25; %step size r=0.90; nT=0:255; x=sin(2*pi*fi I *nT/fs)+sin(2*pi*fi2*nT/fs);%input sequence %11( 128:255)=sin(2*pi*(fi+200)* nT/fs);%Frcqucncy drift by 200Hz xl=O; x2=0; yi=O; y2=0; zi=O; z2=0;

for i=1:255,

y(i)=x(i)-al *xI +x2+a I *r*yl-r*r*y2; z(i)=y(i)-a2*y I +y2+a2*r*z 1-r*r*z2;

y2=yl; yl=y(i); x2=xl; xl=x(i); z2=zl; zl=z(i);

end

101

Page 106: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

subplot (2, I, I), plot(x); title ('Multiple Channel Adaptive Notch Filter'); xlabd('No. of Samplcs');ylabcl('lnput Sequence'): subplot (2, I ,2), plot(z);ylabei('Output Sequence');

102

Page 107: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

APPENDIX B - C Language l'rogramming

/*Basic Notch Filter r- 0.9*/

#include <stdio.h>

#definer 0.9 #define a I.O //2cos(2xpix(8KHz/48KHz))

float output[200]; float input[200];

void main( void) {

float y = 0; float x = 0; float xi= 0; float x2 = 0; float yi = 0; float y2 = 0; int i;

printf("input. .. ln ");

for (i=O; i<200; i++) {

x=input[i];

y = x-a*xl+x2+a*r*yl-r*r*y2; y2 = yi; yi =y; x2 =xi; xi= x;

output[i]=y; }

printf("output. .. In");

}

/*Basic Notch Filter r- 0.75*/

103

Page 108: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

#include <stdio.h>

#define r0.75 #define a 1.0 //2cos(2xpix(8KH7J48KHz))

float output[200]; float input[200];

void rnain(void) (

float y = 0; float x = 0; float xi= 0; float x2 = 0; float yi = 0; float y2 = 0; int i;

printf("input. .. \n ");

for (i=O; i<200; i++) (

x=input[i];

y = x-a*xl +x2+a*r*y l-r*r*y2; y2 = yi; yi = y; x2 =xi; xl =x;

output[i]=y;

l

printf("output. .. In");

/*Adaptive Notch Filter u- 0.2*/

I04

Page 109: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

#include <stdio.h>

#definer 0.9 #define u 0.2 //Step Size //#define a 1.0 //2cos(2xpix(8KHz/48KHz))

float output[200]; float input[200];

void main(void) (

float y; 0; float x; 0; float xi = 0; float x2 = 0; float yl; 0; float y2; 0; float a; I; float a! = 0; int i;

printf("input .... ./n ");

for (i;O; k200; i++) (

x=input[i]; y = x-a*xl+x2+a*r*yl-r*r*y2;

a!; a+2*u*y*(xl-r*yl);

y2 = yl; yl; y; x2; xi; xi= x; a= al;

output[i]=y; }

printf("output. ... ./n "); } /*Cascade Notch Filter*/

#include <stdio.h>

105

Page 110: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

#define r 0. 9 #define u 0.25/*Stcp Si:t.c*/

float output[2001; float input[2001;

void rnain(void) {

float q = 0; float q l = 0; float q2 = 0; float y = 0; float x = 0; float xl = 0; float x2 = 0; float yl = 0; float y2 = 0; float a= 1.0; float a!= 0; int i;

printf("input. ... ./n ");

for (i=O; i<200; i++) {

x=input[i);

q = x-a*xl +x2+a*r*q l-r*r*q2; y = q-a*q I +q2+a*r*yl-r*r*y2; a!= a+2*u*y*(ql-r*yl);

I

I

q2 = ql; ql = q; x2 = xl; xl =x; y2 = yl; yl = y;

a=al; output[i)=y;

printf("output. ... ./n ");

106

Page 111: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

/*Mutliplc Notch Filter*/

#include <sldio.h>

#define r 0.9 #define u 0.25 //Step Size

float output[200]; float input[200];

void main( void) { float q = 0; float ql = 0; float q2 = 0; float y = 0; float x = 0; float xl = 0; float x2 = 0; float yl = 0; float y2 = 0; float a= 1.73; float a! =0·

' float b = 1.73; float a2 = 0; int i;

printf("input. ... .In");

for (i=O; k200; i++) {

x=input[i];

q = x- a*xl+x2+a*r*ql-r*r*q2; a!= a+2*u*y*(ql-r*yl);

q2 = ql;

y = q- b*q 1 +q2+b*r*y l-r*r*y2; a2 = b+2*u*y*(ql-r*yl);

ql = q; y2 = yl; yl =y; x2 =xi; xl =x; a= al; b = a2;

107

Page 112: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

output[i]~y;

printf("output... . .In");

108

Page 113: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

/*Single Sine Wave Generator*/

#include <stdio.h> #include <stdlih.h> #include <math.h> #include <conio.h>

float f(float t, unsigned int flag) {

}

flflat y; static float f,a; if(flag!=O) {

}

printf("Sine wave function initialisation."); printf("lnEnter frequency (Hz) : "); scanf("%f',&f); printf("lnEntcr amplitude (0-!6384) : "); scanf("%f',&a);

y=sin(2*3.14*f*t); retum(y);

main() { char ouUile[IO]; float T.y~ int N,n; FILE *fp;

while(!) {

}

printf("lnEnter output filename : "); fflush(stdin); scanf("%s ",out_file ); fp=fopen(out_file,"a"); if (fp!=O) break;

printf("lnCannot open file '%s'. ",out_file);

printf("lnEnter sampling period : "); scanf("%f' ,&T);

while(!) {

109

Page 114: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

printf("lnEntcr no. of output samples : "); scanf("%d",&N); if(N~~oJ

cxit(O); f(O, I);

for (n~O;n<N;n++) [ y~f(n*T,O);

fprintf(fp, "%din" ,(int)y ); )

) exit(O);

)

110

Page 115: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

/*Multiple Sine Wave Generator*/

#include <stdio.h> #include <stdlib.h> #include <rmuh.h> #include <conio.h>

float f(f1oat t, unsigned int flag) { float y; static float f,fl,a; if(flag!=O) { printf(''Sinc wave function initialisation."); printf("\nEnter frequency (Hz) : "); scanf("o/cf',&f);

)

)

printf("\nEntcr frequency (Hz): "); scanf("%f',&fl ); printf("\nEnter amplitude (0-16384): "); scanf("%f',&a);

y=a*(sin(2*3.142*f*t)+sin(2*3.142*fl*t)); retum(y);

void main( void) { char out_file[ 10]; float T,y; int N,n; FILE *fp;

while( I) { printf("\nEntcr output filename : "); fflush(stdin); scanf("%s" ,out_file); fp=fopen( out_file, "a"); if (fp!=O)

break; printf("\nCannot open file 'o/os'.",out_file);

)

printf("\nEnter sampling period : "); scanf("%f',&T);

Ill

Page 116: Adaptive notch filter for single and multiple narrow-band

ENS4241 ENGINEERING PROJECT 2

while( I)

I printf("\.nEntcr no. of output samples ; "); scanf("'/od" ,&N); if (N~~o) cxit(O);

f(O,I );

for (n~O;n<N;n++)

I y~f(n*T,O);

fprintf(fp, "%din" ,(int)y ); )

) cxit(O);

)

112