BPSK sync bit implemented
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 27 Mar 2012 22:28:45 +0000 (22:28 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 27 Mar 2012 22:28:45 +0000 (22:28 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@355 01035d8c-6547-0410-b346-abe4f91aad63

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

index d9a2a442060970a8fc32263b3cc4212493c2b170..3df287d3367ea0b7027fc24e76d50335ea78ee61 100644 (file)
@@ -307,12 +307,12 @@ function foff = rx_est_freq_offset(rx_fdm, pilot)
   s = pilot_lpf(1:Mpilot:Npilotlpf) .* hanning(Npilotlpf/Mpilot)';
   S = abs(fft(s, Mpilotfft));
 
-  figure(3)
+  %figure(3)
   %plot(real(pilot_baseband))
-  plot(real(s))
-  figure(4)
+  %plot(real(s))
+  %figure(4)
   %plot(abs(fft(pilot_baseband)))
-  plot(S)
+  %plot(S)
 
   % peak pick and convert to Hz
 
@@ -402,7 +402,7 @@ endfunction
 
 % convert symbols back to an array of bits
 
-function rx_bits = qpsk_to_bits(prev_rx_symbols, rx_symbols, modulation)
+function [rx_bits sync_bit] = qpsk_to_bits(prev_rx_symbols, rx_symbols, modulation)
   global Nc;
   global Nb;
   global Nb;
@@ -411,7 +411,7 @@ function rx_bits = qpsk_to_bits(prev_rx_symbols, rx_symbols, modulation)
     % extra 45 degree clockwise lets us use real and imag axis as
     % decision boundaries
 
-    phase_difference = rx_symbols .* conj(prev_rx_symbols) * exp(j*pi/4);
+    phase_difference(1:Nc) = rx_symbols(1:Nc) .* conj(prev_rx_symbols(1:Nc)) * exp(j*pi/4);
   
     % map (Nc,1) DQPSK symbols back into an (1,Nc*Nb) array of bits
 
@@ -432,6 +432,15 @@ function rx_bits = qpsk_to_bits(prev_rx_symbols, rx_symbols, modulation)
       rx_bits(2*(c-1)+1) = msb;
       rx_bits(2*(c-1)+2) = lsb;
     end
+    % Extract DBPSK encoded Sync bit
+
+    phase_difference(Nc+1) = rx_symbols(Nc+1) .* conj(prev_rx_symbols(Nc+1));
+    if (real(phase_difference(Nc+1)) < 0)
+      sync_bit = 0;
+    else
+      sync_bit = 1;
+    end
 
   else
     % map (Nc,1) QPSK symbols back into an (1,Nc*Nb) array of bits
@@ -478,7 +487,7 @@ function [sync bit_errors] = put_test_bits(rx_bits)
 
   bit_errors = sum(xor(test_bits,rx_test_bits_mem));
 
-  % if less than a thresh we are aligned and in sync
+  % if less than a thresh we are aligned and in sync with test sequence
 
   ber = bit_errors/Ntest_bits;
   
index 7f0f421551c3d0049ffd14282b7946f946ba794b..670c18a9a235c350d0ed10b10831100ec01d52c5 100644 (file)
@@ -13,7 +13,7 @@ fdmdv;               % load modem code
  
 % Simulation Parameters --------------------------------------
 
-frames = 50;
+frames = 100;
 EbNo_dB = 7.3;
 Foff_hz = -100;
 modulation = 'dqpsk';
@@ -36,12 +36,16 @@ prev_tx_symbols(Nc+1) = 1;
 prev_rx_symbols = sqrt(2)*ones(Nc+1,1)*exp(j*pi/4);
 foff_log = [];
 tx_baseband_log = [];
+tx_fdm_log = [];
+sync_log = [];
 
 Ndelay = M+20;
 rx_fdm_delay = zeros(Ndelay,1);
 
+% ---------------------------------------------------------------------
 % Eb/No calculations.  We need to work out Eb/No for each FDM carrier.
 % Total power is sum of power in all FDM carriers
+% ---------------------------------------------------------------------
 
 C = 1; % power of each FDM carrier (energy/sample).  Total Carrier power should = Nc*C = Nc
 N = 1; % total noise power (energy/sample) of noise source across entire bandwidth
@@ -72,7 +76,9 @@ freq_offset = exp(j*2*pi*Foff_hz/Fs);
 foff_phase = 1;
 t = 0;
 
-% Main loop ----------------------------------------------------
+% ---------------------------------------------------------------------
+% Main loop 
+% ---------------------------------------------------------------------
 
 for i=1:frames
 
@@ -86,6 +92,7 @@ for i=1:frames
   tx_baseband = tx_filter(tx_symbols);
   tx_baseband_log = [tx_baseband_log tx_baseband];
   [tx_fdm pilot] = fdm_upconvert(tx_baseband);
+  tx_fdm_log = [tx_fdm_log tx_fdm];
   tx_pwr = 0.9*tx_pwr + 0.1*real(tx_fdm)*real(tx_fdm)'/(M);
 
   % -------------------
@@ -150,28 +157,39 @@ for i=1:frames
   else
     rx_symbols_log = [rx_symbols_log rx_symbols];
   endif
-  rx_bits = qpsk_to_bits(prev_rx_symbols, rx_symbols, modulation);
+  [rx_bits sync] = qpsk_to_bits(prev_rx_symbols, rx_symbols, modulation);
   prev_rx_symbols = rx_symbols;
+  sync_log = [sync_log sync];
 
-  % count bit errors
+  % count bit errors if we find a test frame
 
-  [sync bit_errors] = put_test_bits(rx_bits);
-  if (sync == 1)
+  [test_frame_sync bit_errors] = put_test_bits(rx_bits);
+  if (test_frame_sync == 1)
     total_bit_errors = total_bit_errors + bit_errors;
     total_bits = total_bits + Ntest_bits;
   end
 
 end
 
+% ---------------------------------------------------------------------
+% Print Stats
+% ---------------------------------------------------------------------
+
+peak = max(real(tx_fdm_log));
 ber = total_bit_errors/total_bits;
-printf("Eb/No (meas): %2.2f (%2.2f) dB  %d bits  %d errors  QPSK BER (meas): %1.4f (%1.4f)\n", 
+printf("Eb/No (meas): %2.2f (%2.2f) dB  %d bits  %d errors  BER: (%1.4f) Pk/rms: %1.2f\n", 
        EbNo_dB, 10*log10(0.25*tx_pwr*Fs/(Rs*Nc*noise_pwr)),
-       total_bits, total_bit_errors, 0.5*erfc(sqrt(10.^(EbNo_dB/10))), ber );
+       total_bits, total_bit_errors, ber, peak/std(real(tx_fdm_log)) );
+
+% ---------------------------------------------------------------------
+% Plots
+% ---------------------------------------------------------------------
 
 figure(1)
 clf;
 [n m] = size(rx_symbols_log);
 plot(real(rx_symbols_log(1:Nc,20:m)),imag(rx_symbols_log(1:Nc,20:m)),'+')
+title('Scatter Diagram');
 
 figure(2)
 clf;
@@ -182,14 +200,12 @@ subplot(212)
 plot(foff_log)
 title('Freq offset (Hz)');
 
-%figure(3)
-%clf;
-%Nfft=Fs;
-%S=fft(rx_fdm_log,Nfft);
-%SdB=20*log10(abs(S));
-%plot(-Fs/2+1:Fs/2,fftshift(SdB))
-%plot(SdB(1:Fs/4))
-
+figure(3)
+clf;
+subplot(211)
+plot(real(tx_fdm_log));
+subplot(212)
+stem(sync_log)
 
 
 % TODO