Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.90 KB | None | 0 0
  1. parity_check_matrix: the code parity check matrix.
  2. code_word_aprior_prob: the code probality given the measurments. p(b=0/y)
  3. for every code bit.
  4.  
  5. detcted_code_word: the detected code word.
  6.  
  7. function [detcted_code_word] = lpdc_soft_decision_detect...
  8. (parity_check_matrix, code_word_aprior_prob)
  9. %Detect ldpc code word using belief propogation.
  10.  
  11. %
  12. %
  13. %Attributes:
  14. % UN_DECIDED_ELEMENT: a symbol for a bit that an equation doesn't conatin.
  15. % MAX_ITER_NUM: the maximum number of iterations.
  16. % NOT_CONNECTED_BIT: set to zero to indicate that a bit that is not
  17. % connected to an equation in the ldpc graph representaion.
  18. % BIT_IS_CERTAINLY_ONE: set to -inf, to indicate the llr is infinty,
  19. % thus the bit is 1. In the code we use for the case of a possible
  20. % substraction of inf - inf.
  21. % BIT_IS_CERTAINLY_ZERO: set to inf, to indicate the llr is infinty,
  22. % thus the bit is 0. In the code we use for the case of a possible
  23. % substraction of inf - inf.
  24. MAX_ITER_NUM = 1000;
  25. UN_DECIDED_ELEMENT = 1i;
  26. BIT_IS_CERTAINLY_ONE = -inf;
  27. BIT_IS_CERTAINLY_ZERO = inf;
  28. [II, JJ] = find(parity_check_matrix);
  29. [ROW_NUM, COL_NUM] = size(parity_check_matrix);
  30. [NUMBER_OF_EQ, ~] = size(parity_check_matrix);
  31.  
  32. detcted_code_word = 0;
  33. iteration_num = 0;
  34. detection_fail = true;
  35.  
  36. code_word_llr = get_llr(code_word_aprior_prob);
  37. messages_matrix = initialize_llr(code_word_llr);
  38. check_matrix = sparse(ROW_NUM, COL_NUM);
  39. %%
  40. %Iterating
  41. while and(detection_fail, (iteration_num < MAX_ITER_NUM))
  42. iteration_num = iteration_num + 1;
  43. check_matrix = get_llr_from_message_matrix(messages_matrix,...
  44. check_matrix);
  45.  
  46. messages_matrix = get_llr_from_check_matrix(check_matrix,...
  47. code_word_aprior_prob,...
  48. messages_matrix);
  49.  
  50. detcted_code_word = get_current_detection(check_matrix,...
  51. code_word_llr);
  52.  
  53. if mod(parity_check_matrix * (detcted_code_word'), 2) == ...
  54. zeros(1, NUMBER_OF_EQ)'
  55. detection_fail = false;
  56. end
  57.  
  58. end
  59.  
  60. %%
  61. function llr = get_llr(prob)
  62. % Get llr out of the propality for a bit to be zero.
  63. %
  64. % Args:
  65. % prob: the probality of a bit to be zero.
  66. %
  67. % Retruns:
  68. % llr. log likelihood ratio. log(p(b=0)/p(b=0)).
  69. llr = log(prob./(1-prob));
  70. end
  71.  
  72. function [messages_llr_matrix] = initialize_llr(code_word_aprior_prob)
  73. %initialize the messages_llr_matrix with aprirori probalities.
  74. %
  75. % It assigns each element in the matrix the aprirori probality.
  76. % For example: messages_llr_matrix[i][j] will be set to
  77. % code_word_aprior_prob[i] if the i'th bit apeares in the j'th equation
  78. % in the parity check matrix.
  79. % Args:
  80. % code_word_aprior_prob: the code probality given the measurments.
  81. % p(b/y) for every code bit. a vector.
  82. % parity_check_matrix: parity check matrix. should be in the form that
  83. % the rows are the equations.
  84. %
  85. % Retruns:
  86. % messages_llr_matrix: the matrix containing the llr for each
  87. % bit that will be sent to every check node.
  88. if ROW_NUM > COL_NUM
  89. error('The parity check matrix should be transpozed.')
  90. end
  91.  
  92. messages_llr_matrix = ...
  93. sparse(II,JJ,code_word_aprior_prob(JJ),ROW_NUM,COL_NUM);
  94. end
  95.  
  96. function check_matrix = get_llr_from_message_matrix(messages_matrix, ...
  97. check_matrix)
  98. % Calc the llr each check node belives each bit is.
  99. %
  100. % check_matrix[i][j] - is the llr that the i'th equation from the
  101. % parity check, believes the j'th bit is.
  102. % check_matrix[i][j] is calculated by taking the i'th row from the
  103. % messages_matrix elements besides the j'th and that do not contain
  104. % 'UN_DECIDED_ELEMENT' and using this vector to calclate the llr.
  105. % This is done by calculating each equation tanh message multipication
  106. % element and than divding it for every relevant bit.
  107. %
  108. % Args:
  109. % messages_matrix: the code bit's calculated llr's.
  110. % code_word_aprior_prob.
  111. % check_llr_matrix.
  112. %
  113. % Retruns:
  114. % check_matrix.
  115. all_tanh_bits = ones(1, NUMBER_OF_EQ);
  116. %Calculating each equation multipicative factor.
  117. for index = 1 : length(II)
  118. all_tanh_bits(II(index)) = (all_tanh_bits(II(index)) * ...
  119. tanh(messages_matrix(II(index), JJ(index))/2));
  120. end
  121.  
  122. for index = 1 : length(II)
  123. %not_relevant_mul is the elemnt to divide - so the
  124. %current node only uses other message nodes for
  125. %calculating the llr.
  126. not_relevant_mul = tanh(messages_matrix(II(index), ...
  127. JJ(index)) / 2);
  128.  
  129. check_matrix_mul = all_tanh_bits(II(index)) / not_relevant_mul;
  130. check_matrix(II(index), JJ(index)) = ...
  131. log((1 + check_matrix_mul) / (1 - check_matrix_mul));
  132. end
  133.  
  134. end
  135.  
  136. function messages_matrix = get_llr_from_check_matrix(check_matrix,...
  137. code_word_aprior_prob,...
  138. messages_matrix)
  139. % Calc the llr each bit is - to be sent to the check nodes.
  140. %
  141. % messages_matrix[i][j] - is the llr that the j'th bit from the
  142. % parity check, sends to the i'th equation.
  143. % check_matrix[i][j] is calculated by taking the j'th column from the
  144. % messages_matrix elements besides the i'th element that do not contain
  145. % 'UN_DECIDED_ELEMENT'. this is what the j'th bit will send to the i'th
  146. % equation.
  147. % This is done by calculating each bit llr corresponding equation
  148. % and substracting for every equation.
  149. %
  150. % Args:
  151. % check_matrix: the code bit's calculated llr's,
  152. % code_word_aprior_prob.
  153. % messages_matrix. the message matrix from the previous iteration.
  154. %
  155. %Retruns:
  156. % messages_matrix.
  157. llr_sum = get_llr(code_word_aprior_prob);
  158. %Calculating each bit additive factor.
  159. for index = 1 : length(II)
  160. llr_sum(JJ(index)) = llr_sum(JJ(index)) + ...
  161. check_matrix(II(index), JJ(index));
  162. end
  163.  
  164. for index = 1 : length(II)
  165. certain_llr = or(llr_sum(JJ(index)) == BIT_IS_CERTAINLY_ONE,...
  166. llr_sum(JJ(index)) == BIT_IS_CERTAINLY_ZERO);
  167.  
  168. if not(certain_llr)
  169. %the problem is substracting -inf from -inf!
  170. add_to_remove = check_matrix(II(index), JJ(index));
  171. messages_matrix(II(index), JJ(index)) = ...
  172. llr_sum(JJ(index)) - add_to_remove;
  173.  
  174. else
  175. messages_matrix(II(index), JJ(index)) = ...
  176. llr_sum(JJ(index));
  177. end
  178.  
  179. end
  180.  
  181. end
  182.  
  183. function estimated_code_word = get_current_detection(messages_matrix,....
  184. code_word_llr)
  185. % Get the current estimation of the code word.
  186. %
  187. % Estimate the code word based on the llr that each check node believes
  188. % each bit connected to it is.
  189. % if the llr > 0 that the estimation is '0'.
  190. %
  191. % Args:
  192. % messages_matrix.
  193. % code_word_llr: the apriroi code word llr.
  194. %
  195. % Retruns:
  196. % estimated_code_word.
  197.  
  198. new_code_word_llr = sum(real(messages_matrix)) + code_word_llr;
  199. estimated_code_word = sign(new_code_word_llr);
  200. estimated_code_word(estimated_code_word == -1) = 0;
  201. estimated_code_word = not(estimated_code_word);
  202. end
  203.  
  204. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement