导航:首页 > 源码编译 > rls算法的matlab程序

rls算法的matlab程序

发布时间:2022-09-13 20:50:24

⑴ 我现在在做RBF神经网络k-means算法与RLS递归二乘法结合训练,求哪位大神能给个RLS的算法的MTALAB程序

直接用广义RBF网络我感觉比较方便,而且可以直接用newgrnn(P,T,spread)函数。

RLS算法的MATLAB程序在附件,你可以参考下。


最小二乘大约是1795年高斯在他那星体运动轨道预报工作中提出的[1]。后来,最小二乘法就成了估计理论的奠基石。由于最小二乘法结构简单,编制程序也不困难,所以它颇受人们重视,应用相当广泛。
如用标准符号,最小二乘估计可被表示为:
AX=B (2-43)
上式中的解是最小化 ,通过下式中的伪逆可求得:
A'AX=A'B (2-44)
(A'A)^(-1)A'AX=(A'A)^(-1)A'B (2-45)
由于
(A'A)^-1A'A=I (2-46)
所以有
X=(A'A)^(-1)A'B (2-47)
此即最小二乘的一次完成算法,现代的递推算法,更适用于计算机的在线辨识。
最小二乘是一种最基本的辨识方法,但它具有两方面的缺陷[1]:一是当模型噪声是有色噪声时,最小二乘估计不是无偏、一致估计;二是随着数据的增长,将出现所谓的“数据饱和”现象。针对这两个问题,出现了相应的辨识算法,如遗忘因子法、限定记忆法、偏差补偿法、增广最小二乘、广义最小二乘、辅助变量法、二步法及多级最小二乘法等。

⑵ 神经网络,大神检查下matlab中RLS算法过程,运行不过啊

能把x=[...];%训练样本
d=[...];%期望值
文件发过来,调试用吗?

⑶ 急求,matlab在自适应均衡中RLS和LMS算法的程序

%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') ;

可以看得出来,收敛速度RLS更快,对程序可以看得出来运算量也是RLS更大。
可以参照我回答的解决一个RLS具体问题的例子。在网络里面可以搜到。

⑷ 基于matlab的跳频扩频通信的实现及性能的程序代码

rho_b1=0:5:35;
rho_b2=0:0.1:35;
for i=1:length(rho_b1)
smlid_err_prb(i)=ssfh_Pe(rho_b1(i));
end;
for i=1:length(rho_b2)
temp=10^(rho_b2(i)/10);
if(temp>2)
theo_err_rate(i)=1/(exp(1)*temp);
else
theo_err_rate(i)=(1/2)*exp(-temp/2);
end;
end;
semilogy(rho_b1,smlid_err_prb,'k*',rho_b2,theo_err_rate,'k-);
在程序中调用了ssfh_Pe子函数,程序如下:

function[p]=ssfh_Pe(tho_in_dB)
rho=10^(rho_in_dB/10);
Eb=rho;
if(rho>2) alpa=2/rho;
else alpa=1;
end;
agma=sqrt(1/(2*alpha));
N=10000;
for i=1:N
temp=rand;
if(temp<0.5) data(i)=1;
else data(i)=0;
end;
end;
for i=1:N
if(data(i)==0)
rlc(i)=sqrt(Eb);rls(i)=0;r2c(i)=0;r2s(i)=0;
else
rlc(i)=0;rls(i)=0;r2c(i)=sqrt(Eb);r2s(i)=0;
end;
if(rand<alpha)
rlc(i)=rlc(i)+gngauss(sgma);
rls(i)=rls(i)+gngauss(sgma);
r2c(i)=r2c(i)+gngauss(sgma);
r2s(i)=r2s(i)+gngauss(sgma);
end;
end;
num_of_err=0;
for i=1:N
r1=rlc(i)^2+rls(i)^2;
r2=r2c(i)^2+r2s(i)^2;
if(r1>r2) decis=0;
else decis=1;
end;
if(decis~=data(i))
num_off_eff=num_of_err+1;
end;
end;
p=num_of_err/N;

其中高斯分布随机变量函数gngauss程序如下

function[gsrv1,gsrv2]=gngauss(n,sgma)
if nargin==0,
m=0;sgma=1;
elseif nargin==1,
sgma=m;m=0;
end;
u=rand;
z=sgma*(sqrt(2*log(1/(1-u))));
u=rand;
gsrv1=m+z*cos(2*pi*u);
gsrv2=m+z*sin(2*pi*u);

⑸ 求在MIMO-OFDM系统使用RLS算法计算迭代次数与均方误差的Matlab程序

pudn 上面有

⑹ 求:matlab 自适应算法 程序!

%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') ;

⑺ 实现RLS算法的matlab程序有没有大神会的一直出不来

% 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') ;

⑻ MATLAB高手来,帮忙改改程序,关于自适应滤波器算法的

clear all;
clc;
m=500;%将输入量赋值
u=0.002;%将输入量赋值
a1=-1.6;a2=0.8;
w1(1)=0;w2(1)=0;
w1(2)=0;w2(2)=0;
n(1)=1;n(2)=2;
%%%%%%%%
% true sequence x(n)
rd=randn(1,m);
x(1)=rd(1);x(2)=rd(2);
for k=3:m
x(k)=rd(k)-a1*x(k-1)-a2*x(k-2);
end
R=[x(1)*x(1) 0;0 0];
T=0;
e(1)=0;
W=[0;1];
X=[x(2);x(1)];
e(2)=x(2)-W'*X;
%%%%%%%%%%
for i=3:1:m %权系数迭代m次
R=[x(i-1)*x(i-1) x(i-1)*x(i-2);x(i-1)*x(i-2) x(i-2)*x(i-2)];%列出自相关矩阵
T=1/(T+trace(R)); %求出迹的值,为后续u的判断做准备
if(u>T)
error('u is larger than 1/t[R]');%判断u的值是否小于迹的倒数
end
W=W+2*u*X*e(i-1); %LMS算法的权系数迭代公式
X=[x(i-1) x(i-2)]'; %LMS算法中输入信号矢量的递推
e(i)=x(i)-W'*X;
w1(i)=-W(1); %LMS算法中权系数a1的提取
n(i)=i;
end
lambda=eig(R);%由R得出特征值
v=[1;1];%给主轴坐标赋初值
for n1=1:50
w(n1)=v(1)*v(1)*lambda(1)*((1-2*u*lambda(1))^(2*n1))+v(2)*v(2)*lambda(2)*((1-2*u*lambda(2))^(2*n1));%学习曲线的迭代公式
end
figure(1)
plot(w1,'r-'); %曲线绘图
%title('LMS算法权值收敛情况');
xlabel('迭代次数');
ylabel('权值变化');
grid on;
hold on;

% m=500;%权系数迭代m次
len=0.98;%%%%遗忘因子
% a1=-1.6;a2=0.8;
% w1(1)=1;
% w2(1)=1;
% w1(2)=1;
% w2(2)=2;
% n(1)=1;
% n(2)=2;
% %%%%%%%%%%%输入序列产生%%%%%%%%%%%%
% rd=randn(1,m);% 生成白噪声序列
% x(1)=rd(1);x(2)=rd(2);%产生前两个输入序列
% for k=3:m
% x(k)=rd(k)-a1*x(k-1)-a2*x(k-2);%产生其余输入序列
% end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
R=[0,0;0,0];%自相关矩阵初值R(-1)=0
W=[w1(2);w2(2)]; %初始权值
P=[0;0];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=3:1:m
X=[x(i-1),x(i-2)]';
R= len*R+ X*X';%迭代公式中自相关矩阵的计算
e=x(i)-W'*X;%输出信号误差e(n\n-1)
W=W+inv(R)*X*e; %RLS算法的权系数迭代公式
w1(i)=-W(1); %RLS算法中权系数a1的提取
w2(i)=-W(2); %RLS算法中权系数a2的提取
n(i)=i;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
plot(w1,'b-'); %曲线绘图
title('自适应权系数a1(n)的过渡过程(RLS和LMS算法比较)');
xlabel('迭代次数');
ylabel('权值变化');
legend('LMS','RLS');
grid on;
hold off;
for k=3:m
y(k)=x(k)+w1(k)*x(k-1)+w2(k)*x(k-2);
end
figure(2);
hold on;
plot(x,'b-'); %曲线绘图
grid on;
plot(y,'r-');
title('RLS滤波效果');
xlabel('迭代次数');
ylabel('输入及输出值');
legend('噪音','滤波器输出');
hold off;

⑼ RLS算法在MATLAB上仿真实现的程序

% RLS 算法
<br>randn('seed', 0) ;
<br>rand('seed', 0) ;
<br>
<br>NoOfData = 8000 ; % Set no of data points used for training
<br>Order = 32 ; % Set the adaptive filter order
<br>
<br>Lambda = 0.98 ; % Set the forgetting factor
<br>Delta = 0.001 ; % R initialized to Delta*I
<br>
<br>x = randn(NoOfData, 1) ;% Input assumed to be white
<br>h = rand(Order, 1) ; % System picked randomly
<br>d = filter(h, 1, x) ; % Generate output (desired signal)
<br>
<br>% Initialize RLS
<br>
<br>P = Delta * eye ( Order, Order ) ;
<br>w = zeros ( Order, 1 ) ;
<br>
<br>% RLS Adaptation
<br>
<br>for n = Order : NoOfData ;
<br>
<br>u = x(n:-1:n-Order+1) ;
<br>pi_ = u' * P ;
<br>k = Lambda + pi_ * u ;
<br>K = pi_'/k;
<br>e(n) = d(n) - w' * u ;
<br>w = w + K * e(n) ;
<br>PPrime = K * pi_ ;
<br>P = ( P - PPrime ) / Lambda ;
<br>w_err(n) = norm(h - w) ;
<br>
<br>end ;
<br>
<br>% Plot results
<br>
<br>figure ;
<br>plot(20*log10(abs(e))) ;
<br>title('Learning Curve') ;
<br>xlabel('Iteration Number') ;
<br>ylabel('Output Estimation Error in dB') ;
<br>
<br>figure ;
<br>semilogy(w_err) ;
<br>title('Weight Estimation Error') ;
<br>xlabel('Iteration Number') ;
<br>ylabel('Weight Error in dB') ;
<br>

阅读全文

与rls算法的matlab程序相关的资料

热点内容
卡尔曼滤波算法书籍 浏览:763
安卓手机怎么用爱思助手传文件进苹果手机上 浏览:841
安卓怎么下载60秒生存 浏览:800
外向式文件夹 浏览:232
dospdf 浏览:428
怎么修改腾讯云服务器ip 浏览:382
pdftoeps 浏览:490
为什么鸿蒙那么像安卓 浏览:732
安卓手机怎么拍自媒体视频 浏览:183
单片机各个中断的初始化 浏览:721
python怎么集合元素 浏览:477
python逐条解读 浏览:829
基于单片机的湿度控制 浏览:496
ios如何使用安卓的帐号 浏览:879
程序员公园采访 浏览:807
程序员实战教程要多长时间 浏览:970
企业数据加密技巧 浏览:132
租云服务器开发 浏览:809
程序员告白妈妈不同意 浏览:332
攻城掠地怎么查看服务器 浏览:597