forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRlsadf.m
60 lines (44 loc) · 1.26 KB
/
Rlsadf.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
function RLSadf
% program to illustrate adaptive filtering using
% the RLS algorithm
% X delayed input signal
% Y measured signal
% W coefficient vector
% E enhanced signal
N = 30; % filter length
M = 1; % stages of delay
SF = 2048; % 12-bit ADC scaling
p0 = 0.05;
w0 = 100;
gamma = 0.98;
RemoveMean = 0; % 1 to remove the mean, 0 otherwise
W = w0*ones(N,1); % adaptive filter weights
X = zeros(N,1);
delay = zeros(1,M+1);
P = p0*diag(ones(1,N),0);
if w0==0
sf = SF; % scaling factor for display
else
sf = SF/N/w0;
end
in = fopen('ADF.dat','r'); %read input data from specified data file
Y = fscanf(in,'%g',inf)/SF;
fclose(in);
if RemoveMean % remove the mean from the data if required
Y = Y - sum(Y)/length(Y);
end
for i=1:length(Y)
if M>0
delay(2:M+1) = delay(1:M); % shift input data in delay registers
end
delay(1) = Y(i);
X(2:N) = X(1:N-1); % update buffer
X(1) = delay(M+1);
E(i) = Y(i) - X'*W; % the enhanced signal
G = P*X/(gamma + X'*P*X);
P = (P - G*X'*P)/gamma;
W = W + G*E(i); % update the weights
end
subplot(2,1,1),plot(1:length(Y),Y*SF); title('Input Signal');
subplot(2,1,2),plot(1:length(E),E*sf); title('Enhanced Signal');