first pass working with Codec 2 700C! However only works on 1 or 2 frame interleaver...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 19 Apr 2018 05:04:59 +0000 (05:04 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 19 Apr 2018 05:04:59 +0000 (05:04 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3503 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/README_ofdm.txt
codec2-dev/src/c2dec.c
codec2-dev/src/interldpc.c
codec2-dev/src/ofdm_demod.c
codec2-dev/src/ofdm_mod.c

index da02ee4473fdcd7d1508dd5b091e6a3a0f8c8711..7564f213fdda0c96c7b4b26133b73abcfce4d232 100644 (file)
@@ -35,18 +35,17 @@ Built as part of codec2-dev, see README for build instructions.
 1. Generate 10 seconds of test frame bits, modulate, and play audio
    out of sound device:
 
-    build_linux/src$ ./ofdm_get_test_bits - 10 | ./ofdm_mod - - | play -t raw -r 8000 -s -2 -
+     build_linux/src$ ./ofdm_get_test_bits - 10 | ./ofdm_mod - - | play -t raw -r 8000 -s -2 -
 
 2. Generate 10 seconds of uncoded test frame bits, modulate, demodulate, count errors:
 
-    build_linux/src$ ./ofdm_get_test_bits - 10 | ./ofdm_mod - - | ./ofdm_demod - /dev/null -t
+     build_linux/src$ ./ofdm_get_test_bits - 10 | ./ofdm_mod - - | ./ofdm_demod - /dev/null -t
 
-    (TODO write ofdm_demod_c.m)
-    Use Octave to look at plots of C modem operation:
+   Use Octave to look at plots of C modem operation:
 
-    $ cd ../octave
-    $ octave
-    octave:1> ofdm_demod_c("../src/demod_dump.txt")
+     $ cd ../octave
+     $ octave
+     octave:1> ofdm_demod_c("../src/demod_dump.txt")
 
 4. Run Octave versions of mod and demod (called tx and rx to avoid
    namespace clashes in Octave):
@@ -77,7 +76,16 @@ Built as part of codec2-dev, see README for build instructions.
    C demodulator/LDPC decoder:
    
      build_linux/src$ ./ofdm_demod ../../octave/ofdm_test.raw /dev/null -v -t --ldpc --interleave 4
-     
+
+6.  Run C mod/demod with LDPC and 2 frames interleaving:
+
+      build_linux/src$ ./ofdm_mod /dev/zero - --ldpc -t 2 --interleave 2 | ./ofdm_demod - /dev/null -t --ldpc -v --interleave 2
+
+7. Pass Codec 2 700C through modem:
+
+      build_linux/src$ ./c2enc 700C ../../raw/ve9qrp_10s.raw - --bitperchar | ./ofdm_mod - - --ldpc --interleave 2 | ./ofdm_demod - - --ldpc --interleave 2 | ./c2dec 700C - - --bitperchar | play -t raw -r 8000 -s -2 -
+
+
 Acceptance Tests
 ----------------
 
index cbcd2ee7fb768304caf215887f52d7a8adaefaf2..59e24d1d9e8e69f64d91259416ccec99bb112fa3 100644 (file)
@@ -100,29 +100,25 @@ int main(int argc, char *argv[])
        exit(1);
     }
 
-    mode = -1;
-    
     // Attempt to detect a .c2 file with a header
     struct c2_header in_hdr;
     char *ext = strrchr(argv[2], '.');
-    if (ext != NULL) {
-        if (strcmp(ext, ".c2") == 0) {
-            fread(&in_hdr,sizeof(in_hdr),1,fin);
+    if ((ext != NULL) && (strcmp(ext, ".c2") == 0)) {
+        fread(&in_hdr,sizeof(in_hdr),1,fin);
                 
-            if (memcmp(in_hdr.magic, c2_file_magic, sizeof(c2_file_magic)) == 0) {
-                fprintf(stderr, "Detected Codec2 file version %d.%d in mode %d\n",
-                        in_hdr.version_major,
-                        in_hdr.version_minor,
-                        in_hdr.mode);
+        if (memcmp(in_hdr.magic, c2_file_magic, sizeof(c2_file_magic)) == 0) {
+            fprintf(stderr, "Detected Codec2 file version %d.%d in mode %d\n",
+                    in_hdr.version_major,
+                    in_hdr.version_minor,
+                    in_hdr.mode);
                             
-                mode = in_hdr.mode;
-            } else {
-                fprintf(stderr, "Codec2 file specified but no header detected\n");
-                // Rewind the input file so we can try to decode
-                // based on command line mode selection
-                fseek(fin,0,SEEK_SET);
-            } /* end if - magic detection */
-        };
+            mode = in_hdr.mode;
+        } else {
+            fprintf(stderr, "Codec2 file specified but no header detected\n");
+            // Rewind the input file so we can try to decode
+            // based on command line mode selection
+            fseek(fin,0,SEEK_SET);
+        } /* end if - magic detection */
     } else {
         // If we got here, we need to honor the command line mode
         if (strcmp(argv[1],"3200") == 0)
index 9d4b2ec7d928668d47c04b101faf7d57c05a763a..a7ff46c7851f728df482b7ed1ed44ce15736e9da 100644 (file)
@@ -79,7 +79,7 @@ void set_up_hra_112_112(struct LDPC *ldpc) {
 }
 
 void ldpc_encode_frame(struct LDPC *ldpc, int codeword[], unsigned char tx_bits_char[]) {
-    unsigned char pbits[ldpc->coded_bits_per_frame];
+    unsigned char pbits[ldpc->NumberParityBits];
     int           i,j;
     
     encode(ldpc, tx_bits_char, pbits);
@@ -87,7 +87,7 @@ void ldpc_encode_frame(struct LDPC *ldpc, int codeword[], unsigned char tx_bits_
         codeword[i] = tx_bits_char[i];
     }
     for(j=0; i<ldpc->coded_bits_per_frame; i++,j++) {
-        codeword[i] = pbits[i];
+        codeword[i] = pbits[j];
     }
 }
 
index c1219be124f05112d4fd3135cb1b83646ede1168..8fc128749c1b694c79034bcc35291bfbd35a62aa 100644 (file)
@@ -250,8 +250,11 @@ int main(int argc, char *argv[])
                         symbols_to_llrs(llr, codeword_symbols_de, codeword_amps_de, EsNo, coded_syms_per_frame);               
                         iter = run_ldpc_decoder(&ldpc, out_char, llr, &parityCheckCount);
                         Nerrs = data_bits_per_frame - parityCheckCount;
-                        //fprintf(stderr, "iter: %d pcc: %d Nerrs: %d\n", iter, parityCheckCount, Nerrs);
-                        if (Nerrs < 10) {
+                        for(i=0; i<20; i++)
+                            fprintf(stderr,"%d ", out_char[i]);
+                        fprintf(stderr,"\n");
+                        fprintf(stderr, "iter: %d pcc: %d Nerrs: %d\n", iter, parityCheckCount, Nerrs);
+                        if ((Nerrs < 10)) {
                             /* sucessful decode! */
                             strcpy(next_sync_state_interleaver, "synced");
                             ofdm->frame_count_interleaver = interleave_frames;
@@ -296,7 +299,7 @@ int main(int argc, char *argv[])
                                                  &codeword_amps_de[j*coded_syms_per_frame],
                                                  EsNo, coded_syms_per_frame);               
                             iter = run_ldpc_decoder(&ldpc, out_char, llr, &parityCheckCount);
-
+                            fprintf(stderr,"j: %d iter: %d parityCheckCount: %d\n", j, iter, parityCheckCount);
                             if (testframes) {
                                 Nerrs = 0;
                                 for(i=0; i<data_bits_per_frame; i++) {
@@ -308,7 +311,7 @@ int main(int argc, char *argv[])
                                 Terrs_coded += Nerrs;
                                 Tbits_coded += data_bits_per_frame;
                             }
-                            fwrite(out_char, sizeof(char), coded_bits_per_frame, fout);
+                            fwrite(out_char, sizeof(char), data_bits_per_frame, fout);
                         }
                     } /* if interleaver synced ..... */
                          
index 86972ec096b55f8ef173e8b952fd223f74f5bc4e..853664e85b47ee88fd9e1f3fdd2f548b48cc3f11 100644 (file)
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
     struct OFDM   *ofdm;
     int           frames;
     int           i, j, arg;
-    int           testframes, ldpc_en, interleaver_frames;
+    int           testframes, ldpc_en, interleave_frames;
    
     /* Set up default LPDC code.  We could add other codes here if we like */
     
@@ -71,11 +71,11 @@ int main(int argc, char *argv[])
     if (argc < 3) {
         fprintf(stderr, "\n");
        fprintf(stderr, "usage: %s InputOneCharPerBitFile OutputModemRawFile [--lpdc] [--interleaver depth]\n\n", argv[0]);
-        fprintf(stderr, "  -t            Transmit test frames (adjusts test frames for raw and LDPC modes)\n");
+        fprintf(stderr, "  -t Nsecs      Transmit test frames (adjusts test frames for raw and LDPC modes)\n");
         fprintf(stderr, "  --ldpc        Run (%d,%d) LDPC decoder.  This forces 112, one char/bit output values\n"
                         "                per frame.  In testframe mode (-t) raw and coded errors will be counted\n",
                                          coded_bits_per_frame, data_bits_per_frame);
-        fprintf(stderr, "  --interleave  Interleaver for LDPC frames, e.g. 1,2,4,8,16, default is 1\n");
+        fprintf(stderr, "  --interleave  Interleave depth for LDPC frames, e.g. 1,2,4,8,16, default is 1\n");
         fprintf(stderr, "\n");
        exit(1);
     }
@@ -97,24 +97,19 @@ int main(int argc, char *argv[])
     ofdm = ofdm_create(OFDM_CONFIG_700D);
     assert(ofdm != NULL);
 
-    testframes = 0;
-    if (opt_exists(argv, argc, "-t")) {
-        testframes = 1;
-    }
-
     /* set for LDPC coded or uncoded frames */
     
-    ldpc_en = 0; interleaver_frames = 1;
+    ldpc_en = 0; interleave_frames = 1;
     int Nbitsperframe;
     if (opt_exists(argv, argc, "--ldpc")) {
 
         assert((OFDM_NUWBITS+OFDM_NTXTBITS+coded_bits_per_frame) == OFDM_BITSPERFRAME); /* sanity check */
 
         ldpc_en = 1;
-        if ((arg = opt_exists(argv, argc, "--interleaver"))) {
-            interleaver_frames = atoi(argv[arg]);
+        if ((arg = opt_exists(argv, argc, "--interleave"))) {
+            interleave_frames = atoi(argv[arg+1]);
         }
-        Nbitsperframe = interleaver_frames*data_bits_per_frame;
+        Nbitsperframe = interleave_frames*data_bits_per_frame;
         
     } else {
         /* vanilla uncoded input bits mode */
@@ -122,6 +117,7 @@ int main(int argc, char *argv[])
     }
     
     int Nsamperframe = ofdm_get_samples_per_frame();
+    fprintf(stderr, "Nbitsperframe: %d interleave_frames: %d\n", Nbitsperframe, interleave_frames);
 
     unsigned char tx_bits_char[Nbitsperframe];
     int           tx_bits[Nbitsperframe];
@@ -143,20 +139,29 @@ int main(int argc, char *argv[])
         tx_symbols[i] = uw_txt_syms[i].real + I * uw_txt_syms[i].imag;
     }
     
+    testframes = 0;
+    int Nframes = 0;
+    if ((arg = (opt_exists(argv, argc, "-t")))) {
+        testframes = 1;
+        int Nsec, Nrows;
+        Nsec = atoi(argv[arg+1]);
+        Nrows = Nsec*OFDM_RS;
+        Nframes = floor((Nrows-1)/OFDM_NS);
+        fprintf(stderr, "Nframes: %d\n", Nframes);
+    }
+
     /* main loop ----------------------------------------------------------------*/
     
     frames = 0;
 
     while(fread(tx_bits_char, sizeof(char), Nbitsperframe, fin) == Nbitsperframe) {
-       frames++;
-
         if (ldpc_en) {
             /* fancy interleaved LDPC encoded frames ----------------------------------------*/
             
             /* optionally overwrite input data with test frame nown to demodulator */
             
             if (testframes) {
-                for (j=0; j<interleaver_frames; j++) {
+                for (j=0; j<interleave_frames; j++) {
                     for(i=0; i<data_bits_per_frame; i++) {
                         tx_bits_char[j*data_bits_per_frame + i] = payload_data_bits[i];
                     }
@@ -164,14 +169,16 @@ int main(int argc, char *argv[])
             }
             
             int codeword[coded_bits_per_frame];
-            COMP coded_symbols[interleaver_frames*coded_syms_per_frame];
-            COMP coded_symbols_inter[interleaver_frames*coded_syms_per_frame];
+            COMP coded_symbols[interleave_frames*coded_syms_per_frame];
+            COMP coded_symbols_inter[interleave_frames*coded_syms_per_frame];
             complex float tx_sams[Nsamperframe];
 
-            for (j=0; j<interleaver_frames; j++) {
+            for (j=0; j<interleave_frames; j++) {
                 ldpc_encode_frame(&ldpc, codeword, &tx_bits_char[j*data_bits_per_frame]);
                 qpsk_modulate_frame(&coded_symbols[j*coded_syms_per_frame], codeword, coded_syms_per_frame);
-                gp_interleave_comp(coded_symbols_inter, coded_symbols, interleaver_frames*coded_syms_per_frame);
+            }
+            gp_interleave_comp(coded_symbols_inter, coded_symbols, interleave_frames*coded_syms_per_frame);
+            for (j=0; j<interleave_frames; j++) {            
                 for(i=0; i<coded_syms_per_frame; i++) {
                     tx_symbols[(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS+i] = coded_symbols_inter[j*coded_syms_per_frame+i].real
                                                                         + I * coded_symbols_inter[j*coded_syms_per_frame+i].imag;
@@ -181,9 +188,9 @@ int main(int argc, char *argv[])
                     tx_scaled[i] = ASCALE * crealf(tx_sams[i]);
                 }
                 fwrite(tx_scaled, sizeof(short), Nsamperframe, fout);
+                frames++;
             }
-        
-        } else {
+         } else {
             /* just modulate uncoded raw bits ----------------------------------------------*/
             
             if (testframes) {
@@ -202,6 +209,7 @@ int main(int argc, char *argv[])
                 tx_scaled[i] = ASCALE * tx_sams[i].real;
 
             fwrite(tx_scaled, sizeof(short), Nsamperframe, fout);
+            frames++;
         }
         
        /* if this is in a pipeline, we probably don't want the usual
@@ -209,8 +217,13 @@ int main(int argc, char *argv[])
 
         if (fout == stdout) fflush(stdout);
         if (fin == stdin) fflush(stdin);
+
+        if (testframes && (frames >= Nframes)) {
+            goto finished;
+        }
     }
 
+ finished:
     fclose(fin);
     fclose(fout);
     ofdm_destroy(ofdm);