refactoring to separate modem from protocol states
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 13 Apr 2018 21:41:09 +0000 (21:41 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 13 Apr 2018 21:41:09 +0000 (21:41 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3478 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/fsk_horus.m
codec2-dev/octave/fsk_horus_stream.m

index 028838b1c6cd48e98d32873cdf798252e3198b2d..57549abb72d897e0e1014b2cc221a7891ef4009c 100644 (file)
@@ -9,11 +9,11 @@
 fsk_lib;
 
 
+% Basic modem set up for Horus
+
 function states = fsk_horus_init(Fs,Rs,M=2)
 
   states = fsk_init(Fs,Rs,M);
-  states.rtty = fsk_horus_init_rtty_uw(states);
-  states.binary = fsk_horus_init_binary_uw;
 
   % Freq. estimator limits - keep these narrow to stop errors with low SNR 4FSK
 
@@ -24,9 +24,9 @@ function states = fsk_horus_init(Fs,Rs,M=2)
 endfunction
 
 
-% init rtty protocol specifc states
+% init rtty protocol specific states
 
-function rtty = fsk_horus_init_rtty_uw(states)
+function rtty = fsk_horus_init_rtty
   % Generate unque word that correlates against the ASCII "$$$$$" that
   % is at the start of each frame.
   % $ -> 36 decimal -> 0 1 0 0 1 0 0 binary 
@@ -35,11 +35,10 @@ function rtty = fsk_horus_init_rtty_uw(states)
   mapped_db = 2*dollar_bits - 1;
   sync_bits = [1 1 0];
   mapped_sb = 2*sync_bits - 1;
-  %mapped_sb = [ 0 0 0 ];
 
   mapped = [mapped_db mapped_sb];
-  npad = rtty.npad = 3;     % one start and two stop bits between 7 bit ascii chars
-  nfield = rtty.nfield = 7; % length of ascii character field
+  npad   = rtty.npad   = 3;     % one start and two stop bits between 7 bit ascii chars
+  nfield = rtty.nfield = 7;     % length of ascii character field
 
   rtty.uw = [mapped mapped mapped mapped mapped];
   rtty.uw_thresh = length(rtty.uw) - 2; % allow a few bit errors when looking for UW
@@ -95,7 +94,7 @@ function [str crc_ok] = extract_ascii(states, rx_bits_buf, uw_loc)
   nfield = states.nfield;
   npad = states.npad;
 
-  str = []; str_dec = []; nstr = 0; ptx_crc = 1; rx_crc = "";
+  str = ""; str_dec = []; nstr = 0; ptx_crc = 1; rx_crc = "";
   endpacket = 0;
 
   st = uw_loc + length(states.uw);  % first bit of first char
@@ -336,8 +335,10 @@ function run_sim(test_frame_mode, M=2, frames = 10, EbNodB = 100)
 
   if test_frame_mode == 4
     % horus rtty config ---------------------
-    states = fsk_horus_init(8000, 100);
-    states.tx_bits_file = "horus_tx_bits_rtty.txt"; % Octave file of bits we FSK modulate
+    states = fsk_horus_init(8000, 100, 2);
+    states.tx_bits_file = "horus_payload_rtty.txt"; % Octave file of bits we FSK modulate
+    uwstates = fsk_horus_init_rtty_uw(states);
+    states.ntestframebits = states.nbits;
   end
                                
   if test_frame_mode == 5
@@ -808,7 +809,7 @@ endfunction
 % run test functions from here during development
 
 if exist("fsk_horus_as_a_lib") == 0
-  %run_sim(1, 2, 100, 9);
+  run_sim(4, 2, 10, 100);
   %rx_bits = demod_file("~/Desktop/115.wav",6,0,90);
   %rx_bits = demod_file("fsk_horus.raw",5);
   %rx_bits = demod_file("~/Desktop/4FSK_Binary_NoLock.wav",4);
@@ -826,5 +827,5 @@ if exist("fsk_horus_as_a_lib") == 0
   %rx_bits = demod_file("mp.raw",4);
   %rx_bits = demod_file("~/Desktop/launchbox_v2_landing_8KHz_final.wav",4);
   %rx_bits = demod_file("~/Desktop/bench_test_003.wav",7);
-  rx_bits = demod_file("../build_linux/unittest/fskrx2.raw",8);
+  %rx_bits = demod_file("../build_linux/unittest/fskrx2.raw",8);
 end
index 0c4fd55d691c80abc7440a6fdd40457b79b70263..6894357af3d2dbe94b027945f661a4a87d7f06ca 100755 (executable)
@@ -60,13 +60,14 @@ telem_upload_command = "python telem_upload.py -c vk5dgr_Octave";
 
 more off;
 states = fsk_horus_init(8000, Rs, mFSK);
-uwstates = fsk_horus_init_rtty_uw(states);
+rtty = fsk_horus_init_rtty;
+binary = fsk_horus_init_binary_uw;
 N = states.N;
 Rs = states.Rs;
 nsym = states.nsym;
 nin = states.nin;
-nfield = states.rtty.nfield;
-npad = states.rtty.npad;
+nfield = rtty.nfield;
+npad = rtty.npad;
 EbNo = 0;
 SNR = 0;
 
@@ -101,18 +102,18 @@ while c
   % Look for complete Horus RTTY frame -------------------------------------------------------------------
 
   nbits = length(rx_bits_buf);
-  uw_loc = find_uw(states.rtty, 1, rx_bits_buf);
+  uw_loc = find_uw(rtty, 1, rx_bits_buf);
 
   if uw_loc != -1
     packet_found = 1;
 
-    if (uw_loc + states.rtty.max_packet_len) < nbits
+    if (uw_loc + rtty.max_packet_len) < nbits
       %printf("\n%d nbits: %d\n",uw_loc + states.rtty.max_packet_len, nbits);
 
-      [str crc_ok] = extract_ascii(states.rtty, rx_bits_buf, uw_loc);
+      [str crc_ok] = extract_ascii(rtty, rx_bits_buf, uw_loc);
 
       if crc_ok == 0
-        [str_flipped crc_flipped_ok] = sd_bit_flipping(states.rtty, rx_bits_buf, rx_bits_sd_buf, uw_loc, uw_loc+states.rtty.max_packet_len); 
+        [str_flipped crc_flipped_ok] = sd_bit_flipping(rtty, rx_bits_buf, rx_bits_sd_buf, uw_loc, uw_loc+rtty.max_packet_len); 
         if crc_flipped_ok
           str = sprintf("%s fixed", str_flipped);
           crc_ok = 1;
@@ -137,8 +138,8 @@ while c
       % so lets remove everything up to just after the UW we just used to force
       % a search for the next UW.
 
-      rx_bits_buf    = rx_bits_buf(uw_loc+length(states.rtty.uw):length(rx_bits_buf));
-      rx_bits_sd_buf = rx_bits_sd_buf(uw_loc+length(states.rtty.uw):length(rx_bits_sd_buf));
+      rx_bits_buf    = rx_bits_buf(uw_loc+length(rtty.uw):length(rx_bits_buf));
+      rx_bits_sd_buf = rx_bits_sd_buf(uw_loc+length(rtty.uw):length(rx_bits_sd_buf));
 
       if crc_ok
         % extract GPS coords and save to log file for mapping software
@@ -163,21 +164,21 @@ while c
   % Look for complete Horus BINARY frame -------------------------------------------------------------------
 
   nbits = length(rx_bits_buf);
-  uw_loc = find_uw(states.binary, 1, rx_bits_buf);
+  uw_loc = find_uw(binary, 1, rx_bits_buf);
 
   if uw_loc != -1
     packet_found = 1;
 
-    if (uw_loc + states.binary.max_packet_len) < nbits
+    if (uw_loc + binary.max_packet_len) < nbits
      
       pin = uw_loc; 
-      nbytes = states.binary.max_packet_len/8;
+      nbytes = binary.max_packet_len/8;
       for i=1:nbytes
         if (pin+7) > nbits
           pin
           nbits
           uw_loc
-          states.binary.max_packet_len
+          binary.max_packet_len
         end
         rx_bytes(i) = rx_bits_buf(pin:pin+7) * (2.^(7:-1:0))';
         pin += 8;
@@ -206,8 +207,8 @@ while c
       % so lets remove everything up to just after the UW we just used to force
       % a search for the next UW.
 
-      rx_bits_buf    = rx_bits_buf(uw_loc+length(states.binary.uw):length(rx_bits_buf));
-      rx_bits_sd_buf = rx_bits_sd_buf(uw_loc+length(states.binary.uw):length(rx_bits_sd_buf));
+      rx_bits_buf    = rx_bits_buf(uw_loc+length(binary.uw):length(rx_bits_buf));
+      rx_bits_sd_buf = rx_bits_sd_buf(uw_loc+length(binary.uw):length(rx_bits_sd_buf));
     end
   end
 
@@ -215,10 +216,10 @@ while c
   % Keep very end of it as it may have part of a UW in it
 
   if packet_found == 0
-    max_len = states.rtty.max_packet_len*4;
+    max_len = rtty.max_packet_len*4;
     if length(rx_bits_buf) > max_len
-      rx_bits_buf = rx_bits_buf(length(rx_bits_buf)-states.rtty.max_packet_len:length(rx_bits_buf));
-      rx_bits_sd_buf = rx_bits_sd_buf(length(rx_bits_sd_buf)-states.rtty.max_packet_len:length(rx_bits_sd_buf));
+      rx_bits_buf = rx_bits_buf(length(rx_bits_buf)-rtty.max_packet_len:length(rx_bits_buf));
+      rx_bits_sd_buf = rx_bits_sd_buf(length(rx_bits_sd_buf)-rtty.max_packet_len:length(rx_bits_sd_buf));
     end
   end