📄 lms.m
字号:
function [theta,x,e] = lms (u,y,x,theta,mu,m)
%-----------------------------------------------------------------------
% Usage: [theta,x,e] = lms (u,y,x,theta,mu,m)
%
% Description: Use the current input samples u and output sample y to
% update the (m+1) by 1 parameter vector theta of a MA
% model using the least-mean square (LMS) method. The
% MA model has the following transfer function.
%
% Y(z)/U(z) = theta(1) + theta(2)*z^(-1) +...+ theta(m+1)*z^(-m)
%
% Inputs: u = current value of system input
% y = current value of system output
% x = (m+1) by 1 vector containing current state of
% MA model: [u(k),u(k-1),...,u(k-m)]'.
% theta = (m+1) by 1 vector containing estimated values
% of MA model parameters.
% mu = step size used for stepest descent search (mu > 0)
% m = order of MA model (m >= 0)
%
% Outputs: theta = (m+1) by 1 vector containing updated estimate of
% of MA model parameters.
% x = (m+1) by 1 vector containing updated state of
% MA model with x(1) = 0.
% e = error between actual output y and output predicted
% by MA moded, e = x'*theta - y
%
% Notes: For the LMS method to converge, the step size mu must not
% be too large. If P(u) denotes the average power of the
% input signal u(k), then the step size should be in the
% range:
%
% 0 < mu < 1/[(m+1)*P(u)]
%-----------------------------------------------------------------------
% Initialize
chkvec (x,3,'lms');
chkvec (theta,4,'lms');
mu = args (mu,eps,mu,5,'lms');
m = args (m,0,m,6,'lms');
x1 = zeros (m+1,1);
% Update theta
x1 = x; % save original x
x1(1) = u; % update first element
[x,y1] = arma (u,theta,x,0,m);
e = y - y1;
for i = 1 : m+1
theta(i) = theta(i) + 2*mu*e*x1(i);
end
%-----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -