added phase_est_pilot and rx_amp, working OK with phase est swicthed off
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 19 Jun 2017 00:42:20 +0000 (00:42 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 19 Jun 2017 00:42:20 +0000 (00:42 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3215 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/autotest.m
codec2-dev/octave/ofdm_dev.m
codec2-dev/octave/ofdm_lib.m
codec2-dev/octave/tofdm.m
codec2-dev/src/ofdm.c
codec2-dev/unittest/tofdm.c

index b6623d8a3d32d4c7b7a624f64104be260f7b3745..05ff935c711fa3b798042752639008029fbd432e 100644 (file)
@@ -44,7 +44,7 @@ function plot_sig_and_error(plotnum, subplotnum, sig, error, titlestr, axisvec)
 endfunction
 
 
-function check(a, b, test_name, tol)
+function check(a, b, test_name, tol, its_an_angle = 0)
   global passes;
   global fails;
 
@@ -65,7 +65,13 @@ function check(a, b, test_name, tol)
   end
   printf(": ");  
   
-  e = sum(sum(abs(a - b))/ll);
+  if its_an_angle
+    % take into account pi is close to -pi for angles in rads
+    e = sum(sum(abs(exp(j*a) - exp(j*b)))/ll);
+  else
+    e = sum(sum(abs(a - b))/ll);
+  end
+
   if e < tol
     printf("OK\n");
     passes++;
index f66e08cbbbef1d24a97f3275dbad36d03296a22a..bb35675491b8e021d7d783e99652799bc3e1c954 100644 (file)
@@ -454,7 +454,7 @@ function [sim_out rx states] = run_sim(sim_in)
       title('Scatter');
       
       figure(2); clf;
-      plot(phase_est_pilot_log(:,2:Nc+1),'g+', 'markersize', 5); 
+      plot(phase_est_pilot_log,'g+', 'markersize', 5); 
       title('Phase est');
       axis([1 Nrp -pi pi]);  
 
index 6044db414d1a32a2aac6452d187850fd8654c3c5..323fbfde7b60eebee45430e436c913ef6d51bf31 100644 (file)
@@ -383,7 +383,7 @@ function [rx_bits states aphase_est_pilot_log rx_np rx_amp] = ofdm_demod(states,
       end
       rx_bits = [rx_bits abit];
     end % c=2:Nc+1
-    aphase_est_pilot_log = [aphase_est_pilot_log; aphase_est_pilot];
+    aphase_est_pilot_log = [aphase_est_pilot_log; aphase_est_pilot(2:Nc+1)];
   end 
 
   % Adjust nin to take care of sample clock offset
index c1f43e61b9b02fbaa8b8027ba04c8586f5d603f6..8ade1366c38c5157be3c1ab6ae6d1331dcc2d993 100644 (file)
@@ -41,7 +41,9 @@ nin = Nsamperframe+2*(M+Ncp);
 states.rxbuf(Nrxbuf-nin+1:Nrxbuf) = rx(prx:nin);
 prx += nin;
 
-rxbuf_log = []; rxbuf_in_log = []; rx_sym_log = []; foff_hz_log = []; rx_bits_log = [];
+rxbuf_log = []; rxbuf_in_log = []; rx_sym_log = []; foff_hz_log = []; 
+phase_est_pilot_log = []; rx_amp_log = [];
+rx_bits_log = [];
 
 states.timing_en = 0;
 states.foff_est_en = 1;
@@ -69,6 +71,8 @@ for f=1:Nframes
   rxbuf_in_log = [rxbuf_in_log rxbuf_in];
   rxbuf_log = [rxbuf_log states.rxbuf];
   rx_sym_log = [rx_sym_log; states.rx_sym];
+  phase_est_pilot_log = [phase_est_pilot_log; aphase_est_pilot_log];
+  rx_amp_log = [rx_amp_log arx_amp];
   foff_hz_log = [foff_hz_log; states.foff_est_hz];
   rx_bits_log = [rx_bits_log rx_bits];
   
@@ -83,7 +87,7 @@ end
 if exist("path_to_tofdm", "var") == 0
    path_to_tofdm = "../build_linux/unittest/tofdm";
 end
-system(path_to_tofdm) 
+system(path_to_tofdm);
 
 load tofdm_out.txt;
 
@@ -101,9 +105,14 @@ stem_sig_and_error(4, 212, imag(rxbuf_log_c), imag(rxbuf_log - rxbuf_log_c), 'rx
 stem_sig_and_error(5, 211, real(rx_sym_log_c), real(rx_sym_log - rx_sym_log_c), 'rx sym re', [1 length(rx_sym_log_c) -1.5 1.5])
 stem_sig_and_error(5, 212, imag(rx_sym_log_c), imag(rx_sym_log - rx_sym_log_c), 'rx sym im', [1 length(rx_sym_log_c) -1.5 1.5])
 
-stem_sig_and_error(6, 111, foff_hz_log_c, (foff_hz_log - foff_hz_log_c), 'foff hz', [1 length(foff_hz_log_c) -1.5 1.5])
+% for angles pi and -pi are the same
+d = phase_est_pilot_log - phase_est_pilot_log_c; d = angle(exp(j*d));
+stem_sig_and_error(6, 211, phase_est_pilot_log_c, d, 'phase est pilot', [1 length(phase_est_pilot_log_c) -1.5 1.5])
+stem_sig_and_error(6, 212, rx_amp_log_c, rx_amp_log - rx_amp_log_c, 'rx amp', [1 length(rx_amp_log_c) -1.5 1.5])
 
-stem_sig_and_error(7, 111, rx_bits_log_c, rx_bits_log - rx_bits_log_c, 'rx bits', [1 length(rx_bits_log) -1.5 1.5])
+stem_sig_and_error(7, 111, foff_hz_log_c, (foff_hz_log - foff_hz_log_c), 'foff hz', [1 length(foff_hz_log_c) -1.5 1.5])
+
+stem_sig_and_error(8, 111, rx_bits_log_c, rx_bits_log - rx_bits_log_c, 'rx bits', [1 length(rx_bits_log) -1.5 1.5])
 
 % Run through checklist -----------------------------
 
@@ -113,5 +122,7 @@ check(tx_log, tx_log_c, 'tx');
 check(rxbuf_in_log, rxbuf_in_log_c, 'rxbuf in');
 check(rxbuf_log, rxbuf_log_c, 'rxbuf');
 check(rx_sym_log, rx_sym_log_c, 'rx_sym');
+check(phase_est_pilot_log, phase_est_pilot_log_c, 'phase_est_pilot', tol=1E-3, its_an_angle=1);
+check(rx_amp_log, rx_amp_log_c, 'rx_amp');
 check(foff_hz_log, foff_hz_log_c, 'foff_est_hz');
 check(rx_bits_log, rx_bits_log_c, 'rx_bits');
index 52d0071fa6942fc79e481d765b0bb2225ac0bfaf..5397e4449463d933157c1282a0e98e29eb3f9f81 100644 (file)
@@ -602,6 +602,9 @@ void ofdm_demod(struct OFDM *ofdm, int *rx_bits, COMP *rxbuf_in) {
         aphase_est_pilot_rect += vector_sum(symbol, 3);
 
         aphase_est_pilot[i] = cargf(aphase_est_pilot_rect);
+
+        /* TODO David: WTF 12.0 constant?  Something to do with LDPC input scaling? */
+
         aamp_est_pilot[i] = cabsf(aphase_est_pilot_rect / 12.0f);
     }
 
@@ -624,7 +627,17 @@ void ofdm_demod(struct OFDM *ofdm, int *rx_bits, COMP *rxbuf_in) {
             }
 
             ofdm->rx_np[(rr * OFDM_ROWSPERFRAME) + (i - 1)] = rx_corr;
-            ofdm->rx_amp[(rr * OFDM_ROWSPERFRAME) + (i - 1)] = aamp_est_pilot[i];
+
+            /* note even though amp ests are the same for each col,
+               the FEC decoder likes to have one amplitude per symbol
+               so convenient to log them all */
+
+            ofdm->rx_amp[(rr * OFDM_NC) + (i - 1)] = aamp_est_pilot[i];
+
+            /* note like amps in this implementation phase ests the
+               same for each col, but we log them for each symbol anyway */
+
+            ofdm->aphase_est_pilot_log[(rr * OFDM_NC) + (i - 1)] = aphase_est_pilot[i];
 
             if (OFDM_BPS == 1) {
                 rx_bits[bit_index++] = crealf(rx_corr) > 0.0f;
@@ -633,9 +646,9 @@ void ofdm_demod(struct OFDM *ofdm, int *rx_bits, COMP *rxbuf_in) {
                 rx_bits[bit_index++] = abit[1];
                 rx_bits[bit_index++] = abit[0];
             }
-        }
 
-        ofdm->aphase_est_pilot_log[(rr * OFDM_ROWSPERFRAME) + (i - 1)] = aphase_est_pilot[i];
+       }
+
     }
 
     /* Adjust nin to take care of sample clock offset */
index aca6609eb3b52d928860336d92493c2229a7898f..4113d58573fefbccf46db8dc87fdad2e9cf2e944 100644 (file)
@@ -48,7 +48,8 @@ int main(int argc, char *argv[])
     int            max_samples_per_frame = ofdm_get_max_samples_per_frame();
 
     struct OFDM   *ofdm;
-    COMP           tx[samples_per_frame];      /* one frame of tx samples */
+    COMP           tx[samples_per_frame];         /* one frame of tx samples */
+
     int            rx_bits[OFDM_BITSPERFRAME];    /* one frame of rx bits    */
 
     /* log arrays */
@@ -58,6 +59,8 @@ int main(int argc, char *argv[])
     COMP           rxbuf_in_log[max_samples_per_frame*NFRAMES];
     COMP           rxbuf_log[OFDM_RXBUF*NFRAMES];
     COMP           rx_sym_log[(OFDM_NS + 3)*NFRAMES][OFDM_NC + 2];
+    float          phase_est_pilot_log[OFDM_ROWSPERFRAME*NFRAMES][OFDM_NC];
+    float          rx_amp_log[OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES];
     float          foff_hz_log[NFRAMES];
     int            rx_bits_log[OFDM_BITSPERFRAME*NFRAMES];
 
@@ -163,6 +166,15 @@ int main(int argc, char *argv[])
             }
         }
 
