This file is indexed.

/usr/include/gnuradio/digital/constellation.h is in gnuradio-dev 3.7.10.1-2+b3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
/* -*- c++ -*- */
/*
 * Copyright 2010-2012 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.
 */

#ifndef INCLUDED_DIGITAL_CONSTELLATION_H
#define	INCLUDED_DIGITAL_CONSTELLATION_H

#include <gnuradio/digital/api.h>
#include <gnuradio/digital/metric_type.h>
#include <boost/enable_shared_from_this.hpp>
#include <boost/any.hpp>
#include <gnuradio/gr_complex.h>
#include <pmt/pmt.h>
#include <vector>

namespace gr {
  namespace digital {

    /************************************************************/
    /* constellation                                            */
    /*                                                          */
    /* Base class defining interface.                           */
    /************************************************************/

    class constellation;
    typedef boost::shared_ptr<constellation> constellation_sptr;

    /*!
     * \brief An abstracted constellation object
     * \ingroup symbol_coding_blk
     *
     * \details
     * The constellation objects hold the necessary information to pass
     * around constellation information for modulators and
     * demodulators. These objects contain the mapping between the bits
     * and the constellation points used to represent them as well as
     * methods for slicing the symbol space. Various implementations are
     * possible for efficiency and ease of use.
     *
     * Standard constellations (BPSK, QPSK, QAM, etc) can be inherited
     * from this class and overloaded to perform optimized slicing and
     * constellation mappings.
     */
    class DIGITAL_API constellation
      : public boost::enable_shared_from_this<constellation>
    {
    public:
      constellation(std::vector<gr_complex> constell,
		    std::vector<int> pre_diff_code,
		    unsigned int rotational_symmetry,
		    unsigned int dimensionality);
      constellation();
      virtual ~constellation();

      //! Returns the constellation points for a symbol value
      void map_to_points(unsigned int value, gr_complex *points);
      std::vector<gr_complex> map_to_points_v(unsigned int value);

      //! Returns the constellation point that matches best.
      virtual unsigned int decision_maker(const gr_complex *sample) = 0;
      //! Takes a vector rather than a pointer.  Better for SWIG wrapping.
      unsigned int decision_maker_v(std::vector<gr_complex> sample);
      //! Also calculates the phase error.
      unsigned int decision_maker_pe(const gr_complex *sample, float *phase_error);
      //! Calculates distance.
      //unsigned int decision_maker_e(const gr_complex *sample, float *error);

      //! Calculates metrics for all points in the constellation.
      //! For use with the viterbi algorithm.
      virtual void calc_metric(const gr_complex *sample, float *metric, gr::digital::trellis_metric_type_t type);
      virtual void calc_euclidean_metric(const gr_complex *sample, float *metric);
      virtual void calc_hard_symbol_metric(const gr_complex *sample, float *metric);

      //! Returns the set of points in this constellation.
      std::vector<gr_complex> points() { return d_constellation;}
      //! Returns the vector of points in this constellation.
      //! Raise error if dimensionality is not one.
      std::vector<gr_complex> s_points();
      //! Returns a vector of vectors of points.
      std::vector<std::vector<gr_complex> > v_points();
      //! Whether to apply an encoding before doing differential encoding. (e.g. gray coding)
      bool apply_pre_diff_code() { return d_apply_pre_diff_code;}
      //! Whether to apply an encoding before doing differential encoding. (e.g. gray coding)
      void set_pre_diff_code(bool a) { d_apply_pre_diff_code = a;}
      //! Returns the encoding to apply before differential encoding.
      std::vector<int> pre_diff_code() { return d_pre_diff_code;}
      //! Returns the order of rotational symmetry.
      unsigned int rotational_symmetry() { return d_rotational_symmetry;}
      //! Returns the number of complex numbers in a single symbol.
      unsigned int dimensionality() {return d_dimensionality;}

      unsigned int bits_per_symbol()
      {
        return floor(log(double(d_constellation.size()))/d_dimensionality/log(2.0));
      }

      unsigned int arity()
      {
        return d_arity;
      }

      constellation_sptr base()
      {
        return shared_from_this();
      }

      pmt::pmt_t as_pmt()
      {
        return pmt::make_any(boost::any(base()));
      }

      /*! \brief Generates the soft decision LUT based on
       *         constellation and symbol map.
       *
       * \details Generates the soft decision LUT based on
       * constellation and symbol map.  It can be given a estimate of
       * the noise power in the channel as \p npwr.
       *
       * \param precision Number of bits of precision on each axis.
       * \param npwr Estimate of the noise power (if known).
       *
       * This is expensive to compute.
       */
      void gen_soft_dec_lut(int precision, float npwr=1.0);

      /*! \brief Calculate soft decisions for the given \p sample.
       *
       * \details Calculate the soft decisions from the given \p sample
       * at the given noise power \p npwr.
       *
       * This is a very costly algorithm (especially for higher order
       * modulations) and should be used sparingly. It uses the
       * #gen_soft_dec_lut function to generate the LUT, which
       * should be done once or if a large change in the noise floor
       * is detected.
       *
       * Instead of using this function, generate the LUT using the
       * #gen_soft_dec_lut after creating the constellation object
       * and then use the #soft_decision_maker function to return the
       * answer from the LUT.
       *
       * \param sample The complex sample to get the soft decisions.
       * \param npwr Estimate of the noise power (if known).
       */
      virtual std::vector<float> calc_soft_dec(gr_complex sample, float npwr=1.0);

      /*! \brief Define a soft decision look-up table.
       *
       * \details Define a soft decision look-up table (LUT). Because
       * soft decisions can be calculated in various ways with various
       * levels of accuracy and complexity, this function allows
       * users to create a LUT in their own way.
       *
       * Setting the LUT here means that #has_soft_dec_lut will return
       * true. Decision vectors returned by #soft_decision_maker will
       * be calculated using this LUT.
       *
       * \param soft_dec_lut The soft decision LUT as a vector of
       *        tuples (vectors in C++) of soft decisions. Each
       *        element of the LUT is a vector of k-bit floats (where
       *        there are k bits/sample in the constellation).
       * \param precision The number of bits of precision used when
       *        generating the LUT.
       */
      void set_soft_dec_lut(const std::vector< std::vector<float> > &soft_dec_lut,
                            int precision);

      //! Returns True if the soft decision LUT has been defined, False otherwise.
      bool has_soft_dec_lut();


      std::vector< std::vector<float> > soft_dec_lut();



      /*! \brief Returns the soft decisions for the given \p sample.
       *
       * \details Returns the soft decisions for the given \p
       * sample. If a LUT is defined for the object, the decisions
       * will be calculated from there. Otherwise, this function will
       * call calc_soft_dec directly to calculate the soft decisions.
       *
       * \param sample The complex sample to get the soft decisions.
       */
      std::vector<float> soft_decision_maker(gr_complex sample);


    protected:
      std::vector<gr_complex> d_constellation;
      std::vector<int> d_pre_diff_code;
      bool d_apply_pre_diff_code;
      unsigned int d_rotational_symmetry;
      unsigned int d_dimensionality;
      unsigned int d_arity;
      //! The factor by which the user given constellation points were
      //! scaled by to achieve an average amplitude of 1.
      float d_scalefactor;
      float d_re_min, d_re_max, d_im_min, d_im_max;

      std::vector< std::vector<float> > d_soft_dec_lut;
      int d_lut_precision;
      float d_lut_scale;

      float get_distance(unsigned int index, const gr_complex *sample);
      unsigned int get_closest_point(const gr_complex *sample);
      void calc_arity();

      void max_min_axes();
    };

