plotting some stats for balloon flight
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 6 Jan 2016 19:34:43 +0000 (19:34 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 6 Jan 2016 19:34:43 +0000 (19:34 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2608 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/fsk_horus.m

index 4b92a00af6c59fc77497e9d972f61a74421db09d..60a3983af74a334a988326a1f2d965d486267cd8 100644 (file)
@@ -341,7 +341,7 @@ endfunction
 % UW found Sometimes there may be several matches, returns the
 % position of the best match to UW.
 
-function uw_start = find_uw(states, start_bit, rx_bits)
+function [uw_start best_corr] = find_uw(states, start_bit, rx_bits)
   uw = states.uw;
 
   mapped_rx_bits = 2*rx_bits - 1;
@@ -485,19 +485,21 @@ function extract_and_print_rtty_packets(states, rx_bits_log, rx_bits_sd_log)
 
       if crc_ok == 0
         [str_flipped crc_flipped_ok rx_bits_log] = sd_bit_flipping(states.rtty, rx_bits_log, rx_bits_sd_log, uw_loc, uw_loc+states.rtty.max_packet_len); 
-        if crc_flipped_ok
-          str = sprintf("%s fixed", str_flipped);
-        end
       end
 
       % update memory of previous packet, we use this to guess where errors may be
       if crc_ok || crc_flipped_ok
         states.prev_pkt = rx_bits_log(uw_loc+length(states.rtty.uw):uw_loc+states.rtty.max_packet_len);
       end
+
       if crc_ok
         str = sprintf("%s CRC OK", str);
       else
-        str = sprintf("%s CRC BAD", str);
+        if crc_flipped_ok
+          str = sprintf("%s fixed", str_flipped);
+        else
+          str = sprintf("%s CRC BAD", str);
+        end
       end
       printf("%s\n", str);
     end
@@ -511,7 +513,7 @@ function extract_and_print_rtty_packets(states, rx_bits_log, rx_bits_sd_log)
 endfunction
  
 
-% Extract as many ASCII packets as we can from a great big buffer of bits,
+% Extract as many binary packets as we can from a great big buffer of bits,
 % and send them to the C decoder for FEC decoding.
 % horus_l2 can be compiled a bunch of different ways.  You need to
 % compile with:
@@ -832,7 +834,7 @@ function rx_bits_log = demod_file(filename, test_frame_mode, noplot)
     uwstates = fsk_horus_init_binary_uw;
   end
 
-  states.verbose = 0x1 + 0x8;
+  states.verbose = 0x1;
 
   N = states.N;
   P = states.P;
@@ -850,6 +852,8 @@ function rx_bits_log = demod_file(filename, test_frame_mode, noplot)
   f2_int_resample_log = [];
   EbNodB_log = [];
   ppm_log = [];
+  f1_log = [];
+  f2_log = [];
   rx_bits_buf = zeros(1,2*nsym);
 
   % First extract raw bits from samples ------------------------------------------------------
@@ -887,6 +891,8 @@ function rx_bits_log = demod_file(filename, test_frame_mode, noplot)
       f2_int_resample_log = [f2_int_resample_log abs(states.f2_int_resample)];
       EbNodB_log = [EbNodB_log states.EbNodB];
       ppm_log = [ppm_log states.ppm];
+      f1_log = [f1_log states.f1];
+      f2_log = [f2_log states.f2];
 
       if test_frame_mode == 1
         states = ber_counter(states, test_frame, rx_bits_buf);
@@ -904,12 +910,18 @@ function rx_bits_log = demod_file(filename, test_frame_mode, noplot)
     printf("plotting...\n");
 
     figure(1);
+    plot(f1_log);
+    hold on;
+    plot(f2_log,'g');
+    hold off;
+
+    figure(2);
     plot(f1_int_resample_log,'+')
     hold on;
     plot(f2_int_resample_log,'g+')
     hold off;
 
-    figure(2)
+    figure(3)
     clf
     subplot(211)
     plot(norm_rx_timing_log)
@@ -920,28 +932,29 @@ function rx_bits_log = demod_file(filename, test_frame_mode, noplot)
     plot(states.nerr_log)
     title('num bit errors each frame')
  
-    figure(3)
+    figure(4)
     clf
     plot(EbNodB_log);
     title('Eb/No estimate')
 
-    figure(4)
+    figure(5)
     clf
+    rx_nowave = rx(1000:length(rx));
     subplot(211)
-    plot(rx(1:states.Fs));
+    plot(rx_nowave(1:states.Fs));
     title('input signal to demod (1 sec)')
     xlabel('Time (samples)');
     axis([1 states.Fs -35000 35000])
 
-    % normalise spectrum to 0dB full scale witha 32767 sine wave input
+    % normalise spectrum to 0dB full scale with a 32767 sine wave input
 
     subplot(212)
-    RxdBFS = 20*log10(abs(fft(rx(1:states.Fs)))) - 20*log10((states.Fs/2)*32767);
+    RxdBFS = 20*log10(abs(fft(rx_nowave(1:states.Fs)))) - 20*log10((states.Fs/2)*32767);
     plot(RxdBFS)
     axis([1 states.Fs/2 -80 0])
     xlabel('Frequency (Hz)');
 
-    figure(5);
+    figure(6);
     clf
     plot(ppm_log)
     title('Sample clock (baud rate) offset in PPM');
@@ -966,7 +979,9 @@ if exist("fsk_horus_as_a_lib") == 0
   %run_sim(5);
   %rx_bits = demod_file("horus.raw",4);
   %rx_bits = demod_file("fsk_horus_100bd_binary.raw",5);
-  rx_bits = demod_file("~/Desktop/phorus_binary_ascii.wav",4);
+  %rx_bits = demod_file("~/Desktop/phorus_binary_ascii.wav",4);
+  %rx_bits = demod_file("~/Desktop/binary/horus_160102_binary_rtty_2.wav",4);
+  rx_bits = demod_file("~/Desktop/horus_160102_vk5ei_capture2.wav",4);
   %rx_bits = demod_file("~/Desktop/horus_rtty_binary.wav",4);
   %rx_bits = demod_file("t.raw",5);
   %rx_bits = demod_file("~/Desktop/fsk_horus_10dB_1000ppm.wav",4);