summaryrefslogtreecommitdiff
path: root/gnuradio-core
diff options
context:
space:
mode:
authorBen Reynwar2011-01-31 22:30:15 -0700
committerBen Reynwar2011-01-31 22:30:15 -0700
commitf2196f9ca883114d2c39beb59489387a43b8bff7 (patch)
tree74acdaa203af78cc1a69c53cff7a2c3870f7cd7c /gnuradio-core
parent8f81162fbd94c708e71caf2f402588db4d1d82c6 (diff)
downloadgnuradio-f2196f9ca883114d2c39beb59489387a43b8bff7.tar.gz
gnuradio-f2196f9ca883114d2c39beb59489387a43b8bff7.tar.bz2
gnuradio-f2196f9ca883114d2c39beb59489387a43b8bff7.zip
Added BPSK constellation object.
Diffstat (limited to 'gnuradio-core')
-rw-r--r--gnuradio-core/src/lib/general/gr_constellation.cc21
-rw-r--r--gnuradio-core/src/lib/general/gr_constellation.h43
-rw-r--r--gnuradio-core/src/lib/general/gr_constellation.i23
-rw-r--r--gnuradio-core/src/python/gnuradio/blks2impl/Makefile.am1
-rw-r--r--gnuradio-core/src/python/gnuradio/blks2impl/bpsk.py98
5 files changed, 171 insertions, 15 deletions
diff --git a/gnuradio-core/src/lib/general/gr_constellation.cc b/gnuradio-core/src/lib/general/gr_constellation.cc
index 8b98a5731..477532e5c 100644
--- a/gnuradio-core/src/lib/general/gr_constellation.cc
+++ b/gnuradio-core/src/lib/general/gr_constellation.cc
@@ -43,6 +43,10 @@ gr_constellation::gr_constellation (std::vector<gr_complex> constellation) :
{
}
+gr_constellation::gr_constellation ()
+{
+}
+
unsigned int get_closest_point(std::vector<gr_complex> constellation, gr_complex sample) {
unsigned int table_size = constellation.size();
@@ -169,3 +173,20 @@ unsigned int gr_constellation_psk::calc_sector_value (unsigned int sector) {
}
+gr_constellation_bpsk_sptr
+gr_make_constellation_bpsk()
+{
+ return gr_constellation_bpsk_sptr(new gr_constellation_bpsk ());
+}
+
+gr_constellation_bpsk::gr_constellation_bpsk ()
+{
+ d_constellation.resize(2);
+ d_constellation[0] = gr_complex(-1, 0);
+ d_constellation[1] = gr_complex(1, 0);
+}
+
+unsigned int gr_constellation_bpsk::decision_maker(gr_complex sample)
+{
+ return (real(sample) > 0);
+}
diff --git a/gnuradio-core/src/lib/general/gr_constellation.h b/gnuradio-core/src/lib/general/gr_constellation.h
index d7f7b09b4..fcc947ca6 100644
--- a/gnuradio-core/src/lib/general/gr_constellation.h
+++ b/gnuradio-core/src/lib/general/gr_constellation.h
@@ -42,12 +42,12 @@ gr_constellation_sptr
gr_make_constellation (std::vector<gr_complex> constellation);
class gr_constellation : public boost::enable_shared_from_this<gr_constellation>
-//class gr_constellation
{
public:
gr_constellation (std::vector<gr_complex> constellation);
-
+ gr_constellation ();
+
//! Returns the set of points in this constellation.
std::vector<gr_complex> points() { return d_constellation;}
@@ -60,7 +60,6 @@ class gr_constellation : public boost::enable_shared_from_this<gr_constellation>
}
gr_constellation_sptr base() {
- //return gr_constellation_sptr(this);
return shared_from_this();
}
@@ -91,7 +90,7 @@ class gr_constellation_sector : public gr_constellation
unsigned int decision_maker (gr_complex sample);
- // protected:
+ protected:
virtual unsigned int get_sector (gr_complex sample) = 0;
@@ -101,7 +100,7 @@ class gr_constellation_sector : public gr_constellation
unsigned int n_sectors;
- // private:
+ private:
std::vector<unsigned int> sector_values;
@@ -133,13 +132,13 @@ class gr_constellation_rect : public gr_constellation_sector
gr_constellation_rect (std::vector<gr_complex> constellation, unsigned int real_sectors, unsigned int imag_sectors,
float width_real_sectors, float width_imag_sectors);
- // protected:
+ protected:
unsigned int get_sector (gr_complex sample);
unsigned int calc_sector_value (unsigned int sector);
- // private:
+ private:
unsigned int n_real_sectors;
unsigned int n_imag_sectors;
@@ -175,17 +174,43 @@ class gr_constellation_psk : public gr_constellation_sector
gr_constellation_psk (std::vector<gr_complex> constellation, unsigned int n_sectors);
- // protected:
+ protected:
unsigned int get_sector (gr_complex sample);
unsigned int calc_sector_value (unsigned int sector);
- // private:
+ private:
friend gr_constellation_psk_sptr
gr_make_constellation_psk (std::vector<gr_complex> constellation, unsigned int n_sectors);
};
+/************************************************************/
+/* gr_constellation_bpsk */
+/* */
+/* Only works for BPSK. */
+/* */
+/************************************************************/
+
+class gr_constellation_bpsk;
+typedef boost::shared_ptr<gr_constellation_bpsk> gr_constellation_bpsk_sptr;
+
+// public constructor
+gr_constellation_bpsk_sptr
+gr_make_constellation_bpsk ();
+
+class gr_constellation_bpsk : public gr_constellation
+{
+ public:
+
+ gr_constellation_bpsk ();
+ unsigned int decision_maker (gr_complex sample);
+
+ friend gr_constellation_bpsk_sptr
+ gr_make_constellation_bpsk ();
+
+};
+
#endif
diff --git a/gnuradio-core/src/lib/general/gr_constellation.i b/gnuradio-core/src/lib/general/gr_constellation.i
index 2d15b8b1e..a34aade9f 100644
--- a/gnuradio-core/src/lib/general/gr_constellation.i
+++ b/gnuradio-core/src/lib/general/gr_constellation.i
@@ -77,12 +77,23 @@ public:
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;
+typedef boost::shared_ptr<gr_constellation_bpsk> gr_constellation_bpsk_sptr;
+%template(gr_constellation_bpsk_sptr) boost::shared_ptr<gr_constellation_bpsk>;
+%rename(constellation_bpsk) gr_make_constellation_bpsk;
+gr_constellation_bpsk_sptr gr_make_constellation_bpsk();
+%ignore gr_constellation_bpsk;
- unsigned int get_sector (gr_complex sample);
- unsigned int calc_sector_value (unsigned int sector);
- void find_sector_values ();
- unsigned int n_sectors;
- std::vector<unsigned int> sector_values;
+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 ();
};
+
diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/Makefile.am b/gnuradio-core/src/python/gnuradio/blks2impl/Makefile.am
index f7e92442f..2a7f59176 100644
--- a/gnuradio-core/src/python/gnuradio/blks2impl/Makefile.am
+++ b/gnuradio-core/src/python/gnuradio/blks2impl/Makefile.am
@@ -29,6 +29,7 @@ grblkspythondir = $(grpythondir)/blks2impl
grblkspython_PYTHON = \
__init__.py \
am_demod.py \
+ bpsk.py \
channel_model.py \
dbpsk.py \
dbpsk2.py \
diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/bpsk.py b/gnuradio-core/src/python/gnuradio/blks2impl/bpsk.py
new file mode 100644
index 000000000..222178abb
--- /dev/null
+++ b/gnuradio-core/src/python/gnuradio/blks2impl/bpsk.py
@@ -0,0 +1,98 @@
+#
+# Copyright 2005,2006 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+"""
+BPSK modulation and demodulation.
+"""
+
+from math import pi, log
+from cmath import exp
+
+from gnuradio import gr, modulation_utils2
+from gnuradio.blks2impl.generic_mod_demod import generic_mod, generic_demod
+
+# Default number of points in constellation.
+_def_constellation_points = 2
+# Whether differential coding is used.
+_def_differential = True
+
+# /////////////////////////////////////////////////////////////////////////////
+# BPSK constellation
+# /////////////////////////////////////////////////////////////////////////////
+
+def bpsk_constellation(m=_def_constellation_points):
+ if m != _def_constellation_points:
+ raise ValueError("BPSK can only have 2 constellation points.")
+ return gr.constellation_bpsk()
+
+# /////////////////////////////////////////////////////////////////////////////
+# BPSK modulator
+# /////////////////////////////////////////////////////////////////////////////
+
+class bpsk_mod(generic_mod):
+
+ def __init__(self, constellation_points=_def_constellation_points,
+ *args, **kwargs):
+
+ """
+ Hierarchical block for RRC-filtered BPSK modulation.
+
+ The input is a byte stream (unsigned char) and the
+ output is the complex modulated signal at baseband.
+
+ See generic_mod block for list of parameters.
+ """
+
+ constellation = gr.constellation_bpsk()
+ if constellation_points != 2:
+ raise ValueError('Number of constellation points must be 2 for BPSK.')
+ super(bpsk_mod, self).__init__(constellation, *args, **kwargs)
+
+# /////////////////////////////////////////////////////////////////////////////
+# BPSK demodulator
+#
+# /////////////////////////////////////////////////////////////////////////////
+
+class bpsk_demod(generic_demod):
+
+ def __init__(self, constellation_points=_def_constellation_points,
+ *args, **kwargs):
+
+ """
+ Hierarchical block for RRC-filtered BPSK modulation.
+
+ The input is a byte stream (unsigned char) and the
+ output is the complex modulated signal at baseband.
+
+ See generic_demod block for list of parameters.
+ """
+
+ constellation = gr.constellation_bpsk()
+ if constellation_points != 2:
+ raise ValueError('Number of constellation points must be 2 for BPSK.')
+ super(bpsk_demod, self).__init__(constellation, *args, **kwargs)
+
+#
+# Add these to the mod/demod registry
+#
+modulation_utils2.add_type_1_mod('bpsk', bpsk_mod)
+modulation_utils2.add_type_1_demod('bpsk', bpsk_demod)
+modulation_utils2.add_type_1_constellation('bpsk', bpsk_constellation)