pte1.m

来自「学习通信的人都知道」· M 代码 · 共 54 行

M
54
字号

%PTE1 Problem 3.2
%
%   'ifile.mat' - input file containing:
%      I - members of ensemble
%      K - iterations
%      s - deterministic part of signal to predict
%      sigman - standard deviation of noise in signal to predict
%      ND - delayer order
%      N - filter order
%      mu - convergence factor
%      bd - error wordlength
% 
%   'ofile.mat' - output file containing:
%      ind - sample indexes 
%      MSE - mean-square error

clear all	% clear memory
load ifile;	% read input variables
LD=ND+1;	% delayer length
L=N+1;		% filter length
lim=2^(-bd+1);		% inferior limit
MSE=zeros(K,1);		% prepare to accumulate MSE*I

for i=1:I,		% ensemble
   D=zeros(LD,1);	% initial delayer memory
   X=zeros(L,1);    	% initial memory
   Wpr=zeros(L,1);	% initial coefficient vector
   n=randn(K,1)*sigman;	% noise in signal to predict
   for k=1:K,		% iterations
      d=s(k)+n(k);	% sample of signal to predict
      D=[d
         D(1:ND)];	% new delay vector
      X=[D(LD)		
         X(1:N)];	% new input vector
      y=Wpr'*X;	% output sample
      e(k)=d-y;		% error sample
      if abs(e(k))>=1, 
         pe=1;
      elseif abs(e(k))<=lim,
         pe=0;
      else
         pe=2^(fix(log(abs(e(k)))/log(2)));
      end
      pe=pe*sign(e(k));		% power-of-two error
      Wpr=Wpr+2*mu*pe*X;	% new coefficient vector
      MSE(k)=MSE(k)+(e(k))^2;	% accumulate MSE*I
   end
end

ind=0:(K-1);	% sample indexes
MSE=MSE/I;	% calculate MSE
save ofile ind MSE;	% write output variables

⌨️ 快捷键说明

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