llr calculations in C, modified Octave to use bit exact procedure
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 14 Sep 2016 09:57:13 +0000 (09:57 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 14 Sep 2016 09:57:13 +0000 (09:57 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2862 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/ldpc_dec.c
codec2-dev/src/ldpc_enc.c

index 70af95a9f29438974c6d12572dd23d196386bbfd..ec1c528655218458ba11d1d22bfb8fca1f195a41 100644 (file)
@@ -66,7 +66,12 @@ int main(int argc, char *argv[])
        \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
@@ -81,7 +86,7 @@ int main(int argc, char *argv[])
         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
@@ -107,6 +112,7 @@ int main(int argc, char *argv[])
     }\r
     else {\r
         FILE *fin, *fout;\r
+        int   sdinput;\r
 \r
         /* File I/O mode ------------------------------------------------*/\r
 \r
@@ -124,10 +130,47 @@ int main(int argc, char *argv[])
             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
index f648860336782b10a0b907c60308aab16e52f0ed..bb8d7156ee9d299813f5416c5f303b7195b830d7 100644 (file)
@@ -5,6 +5,8 @@
 
   RA LDPC encoder program. Using the elegant back substitution of RA
   LDPC codes.
+
+  building: gcc ldpc_enc.c -o ldpc_enc -Wall -g
 */
 
 #include <stdio.h>