    /************************************************************/
    /* constellation_calcdist                                   */
    /*                                                          */
    /************************************************************/

    /*! \brief Calculate Euclidian distance for any constellation
     *  \ingroup digital
     *
     * \details
     * Constellation which calculates the distance to each point in the
     * constellation for decision making. Inefficient for large
     * constellations.
     */
    class DIGITAL_API constellation_calcdist
      : public constellation
    {
    public:
      typedef boost::shared_ptr<constellation_calcdist> sptr;

      /*!
       * Make a general constellation object that calculates the Euclidean distance for hard decisions.
       *
       * \param constell List of constellation points (order of list matches pre_diff_code)
       * \param pre_diff_code List of alphabet symbols (before applying any differential
       *                      coding) (order of list matches constell)
       * \param rotational_symmetry Number of rotations around unit circle that have the same representation.
       * \param dimensionality Number of dimensions to the constellation.
       */
      static sptr make(std::vector<gr_complex> constell,
		       std::vector<int> pre_diff_code,
		       unsigned int rotational_symmetry,
		       unsigned int dimensionality);

      unsigned int decision_maker(const gr_complex *sample);
      // void calc_metric(gr_complex *sample, float *metric, trellis_metric_type_t type);
      // void calc_euclidean_metric(gr_complex *sample, float *metric);
      // void calc_hard_symbol_metric(gr_complex *sample, float *metric);

    protected:
      constellation_calcdist(std::vector<gr_complex> constell,
			     std::vector<int> pre_diff_code,
			     unsigned int rotational_symmetry,
			     unsigned int dimensionality);
    };


    /************************************************************/
    /*! constellation_sector                                    */
    /************************************************************/

    /*!
     * \brief Sectorized digital constellation
     * \ingroup digital
     *
     * \details
     * Constellation space is divided into sectors. Each sector is
     * associated with the nearest constellation point.
     */
    class DIGITAL_API constellation_sector : public constellation
    {
    public:

      /*!
       * Make a sectorized constellation object.
       *
       * \param constell List of constellation points (order of list matches pre_diff_code)
       * \param pre_diff_code List of alphabet symbols (before applying any differential
       *                      coding) (order of list matches constell)
       * \param rotational_symmetry Number of rotations around unit circle that have the same representation.
       * \param dimensionality Number of z-axis dimensions to the constellation
       * \param n_sectors Number of sectors in the constellation.
       */
      constellation_sector(std::vector<gr_complex> constell,
			   std::vector<int> pre_diff_code,
			   unsigned int rotational_symmetry,
			   unsigned int dimensionality,
			   unsigned int n_sectors);

      ~constellation_sector();

      unsigned int decision_maker(const gr_complex *sample);

    protected:
      virtual unsigned int get_sector(const gr_complex *sample) = 0;
      virtual unsigned int calc_sector_value(unsigned int sector) = 0;
      void find_sector_values();

      unsigned int n_sectors;

    private:
      std::vector<int> sector_values;
    };

    /************************************************************/
    /* constellation_rect                                       */
    /************************************************************/

    /*!
     * \brief Rectangular digital constellation
     * \ingroup digital
     *
     * Only implemented for 1-(complex)dimensional constellation.
     *
     * Constellation space is divided into rectangular sectors. Each
     * sector is associated with the nearest constellation point.
     *
     * Works well for square QAM.
     *
     * Works for any generic constellation provided sectors are not
     * too large.
     */
    class DIGITAL_API constellation_rect
      : public constellation_sector
    {
    public:
      typedef boost::shared_ptr<constellation_rect> sptr;

      /*!
       * Make a rectangular constellation object.
       *
       * \param constell List of constellation points (order of list matches pre_diff_code)
       * \param pre_diff_code List of alphabet symbols (before applying any differential
       *                      coding) (order of list matches constell)
       * \param rotational_symmetry Number of rotations around unit circle that have the same representation.
       * \param real_sectors Number of sectors the real axis is split in to.
       * \param imag_sectors Number of sectors the imag axis is split in to.
       * \param width_real_sectors width of each real sector to calculate decision boundaries.
       * \param width_imag_sectors width of each imag sector to calculate decision boundaries.
       */
      static constellation_rect::sptr make(std::vector<gr_complex> constell,
					   std::vector<int> pre_diff_code,
					   unsigned int rotational_symmetry,
					   unsigned int real_sectors,
					   unsigned int imag_sectors,
					   float width_real_sectors,
					   float width_imag_sectors);
      ~constellation_rect();

    protected:

      constellation_rect(std::vector<gr_complex> constell,
			 std::vector<int> pre_diff_code,
			 unsigned int rotational_symmetry,
			 unsigned int real_sectors,
			 unsigned int imag_sectors,
			 float width_real_sectors,
			 float width_imag_sectors);

      unsigned int get_sector(const gr_complex *sample);
      gr_complex calc_sector_center(unsigned int sector);
      unsigned int calc_sector_value(unsigned int sector);

    private:
      unsigned int n_real_sectors;
      unsigned int n_imag_sectors;
      float d_width_real_sectors;
      float d_width_imag_sectors;
    };


