refactoring mod functions that can be used for freedv_api 700D mode
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 21 Apr 2018 04:00:41 +0000 (04:00 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 21 Apr 2018 04:00:41 +0000 (04:00 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3516 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/interldpc.c
codec2-dev/src/interldpc.h
codec2-dev/src/ofdm_demod.c
codec2-dev/src/ofdm_mod.c

index 4c5c6904e6af83074e187d81879399028b35290e..716c4c7f310bb369a72940eaf22c100367515641 100644 (file)
@@ -173,3 +173,65 @@ int count_uncoded_errors(struct LDPC *ldpc, int Nerrs_raw[], int interleave_fram
 
     return Terrs;
 }
+
+int count_errors(int tx_bits[], char rx_bits[], int n) {
+    int i;
+    int Nerrs = 0;
+    
+    Nerrs = 0;
+    for(i=0; i<n; i++) {
+        if (tx_bits[i] != rx_bits[i]) {
+            Nerrs++;
+        }
+    }
+    return Nerrs;
+}
+
+
+void ofdm_ldpc_interleave_tx(struct OFDM *ofdm, struct LDPC *ldpc, complex float tx_sams[], uint8_t tx_bits_char[], complex float tx_symbols[], int interleave_frames)
+{
+    int coded_syms_per_frame = ldpc->coded_syms_per_frame;
+    int coded_bits_per_frame = ldpc->coded_bits_per_frame;
+    int data_bits_per_frame = ldpc->data_bits_per_frame;
+
+    int codeword[coded_bits_per_frame];
+    COMP coded_symbols[interleave_frames*coded_syms_per_frame];
+    COMP coded_symbols_inter[interleave_frames*coded_syms_per_frame];
+    int Nsamperframe = ofdm_get_samples_per_frame();
+
+    int i,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, 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;
+        }
+        ofdm_txframe(ofdm, &tx_sams[j*Nsamperframe], tx_symbols);
+    }
+}
+
+/* UW never changes so we can pre-load tx_symbols with modulated UW */
+
+void build_modulated_uw(struct OFDM *ofdm, complex float tx_symbols[])
+{
+    int  uw_txt_bits[OFDM_NUWBITS+OFDM_NTXTBITS];
+    COMP uw_txt_syms[(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS];
+    int i,j;
+
+    for(i=0; i<OFDM_NUWBITS; i++) {
+        uw_txt_bits[i] = ofdm->tx_uw[i];
+    }
+    /* clear txt bits for now, they can be added in later */
+    for(j=0; j<OFDM_NTXTBITS; j++,i++) {
+        uw_txt_bits[i] = 0;
+    }    
+    qpsk_modulate_frame(uw_txt_syms, uw_txt_bits, (OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS);
+    for(i=0; i<(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS; i++) {
+        tx_symbols[i] = uw_txt_syms[i].real + I * uw_txt_syms[i].imag;
+    }
+}
index 2610e7b3c859707ea7c5d4d0fee0968775730900..3255575fc133658b791a9ae78405ca3042c17e0e 100644 (file)
@@ -28,6 +28,7 @@
 #ifndef __INTERLDPC__
 #define __INTERLDPC__
 
+#include <stdint.h>
 #include "comp.h"
 #include "mpdecode_core.h"
 #include "ofdm_internal.h"
@@ -46,5 +47,8 @@ void interleaver_sync_state_machine(struct OFDM *ofdm,
                                     float EsNo, int interleave_frames,
                                     int *inter, int *parityCheckCount, int *Nerrs_coded);
 int count_uncoded_errors(struct LDPC *ldpc, int Nerrs_raw[], int interleave_frames, COMP codeword_symbols_de[]);
+int count_errors(int tx_bits[], char rx_bits[], int n);
+void ofdm_ldpc_interleave_tx(struct OFDM *ofdm, struct LDPC *ldpc, complex float tx_sams[], uint8_t tx_bits_char[], complex float tx_symbols[], int interleave_frames);
+void build_modulated_uw(struct OFDM *ofdm, complex float tx_symbols[]);
 
 #endif
index e4c7a3b7ff83b43bceee04e3396bbb9748a753cb..dd784dbdf92071bfb991deb593be5e4877ab0c4f 100644 (file)
@@ -260,14 +260,8 @@ int main(int argc, char *argv[])
                             iter[j] = run_ldpc_decoder(&ldpc, out_char, llr, &parityCheckCount[j]);
                             //fprintf(stderr,"j: %d iter: %d pcc: %d\n", j, iter[j], parityCheckCount[j]);
                             if (testframes) {
-                                Nerrs = 0;
-                                for(i=0; i<data_bits_per_frame; i++) {
-                                    if (payload_data_bits[i] != out_char[i]) {
-                                        Nerrs++;
-                                    }
-                                }
-                                Nerrs_coded[j] = Nerrs;
-                                Terrs_coded += Nerrs;
+                                Nerrs_coded[j] = count_errors(payload_data_bits, out_char, data_bits_per_frame);
+                                Terrs_coded += Nerrs_coded[j];
                                 Tbits_coded += data_bits_per_frame;
                             }
                             fwrite(out_char, sizeof(char), data_bits_per_frame, fout);
index 853664e85b47ee88fd9e1f3fdd2f548b48cc3f11..391e1b283180bab72621e4257caf694c6a582c40 100644 (file)
 #include "ofdm_internal.h"
 #include "interldpc.h"
 #include "gp_interleaver.h"
-#include "test_bits_ofdm.h"
 
 #define ASCALE (2E5*1.1491)
 
+extern int payload_data_bits[];
+extern int test_bits_ofdm[];
+
 int opt_exists(char *argv[], int argc, char opt[]) {
     int i;
     for (i=0; i<argc; i++) {
@@ -125,20 +127,9 @@ int main(int argc, char *argv[])
     
     /* build modulated UW and txt bits */
 
-    int  uw_txt_bits[OFDM_NUWBITS+OFDM_NTXTBITS];
-    COMP uw_txt_syms[(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS];
     complex float tx_symbols[(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS + coded_syms_per_frame];
-    for(i=0; i<OFDM_NUWBITS; i++) {
-        uw_txt_bits[i] = ofdm->tx_uw[i];
-    }
-    for(j=0; j<OFDM_NTXTBITS; j++,i++) {
-        uw_txt_bits[i] = 0;
-    }    
-    qpsk_modulate_frame(uw_txt_syms, uw_txt_bits, (OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS);
-    for(i=0; i<(OFDM_NUWBITS+OFDM_NTXTBITS)/OFDM_BPS; i++) {
-        tx_symbols[i] = uw_txt_syms[i].real + I * uw_txt_syms[i].imag;
-    }
-    
+    build_modulated_uw(ofdm, tx_symbols);
+     
     testframes = 0;
     int Nframes = 0;
     if ((arg = (opt_exists(argv, argc, "-t")))) {
@@ -158,7 +149,8 @@ int main(int argc, char *argv[])
         if (ldpc_en) {
             /* fancy interleaved LDPC encoded frames ----------------------------------------*/
             
-            /* optionally overwrite input data with test frame nown to demodulator */
+            /* optionally overwrite input data with test frame of
+               payload data bits known to demodulator */
             
             if (testframes) {
                 for (j=0; j<interleave_frames; j++) {
@@ -167,29 +159,18 @@ int main(int argc, char *argv[])
                     }
                 }
             }
-            
-            int codeword[coded_bits_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<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, interleave_frames*coded_syms_per_frame);
+
+            complex float tx_sams[interleave_frames*Nsamperframe];
+            ofdm_ldpc_interleave_tx(ofdm, &ldpc, tx_sams, tx_bits_char, tx_symbols, interleave_frames);
+
             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;
-                }
-                ofdm_txframe(ofdm, tx_sams, tx_symbols);
                 for(i=0; i<Nsamperframe; i++) {
-                    tx_scaled[i] = ASCALE * crealf(tx_sams[i]);
+                    tx_scaled[i] = ASCALE * crealf(tx_sams[j*Nsamperframe+i]);
                 }
                 fwrite(tx_scaled, sizeof(short), Nsamperframe, fout);
                 frames++;
             }
+
          } else {
             /* just modulate uncoded raw bits ----------------------------------------------*/
             
@@ -198,6 +179,7 @@ int main(int argc, char *argv[])
                     tx_bits_char[i] = test_bits_ofdm[i];
                 }
             }
+
             for(i=0; i<Nbitsperframe; i++)
                 tx_bits[i] = tx_bits_char[i];
             COMP tx_sams[Nsamperframe];