tx filtering and up conversion working in Octave
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 17 Mar 2015 04:17:49 +0000 (04:17 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 17 Mar 2015 04:17:49 +0000 (04:17 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2079 01035d8c-6547-0410-b346-abe4f91aad63

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

index 415a6d7d6930dc82575b47e46b82e8a04044772c..c0ad4540f8a9834be2def3d62d9afe1c56ec775e 100644 (file)
@@ -8,7 +8,7 @@
 % Version 2
 %
 
-% reqd to mak sure we get same random bits at mod and demod
+% reqd to make sure we get same random bits at mod and demod
 
 rand('state',1); 
 randn('state',1);
@@ -165,21 +165,21 @@ function tx_symbols = bits_to_psk(prev_tx_symbols, tx_bits)
 endfunction
 
 
-% Given Nc*Nb bits construct M samples (1 symbol) of Nc filtered
+% Given Nc symbols construct M samples (1 symbol) of Nc filtered
 % symbols streams
 
-function tx_baseband = tx_filter(tx_symbols)
-  global Nc;
-  global M;
-  global tx_filter_memory;
-  global Nfilter;
-  global gt_alpha5_root;
+function [tx_baseband fdmdv] = tx_filter(fdmdv, tx_symbols)
+  Nc = fdmdv.Nc;
+  M = fdmdv.M;
+  tx_filter_memory = fdmdv.tx_filter_memory;
+  Nfilter = fdmdv.Nfilter;
+  gt_alpha5_root = fdmdv.gt_alpha5_root;
 
   tx_baseband = zeros(Nc+1,M);
 
   % tx filter each symbol, generate M filtered output samples for each symbol.
   % Efficient polyphase filter techniques used as tx_filter_memory is sparse
-
+  
   tx_filter_memory(:,Nfilter) = sqrt(2)/2*tx_symbols;
 
   for i=1:M
@@ -188,6 +188,7 @@ function tx_baseband = tx_filter(tx_symbols)
   tx_filter_memory(:,1:Nfilter-M) = tx_filter_memory(:,M+1:Nfilter);
   tx_filter_memory(:,Nfilter-M+1:Nfilter) = zeros(Nc+1,M);
 
+  fdmdv.tx_filter_memory = tx_filter_memory;
 endfunction
 
 
@@ -195,19 +196,19 @@ endfunction
 % stream.  Returns complex signal so we can apply frequency offsets
 % easily.
 
-function tx_fdm = fdm_upconvert(tx_filt)
-  global Fs;
-  global M;
-  global Nc;
-  global Fsep;
-  global phase_tx;
-  global freq;
-  global fbb_rect;
-  global fbb_phase_tx;
+function [tx_fdm fdmdv] = fdm_upconvert(fdmdv, tx_filt)
+  Fs = fdmdv.Fs;
+  M = fdmdv.M;
+  Nc = fdmdv.Nc;
+  Fsep = fdmdv.Fsep;
+  phase_tx = fdmdv.phase_tx;
+  freq = fdmdv.freq;
+  fbb_rect = fdmdv.fbb_rect;
+  fbb_phase_tx = fdmdv.fbb_phase_tx;
 
   tx_fdm = zeros(1,M);
 
-  % Nc/2 tones below zero
+  % Nc+1 tones
   
   for c=1:Nc+1
       for i=1:M
@@ -239,6 +240,8 @@ function tx_fdm = fdm_upconvert(tx_filt)
   mag = abs(fbb_phase_tx);
   fbb_phase_tx /= mag;
 
+  fdmdv.fbb_phase_tx = fbb_phase_tx;
+  fdmdv.phase_tx = phase_tx;
 endfunction
 
 
index 9e9e9d45e6cd78a19ad383a21e556fb2a848b757..b5e6e0607513686c9c82de66fbe23a3891421790 100644 (file)
 %     [ ] feedback to correct out freq offset est
 %     [ ] fading channel
 
-rand('state',1); 
-randn('state',1);
 graphics_toolkit ("gnuplot");
 
 cohpsk;
+fdmdv;
 autotest;
 
+rand('state',1); 
+randn('state',1);
+
 n = 2000;
 frames = 35;
 framesize = 160;
@@ -35,7 +37,7 @@ sim_in = standard_init();
 sim_in.framesize        = 160;
 sim_in.ldpc_code        = 0;
 sim_in.ldpc_code_rate   = 1;
-sim_in.Nc               = 4;
+sim_in.Nc = Nc          = 4;
 sim_in.Rs               = 50;
 sim_in.Ns               = 4;
 sim_in.Np               = 2;
@@ -57,6 +59,8 @@ rx_symb_log = [];
 rx_bits_log = [];
 noise_log = [];
 nerr_log = [];
+tx_baseband_log = [];
+tx_fdm_log = [];
 
 phase = 1;
 freq = exp(j*2*pi*foff/sim_in.Rs);
@@ -65,6 +69,20 @@ ch_symb = zeros(sim_in.Nsymbrowpilot, sim_in.Nc);
 
 Nerrs = Tbits = 0;
 
+fdmdv.Fs = 8000;
+fdmdv.Nc = Nc-1;
+fdmdv.M = Fs/Rs;
+fdmdv.tx_filter_memory = zeros(fdmdv.Nc+1, Nfilter);
+fdmdv.Nfilter =  Nfilter;
+fdmdv.gt_alpha5_root = gt_alpha5_root;
+fdmdv.Fsep = 75;
+fdmdv.phase_tx = exp(j*2*pi*(0:Nc)/(Nc+1));
+freq_hz = Fsep*( -Nc/2 - 0.5 + (1:Nc) );
+fdmdv.freq = exp(j*2*pi*freq_hz/Fs);
+Fcentre = 1500;
+fdmdv.fbb_rect = exp(j*2*pi*Fcentre/Fs);
+fdmdv.fbb_phase_tx = 1;
+
 for i=1:frames
   tx_bits = tx_bits_coh(ptx_bits_coh:ptx_bits_coh+framesize-1);
   ptx_bits_coh += framesize;
@@ -77,6 +95,13 @@ for i=1:frames
   [tx_symb tx_bits prev_tx_sym] = bits_to_qpsk_symbols(sim_in, tx_bits, [], []);
   tx_symb_log = [tx_symb_log; tx_symb];
 
+  for r=1:sim_in.Nsymbrowpilot
+    [tx_baseband fdmdv] = tx_filter(fdmdv, rot90(tx_symb(r,:),1));
+    tx_baseband_log = [tx_baseband_log tx_baseband];
+    [tx_fdm fdmdv] = fdm_upconvert(fdmdv, tx_baseband);
+    tx_fdm_log = [tx_fdm_log tx_fdm];
+  end
+
   noise = sqrt(variance*0.5)*(randn(sim_in.Nsymbrowpilot,sim_in.Nc) + j*randn(sim_in.Nsymbrowpilot,sim_in.Nc));
   noise_log = [noise_log; noise];