3
* Copyright 2006 Free Software Foundation, Inc.
5
* This file is part of GNU Radio
7
* GNU Radio is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 3, or (at your option)
12
* GNU Radio is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with GNU Radio; see the file COPYING. If not, write to
19
* the Free Software Foundation, Inc., 51 Franklin Street,
20
* Boston, MA 02110-1301, USA.
27
#include <gr_constellation_decoder_cb.h>
28
#include <gr_io_signature.h>
36
static const bool compute_EVM = false;
38
gr_constellation_decoder_cb_sptr
39
gr_make_constellation_decoder_cb (const std::vector<gr_complex> &sym_position,
40
const std::vector<unsigned char> &sym_value_out)
42
return gr_constellation_decoder_cb_sptr
43
(new gr_constellation_decoder_cb(sym_position, sym_value_out));
46
gr_constellation_decoder_cb::
47
gr_constellation_decoder_cb (const std::vector<gr_complex> &sym_position,
48
const std::vector<unsigned char> &sym_value_out)
49
: gr_sync_block ("constellation_decoder_cb",
50
gr_make_io_signature (1, 1, sizeof (gr_complex)),
51
gr_make_io_signature (1, 1, sizeof (unsigned char)))
53
if (!set_constellation(sym_position,sym_value_out))
54
throw std::invalid_argument("constellation_decoder_cb");
58
gr_constellation_decoder_cb::~gr_constellation_decoder_cb(){}
62
gr_constellation_decoder_cb::set_constellation(const std::vector<gr_complex> &sym_position,
63
const std::vector<unsigned char> &sym_value_out)
65
if (sym_position.size() != sym_value_out.size())
68
if (sym_position.size()<1)
71
d_sym_position = sym_position;
72
d_sym_value_out = sym_value_out;
78
gr_constellation_decoder_cb::work(int noutput_items,
79
gr_vector_const_void_star &input_items,
80
gr_vector_void_star &output_items)
82
gr_complex const *in = (const gr_complex *) input_items[0];
83
unsigned char *out = (unsigned char *) output_items[0];
84
unsigned int table_size = d_sym_value_out.size();
85
unsigned int min_index = 0;
86
float min_euclid_dist = 0;
87
float euclid_dist = 0;
88
double total_error = 0;
90
for(int i = 0; i < noutput_items; i++){
91
min_euclid_dist = norm(in[i] - d_sym_position[0]);
93
for (unsigned int j = 1; j < table_size; j++){
94
euclid_dist = norm(in[i] - d_sym_position[j]);
95
if (euclid_dist < min_euclid_dist){
96
min_euclid_dist = euclid_dist;
101
out[i] = d_sym_value_out[min_index];
104
total_error += sqrtf(min_euclid_dist);
108
double mean = total_error / noutput_items;
109
double rms = sqrt(mean * mean);
110
fprintf(stderr, "EVM = %8.4f\n", rms);
113
return noutput_items;