From 33d9cf8800d3b4c0bbbff09b7588c21ed35e3220 Mon Sep 17 00:00:00 2001
From: Ben Reynwar <ben@reynwar.net>
Date: Sun, 30 Sep 2012 17:23:19 -0700
Subject: digital: Fixed scaling bug in QAM constellations.

---
 gr-digital/include/digital_constellation.h     |  3 +++
 gr-digital/lib/digital_constellation.cc        | 13 +++++++++++++
 gr-digital/python/qa_constellation.py          |  4 ++++
 gr-digital/python/qa_constellation_receiver.py |  2 +-
 4 files changed, 21 insertions(+), 1 deletion(-)

(limited to 'gr-digital')

diff --git a/gr-digital/include/digital_constellation.h b/gr-digital/include/digital_constellation.h
index a72bfb74c5..76cd30b25f 100644
--- a/gr-digital/include/digital_constellation.h
+++ b/gr-digital/include/digital_constellation.h
@@ -120,6 +120,9 @@ public:
   unsigned int d_rotational_symmetry;
   unsigned int d_dimensionality;
   unsigned int d_arity;
+  // The orignal constellation points were multiplied by this factor to get a
+  // constellation with average magnitude 1.
+  float d_scalefactor;
 
   float get_distance(unsigned int index, const gr_complex *sample);
   unsigned int get_closest_point(const gr_complex *sample);
diff --git a/gr-digital/lib/digital_constellation.cc b/gr-digital/lib/digital_constellation.cc
index d9a53c4930..da79f2caa4 100644
--- a/gr-digital/lib/digital_constellation.cc
+++ b/gr-digital/lib/digital_constellation.cc
@@ -49,6 +49,17 @@ digital_constellation::digital_constellation (std::vector<gr_complex> constellat
   d_rotational_symmetry(rotational_symmetry),
   d_dimensionality(dimensionality)
 {
+  // Scale constellation points so that average magnitude is 1.
+  float summed_mag = 0;
+  unsigned int constsize = d_constellation.size();
+  for (unsigned int i=0; i<constsize; i++) {
+    gr_complex c = d_constellation[i];
+    summed_mag += sqrt(c.real()*c.real() + c.imag()*c.imag());
+  }
+  d_scalefactor = constsize/summed_mag;
+  for (unsigned int i=0; i<constsize; i++) {
+    d_constellation[i] = d_constellation[i]*d_scalefactor;
+  }
   if (pre_diff_code.size() == 0)
     d_apply_pre_diff_code = false;
   else if (pre_diff_code.size() != constellation.size())
@@ -293,6 +304,8 @@ digital_constellation_rect::digital_constellation_rect (std::vector<gr_complex>
   n_real_sectors(real_sectors), n_imag_sectors(imag_sectors),
   d_width_real_sectors(width_real_sectors), d_width_imag_sectors(width_imag_sectors)
 {
+  d_width_real_sectors *= d_scalefactor;
+  d_width_imag_sectors *= d_scalefactor;
   find_sector_values();
 }
 
diff --git a/gr-digital/python/qa_constellation.py b/gr-digital/python/qa_constellation.py
index b17d2a0fcb..6962ec6338 100755
--- a/gr-digital/python/qa_constellation.py
+++ b/gr-digital/python/qa_constellation.py
@@ -69,6 +69,10 @@ tested_constellation_info = (
      {'m': (2, 4, 8, 16, 32, 64),
       'mod_code': tested_mod_codes, },
      True, None),
+    (qam.qam_constellation,
+     {'constellation_points': (4, 16, 64),
+      'mod_code': tested_mod_codes, },
+     True, None),
     (digital_swig.constellation_bpsk, {}, True, None),
     (digital_swig.constellation_qpsk, {}, False, None),
     (digital_swig.constellation_dqpsk, {}, True, None),
diff --git a/gr-digital/python/qa_constellation_receiver.py b/gr-digital/python/qa_constellation_receiver.py
index 2d25433b92..fe9c923c54 100755
--- a/gr-digital/python/qa_constellation_receiver.py
+++ b/gr-digital/python/qa_constellation_receiver.py
@@ -39,7 +39,7 @@ SEED = 1239
 # We need this many to let the frequency recovery block converge.
 DATA_LENGTH = 2000
 # Test fails if fraction of output that is correct is less than this.
-REQ_CORRECT = 0.7
+REQ_CORRECT = 0.9
 
 # CHANNEL PARAMETERS
 NOISE_VOLTAGE = 0.01
-- 
cgit v1.2.3


From a5f794128d8386ff0067cbe2928af4ded728d3b2 Mon Sep 17 00:00:00 2001
From: Ben Reynwar <ben@reynwar.net>
Date: Mon, 1 Oct 2012 21:45:43 -0700
Subject: digital: Increase acceptable BER in qa_constellation_receiver back to
 prior value.

---
 gr-digital/python/qa_constellation_receiver.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'gr-digital')

diff --git a/gr-digital/python/qa_constellation_receiver.py b/gr-digital/python/qa_constellation_receiver.py
index fe9c923c54..2d25433b92 100755
--- a/gr-digital/python/qa_constellation_receiver.py
+++ b/gr-digital/python/qa_constellation_receiver.py
@@ -39,7 +39,7 @@ SEED = 1239
 # We need this many to let the frequency recovery block converge.
 DATA_LENGTH = 2000
 # Test fails if fraction of output that is correct is less than this.
-REQ_CORRECT = 0.9
+REQ_CORRECT = 0.7
 
 # CHANNEL PARAMETERS
 NOISE_VOLTAGE = 0.01
-- 
cgit v1.2.3