
%channel system order
sysorder = 5 ; %抽头数
% Number of system points
N=2000; %总采样次数
inp = randn(N,1); %产生高斯随机序列
n = randn(N,1);
[b,a] = butter(2,0.25);
Gz = tf(b,a,-1); %逆变换函数
%This function is submitted to make inverse Z-transform (Matlab central file exchange)
%The first sysorder weight value
%h=ldiv(b,a,sysorder)';
% if you use ldiv this will give h :filter weights to be
h= [0.0976; 0.2873; 0.3360; 0.2210; 0.09;]; %信道特性向量
y = lsim(Gz,inp); %加入噪声
%add some noise
n = n * std(y)/(10*std(n)); %噪声信号
d = y + n; %期望输出信号
totallength=size(d,1); %步长
%Take 60 points for training %60节点作为训练序列
N=60 ;
%begin of algorithm %算法的开始
w = zeros ( sysorder , 1 ) ; %初始化
for n = sysorder : N
u = inp(n:-1:n-sysorder+1) ; % u的矩阵
y(n)= w' * u; %系统输出
e(n) = d(n) - y(n) ; %误差
% Start with big mu for speeding the convergence then slow down to reach the correct weights %从大的mu加速收敛然后慢下来,以达到正确的权值
if n < 20
mu=0.32;
else
mu=0.15;
end
w = w + mu * u * e(n) ; %迭代方程
end
%check of results %检验结果
for n = N+1 : totallength
u = inp(n:-1:n-sysorder+1) ;
y(n) = w' * u ;
e(n) = d(n) - y(n) ; %误差
end
hold on
plot(d)
plot(y,'r');
title('System output') ; %系统输出
xlabel('Samples') %样本
ylabel('True and estimated output') %实际输出
figure
semilogy((abs(e))) ; % e的绝对值坐标
title('Error curve') ; %误差曲线
xlabel('Samples') %样本
ylabel('Error value') %误差矢量
figure %作图
plot(h, 'k+')
hold on
plot(w, 'r*')
legend('Actual weights','Estimated weights') %实际权矢量 估计权矢量
title('Comparison of the actual weights and the estimated weights') ; %比较实际权和估计权矢量
axis([0 6 0.05 0.35])
仿真图
