📄 lmsmmse.m
字号:
clc
fbconnection=[0 1 0 0 1];
mseq=m_sequence(fbconnection);
fbconnection1=[0 0 1 0 1];
fbconnection2=[0 1 1 1 1];
goldseq=gold_seq(fbconnection1,fbconnection2);
N=2^length(fbconnection)-1;
ind1=find(mseq==0);
mseq(ind1)=-1;
ind2=find(goldseq==0);
goldseq(ind2)=-1;
bit_number=10000;
K=16;
data=zeros(K,bit_number);
for i=1:K
data(i,:)=randsrc(1,bit_number);
end
r=zeros(N,bit_number);
rideal=zeros(N,bit_number);
r1=zeros(N,bit_number);
SNR=-30;
for k=1:K
r1=goldseq(k,:)'*data(k,:);
rideal=rideal+r1;
r1=awgn(r1,SNR);
r=r+r1;
end
%lms 算法
userk=10;
lmsN=bit_number;
inp=goldseq(userk,:)*r;
max_inp=max(inp);
inp=inp/max_inp;
d=data(userk,:);
[dtemp,totallength]=size(d);
lmsN=60;
w=zeros(userk,1);
for n=1:lmsN
u=inp(n)*ones(userk,1);%u=inp(n:-1:n-userk+1);
y(n)=w'*u;%y(n)=u*w;
e(n)=d(n)-y(n);
if n<20
mu=0.32;
else
mu=0.15;
end
w=w+mu*u*e(n);%w=w+mu*u'*e(n);
end
for n=lmsN+1:totallength
u=inp(n)*ones(userk,1); %u=inp(n:-1:n-userk+1);
y(n)=w'*u; % y(n)=u*w;
e(n)=d(n)-y(n);
end
tright=0;
newy=sign(y); %最后输出数据
for lmsi=2:bit_number
if newy(lmsi)==d(lmsi)
tright=1+tright; %与原始数据对比,正确的个数
end
end
trightf=0;
newinp=sign(inp); %非多用户,最后输出数据
for lmsi=2:bit_number
if newinp(lmsi)==d(lmsi)
trightf=1+trightf; %与原始数据对比,正确的个数
end
end
checkr=[newy;d];
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')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -