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

传真(Fax)编程

开发平台:

Matlab

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