tofdm working with and without CML support
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 19 Apr 2018 07:23:57 +0000 (07:23 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 19 Apr 2018 07:23:57 +0000 (07:23 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3506 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/tofdm.m
codec2-dev/src/test_bits_ofdm.h
codec2-dev/unittest/tofdm.c

index 2bc4a25245dabb62f4eddda6a3e9f877f98e421f..6bcc949ec6a4b671f3d0d28a5117d904b4603c56 100644 (file)
@@ -16,8 +16,8 @@ ldpc
 
 % attempt to start up CML, path will be different on your machine
 
-path_to_cml = '/home/david/Desktop/cml/mex';
-addpath(path_to_cml);
+path_to_cml = '~/cml';
+addpath(strcat(path_to_cml, "/mex"), strcat(path_to_cml, "/mat"));
 cml_support = 0;
 if exist("Somap") == 0
   printf("Can't find CML mex directory so we won't run those tests for now...\n");
@@ -51,14 +51,18 @@ if cml_support
   assert(Nbitsperframe == (code_param.code_bits_per_frame + states.Nuwbits + states.Ntxtbits));
 end
 
+tx_bits = zeros(1,Nbitsperframe);
 rand('seed',1);
-tx_bits = round(rand(1,Nbitsperframe));
+
+payload_data_bits = round(rand(1,(Nbitsperframe-Nuwbits-Ntxtbits)/2));
 if cml_support
-  ibits = tx_bits(Nuwbits+Ntxtbits+1:Nuwbits+Ntxtbits+code_param.data_bits_per_frame);
+  ibits = payload_data_bits;
   codeword = LdpcEncode(ibits, code_param.H_rows, code_param.P_matrix);
   tx_bits(Nuwbits+Ntxtbits+1:end) = codeword;
+else
+  tx_bits(Nuwbits+Ntxtbits+1:end) = [payload_data_bits payload_data_bits];
 end
-tx_bits(1:Nuwbits+Ntxtbits) = 0;
+tx_bits(1:Nuwbits+Ntxtbits) = [states.tx_uw zeros(1,Ntxtbits)];
 
 % Run tx loop
 
@@ -138,9 +142,10 @@ for f=1:Nframes
     symbol_likelihood = Demod2D(arx_np(Nuwtxtsymbolsperframe+1:end), S_matrix, EsNo, arx_amp(Nuwtxtsymbolsperframe+1:end));
     bit_likelihood = Somap(symbol_likelihood);
 
-    [x_hat errors] = MpDecode(-bit_likelihood(1:code_param.code_bits_per_frame), code_param.H_rows, code_param.H_cols, max_iterations, decoder_type, 1, 1);
-    detected_data = x_hat(max_iterations,:);
-
+    [x_hat paritychecks] = MpDecode(-bit_likelihood(1:code_param.code_bits_per_frame), code_param.H_rows, code_param.H_cols, max_iterations, decoder_type, 1, 1);
+    [mx mx_ind] = max(paritychecks);
+    detected_data = x_hat(mx_ind,:);
+    
     % make sure LDPC decoding is working OK
     
     assert(codeword == detected_data);
@@ -224,7 +229,9 @@ check(coarse_foff_est_hz_log, coarse_foff_est_hz_log_c, 'coarse_foff_est_hz');
 check(sample_point_log, sample_point_log_c, 'sample_point');
 check(foff_hz_log, foff_hz_log_c, 'foff_est_hz');
 check(rx_bits_log, rx_bits_log_c, 'rx_bits');
-check(symbol_likelihood_log, symbol_likelihood_log_c, 'symbol_likelihood_log');
-check(bit_likelihood_log, bit_likelihood_log_c, 'bit_likelihood_log');
-check(detected_data_log, detected_data_log_c, 'detected_data');
+if cml_support
+  check(symbol_likelihood_log, symbol_likelihood_log_c, 'symbol_likelihood_log');
+  check(bit_likelihood_log, bit_likelihood_log_c, 'bit_likelihood_log');
+  check(detected_data_log, detected_data_log_c, 'detected_data');
+end
 
index 423626e51461eb4a236705fd1b7bbe51647201bd..1d54ed8c5de505a11be499dc69e44ddd504e33cd 100644 (file)
@@ -1,15 +1,15 @@
 /* Generated by test_bits_ofdm_file() Octave function */
 
 const int test_bits_ofdm[]={
-  1,
   0,
   0,
-  1,
   0,
-  1,
   0,
   0,
-  1,
+  0,
+  0,
+  0,
+  0,
   0,
   0,
   0,
@@ -356,7 +356,7 @@ const int payload_data_bits[]={
   0
 };
 
-const int test_codeword[]={
+const int codeword[]={
   1,
   1,
   0,
@@ -580,5 +580,6 @@ const int test_codeword[]={
   0,
   1,
   0,
+  0,
   0
 };
index b0890d968adec02825f912bfdd899e615588f9c4..a471d7f14beab4e80be6594f7eb7bb04f1d0e2f4 100644 (file)
 
 #define CODED_BITSPERFRAME 224    /* number of LDPC codeword bits/frame   */
 
+/* QPSK constellation for symbol likelihood calculations */
+
+static COMP S_matrix[] = {
+    { 1.0f,  0.0f},
+    { 0.0f,  1.0f},
+    { 0.0f, -1.0f},
+    {-1.0f,  0.0f}
+};
+         
 /*---------------------------------------------------------------------------*\
 
   FUNCTION....: fs_offset()
@@ -196,6 +205,13 @@ int main(int argc, char *argv[])
 
         /* See CML startup code in tofdm.m */
 
+        for(i=0; i<OFDM_NUWBITS; i++) {
+            tx_bits[i] = ofdm->tx_uw[i];
+        }
+        for(i=OFDM_NUWBITS; i<OFDM_NUWBITS+OFDM_NTXTBITS; i++) {
+            tx_bits[i] = 0;
+        }       
+
         #define LDPC_ENABLE
         #ifdef LDPC_ENABLE
         unsigned char ibits[HRA_112_112_NUMBERROWSHCOLS];
@@ -203,13 +219,10 @@ int main(int argc, char *argv[])
 
         assert(HRA_112_112_NUMBERROWSHCOLS == ldpc.CodeLength/2);
         for(i=0; i<ldpc.CodeLength/2; i++) {
-            ibits[i] = test_bits_ofdm[i+OFDM_NUWBITS+OFDM_NTXTBITS];
+            ibits[i] = payload_data_bits[i];
         }
         encode(&ldpc, ibits, pbits);
-        for(i=0; i<OFDM_NUWBITS+OFDM_NTXTBITS; i++) {
-            tx_bits[i] = 0;
-        }
-        for(j=0; j<ldpc.CodeLength/2; i++,j++) {
+        for(j=0, i=OFDM_NUWBITS+OFDM_NTXTBITS; j<ldpc.CodeLength/2; i++,j++) {
             tx_bits[i] = ibits[j];
         }
         for(j=0; j<ldpc.CodeLength/2; i++,j++) {
@@ -217,8 +230,11 @@ int main(int argc, char *argv[])
         }
         assert(i == OFDM_BITSPERFRAME);
         #else
-        for(i=0; i<OFDM_BITSPERFRAME; i++) {
-            tx_bits = test_bits_ofdm[i];
+        for(i=OFDM_NUWBITS+OFDM_NTXTBITS,j=0; j<ldpc.CodeLength/2; i++,j++) {
+            tx_bits[i] = payload_data_bits[j];
+        }
+        for(j=0; j<ldpc.CodeLength/2; i++,j++) {
+            tx_bits[i] = payload_data_bits[j];
         }
         #endif