commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8144 - gnuradio/trunk/gnuradio-core/src/lib/general


From: trondeau
Subject: [Commit-gnuradio] r8144 - gnuradio/trunk/gnuradio-core/src/lib/general
Date: Mon, 31 Mar 2008 17:30:35 -0600 (MDT)

Author: trondeau
Date: 2008-03-31 17:30:32 -0600 (Mon, 31 Mar 2008)
New Revision: 8144

Modified:
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_acquisition.cc
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_sink.cc
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_sink.h
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.cc
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.h
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.cc
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.h
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.i
Log:
merging branch trondeau/ofdm r7971:8143. Fixing subcarriers and other issues to 
improve OFDM system operation. Not much more we can do with this than add 
channel coding and cleaning up.

Modified: 
gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_acquisition.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_acquisition.cc   
2008-03-31 22:42:14 UTC (rev 8143)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_acquisition.cc   
2008-03-31 23:30:32 UTC (rev 8144)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006, 2007 Free Software Foundation, Inc.
+ * Copyright 2006,2007,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -66,7 +66,7 @@
 
   std::fill(d_known_phase_diff.begin(), d_known_phase_diff.end(), 0);
   for(i = 0; i < d_known_symbol.size()-2; i+=2) {
-    d_known_phase_diff[i] = fabs(gr_fast_atan2f(d_known_symbol[i]) - 
gr_fast_atan2f(d_known_symbol[i+2]));
+    d_known_phase_diff[i] = norm(d_known_symbol[i] - d_known_symbol[i+2]);
   }
   
   d_phase_lut = new gr_complex[(2*d_freq_shift_len+1) * MAX_NUM_SYMBOLS];
@@ -108,7 +108,7 @@
   
   std::fill(d_symbol_phase_diff.begin(), d_symbol_phase_diff.end(), 0);
   for(i = 0; i < d_fft_length-2; i++) {
-    d_symbol_phase_diff[i] = fabs(gr_fast_atan2f(symbol[i]) - 
gr_fast_atan2f(symbol[i+2]));
+    d_symbol_phase_diff[i] = norm(symbol[i] - symbol[i+2]);
   }
 
   // sweep through all possible/allowed frequency offsets and select the best
@@ -119,7 +119,7 @@
     for(j = 0; j < d_occupied_carriers; j++) {
       sum += (d_known_phase_diff[j] * d_symbol_phase_diff[i+j]);
     }