    /************************************************************/
    /* constellation_expl_rect                                  */
    /************************************************************/

    /*!
     * \brief Rectangular digital constellation.
     * \ingroup digital
     *
     * \details
     * Only implemented for 1-(complex)dimensional constellation.
     *
     * Constellation space is divided into rectangular sectors. Each
     * sector is associated with the nearest constellation point.
     *
     * This class is different from constellation_rect in that the
     * mapping from sector to constellation point is explicitly passed
     * into the constructor as sector_values.  Usually we do not need
     * this, since we want each sector to be automatically mapped to
     * the closest constellation point, however sometimes it's nice to
     * have the flexibility.
     */
    class DIGITAL_API constellation_expl_rect
      : public constellation_rect
    {
    public:
      typedef boost::shared_ptr<constellation_expl_rect> sptr;

      static sptr make(std::vector<gr_complex> constellation,
                       std::vector<int> pre_diff_code,
                       unsigned int rotational_symmetry,
                       unsigned int real_sectors,
                       unsigned int imag_sectors,
                       float width_real_sectors,
                       float width_imag_sectors,
                       std::vector<unsigned int> sector_values);
      ~constellation_expl_rect();

    protected:
      constellation_expl_rect(std::vector<gr_complex> constellation,
                              std::vector<int> pre_diff_code,
                              unsigned int rotational_symmetry,
                              unsigned int real_sectors,
                              unsigned int imag_sectors,
                              float width_real_sectors,
                              float width_imag_sectors,
                              std::vector<unsigned int> sector_values);

      unsigned int calc_sector_value (unsigned int sector) {
        return d_sector_values[sector];
      }

    private:
      std::vector<unsigned int> d_sector_values;
    };

    /************************************************************/
    /* constellation_psk                                        */
    /************************************************************/

    /*!
     * \brief constellation_psk
     * \ingroup digital
     *
     * Constellation space is divided into pie slices sectors.
     *
     * Each slice is associated with the nearest constellation point.
     *
     * Works well for PSK but nothing else.
     *
     * Assumes that there is a constellation point at 1.x
     */
    class DIGITAL_API constellation_psk : public constellation_sector
    {
    public:
      typedef boost::shared_ptr<constellation_psk> sptr;

      // public constructor
      static sptr make(std::vector<gr_complex> constell,
		       std::vector<int> pre_diff_code,
		       unsigned int n_sectors);

      ~constellation_psk();

    protected:
      unsigned int get_sector(const gr_complex *sample);

      unsigned int calc_sector_value(unsigned int sector);

      constellation_psk(std::vector<gr_complex> constell,
			std::vector<int> pre_diff_code,
			unsigned int n_sectors);
    };


    /************************************************************/
    /* constellation_bpsk                                       */
    /*                                                          */
    /* Only works for BPSK.                                     */
    /*                                                          */
    /************************************************************/

    /*!
     * \brief Digital constellation for BPSK .
     * \ingroup digital
     *
     * \details
     * \verbatim
       0 | 1
       \endverbatim
     */
    class DIGITAL_API constellation_bpsk : public constellation
    {
    public:
      typedef boost::shared_ptr<constellation_bpsk> sptr;

      // public constructor
      static sptr make();

      ~constellation_bpsk();

