Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
using
LMS and RLS Algorithms
C
CC BY: $
\
Acknowledgement
I thank God Almighty for his showering his blessings and guiding me in
accomplishing this project.
I am extremely grateful to Shri. S. Anantha Narayanan, Director,
NPOL, for giving me this golden opportunity to do my internship in this
prestigious organization.
I express my heartfelt gratitude to Dr. A. Unnikrishnan, Scientist `G',
Chairman, HRD Council and Mrs. Lasitha Ranjit, Scientist `F', HRD
Coordinator for facilitating the project work and Mr. K. V. Surendran,
Technical Ocer for his support.
It would not have been possible to carry out this event without the
guidance and encouragement of my guide, Mr. Sarath Gopi, Scientist `D',
Naval Physical and Oceanographic Laboratory (NPOL), Kochi. I express my
sincere gratitude towards him.
I also thank one and all, who have been directly or indirectly, involved in
successful completion of this project.
V. A. Amarnath
i
Contents
1 Wiener Filters 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Principle of Orthogonality . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Minimum Mean Square Error . . . . . . . . . . . . . . . . . . . . 3
1.4 Wiener-Hopf Equations . . . . . . . . . . . . . . . . . . . . . . . 4
ii
1 Wiener Filters
1.1 Introduction
Wiener lter is a class of optimum discrete time lters. Wiener lters are
used to solve signal estimation problem of stationary signals. Typically, Wiener
lters are used to lter out noise that has corrupted a signal.
Wiener lters are designed on the basis of the knowledge of the spectral
properties of the original signal and the noise. The design of yields a linear
time invariant lter whose output tends to the original signal. Only if the signal
and the noise are stationary linear stochastic processes, the Wiener lter can be
designed. The Wiener lter works by trying to minimize the mean square error.
Hence, they are also called minimum mean square error lters.
u(n) represents the input to the lter at any discrete time n and
In Fig. (1),
correspondingly y(n) represents the lter output. w(n) represents the impulse
response of the lter. The output, y(n) is used to estimate a desired response,
say d(n). Then, the estimation error, e(n) is dened as the dierence between
the desired response, d(n) and the lter output y(n). The requirement is to
minimize the estimation error, e(n).
Wiener lters considered in this project are all FIR lters, as they are in-
herently stable. FIR lters have only forward paths, whereas IIR lters have
feedforward and feedback paths. Therefore, if design of IIR lters needs to be
carefully done so that the lter does not become unstable.
From Figure 1 on page 1, the lter output, y(n) can be dened by linear
convolution as,
∞
X
y(n) = wi∗ u(n − i), n = 0, 1, 2, . . . (1)
i=0
1
The aim of this lter is to produce an estimate of the desired response, d(n).
So, its required to minimize the estimation error, e(n) given by
To optimize the lter design, the mean square value of e(n) needs to be
minimized. The cost function is, therefore the mean square error given by
C = E [e(n)e∗ (n)]
h i
2
= E |e(n)| (3)
When u(n) is complex, generally lter coecients are also complex in nature.
ith lter coecient wi can be expressed as
wi = ai + jbi , i = 0, 1, 2, . . . (4)
For minimizing the cost function, C, the gradient operator is made use. C
attains a minimum value when all elements of ∇C are simultaneously equal to
zero.
∂C ∂C
∇i C = +j (5)
∂ai ∂bi
= 0 (6)
Under these conditions, the lter is said to be optimum in mean square error
sense. Now, substituting Eq. (3) in Eq. (5),
∂e(n)
= −u(n − i)
∂ai
∂e(n)
= ju(n − i) (8)
∂bi
∂e∗ (n)
= −u∗ (n − i)
∂ai
∂e∗ (n)
= −ju∗ (n − i)
∂bi
2
Using Eqs. (8) in Eq. (7) and on simplication gives,
where eo denotes the optimum estimation error. In words, Eq. (10) states
Corollary:
When the lter operates in its optimum condition, the estimate
of the desired response dened by the lter output yo (n) and the
corresponding estimation error eo (n) are orthogonal to each other.
= d(n) − yo (n)
eo (n)
⇒ d(n) = d(n|Γ
b n ) + eo (n) (11)
where d(n|Γ
b n ) denotes the estimate of the desired response that is optimized
in MSE sense, given the input signal spans the space Γn .
Evaluating mean square value of Eq. (11),
where σd2 is the variance of the desired response, σd2b is the variance of the
estimate d(n|Γ
b n ) and εmin denotes the minimum mean square error. Here, it is
assumed that both the random variables have zero mean. Dening normalized
mean square error = εmin/σd2 . From Eq. (12),
3
From Eq. (13) it can be noted that,
0≤≤1
In section 1.2 on page 1, the necessary and sucient condition for optimum
operation of the lter is specied. Using Eqs. (1) and (2) in Eq. (10) gives,
∞
" !#
X
∗ ∗
E u(n − i) d (n) − wok u (n − k) = 0 (14)
k=0
where wok is the k th coecient in the impulse response of the optimum lter.
From Eq. (14),
∞
X
wok E [u(n − i)u∗ (n − k)] = E [u(n − i)d∗ (n)] (15)
k=0
The rst expectation term, E [u(n − i)u∗ (n − k)] in Eq. (15) is equal to the
autocorrelation function of the lter input for a lag k − i, i.e.,
and the second expectation term, E [u(n − i)d∗ (n)] in Eq. (15) is equal to
the cross correlation between the lter input u(n − i) and the desired response
d(n) for a lag of −i, i.e.,
Using the denitions from Eqs. (16) and (17) in Eq. (15),
∞
X
wok Ruu (k − i) = rud (−i), i = 0, 1, 2, . . . (18)
k=0
The system of equations (18) denes the optimum lter coecients in terms
of the autocorrelation function of the input and the cross correlation between the
lter input and the desired response. These equations are caller Wiener-Hopf
equations.
4
Matrix Formulation of Wiener-Hopf Equations
Let Ruu denote the M × M correlation matrix of the lter input u(n),
T
Ruu = E u(n)uH (n) where u(n) = [u(n), u(n − 1), . . . , u(n − M + 1)] is the
M × 1 input vector. The expanded form of Ruu is,
Ruu (0) Ruu (1) · · · Ruu (M − 1)
∗
Ruu (1) Ruu (0) · · · Ruu (M − 2)
Ruu =
. . .. .
. . .
. . . .
∗ ∗
Ruu (M − 1) Ruu (M − 2) · · · Ruu (0)
The M ×1 cross correlation vector is given by, rud = E [u(n)d∗ (n)], in
expanded form is,
T
rud = [rud (0), rud (−1), . . . , rud (1 − M )]
Thus, the Wiener-Hopf equation given in Eq. (18) can be expressed as,
T
wo = wo0 , wo1 , . . . , wo(M −1)
Hence, Wiener-Hopf equation can be solved to obtain the lter coecients if
the correlation matrix of the input vector u(n) and correlation vector between
input vector u(n) and desired response d(n) is known.
wo = R−1
uu rud (20)
Need for adaptive lters From the previous derivations, its clear that the
Wiener solution is the optimum solution for a given problem. But, once the
solution is obtained, the lter coecients remains xed. But, for most practical
cases the input signal keeps on varying due to several reasons like change in
channel characteristics, external disturbances, etc. Therefore, the need for an
adaptive lter arises. The LMS and the RLS are two basic adaptive lters which
tries to reach the optimum solution at every instant.
5
2 Least Mean Squares Algorithm
2.1 Introduction
The least mean square algorithm is one of the stochastic gradient algorithms.
The LMS algorithm is signicant because of its simplicity. It does not require
measurements of the correlation functions nor does it require any matrix inver-
sion.
The LMS algorithm is a linear adaptive ltering algorithms consisting of two
processes,
During the ltering process, the desired response d(n) is also given along
with the input vector u(n). The lter generates the output d(n|Γ
b n) which is
an estimate of desired response d(n). The estimation error is also computed as
the dierence between the desired response and the lter output. The estima-
tion error e(n) and the input u(n) are applied to the adaptive weight control
mechanism. (See Fig. 2).
In the adaptive process, the the estimation error e(n) is rst scaled by a
factor µ and then the scalar inner product of the estimation error e(n) and the
input u(n − i) is computed for i = 0, 1, 2, . . . , M − 1. The result so obtained
denes the correction δwi (n) applied to the weight wi (n) at iteration n + 1. The
scaling factor µ is a positive quantity and is called the step size parameter.
∗
The LMS algorithm makes use of u(n − i)e (i) as the estimate of element i
which results in a gradient noise due to recursive computation of weights.
6
2.2 Method of Steepest Descent
wi = wi−1 − η∇J(wi−1 )
The algorithms iterates starting from w0 for some η>0 till a xed point is
reached.
LMS algorithm makes use of the steepest descent to compute the lter
weights w(n) which minimizes the cost function. Here, the cost function is
chosen as mean square error, see Eq. (3),
h i
2
C(n) = E |e(n)| (21)
This cost function needs to be minimized to get least mean square error.
Therefore, the partial derivative of the cost function with respect to the indi-
vidual weights of the lter coecient vector is computed.
7
∇C(n) = ∇ {E [e(n)e∗ (n)]}
= 2E [∇ (e(n)) e∗ (n)]
b H u(n) e∗ (n)
= 2E ∇ d(n) − w
∴ ∇C(n) = −2E [u(n)e∗ (n)] (23)
Gradient vector points in the direction of steepest ascent of the cost function.
To nd minimum of the cost function, its required to move in opposite direction
of ∇C(n). Mathematically,
µ
w(n
b + 1) = w(n)
b − ∇C(n) (24)
2
⇒ w(n
b + 1) = w(n)
b + E [u(n)e∗ (n)] (25)
N −1
b [u(n)e∗ (n)] 1 X
E = u(n − i)e∗ (n − i) (26)
N i=0
where N is the number of samples used for the estimate. Going for the
simplest case N = 1,
b [u(n)e∗ (n)]
E = u(n)e∗ (n)
w(n
b + 1) = w(n)
b + µu(n)e∗ (n) (27)
LMS Algorithm
Parameters:
M → lter order
Initialization:
w(0)
b =0
8
Data:
u(n) → M × 1 input vector at time n
d(n) → desired response at time n
Computation:
For n = 0, 1, 2, . . .
b H u(n)
e(n) = d(n) − w
w(n
b + 1) = w(n)
b + µu(n)e∗ (n)
It can be observed that changing µ aects the learning curve. Small µ causes
the curve to take longer iterations to converge to the nal value, whereas larger
µ speeds up the curve. Also, it can be noted that increasing the order speeds
up the convergence of the curve, but the steady state error also increases.
9
Figure 5: Learning curve for µ = 0.01
Previously, LMS lter was referred to as a linear adaptive lter. In real, LMS
is a non linear lter which violates the superposition and homogeneity conditions
satised by a linear lter. Consider a LMS lter with initial condition ŵ(0) = 0,
n−1
X
w(n)
b = µ e∗ (i)u(i) (28)
i=−∞
y(n) b H (n)u(n)
= w (29)
n−1
X
⇒ y(n) = µ e(i)uH (i)u(n) (30)
i=−∞
From Eq. (30), it can be noted that the output y(n) of LMS lter is a non
linear function of the input u(n). The LMS lter can be analyzed using the
weight error vector given by,
w(n)
e = wo − w(n)
b (31)
10
From Eq. (27),
wo − w(n
b + 1) = wo − {w(n)
b + µu(n)e∗ (n)} (32)
H
∗
⇒ w(n
e + 1) = w(n)
e − µu(n) d(n) − w b (n)u(n)
uH (n)
= w(n)
e − µu(n) d(n) − (wo − w(n))
e
− µu(n) d(n) − wo uH (n) + w(n)u H
= w(n)
e e (n)
− µu(n) e∗o (n) + w(n)uH
∴ w(n
e + 1) = w(n)
e e (n) (33)
h i
H
E [µu(n)e∗o (n)] = E µu(n) {d(n) − wo u(n)}
= µ E [u(n)d(n)] − woH E [u(n)u(n)]
= µ rud − R−1
H
uu rud Ruu
∴ E [µu(n)e∗o (n)] = 0 (35)
Using result obtained in Eq. (35) in Eq. (34) and assuming u and w
b are
independent,
11
Using Eq. (37), for n = 0, 1, 2, . . .
h i h i
E W(1)
c = {I − µΛ} E W(0)
c
h i h i
2
E W(2)
c = {I − µΛ} E W(0)
c
. .
.
h i. = .. h i
n
E W(n)
c = {I − µΛ} E W(0)
c (38)
For the lter to be stable, the Eq. (38) should converge. Thus,
|1 − µλ| < 1
∴ µλ > 0 and µλ < 2
2
or, µ>0 and µ< (39)
λmax
where λ represents the eigen values of the autocorrelation matrix Ruu .
Eq. (39) dictates the selection of step size parameter µ in the LMS algorithm.
w(n
b + 1) = w(n)
b + µu(n − 1)f (n)
f (n) = u(n) − w(n)u(n
b − 1)
The algorithm is implemented in Matlab and the code is given in the ap-
pendix, section.(2.7). The observations are given below.
12
Figure 6: Transient behavior of weight w(n)
b for µ = 0.05
The blue curve shows how the weight varies with number of iterations. The
curve appears like really noisy. Therefore, its dicult to obtain the value to
which the curve is actually tending to. The experiment is repeated a number of
times, here for 100 times. Then, the ensemble weight is calculated and plotted
against number of iterations. The red curve shows this. Here, it can be observed
that the weight tends to a particular value, close to the desired one.
It is also observed that changing µ aects the plot. Decreasing µ causes the
curve to take longer iterations to reach the nal value, whereas increasing µ
speeds up the curve.
13
2.6 LMS algorithm Example - FIR lter
Here, the LMS algorithm is used to estimate the lter coecients of a FIR
lter. The desired response is found using the given transfer function of the
lter.
1 1
F (z) = 1 + z −1 + z −2
2 5
The Matlab code is included in the appendix in section (2.7)
14
(a) w(1)
(b) w(2)
(c) w(3)
15
2.7 Appendix
Code - AR process estimation
clear all;
clc;
EW = zeros(1, 1000);
EF = zeros(1, 999);
for j=1:100
for i=2:999
f(i) = u(i) - w(i)*u(i-1);
w(i+1) = w(i) + mu*u(i-1)*f(i);
end
end
figure(1);
clf;
hold on;
plot(w);
plot(EW,'r');
figure(2);
clf;
hold on;
plot(EF.^2,'r');
16
EE = zeros(1, N);
EW = zeros(ord, N);
WE = zeros(ord, N);
for j=1:100
clear w;
x = rand(1,N); %input
y = filter(num,den,x); %desired output
for i=1:ord
w(:,i) = 0;
end
X = zeros(1,ord);
X(1) = x(1);
X = X';
w = w';
z(2) = w(:,1)'*X;
e(2) = y(2) - z(2) ; %causal
w(:,2) = w(:,1) + mu*X*conj(e(2));
for i=2:N-1
X = circshift(X,[1,0]);
X(1) = x(i);
z(i+1) = w(:,i)'*X;
e(i+1) = y(i+1) - z(i+1);
w(:,i+1) = w(:,i) + mu.*X.*conj (e(i+1));
end
EE = (EE*(j-1)+e.^2)/j;
EW = (EW.*(j-1)+w)./j;
end
figure(1);
plot(EE.^2,'b');
% for j=1:ord
% figure(j+1);
% hold on;
% plot(EW(j,:),'b');
% plot(w(j,:),'r');
% end
17
3 Recursive Least Squares Algorithm
3.1 Introduction
n
X
C= λn−i e2 (i) (42)
i=0
n
∂C (wn ) X ∂e(i)
= 2 λn−i e(i) (43)
∂wn (k) i=0
∂wn (k)
Xn
= 2 λn−i e(i)u(i − k)
i=0
For minimum value of the cost function C, Eq. (43) is equal to zero,
n
X
⇒ λn−i e(i)u(i − k) = 0
i=0
n
X M
X
λn−i d(i) − (wn (j)u(i − j)) u(i − k) = 0
i=0 j=0
18
M
( n
) n
X X X
n−i
wn (j) λ u(i − j)u(i − k) = λn−i d(i)u(i − k) (44)
j=0 i=0 i=0
n
X
rud (n) = λn−i d(i)u(i)
i=0
n−1
X
= λn−i d(i)u(i) + d(n)u(n)
i=0
rud (n) = λrud (n − 1) + d(n)u(n) (46)
Also,
n
X
Ruu (n) = λn−i u(i)uT (i)
i=0
n−1
X
= λn−i u(i)uT (i) + u(n)uT (n)
i=0
Ruu (n) = λRuu (n − 1) + u(n)uT (n) (47)
−1 −1
(A + U CV ) = A−1 − A−1 U C −1 + V A−1 U V A−1 (48)
where A is n × n, U is n × k , C is k × k and V is k × n.
In this case, A → λRuu (n − 1), U → u(n), C → I and V → uT (n), on
substitution in Eq. (48),
−1
R−1 λRuu (n − 1) + u(n)uT (n)
uu (n) =
= λ−1 R−1
uu (n − 1) − λ
−1 −1
Ruu (n − 1)u(n)
−1 −1
−1 T
T
u (n)λ−1 R−1
1 + u (n)λ Ruu (n − 1)u(n) uu (n − 1)
19
⇒ P(n) = λ−1 P(n − 1) − g(n)uT (n)λ−1 P(n − 1) (49)
−1
= λ−1 P(n − 1)u(n) 1 + uT (n)λ−1 P(n − 1)u(n)
g(n) (50)
on simplifying,
Hence, Eq. (52) gives the update equation for the RLS algorithm.
The
correction factor at time n−1 is given by α(n)= g(n) d(n) − uT (n)wn−1 and
uT (n)wn−1 is the a priori error calculated before the lter is updated.
RLS Algorithm
Parameters:
M → lter order
λ→ forgetting factor
Initialization:
w(0)
b =0
P(0) = δ −1 I where I is a (M + 1) × (M + 1) identity matrix
Data:
u(n) → M × 1 input vector at time n
d(n) → desired response at time n
20
Computation:
For n = 0, 1, 2, . . .
α(n) = d(n) − w(n − 1)T x(n)
−1
g(n) = P(n − 1)x(n) λ + xT (n)P(n − 1)x(n)
P(n) = λ−1 P(n − 1) − g(n)xT (n)λ−1 P(n − 1)
w(n) = w(n − 1) + α(n)g(n)
21
4 Applications of LMS and RLS Algorithms
4.1 Adaptive Noise Cancellation
The traditional method for noise cancellation makes use of the concept of
the notch lters. Notch lters removes a particular frequency of noise for which
it is designed for. These lters are designed with prior knowledge of the signal
and the noise. The lters have xed weights. But, practically when the noise
characteristics are not known, adaptive noise cancellers can help. Adaptive
lters have the ability to adjust the lter coecients by itself and doesn't require
the prior knowledge of signal or noise characteristics.
Adaptive noise cancellers is a dual input system. The primary input is the
information signal and a noise that are uncorrelated to each other. The sec-
ondary input is called the reference input which supplies a correlated version of
the noise. Noise cancellation works by ltering the reference input and then sub-
tracting from the primary input to give the information signal. This eliminates
or attenuates the noise content in the primary input.
Concept: Fig. (11) shows the typical noise cancellation system. s is the signal
transmitted from the transmitter and n0 is the noise added by the channel. s
and n0 are uncorrelated. n1 is another source of input which is uncorrelated to
s but correlated to n0 . n1 is ltered to produce an output y which is
The noise
an estimate of n0 . y is subtracted from the primary input s + n0 to
The output
give the system output z = s + n0 − y . The noise n1 is processed by an adaptive
lter which tries to minimize the error signal continuously. Here, the objective
is to produce a system output z that best t in to the transmitted signal s.
This is accomplished by feeding the system output z as the error signal e to
the adaptive lter. The adaptive algorithm actually tries to minimize the total
system output power.
Problem: A music le corrupted with drum beats is given. The objective is
to cancel out the drum beats and generate a le which is noise free. Also given
22
a le containing drum beats which is uncorrelated to the music but correlated
to the drum beats in the rst le.
Here, the music le is taken as the primary input and the second le with
drum beats is taken as the secondary input. Then, the adaptive noise canceller is
implemented using the LMS and the RLS algorithms as explained next sections.
The adaptive lter may use the LMS algorithm for estimating the lter
coecients. The LMS algorithm explained in section (2.3) is implemented for
noise cancellation. This is made use to process a noise corrupted audio le and
to cancel out the noise present in it. This simulated use Matlab, the code is
given in the appendix, section (4.3).
The plots in Fig. (12) below shows the power spectral density of the noise
corrupted input signal and the noise cancelled output signal.
(a) PSD of input noise corrupted signal (b) PSD of the output signal
For adaptive noise cancellation, the RLS algorithm given in section (3.2) can
also be used. When the RLS algorithm is used to estimate the lter coecients,
its observed that the noise cancellation occurs much more faster and the steady
state error is also lesser. From the qualitative analysis of the output signal, it
can be concluded that the performance of the RLS lters are better compared
to the LMS lters.
The Matlab code for the RLS noise cancellation is given in the appendix,
section (4.3). The plots in Fig. (13) below shows the power spectral density of
23
the noise corrupted input signal and the noise cancelled output signal.
(a) PSD of input noise corrupted signal (b) PSD of the output signal
Causes:
Bandlimited Channels: In most practical cases the channels are
bandlimited. Therefore, the signal frequencies below and above
the cuto frequencies are attenuated by the channel. This af-
fects the shape of the pulse received. As in frequency domain,
higher frequencies are attenuated, the pulse spreads in time do-
main. This causes the symbol to interfere with the neighbouring
symbols.
24
propagate through various paths owing to reection, refraction,
ionospheric reection. This results in arrival dierent versions of
the signal at dierent times. This delay may cause a symbol to
interfere with other symbols resulting in ISI.
Adaptive Equalizer:
At receiver the adaptive equalizer tries to undo the eects of the channel on
the signal before decoding the information from the received signal.
The transmitter sends a sequence of data before the actual message is trans-
mitted, called the training sequence. This sequence is already known to the re-
ceiver. Therefore, the receiver tries to estimate transfer function of the channel,
from the received sequence. The adaptive lter the plays the role for estimating
the training sequence. The known sequence is taken as the primary input and
the received sequence is chosen as the secondary input. The error signal is the
dierence between the known sequence and the ltered sequence. The adaptive
algorithm tries to minimize the error signal.
Once the channel transfer function is known, linear convolution with the
received sequence gives the estimate of the transmitted sequence. The delay
due to the convolution operation have to be taken care of.
Here, the adaptive equalizer is implemented using the LMS algorithm given
in section (2.3). For a channel with the transfer function h(n) the adaptive
equalization is implemented.
25
The channel transfer function is given as
(
1 2π
2 1 + cos 3 (n − 2) n = 1, 2, 3
h(n) =
0 otherwise
The Matlab code for the same is given in appendix, section (4.3). Fig. (14)
shows the variation of bit error rate (BER) with inverse of the noise variance
(1/σn
2
).
4.3 Appendix
Noise Cancellation using LMS algorithm
%lms code
clear all;clc;
[y,fs,nbit] = wavread('file4_i.wav'); %noise corrupted file
N = length(y);
[u,fs,nbit] = wavread('file4_n.wav'); %reference input
ord = 11;
mu = 0.1;
w = zeros(ord,1);
X = zeros(1,ord);
X(1) = u(1);
X = X';
z = w'*X;
e(2) = y(2) - z ; %causal
w = w + mu*X*conj(e(2));
for i=2:N-1
X = circshift(X,[1,0]);
X(1) = u(i);
e(i+1) = y(i+1) - w'*X;
w = w + mu.*X.*conj (e(i+1));
end
periodogram(y,[],'onesided',512,fs);
figure(2);
periodogram(e,[],'onesided',512,fs);
wavwrite(e',fs,nbit,'file4_f.wav');
26
del = 0.005;
lam = 1;
w(:,1) = zeros(ord,1);
X = zeros(ord,1);
X(1) = u(1);
P = eye(ord)./del;
pi = P*X;
k(:,2) = pi./(lam+X'*pi);
e(2) = y(2) - w(:,1)'*X;
w(:,1) = w(:,1) + k(:,2)*conj(e(2));
P = lam'*P-lam'*k(:,2)*X'*P;
for i=2:N-1;
X = circshift(X,[1,0]);
X(1) = u(i);
pi = P*X;
k(:,i+1) = pi./(lam+X'*pi);
e(i+1) = y(i+1) - w(:,1)'*X;
w(:,1) = w(:,1) + k(:,i+1)*conj(e(i+1));
P = lam'*P-lam'*k(:,i+1)*X'*P;
end
wavwrite(e',fs,nbit,'rls4.wav');
periodogram(y,[],'onesided',512,fs);
figure(2);
periodogram(e,[],'onesided',512,fs);
27
y = awgn(y_free,SNR);
w = zeros(ord,1);
X = zeros(1,ord);
X(1) = x(1);
X = X';
z = w'*X;
e(2) = y(2) - z ; %causal
w = w + mu*X*conj(e(2));
for i=2:N/4
X = circshift(X,[1,0]);
X(1) = x(i);
e(i+1) = y(i+1) - w'*X;
w = w + mu.*X.*conj (e(i+1));
end
dec = conv(w,y(N/4:N));
for i = 1:length(dec)
if dec(i)<0
dec(i) = -1;
else
dec(i) = 1;
end
end
res = dec(3:.75*N+2);
c(1,:) = x((N/4)+1:N);
c(2,:) = res;
count = 0;
for i = 1:.75*N
if c(1,i)~=c(2,i)
count = count + 1;
end
end
BER = count/(.75*N);
v(k) = (10^(SNR/10))/sig_pow;
b(k) = BER;
SNR = SNR + .3;
k = k + 1;
if cc==1
B = b;
end
end
B = (B*(cc-1)+b)/cc;
end
plot(v,B);
28
References
[1] Simon Haykin, Adaptive Filter Theory 4th Ed., Pearson Education
[2] Bernad Widrow, John R. Glover, John M. McCool, John Kaunitz, Charles
S. Williams, Robert H. Hearn, James R. Zeidler, Eugene Dong and Robert
C. Goodlin, Adaptive Noise Cancellation: Principles and Applications,
Proceedings of IEEE, vol. 63, pp. 1692-1716, Dec. 1975
[3] Simon Haykin, Communication Systems 4th Ed., Wiley & Sons Inc.
[5] Wikipedia Foundation Inc.: Wiener Filter, LMS Filter, RLS Filter
29