diff options
author | Ben Reynwar <ben@reynwar.net> | 2011-02-09 14:19:40 -0700 |
---|---|---|
committer | Ben Reynwar <ben@reynwar.net> | 2011-02-09 14:19:40 -0700 |
commit | e4df34e785651787930b2b2fcd4c9fbdeac5d8fc (patch) | |
tree | 1a363fd74dbb184e2d78d6d278d7c4a27195b808 /gnuradio-core/src/lib | |
parent | 765c9f6e947d6dd765d1f33f3d4668f0c69486ee (diff) |
Changed constellation objects so that codings besides gray code can be used.
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/general/gr_constellation.cc | 36 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_constellation.h | 33 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_constellation.i | 43 |
3 files changed, 68 insertions, 44 deletions
diff --git a/gnuradio-core/src/lib/general/gr_constellation.cc b/gnuradio-core/src/lib/general/gr_constellation.cc index 8f56246680..e3b4c14e74 100644 --- a/gnuradio-core/src/lib/general/gr_constellation.cc +++ b/gnuradio-core/src/lib/general/gr_constellation.cc @@ -35,19 +35,27 @@ #define SQRT_TWO 0.707107 gr_constellation_sptr -gr_make_constellation(std::vector<gr_complex> constellation) +gr_make_constellation(std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code) { - return gr_constellation_sptr(new gr_constellation (constellation)); + return gr_constellation_sptr(new gr_constellation (constellation, pre_diff_code)); } // Base Constellation Class -gr_constellation::gr_constellation (std::vector<gr_complex> constellation) : - d_constellation(constellation) +gr_constellation::gr_constellation (std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code) : + d_constellation(constellation), + d_pre_diff_code(pre_diff_code) { + if (pre_diff_code.size() == 0) + d_apply_pre_diff_code = false; + else if (pre_diff_code.size() != constellation.size()) + throw std::runtime_error ("The constellation and pre-diff code must be of the same length."); + else + d_apply_pre_diff_code = true; } -gr_constellation::gr_constellation () +gr_constellation::gr_constellation () : + d_apply_pre_diff_code(false) { } @@ -119,8 +127,9 @@ void gr_constellation::calc_hard_symbol_metric(gr_complex sample, float *metric) } gr_constellation_sector::gr_constellation_sector (std::vector<gr_complex> constellation, + std::vector<unsigned int> pre_diff_code, unsigned int n_sectors) : - gr_constellation(constellation), + gr_constellation(constellation, pre_diff_code), n_sectors(n_sectors) { } @@ -141,16 +150,18 @@ void gr_constellation_sector::find_sector_values () { gr_constellation_rect_sptr gr_make_constellation_rect(std::vector<gr_complex> constellation, + std::vector<unsigned int> pre_diff_code, unsigned int real_sectors, unsigned int imag_sectors, float width_real_sectors, float width_imag_sectors) { - return gr_constellation_rect_sptr(new gr_constellation_rect (constellation, real_sectors, imag_sectors, width_real_sectors, width_imag_sectors)); + return gr_constellation_rect_sptr(new gr_constellation_rect (constellation, pre_diff_code, real_sectors, imag_sectors, width_real_sectors, width_imag_sectors)); } gr_constellation_rect::gr_constellation_rect (std::vector<gr_complex> constellation, + std::vector<unsigned int> pre_diff_code, unsigned int real_sectors, unsigned int imag_sectors, float width_real_sectors, float width_imag_sectors) : - gr_constellation_sector(constellation, real_sectors * imag_sectors), + gr_constellation_sector(constellation, pre_diff_code, real_sectors * imag_sectors), n_real_sectors(real_sectors), n_imag_sectors(imag_sectors), d_width_real_sectors(width_real_sectors), d_width_imag_sectors(width_imag_sectors) { @@ -184,14 +195,17 @@ unsigned int gr_constellation_rect::calc_sector_value (unsigned int sector) { gr_constellation_psk_sptr -gr_make_constellation_psk(std::vector<gr_complex> constellation, unsigned int n_sectors) +gr_make_constellation_psk(std::vector<gr_complex> constellation, + std::vector<unsigned int> pre_diff_code, + unsigned int n_sectors) { - return gr_constellation_psk_sptr(new gr_constellation_psk (constellation, n_sectors)); + return gr_constellation_psk_sptr(new gr_constellation_psk (constellation, pre_diff_code, n_sectors)); } gr_constellation_psk::gr_constellation_psk (std::vector<gr_complex> constellation, + std::vector<unsigned int> pre_diff_code, unsigned int n_sectors) : - gr_constellation_sector(constellation, n_sectors) + gr_constellation_sector(constellation, pre_diff_code, n_sectors) { find_sector_values(); } diff --git a/gnuradio-core/src/lib/general/gr_constellation.h b/gnuradio-core/src/lib/general/gr_constellation.h index 6908f43f19..440e32e571 100644 --- a/gnuradio-core/src/lib/general/gr_constellation.h +++ b/gnuradio-core/src/lib/general/gr_constellation.h @@ -40,17 +40,21 @@ typedef boost::shared_ptr<gr_constellation> gr_constellation_sptr; // public constructor gr_constellation_sptr - gr_make_constellation (std::vector<gr_complex> constellation); +gr_make_constellation (std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code); class gr_constellation : public boost::enable_shared_from_this<gr_constellation> { public: - gr_constellation (std::vector<gr_complex> constellation); + gr_constellation (std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code); gr_constellation (); //! Returns the set of points in this constellation. std::vector<gr_complex> points() { return d_constellation;} + //! Whether to apply an encoding before doing differential encoding. (e.g. gray coding) + bool apply_pre_diff_code() { return d_apply_pre_diff_code;} + //! Returns the encoding to apply before differential encoding. + std::vector<unsigned int> pre_diff_code() { return d_pre_diff_code;} //! Returns the constellation point that matches best. //! Also calculates the phase error. @@ -77,6 +81,8 @@ class gr_constellation : public boost::enable_shared_from_this<gr_constellation> protected: std::vector<gr_complex> d_constellation; + std::vector<unsigned int> d_pre_diff_code; + bool d_apply_pre_diff_code; private: friend gr_constellation_sptr @@ -97,6 +103,7 @@ class gr_constellation_sector : public gr_constellation public: gr_constellation_sector (std::vector<gr_complex> constellation, + std::vector<unsigned int> pre_diff_code, unsigned int n_sectors); unsigned int decision_maker (gr_complex sample); @@ -133,15 +140,17 @@ typedef boost::shared_ptr<gr_constellation_rect> gr_constellation_rect_sptr; // public constructor gr_constellation_rect_sptr -gr_make_constellation_rect (std::vector<gr_complex> constellation, unsigned int real_sectors, unsigned int imag_sectors, +gr_make_constellation_rect (std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code, + unsigned int real_sectors, unsigned int imag_sectors, float width_real_sectors, float width_imag_sectors); class gr_constellation_rect : public gr_constellation_sector { public: - gr_constellation_rect (std::vector<gr_complex> constellation, unsigned int real_sectors, unsigned int imag_sectors, - float width_real_sectors, float width_imag_sectors); + gr_constellation_rect (std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code, + unsigned int real_sectors, unsigned int imag_sectors, + float width_real_sectors, float width_imag_sectors); protected: @@ -157,8 +166,9 @@ class gr_constellation_rect : public gr_constellation_sector float d_width_imag_sectors; friend gr_constellation_rect_sptr - gr_make_constellation_rect (std::vector<gr_complex> constellation, unsigned int real_sectors, unsigned int imag_sectors, - float width_real_sectors, float width_imag_sectors); + gr_make_constellation_rect (std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code, + unsigned int real_sectors, unsigned int imag_sectors, + float width_real_sectors, float width_imag_sectors); }; @@ -177,13 +187,15 @@ typedef boost::shared_ptr<gr_constellation_psk> gr_constellation_psk_sptr; // public constructor gr_constellation_psk_sptr -gr_make_constellation_psk (std::vector<gr_complex> constellation, unsigned int n_sectors); +gr_make_constellation_psk (std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code, + unsigned int n_sectors); class gr_constellation_psk : public gr_constellation_sector { public: - gr_constellation_psk (std::vector<gr_complex> constellation, unsigned int n_sectors); + gr_constellation_psk (std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code, + unsigned int n_sectors); protected: @@ -194,7 +206,8 @@ class gr_constellation_psk : public gr_constellation_sector private: friend gr_constellation_psk_sptr - gr_make_constellation_psk (std::vector<gr_complex> constellation, unsigned int n_sectors); + gr_make_constellation_psk (std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code, + unsigned int n_sectors); }; diff --git a/gnuradio-core/src/lib/general/gr_constellation.i b/gnuradio-core/src/lib/general/gr_constellation.i index d00c62f908..762289c57c 100644 --- a/gnuradio-core/src/lib/general/gr_constellation.i +++ b/gnuradio-core/src/lib/general/gr_constellation.i @@ -30,17 +30,26 @@ class gr_constellation; typedef boost::shared_ptr<gr_constellation> gr_constellation_sptr; %template(gr_constellation_sptr) boost::shared_ptr<gr_constellation>; %rename(constellation) gr_make_constellation; -gr_constellation_sptr gr_make_constellation(std::vector<gr_complex> constellation); +gr_constellation_sptr gr_make_constellation(std::vector<gr_complex> constellation, + std::vector<unsigned int> pre_diff_code); %ignore gr_constellation; class gr_constellation { public: - gr_constellation (std::vector<gr_complex> constellation); + gr_constellation (std::vector<gr_complex> constellation, + std::vector<unsigned int> pre_diff_code); std::vector<gr_complex> points(); unsigned int decision_maker (gr_complex sample); unsigned int bits_per_symbol (); + unsigned int arity (); gr_constellation_sptr base (); + bool apply_pre_diff_code(); + std::vector<unsigned int> pre_diff_code(); +}; + +class gr_constellation_sector: public gr_constellation +{ }; class gr_constellation_rect; @@ -48,20 +57,18 @@ typedef boost::shared_ptr<gr_constellation_rect> gr_constellation_rect_sptr; %template(gr_constellation_rect_sptr) boost::shared_ptr<gr_constellation_rect>; %rename(constellation_rect) gr_make_constellation_rect; gr_constellation_rect_sptr gr_make_constellation_rect(std::vector<gr_complex> constellation, - unsigned int real_sectors, unsigned int imag_sectors, - float width_real_sectors, float width_imag_sectors); + std::vector<unsigned int> pre_diff_code, + unsigned int real_sectors, unsigned int imag_sectors, + float width_real_sectors, float width_imag_sectors); %ignore gr_constellation_rect; class gr_constellation_rect : public gr_constellation_sector { public: gr_constellation_rect (std::vector<gr_complex> constellation, - unsigned int real_sectors, unsigned int imag_sectors, - float width_real_sectors, float width_imag_sectors); - std::vector<gr_complex> points (); - unsigned int decision_maker (gr_complex sample); - unsigned int bits_per_symbol (); - gr_constellation_sptr base (); + std::vector<unsigned int> pre_diff_code, + unsigned int real_sectors, unsigned int imag_sectors, + float width_real_sectors, float width_imag_sectors); }; class gr_constellation_psk; @@ -69,18 +76,16 @@ typedef boost::shared_ptr<gr_constellation_psk> gr_constellation_psk_sptr; %template(gr_constellation_psk_sptr) boost::shared_ptr<gr_constellation_psk>; %rename(constellation_psk) gr_make_constellation_psk; gr_constellation_psk_sptr gr_make_constellation_psk(std::vector<gr_complex> constellation, + std::vector<unsigned int> pre_diff_code, unsigned int n_sectors); %ignore gr_constellation_psk; class gr_constellation_psk : public gr_constellation_sector { public: - gr_constellation_psk (std::vector<gr_complex> constellation, + gr_constellation_psk (std::vector<gr_complex> constellation, + std::vector<unsigned int> pre_diff_code, unsigned int n_sectors); - std::vector<gr_complex> points (); - unsigned int decision_maker (gr_complex sample); - unsigned int bits_per_symbol (); - gr_constellation_sptr base (); }; class gr_constellation_bpsk; @@ -94,10 +99,6 @@ class gr_constellation_bpsk : public gr_constellation { public: gr_constellation_bpsk (); - std::vector<gr_complex> points(); - unsigned int decision_maker (gr_complex sample); - unsigned int bits_per_symbol (); - gr_constellation_sptr base (); }; class gr_constellation_qpsk; @@ -111,9 +112,5 @@ class gr_constellation_qpsk : public gr_constellation { public: gr_constellation_qpsk (); - std::vector<gr_complex> points(); - unsigned int decision_maker (gr_complex sample); - unsigned int bits_per_symbol (); - gr_constellation_sptr base (); }; |