      unsigned int decision_maker(const gr_complex *sample);

    protected:
      constellation_bpsk();
    };


    /************************************************************/
    /* constellation_qpsk                                       */
    /*                                                          */
    /* Only works for QPSK.                                     */
    /*                                                          */
    /************************************************************/

    /*!
     * \brief Digital constellation for QPSK
     * \ingroup digital
     *
     * \details
     * \verbatim
       01 | 11
       -------
       00 | 10
       \endverbatim
     */
    class DIGITAL_API constellation_qpsk : public constellation
    {
    public:
      typedef boost::shared_ptr<constellation_qpsk> sptr;

      // public constructor
      static sptr make();

      ~constellation_qpsk();

      unsigned int decision_maker(const gr_complex *sample);

    protected:
      constellation_qpsk();
    };


    /************************************************************/
    /* constellation_dqpsk                                      */
    /*                                                          */
    /* Works with differential encoding; slower decisions.      */
    /*                                                          */
    /************************************************************/

    /*!
     * \brief Digital constellation for DQPSK.
     * \ingroup digital
     *
     * \details
     * \verbatim
       01 | 00
       -------
       11 | 10
       \endverbatim
     */
    class DIGITAL_API constellation_dqpsk : public constellation
    {
    public:
      typedef boost::shared_ptr<constellation_dqpsk> sptr;

      // public constructor
      static sptr make();

      ~constellation_dqpsk();

      unsigned int decision_maker(const gr_complex *sample);

    protected:
      constellation_dqpsk();
    };


    /************************************************************/
    /* constellation_8psk                                       */
    /*                                                          */
    /* Only works for 8PSK.                                     */
    /*                                                          */
    /************************************************************/

    /*!
     * \brief Digital constellation for 8PSK.
     * \ingroup digital
     *
     * \details
     * \verbatim
           101 | 100
       001     |     000
       -----------------
       011     |     010
           111 | 110
       \endverbatim
     */
    class DIGITAL_API constellation_8psk : public constellation
    {
    public:
      typedef boost::shared_ptr<constellation_8psk> sptr;

      // public constructor
      static sptr make();

      ~constellation_8psk();

      unsigned int decision_maker(const gr_complex *sample);

    protected:
      constellation_8psk();
    };

    /************************************************************/
    /* constellation_8psk_natural                                       */
    /*                                                          */
    /* Only works for natural 8psk                                     */
    /*                                                          */
    /************************************************************/

    /*! 
     * \brief Digital constellation for natually mapped 8PSK.
     * \ingroup digital
     *
     * \details
     * \verbatim
           011 | 010
       100     |     001
       -----------------
       101     |     000
           110 | 111
       \endverbatim
     */
    class DIGITAL_API constellation_8psk_natural : public constellation
    {
    public:
      typedef boost::shared_ptr<constellation_8psk_natural> sptr;

      // public constructor
      static sptr make();

      ~constellation_8psk_natural();

      unsigned int decision_maker(const gr_complex *sample);

    protected:
      constellation_8psk_natural();
    };

    /************************************************************/
    /* constellation_16qam                                       */
    /*                                                          */
    /* the 16qam mapping used in set partition of tcm           */
    /*                                                          */
    /************************************************************/

    /*! 
     * \brief Digital constellation for 16qam.
     * \ingroup digital
     *
     * \details
     * \verbatim
   1000   1101 | 1100   1001
               |     
   1111   1010 | 1011   1110
       -----------------
   0100   0001 | 0000   0101
               | 
   0011   0110 | 0111   0010
       \endverbatim
     */
    class DIGITAL_API constellation_16qam : public constellation
    {
    public:
      typedef boost::shared_ptr<constellation_16qam> sptr;

      // public constructor
      static sptr make();

      ~constellation_16qam();

      unsigned int decision_maker(const gr_complex *sample);

    protected:
      constellation_16qam();
    };

  } /* namespace digital */
} /* namespace gr */

#endif /* INCLUDED_DIGITAL_CONSTELLATION_H */