+        /* note phase/amp ests the same for each col, but check them all anyway */
+
+        for (i = 0; i < OFDM_ROWSPERFRAME; i++) {
+            for (j = 0; j < OFDM_NC; j++) {
+                phase_est_pilot_log[OFDM_ROWSPERFRAME*f+i][j] = ofdm->aphase_est_pilot_log[OFDM_NC*i+j];
+                rx_amp_log[OFDM_ROWSPERFRAME*OFDM_NC*f+OFDM_NC*i+j] = ofdm->rx_amp[OFDM_NC*i+j];
+            }
+        }
+
         foff_hz_log[f] = ofdm->foff_est_hz;
 
         memcpy(&rx_bits_log[OFDM_BITSPERFRAME*f], rx_bits, sizeof(rx_bits));
@@ -182,6 +194,8 @@ int main(int argc, char *argv[])
     octave_save_complex(fout, "rxbuf_in_log_c", (COMP*)rxbuf_in_log, 1, nin_tot, nin_tot);
     octave_save_complex(fout, "rxbuf_log_c", (COMP*)rxbuf_log, 1, OFDM_RXBUF*NFRAMES,  OFDM_RXBUF*NFRAMES);
     octave_save_complex(fout, "rx_sym_log_c", (COMP*)rx_sym_log, (OFDM_NS + 3)*NFRAMES, OFDM_NC + 2, OFDM_NC + 2);
+    octave_save_float(fout, "phase_est_pilot_log_c", (float*)phase_est_pilot_log, OFDM_ROWSPERFRAME*NFRAMES, OFDM_NC, OFDM_NC);
+    octave_save_float(fout, "rx_amp_log_c", (float*)rx_amp_log, 1, OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES, OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES);
     octave_save_float(fout, "foff_hz_log_c", foff_hz_log, NFRAMES, 1, 1);
     octave_save_int(fout, "rx_bits_log_c", rx_bits_log, 1, OFDM_BITSPERFRAME*NFRAMES);
     fclose(fout);