lms3.m
来自「一个matlab实现IIR、FIR、LMS、NLMS等算法的m代码」· M 代码 · 共 47 行
M
47 行
%LMS3 Problem 1.1.1.2.1
%
% 'ifile.mat' - input file containing:
% I - members of ensemble
% K - iterations
% a1 - coefficient of input AR process
% sigmax - standard deviation of input
% Wo - coefficient vector of plant
% sigman - standard deviation of measurement noise
% mu - convergence factor
%
% 'ofile.mat' - output file containing:
% ind - sample indexes
% M - misadjustment
clear all % clear memory
load ifile; % read input variables
sigmav=sigmax*sqrt(1-a1^2);
% standard deviation of input to AR process
L=length(Wo); % plant and filter length
N=L-1; % plant and filter order
MSE=zeros(K,1); % prepare to accumulate MSE*I
MSEmin=zeros(K,1); % prepare to accumulate MSEmin*I
for i=1:I, % ensemble
X=zeros(L,1); % initial memory
W=zeros(L,1); % initial coefficient vector
v=randn(K,1)*sigmav; % input to AR process
x=filter([1,0],[1,a1],v); % input
n=randn(K,1)*sigman; % measurement noise
for k=1:K, % iterations
X=[x(k)
X(1:N)]; % new input vector
d=Wo'*X; % desired signal sample
y=W'*X; % output sample
e=d+n(k)-y; % error sample
W=W+2*mu*e*X; % new coefficient vector
MSE(k)=MSE(k)+e^2; % accumulate MSE*I
MSEmin(k)=MSEmin(k)+(n(k))^2; % accumulate MSEmin*I
end
end
ind=0:(K-1); % sample indexes
M=MSE./MSEmin-1; % calculate misadjustment
save ofile ind M; % write output variables
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?