summaryrefslogtreecommitdiff
path: root/gr-digital/lib/digital_constellation.cc
diff options
context:
space:
mode:
authorTom Rondeau2011-04-08 21:44:52 -0400
committerTom Rondeau2011-04-08 21:44:52 -0400
commitc6d7be41abc63a9e5b52a12ef05d578f09797054 (patch)
tree17e23a520b33d3be3265d7089bd877195833f696 /gr-digital/lib/digital_constellation.cc
parent78078fe0015fe87b15777b94858f5110e65244c5 (diff)
downloadgnuradio-c6d7be41abc63a9e5b52a12ef05d578f09797054.tar.gz
gnuradio-c6d7be41abc63a9e5b52a12ef05d578f09797054.tar.bz2
gnuradio-c6d7be41abc63a9e5b52a12ef05d578f09797054.zip
gr-digital: updating build for consetellation object move.
Diffstat (limited to 'gr-digital/lib/digital_constellation.cc')
-rw-r--r--gr-digital/lib/digital_constellation.cc104
1 files changed, 53 insertions, 51 deletions
diff --git a/gr-digital/lib/digital_constellation.cc b/gr-digital/lib/digital_constellation.cc
index eede99ffd..804a65ac8 100644
--- a/gr-digital/lib/digital_constellation.cc
+++ b/gr-digital/lib/digital_constellation.cc
@@ -21,7 +21,7 @@
*/
#include <gr_io_signature.h>
-#include <gr_constellation.h>
+#include <digital_constellation.h>
#include <gr_metric_type.h>
#include <gr_math.h>
#include <gr_complex.h>
@@ -36,8 +36,10 @@
// Base Constellation Class
-gr_constellation::gr_constellation (std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code,
- unsigned int rotational_symmetry, unsigned int dimensionality) :
+digital_constellation::digital_constellation (std::vector<gr_complex> constellation,
+ std::vector<unsigned int> pre_diff_code,
+ unsigned int rotational_symmetry,
+ unsigned int dimensionality) :
d_constellation(constellation),
d_pre_diff_code(pre_diff_code),
d_rotational_symmetry(rotational_symmetry),
@@ -52,7 +54,7 @@ gr_constellation::gr_constellation (std::vector<gr_complex> constellation, std::
calc_arity();
}
-gr_constellation::gr_constellation () :
+digital_constellation::digital_constellation () :
d_apply_pre_diff_code(false),
d_rotational_symmetry(0),
d_dimensionality(1)
@@ -61,19 +63,19 @@ gr_constellation::gr_constellation () :
}
//! Returns the constellation points for a symbol value
-void gr_constellation::map_to_points(unsigned int value, gr_complex *points) {
+void digital_constellation::map_to_points(unsigned int value, gr_complex *points) {
for (unsigned int i=0; i<d_dimensionality; i++)
points[i] = d_constellation[value*d_dimensionality + i];
}
-std::vector<gr_complex> gr_constellation::map_to_points_v(unsigned int value) {
+std::vector<gr_complex> digital_constellation::map_to_points_v(unsigned int value) {
std::vector<gr_complex> points_v;
points_v.resize(d_dimensionality);
map_to_points(value, &(points_v[0]));
return points_v;
}
-float gr_constellation::get_distance(unsigned int index, const gr_complex *sample) {
+float digital_constellation::get_distance(unsigned int index, const gr_complex *sample) {
float dist = 0;
for (unsigned int i=0; i<d_dimensionality; i++) {
dist += norm(sample[i] - d_constellation[index*d_dimensionality + i]);
@@ -81,7 +83,7 @@ float gr_constellation::get_distance(unsigned int index, const gr_complex *sampl
return dist;
}
-unsigned int gr_constellation::get_closest_point(const gr_complex *sample) {
+unsigned int digital_constellation::get_closest_point(const gr_complex *sample) {
unsigned int min_index = 0;
float min_euclid_dist;
@@ -99,7 +101,7 @@ unsigned int gr_constellation::get_closest_point(const gr_complex *sample) {
return min_index;
}
-unsigned int gr_constellation::decision_maker_pe(const gr_complex *sample, float *phase_error)
+unsigned int digital_constellation::decision_maker_pe(const gr_complex *sample, float *phase_error)
{
unsigned int index = decision_maker(sample);
*phase_error = 0;
@@ -109,7 +111,7 @@ unsigned int gr_constellation::decision_maker_pe(const gr_complex *sample, float
}
/*
-unsigned int gr_constellation::decision_maker_e(const gr_complex *sample, float *error)
+unsigned int digital_constellation::decision_maker_e(const gr_complex *sample, float *error)
{
unsigned int index = decision_maker(sample);
*error = 0;
@@ -119,14 +121,14 @@ unsigned int gr_constellation::decision_maker_e(const gr_complex *sample, float
}
*/
-std::vector<gr_complex> gr_constellation::s_points () {
+std::vector<gr_complex> digital_constellation::s_points () {
if (d_dimensionality != 1)
throw std::runtime_error ("s_points only works for dimensionality 1 constellations.");
else
return d_constellation;
}
-std::vector<std::vector<gr_complex> > gr_constellation::v_points () {
+std::vector<std::vector<gr_complex> > digital_constellation::v_points () {
std::vector<std::vector<gr_complex> > vv_const;
vv_const.resize(d_arity);
for (unsigned int p=0; p<d_arity; p++) {
@@ -140,7 +142,7 @@ std::vector<std::vector<gr_complex> > gr_constellation::v_points () {
return vv_const;
}
-void gr_constellation::calc_metric(const gr_complex *sample, float *metric, trellis_metric_type_t type) {
+void digital_constellation::calc_metric(const gr_complex *sample, float *metric, trellis_metric_type_t type) {
switch (type){
case TRELLIS_EUCLIDEAN:
calc_euclidean_metric(sample, metric);
@@ -156,13 +158,13 @@ void gr_constellation::calc_metric(const gr_complex *sample, float *metric, trel
}
}
-void gr_constellation::calc_euclidean_metric(const gr_complex *sample, float *metric) {
+void digital_constellation::calc_euclidean_metric(const gr_complex *sample, float *metric) {
for (unsigned int o=0; o<d_arity; o++) {
metric[o] = get_distance(o, sample);
}
}
-void gr_constellation::calc_hard_symbol_metric(const gr_complex *sample, float *metric){
+void digital_constellation::calc_hard_symbol_metric(const gr_complex *sample, float *metric){
float minm = FLT_MAX;
unsigned int minmi = 0;
for (unsigned int o=0; o<d_arity; o++) {
@@ -177,56 +179,56 @@ void gr_constellation::calc_hard_symbol_metric(const gr_complex *sample, float *
}
}
-void gr_constellation::calc_arity () {
+void digital_constellation::calc_arity () {
if (d_constellation.size() % d_dimensionality != 0)
throw std::runtime_error ("Constellation vector size must be a multiple of the dimensionality.");
d_arity = d_constellation.size()/d_dimensionality;
}
-unsigned int gr_constellation::decision_maker_v (std::vector<gr_complex> sample) {
+unsigned int digital_constellation::decision_maker_v (std::vector<gr_complex> sample) {
assert(sample.size() == d_dimensionality);
return decision_maker (&(sample[0]));
}
-gr_constellation_calcdist_sptr
-gr_make_constellation_calcdist(std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code,
+digital_constellation_calcdist_sptr
+digital_make_constellation_calcdist(std::vector<gr_complex> constellation, std::vector<unsigned int> pre_diff_code,
unsigned int rotational_symmetry, unsigned int dimensionality)
{
- return gr_constellation_calcdist_sptr(new gr_constellation_calcdist (constellation, pre_diff_code, rotational_symmetry,
+ return digital_constellation_calcdist_sptr(new digital_constellation_calcdist (constellation, pre_diff_code, rotational_symmetry,
dimensionality));
}
-gr_constellation_calcdist::gr_constellation_calcdist(std::vector<gr_complex> constellation,
+digital_constellation_calcdist::digital_constellation_calcdist(std::vector<gr_complex> constellation,
std::vector<unsigned int> pre_diff_code,
unsigned int rotational_symmetry,
unsigned int dimensionality) :
- gr_constellation(constellation, pre_diff_code, rotational_symmetry, dimensionality)
+ digital_constellation(constellation, pre_diff_code, rotational_symmetry, dimensionality)
{}
// Chooses points base on shortest distance.
// Inefficient.
-unsigned int gr_constellation_calcdist::decision_maker(const gr_complex *sample)
+unsigned int digital_constellation_calcdist::decision_maker(const gr_complex *sample)
{
return get_closest_point(sample);
}
-gr_constellation_sector::gr_constellation_sector (std::vector<gr_complex> constellation,
+digital_constellation_sector::digital_constellation_sector (std::vector<gr_complex> constellation,
std::vector<unsigned int> pre_diff_code,
unsigned int rotational_symmetry,
unsigned int dimensionality,
unsigned int n_sectors) :
- gr_constellation(constellation, pre_diff_code, rotational_symmetry, dimensionality),
+ digital_constellation(constellation, pre_diff_code, rotational_symmetry, dimensionality),
n_sectors(n_sectors)
{
}
-unsigned int gr_constellation_sector::decision_maker (const gr_complex *sample) {
+unsigned int digital_constellation_sector::decision_maker (const gr_complex *sample) {
unsigned int sector;
sector = get_sector(sample);
return sector_values[sector];
}
-void gr_constellation_sector::find_sector_values () {
+void digital_constellation_sector::find_sector_values () {
unsigned int i;
sector_values.clear();
for (i=0; i<n_sectors; i++) {
@@ -234,31 +236,31 @@ void gr_constellation_sector::find_sector_values () {
}
}
-gr_constellation_rect_sptr
-gr_make_constellation_rect(std::vector<gr_complex> constellation,
+digital_constellation_rect_sptr
+digital_make_constellation_rect(std::vector<gr_complex> constellation,
std::vector<unsigned int> pre_diff_code,
unsigned int rotational_symmetry,
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, pre_diff_code, rotational_symmetry,
+ return digital_constellation_rect_sptr(new digital_constellation_rect (constellation, pre_diff_code, rotational_symmetry,
real_sectors, imag_sectors, width_real_sectors,
width_imag_sectors));
}
-gr_constellation_rect::gr_constellation_rect (std::vector<gr_complex> constellation,
+digital_constellation_rect::digital_constellation_rect (std::vector<gr_complex> constellation,
std::vector<unsigned int> pre_diff_code,
unsigned int rotational_symmetry,
unsigned int real_sectors, unsigned int imag_sectors,
float width_real_sectors, float width_imag_sectors) :
- gr_constellation_sector(constellation, pre_diff_code, rotational_symmetry, 1, real_sectors * imag_sectors),
+ digital_constellation_sector(constellation, pre_diff_code, rotational_symmetry, 1, 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)
{
find_sector_values();
}
-unsigned int gr_constellation_rect::get_sector (const gr_complex *sample) {
+unsigned int digital_constellation_rect::get_sector (const gr_complex *sample) {
int real_sector, imag_sector;
unsigned int sector;
real_sector = int(real(*sample)/d_width_real_sectors + n_real_sectors/2.0);
@@ -271,7 +273,7 @@ unsigned int gr_constellation_rect::get_sector (const gr_complex *sample) {
return sector;
}
-unsigned int gr_constellation_rect::calc_sector_value (unsigned int sector) {
+unsigned int digital_constellation_rect::calc_sector_value (unsigned int sector) {
unsigned int real_sector, imag_sector;
gr_complex sector_center;
unsigned int closest_point;
@@ -284,24 +286,24 @@ unsigned int gr_constellation_rect::calc_sector_value (unsigned int sector) {
}
-gr_constellation_psk_sptr
-gr_make_constellation_psk(std::vector<gr_complex> constellation,
+digital_constellation_psk_sptr
+digital_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, pre_diff_code,
+ return digital_constellation_psk_sptr(new digital_constellation_psk (constellation, pre_diff_code,
n_sectors));
}
-gr_constellation_psk::gr_constellation_psk (std::vector<gr_complex> constellation,
+digital_constellation_psk::digital_constellation_psk (std::vector<gr_complex> constellation,
std::vector<unsigned int> pre_diff_code,
unsigned int n_sectors) :
- gr_constellation_sector(constellation, pre_diff_code, constellation.size(), 1, n_sectors)
+ digital_constellation_sector(constellation, pre_diff_code, constellation.size(), 1, n_sectors)
{
find_sector_values();
}
-unsigned int gr_constellation_psk::get_sector (const gr_complex *sample) {
+unsigned int digital_constellation_psk::get_sector (const gr_complex *sample) {
float phase = arg(*sample);
float width = M_TWOPI / n_sectors;
int sector = floor(phase/width + 0.5);
@@ -311,7 +313,7 @@ unsigned int gr_constellation_psk::get_sector (const gr_complex *sample) {
return sector;
}
-unsigned int gr_constellation_psk::calc_sector_value (unsigned int sector) {
+unsigned int digital_constellation_psk::calc_sector_value (unsigned int sector) {
float phase = sector * M_TWOPI / n_sectors;
gr_complex sector_center = gr_complex(cos(phase), sin(phase));
unsigned int closest_point = get_closest_point(&sector_center);
@@ -319,13 +321,13 @@ unsigned int gr_constellation_psk::calc_sector_value (unsigned int sector) {
}
-gr_constellation_bpsk_sptr
-gr_make_constellation_bpsk()
+digital_constellation_bpsk_sptr
+digital_make_constellation_bpsk()
{
- return gr_constellation_bpsk_sptr(new gr_constellation_bpsk ());
+ return digital_constellation_bpsk_sptr(new digital_constellation_bpsk ());
}
-gr_constellation_bpsk::gr_constellation_bpsk ()
+digital_constellation_bpsk::digital_constellation_bpsk ()
{
d_constellation.resize(2);
d_constellation[0] = gr_complex(-1, 0);
@@ -335,19 +337,19 @@ gr_constellation_bpsk::gr_constellation_bpsk ()
calc_arity();
}
-unsigned int gr_constellation_bpsk::decision_maker(const gr_complex *sample)
+unsigned int digital_constellation_bpsk::decision_maker(const gr_complex *sample)
{
return (real(*sample) > 0);
}
-gr_constellation_qpsk_sptr
-gr_make_constellation_qpsk()
+digital_constellation_qpsk_sptr
+digital_make_constellation_qpsk()
{
- return gr_constellation_qpsk_sptr(new gr_constellation_qpsk ());
+ return digital_constellation_qpsk_sptr(new digital_constellation_qpsk ());
}
-gr_constellation_qpsk::gr_constellation_qpsk ()
+digital_constellation_qpsk::digital_constellation_qpsk ()
{
d_constellation.resize(4);
// Gray-coded
@@ -360,7 +362,7 @@ gr_constellation_qpsk::gr_constellation_qpsk ()
calc_arity();
}
-unsigned int gr_constellation_qpsk::decision_maker(const gr_complex *sample)
+unsigned int digital_constellation_qpsk::decision_maker(const gr_complex *sample)
{
// Real component determines small bit.
// Imag component determines big bit.