\r
Build:\r
\r
- $ gcc -o ldpc_dec ldpc_dec.c mpdecode_core.c -Wall -lm -g\r
+ $ gcc -O2 -o ldpc_dec ldpc_dec.c mpdecode_core.c -Wall -lm -g\r
+\r
+ Note: -O2 option was required to get identical results to MpDecode,\r
+ which is also compiled with -O2. Without it the number of bit errors\r
+ between C and Octave was different, especially when the code did\r
+ not converge and hit max_iters.\r
\r
TODO:\r
[ ] C cmd line encoder\r
fprintf(stderr, "Codeword length: %d\n", CodeLength);\r
fprintf(stderr, "Parity Bits....: %d\n", NumberParityBits);\r
\r
- num_runs = 100; num_ok = 0;\r
+ num_runs = 1; num_ok = 0;\r
\r
for(r=0; r<num_runs; r++) {\r
\r
run_ldpc_decoder(DecodedBits, ParityCheckCount, input);\r
\r
- /* Check output. Bill has modified decoded to write number of parity checks that are correct\r
- to the BitErrors array. So if decoding is correct the final BitErrors entry will have \r
- NumberParityBits */\r
-\r
- /* find output bit row where decoding has finished */\r
+ /* Check output by comparing every output iteration */\r
\r
int ok = 0;\r
- for (i=0;i<max_iter;i++) {\r
- if (ParityCheckCount[i] == NumberParityBits) {\r
- for (j=0;j<CodeLength;j++) {\r
- if (output[i + j*max_iter] == DecodedBits[i+j*max_iter]) \r
+ for (i=0;i<max_iter*CodeLength;i++) {\r
+ if (output[i] == DecodedBits[i]) \r
ok++;\r
- }\r
- }\r
}\r
- if (ok == CodeLength)\r
+ if (ok == max_iter*CodeLength)\r
num_ok++; \r
}\r
\r
double *input_double = calloc(CodeLength, sizeof(double));\r
\r
while(fread(input_double, sizeof(double), CodeLength, fin) == CodeLength) {\r
+ \r
run_ldpc_decoder(DecodedBits, ParityCheckCount, input_double);\r
+ \r
+ /* extract output bits from ouput iteration that solved all parity equations, or failing that\r
+ the last iteration. */\r
\r
- /* default is all zeros - just in case we don't get a decode */\r
-\r
- memset(out_char, sizeof(out_char), 0);\r
-\r
- /* extract output bits from ouput iteration that solved all paritry equations */\r
-\r
+ int converged = 0;\r
+ int iter = 0;\r
for (i=0;i<max_iter;i++) {\r
- if (ParityCheckCount[i] == NumberParityBits) {\r
+ if (converged == 0)\r
+ iter++;\r
+ if ((ParityCheckCount[i] == NumberParityBits)) {\r
for (j=0; j<CodeLength; j++) {\r
- out_char[j] = DecodedBits[i+j*max_iter]; \r
+ out_char[j] = DecodedBits[i+j*max_iter];\r
}\r
+ converged = 1;\r
+ } \r
+ }\r
+ if (converged == 0) {\r
+ for (j=0; j<CodeLength; j++) {\r
+ out_char[j] = DecodedBits[max_iter-1+j*max_iter];\r
}\r
}\r
-\r
+ //printf("%4d ", iter);\r
fwrite(out_char, sizeof(char), CodeLength, fout);\r
}\r
\r
max_row_weight = MAX_ROW_WEIGHT;\r
max_col_weight = MAX_COL_WEIGHT;\r
\r
-#ifdef TT\r
- /* check H_rows[] */\r
-\r
- int length;\r
- int gd = 0, bd = 0;\r
- length = NumberRowsHcols*max_col_weight;\r
- for (i=0;i<length;i++) {\r
- if (H_cols[i] == H_cols2[i])\r
- gd++;\r
- else {\r
- bd++;\r
- printf("%d H_cols: %f H_cols2: %f\n", i, H_cols[i], H_cols2[i]);\r
- }\r
- if (bd == 10)\r
- exit(0);\r
- }\r
- printf("gd: %d bd: %d\n", gd, bd);\r
-#endif\r
-\r
c_nodes = calloc( NumberParityBits, sizeof( struct c_node ) );\r
v_nodes = calloc( CodeLength, sizeof( struct v_node));\r
\r
int DataLength = CodeLength - NumberParityBits;\r
int *data_int = calloc( DataLength, sizeof(int) );\r
\r
+ /* need to clear these on each call */\r
+\r
+ for(i=0; i<max_iter; i++)\r
+ ParityCheckCount[i] = 0;\r
+ for(i=0; i<max_iter*CodeLength; i++)\r
+ DecodedBits[i] = 0;\r
+\r
/* Call function to do the actual decoding */\r
\r
if ( dec_type == 1) {\r