-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathrlsadapt.m
100 lines (80 loc) · 1.49 KB
/
rlsadapt.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function out = lsqdata( )
%A demo to show recursive least squares parameter estimation and prediction.
clf;
numpts = 200;
order = 2;
noise = 1.0;
trsize = 5;
theta = [0.607;0.4];
disp('True parameter vector = ')
disp(theta');
y=10+ noise*(rand(1,order)-0.5);
fudge=0.5;
theta = fudge*theta;
for i=order+1:numpts,
for j=1:order,
phip(j) = y(i-j);
end
phi=phip';
if i==trsize+1,
theta = theta/fudge;
phi(1)=phi(1)*10/y(i-1);
end
y(i)=theta'*phi + noise*(rand(1)-0.5);
end
x=[1:numpts];
plot(x,y,'r-');
disp('Press any key to plot predicted signal');
pause
hold on;
for i=1:order+1,
ytr(:,i)=y(i:trsize+i-1)';
end
for i=1:order,
A(:,i)=ytr(:,order-i+1);
end
b = ytr(:,order+1);
thetahat=(A'*A)\(A'*b);
disp('Estimate of parameter vector = ')
disp(thetahat');
for j=1:order,
yhat(j)=y(j);
end
for i=order+1:numpts,
for j=1:order,
phip(j) = y(i-j);
end
phi=phip';
yhat(i)=thetahat'*phi;
end
x=[1:numpts];
plot(x,yhat,'b-.');
disp('Press any key to plot RLS predicted signal');
pause
for i=1:order+1,
ytr2(:,i)=y(i:order+i-1)';
end
for i=1:order,
A2(:,i)=ytr2(:,order-i+1);
end
b2 = ytr2(:,order+1);
P=inv(A2'*A2);
that=P*A2'*b2;
for j=1:order,
yhat(j)=y(j);
end
for i=order+1:numpts,
for j=1:order,
phip(j) = y(i-j);
end
phi=phip';
yhat(i)=that'*phi;
P=P-(P*phi*phi'*P)/(1+phi'*P*phi);
that=that+P*phi*(y(i)-phi'*that);
%disp('that =');
%disp(that');
end
disp('Estimate of parameter vector = ')
disp(that');
x=[1:numpts];
plot(x,yhat,'g-');