⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mequal_estimation_bit_improve.m

📁 Convolution_decoder_bit_by_bit for DS-UWB is revising信号模板的估计
💻 M
📖 第 1 页 / 共 4 页
字号:
				judge(7,5)=1;
                judge(7,6)=1;
				judge(8,7)=1;
                judge(8,8)=1;
				
			%the value of c(i)(j) is the input data of encoder that tansform state i into state j
				c(1,1)=0;
                c(1,2)=1;   
				c(2,3)=0;
                c(2,4)=1;
				c(3,5)=0;
                c(3,6)=1;
				c(4,7)=0;
                c(4,8)=1;
				c(5,1)=0;
                c(5,2)=1;
				c(6,3)=0;
                c(6,4)=1;
				c(7,5)=0;
                c(7,6)=1;
				c(8,7)=0;
                c(8,8)=1;
				
              
             %//  the output data when state i turn into state j
			
                d(1,1,1)=0;d(1,1,2)=0;%d(state,nextstate,output1/2th)=output
                d(1,2,1)=1; d(1,2,2)=1;   
				d(2,3,1)=1;d(2,3,2)=1;
                d(2,4,1)=0;d(2,4,2)=0;
				d(3,5,1)=0;d(3,5,2)=1;
                d(3,6,1)=1;d(3,6,2)=0;
				d(4,7,1)=1;d(4,7,2)=0;
                d(4,8,1)=0;d(4,8,2)=1;
				d(5,1,1)=1;d(5,1,2)=1;
                d(5,2,1)=0; d(5,2,2)=0;
				d(6,3,1)=0;d(6,3,2)=0;
                d(6,4,1)=1;d(6,4,2)=1;
				d(7,5,1)=1;d(7,5,2)=0;
                d(7,6,1)=0; d(7,6,2)=1;
				d(8,7,1)=0;d(8,7,2)=1;
                d(8,8,1)=1;d(8,8,2)=0;
				
			
			
			%--------------------Training Stage-----------------------
			
			algorithp =1;% input('输入采用何种算法更新训练权系数[0-LMS,1-RLS] algorithp =' ');
			             %PN = input('输入训练比特数目 PN = ');
			soft_PNandData=zeros(K,length(encoderout)+2); %shift 2 bits
			error = zeros(1,length(encoderout));
			wrong_No=zeros(1,K);
            wrong_cut=zeros(1,K);
			ben = zeros(1,K); % 每个用户判决错误比特个数
			ben_all = 0; % 所有用户判决错误的总比特数
            
			mse=zeros(1,K);
            abero=zeros(K,bit_extension/fs);
            template_signal=zeros(K,fix(bit_extension/fs));
            template_signal1=zeros(K,fix(bit_extension/fs));
            template_signal2=zeros(K,fix(bit_extension/fs));
            template_u1=zeros(K,fix(bit_extension/fs));
            template_u2=zeros(K,fix(bit_extension/fs));
            temp_counter=0;
            temp_variant=zeros( buflength+2, fix(bit_extension/fs));  %由于信道译码有延迟buflength,需要存储buflength个数据用于信道估计,为衔接,从训练阶段就开始
 
            
			for nn = 1: num  
                
                w = zeros(fix(bit_extension/fs),K); % 初使化用户的权值 
                for ppp = 1 : K                     % 初使化P
                    P(:,:,ppp) = diat*I;
                end
			
                tr1=(nn-1)*(PN/2+block)+2;
                tr2=(nn-1)*(PN/2+block)+PN/2+1; 
                
				for i = tr1:tr2 %      训练比特数,每次读2比特,PN/2次。
                        
                    u1 = zeros(1,fix(bit_extension/fs)); 
                    u2 = zeros(1,fix(bit_extension/fs)); 
				
                        
                    for j = 1:K         %u1,u2 叠加各个用户的有用信号
                            
                        t = min(2*i-1,datav(j,3)-datav(j,2)+1);
                        
                        for kk = (datav(j,1)-datav(j,2)+1):1:t
                           
                            u1 = u1 + encoder_positive_nagetive(j,2*i-1-kk+1)*v((kk+datav(j,2)-1),:,j); %  V就是窗口长度截取的数据V(1~20,180,USER),(1 2) (2 3) (3 4)......
                            
                        end
                        t = min(2*i,datav(j,3)-datav(j,2)+1);
                        
                        for kk = (datav(j,1)-datav(j,2)+1):1:t
                           
                            u2 = u2 + encoder_positive_nagetive(j,2*i-kk+1)*v((kk+datav(j,2)-1),:,j);
                            
                        end
                          
                    end  %end users
                                       
                    if(open==1) % 考虑高斯噪声
                        
                        u1 = u1 + noise;
                        
                        tempnoise1 = noise(fix(90/fs)+1:fix(bit_extension/fs));
                        
                        tempnoise2 = normrnd(MU,SIGMA);
                        
                        noise = tempnoise2;
                        
                        noise(1:round((across-1)*90/fs)) = tempnoise1;
                        
                        u2 = u2 + noise;
                        
                        tempnoise1 = noise(fix(90/fs)+1:fix(bit_extension/fs));
                        
                        tempnoise2 = normrnd(MU,SIGMA);
                        
                        noise = tempnoise2;
                        
                        noise(1:round((across-1)*90/fs)) = tempnoise1;
                        
                    end
                    % plot(u)
                    
                    %此处加入针对多用户的模板估计算法=======================================
                    for j = 1:K         %u1,u2 
                        template_signal(j,:)=template_signal(j,:)+u1*encoder_positive_nagetive(j,2*i-1);
                        template_signal(j,:)=template_signal(j,:)+u2*encoder_positive_nagetive(j,2*i);
                    end
                    %针对多用户的模板估计算法结束
        
                    
                    %adjust u1,u2
%                     if i>tr2
                        template_temp=template_signal/( (i-1)*2 );%模版
                        for j=1:K
                            template_u1(j,:) = template_temp(j,:).*u1;%相关
                            template_u2(j,:) = template_temp(j,:).*u2;
                        end
%                     else
%                         for j=1:K
%                             template_u1(j,:) = u1;%接收信号直接用于训练
%                             template_u2(j,:) = u2;
%                         end
% 
%                     end
                    %adjust u1,u2 end
                    %缓存60个u1,u2值,目前无用,译码时才有用--------------------- 
                    for mm= 1 : buflength/2
                        temp_variant( 2*mm-1,:) = temp_variant( 2*(mm+1)-1,:);
                        temp_variant( 2*mm,:) = temp_variant( 2*(mm+1),:);
                    end
                    temp_variant( buflength+1,:) = u1;
                    temp_variant( buflength+2,:) = u2;
                    %------------------------------------------------------
                    
                    if  algorithp==1          %input('输入采用何种算法更新判决权系数[0-LMS,1-RLS,2-LMS_modify] algorithd =' ');
                    
                        for jj = 1:K
                            pai(jj,:) = template_u1(jj,:) * P(:,:,jj);     % for all users u1
                            k(:,jj) = pai(jj,:)'/( nmda+pai(jj,:) * template_u1(jj,:)' );    % for all users
                            soft_PNandData(jj,2*i-1) = template_u1(jj,:) * w(:,jj);
                            w(:,jj) = w(:,jj) + (encoder_positive_nagetive(jj,2*i-1) - soft_PNandData(jj,2*i-1))*k(:,jj); % for different users ,RLS
                            P(:,:,jj) = (P(:,:,jj)-k(:,jj)*pai(jj,:))/nmda; % for all users u2
                        end
                                        
                        for jj = 1:K
                            
                            pai(jj,:) = template_u2(jj,:) * P(:,:,jj);% for all users
                            k(:,jj) = pai(jj,:)'/( nmda+pai(jj,:) * template_u2(jj,:)' ); % for all users
                            soft_PNandData(jj,2*i)=template_u2(jj,:)*w(:,jj);
                            w(:,jj) = w(:,jj) + (encoder_positive_nagetive(jj,2*i) - soft_PNandData(jj,2*i))*k(:,jj); % for different users ,RLS
                            P(:,:,jj) = (P(:,:,jj)-k(:,jj)*pai(jj,:))/nmda; % for all users u2
                        end
                        
                    elseif  algorithp==0  % input('输入采用何种算法更新判决权系数[0-LMS,1-RLS,2-LMS_modify] algorithd = ');
                    
                        if(i<PN/2)
                        
                            mlms = 0.0032;
                            
                        else
                            
                            mlms = 0.0005;
                            
                        end
                        
                        for jj = 1:K                   %LMS算法   FPGA中用这种算法实现比较好
                            soft_PNandData(jj,2*i-1)=template_u1(jj,:)*w(:,jj);% for different users ,LMS
                            w(:,jj) = w(:,jj) + mlms*(encoder_positive_nagetive(jj,2*i-1) - soft_PNandData(jj,2*i-1))*template_u1(jj,:)'; 
                            soft_PNandData(jj,2*i)=template_u2(jj,:)*w(:,jj); 
                            w(:,jj) = w(:,jj) + mlms*(encoder_positive_nagetive(jj,2*i) - soft_PNandData(jj,2*i))*template_u2(jj,:)';
                               
                        end 
                      
                        
                    end  %algorithm,某2个比特i,i+1
                    
                    %-----------------画平均误差曲线图----------------                  
                    temp1 = 0;
                    temp2 = 0; 
                    for jj = 1:K %K=1只是单个用户
                        
                        temp1 = temp1 + abs(encoder_positive_nagetive(jj,2*i-1) -soft_PNandData(jj,2*i-1));
                        temp2 = temp2 + abs(encoder_positive_nagetive(jj,2*i) - soft_PNandData(jj,2*i)); 
                     
                    end
                    
                    error(2*i-3) = temp1/K;% 第i个比特平均训练误差
                    error(2*i-2) = temp2/K;     %此处应该有个关于i的for循环
                     %---------------------------------------------------
               				
				
                %--------------compute aa(i)--------------------------------
                 
                 for jj=1:K        %jj start
                    x(jj,i-1)=soft_PNandData(jj,2*i-1);
                    y(jj,i-1)=soft_PNandData(jj,2*i);
                    var1=computevariance(x);         %调用计算变量函数
                    if (var1<= 0.01)
                        var1=0.01;
                    end
                    var2=computevariance(y);           %调用计算变量函数
                    if (var2<=0.01)
                    var2=0.01;
                    end
                    Lc1(jj)=2/var1;      %公式里的两个常数
                    Lc2(jj)=2/var2;
                    
                      
                    factor=0;
                    for m=1:nstates
                        a_temp(m)=0;
                        for fm=1:nstates
                            if (judge(fm,m)==0)
                                gama_with_info=0;   %r等于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));  %求出r值
                                  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*aa(jj,i-1-(nn-1)*(PN/2+block),fm); %a(i-1)
                            if (a_temp(m)==inf)
                                a_temp(m)=300;
                            end
                        end
                        factor=factor+a_temp(m);    
                    end
                    
                   	for ii=1:nstates
					   aa(jj,i-(nn-1)*(PN/2+block),ii)=a_temp(ii)/factor;   %求得a(i)
                    end
                    
                 end    %jj end multiuser,compute aa(i)
                 
                end     %i PN
            
            
			%此处加入针对多用户的模板估计算法
             template_signal2=template_signal;
            template_signal_average=template_signal/( (tr2-tr1+1)*2 );
              template_signal1=template_signal_average;%作为判决阶段的初始模版
            %针对多用户的模板估计算法结束
            
%             for i=1:K
 %                figure(i);
  %               subplot(2,1,1)
   %              stem(1:180,v( datav(i,2) , 1:180 , i ),'.');
    %             title('Actual signal');
     %            axis([1 180 -1.5 1.5]);
 		
 %                subplot(2,1,2)               %draw the estimated signal
  %               stem( 1:180,template_signal_average(i,:), '.' );
   %              title('Estimated signal template');
    %             axis([1 180 -1.5 1.5]);
     %        end

			%end%nn
		vv=v;	
			%------------------Decision-Direct Stage-----------------
			
			algorithd =1;% input('输入采用何种算法更新判决权系数[0-LMS,1-RLS, 2-LMS_modify] algorithd =‘ ');
			% Sign_Data=zeros(K,length(encoderout)-PN+2+10);%+10以防溢出
			% Sign_Data(1:K,3:length(encoderout)-PN+2)=b(1:K,PN+1:length(encoderout));
			
			%  soft_in = zeros(K,length(encoderout)-PN+2);%卷积码软输入,前面空2比特
            soft_out = zeros(K,2*block+2);                %卷积码软输出,前面空2比特

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -