Professional Documents
Culture Documents
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
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
x(t)
Echo
k.x(t)
(I)
A receiver B transmitter
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.
. 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
The lms filter calculation takes place according to the following algorithm which calculates
at every Ts sampling step:
lmsl.mfile
% LMB adaptive filtering
% Gradient algoritbm
switeb flag
xe zero.(l,n),
b zero.(l,n);
err 0;
[.ya,xO,atr,tal Znitialiaation(T.);
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
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
~
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.
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
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
An improvement factor would simply consist of increasing the filter order if the technical
limits of the material used allow it.
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
rlsl.mfile
, 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
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
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
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 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.
The lms filter calculation takes place according to the following algorithm which calculates
at every Ts sampling step:
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')
stem(f(1:50),ef(1:50
title('e(t) spectrum')
xlabel ( 'Frequency in Hz')
ylabel('Components amplitude')
% 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));
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
5 ~)
~
P D
~4
a
E
as
~ 3 P
Q)
c:
0 P
c- D
E
82 ~
P
Pp
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.
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.
\\
-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
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
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.
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.
rls2.mfile
.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 ~;
.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
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
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
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:
-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
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'
.....
To rll
.....
478 Applications
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.
>
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
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
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
\
-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.