24小时热门版块排行榜    

查看: 802  |  回复: 5
当前主题已经存档。
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

zzbei

木虫 (正式写手)

[交流] 自适应matlab程序(LMS和RLS)

%lms算法源程序

clear all
close all
%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.0964;];
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
N=60 ;  
%begin of algorithm
w = zeros ( sysorder , 1 ) ;
for n = sysorder : N
  u = inp(n:-1:n-sysorder+1) ;
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
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))) ;
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])

% RLS 算法
randn('seed', 0) ;
rand('seed', 0) ;

NoOfData = 8000 ;  % Set no of data points used for training
Order = 32 ;    % Set the adaptive filter order

Lambda = 0.98 ;    % Set the forgetting factor
Delta = 0.001 ;    % R initialized to Delta*I

x = randn(NoOfData, 1) ;% Input assumed to be white
h = rand(Order, 1) ;  % System picked randomly
d = filter(h, 1, x) ;  % Generate output (desired signal)

% Initialize RLS

P = Delta * eye ( Order, Order ) ;
w = zeros ( Order, 1 ) ;

% RLS Adaptation

for n = Order : NoOfData ;
   
  u = x(n:-1:n-Order+1) ;
  pi_ = u' * P ;
  k = Lambda + pi_ * u ;
  K = pi_'/k;
  e(n) = d(n) - w' * u ;
  w = w + K * e(n) ;
  PPrime = K * pi_ ;
  P = ( P - PPrime ) / Lambda ;
  w_err(n) = norm(h - w) ;

end ;

% Plot results

figure ;
plot(20*log10(abs(e))) ;
title('Learning Curve') ;
xlabel('Iteration Number') ;
ylabel('Output Estimation Error in dB') ;

figure ;
semilogy(w_err) ;
title('Weight Estimation Error') ;
xlabel('Iteration Number') ;
ylabel('Weight Error in dB') ;

[ Last edited by 幻影无痕 on 2006-10-26 at 07:47 ]
回复此楼

» 收录本帖的淘贴专辑推荐

source

» 猜你喜欢

经历就是一种享受
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wanglong

铁杆木虫 (正式写手)

非常感谢!!!!老大,有啥好东东,多上穿一点
4楼2006-05-11 12:51:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wanglong

铁杆木虫 (正式写手)

0.5

非常感谢,刚才没评价,重来
5楼2006-05-11 12:52:37
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 zzbei 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 工材口青年基金大概什么样能上会? +7 今晚推荐22 2024-06-20 9/450 2024-06-20 14:46 by 我1的飞翔
[考博] 这个博士要读吗 +15 Sea Breeze 2024-06-16 29/1450 2024-06-20 14:30 by Sea Breeze
[考博] 34岁读博士晚吗 +41 emitdne 2024-06-13 41/2050 2024-06-20 13:27 by 1429524838
[教师之家] 试用期辞职 +10 ZHONGWU_U 2024-06-18 16/800 2024-06-20 11:52 by xiang104
[论文投稿] 投稿求助 +3 平凡的日子 2024-06-19 4/200 2024-06-20 11:05 by 平凡的日子
[找工作] 高校两个offer选择 +14 cowox2021 2024-06-18 15/750 2024-06-20 08:34 by 梦渺岚烟
[论文投稿] Scientific Reports二审90天了,催稿也没反应怎么办? +3 智晨君 2024-06-18 6/300 2024-06-19 20:08 by licheng78
[基金申请] F口信息学部拿面上,大概需要什么样的成果 +7 _奋黎_ 2024-06-16 18/900 2024-06-19 20:02 by _奋黎_
[论文投稿] 审稿 +5 香瓜木香 2024-06-19 6/300 2024-06-19 17:44 by xli1984
[基金申请] 基金得中 +4 woaini0218 2024-06-18 4/200 2024-06-19 17:27 by mengzl
[论文投稿] 求机械类四区sci推荐 5+4 迷茫小旷 2024-06-14 5/250 2024-06-19 14:08 by tangjie12345
[论文投稿] ACS AMI 返回审稿意见,一个大修,两个据稿,编辑给的修改重投 +5 智商已更新 2024-06-19 5/250 2024-06-19 12:35 by nono2009
[基金申请] 博后基金刷到的BUG,图片来的更直观 +15 carolloo 2024-06-17 16/800 2024-06-19 09:42 by msjy
[论文投稿] 审稿人含糊拒稿,还需要回复吗?如何回复? 20+4 BruceChum 2024-06-15 22/1100 2024-06-19 08:00 by kanyechris
[基金申请] F口401需要啥文章水平 +3 lhjr123 2024-06-16 7/350 2024-06-18 16:05 by hon920603
[有机交流] 跑板能跑开,过柱过不纯怎么办 +4 小胡在努力 2024-06-18 6/300 2024-06-18 15:20 by long8811
[论文投稿] 投稿求助 10+3 2022_灵魂工程师 2024-06-16 8/400 2024-06-18 12:12 by 投必得科研顾问
[论文投稿] 审稿问题:为什么荧光激发波长和紫外吸收波长差的大? 10+5 sdawege 2024-06-14 10/500 2024-06-17 18:54 by HH-探针
[论文投稿] 投稿被一个审稿人恶意评审了怎么样? +5 1chen 2024-06-14 7/350 2024-06-15 23:15 by xy66xy
[基金申请] 博后基金,以往的结果点不开,怎么回事呢?最后一次机会了,两次都没中前面。 +7 kyukitu 2024-06-14 13/650 2024-06-15 06:46 by 我是王小帅
信息提示
请填处理意见