lms_eq.m

来自「matlab里面的一些经典的例子程序」· M 代码 · 共 44 行

M
44
字号
% 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, :);
    if (rp.decay == 1)
      rp.mu = rp.mu * n/(n+1); % use O(1/n) decay rate
    end;
end % for n




⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?