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

传真(Fax)编程

开发平台:

Matlab

  1. %****************************************************************
  2. % 内容概述:FPGA验证调试
  3. % 创 建 人:朱殿荣/QQ:235347/MSN:njzdr@msn.com
  4. % 单    位:南京邮电大学,通信工程系
  5. % 创建时间:2006年1月10日
  6. % 修改时间:
  7. % 参考文献:《数字通信--基础与应用》
  8. %          《改进的Turbo码算法及其FPGA实现过程的研究》,天津大学,张宁,赵雅兴
  9. % 版权声明:任何人均可复制、传播、修改此文件,同时需保留原始版权信息。
  10. %****************************************************************
  11.  
  12. x=in(1,:);              %输入系统位
  13. y=in(2,:);              %输入校验位
  14. in_length=length(in);
  15. %---初始化&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  16. Infty = -128;
  17. d=zeros(8,2,in_length);     %分支量度,8种可能状态,输入为0或者1
  18.                             %D(S,i,k)
  19. a=Infty*ones(8,in_length);  %前向分支量度,A(S,k)
  20. a(1,1)=0;                   %寄存器状态由全零开始
  21. b=Infty*ones(8,in_length+1);%后向分支量度,B(S,k)
  22. b(1,in_length)=0;           %寄存器状态由全零结束
  23. %---计算分支度量和LLR&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  24. for k=1:in_length
  25.     d(1,2,k)=x(k)+y(k)+app(k);
  26.     d(2,2,k)=d(1,2,k);
  27.     d(7,2,k)=d(1,2,k);
  28.     d(8,2,k)=d(1,2,k);
  29.     d(3,2,k)=x(k)+app(k);
  30.     d(4,2,k)=d(3,2,k);
  31.     d(5,2,k)=d(3,2,k);
  32.     d(6,2,k)=d(3,2,k);
  33.     d(3,1,k)=y(k);
  34.     d(4,1,k)=d(3,1,k);
  35.     d(5,1,k)=d(3,1,k);
  36.     d(6,1,k)=d(3,1,k);
  37.     
  38.     if k>1
  39.         a(1,k)=max(a(1,k-1),(a(2,k-1)+d(2,2,k-1)));
  40.         a(2,k)=max((a(4,k-1)+d(4,1,k-1)),(a(3,k-1)+d(3,2,k-1)));
  41.         a(3,k)=max((a(5,k-1)+d(5,1,k-1)),(a(6,k-1)+d(6,2,k-1)));
  42.         a(4,k)=max(a(8,k-1),(a(7,k-1)+d(7,2,k-1)));
  43.         a(5,k)=max(a(2,k-1),(a(1,k-1)+d(1,2,k-1)));
  44.         a(6,k)=max((a(3,k-1)+d(3,1,k-1)),(a(4,k-1)+d(4,2,k-1)));
  45.         a(7,k)=max((a(6,k-1)+d(6,1,k-1)),(a(5,k-1)+d(5,2,k-1)));
  46.         a(8,k)=max(a(7,k-1),(a(8,k-1)+d(8,2,k-1)));      
  47.     end
  48.     
  49.     if k==in_length
  50.         b(1,k)=max(b(1,k+1),(b(5,k+1)+d(1,2,k)));
  51.         b(2,k)=max(b(5,k+1),(b(1,k+1)+d(2,2,k)));
  52.         b(3,k)=max((b(6,k+1)+d(3,1,k)),(b(2,k+1)+d(3,2,k)));
  53.         b(4,k)=max((b(2,k+1)+d(4,1,k)),(b(6,k+1)+d(4,2,k)));
  54.         b(5,k)=max((b(3,k+1)+d(5,1,k)),(b(7,k+1)+d(5,2,k)));
  55.         b(6,k)=max((b(7,k+1)+d(6,1,k)),(b(3,k+1)+d(6,2,k)));
  56.         b(7,k)=max(b(8,k+1),(b(4,k+1)+d(7,2,k)));
  57.         b(8,k)=max(b(4,k+1),(b(8,k+1)+d(8,2,k)));
  58.         %计算LLR--------------------------------------
  59.         l(k)=max([...
  60.             (a(1,k)+d(1,2,k)+b(5,k+1)),(a(2,k)+d(2,2,k)+b(1,k+1)),...
  61.             (a(3,k)+d(3,2,k)+b(2,k+1)),(a(4,k)+d(4,2,k)+b(6,k+1)),...
  62.             (a(5,k)+d(5,2,k)+b(7,k+1)),(a(6,k)+d(6,2,k)+b(3,k+1)),...
  63.             (a(7,k)+d(7,2,k)+b(4,k+1)),(a(8,k)+d(8,2,k)+b(8,k+1))...
  64.             ])-max([...
  65.             (a(1,k)+b(1,k+1)),(a(2,k)+b(5,k+1)),...
  66.             (a(3,k)+d(3,1,k)+b(6,k+1)),(a(4,k)+d(4,1,k)+b(2,k+1)),...
  67.             (a(5,k)+d(5,1,k)+b(3,k+1)),(a(6,k)+d(6,1,k)+b(7,k+1)),...
  68.             (a(7,k)+b(8,k+1)),(a(8,k)+b(4,k+1))...
  69.             ]);
  70.     end
  71. end
  72. for k=in_length-1:-1:1
  73.         b(1,k)=max(b(1,k+1),(b(5,k+1)+d(1,2,k)));
  74.         b(2,k)=max(b(5,k+1),(b(1,k+1)+d(2,2,k)));
  75.         b(3,k)=max((b(6,k+1)+d(3,1,k)),(b(2,k+1)+d(3,2,k)));
  76.         b(4,k)=max((b(2,k+1)+d(4,1,k)),(b(6,k+1)+d(4,2,k)));
  77.         b(5,k)=max((b(3,k+1)+d(5,1,k)),(b(7,k+1)+d(5,2,k)));
  78.         b(6,k)=max((b(7,k+1)+d(6,1,k)),(b(3,k+1)+d(6,2,k)));
  79.         b(7,k)=max(b(8,k+1),(b(4,k+1)+d(7,2,k)));
  80.         b(8,k)=max(b(4,k+1),(b(8,k+1)+d(8,2,k)));
  81.         %计算LLR--------------------------------------
  82.         l(k)=max([...
  83.             (a(1,k)+d(1,2,k)+b(5,k+1)),(a(2,k)+d(2,2,k)+b(1,k+1)),...
  84.             (a(3,k)+d(3,2,k)+b(2,k+1)),(a(4,k)+d(4,2,k)+b(6,k+1)),...
  85.             (a(5,k)+d(5,2,k)+b(7,k+1)),(a(6,k)+d(6,2,k)+b(3,k+1)),...
  86.             (a(7,k)+d(7,2,k)+b(4,k+1)),(a(8,k)+d(8,2,k)+b(8,k+1))...
  87.             ])-max([...
  88.             (a(1,k)+b(1,k+1)),(a(2,k)+b(5,k+1)),...
  89.             (a(3,k)+d(3,1,k)+b(6,k+1)),(a(4,k)+d(4,1,k)+b(2,k+1)),...
  90.             (a(5,k)+d(5,1,k)+b(3,k+1)),(a(6,k)+d(6,1,k)+b(7,k+1)),...
  91.             (a(7,k)+b(8,k+1)),(a(8,k)+b(4,k+1))...
  92.             ]);
  93. end
  94. soft_out=l;
  95. ex_info=soft_out-app-x;