0% found this document useful (0 votes)
53 views

Assignment 5: Aait School of Electrical and Computer Eng. Communications Engineering (CNT), PG

The document appears to be an assignment submission for an adaptive filtering course. It includes: 1) A recording of the author's speech signal to be used as the desired signal in an adaptive filtering problem. 2) Implementation of an adaptive filter using the LMS algorithm to estimate the input signal from the desired signal, assuming a filter order of 3. 3) Implementation of an adaptive filter using the recursive least squares (RLS) algorithm to estimate the input signal from the desired signal, also assuming a filter order of 3. 4) Discussion of how the filter coefficients change with time for the LMS and RLS adaptive filters.

Uploaded by

Yonas D. Ebren
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Assignment 5: Aait School of Electrical and Computer Eng. Communications Engineering (CNT), PG

The document appears to be an assignment submission for an adaptive filtering course. It includes: 1) A recording of the author's speech signal to be used as the desired signal in an adaptive filtering problem. 2) Implementation of an adaptive filter using the LMS algorithm to estimate the input signal from the desired signal, assuming a filter order of 3. 3) Implementation of an adaptive filter using the recursive least squares (RLS) algorithm to estimate the input signal from the desired signal, also assuming a filter order of 3. 4) Discussion of how the filter coefficients change with time for the LMS and RLS adaptive filters.

Uploaded by

Yonas D. Ebren
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Yonas Desta

AAiT
School of Electrical and Computer Eng.
Communications Engineering (CNT), PG
ID-GSR/3116/12, Regular
[email protected]

Assignment 5
ECEG 6306 : SDSP : Mr. Bisrat Derebssa
Due MONDAY, may 15, 2020

Contents
Problem 1 2
(a) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
(b) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
(c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
(d) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
(glossary) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1
Yonas Desta ECEG 6306: Assignment 5

Problem 1
Consider an observed random signal x(n) is generated by passing a desired signal through a certain
system

x(n) = 0.7y(n) − 0.5y(n − 1) + w(n) Where w(n) ≈ W GN (0, sigma2 ), (Substitute your ID number
divided by 10, 000 for σ 2 .Example if your ID is GSE/1234/11, then σ 2 = (0.1234).

You are required to implement an adaptive filter to identify the system from observation of x(n) and
y(n). By using MATLAB obtain the following.

(a)
Record a 10 second duration of your speech signal as y(n) and generate the random signal x(n) for 0n500.
Use a sampling frequency of 8kHz. Then x(n) is observed and you are required to design an adaptive filter.

Answer
By using the audiorecord comand on mathlab we can record directly the voice, but due to the
inability of my laptop’s sound card, i rather have recorded my speech on my phone and get the
audiodata directly from the recorded speech by using audioread command.
The Recorded sound is found on archived folder.
The matlab code for the above adaptive filter design will be shown bellow.

rls = dsp.RLSF ilter(0 Length0 , 21,0 M ethod0 ,0 HouseholderRLS 0 );


signal,fs= audioread(’RecordedSound.wav’);
v=random(’norm’,1,sqrt(0.3116),1,length(signal));
signal=signal(:,1);
for n = 2:length(signal)
x=0.7*signal(n)-0.5*signal(n-1)+v;end
filt2 = dsp.FIRFilter(’Numerator’,fir1(10, [.5, .75]));
x = filt2(x)’;
y,e= rls(signal,x);
figure()
subplot(3,1,1)
plot([1:length(signal)]/fs,signal);
xlabel(’time’);
title(’signal(n)’);
subplot(3,1,2)
plot([1:length(x)]/fs,x);
xlabel(’time’);
title(’x(n)’);
subplot(3,1,3)
plot([1:length(y)]/fs,(1/abs(min(y)))*y);
xlabel(’time’);
title(’LMS y(n)’);

Problem 1 [(a)] continued on next page. . . Page 2 of 8


Yonas Desta ECEG 6306: Assignment 5 Problem 1

(b)
Implement the LMS adaptive algorithm to estimate x(n) from y(n) assuming the filter order is 3 and
discuss how the adaptive LMS filter coefficient changes with time.
Answer
In order to implement the LMS , we use the mathlab code bellow and the coefficients will be
computed by the following equation.

For n = 0, 1, 2, . . .
ŷ(n) = cH (n − 1)x(n).....F iltering
c(n)=y(n)- (n).....error formation
c(n)=c(n-1)+2µx(n)e∗ (n)...coeffcient updating

The mathlab code for LMS and normalized LMS filter is written bellow.

[signal, f s] = audioread(0 RecordedSound.wav 0 );


fs=8000;
v = random(’norm’,1,sqrt(0.3116),1,length(signal));
signal = signal(:,1);
for n = 2:length(signal)
x(n) = 0.7*signal(n)-0.5*signal(n-1); end
d = x + v;
µ = 0.1;
µ2 = 0.8;
a = 0.01;
λ = 0.999;

Problem 1 [(b)] continued on next page. . . Page 3 of 8


Yonas Desta ECEG 6306: Assignment 5 Problem 1

M = 3;
tic [e1, y1, w1] = myLMS(d, v, mu, M); toc
figure()
subplot(3,1,1)
plot(e1)
title(’Least Mean Square Adaptive Filter Output ’)
ylim([-0.11,0.11])
subplot(3,1,2)
plot(e2)
title(’Normalized Least Mean Square Adaptive Filter Output’)
ylim([-0.11,0.11])

The two functions called in the above script are found on the glossary.

The LMS filters adapt their coefficients until the difference between the desired signal and the
actual signal is minimized (least mean squares of the error signal). This is the state when
the filter weights converge to optimal values, that is, they converge close enough to the actual
coefficients of the unknown system. This class of algorithms adapt based on the error at the
current time.

Problem 1 continued on next page. . . Page 4 of 8


Yonas Desta ECEG 6306: Assignment 5 Problem 1 (continued)

(c)
Implement the recursive LS adaptive algorithm to estimate x(n) from y(n) assuming the filter order is 3
and discuss how the adaptive recursive LS filter coefficient changes with time.
Answer
In order to implement the recursive LS , we use the mathlab code bellow and the coefficients will
be computed by the following equation.

For n = 0, 1, 2, . . .
ŷ(n) = cH (n − 1)x(n)
c(n)=y(n)- (n)
c(n)=c(n-1)+g(n)e∗ (n)

where

g(n) = (ĝλ (n))/(α̂λ (n))


ĝλ (n) = p(n − 1)x(n)
(
αλ (n) = λ + ĝλ H)(n)x(n)
(
P (n) = λ−1 [P (n − 1) − g(n)ĝλ H)(n)]
The mathlab code for LMS and normalized LMS filter is written bellow.

[signal, f s] = audioread(0 RecordedSound.wav 0 );


fs=8000;
v = random(’norm’,1,sqrt(0.3116),1,length(signal));
signal = signal(:,1);
for n = 2:length(signal)
x(n) = 0.7*signal(n)-0.5*signal(n-1); end
d = x + v;
mu = 0.1; mu2 = 0.8; a = 0.01; lamda = 0.999; M = 3;
tic [e3, y3, w3] = myRLS(d, v,lamda,M); toc
figure() subplot(3,1,3) plot(e3)
ylim([-0.11,0.11])
title(’Recursive Least Square Adaptive Filter Output’) ylim([-0.11,0.11])
sound(e3)

The function called on the above script is found on the glossary.

The RLS adaptive filter algorithm recursively finds the filter coefficients that minimize a weighted
linear least squares cost function relating to the input signals. These filters adapt based on the
total error computed from the beginning.
It minimize the cost function, C(n) by appropriately selecting the filter coefficients w(n) and
updating the filter as the new data arrives.

Problem 1 continued on next page. . . Page 5 of 8


Yonas Desta ECEG 6306: Assignment 5 Problem 1 (continued)

(d)
Compare LMS with RLS adaptive algorithm.
Answer
Comparison:
Least mean squares (LMS) algorithms represent the simplest and most easily applied adaptive
algorithms. The recursive least squares (RLS) algorithms, on the other hand, are known for
their excellent performance and greater fidelity, but they come with increased complexity and
computational cost.
Compared to the LMS algorithm, the RLS approach offers faster convergence and smaller error
with respect to the unknown system at the expense of requiring more computations. The General
comparision scheme for the above two filter types can be summerized as follows.

Problem 1 continued on next page. . . Page 6 of 8


Yonas Desta ECEG 6306: Assignment 5 Problem 1 (continued)

(glossary)
Answer
1. myRLS function.

f unction[e, y, w] = myRLS(d, x, lamda, M )


Ns = length(d);
if (Ns ¡= M)
print(’error’);
return;
end
if (Ns = length(x))
print(’error’);
return;
end
I = eye(M);
a = 0.01;
p = a * I;
x = x’;
w1 = zeros(M,1);
y = zeros(Ns, 1);
e = zeros(Ns, 1);
xx = zeros(M,1);
for n = 1:Ns
xx = [x(n); xx(1:M-1)];
k = (p * xx) ./ (lamda + xx’ * p * xx);
y(n) = xx’*w1;
e(n) = d(n) - y(n);
w1 = w1 + k * e(n);
p = (p - k * xx’ * p) ./ lambda;
w(:,n) = w1;
end

Problem 1 [(glossary)] continued on next page. . . Page 7 of 8


Yonas Desta ECEG 6306: Assignment 5 Problem 1

2. myNLMS function.

f unction[e, y, w] = myN LM S(d, x, mu, M, a)


Ns = length(d);
if (Ns ¡= M)
print(’error’); return;
end
if (Ns = length(x))
print(’error’);
return;
end
x = x’;
xx = zeros( M,1);
w1 = zeros( M,1);
y = zeros(Ns,1);
e = zeros(Ns,1);
for n = 1:Ns
xx = [xx(2:M);x(n)];
y(n) = w1’ * xx;
k = mu/(a + xx’*xx);
e(n) = d(n) - y(n);
w1 = w1 + k * e(n) * xx;
w(:,n) = w1;
end
end

3. myLMS function.

f unction[e, y, w] = myLM S(d, x, mu, M )


N = length(d);
if (N ¡= M)
print(’error’);
return;
end
if (N = length(x))
print(’error’);
return;
end
x = x’;
xx = zeros(M,1);
w1 = zeros(M,1);
y = zeros(N,1);
e = zeros(N,1);
for n = 1:N
xx = [xx(2:M);x(n)];
y(n) = w1’ * xx;
e(n) = d(n) - y(n);
w1 = w1 + mu * e(n) * xx;
w(:,n) = w1;
end

Page 8 of 8

You might also like