correct timing instant when timing_en==0, added timing_est and sample_point and rx_np...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 19 Jun 2017 22:04:58 +0000 (22:04 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 19 Jun 2017 22:04:58 +0000 (22:04 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3225 01035d8c-6547-0410-b346-abe4f91aad63

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

index 8ade1366c38c5157be3c1ab6ae6d1331dcc2d993..63391aac9443a0e051d4ff607116552f6980e486 100644 (file)
@@ -42,12 +42,18 @@ states.rxbuf(Nrxbuf-nin+1:Nrxbuf) = rx(prx:nin);
 prx += nin;
 
 rxbuf_log = []; rxbuf_in_log = []; rx_sym_log = []; foff_hz_log = []; 
+timing_est_log = []; sample_point_log = []; 
 phase_est_pilot_log = []; rx_amp_log = [];
-rx_bits_log = [];
+rx_np_log = []; rx_bits_log = [];
 
-states.timing_en = 0;
-states.foff_est_en = 1;
-states.phase_est_en = 0;
+states.timing_en = 1;
+states.foff_est_en = 0;
+states.phase_est_en = 1;
+
+if states.timing_en == 0
+  % manually set ideal timing instant
+  states.sample_point = Ncp;
+end
 
 for f=1:Nframes
 
@@ -74,6 +80,9 @@ for f=1:Nframes
   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];
+  timing_est_log = [timing_est_log; states.timing_est];
+  sample_point_log = [sample_point_log; states.sample_point];
+  rx_np_log = [rx_np_log arx_np];
   rx_bits_log = [rx_bits_log rx_bits];
   
 end
@@ -91,28 +100,37 @@ system(path_to_tofdm);
 
 load tofdm_out.txt;
 
-stem_sig_and_error(1, 111, tx_bits_log_c, tx_bits_log - tx_bits_log_c, 'tx bits', [1 length(tx_bits_log) -1.5 1.5])
+fg = 1;
+figure(fg++); clf; plot(rx_np_log,'+'); title('Octave Scatter Diagram'); axis([-1.5 1.5 -1.5 1.5]);
+figure(fg++); clf; plot(rx_np_log_c,'+'); title('C Scatter Diagram'); axis([-1.5 1.5 -1.5 1.5]);
+
+stem_sig_and_error(fg++, 111, tx_bits_log_c, tx_bits_log - tx_bits_log_c, 'tx bits', [1 length(tx_bits_log) -1.5 1.5])
 
-stem_sig_and_error(2, 211, real(tx_log_c), real(tx_log - tx_log_c), 'tx re', [1 length(tx_log_c) -0.1 0.1])
-stem_sig_and_error(2, 212, imag(tx_log_c), imag(tx_log - tx_log_c), 'tx im', [1 length(tx_log_c) -0.1 0.1])
+stem_sig_and_error(fg, 211, real(tx_log_c), real(tx_log - tx_log_c), 'tx re', [1 length(tx_log_c) -0.1 0.1])
+stem_sig_and_error(fg++, 212, imag(tx_log_c), imag(tx_log - tx_log_c), 'tx im', [1 length(tx_log_c) -0.1 0.1])
 
-stem_sig_and_error(3, 211, real(rxbuf_in_log_c), real(rxbuf_in_log - rxbuf_in_log_c), 'rxbuf in re', [1 length(rxbuf_in_log_c) -0.1 0.1])
-stem_sig_and_error(3, 212, imag(rxbuf_in_log_c), imag(rxbuf_in_log - rxbuf_in_log_c), 'rxbuf in im', [1 length(rxbuf_in_log_c) -0.1 0.1])
+stem_sig_and_error(fg, 211, real(rxbuf_in_log_c), real(rxbuf_in_log - rxbuf_in_log_c), 'rxbuf in re', [1 length(rxbuf_in_log_c) -0.1 0.1])
+stem_sig_and_error(fg++, 212, imag(rxbuf_in_log_c), imag(rxbuf_in_log - rxbuf_in_log_c), 'rxbuf in im', [1 length(rxbuf_in_log_c) -0.1 0.1])
 
-stem_sig_and_error(4, 211, real(rxbuf_log_c), real(rxbuf_log - rxbuf_log_c), 'rxbuf re', [1 length(rxbuf_log_c) -0.1 0.1])
-stem_sig_and_error(4, 212, imag(rxbuf_log_c), imag(rxbuf_log - rxbuf_log_c), 'rxbuf im', [1 length(rxbuf_log_c) -0.1 0.1])
+stem_sig_and_error(fg, 211, real(rxbuf_log_c), real(rxbuf_log - rxbuf_log_c), 'rxbuf re', [1 length(rxbuf_log_c) -0.1 0.1])
+stem_sig_and_error(fg++, 212, imag(rxbuf_log_c), imag(rxbuf_log - rxbuf_log_c), 'rxbuf im', [1 length(rxbuf_log_c) -0.1 0.1])
 
-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(fg, 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(fg++, 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])
 
 % 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, 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(fg, 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(fg++, 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(fg++, 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(fg,   211, timing_est_log_c, (timing_est_log - timing_est_log_c), 'timing est', [1 length(timing_est_log_c) -1.5 1.5])
+stem_sig_and_error(fg++, 212, sample_point_log_c, (sample_point_log - sample_point_log_c), 'sample point', [1 length(sample_point_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])
+stem_sig_and_error(fg++, 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 -----------------------------
 
@@ -124,5 +142,7 @@ 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(timing_est_log, timing_est_log_c, 'timing_est');
+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');
index 4637ef039d13304b7f02ecdae1e345ba7694aab7..04c40c00ecc40a60421f8eb61ec15dc54e0cdab9 100644 (file)
@@ -372,6 +372,11 @@ void ofdm_set_verbose(struct OFDM *ofdm, int level) {
 
 void ofdm_set_timing_enable(struct OFDM *ofdm, bool val) {
     ofdm->timing_en = val;
+
+    if (ofdm->timing_en == false) {
+        /* manually set ideal timing instant */
+        ofdm->sample_point = OFDM_NCP-1;
+    }
 }
 
 void ofdm_set_foff_est_enable(struct OFDM *ofdm, bool val) {
index 4113d58573fefbccf46db8dc87fdad2e9cf2e944..10088039aa97d33274b9a504f6d6f01acef71fd7 100644 (file)
@@ -60,9 +60,12 @@ int main(int argc, char *argv[])
     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];
+    COMP           rx_np_log[OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES];
     float          rx_amp_log[OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES];
     float          foff_hz_log[NFRAMES];
     int            rx_bits_log[OFDM_BITSPERFRAME*NFRAMES];
+    int            timing_est_log[OFDM_BITSPERFRAME*NFRAMES];
+    int            sample_point_log[OFDM_BITSPERFRAME*NFRAMES];
 
     FILE          *fout;
     int            f,i,j;
@@ -112,9 +115,9 @@ int main(int argc, char *argv[])
     /* disable estimators for initial testing */
 
     ofdm_set_verbose(ofdm, true);
-    ofdm_set_timing_enable(ofdm, false);
-    ofdm_set_foff_est_enable(ofdm, true);
-    ofdm_set_phase_est_enable(ofdm, false);
+    ofdm_set_timing_enable(ofdm, true);
+    ofdm_set_foff_est_enable(ofdm, false);
+    ofdm_set_phase_est_enable(ofdm, true);
 
     for(f=0; f<NFRAMES; f++) {
         /* For initial testng, timing est is off, so nin is always
@@ -166,6 +169,13 @@ int main(int argc, char *argv[])
             }
         }
 
+        /* note corrected phase (rx no phase) is one big linear array for frame */
+
+        for (i = 0; i < OFDM_ROWSPERFRAME*OFDM_NC; i++) {
+            rx_np_log[OFDM_ROWSPERFRAME*OFDM_NC*f + i].real = crealf(ofdm->rx_np[i]);
+            rx_np_log[OFDM_ROWSPERFRAME*OFDM_NC*f + i].imag = cimagf(ofdm->rx_np[i]);
+        }
+
         /* note phase/amp ests the same for each col, but check them all anyway */
 
         for (i = 0; i < OFDM_ROWSPERFRAME; i++) {
@@ -176,6 +186,8 @@ int main(int argc, char *argv[])
         }
 
         foff_hz_log[f] = ofdm->foff_est_hz;
+        timing_est_log[f] = ofdm->timing_est + 1;      /* offset by 1 to match Octave */
+        sample_point_log[f] = ofdm->sample_point + 1; /* offset by 1 to match Octave */
 
         memcpy(&rx_bits_log[OFDM_BITSPERFRAME*f], rx_bits, sizeof(rx_bits));
     }
@@ -197,6 +209,9 @@ int main(int argc, char *argv[])
     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, "timing_est_log_c", timing_est_log, NFRAMES, 1);
+    octave_save_int(fout, "sample_point_log_c", sample_point_log, NFRAMES, 1);
+    octave_save_complex(fout, "rx_np_log_c", (COMP*)rx_np_log, 1, OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES, OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES);
     octave_save_int(fout, "rx_bits_log_c", rx_bits_log, 1, OFDM_BITSPERFRAME*NFRAMES);
     fclose(fout);