📄 mequal_estimation_bit_improve.m
字号:
elseif(gama_yk1>300)
gama_yk1=300;
end
end%
tempu1=tempu1+gama_yu1*a_buf(jj,1,fm)*bb(jj,m);%a(k-1)b(k),buffer头部数据.
tempu0=tempu0+gama_yu0*a_buf(jj,1,fm)*bb(jj,m);
tempd1=tempd1+gama_yd1*a_buf(jj,1,fm)*bb(jj,m);
tempd0=tempd0+gama_yd0*a_buf(jj,1,fm)*bb(jj,m);
temp1=temp1+gama_yk1*a_buf(jj,1,fm)*bb(jj,m);
temp0=temp0+gama_yk0*a_buf(jj,1,fm)*bb(jj,m);
end%fm
end%m
%--compute next aa---
factor=0;
for m=1:8
a_temp(m)=0;
for fm=1:8
if (judge(fm,m)==0)
gama_with_info=0;
else
x_up=(2*d(fm,m,1)-1);%*(0.1746);
x_down=(2*d(fm,m,2)-1);%*(0.1746);
gama_with_info=exp(0.5*(x_up*Lc1(jj)*soft_PNandData(jj,2*i-1)+Lc2(jj)* soft_PNandData(jj,2*i)*x_down)); % buffer尾部数据
if (gama_with_info==inf)
gama_with_info=300;
elseif(gama_with_info>300)
gama_with_info=300;
end
end
a_temp(m)=a_temp(m)+gama_with_info*a_buf(jj,buflength/2+1,fm); %aa(k-1)
if (a_temp(m)==inf)
a_temp(m)=300;
end
end%fm
factor=factor+a_temp(m);
end%m
%以下计算 out_up
if((tempu0==0)&(tempu1==0))
Temp=0;
elseif((tempu0==0)&(tempu1~=0))
Temp=300;
elseif((tempu1==0)&(tempu0~=0))
Temp=-300;
else
Temp=log(tempu1/tempu0);
end
if (Temp==Inf)
out_up(jj,i-(nn-1)*(PN/2+block)-PN/2-1)=300;%找出最大值赋给out
elseif(Temp==-Inf)
out_up(jj,i-(nn-1)*(PN/2+block)-PN/2-1)=-300;%找出负最大值赋给out
else
out_up(jj,i-(nn-1)*(PN/2+block)-PN/2-1)=Temp;
end
%以下计算 out_down
if((tempd0==0)&(tempd1==0))
Temp=0;
elseif((tempd0==0)&(tempd1~=0))
Temp=300;
elseif((tempd1==0)&(tempd0~=0))
Temp=-300;
else
Temp=log(tempd1/tempd0);
end
if (Temp==Inf)
out_down(jj,i-(nn-1)*(PN/2+block)-PN/2-1)=300;
elseif(Temp==-Inf)
out_down(jj,i-(nn-1)*(PN/2+block)-PN/2-1)=-300;
else
out_down(jj,i-(nn-1)*(PN/2+block)-PN/2-1)=Temp;
end
%compute decoding output
if((temp0==0)&(temp1==0))
Temp=0;
elseif((temp0==0)&(temp1~=0))
Temp=300;
elseif((temp1==0)&(temp0~=0))
Temp=-300;
else
Temp=log(temp1/temp0);
end
if (Temp==Inf)
out(jj,i-(nn-1)*(PN/2+block)-PN/2-1)=300;
elseif(Temp==-Inf)
out(jj,i-(nn-1)*(PN/2+block)-PN/2-1)=-300;
else
out(jj,i-(nn-1)*(PN/2+block)-PN/2-1)=Temp;
end
% end %i %在此之前的内容已看懂
%根据译码反馈值,针对多用户的模板估计算法 ,重要,表明迭代! ===================soft_out are current???
%u1,u2 叠加各个用户的有用信号
template_signal2(jj,:) = template_signal2(jj,:)+temp_variant(1,:) * sign( out_up(jj,i-(nn-1)*(PN/2+block)-PN/2-1) );%??
template_signal2(jj,:) = template_signal2(jj,:)+temp_variant(2,:) * sign( out_down(jj,i-(nn-1)*(PN/2+block)-PN/2-1));
%针对多用户的模板估计算法结束
if i>(nn-1)*(PN/2+block)+PN/2+buflength/2+1 %前buflength/2次是训练比特,不计。ben 为接收编码值的概率估计误码个数
soft_out(jj,2*i-1-buflength-PN-2*(nn-1)*(PN/2+block))=out_up(jj,i-(nn-1)*(PN/2+block)-PN/2-1);
soft_out(jj,2*i-buflength-PN-2*(nn-1)*(PN/2+block))= out_down(jj,i-(nn-1)*(PN/2+block)-PN/2-1);
if(encoder_positive_nagetive(jj,2*i-1-buflength)~=sign(soft_out(jj,2*i-1-buflength-PN-2*(nn-1)*(PN/2+block))))
ben(jj) = ben(jj) + 1;
ben_all = ben_all + 1;
end
if(encoder_positive_nagetive(jj,2*i-buflength)~=sign(soft_out(jj,2*i-buflength-PN-2*(nn-1)*(PN/2+block))))
ben(jj) = ben(jj) + 1;
ben_all = ben_all + 1;
end
end % 以上为求误比特率
buf_len(jj,1:buflength-2) = buf_len(jj,3:buflength);
buf_len(jj,buflength-1)=soft_PNandData(jj,2*i-1);
buf_len(jj,buflength)=soft_PNandData(jj,2*i);
%---compute归一化 aa(ith bit)-----
a_buf(jj,1:buflength/2,1:nstates)=a_buf(jj,2:buflength/2+1,1:nstates);
for ii=1:8
a_buf(jj,buflength/2+1,ii)=a_temp(ii)/factor; %aa(k),buffer尾部
end
if( i == ((nn)*(PN/2+block)+1))
aa(jj,1,1:nstates) = a_buf(jj,buflength/2+1,1:nstates);%initial a(1) for next trainning
end
%----------- aa computing end-------
end%jj
elseif algorithp==0 %尚未考虑,错 此为LMS算法
if(i<PN/2)
mlms = 0.0032;
else
mlms = 0.0005;
end
for jj = 1:K
w(:,jj) = w(:,jj) + mlms*(encoder_positive_nagetive(jj,2*i-1) - w(:,jj)'*u1')*u1';
soft_PNandData(jj,2*i-1)=u1*w(:,jj);% for different users ,LMS
w(:,jj) = w(:,jj) + mlms*(encoder_positive_nagetive(jj,2*i) - w(:,jj)'*u2')*u2';
soft_PNandData(jj,2*i)=u2*w(:,jj);
end
end %algorithm,某2个比特i,i+1
%-----------------画误差曲线图----------------
%以下为求误码率 未看懂
if i>(nn-1)*(PN/2+block)+PN/2+buflength/2+1
temp1 = 0;
temp2 = 0;
for jj = 1:K
temp1 = temp1 + abs(encoder_positive_nagetive(jj,2*i-1-buflength) -soft_PNandData(jj,2*i-1-buflength));
temp2 = temp2 + abs(encoder_positive_nagetive(jj,2*i-buflength) - soft_PNandData(jj,2*i-buflength));
end
error(2*i-3-buflength) = temp1/K; % 第i个比特平均训练误差
error(2*i-2-buflength) = temp2/K;
end
%----------------------------------------------
%此处加入针对多用户的模板估计算法
%根据译码反馈,修改信道估计值template_signal
temp_counter=temp_counter+2;
template_signal1 = template_signal2/ (temp_counter+(tr2-tr1+1)*2); % 每次2个比特用于信道估计
end %i
for jj=1:K
for i=1:block
%如果i>variance_position+恢复期,才计算误码。恢复期=recover_length
if (sign(out(jj,buflength/2+i))~=2*data(jj,(nn-1)*(PN/2+block)+PN/2+i)-1) % 数据误码率
% if ((variance_position-PN/2)>i)|(i>(variance_position-PN/2-buflength/2+recover_length))
wrong_No(jj)=wrong_No(jj)+1;
% display=i
% else
% wrong_cut(jj)=wrong_cut(jj)+1;
% i
% end
end
end
end%jj
%均衡以后,没有译码的BER ,硬判决
error1=0;
for jj=1:K
for i=1:length(encoderout)
if sign( soft_PNandData(jj,2+i) )~=2*encoderout(jj,i)-1
error1=error1+1;
end
end
end%jj
%end
no_coded=error1/(length(encoderout)*K)%硬判决误码率
end %nn
% repeat=nn%display====
equal1_K = ben./(num*2*block);
equal1_all = ben_all/((num*2*block)*K) % 编码码字 的误码率
wrong_No
wrong_cut
block1=block-recover_length;%扣除恢复期
Ber=wrong_No/(block1) % 译码后信息数据误码率
sum_wrong=0;
% for jj=1:K
sum_wrong=sum(wrong_No);
% end
SUM_decode = SUM_decode + sum_wrong;
SUM_encode = SUM_encode + ben_all;
end %repeatnum
decoder_BER(var,zz)=SUM_decode/(K*block1*num*repeatnum);
encoder_BER(var,zz)=SUM_encode/(2*block1*K*num*repeatnum);
for jj=1:K
mse1(1,jj)=sum((vv( datav(jj,2) , 1:180 , jj )-template_signal_average(jj,:)).^2)/sum(vv( datav(jj,2) , 1:180 , jj ).^2);
mse2(1,jj)=sum((v( datav(jj,2) , 1:180 , jj )-template_signal1(jj,:)).^2)/sum(v( datav(jj,2) , 1:180 , jj ).^2);
abero1(jj,:) =(vv( datav(jj,2) , 1:180 , jj )-template_signal_average(jj,:));
abero2(jj,:) =(v( datav(jj,2) , 1:180 , jj )-template_signal1(jj,:));
end
MSE_averag(var,zz)=sum(mse2)/K;
%for i=1:K
% figure(i);
% subplot(2,3,1)
% stem(1:180,vv( datav(i,2) , 1:180 , i ),'.');
% title('Training Signal');
% axis([1 180 -1.5 1.5]);
% subplot(2,3,2)
% stem(1:180,template_signal_average(i,:),'.');
% title('Estimated Train Template');
% axis([1 180 -1.5 1.5]);
%
% subplot(2,3,3)
% stem(1:180,abero1(i,:),'.');
% title(' Train Template Error');
% axis([1 180 -1.5 1.5]);
% subplot(2,3,4)
% stem(1:180,v( datav(i,2) , 1:180 , i ),'.');
% title('Time-variance Signal');
% axis([1 180 -1.5 1.5]);
%
% subplot(2,3,5) %draw the estimated signal
% stem( 1:180,template_signal1(i,:), '.' );
% title('Estimated Time-variance Template');
% axis([1 180 -1.5 1.5]);
%
% subplot(2,3,6)
% stem(1:180,abero2(i,:),'.');
% title('Estimated Template Error');
% axis([1 180 -1.5 1.5]);
% end
%
% figure(K+1);
% plot(error);
% title('Channel Bits Estimated Errors');
% axis([1 2*block+PN 0 1.5]);
%end%nn
end%dB
end%fs,var
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -