+ еще надо переделать на мягкие решения.
Код: Выделить всё
void bitflip()
{
// BIT-FLIP decoding
int i,j,l,iter;
int delt,m,aux;
int all_zero; // Flag for syndrome testing
int count;
// -------------------
// INITIALIZATION STEP
// -------------------
// Prior values (used to be probabilities in soft-decision)
for (i=0;i<N;i++)
{
decoded[i] = hard[i];
}
iter = 0; // Counter of iterations
do {
// ---------------------------------------
// HORIZONTAL STEP = BOTTOM-UP PROPAGATION
// ---------------------------------------
//
// Run through the checks m and compute, for each n in N(m) the
// probabilitiy of a check symbol when code symbol is 0 (or 1)
// given that the other code symbols have values 0, 1
//
// Pearl:
// Node x_m computes new "lambda" messages to be sent to its parents
// u_1, u_2, ..., u_K
// Flag to determine if syndrome is all zero
all_zero = 1;
for (i=0; i<M; i++)
{
delt = 0;
for (j=0; j<check_node[i].size; j++)
{
aux = check_node[i].index[j];
delt ^= decoded[aux-1];
}
check_node[i].syndrome = delt;
// Check if anyone of the syndromes is not zero
if (delt) all_zero = 0;
}
// CONTINUE IF A CODEWORD HAS NOT BEEN FOUND
if (!all_zero) {
// ------------------------------------
// VERTICAL STEP = TOP-DOWN PROPAGATION
// ------------------------------------
//
// MacKay:
// Take the computed values of rm0, rm1 and update the values of
// the probabilities qm0, qm1
//
// Pearl:
// Each node u_l computes new "pi" messages to be send to its
// children x_1, x_2, ..., x_J
for (i=0; i<N; i++)
{
count = 0;
for (j=0; j<code_node[i].size; j++)
{
aux = code_node[i].index[j]-1;
// Compute index "m" of message from children
m = 0;
while ( ( (check_node[aux].index[m]-1) != i )
&& ( m < check_node[aux].size ) ) m++;
if (check_node[aux].syndrome)
count++;
}
// If more that 1/2 checks are unsatisfied, FLIP the BIT
if (count > threshold)
// if (count > (code_node[i].size-1)/2 )
{
decoded[i] ^= 1;
}
}
}
// Increment the number of iterations, and check if maximum reached
iter++;
} while (iter < max_iter);
}