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

传真(Fax)编程

开发平台:

Matlab

  1. %function [soft_out,ex_info]=com_decoder_cap(in,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年7月23日
  10. % 修改时间:
  11. % 参考文献:《数字通信--基础与应用》
  12. %          《改进的Turbo码算法及其FPGA实现过程的研究》,天津大学,张宁,赵雅兴
  13. %           后向度量的计算方式和decoder_3GPP_MAX.m有所不同
  14. % 版权声明:任何人均可复制、传播、修改此文件,同时需保留原始版权信息。
  15. %****************************************************************
  16. clear 
  17. o_in=[1 0 1 0 0];
  18. %编码器输入
  19. [encoder_out,alphaout]=turbo(o_in);
  20. %编码器输出
  21. in1=encoder_out(1:2,:);
  22. %选取RSC1编码输入作为译码输入
  23. app=zeros(1,8);
  24. %定义app为全零
  25. in=in1;
  26. x=in(1,:);              %输入系统位
  27. y=in(2,:);              %输入校验位
  28. in_length=length(in);
  29. % Kw=0;
  30. %---初始化&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  31. Infty = -128;
  32. d=zeros(8,2,in_length);     %分支量度,8种可能状态,输入为0或者1
  33.                             %D(S,i,k)
  34. a=Infty*ones(8,in_length);  %前向分支量度,A(S,k)
  35. a(1,1)=0;                   %寄存器状态由全零开始
  36. b=Infty*ones(8,in_length+1);%后向分支量度,B(S,k)
  37. b(1,in_length+1)=0;           %寄存器状态由全零结束
  38. %---计算度量和LLR&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  39. for k=1:in_length
  40.     d(1,2,k)=x(k)+y(k)+app(k);
  41.     d(2,2,k)=d(1,2,k);
  42.     d(7,2,k)=d(1,2,k);
  43.     d(8,2,k)=d(1,2,k);
  44.     
  45.     d(3,2,k)=x(k)+app(k);
  46.     d(4,2,k)=d(3,2,k);
  47.     d(5,2,k)=d(3,2,k);
  48.     d(6,2,k)=d(3,2,k);
  49.     d(3,1,k)=y(k);
  50.     d(4,1,k)=d(3,1,k);
  51.     d(5,1,k)=d(3,1,k);
  52.     d(6,1,k)=d(3,1,k);
  53.     
  54.     if k>1
  55.         %a(1,k)=max((a(1,k-1)+d(1,1,k-1)),(a(2,k-1)+d(2,2,k-1)))+Kw;
  56.         %a(2,k)=max((a(4,k-1)+d(4,1,k-1)),(a(3,k-1)+d(3,2,k-1)))+Kw;
  57.         %a(3,k)=max((a(5,k-1)+d(5,1,k-1)),(a(6,k-1)+d(6,2,k-1)))+Kw;
  58.         %a(4,k)=max((a(8,k-1)+d(8,1,k-1)),(a(7,k-1)+d(7,2,k-1)))+Kw;
  59.         %a(5,k)=max((a(2,k-1)+d(2,1,k-1)),(a(1,k-1)+d(1,2,k-1)))+Kw;
  60.         %a(6,k)=max((a(3,k-1)+d(3,1,k-1)),(a(4,k-1)+d(4,2,k-1)))+Kw;
  61.         %a(7,k)=max((a(6,k-1)+d(6,1,k-1)),(a(5,k-1)+d(5,2,k-1)))+Kw;
  62.         %a(8,k)=max((a(7,k-1)+d(7,1,k-1)),(a(8,k-1)+d(8,2,k-1)))+Kw;         
  63.         a(1,k)=max(a(1,k-1),(a(2,k-1)+d(2,2,k-1)));
  64.         a(2,k)=max((a(4,k-1)+d(4,1,k-1)),(a(3,k-1)+d(3,2,k-1)));
  65.         a(3,k)=max((a(5,k-1)+d(5,1,k-1)),(a(6,k-1)+d(6,2,k-1)));
  66.         a(4,k)=max(a(8,k-1),(a(7,k-1)+d(7,2,k-1)));
  67.         a(5,k)=max(a(2,k-1),(a(1,k-1)+d(1,2,k-1)));
  68.         a(6,k)=max((a(3,k-1)+d(3,1,k-1)),(a(4,k-1)+d(4,2,k-1)));
  69.         a(7,k)=max((a(6,k-1)+d(6,1,k-1)),(a(5,k-1)+d(5,2,k-1)));
  70.         a(8,k)=max(a(7,k-1),(a(8,k-1)+d(8,2,k-1)));      
  71.     end
  72.     
  73.     if k==in_length
  74.         %b(1,k)=max((b(1,k+1)+d(1,1,k)),(b(5,k+1)+d(1,2,k)))+Kw;
  75.         %b(2,k)=max((b(5,k+1)+d(2,1,k)),(b(1,k+1)+d(2,2,k)))+Kw;
  76.         %b(3,k)=max((b(6,k+1)+d(3,1,k)),(b(2,k+1)+d(3,2,k)))+Kw;
  77.         %b(4,k)=max((b(2,k+1)+d(4,1,k)),(b(6,k+1)+d(4,2,k)))+Kw;
  78.         %b(5,k)=max((b(3,k+1)+d(5,1,k)),(b(7,k+1)+d(5,2,k)))+Kw;
  79.         %b(6,k)=max((b(7,k+1)+d(6,1,k)),(b(3,k+1)+d(6,2,k)))+Kw;
  80.         %b(7,k)=max((b(8,k+1)+d(7,1,k)),(b(4,k+1)+d(7,2,k)))+Kw;
  81.         %b(8,k)=max((b(4,k+1)+d(8,1,k)),(b(8,k+1)+d(8,2,k)))+Kw;
  82.         
  83.         b(1,k)=max(b(1,k+1),(b(5,k+1)+d(1,2,k)));
  84.         b(2,k)=max(b(5,k+1),(b(1,k+1)+d(2,2,k)));
  85.         b(3,k)=max((b(6,k+1)+d(3,1,k)),(b(2,k+1)+d(3,2,k)));
  86.         b(4,k)=max((b(2,k+1)+d(4,1,k)),(b(6,k+1)+d(4,2,k)));
  87.         b(5,k)=max((b(3,k+1)+d(5,1,k)),(b(7,k+1)+d(5,2,k)));
  88.         b(6,k)=max((b(7,k+1)+d(6,1,k)),(b(3,k+1)+d(6,2,k)));
  89.         b(7,k)=max(b(8,k+1),(b(4,k+1)+d(7,2,k)));
  90.         b(8,k)=max(b(4,k+1),(b(8,k+1)+d(8,2,k)));
  91.         %计算LLR--------------------------------------
  92.         l(k)=max([...
  93.             (a(1,k)+d(1,2,k)+b(5,k+1)),(a(2,k)+d(2,2,k)+b(1,k+1)),...
  94.             (a(3,k)+d(3,2,k)+b(2,k+1)),(a(4,k)+d(4,2,k)+b(6,k+1)),...
  95.             (a(5,k)+d(5,2,k)+b(7,k+1)),(a(6,k)+d(6,2,k)+b(3,k+1)),...
  96.             (a(7,k)+d(7,2,k)+b(4,k+1)),(a(8,k)+d(8,2,k)+b(8,k+1))...
  97.             ])-max([...
  98.             (a(1,k)+b(1,k+1)),(a(2,k)+b(5,k+1)),...
  99.             (a(3,k)+d(3,1,k)+b(6,k+1)),(a(4,k)+d(4,1,k)+b(2,k+1)),...
  100.             (a(5,k)+d(5,1,k)+b(3,k+1)),(a(6,k)+d(6,1,k)+b(7,k+1)),...
  101.             (a(7,k)+b(8,k+1)),(a(8,k)+b(4,k+1))...
  102.             ]);
  103.     end
  104. end
  105. for k=in_length-1:-1:1
  106.         b(1,k)=max(b(1,k+1),(b(5,k+1)+d(1,2,k)));
  107.         b(2,k)=max(b(5,k+1),(b(1,k+1)+d(2,2,k)));
  108.         b(3,k)=max((b(6,k+1)+d(3,1,k)),(b(2,k+1)+d(3,2,k)));
  109.         b(4,k)=max((b(2,k+1)+d(4,1,k)),(b(6,k+1)+d(4,2,k)));
  110.         b(5,k)=max((b(3,k+1)+d(5,1,k)),(b(7,k+1)+d(5,2,k)));
  111.         b(6,k)=max((b(7,k+1)+d(6,1,k)),(b(3,k+1)+d(6,2,k)));
  112.         b(7,k)=max(b(8,k+1),(b(4,k+1)+d(7,2,k)));
  113.         b(8,k)=max(b(4,k+1),(b(8,k+1)+d(8,2,k)));
  114.         %计算LLR--------------------------------------
  115.         l(k)=max([...
  116.             (a(1,k)+d(1,2,k)+b(5,k+1)),(a(2,k)+d(2,2,k)+b(1,k+1)),...
  117.             (a(3,k)+d(3,2,k)+b(2,k+1)),(a(4,k)+d(4,2,k)+b(6,k+1)),...
  118.             (a(5,k)+d(5,2,k)+b(7,k+1)),(a(6,k)+d(6,2,k)+b(3,k+1)),...
  119.             (a(7,k)+d(7,2,k)+b(4,k+1)),(a(8,k)+d(8,2,k)+b(8,k+1))...
  120.             ])-max([...
  121.             (a(1,k)+b(1,k+1)),(a(2,k)+b(5,k+1)),...
  122.             (a(3,k)+d(3,1,k)+b(6,k+1)),(a(4,k)+d(4,1,k)+b(2,k+1)),...
  123.             (a(5,k)+d(5,1,k)+b(3,k+1)),(a(6,k)+d(6,1,k)+b(7,k+1)),...
  124.             (a(7,k)+b(8,k+1)),(a(8,k)+b(4,k+1))...
  125.             ]);
  126.    %计算LLR--------------------------------------
  127. %   l(k)=max([...
  128. %       (a(1,k)+d(1,2,k)+b(5,k+1)),(a(2,k)+d(2,2,k)+b(1,k+1)),...
  129. %       (a(3,k)+d(3,2,k)+b(2,k+1)),(a(4,k)+d(4,2,k)+b(6,k+1)),...
  130. %       (a(5,k)+d(5,2,k)+b(7,k+1)),(a(6,k)+d(6,2,k)+b(3,k+1)),...
  131. %       (a(7,k)+d(7,2,k)+b(4,k+1)),(a(8,k)+d(8,2,k)+b(8,k+1))...
  132. %       ])-max([...
  133. %       (a(1,k)+d(1,1,k)+b(1,k+1)),(a(2,k)+d(2,1,k)+b(5,k+1)),...
  134. %       (a(3,k)+d(3,1,k)+b(6,k+1)),(a(4,k)+d(4,1,k)+b(2,k+1)),...
  135. %       (a(5,k)+d(5,1,k)+b(3,k+1)),(a(6,k)+d(6,1,k)+b(7,k+1)),...
  136. %       (a(7,k)+d(7,1,k)+b(8,k+1)),(a(8,k)+d(8,1,k)+b(4,k+1))...
  137. %       ]); 
  138. end
  139. soft_out=l;
  140. ex_info=soft_out-app-x;