You are on page 1of 28

Application 7

Echo cancellation on a transmission line

1. Transmission line modelling


2. LMS filtering, Imsl S-function
3. RLS filtering, rlsl S-function

This application consists of using the particular characteristic that presents the adaptive
filtering to adjust to its environment when its features evolve in time. We use it to eliminate
the echo produced on a transmission line, for example, a telephone line.
Indeed, because of the line length and its possible loss of adaptability, a given-out signal can
partly be sent back towards its emitter, thus producing an unpleasant echo phenomenon.
The line characteristics, and therefore its shortcomings, are different for every link made; the
use of the adaptive filtering to limit the effect of these shortcomings therefore seems perfectly
justified here.

Transmission line

I_ ,,,,,mit''' f-- -------~--:---OChO~~ ~,,' B ...

1_n";,,, ~I~S_OChO_ _ "--------l1 B " ... ml~, 1

If we study the echo cancellation produced only in the communication direction A post
towards B post, we can implant the adaptive filter as shown on the diagram below.

Transmission line

A transmitter f------------------r---;--~ B receiver

x(t)

Echo
k.x(t)

(I)

A receiver B transmitter

M. Mokhtari et al., Engineering Applications of MATLAB 5.3 and SIMULINK 3


Springer-Verlag London Limited 2000
454 Applications

The x(t) signal and its k x(t) echo are very strongly correlated.
On the other hand, the yet) transmitter and the k x(t) echo signals are greatly decorrelated, so
that the filter adjusting to cancel e(t) from reference x(t) is going to make e(t) tend towards
y(t), thus attenuating the echo signal present on the back line.

1. Transmission line modelling


For transmission line modelling, we limit ourselves to a transmission delay due to the signal
propagation duration.
The echo signal is produced from the received signal, multiplied by an attenuation factor after
having undergone to a light distortion.

The SIMULINK model of the whole is presented below .

. ec hD c.me PI("ij 3
fJe tilt j........ FOIIIIj

~-:=,-.g I

To Fit.
A.,OIIinI

In this first example, the echo signal doesn't undergo a distortion, but only an attenuation
materialised by a variable gain in limits [0, 1].

The transmission time, controlled at 10 ms, is weak in relation to delays which can occur on
long distance links.

This choice is made simply because the "Transport delay" block due to its very
function, will make the output signal appear only after time has elapsed.

The adaptive filter is achieved with the help of an S-function, to which we will pass as
parameters the Ts sampling period, the 1) filter adaptation coefficient and the n filter order.

This lmsl S-function implements an adaptive filter using the gradient algorithm.
Echo cancellation on a transmission line 455

2. LMS filtering, LMS1 Sfunction


In addition to the system parameters, Ts, delta and n parameters are passed to the Ims 1
function.
The initialisation stage conditions to zero the Xe input vector, the h coefficients vector and the
err error scalar and calls the system initialisation function.

The lms filter calculation takes place according to the following algorithm which calculates
at every Ts sampling step:

y(k) = h(k -1) x'(k)

h(k) = h(k -1) +8 e(k) x(k)

e(k) =x,(k) - y(k)

with for this application:

x(k) = u(l) 1st input of the S-function,


x,(k) = e(k) = y(k) + x(k) - x(k) = u(2) 2nd input,
y(k) = x(k) = yf = sys S-function output

lmsl.mfile
% LMB adaptive filtering
% Gradient algoritbm

function [.y.,xO,.tr,t.l lmal(t,x,u,flag,T.,delta,n)


global y xe b err

switeb flag

xe zero.(l,n),
b zero.(l,n);
err 0;
[.ya,xO,atr,tal Znitialiaation(T.);

ca.e 3 % output calculation .tage


xe(l,n) u(2);
yf 0;
for j l:n
yf yf+b(l,j)'*xe(l,n-j+l);
b(l,j) b(l,j)+delta*err*xe(l,n-j +1);
end
err. u(l)-yf;
for j 11n-1
xe(l,j) xe(1,j+l);
end
ay y;
ca (l,2,',9) % non uaed atag
ay. [];
456 Applications


er.roc([aa.2.tr(flag)),
ad

fUDCIticm

.i... . .tm.i.,
fUDaticm [8yW,zO,.tr,t.]

.i aa.caat.tat 0,
.i .u.Di.cBtat 0,
.i . .u.Datput. 1,
. i. ~t 2,
.iz. Dirr.e4through 0,
. i RUaBampl.~ta. 1,
.YW t.8i (.iz )1
xO [],
. t r [II
t [~. Ol'________________________ ______ ____________
~ ~ ~

The A transmitter signal is sinusoidal, of unit amplitude and 300 Hz frequency. The line
introduces a lms delay and the x(t) received signal produces an echo of amplitude
0.833 x(t) added to the feedback signal.
The B transmitter signal is also sinusoidal of unit amplitude, but of 1000 Hz frequency.
For the simulation, the parameters passed to the Imsl function take the following values:
Ts =0.000125s
I8 =0.005
n = 10

The simulation results done over a O.5s duration are represented with the help of the
echol . m file.

echol.mfile
% Bcbo canc.llatioa
load adapt .mat
t ignal.(1,:),
x ignal.(2,1);
x. .ignal.(3,:);
y ignal.(4,1),
yx ignal.(5,:),
.ignal.(6,:);
1 length(t),

% .ignal. tracing
figur.(1)
plot(t(1:floor(1/50,x(lzfloor(1/SO),hold OD
plot(t(1:floor(1/50,y(1:floor(1/S0),bold off,grid
&Xi.([0 0.01 -1.2 1.2)
gtext ('x(t) ) ,gtext ( 'y(t) )
titl.(' x(t) and yet) .ignal )
label ( Time' )
Echo cancellation on a transmission line 457

ylebel ('Magnitude.')

figure (2)
plot(t(l;floor(l/lO,xe(l:floor(l/lO),grid
titleC' xf(t) output filter ')
Klebel ( 'Time' ), ylabel ( 'JIagni tude' )

figure (3)
plot(t(1:floor(l/20,yx(lzfloor(l/20,'r'),grid
title('x(t)+y(t) traa.mitter aignal + echo')
xlabel( 'Time') ,ylabel ('Magnitude')

figure(')
plot(t(ceil(l-l/20):1),e(ceil(l-l/20)zl,grid
title(' eft) aignal '}
Klabel ( Time ' )
ylabel ('Magnitude')
clear t

A and B transmitters signals

x(l) and y(l) signals

x(l) V(I

0.8
A ~( A
A A I ~\ A A
~ \ A
0.6
~ / \

0.4
'/ I \
: 0.2
\ I \
'0
,2
a 1\ I I \
\ I
'2
:iP
:::!: -0.2
\
-0.4
\
IIII
-0.6
I
-0.8
/ IV
-1
V V V \ ~ V V ~ I
V V V
a 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
Time
458 Applications

ld(t) filter output signal


0.6

~
0.4
IV
0.2
IU

11
1
~ 0
a
'2
g>
::!! -0.2

-0.4
~
-0.6

-0.8
o 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
Time

The output filtering slowly adjusts to the k.x(t) signal because of the weak A adaptation
coefficient.
We measure the adaptation time constant for an output signal of about 63% of the final
amplitude i.e., an amplitude of about 0.5 V, and we obtain 't '" 20 ms i.e., with
Ts = 0.125 ms a 160Ts time constant.

y(t)+ Ioc(t): transmlttar signal + echo


2r--------r--------r--------r--------r--------,

1.5 1---,/r-----fl-----*'--+---f----f1f----*'--+----A----j

0.5 tt-1+t+--tt+H--+t-H-+-ttll-t--Ifl++-It---H-H-t-+I-1H--I1t-i

-1.5 f-------1f--+---~----IfI------+!--+---H------'II------H--f

_2~------~------~--------L-------~-------J
o 0.005 0.01 0.D15 0.02 0.025
Time
Echo cancellation on a transmission line 459

The B transmitter signal is strongly disturbed by the added echo.


On the feedback line we get a filtered signal on which it only persists a weak interaction of
the echo signal.

e(l) signal
1.5,...------r-----r-----,-----r------,

0.5 H-lt-ifHHI-H-H-tt-tt--It-tt-it-IHHHH-lHt-lt+t+t-tt-t+1I-Hi-i

-0.5 Hf-++++-*H-I+-IH-HHHli-H-It++-#-+l-H-lrHHH-H-l-4+-+I--H

1 .5 1 - - - - - - ' - - - - - - - 1 . - - - - . 1 . . - - - - - ' - - - - - '


0.475 0.48 0.485 0.49 0.495 0.5
nme

An improvement factor would simply consist of increasing the filter order if the technical
limits of the material used allow it.

Simulation for n 100 =


e(l) signal
1.5,...------r-----r-----,-----r------,

0.5 H-1lt-ifHt-+I-H-H-tt-H--H-tt-tHfHHHi-H-+t-H-+t-ft-fhI-HHH

j
c 0 H-!-H -t++..-l-HH-iH-t-t++t-rhH-i-t+++++I--HH-t-t++t-t+H-i,+++++-t
g'
::::!!

-0.5 Hf-+l--I+-H-tt-.-HIHHHI-tf-H-ti--H-tt-+l-IHHHHlHt-lt-+t-+I

-1 .5 ' - - - - -.......- - - -......- - -.......- - - -......- - - - '


0.475 0.48 0.485 0.49 0.495 0.5
Time
460 Applications

3. RLS filtering, RLS1 S-function


The S-function performing the adaptive filter is achieved at the present time according to the
RLS filtering technique.
In addition to the system parameters, Ts and n parameters are passed to the rlsl function.
The initialisation stage conditions to zero the Xe input vector, the g gain vector, the h
coefficients vector and the err error scalar. The inverse matrix of variances is initialised to
10000 I, with I =identity matrix (n,n). The system initialisation function is then called.
The rls filter calculation takes place according to the following algorithm which calculates
at every Ts sampling period:
k _ Cxx- I (k-l) xT(k)
g( )-I+x(k) Cxx- I (k-l) xT(k)

e(k) = y(k) - x(k) hT (k -1)

h(k) =h(k -1) + g(k) e(k)


y(k) = h(k) x T (k)

with for this application:


x(k)=u(1) 1sl input of the S-function,
x, (k) =e(k) = y(k) +k x(k) - x(k)=u(2) t Jd input,
y(k)=x(k)= yf =sys S-function output.

rlsl.mfile

, RLB adaptive filtering


" Kelt Algori thID

, Global variable.
global yf . . h err i CXX g

ftitch flag

o..e 0
i 21,
CXX 10000*eye(n),
g zero.(l,n);
. . aero.(l,n),
h aero.(l,n),
err 0,
[.y.,xO,.tr,t.J ~tiali.ation(T.);
Echo cancellation on a transmission line 461

% output .tag. calCUlation


.oa 3
. . (l,n) u(2),
g (CXZ. . /(I+. . CXZ. . , , A4aptati~ gain
.rr u(I)-b. . ' , ,. prioz:i U'ror
b b+er.rg, , Coefficient.
cxz CXZ-g. . CXZ, , Correlation . .tz:iz
yf b . . ; , Piltez: output
i i+l;

foz: j Iln-l
(I,j) xe(l,j+1),
end
8y. yf,

, non u d .tag
ca (i,2,.,')
.y [),

otbezwi
rz:oz:(CUDbandl.d flag - ',num2.tz:(flag));
end

% initiali.ation function
funotion C.y.,xO,.tz:,t.) lnitiali.ation(T.)
.iz.. .imaiz ,
.iz . HamContStat 0,
.1z NUmDi.cStat - 0,
.iz . NUmOutput 1,
.iz . HUm%Dput 2,
.1z . Diz:FdtbJ:ougb 0,

.y. -
.iz . HUmSampl.Ttm. 1,

xO [),
.imaiz (.iz ),

.tz: C);
t. - [T. 0),

For the simulation, the parameters passed to the rlsl function take the following values:

{
TS =0.000125s
n = 10

For the same driving signal, the results of the simulation done over a 0.5s duration are
represented with the help of the echo 1 . In file.
We note that the convergence of the filter output signal is faster than with the LMS filter,
which is explained by the important initial value given to the variances matrix. On the other
hand, as the adaptation gain attenuates quickly, it will be more difficult for this filter to follow
the variations of a non-stationary signal so the LMS filter seems better adapted to this type of
application.
462 Applications

xf(t) filter output signal

0.8

0.6 II
0.4

Q) 0.2
I
"Q
.3
.i: 0

,
lij'
:::i:
-0.2
I~
-0.4

-0.6

-0.8

-1
o 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
Time

e(l) signal
1.5.--------.------r-------,,..----.,...-------,

_1.5L.------'-------''-----....L...------L-------'
0.475 0.48 0.485 0.49 0.495 0.5
Time
Application 8

Noise cancellation in a conduit

1. Conduit modelling
2. LMS filtering, lms2 S-function
3. RLS filtering, rls2 S-function
4. Composite noise filtering

This application consists of using an adaptive filter to eliminate the noise produced by a fan in
a ventilation conduit.
The fan generates an acoustic wave which is propagated within the conduit. Moreover this
can amplify some components of the noise while entering in resonance.

rv
Conduit

~
MI<rol Micro 1
x,(tl
v Counlernoise loudspeaker

]I (I)

A daptin
fille r e(l)

The conduit noise is captured by the microphone 1 in order to apply it at the adaptive filter
input, x(t) signal. The y(t) filter output generates the counternoise aiming to cancel the
residual noise in the conduit. As for microphone 2, it captures the residual noise used to adapt
the filter coefficients in order to make e(t) tend to zero.

1. Conduit modelling
The noise produced by the fan presents a fundamental frequency according to the speed
rotation and the blades number. We shall suppose that the fan turns to the 25 r.p.s speed and
includes 6 blades, which corresponds to a 150 Hz noise fundamental frequency.

The noise harmonics are generated by the passage of the fundamental signal through a "look-
up counts" non-linear function. A gain term will symbolise the attenuation undergone by the
M. Mokhtari et al., Engineering Applications of MATLAB 5.3 and SIMULINK 3
Springer-Verlag London Limited 2000
464 Applications

noise between the posItIOn of microphone 1 and the countemoise loudspeaker; the
"transport delay" function will symbolise the propagation time of the sound signal.

The SIMULINK model of the whole is given below.

..""

..""

The adaptive filter is achieved with the help of an S-function, to which we will pass as
parameters the Ts sampling period, the 8 filter adaptation coefficient and the n filter order.

The adaptive filter uses the gradient algorithm, and the corresponding file is called Ims2.m.

2. LMS filtering, Ims2 S-function


In addition to the system parameters, Ts, delta and n parameters are passed to the function
Ims2.
The initialisation stage conditions to zero the xe input vector, the h coefficients vector and
the err error scalar, and then calls the system initialisation function.

The lms filter calculation takes place according to the following algorithm which calculates
at every Ts sampling step:

y(k) = h(k -1) x'(k)

h(k) = h(k -1) + 8 e(k) x(k)

with for this application,

x(k) = u(l) : 1st input of the S-function,


e(k) = u(2) : 2nd input,
y(k) = sys = yf : S-function output.
Noise cancellation in a conduit 465

Ims2.mfile
% LHS Adaptive filt.ring
% Gradient algorithm
function [.y.,xO,.tr,t.] ~l(t,x,u,flag,T.,d.lta,n)
global err h xe yf

nitoh flag,
ca.. 0
xe z.ro.(l,n);
h z.ro.(l,n);
err 0;
[.ya,xO,.tr,t.) XDitiali.ation(T.);
ca.. 3 % OUtput calculation .tag.
x.(l,n) u(l);
yf h*xe',
.rr -u(2);
h h+d.lta*.rr*x.;
for j l:n-l,
x.(l,j) x.(l,j+l);
end
.ya yf;
caa. {l,2,4,9} % Non u d atag
ay [);
oth.rwia
rror(['ODhandl.d flag. ',num2.tr(flag));
and

rnitiali.atioD function
function [.ya,xO,.tr,ta] rnitia1i.ation(Ta)
.i a atm.!z ;
aiz.a.NUmContStat 0;
.i . NUmDiacStat 0,
a! a.HUmOutput. I;
.iz NUmXnputa 2;
.i Dirrdthrough 0;
aiz HumSampl.T1mea 1;
.y tm.i (.i ),
xO [);
.tr [);
t [T. 0);

I
For the simulation, the parameters passed to the lms2 S-function are:
Ts = O.lms
8 =0.0002
n =100
The sampling period chosen is relatively weak compared with the fundamental one, in order
to take into account an important number of harmonics.
466 Applications

The 8 adaptation coefficient chosen is weak to minimise the residual error; on the other hand,
the filter adaptation time constant will be high, which is without consequence as the noise is
stationary.
As the gradient algorithm requires few calculations, compared with the other adaptive
algorithms, we can take the liberty of choosing an elevated order.
The algorithm used requires 2n multiplications with accumulation. As a multiplication with
accumulation can be treated in I MPU cycle with Digital Signal Pocessor "DSP", in our case,
a rapid calculation gives an approached duration of the MPU cycle of !:.... =0.5}1S i.e., a
2n
processor at a frequency of at least 2MHz, which is usual .
The simulation results carried out over a O.1s duration are represented with the help of the
conduitl.m file.

conduicl.m file
% cODduit noia. canc.llation

load con4uJ.t._t
t SignalaCl,:);
x Signala{2,:),
xr Signala(3,:);
Signala(~,:);
y Signala(S,:),

% Signala repreaentation
figure(l)
plot(t,x), grid
uebel ( ''1'u. ' ), ylabel ( 'Ampli tude in V')
ti tle ( Noiae meaaured by microphon. l')
figure(2}
plot(t,y), grid
uabel (''1'u.'), ylabel ('Amplitude in V')
title(' yet) countemoiae ')
figure (3)
plot(t,e), grid
uebel (''1'u.'), ylabel ('Amplitude in V')
ti tIe ( 'Raaidual error meaaured by microphone 2')

% No~ized apectra repreaentation


figure(~)
H 512,
xf aha(fft(x,H*2/HI
t (O:H-l}/(H*'1'.);
at.m(f(lJ50),xt(1150
title('x(t) apectrum')
xlebel ( 'PreQUency in HI:')
yl&bel('componenta amplitude')
figurerS)
1 length (e) ,
et aha(fft(e(1-N:H),H})*2/H,
Noise cancellation in a conduit 467

stem(f(1:50),ef(1:50
title('e(t) spectrum')
xlabel ( 'Frequency in Hz')
ylabel('Components amplitude')

% Power spectral densities


figure (6)
psd(x,N,l/'l'.)
title('x(t) power spectral density')
xlabel ( 'Frequency in Hz')
ylabel( 'Modulus in dB')
figure(7)
psdCe{l-N:N),N,l/'l's)
titleC'eCt) power spectral density')
xlabal ( Frequency in Hz')
ylabal ( Kodulus in dB I )

% Nois.. power.
Px sum(xf. 4 2)/4;
Pe sum(ef. A 2}/4;
diaper' Noise power before filtering. 'num2str(Px));
disp([' Noise power after filtering 'num2str(Pe));
disp([' Xmprovement factor 'num2str(Px/Pe));

Noise measured by microphone 1

0.8
" fl 1\ fI 1\

0.6 -
0.4

> 0.2
~

~
~ 0
a
~ -0.2

-0.4

-0.6
I
i -
-0.8
V V V v
-1
o 0.D1 0.02 0.03 004 0.05 0.06 0.07 0.08 0.09 0.1
nme

The countemoise generated by the filter is in phase opposition to the noise measured by
microphone 1.
468 Applications

y(t) countemoise
0.8

0.6

0.4

II
> 0.2
oS
CD
"C /\
. 0
a. v \
E
-0.2
V
-0.4

-0.6

-0.8
o 0.D1 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
Time

The filter time constant established is relatively high, at about 25 ms, i.e., 250Ts, this being
due to the weak value of the 8 adaptation coefficient.
Residual error measured by microphone 2
0.8

~
0.6
(I,

0.4
~
> I~
.S: 0.2

~! IJllft
l~
CD

~
a. 0 I-I-
N nllR~ , nH~ ~~n~ ~A~ A~
~ W rVVII ,VIIVV nV~
Il/r~
IV~lrij

-0.2 l~ ~ J
If
-0.4 I

-0.6
o 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
Time
Noise cancellation in a conduit 469

The use of the f f t function enables us to obtain the x(t) noise measured and the e(t) residual
noise spectra. The x(t) spectrum makes the fundamental appear at 150Hz amplitude 0.9 and
the harmonics appear bound to the non-linear organ. in particular the harmonic 3.

x(l) spectrum

0.9

0.8

~ 0.7

~0.6
III

E0.5
Q)
c:
o
~0.4
o
Q 0.3

0.2

0.1

100 200 300 400 500 600 700 800 900 1000
Frequency in Hz

The e(t) spectrum is much larger. tending ideally to a white noise.


The amplitude of its lines is weak.
-3
x 10 e(l) Spectrum
6

5 ~)
~
P D
~4
a
E
as
~ 3 P
Q)
c:
0 P
c- D
E
82 ~
P
Pp

>r 0 100 200 300 400 500


Frequency in Hz
600 700 800
rfnm
900 1000
470 Applications

The power spectral density, or distribution in frequencies of powers, is obtained with the help
of the psd function. The power periodic distribution on the x(t) noise odd harmonics thus
appears more clearly.

x(l) power spectral density


20

aJ
'".,
.s
"
:;
"8
20

-40

-60
, I~ I \~
~~I
::::!:
II/IW
eo VI

100

120
o 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency In Hz

The main part of the e(t) residual noise power lies in the 0 to 1000 Hz frequency band.

e(l) power spectral density


55

\\
-60
/
65

~
\

75
~"-
80
'\ r---..
85
o 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency In Hz

The total signals power can be obtained by adding the power of each of the lines of their
spectra.
Noise cancellation in a conduit 471

MOt.e power filter DQ 0.59857


~fore
~i ~ after filtering O.00038~1~
%mpravem.nt faotor 1558.2102

A new simulation is achieved by dividing the adaptation gain by 10. The new parameters
passed to the S-function are Ts =O.lms, 8 =0.002 and n =100.

y(l) counlernoise
0.8

1\ n
0.6

0.4

0.2
>
.E
~
\
0
.'Q."
~ -0.2 ~

-0.4

-0.6

-0.8
o 0.Q1 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
TIme

We note a clear reduction of the filter response time.

Residual elTor measured by the microphone 2


0.6

0.4

0.2

>
.s
-8
0
r~ll\AAn ~AAA
~~V~ IVV yv
AAAfI dhA .AA!J\ A,d. It-A to. ~' ... A
Iyvy IVy IV IIV~ vYT v l"'~ I'" 1 , ... ,. ,
.11 ...


Q.
~ -0.2

-0.4

-0.6

-0.8
o 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
TIme
472 Applications

10 .. e(t) Spectrum
3~X~~----~--~--~~~~--~__- r__- '____~__~

2.5

P
!
'i'i
2 D
E
ll!'"
D
1.5
~ D
8. P
5
(,)
P
D
0.5

OLU~~LUUU~~UU~~UU~~UU~LL~~LUUU~~
frrjlp
o 100 200 300 400 500 600 700 800 900 1000
Frequency in Hz

The global shape of the residual noise spectrum is not modified, but the lines amplitude is
diminished by a factor close to 2.

Noi power before filtering. 0.59857


Noi power after filtering. 9.0992e-005
~rovement factor 6578.2929

The residual noise power has been divided by a factor almost equal to 4. If we go on
diminishing the adaptation gain, we realise that from a certain threshold the residual noise
power increases again.
In practice, the choice of the adaptation gain thus results from a compromise in the light of a
test sequence.

3. RLS filtering, rls2 S-function


The S-function simulating the adaptive filter is now achieved according to the least exact
recursive squares technique.
In addition to the system parameters, Ts and n parameters are passed to the rls2 function.
The initialisation stage conditions to zero the xe input vector I the g gain vector, the h
coefficients vector and the err error scalar. The variances matrix is initialized to 100001,
with I identity matrix (n,n). The system initialisation function is then called.
The RLS filter calculation takes place according to the following algorithm which calculates
at each Ts sampling period:

k _ Cxx- I (k -1) x T (k)


g( ) - 1+ x(k) Cxx-I(k -1) x T (k)
Noise cancellation in a conduit 473

e(k) measured by the microphone 2

h(k) = h(k -I) + g(k) e(k)

y(k) = h(k) x T (k)

with for this application:

x(k) = u(l) : I" input of the S-function,


xr(k) =e(k) =u(2) : 2nd input,
y(k) =sys =yf : S-function output.

rls2.mfile

% RLB adaptive filtering


% IICR a1gorithm

function [.y.,xO,.tr,t.] rl.l(t,x,u,flag,T.,n)


global ~ xe herr i CXx g

.witch flag,
ca.e 0 % xnit1al1.ation .tage
1 nl
CXX lOOOO*eye(n),
g zero.(l,n)1
xe zero. (l,n),
h zero.(l,n),
err 01
[.y.,xO,.tr,t.] Xnit1a11.ation(T.),
ca.e 3 % OUtput calculation .tage
xe(l,n) u(l),
g (Cxx*xe'/(l+xe*CXx*xe''; % Adaptation gain
err -u(2) ; % A priori error
b h+err*g; % Coefficient.
Cxx (CXX-g' *xe*Cxx) ; % Correlation matrix
yf.h*xe'; % OUtput filter
i 1+1,
for j l:n-l
xe(l,j) xe(l,j+l);
end;
.y ~;

ca.e {l,2,',9} % Non u.ed atage


y. [],
otberwi.e
error(['ODbandled flag. ',num2.tr(flag)]);
end
% Xnitiali.ation function
function r.y.,xO,.tr,t.] Xnitiali.ation(T.)
474 Applications

.iz lmaiz J
.iz . NUmCantStat 0;
.iz . NUmDi.oStat 0;
.iz . NUmOutput 1;
.iz RUmXDput 2;
.iz. DirP dthrough 0,

.Y.
.iz NUmSampl.Ttm. 1;

xO [);
.lmaiz (.iz );

.tr [];
t [Ta 0);

SIMULINx. model

condUlIl fII[!] IE:]

ConduRnoise canc ellation


RLS adaptive flHering

Mux

SU'"
To rll o
Oen.t. to,

)(I)

Mux
0(1)

For the simulation, the parameters passed to the rls2 S-function are:
TS == O.lms
{
n == 10
The simulation results carried out on a 0.06 s duration, are represented with the help of the
condui t_2 . m file.

conduiC2. m file
% oonduit noi canc.llation

load conduit.mat
t Signal.(l,:);
x Signal.(2,z);
xr Signal.(3,:);
Signal.(',:);
y Signal.(S,:);
% Signal. rapr antation
figur.(2)
plot(t,y),hold an, plot(t,xr,'r:'), hold off
Noise cancellation in a conduit 475

xlabel ( 'Time' ), ylabel ( 'Amplitude in V')


title(' Noiae and counternoiae')
gtextC'\leftarrowHois.'), gtext('\leftarrowCounternoise')
figure(3), plot(t,e), grid
xlabel ( Time ), ylabel ( , Ampli tude in V')
title('Residual error measured by microphone 2')
% Power spectral densities
figure (6)
N 512; 1 lengthCe); psd(x,N,l/Ts}
title('Power spectral density of x(t)')
xlabel ( Frequency in Hz'), ylabel ( 'Modulus in dB')
figure(7), psd(e(l-N:N),N,l/Ta}
title('Power spectral density of e(t)')
xlabel ( 'Frequency in Hz'), ylabel ( 'Kodulus in dB')
% Powers
xl g abs(fft(x,N})*2/N;
ef - absCfftCe(l-N:N),N)}*2/N;
Px sum(xf. A 2)/4; Pe sum(ef. A 2)/4;
disp([' Noise power before filtering = 'num2str(Px));
disp([' Noise power after filtering 'num2str(Pe)]);
disp([' zmprovamant factor 'num2str(Px/Pe));

Noise and counlemoise


0.8...-----r--....----,r------r--,------,---,----,

II \ I II\ I
tt\ f\ (\ n {\ 1\ f\ f\ ,~ 1\ /f\ f\ AI f\ t'\ f\ {\ f\
I'I {\
0.6

0.4 .
I I
! I.
I
I I II
1
I
\
I I ~Counlemoise
II I I iii .. \
I' i !
I

ill I I j I
> 0.2 , ! .:
.=
<I>
I
"0
.E 0
0.
E
< -0.2

-0.4

-0 .6

_0.8L....----'----'-----'-----'----'---------'-----l
o 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08
Ti me

The residual error converges towards zero in less than 10 ms, which confirms the convergence
speed of the RLS filters on the LMS filters.
476 Applications

Residual error measured by the microphone 2


0.25.-------.-----r----.--------.-----r------,

0.21-- - + - - - 1 - - - - + - - - + - - - - + - - - - 1

0.15 H-- - - - l f - - - - - + - - - - + - - - - I - - - - - I - - - - - - - l

>
.!: 0.1 hf-- - - - l ' - - - - - + - - - - + - - - - I - - - - - I - - - - - - - l
Q)
"C
~
~ 0.051111---H----+----+----+----+---~
-4:

-0.05H-+'f.- - + " ' - - - - - + - - - - + - - - - + - - - - + - - - - - - - l

-0.1 '"'-_ _--L._ _ _....L...._ _ _' -_ _--L._ _ _....L...._ _---'


o 0.01 0.02 0.03 0.04 0.05 0.06
Time

x(t) power spectral density


20

-20

CD
"C \
.!:
-40
CIl
:l
"3 ~
"8 -60
~

W
~
-80 VI
I
-100

-120
o 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency in Hz
Noise cancellation in a conduit 477

e(l) power spectral density


20

30

-40

CD
50
"C
E
~ [,
~ -60
V'
Ii
"3

~ 70 r
j \
~
N
BO
"
90

100
o 500 1000 1500 2000 2SOO 3000 3500 4000 4500 5000
Frequency In Hz

The power spectral density of the residual noise presents a shift of about 50 dB in relation to
the power spectral density of the measured noise.
Hoi.e power before filtering. 0.59S57
Hoi.e ~r after filtering. 0.0001005
Dmprovemant factor 5955.765'

4. Composite noise filtering


A final simulation is considered. by encapsulating a x(t) composite noise formed of the sum
of three signals:
a sinusoidal signal of 2V amplitude and of 150Hz frequency,
a sinusoidal signal of 1V amplitude and of 300Hz frequency,
a square signal of 1V amplitude and of 1000Hz frequency .
. CflrLflwt l' .. r-1 E:i

.....
To rll

.....
478 Applications

The condui t_2 . m file is used to represent the simulation results.

I
For the simulation, the parameters passed to the Irns2 S-function are:
Ts =O.lms
8 =0.0001
n=l00

The adaptation gain takes a relatively weak value here as further on the filter is unsteady.

Noise end counlemolse


4r---r---~--~--~--~--~--~--~--~--,

>
oS

~
,'"
0
Ii
E
<I: -1

-3

_4~--~--~--~--~--~--~--~--~--~--J
o 0.01 0.02 0 0. 3 0.04 0.05 0.06 0.07 0.08 0.09 0.1
Time

Rasldual error measured by mc~ 2


4r---.---,---.----.---.---,--~r_--r_--~__,

3~--~--+---+---+---+---+---+---+---~--~

2H~~+_--~--_+--~----+---4_--~--_4----~~

>
.~

I~ OH&~I~~~~I~IR~UU.RM

-3~~~~~~~~~--~--~--~--~---L--~
o 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1
Time
Noise cancellation in a conduit 479

The composite noise is partly rejected.

x(t) power speclral density


40

20

II) -20
'0
.5
\ I \
,/ \
<II
-40

/\
::l
:;
'8
::::!: -60

\ / \ /
V
-80

-100
~/ ~
-120
o 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency in Hz

e(l) power spectral density


-52
/\

\
-54
V

\ / 1\
-56

-58
II)
'0
.5 -60
\ / \
<II
::l
:;
'8 -62
\ I \
::::!:
,\ I 1\

\\
-64
'\. V
-66

"" ~
-68

-70
o 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency in Hz
480 Applications

The power spectral density of the x(t) noise causes a line to appear at 150Hz and a line at
300Hz due to the sinusoidal signals; the lines at 1000, 3000 and 5000 Hz being due to the
square pulse and to its odd harmonics.

The power spectral density of the residual noise makes the same lines appear, but attenuated
by about 7OdB.

Hoi power before filtering. 3."73


Hoi power after filtering. 0.0050058
t=provement faotor 688.656

You might also like