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

传真(Fax)编程

开发平台:

Matlab

  1. %****************************************************************
  2. % 内容概述:利用硬件化的方式实现TURBO码的MAP译码
  3. %          未使用另外一个译码器反馈的外部信息 
  4. % 创 建 人:朱殿荣/QQ:235347/MSN:njzdr@msn.com
  5. % 单    位:南京邮电大学,通信工程系
  6. % 创建时间:2005年7月6日
  7. % 修改时间:
  8. % 参考文献:《数字通信--基础与应用》
  9. % 版权声明:任何人均可复制、传播、修改此文件,同时需保留原始版权信息。
  10. %****************************************************************
  11. clear;
  12. x=[1.5 0.5 -0.6];
  13. y=[0.8 0.2 1.2];
  14. alpha=zeros(4,4);   %前向状态量度,4种可能状态,约束长度为3.zeros(S,k)
  15. alpha(1,1)=1;       %前向状态量度初始值为1,其他为0
  16. belta=zeros(4,4);   %后向状态量度,4种可能状态,约束长度为3.zeros(S,k)
  17. belta(1,4)=1;       %后向状态量度末尾值为1,其他为0
  18. gamma0=zeros(4,4); %后向状态量度,4种可能状态,约束长度为3,输入0.zeros(S,k)
  19. gamma1=zeros(4,4); %后向状态量度,4种可能状态,约束长度为3,输入1.zeros(S,k)
  20. pi=0.5;           %先验概率
  21. %k=1---------------------------------------------
  22. k=1;
  23. gamma0(1,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,1)));
  24. gamma1(1,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,1)));
  25. gamma0(2,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,2)));
  26. gamma1(2,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,2)));
  27. gamma0(3,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,3)));
  28. gamma1(3,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,3)));
  29. gamma0(4,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,4)));
  30. gamma1(4,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,4)));
  31. %for s=1:4
  32. %    gamma0(s,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,s)));
  33. %    gamma1(s,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,s)));
  34. %end
  35. %k=2---------------------------------------------
  36. k=2;
  37. gamma0(1,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,1)));
  38. gamma1(1,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,1)));
  39. gamma0(2,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,2)));
  40. gamma1(2,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,2)));
  41. gamma0(3,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,3)));
  42. gamma1(3,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,3)));
  43. gamma0(4,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,4)));
  44. gamma1(4,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,4)));
  45. alpha(1,k)=gamma0(1,k-1)*alpha(1,k-1)+gamma0(3,k-1)*alpha(3,k-1);%后一项为0
  46. alpha(2,k)=gamma1(1,k-1)*alpha(1,k-1)+gamma1(3,k-1)*alpha(3,k-1);%后一项为0
  47. %k=3---------------------------------------------
  48. k=3;
  49. gamma0(1,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,1)));
  50. gamma1(1,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,1)));
  51. gamma0(2,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,2)));
  52. gamma1(2,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,2)));
  53. gamma0(3,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,3)));
  54. gamma1(3,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,3)));
  55. gamma0(4,k)=pi*exp(x(k)*(-1)+y(k)*(trellis_simple(-1,4)));
  56. gamma1(4,k)=pi*exp(x(k)*(1)+y(k)*(trellis_simple(1,4)));
  57. alpha(1,k)=gamma0(1,k-1)*alpha(1,k-1)+gamma0(3,k-1)*alpha(3,k-1);%后一项为0
  58. alpha(2,k)=gamma1(1,k-1)*alpha(1,k-1)+gamma1(3,k-1)*alpha(3,k-1);%后一项为0
  59. alpha(3,k)=gamma0(2,k-1)*alpha(2,k-1)+gamma0(4,k-1)*alpha(4,k-1);%后一项为0
  60. alpha(4,k)=gamma1(2,k-1)*alpha(2,k-1)+gamma1(4,k-1)*alpha(4,k-1);%后一项为0
  61. %k=4---------------------------------------------
  62. k=4;
  63. alpha(1,k)=gamma0(1,k-1)*alpha(1,k-1)+gamma0(3,k-1)*alpha(3,k-1);
  64. alpha(2,k)=gamma1(1,k-1)*alpha(1,k-1)+gamma1(3,k-1)*alpha(3,k-1);
  65. alpha(3,k)=gamma0(2,k-1)*alpha(2,k-1)+gamma0(4,k-1)*alpha(4,k-1);
  66. alpha(4,k)=gamma1(2,k-1)*alpha(2,k-1)+gamma1(4,k-1)*alpha(4,k-1);
  67. % for belta,from k=3------------------------
  68. k=3;
  69. belta(1,k)=gamma0(1,k)*belta(1,k+1)+gamma1(2,k)*belta(2,k+1);%后一项为0
  70. belta(3,k)=gamma0(3,k)*belta(1,k+1)+gamma1(2,k)*belta(2,k+1);%后一项为0
  71. % for belta,from k=2------------------------
  72. k=2;
  73. belta(1,k)=gamma0(1,k)*belta(1,k+1)+gamma1(1,k)*belta(2,k+1);%后一项为0
  74. belta(3,k)=gamma0(3,k)*belta(1,k+1)+gamma1(3,k)*belta(2,k+1);%后一项为0
  75. belta(2,k)=gamma0(2,k)*belta(3,k+1)+gamma1(2,k)*belta(4,k+1);%后一项为0
  76. belta(4,k)=gamma0(4,k)*belta(3,k+1)+gamma1(4,k)*belta(4,k+1);%后一项为0
  77. % for belta,from k=1------------------------
  78. k=1;
  79. belta(1,k)=gamma0(1,k)*belta(1,k+1)+gamma1(1,k)*belta(2,k+1);
  80. belta(3,k)=gamma0(3,k)*belta(1,k+1)+gamma1(3,k)*belta(2,k+1);
  81. belta(2,k)=gamma0(2,k)*belta(3,k+1)+gamma1(2,k)*belta(4,k+1);
  82. belta(4,k)=gamma0(4,k)*belta(3,k+1)+gamma1(4,k)*belta(4,k+1);
  83. %calculate LLR-----------------------------------
  84. k=1;
  85. numerator=0;
  86. denominator=0;
  87. numerator=numerator+alpha(1,k)*gamma1(1,k)*belta(2,k+1);
  88. denominator=denominator+alpha(1,k)*gamma0(1,k)*belta(1,k+1);
  89. llr(k)=log10(numerator/denominator);
  90. %calculate LLR-----------------------------------
  91. k=2;
  92. numerator=0;
  93. denominator=0;
  94. numerator=numerator+alpha(1,k)*gamma1(1,k)*belta(2,k+1);
  95. numerator=numerator+alpha(2,k)*gamma1(2,k)*belta(4,k+1);
  96. denominator=denominator+alpha(1,k)*gamma0(1,k)*belta(1,k+1);
  97. denominator=denominator+alpha(2,k)*gamma0(2,k)*belta(3,k+1);
  98. llr(k)=log10(numerator/denominator);
  99. %calculate LLR-----------------------------------
  100. k=3;
  101. numerator=0;
  102. denominator=0;
  103. numerator=numerator+alpha(1,k)*gamma1(1,k)*belta(2,k+1);
  104. numerator=numerator+alpha(2,k)*gamma1(2,k)*belta(4,k+1);
  105. numerator=numerator+alpha(3,k)*gamma1(3,k)*belta(2,k+1);
  106. numerator=numerator+alpha(4,k)*gamma1(4,k)*belta(4,k+1);
  107. denominator=denominator+alpha(1,k)*gamma0(1,k)*belta(1,k+1);
  108. denominator=denominator+alpha(2,k)*gamma0(2,k)*belta(3,k+1);
  109. denominator=denominator+alpha(3,k)*gamma0(3,k)*belta(1,k+1);
  110. denominator=denominator+alpha(4,k)*gamma0(4,k)*belta(3,k+1);
  111. llr(k)=log10(numerator/denominator);
  112. llr