\r
if (argc < 2) {\r
fprintf(stderr, "usage: %s --test\n", argv[0]);\r
- fprintf(stderr, "usage: %s InOneSDSymbolPerDouble OutOneBitPerByte\n", argv[0]);\r
+ fprintf(stderr, " Run internal self test and print code parameters.\n\n");\r
+ fprintf(stderr, "usage: %s InOneSymbolPerDouble OutOneBitPerByte [--sdinput]\n", argv[0]);\r
+ fprintf(stderr, " InOneSymbolPerDouble is a file of double LLRs. If the\n");\r
+ fprintf(stderr, " --sd flag is used the input file can be Soft Decision\n");\r
+ fprintf(stderr, " symbols, and LLRs will be calculated internally. Use -\n");\r
+ fprintf(stderr, " for the file names to use stdin/stdout.\n");\r
exit(0);\r
}\r
\r
fprintf(stderr, "Codeword length: %d\n", CodeLength);\r
fprintf(stderr, "Parity Bits....: %d\n", NumberParityBits);\r
\r
- num_runs = 1; num_ok = 0;\r
+ num_runs = 100; num_ok = 0;\r
\r
for(r=0; r<num_runs; r++) {\r
\r
}\r
else {\r
FILE *fin, *fout;\r
+ int sdinput;\r
\r
/* File I/O mode ------------------------------------------------*/\r
\r
exit(1);\r
}\r
\r
- double *input_double = calloc(CodeLength, sizeof(double));\r
+ sdinput = 0;\r
+ printf("argc: %d\n", argc);\r
+ if (argc == 4)\r
+ if (strcmp(argv[3], "--sdinput") == 0)\r
+ sdinput = 1;\r
+\r
+ double *input_double = calloc(CodeLength, sizeof(double));\r
+ double sum, mean, sign, sumsq, estvar, estEsN0, x;\r
\r
while(fread(input_double, sizeof(double), CodeLength, fin) == CodeLength) {\r
- \r
+ if (sdinput) {\r
+ /* convert SD samples to LLRs -------------------------------*/\r
+\r
+ sum = 0.0;\r
+ for(i=0; i<CodeLength; i++)\r
+ sum += fabs(input_double[i]);\r
+ mean = sum/CodeLength;\r
+ \r
+ /* scale by mean to map onto +/- 1 symbol position */\r
+\r
+ for(i=0; i<CodeLength; i++) {\r
+ input_double[i] /= mean;\r
+ }\r
+\r
+ /* find variance from +/-1 symbol position */\r
+\r
+ sum = sumsq = 0.0; \r
+ for(i=0; i<CodeLength; i++) {\r
+ sign = (input_double[i] > 0.0) - (input_double[i] < 0.0);\r
+ x = (input_double[i] - sign);\r
+ sum += x;\r
+ sumsq += x*x;\r
+ }\r
+ mean = sum/CodeLength;\r
+ estvar = sumsq/CodeLength - mean*mean;\r
+\r
+ estEsN0 = 1.0/(2.0 * estvar + 1E-3); \r
+ for(i=0; i<CodeLength; i++)\r
+ input_double[i] = 4.0 * estEsN0 * input_double[i]; \r
+ }\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