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

📄 cyc_sch_decoder.m

📁 MATLBA 信道仿真,完成信道卷积码循环码的编译码
💻 M
字号:
%cyclic_coder
%g(x)=x^10+x^8+x^6+x^5+x^4+x^2+1
%//输入35位长度
%u:buffer(35-bit length)

function [sysinfo,ccx]=cyc_sch_encoder(u)

%以下为去尾比特
uu=zeros(1,35);
uu(1:35)=u(1:35);

%以下为译码程序
uu=[uu];
feedback=0;
sysinfo=[];
ccx=[];



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%error mode:/g(x)
%the result:error_mode_reg(1:10) //from left to right: low to high

error_mode_reg=zeros(1,10);
error_mode_gg=zeros(1,11);
error_mode_gg(11)=1;
error_mode_gg(9)=1;
error_mode_gg(7)=1;
error_mode_gg(6)=1;
error_mode_gg(5)=1;
error_mode_gg(3)=1;
error_mode_gg(1)=1;
%get the S(x)    //计算伴随式S(x)
for i=1:length(uu)
   feedback=error_mode_gg(11)*error_mode_reg(10);
   for j=10:-1:2
      error_mode_reg(j)=rem(error_mode_reg(j-1)+feedback*error_mode_gg(j),2);
   end
   error_mode_reg(1)=rem(uu(i)+feedback*error_mode_gg(1),2);
end
%S(x)=error_mode_reg(10)*x^9+error_mode_reg(9)*x^8+...+error_mode_reg(1)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% whether S(x)=0   //判断伴随式是否为0,如果为0则说明没有错误
% if S(x)=0 then no error exist 
if(error_mode_reg(6:10)==zeros(1,5))
      sysinfo='System Information : There is no error in the code';
      ccx=uu(1:25);
      return
      %break
end  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%all-zero detector of S: error_mode_reg(2:11) //from left to right: low to high
%//如果不全为0,则判断低5位是否全为0,如果不为0,则自循环移位,再判断低5位是否全为0,如此往复
%//,直到移位次数为35。
bc=0;	
count=0;
while count<35
   %detect the high 5-bit is zero-sequence
   if(error_mode_reg(6:10)==zeros(1,5))
      bc=0;
      break
   end
   
   bc=1;
   
   %loop for one time
   feedback=error_mode_gg(11)*error_mode_reg(10);
   
   for j=10:-1:2
      error_mode_reg(j)=rem(error_mode_reg(j-1)+feedback*error_mode_gg(j),2);
   end
   error_mode_reg(1)=feedback;
   count=count+1;
end

%bc=1 error can not be checked; bc=0 error can be checked
%//如果循环移位35次仍没有满足低5位为全0,则说明无法纠错!
if(bc==1|count==35)
   sysinfo='System Information : Cannot detect the error!';
   ccx=uu(1:25);
   %stop the encoder
   return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%get the count//根据移位次数和求得的错误图样,纠错。
%E(x)=error_mode_reg(1)+error_mode_reg(2)*x+...+error_mode_reg(5)*x^4
%The error = E(x)
%uu(x)=uu(35)+uu(34)*x+uu(33)*x^2+...+uu(3)*x^32+uu(2)*x^33+uu(1)*x^34
%correct the code uu(x)+E(x)
 if count>=10  
     for i=1:10
         j=count-i+1;
         uu(j)=rem(uu(j)+error_mode_reg(i),2);
     end
 end
 if count<10&count>0
     for i=1:count
         j=count-i+1;
         uu(j)=rem(uu(j)+error_mode_reg(i),2);
     end
      for i=1:10-count
          j=35-i+1;
          uu(j)=rem(uu(j)+error_mode_reg(count+i),2); 
      end
 end    
 if count==0
     for i=1:10
         j=35-i+1;
         uu(j)=rem(uu(j)+error_mode_reg(i),2);
         
     end
 end
  sysinfo='System Information : Errors have been corrcted';
ccx=uu(1:25);


⌨️ 快捷键说明

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