suport for plotting error patterns, some experimental code for SNR estimation of...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 18 Feb 2013 01:45:06 +0000 (01:45 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 18 Feb 2013 01:45:06 +0000 (01:45 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1164 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/fdmdv_demod.m
codec2-dev/octave/fdmdv_ut.m

index 0e7a4e8050455f658b58b86b76e2e5322f0e35be..ff6a7fc007f2072ae643466603e8ea9b14bdaeeb 100644 (file)
@@ -29,6 +29,7 @@ function fdmdv_demod(rawfilename, nbits, pngname)
   sync_log = [];
   test_frame_sync_log = [];
   test_frame_sync_state = 0;
+  error_pattern_log = [];
 
   % SNR states
 
@@ -51,6 +52,12 @@ function fdmdv_demod(rawfilename, nbits, pngname)
   track = 0;
   fest_state = 0;
 
+  % spectrum states
+
+  Nspec=1024;
+  spec_mem=zeros(1,Nspec);
+  SdB = zeros(1,Nspec);
+
   % Main loop ----------------------------------------------------
 
   for f=1:frames
@@ -63,6 +70,14 @@ function fdmdv_demod(rawfilename, nbits, pngname)
     
     rx_fdm_log = [rx_fdm_log rx_fdm(1:nin)];
 
+    % update spectrum
+
+    l=length(rx_fdm);
+    spec_mem(1:Nspec-l) = spec_mem(l+1:Nspec);
+    spec_mem(Nspec-l+1:Nspec) = rx_fdm;
+    S=fft(spec_mem.*hanning(Nspec)',Nspec);
+    SdB = 0.9*SdB + 0.1*20*log10(abs(S));
+
     % frequency offset estimation and correction
 
     [pilot prev_pilot pilot_lut_index prev_pilot_lut_index] = get_pilot(pilot_lut_index, prev_pilot_lut_index, nin);
@@ -96,7 +111,7 @@ function fdmdv_demod(rawfilename, nbits, pngname)
     end
 
     if strcmp(modulation,'dqpsk')
-      rx_symbols_log = [rx_symbols_log rx_symbols.*conj(prev_rx_symbols)*exp(j*pi/4)];
+      rx_symbols_log = [rx_symbols_log rx_symbols.*conj(prev_rx_symbols./abs(prev_rx_symbols))*exp(j*pi/4)];
     else
       rx_symbols_log = [rx_symbols_log rx_symbols];
     endif
@@ -115,7 +130,7 @@ function fdmdv_demod(rawfilename, nbits, pngname)
 
     % count bit errors if we find a test frame
 
-    [test_frame_sync bit_errors] = put_test_bits(test_bits, rx_bits);
+    [test_frame_sync bit_errors error_pattern] = put_test_bits(test_bits, rx_bits);
     if (test_frame_sync == 1)
       total_bit_errors = total_bit_errors + bit_errors;
       total_bits = total_bits + Ntest_bits;
@@ -141,20 +156,21 @@ function fdmdv_demod(rawfilename, nbits, pngname)
         test_frame_count = 0;
         if ((test_frame_sync == 0))      
           next_test_frame_sync_state = 0;
+        else
+          error_pattern_log = [error_pattern_log error_pattern];
         end
       end
     end
     test_frame_sync_state = next_test_frame_sync_state;
     test_frame_sync_log = [test_frame_sync_log test_frame_sync_state];
-
   end
-  
   % ---------------------------------------------------------------------
   % Print Stats
   % ---------------------------------------------------------------------
 
   ber = total_bit_errors / total_bits;
-
+  Fcentre
   printf("%d bits  %d errors  BER: %1.4f\n",total_bits, total_bit_errors, ber);
 
   % ---------------------------------------------------------------------
@@ -186,14 +202,7 @@ function fdmdv_demod(rawfilename, nbits, pngname)
 
   figure(3)
   clf;
-  subplot(211)
-  [a b] = size(rx_fdm_log);
-  xt1 = (1:b)/Fs;
-  plot(xt1, rx_fdm_log);
-  title('Rx FDM Signal');
-  subplot(212)
   spec(rx_fdm_log,8000);
-  title('FDM Rx Spectrogram');
 
   figure(4)
   clf;
@@ -211,7 +220,36 @@ function fdmdv_demod(rawfilename, nbits, pngname)
 
   figure(5)
   clf;
+  subplot(211);
   plot(xt, snr_est_log);
   title('SNR Estimates')
+  subplot(212)
+  snrdB_pc = 20*log10(sig_est(1:Nc+1)) - 20*log10(noise_est(1:Nc+1));
+  bar(snrdB_pc(1:Nc) - mean(snrdB_pc(1:Nc)))
+  axis([0 Nc+1 -3 3]);
+
+  figure(6)
+  clf;
+  hold on;
+  lep = length(error_pattern_log);
+  for p=1:Nc
+    plot(p + 0.25*error_pattern_log((p-1)*2+1:Nc*Nb:lep));
+    plot(0.30 + p + 0.25*error_pattern_log(p*2:Nc*Nb:lep),'r')
+  end
+  hold off;
+  axis([1 lep/(Nc*Nb) 0 15])
+
+  figure(7)
+  clf;
+  subplot(211)
+  [a b] = size(rx_fdm_log);
+  xt1 = (1:b)/Fs;
+  plot(xt1, rx_fdm_log);
+  title('Rx FDM Signal');
+  subplot(212)
+  plot((0:Nspec/2-1)*Fs/Nspec, SdB(1:Nspec/2) - 20*log10(Nspec/2))
+  axis([0 Fs/2 -40 0])
+  grid
+  title('FDM Rx Spectrum');
+
 endfunction
index 147322df422bf473835bdb3145f027e153837540..c89aa78c3ab2ded3573a5460408b25029413c87a 100644 (file)
@@ -12,8 +12,8 @@ fdmdv;               % load modem code
  
 % Simulation Parameters --------------------------------------
 
-frames = 100;
-EbNo_dB = 7.3;
+frames = 50*10;
+EbNo_dB = 10.3;
 Foff_hz = 0;
 modulation = 'dqpsk';
 hpa_clip = 150;
@@ -98,6 +98,10 @@ track_log = [];
 
 snr_log = [];
 
+Nspec=1024;
+spec_mem=zeros(1,Nspec);
+SdB = zeros(1,Nspec);
+
 % ---------------------------------------------------------------------
 % Main loop 
 % ---------------------------------------------------------------------
@@ -149,6 +153,14 @@ for f=1:frames
   rx_fdm += noise;
   rx_fdm_log = [rx_fdm_log rx_fdm];
 
+  % update spectrum
+
+  l=length(rx_fdm);
+  spec_mem(1:Nspec-l) = spec_mem(l+1:Nspec);
+  spec_mem(Nspec-l+1:Nspec) = rx_fdm;
+  S=fft(spec_mem.*hanning(Nspec)',Nspec);
+  SdB = 0.9*SdB + 0.1*20*log10(abs(S));
+
   % Delay
 
   rx_fdm_delay(1:Ndelay-M) = rx_fdm_delay(M+1:Ndelay);
@@ -190,7 +202,6 @@ for f=1:frames
 
   [rx_bits sync foff_fine pd] = qpsk_to_bits(prev_rx_symbols, rx_symbols, modulation);
   if strcmp(modulation,'dqpsk')
-    %rx_symbols_log = [rx_symbols_log rx_symbols.*conj(prev_rx_symbols)*exp(j*pi/4)];
     rx_symbols_log = [rx_symbols_log pd];
   else
     rx_symbols_log = [rx_symbols_log rx_symbols];
@@ -212,7 +223,8 @@ for f=1:frames
   % count bit errors if we find a test frame
   % Allow 15 frames for filter memories to fill and time est to settle
 
-  [test_frame_sync bit_errors] = put_test_bits(rx_bits);
+  [test_frame_sync bit_errors] = put_test_bits(test_bits, rx_bits);
+  
   if test_frame_sync == 1
     total_bit_errors = total_bit_errors + bit_errors;
     total_bits = total_bits + Ntest_bits;
@@ -295,13 +307,12 @@ title('Freq offset (Hz)');
 figure(3)
 clf;
 subplot(211)
-plot(real(tx_fdm_log));
-title('FDM Tx Signal');
+plot(real(rx_fdm_log));
+title('FDM Rx Signal');
 subplot(212)
-Nfft=Fs;
-S=fft(rx_fdm_log,Nfft);
-SdB=20*log10(abs(S));
-plot(SdB(1:Fs/4))
+plot((0:Nspec/2-1)*Fs/Nspec, SdB(1:Nspec/2) - 20*log10(Nspec/2))
+axis([0 Fs/2 -40 0])
+grid
 title('FDM Rx Spectrum');
 
 figure(4)
@@ -320,4 +331,11 @@ title('Test Frame Sync')
 
 figure(5)
 clf
+subplot(211)
 plot(snr_log)
+subplot(212)
+%plot(20*log10(sig_est(1:Nc))-20*log10(sig_est(Nc+1))+6)
+%axis([1 Nc -6 6]);
+sdB_pc = 20*log10(sig_est(1:Nc+1));
+bar(sdB_pc(1:Nc) - mean(sdB_pc(1:Nc)))
+axis([0 Nc+1 -3 3]);