Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- parity_check_matrix: the code parity check matrix.
- code_word_aprior_prob: the code probality given the measurments. p(b=0/y)
- for every code bit.
- detcted_code_word: the detected code word.
- function [detcted_code_word] = lpdc_soft_decision_detect...
- (parity_check_matrix, code_word_aprior_prob)
- %Detect ldpc code word using belief propogation.
- %
- %
- %Attributes:
- % UN_DECIDED_ELEMENT: a symbol for a bit that an equation doesn't conatin.
- % MAX_ITER_NUM: the maximum number of iterations.
- % NOT_CONNECTED_BIT: set to zero to indicate that a bit that is not
- % connected to an equation in the ldpc graph representaion.
- % BIT_IS_CERTAINLY_ONE: set to -inf, to indicate the llr is infinty,
- % thus the bit is 1. In the code we use for the case of a possible
- % substraction of inf - inf.
- % BIT_IS_CERTAINLY_ZERO: set to inf, to indicate the llr is infinty,
- % thus the bit is 0. In the code we use for the case of a possible
- % substraction of inf - inf.
- MAX_ITER_NUM = 1000;
- UN_DECIDED_ELEMENT = 1i;
- BIT_IS_CERTAINLY_ONE = -inf;
- BIT_IS_CERTAINLY_ZERO = inf;
- [II, JJ] = find(parity_check_matrix);
- [ROW_NUM, COL_NUM] = size(parity_check_matrix);
- [NUMBER_OF_EQ, ~] = size(parity_check_matrix);
- detcted_code_word = 0;
- iteration_num = 0;
- detection_fail = true;
- code_word_llr = get_llr(code_word_aprior_prob);
- messages_matrix = initialize_llr(code_word_llr);
- check_matrix = sparse(ROW_NUM, COL_NUM);
- %%
- %Iterating
- while and(detection_fail, (iteration_num < MAX_ITER_NUM))
- iteration_num = iteration_num + 1;
- check_matrix = get_llr_from_message_matrix(messages_matrix,...
- check_matrix);
- messages_matrix = get_llr_from_check_matrix(check_matrix,...
- code_word_aprior_prob,...
- messages_matrix);
- detcted_code_word = get_current_detection(check_matrix,...
- code_word_llr);
- if mod(parity_check_matrix * (detcted_code_word'), 2) == ...
- zeros(1, NUMBER_OF_EQ)'
- detection_fail = false;
- end
- end
- %%
- function llr = get_llr(prob)
- % Get llr out of the propality for a bit to be zero.
- %
- % Args:
- % prob: the probality of a bit to be zero.
- %
- % Retruns:
- % llr. log likelihood ratio. log(p(b=0)/p(b=0)).
- llr = log(prob./(1-prob));
- end
- function [messages_llr_matrix] = initialize_llr(code_word_aprior_prob)
- %initialize the messages_llr_matrix with aprirori probalities.
- %
- % It assigns each element in the matrix the aprirori probality.
- % For example: messages_llr_matrix[i][j] will be set to
- % code_word_aprior_prob[i] if the i'th bit apeares in the j'th equation
- % in the parity check matrix.
- % Args:
- % code_word_aprior_prob: the code probality given the measurments.
- % p(b/y) for every code bit. a vector.
- % parity_check_matrix: parity check matrix. should be in the form that
- % the rows are the equations.
- %
- % Retruns:
- % messages_llr_matrix: the matrix containing the llr for each
- % bit that will be sent to every check node.
- if ROW_NUM > COL_NUM
- error('The parity check matrix should be transpozed.')
- end
- messages_llr_matrix = ...
- sparse(II,JJ,code_word_aprior_prob(JJ),ROW_NUM,COL_NUM);
- end
- function check_matrix = get_llr_from_message_matrix(messages_matrix, ...
- check_matrix)
- % Calc the llr each check node belives each bit is.
- %
- % check_matrix[i][j] - is the llr that the i'th equation from the
- % parity check, believes the j'th bit is.
- % check_matrix[i][j] is calculated by taking the i'th row from the
- % messages_matrix elements besides the j'th and that do not contain
- % 'UN_DECIDED_ELEMENT' and using this vector to calclate the llr.
- % This is done by calculating each equation tanh message multipication
- % element and than divding it for every relevant bit.
- %
- % Args:
- % messages_matrix: the code bit's calculated llr's.
- % code_word_aprior_prob.
- % check_llr_matrix.
- %
- % Retruns:
- % check_matrix.
- all_tanh_bits = ones(1, NUMBER_OF_EQ);
- %Calculating each equation multipicative factor.
- for index = 1 : length(II)
- all_tanh_bits(II(index)) = (all_tanh_bits(II(index)) * ...
- tanh(messages_matrix(II(index), JJ(index))/2));
- end
- for index = 1 : length(II)
- %not_relevant_mul is the elemnt to divide - so the
- %current node only uses other message nodes for
- %calculating the llr.
- not_relevant_mul = tanh(messages_matrix(II(index), ...
- JJ(index)) / 2);
- check_matrix_mul = all_tanh_bits(II(index)) / not_relevant_mul;
- check_matrix(II(index), JJ(index)) = ...
- log((1 + check_matrix_mul) / (1 - check_matrix_mul));
- end
- end
- function messages_matrix = get_llr_from_check_matrix(check_matrix,...
- code_word_aprior_prob,...
- messages_matrix)
- % Calc the llr each bit is - to be sent to the check nodes.
- %
- % messages_matrix[i][j] - is the llr that the j'th bit from the
- % parity check, sends to the i'th equation.
- % check_matrix[i][j] is calculated by taking the j'th column from the
- % messages_matrix elements besides the i'th element that do not contain
- % 'UN_DECIDED_ELEMENT'. this is what the j'th bit will send to the i'th
- % equation.
- % This is done by calculating each bit llr corresponding equation
- % and substracting for every equation.
- %
- % Args:
- % check_matrix: the code bit's calculated llr's,
- % code_word_aprior_prob.
- % messages_matrix. the message matrix from the previous iteration.
- %
- %Retruns:
- % messages_matrix.
- llr_sum = get_llr(code_word_aprior_prob);
- %Calculating each bit additive factor.
- for index = 1 : length(II)
- llr_sum(JJ(index)) = llr_sum(JJ(index)) + ...
- check_matrix(II(index), JJ(index));
- end
- for index = 1 : length(II)
- certain_llr = or(llr_sum(JJ(index)) == BIT_IS_CERTAINLY_ONE,...
- llr_sum(JJ(index)) == BIT_IS_CERTAINLY_ZERO);
- if not(certain_llr)
- %the problem is substracting -inf from -inf!
- add_to_remove = check_matrix(II(index), JJ(index));
- messages_matrix(II(index), JJ(index)) = ...
- llr_sum(JJ(index)) - add_to_remove;
- else
- messages_matrix(II(index), JJ(index)) = ...
- llr_sum(JJ(index));
- end
- end
- end
- function estimated_code_word = get_current_detection(messages_matrix,....
- code_word_llr)
- % Get the current estimation of the code word.
- %
- % Estimate the code word based on the llr that each check node believes
- % each bit connected to it is.
- % if the llr > 0 that the estimation is '0'.
- %
- % Args:
- % messages_matrix.
- % code_word_llr: the apriroi code word llr.
- %
- % Retruns:
- % estimated_code_word.
- new_code_word_llr = sum(real(messages_matrix)) + code_word_llr;
- estimated_code_word = sign(new_code_word_llr);
- estimated_code_word(estimated_code_word == -1) = 0;
- estimated_code_word = not(estimated_code_word);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement