starting rx side of tofdm.[cm]
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 14 Jun 2017 21:08:01 +0000 (21:08 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 14 Jun 2017 21:08:01 +0000 (21:08 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3193 01035d8c-6547-0410-b346-abe4f91aad63

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

index ffff746a02f7dc7084b5b47a4cb83ef91ec28d56..82fd2cc090ade6adec61a8063eecc78250d3428e 100644 (file)
@@ -4,13 +4,15 @@
 % Octave script for comparing Octave and C versions of OFDZM modem
 
 
-Frames = 1;
+Nframes = 2;
 
 more off;
 ofdm_lib;
 autotest;
 
-% Run a few frames of Octave version
+% ---------------------------------------------------------------------
+% Run Octave version 
+% ---------------------------------------------------------------------
 
 Ts = 0.018; Tcp = 0.002; Rs = 1/Ts; bps = 2; Nc = 16; Ns = 8;
 states = ofdm_init(bps, Rs, Tcp, Ns, Nc);
@@ -19,13 +21,51 @@ ofdm_load_const;
 rand('seed',1);
 tx_bits = round(rand(1,Nbitsperframe));
 
+% Run tx loop
+
 tx_bits_log = []; tx_log = [];
-for f=1:Frames
+for f=1:Nframes
   tx_bits_log = [tx_bits_log tx_bits];
   tx_log = [tx_log ofdm_mod(states, tx_bits)];
 end
 
-% Run C version and plot Octave and C states and differences -----------------------------
+% Channel simulation
+
+rx = tx_log;
+
+% Init rx with ideal timing so we can test with timing estimation disabled
+
+Nsam = length(rx);
+prx = 1;
+nin = Nsamperframe+2*(M+Ncp);
+states.rxbuf(Nrxbuf-nin+1:Nrxbuf) = rx(prx:nin);
+prx += nin;
+
+rxbuf_log = [];
+
+for f=1:Nframes
+
+  % insert samples at end of buffer, set to zero if no samples
+  % available to disable phase estimation on future pilots on last
+  % frame of simulation
+
+  lnew = min(Nsam-prx,states.nin);
+  rxbuf_in = zeros(1,states.nin);
+
+  if lnew
+    rxbuf_in(1:lnew) = rx(prx:prx+lnew-1);
+  end
+  prx += states.nin;
+  [rx_bits_raw states aphase_est_pilot_log arx_np arx_amp] = ofdm_demod(states, rxbuf_in);
+
+  % log some states for comparison to C
+
+  rxbuf_log = [rxbuf_log states.rxbuf];
+end
+
+% ---------------------------------------------------------------------
+% Run C version and plot Octave and C states and differences 
+% ---------------------------------------------------------------------
 
 system('../build_linux/unittest/tofdm');
 load tofdm_out.txt;
index 61e3a3dc7b84b127005c2b1a2f20d823b5bef4ab..39d8c48b4a9054bbd01f163c827b2aa74e876bc0 100644 (file)
 #include "octave.h"
 #include "test_bits_ofdm.h"
 
-#define FRAMES 1
+#define NFRAMES 2
 
 int main(int argc, char *argv[])
 {
     struct OFDM   *ofdm;
     COMP           tx[OFDM_SAMPLESPERFRAME];      /* one frame of tx samples */
 
-    int            tx_bits_log[OFDM_BITSPERFRAME*FRAMES];
-    COMP           tx_log[OFDM_SAMPLESPERFRAME*FRAMES];
+    int            tx_bits_log[OFDM_BITSPERFRAME*NFRAMES];
+    COMP           tx_log[OFDM_SAMPLESPERFRAME*NFRAMES];
+    COMP           rxbuf_log[OFDM_RXBUF*NFRAMES];
 
     FILE          *fout;
-    int            f;
+    int            f,i;
 
     ofdm = ofdm_create(); assert(ofdm != NULL);
 
     /* Main Loop ---------------------------------------------------------------------*/
 
-    for(f=0; f<FRAMES; f++) {
+    for(f=0; f<NFRAMES; f++) {
 
        /* --------------------------------------------------------*\
                                  Mod
@@ -78,8 +79,12 @@ int main(int argc, char *argv[])
                                Demod
     \*---------------------------------------------------------*/
 
-    for(f=0; f<FRAMES; f++) {
+    for(f=0; f<NFRAMES; f++) {
         /* todo: run demod and log states as it runs */
+        for(i=0; i<OFDM_RXBUF; i++) {
+            rxbuf_log[OFDM_RXBUF*f+i].real = crealf(ofdm->rxbuf[i]);
+            rxbuf_log[OFDM_RXBUF*f+i].imag = cimagf(ofdm->rxbuf[i]);
+       }
     }
 
     /*---------------------------------------------------------*\
@@ -91,8 +96,9 @@ int main(int argc, char *argv[])
     assert(fout != NULL);
     fprintf(fout, "# Created by tofdm.c\n");
     octave_save_complex(fout, "W_c", (COMP*)ofdm->W, OFDM_NC + 2, OFDM_M, OFDM_M);
-    octave_save_int(fout, "tx_bits_log_c", tx_bits_log, 1, OFDM_BITSPERFRAME*FRAMES);
-    octave_save_complex(fout, "tx_log_c", (COMP*)tx_log, 1, OFDM_SAMPLESPERFRAME*FRAMES,  OFDM_SAMPLESPERFRAME*FRAMES);
+    octave_save_int(fout, "tx_bits_log_c", tx_bits_log, 1, OFDM_BITSPERFRAME*NFRAMES);
+    octave_save_complex(fout, "tx_log_c", (COMP*)tx_log, 1, OFDM_SAMPLESPERFRAME*NFRAMES,  OFDM_SAMPLESPERFRAME*NFRAMES);
+    octave_save_complex(fout, "rxbuf_c", (COMP*)rxbuf_log, 1, OFDM_RXBUF*NFRAMES,  OFDM_RXBUF*NFRAMES);
     fclose(fout);
 
     ofdm_destroy(ofdm);