% lms_eq.m - use multidimensional LMS algorithm to estimate channel response
% written for MATLAB 4.0
%
% Input parameters:
% Xi : matrix of training/test points - each row is
% considered a datum
% y : desired vector output values corresponding to Xi
% verbose: set to 1 for interactive processing
% alpha : the initial value of step size
% decay : set to 1 for O(1/n) decay in alpha
Nin = size(Xi, 2);
Nout = size(Y, 2);
% maximum number of timesteps that can be predicted
N = size(Xi, 1);
% initialize weight matrix and associated parameters for LMS predictor
W = zeros(Nout, Nin);
Wo = [];
for n = 1:N,
% save weights
Wo = [Wo W'];
% predict next sample and error
xp(n, :) = Xi(n, :) * W';
e(n, :) = Y(n, :) - xp(n, :);
ne(n) = norm(e(n, :));
if (rp.verbose ~= 0)
disp(['time step ', int2str(n), ': mag. pred. err. = ' , num2str(ne(n)) ] );
end;
% adapt weight matrix and step size
%W = W + rp.mu * e(n, :)' * Xi(n, :);
W = W + (rp.mu./(1+Xi(n, :)'*Xi(n, :)) * e(n, :)' * Xi(n, :);
if (rp.decay == 1)
rp.mu = rp.mu * n/(n+1); % use O(1/n) decay rate
end;
end % for n
评论0