⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lms_filter.m

📁 英文书《Digital Signal Processing with Examples in MATLAB》附带的MATLAB实例
💻 M
字号:
function [g,b]=lms_filter(b,u,d,f,ind)
% [g,b]=lms_filter(b,u,d,f,ind)
%
% Inputs:
%    b  = initial weight vector with length(b)=N.
%    u  = adaptive gain constant; 0 <= u << 1.
%    d  = desired signal vector.
%    f  = input vector to FIR adaptive filter.
%    ind= indicator (see below.)
% Output:  
%    g  = adaptive filter output vector; error=d-g.
%    b  = Final weight vector if ind is omitted or zero, or
%       = NxK array of successive weight vectors if ind=1.
%
% This is Widrow's normalized adaptive LMS algorithm
% computed as in (9.51) in the text with power sigma^2
% equal to avg. power in vector f, i.e., mean(f.^2).
% See also: rls_filter
f=col_vec(f);
d=col_vec(d);
K=min(length(d),length(f));
b=col_vec(b);
N=length(b);
% Check for errors and set ind.
if(u<0 | u>=1),
   error('Adaptive gain u is out of range.');
elseif(K<N),
	error('Lengths of f and d should be > length of b.');
end
if(nargin==5 & ind==1),
    b=[b,zeros(N,K-1)];
else
    ind=0;
end
% Compute mu=2*u/(N*avg. power).
mu=2*u/(N*f'*f/length(f));
% Initialize g=zeros and begin f with N-1 zeros.
g=zeros(K,1);
f=[zeros(N-1,1); f];
% Filter; update g and b at each step.
bb=b(:,1);
for k=1:K,
	fvect=f(k+N-1:-1:k);
	g(k)=bb'*fvect;                     % filter output
	e=d(k)-g(k);                        % error signal
	bb=bb+mu*e*fvect;                   % updated current weight vector
    b(:,(1-ind)+ind*min(k+1,K))=bb;     % updated weight vector history
end

⌨️ 快捷键说明

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