Você está na página 1de 5

Mohammad

Arsalan
Khan
Assignment No 1:

Submitted to:

Sir. Dr. Tair Zaidi..


%%Implement of LMS algorithm for Adaptive Filters.

xi= rand(1000,1);

%%Order of Filter
N=5; (For better results, Higher order is considered)

for n=1:N
z(n) = 0;
for j=0:N-1
z(n) = z(n) + xi (n+j);
end
mov_avg(n) = z(n)/N;
end

%%Inputs
x=mov_avg

%%Desired Response
d=ones(1,N)

%%Auto Correlation Matrix of order N*N using Instanteneous Values


Rx=xcorr(x);

%%Cross Correaltion Matrix of order N*1 using Instanteneous Values


Ry=xcorr(x,d);

R = [Rx(1) Rx(2) Rx(3) Rx(4) Rx(5);


Rx(2) Rx(1) Rx(2) Rx(3) Rx(4);
Rx(3) Rx(2) Rx(1) Rx(2) Rx(3);
Rx(4) Rx(3) Rx(2) Rx(1) Rx(2);
Rx(5) Rx(4) Rx(3) Rx(2) Rx(1)]

P = [Ry(1);
Ry(2);
Ry(3);
Ry(4);
Ry(5)]

%%Scaling Factor
mew=[0.023; 0.055; 0.069; 0.091];

%%Weight Vector
w=zeros(1,5);

for n=1:N-1

%%Error Equation
e(n) = d(n) - w(n) * x(n);

%%Tap Update Equation


w(n+1) = w(n) + mew(n) * e(n) * x(n);
end
RESULTS:

x= 0.6293 0.7359 0.7871 0.7397 0.6863

d= 1 1 1 1 1

R= 0.4319 0.9705 1.5798 2.1321 2.5752

0.9705 0.4319 0.9705 1.5798 2.1321

1.5798 0.9705 0.4319 0.9705 1.5798

2.1321 1.5798 0.9705 0.4319 0.9705

2.5752 2.1321 1.5798 0.9705 0.4319

p= 0.6293

1.3652

2.1522

2.8919

3.5782
Implement of RLS algorithm for Adaptive Filters:-
rnd= rand(1000,1);
N=4; (Order of Filter)
t=[0:N-1];
for
i=1:N
x(i) = 0;
for
j=0:N-1
x(i) = x(i) + rnd (i+j);
end
mov_avg(i) = x(i)/N;
end

y=mov_avg (Inputs)
d=ones(1,N) (Desired Response)
ita=10^4;
I=ones(1,N);
R=ita*I;
w=zeros(1,N);
for
i=1:N
e(i) = d(i) - y(i);
z(i) = R(i) * x(i);
q = x(i)' * z(i);
v = 1/(1+q);
zz(i) = v * z(i);
w(i+1) = w(i) + e(i)*zz(i);
R(i+1) = R(i) - zz(i)*z(i);
end

subplot(3,1,1)
plot(t,d)
title('Desired Signal')

subplot(3,1,2)
plot(t,x)
title('Noise Corrupted Signal')

subplot(3,1,3)
plot(t,e)
title('Error')

y = [0.6802 0.7714 0.7502 0.7567]


d = [1 1 1 1]

Você também pode gostar