max_th.asv
上传用户:hnyfjx
上传日期:2013-06-30
资源大小:2149k
文件大小:6k
源码类别:

传真(Fax)编程

开发平台:

Matlab

  1. function [soft_out,ex_info]=max_th(n,app)
  2. %****************************************************************
  3. % 内容概述:子译码器。
  4. %          利用硬件化的方式实现TURBO码的MAX-LOG-MAP译码
  5. %          生成矩阵按照3GPP标准为[1 1 0 1;1 0 1 1]
  6. %          输入为经过高斯信道的RSC软输入,而输出为软输出和外部信息
  7. % 创 建 人:朱殿荣/QQ:235347/MSN:njzdr@msn.com
  8. % 单    位:南京邮电大学,通信工程系
  9. % 创建时间:2005年9月3日
  10. % 修改时间:
  11. % 参考文献:《数字通信--基础与应用》
  12. %          《改进的Turbo码算法及其FPGA实现过程的研究》,天津大学,张宁,赵雅兴
  13. %           后向度量的计算方式和decoder_3GPP_MAX.m有所不同
  14. % 版权声明:任何人均可复制、传播、修改此文件,同时需保留原始版权信息。
  15. %****************************************************************
  16.  
  17. x=in(1,:);              %输入系统位
  18. y=in(2,:);              %输入校验位
  19. in_length=length(in);
  20. % Kw=0;
  21. %---初始化&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  22. ln2=0.693147;               %超过门限后的max运算补偿值
  23. Infty = -128;
  24. d=zeros(8,2,in_length);     %分支量度,8种可能状态,输入为0或者1
  25.                             %D(S,i,k)
  26. a=Infty*ones(8,in_length);  %前向分支量度,A(S,k)
  27. a(1,1)=0;                   %寄存器状态由全零开始
  28. b=Infty*ones(8,in_length+1);%后向分支量度,B(S,k)
  29. b(1,in_length)=0;           %寄存器状态由全零结束
  30. %---计算度量和LLR&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  31. for k=1:in_length
  32.     d(1,2,k)=x(k)+y(k)+app(k);
  33.     d(2,2,k)=d(1,2,k);
  34.     d(7,2,k)=d(1,2,k);
  35.     d(8,2,k)=d(1,2,k);
  36.     
  37.     d(3,2,k)=x(k)+app(k);
  38.     d(4,2,k)=d(3,2,k);
  39.     d(5,2,k)=d(3,2,k);
  40.     d(6,2,k)=d(3,2,k);
  41.     d(3,1,k)=y(k);
  42.     d(4,1,k)=d(3,1,k);
  43.     d(5,1,k)=d(3,1,k);
  44.     d(6,1,k)=d(3,1,k);
  45.     
  46.     if k>1
  47.         %a(1,k)=max((a(1,k-1)+d(1,1,k-1)),(a(2,k-1)+d(2,2,k-1)))+Kw;
  48.         %a(2,k)=max((a(4,k-1)+d(4,1,k-1)),(a(3,k-1)+d(3,2,k-1)))+Kw;
  49.         %a(3,k)=max((a(5,k-1)+d(5,1,k-1)),(a(6,k-1)+d(6,2,k-1)))+Kw;
  50.         %a(4,k)=max((a(8,k-1)+d(8,1,k-1)),(a(7,k-1)+d(7,2,k-1)))+Kw;
  51.         %a(5,k)=max((a(2,k-1)+d(2,1,k-1)),(a(1,k-1)+d(1,2,k-1)))+Kw;
  52.         %a(6,k)=max((a(3,k-1)+d(3,1,k-1)),(a(4,k-1)+d(4,2,k-1)))+Kw;
  53.         %a(7,k)=max((a(6,k-1)+d(6,1,k-1)),(a(5,k-1)+d(5,2,k-1)))+Kw;
  54.         %a(8,k)=max((a(7,k-1)+d(7,1,k-1)),(a(8,k-1)+d(8,2,k-1)))+Kw;         
  55.         a(1,k)=max(a(1,k-1),(a(2,k-1)+d(2,2,k-1)));
  56.         if abs(a(1,k-1)-(a(2,k-1)+d(2,2,k-1)))<1
  57.             a(1,k)=max(a(1,k-1),(a(2,k-1)+d(2,2,k-1)))+ln2;
  58.         end
  59.         a(2,k)=max((a(4,k-1)+d(4,1,k-1)),(a(3,k-1)+d(3,2,k-1)));
  60.         a(3,k)=max((a(5,k-1)+d(5,1,k-1)),(a(6,k-1)+d(6,2,k-1)));
  61.         a(4,k)=max(a(8,k-1),(a(7,k-1)+d(7,2,k-1)));
  62.         a(5,k)=max(a(2,k-1),(a(1,k-1)+d(1,2,k-1)));
  63.         a(6,k)=max((a(3,k-1)+d(3,1,k-1)),(a(4,k-1)+d(4,2,k-1)));
  64.         a(7,k)=max((a(6,k-1)+d(6,1,k-1)),(a(5,k-1)+d(5,2,k-1)));
  65.         a(8,k)=max(a(7,k-1),(a(8,k-1)+d(8,2,k-1)));      
  66.     end
  67.     
  68.     if k==in_length
  69.         %b(1,k)=max((b(1,k+1)+d(1,1,k)),(b(5,k+1)+d(1,2,k)))+Kw;
  70.         %b(2,k)=max((b(5,k+1)+d(2,1,k)),(b(1,k+1)+d(2,2,k)))+Kw;
  71.         %b(3,k)=max((b(6,k+1)+d(3,1,k)),(b(2,k+1)+d(3,2,k)))+Kw;
  72.         %b(4,k)=max((b(2,k+1)+d(4,1,k)),(b(6,k+1)+d(4,2,k)))+Kw;
  73.         %b(5,k)=max((b(3,k+1)+d(5,1,k)),(b(7,k+1)+d(5,2,k)))+Kw;
  74.         %b(6,k)=max((b(7,k+1)+d(6,1,k)),(b(3,k+1)+d(6,2,k)))+Kw;
  75.         %b(7,k)=max((b(8,k+1)+d(7,1,k)),(b(4,k+1)+d(7,2,k)))+Kw;
  76.         %b(8,k)=max((b(4,k+1)+d(8,1,k)),(b(8,k+1)+d(8,2,k)))+Kw;
  77.         b(1,k)=max(b(1,k+1),(b(5,k+1)+d(1,2,k)));
  78.         b(2,k)=max(b(5,k+1),(b(1,k+1)+d(2,2,k)));
  79.         b(3,k)=max((b(6,k+1)+d(3,1,k)),(b(2,k+1)+d(3,2,k)));
  80.         b(4,k)=max((b(2,k+1)+d(4,1,k)),(b(6,k+1)+d(4,2,k)));
  81.         b(5,k)=max((b(3,k+1)+d(5,1,k)),(b(7,k+1)+d(5,2,k)));
  82.         b(6,k)=max((b(7,k+1)+d(6,1,k)),(b(3,k+1)+d(6,2,k)));
  83.         b(7,k)=max(b(8,k+1),(b(4,k+1)+d(7,2,k)));
  84.         b(8,k)=max(b(4,k+1),(b(8,k+1)+d(8,2,k)));
  85.         %计算LLR--------------------------------------
  86.         l(k)=max([...
  87.             (a(1,k)+d(1,2,k)+b(5,k+1)),(a(2,k)+d(2,2,k)+b(1,k+1)),...
  88.             (a(3,k)+d(3,2,k)+b(2,k+1)),(a(4,k)+d(4,2,k)+b(6,k+1)),...
  89.             (a(5,k)+d(5,2,k)+b(7,k+1)),(a(6,k)+d(6,2,k)+b(3,k+1)),...
  90.             (a(7,k)+d(7,2,k)+b(4,k+1)),(a(8,k)+d(8,2,k)+b(8,k+1))...
  91.             ])-max([...
  92.             (a(1,k)+b(1,k+1)),(a(2,k)+b(5,k+1)),...
  93.             (a(3,k)+d(3,1,k)+b(6,k+1)),(a(4,k)+d(4,1,k)+b(2,k+1)),...
  94.             (a(5,k)+d(5,1,k)+b(3,k+1)),(a(6,k)+d(6,1,k)+b(7,k+1)),...
  95.             (a(7,k)+b(8,k+1)),(a(8,k)+b(4,k+1))...
  96.             ]);
  97.     end
  98. end
  99. for k=in_length-1:-1:1
  100.         b(1,k)=max(b(1,k+1),(b(5,k+1)+d(1,2,k)));
  101.         b(2,k)=max(b(5,k+1),(b(1,k+1)+d(2,2,k)));
  102.         b(3,k)=max((b(6,k+1)+d(3,1,k)),(b(2,k+1)+d(3,2,k)));
  103.         b(4,k)=max((b(2,k+1)+d(4,1,k)),(b(6,k+1)+d(4,2,k)));
  104.         b(5,k)=max((b(3,k+1)+d(5,1,k)),(b(7,k+1)+d(5,2,k)));
  105.         b(6,k)=max((b(7,k+1)+d(6,1,k)),(b(3,k+1)+d(6,2,k)));
  106.         b(7,k)=max(b(8,k+1),(b(4,k+1)+d(7,2,k)));
  107.         b(8,k)=max(b(4,k+1),(b(8,k+1)+d(8,2,k)));
  108.         %计算LLR--------------------------------------
  109.         l(k)=max([...
  110.             (a(1,k)+d(1,2,k)+b(5,k+1)),(a(2,k)+d(2,2,k)+b(1,k+1)),...
  111.             (a(3,k)+d(3,2,k)+b(2,k+1)),(a(4,k)+d(4,2,k)+b(6,k+1)),...
  112.             (a(5,k)+d(5,2,k)+b(7,k+1)),(a(6,k)+d(6,2,k)+b(3,k+1)),...
  113.             (a(7,k)+d(7,2,k)+b(4,k+1)),(a(8,k)+d(8,2,k)+b(8,k+1))...
  114.             ])-max([...
  115.             (a(1,k)+b(1,k+1)),(a(2,k)+b(5,k+1)),...
  116.             (a(3,k)+d(3,1,k)+b(6,k+1)),(a(4,k)+d(4,1,k)+b(2,k+1)),...
  117.             (a(5,k)+d(5,1,k)+b(3,k+1)),(a(6,k)+d(6,1,k)+b(7,k+1)),...
  118.             (a(7,k)+b(8,k+1)),(a(8,k)+b(4,k+1))...
  119.             ]);
  120.    %计算LLR--------------------------------------
  121. %   l(k)=max([...
  122. %       (a(1,k)+d(1,2,k)+b(5,k+1)),(a(2,k)+d(2,2,k)+b(1,k+1)),...
  123. %       (a(3,k)+d(3,2,k)+b(2,k+1)),(a(4,k)+d(4,2,k)+b(6,k+1)),...
  124. %       (a(5,k)+d(5,2,k)+b(7,k+1)),(a(6,k)+d(6,2,k)+b(3,k+1)),...
  125. %       (a(7,k)+d(7,2,k)+b(4,k+1)),(a(8,k)+d(8,2,k)+b(8,k+1))...
  126. %       ])-max([...
  127. %       (a(1,k)+d(1,1,k)+b(1,k+1)),(a(2,k)+d(2,1,k)+b(5,k+1)),...
  128. %       (a(3,k)+d(3,1,k)+b(6,k+1)),(a(4,k)+d(4,1,k)+b(2,k+1)),...
  129. %       (a(5,k)+d(5,1,k)+b(3,k+1)),(a(6,k)+d(6,1,k)+b(7,k+1)),...
  130. %       (a(7,k)+d(7,1,k)+b(8,k+1)),(a(8,k)+d(8,1,k)+b(4,k+1))...
  131. %       ]); 
  132. end
  133. soft_out=l;
  134. ex_info=soft_out-app-x;