first pass coarse timing/frame sync working on ofdm_rx
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 2 May 2017 05:40:32 +0000 (05:40 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 2 May 2017 05:40:32 +0000 (05:40 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3117 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/ofdm_dev.m
codec2-dev/octave/ofdm_lib.m
codec2-dev/octave/ofdm_rx.m

index c314bd96726d9afc2506f3389aac5f5a6de31e31..60377290f589651966ab36d5b3e26ab9f1d57439 100644 (file)
@@ -386,7 +386,7 @@ function [delta_ct delta_foff] = acquisition_test(Ntests=10, EbNodB=100, foff_hz
   sim_in.Nsec = Ntests*(sim_in.Ns+1)/sim_in.Rs;
 
   sim_in.EbNodB = EbNodB;
-  sim_in.verbose = 0;
+  sim_in.verbose = 2;
   sim_in.hf_en = hf_en;
   sim_in.foff_hz = foff_hz; 
   sim_in.timing_en = 0;
@@ -524,5 +524,5 @@ more off;
 
 %run_single
 %run_curves
-acquisition_histograms
-
+%acquisition_histograms
+acquisition_test
index 9164b666ef6c3c26f3e3cd68a464b44546a9204b..3cdfa3c8b3d141162d7222e61b8c063872a23a20 100644 (file)
@@ -220,6 +220,8 @@ function [rx_bits states aphase_est_pilot_log rx_np] = ofdm_demod(states, rxbuf_
   rxbuf(1:Nrxbuf-states.nin) = rxbuf(states.nin+1:Nrxbuf);
   rxbuf(Nrxbuf-states.nin+1:Nrxbuf) = rxbuf_in;
 
+  % get latest freq offset estimate
+
   woff_est = 2*pi*foff_est_hz/Fs;
 
   % update timing estimate --------------------------------------------------
@@ -247,7 +249,7 @@ function [rx_bits states aphase_est_pilot_log rx_np] = ofdm_demod(states, rxbuf_
 
   % down convert at current timing instant----------------------------------
 
-    % todo: this cld be more efficent, as pilot r becomes r-Ns on next frame
+  % todo: this cld be more efficent, as pilot r becomes r-Ns on next frame
 
   rx_sym = zeros(1+Ns+1+1, Nc+2);
 
index 97e7992b82e877962bfbef9067e5e85202dd625f..e9c9b3d7df359fd58f6b93a61a1965dcafb4576c 100644 (file)
@@ -10,6 +10,8 @@ function ofdm_rx(filename)
   states = ofdm_init(bps, Rs, Tcp, Ns, Nc);
   ofdm_load_const;
 
+  states.verbose = 1;
+
   % fixed test frame of tx bits
 
   rand('seed', 100);
@@ -19,7 +21,7 @@ function ofdm_rx(filename)
 
   rx_bits = []; rx_np = []; timing_est_log = []; delta_t_log = []; foff_est_hz_log = [];
   phase_est_pilot_log = [];
-  Nerrs = Nbits = 0;
+  Terrs = Tbits = 0;
 
   % load real samples from file
 
@@ -31,8 +33,12 @@ function ofdm_rx(filename)
   % 'prime' rx buf to get correct coarse timing (for now)
 
   prx = 1;
-  states.rxbuf(M+Ncp+2*Nsamperframe+1:Nrxbuf) = rx(prx:Nsamperframe+2*(M+Ncp));
-  prx += Nsamperframe+2*(M+Ncp);
+  %nin = Nsamperframe+2*(M+Ncp);
+  nin = Nsamperframe+M+Ncp;
+  states.rxbuf(Nrxbuf-nin+1:Nrxbuf) = rx(prx:nin);
+  prx += nin;
+
+  state = 'searching';
 
   % main loop ----------------------------------------------------------------
 
@@ -52,21 +58,57 @@ function ofdm_rx(filename)
 
     [rx_bits states aphase_est_pilot_log arx_np] = ofdm_demod(states, rxbuf_in);
 
-    rx_np = [rx_np arx_np];
-    timing_est_log = [timing_est_log states.timing_est];
-    delta_t_log = [delta_t_log states.delta_t];
-    foff_est_hz_log = [foff_est_hz_log states.foff_est_hz];
-    phase_est_pilot_log = [phase_est_pilot_log; aphase_est_pilot_log];
-
-    % measure bit errors
+    % measure errors and iterate start machine
 
     errors = xor(tx_bits, rx_bits);
-    Nerrs += sum(errors);
-    Nerrs_log(f) = sum(errors);
-    Nbits += Nbitsperframe;
+    Nerrs = sum(errors);
+    next_state = state;
+
+    if strcmp(state,'searching')  
+      if Nerrs/Nbitsperframe < 0.1
+        next_state = 'synced';
+      end
+    end
+    state = next_state;
+
+    if strcmp(state,'searching') 
+
+      % attempt coarse timing estimate (i.e. detect start of frame)
+
+      st = M+Ncp + Nsamperframe + 1; en = st + 2*Nsamperframe; 
+      [ct_est foff_est] = coarse_sync(states, states.rxbuf(st:en), states.rate_fs_pilot_samples);
+      if states.verbose
+        printf("ct_est: %4d foff_est: %3.1f\n", ct_est, foff_est);
+      end
+
+      % calculate number of samples we need on next buffer to get into sync
+     
+      states.nin = Nsamperframe + ct_est - 1;
+
+      % reset modem states
+
+      states.sample_point = states.timing_est = 1;
+      states.foff_est_hz = 0;
+
+    else
+
+      % we are in sync so log states and bit errors
+
+      rx_np = [rx_np arx_np];
+      timing_est_log = [timing_est_log states.timing_est];
+      delta_t_log = [delta_t_log states.delta_t];
+      foff_est_hz_log = [foff_est_hz_log states.foff_est_hz];
+      phase_est_pilot_log = [phase_est_pilot_log; aphase_est_pilot_log];
+
+      % measure bit errors
+
+      Terrs += Nerrs;
+      Nerrs_log(f) = Nerrs;
+      Tbits += Nbitsperframe;
+    end
   end
 
-  printf("BER: %5.4f Nbits: %d Nerrs: %d\n", Nerrs/Nbits, Nbits, Nerrs);
+  printf("BER: %5.4f Tbits: %d Terrs: %d\n", Terrs/Tbits, Tbits, Terrs);
 
   figure(1); clf; 
   plot(rx_np,'+');