-    if(fabs(sum) > max) {
+    if(sum > max) {
       max = sum;
       index = i;
     }

Modified: gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_sink.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_sink.cc  
2008-03-31 22:42:14 UTC (rev 8143)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_sink.cc  
2008-03-31 23:30:32 UTC (rev 8144)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -110,16 +110,19 @@
   carrier=gr_expj(d_phase);
 
   gr_complex accum_error = 0.0;
-  while(i < d_occupied_carriers) {
+  //while(i < d_occupied_carriers) {
+  while(i < d_subcarrier_map.size()) {
     if(d_nresid > 0) {
       d_partial_byte |= d_resid;
       d_byte_offset += d_nresid;
       d_nresid = 0;
       d_resid = 0;
     }
-
-    while((d_byte_offset < 8) && (i < d_occupied_carriers)) {
-      gr_complex sigrot = in[i]*carrier*d_dfe[i];
+    
+    //while((d_byte_offset < 8) && (i < d_occupied_carriers)) {
+    while((d_byte_offset < 8) && (i < d_subcarrier_map.size())) {
+      //gr_complex sigrot = in[i]*carrier*d_dfe[i];
+      gr_complex sigrot = in[d_subcarrier_map[i]]*carrier*d_dfe[i];
       
       if(d_derotated_output != NULL){
        d_derotated_output[i] = sigrot;
@@ -198,6 +201,59 @@
     d_resid(0), 
d_nresid(0),d_phase(0),d_freq(0),d_phase_gain(phase_gain),d_freq_gain(freq_gain),
     d_eq_gain(0.05)
 {
+  std::string carriers = "FE7F";
+
+  // A bit hacky to fill out carriers to occupied_carriers length
+  int diff = (d_occupied_carriers - 4*carriers.length()); 
+  while(diff > 7) {
+    carriers.insert(0, "f");
+    carriers.insert(carriers.length(), "f");
+    diff -= 8;
+  }
+  
+  // if there's extras left to be processed
+  // divide remaining to put on either side of current map
+  // all of this is done to stick with the concept of a carrier map string that
+  // can be later passed by the user, even though it'd be cleaner to just do 
this
+  // on the carrier map itself
+  int diff_left=0;
+  int diff_right=0;
+
+  // dictionary to convert from integers to ascii hex representation
+  char abc[16] = {'0', '1', '2', '3', '4', '5', '6', '7', 
+                 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+  if(diff > 0) {
+    char c[2] = {0,0};
+
+    diff_left = (int)ceil((float)diff/2.0f);  // number of carriers to put on 
the left side
+    c[0] = abc[((1 << diff_left) - 1)];       // convert to bits and move to 
ASCI integer
+    carriers.insert(0, c);
+    
+    diff_right = diff - diff_left;           // number of carriers to put on 
the right side
+    c[0] = abc[(0xF^(1 << diff_left) - 1)];   // convert to bits and move to 
ASCI integer
+    carriers.insert(carriers.length(), c);
+  }
+
+  // It seemed like such a good idea at the time...
+  // because we are only dealing with the occupied_carriers
+  // at this point, the diff_left in the following compensates
+  // for any offset from the 0th carrier introduced
+  unsigned int i,j,k;
+  for(i = 0; i < (d_occupied_carriers/4)+diff_left; i++) {
+    char c = carriers[i];
+    for(j = 0; j < 4; j++) {
+      k = (strtol(&c, NULL, 16) >> (3-j)) & 0x1;
+      if(k) {
+       d_subcarrier_map.push_back(4*i + j - diff_left);
+      }
+    }
+  }
+  
+  // make sure we stay in the limit currently imposed by the occupied_carriers
+  if(d_subcarrier_map.size() > d_occupied_carriers) {
+    throw std::invalid_argument("gr_ofdm_mapper_bcv: subcarriers allocated 
exceeds size of occupied carriers");
+  }
+
   d_bytes_out = new unsigned char[d_occupied_carriers];
   d_dfe.resize(occupied_carriers);
   fill(d_dfe.begin(), d_dfe.end(), gr_complex(1.0,0.0));

Modified: gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_sink.h
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_sink.h   
2008-03-31 22:42:14 UTC (rev 8143)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_frame_sink.h   
2008-03-31 23:30:32 UTC (rev 8144)
@@ -88,6 +88,8 @@
   float d_freq_gain;
   float d_eq_gain;
 
+  std::vector<int> d_subcarrier_map;
+
  protected:
   gr_ofdm_frame_sink(const std::vector<gr_complex> &sym_position, 
                     const std::vector<unsigned char> &sym_value_out,

Modified: gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.cc  
2008-03-31 22:42:14 UTC (rev 8143)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.cc  
2008-03-31 23:30:32 UTC (rev 8144)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2007 Free Software Foundation, Inc.
+ * Copyright 2006,2007,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -54,7 +54,64 @@
 {
   if (!(d_occupied_carriers <= d_fft_length))
     throw std::invalid_argument("gr_ofdm_mapper_bcv: occupied carriers must be 
<= fft_length");
+
+  // this is not the final form of this solution since we still use the 
occupied_tones concept,
+  // which would get us into trouble if the number of carriers we seek is 
greater than the occupied carriers.
+  // Eventually, we will get rid of the occupied_carriers concept.
+  std::string carriers = "FE7F";
+
+  // A bit hacky to fill out carriers to occupied_carriers length
+  int diff = (d_occupied_carriers - 4*carriers.length()); 
+  while(diff > 7) {
+    carriers.insert(0, "f");
+    carriers.insert(carriers.length(), "f");
+    diff -= 8;
+  }
+
+  // if there's extras left to be processed
+  // divide remaining to put on either side of current map
+  // all of this is done to stick with the concept of a carrier map string that
+  // can be later passed by the user, even though it'd be cleaner to just do 
this
+  // on the carrier map itself
+  int diff_left=0;
+  int diff_right=0;
+
+  // dictionary to convert from integers to ascii hex representation
+  char abc[16] = {'0', '1', '2', '3', '4', '5', '6', '7', 
+                 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+  if(diff > 0) {
+    char c[2] = {0,0};
+
+    diff_left = (int)ceil((float)diff/2.0f);   // number of carriers to put on 
the left side
+    c[0] = abc[((1 << diff_left) - 1)];        // convert to bits and move to 
ASCI integer
+    carriers.insert(0, c);
+    
+    diff_right = diff - diff_left;            // number of carriers to put on 
the right side
+    c[0] = abc[(0xF^(1 << diff_left) - 1)];    // convert to bits and move to 
ASCI integer
+        carriers.insert(carriers.length(), c);
+  }
   
+  // find out how many zeros to pad on the sides; the difference between the 
fft length and the subcarrier
+  // mapping size in chunks of four. This is the number to pack on the left 
and this number plus any 
+  // residual nulls (if odd) will be packed on the right. 
+  diff = (d_fft_length/4 - carriers.length())/2; 
+
+  unsigned int i,j,k;
+  for(i = 0; i < carriers.length(); i++) {
+    char c = carriers[i];                            // get the current hex 
character from the string
+    for(j = 0; j < 4; j++) {                         // walk through all four 
bits
+      k = (strtol(&c, NULL, 16) >> (3-j)) & 0x1;     // convert to int and 
extract next bit
+      if(k) {                                        // if bit is a 1, 
+       d_subcarrier_map.push_back(4*(i+diff) + j);  // use this subcarrier
+      }
+    }
+  }
+
+  // make sure we stay in the limit currently imposed by the occupied_carriers
+  if(d_subcarrier_map.size() > d_occupied_carriers) {
+    throw std::invalid_argument("gr_ofdm_mapper_bcv: subcarriers allocated 
exceeds size of occupied carriers");
+  }
+  
   d_nbits = (unsigned long)ceil(log10(d_constellation.size()) / log10(2.0));
 }
 
@@ -75,8 +132,6 @@
   gr_complex *out = (gr_complex *)output_items[0];
   
   unsigned int i=0;
-  unsigned int unoccupied_carriers = d_fft_length - d_occupied_carriers;
-  unsigned int zeros_on_left = (unsigned)ceil(unoccupied_carriers/2.0);
 
   //printf("OFDM BPSK Mapper:  ninput_items: %d   noutput_items: %d\n", 
ninput_items[0], noutput_items);
 
@@ -107,8 +162,9 @@
   
   i = 0;
   unsigned char bits = 0;
-  while((d_msg_offset < d_msg->length()) && (i < d_occupied_carriers)) {
-    
+  //while((d_msg_offset < d_msg->length()) && (i < d_occupied_carriers)) {
+  while((d_msg_offset < d_msg->length()) && (i < d_subcarrier_map.size())) {
+
     // need new data to process
     if(d_bit_offset == 0) {
       d_msgbytes = d_msg->msg()[d_msg_offset];
@@ -116,10 +172,11 @@
     }
 
     if(d_nresid > 0) {
+      // take the residual bits, fill out nbits with info from the new byte, 
and put them in the symbol
       d_resid |= (((1 << d_nresid)-1) & d_msgbytes) << (d_nbits - d_nresid);
       bits = d_resid;
 
-      out[i + zeros_on_left] = d_constellation[bits];
+      out[d_subcarrier_map[i]] = d_constellation[bits];
       i++;
 
       d_bit_offset += d_nresid;
@@ -129,20 +186,16 @@
       //     bits, d_resid, d_nresid, d_bit_offset);
     }
     else {
-      if((8 - d_bit_offset) >= d_nbits) {
+      if((8 - d_bit_offset) >= d_nbits) {  // test to make sure we can fit 
nbits
+       // take the nbits number of bits at a time from the byte to add to the 
symbol
        bits = ((1 << d_nbits)-1) & (d_msgbytes >> d_bit_offset);
        d_bit_offset += d_nbits;
        
-       out[i + zeros_on_left] = d_constellation[bits];
+       out[d_subcarrier_map[i]] = d_constellation[bits];
        i++;
-       
-       /*
-       printf("mod bit: %x  out: %.4f + j%.4f    resid: %x   nresid: %d    
bit_offset: %d\n", 
-              bits, out[i-1 + zeros_on_left].real(), out[i-1 + 
zeros_on_left].imag(), 
-              d_resid, d_nresid, d_bit_offset);
-       */
       }
-      else {
+      else {  // if we can't fit nbits, store them for the next 
+       // saves d_nresid bits of this message where d_nresid < d_nbits
        unsigned int extra = 8-d_bit_offset;
        d_resid = ((1 << extra)-1) & (d_msgbytes >> d_bit_offset);
        d_bit_offset += extra;
@@ -166,8 +219,10 @@
       d_resid = 0;
     }
 
-    while(i < d_occupied_carriers) {   // finish filling out the symbol
-      out[i + zeros_on_left] = d_constellation[randsym()];
+    //while(i < d_occupied_carriers) {   // finish filling out the symbol
+    while(i < d_subcarrier_map.size()) {   // finish filling out the symbol
+      out[d_subcarrier_map[i]] = d_constellation[randsym()];
+
       i++;
     }
 

Modified: gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.h
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.h   
2008-03-31 22:42:14 UTC (rev 8143)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_mapper_bcv.h   
2008-03-31 23:30:32 UTC (rev 8144)
@@ -69,6 +69,8 @@
   unsigned char d_resid;
   unsigned int d_nresid;
 
+  std::vector<int> d_subcarrier_map;
+
   int randsym();
 
  public:

Modified: gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.cc     
2008-03-31 22:42:14 UTC (rev 8143)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.cc     
2008-03-31 23:30:32 UTC (rev 8144)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -103,7 +103,6 @@
     
   case(STATE_FRAME):
     // use this state when we have processed a preamble and are getting the 
rest of the frames
-    //FIXME: add a timeout clause here to enter state STATE_NO_SIG after so 
many times here
     //FIXME: we could also have a power squelch system here to enter 
STATE_NO_SIG if no power is received
 
     // skip over fft length history and cyclic prefix
@@ -113,6 +112,7 @@
     }
 
     if(d_timeout-- == 0) {
+      printf("TIMEOUT\n");
       d_state = STATE_NO_SIG;
     }
 

Modified: gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.h
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.h      
2008-03-31 22:42:14 UTC (rev 8143)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.h      
2008-03-31 23:30:32 UTC (rev 8144)
@@ -30,7 +30,7 @@
 
 gr_ofdm_sampler_sptr gr_make_ofdm_sampler (unsigned int fft_length, 
                                           unsigned int symbol_length,
-                                          unsigned int timeout=100);
+                                          unsigned int timeout=1000);
 
 /*!
  * \brief does the rest of the OFDM stuff

Modified: gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.i
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.i      
2008-03-31 22:42:14 UTC (rev 8143)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_ofdm_sampler.i      
2008-03-31 23:30:32 UTC (rev 8144)
@@ -24,7 +24,7 @@
 
   gr_ofdm_sampler_sptr gr_make_ofdm_sampler (unsigned int fft_length, 
                                             unsigned int symbol_length,
-                                            unsigned int timeout=100);
+                                            unsigned int timeout=1000);
 
 class gr_ofdm_sampler : public gr_sync_block
 {





reply via email to

[Prev in Thread] Current Thread [Next in Thread]