GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
adaptive_algorithm.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2020 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_DIGITAL_ADAPTIVE_ALGORITHM_H
12 #define INCLUDED_DIGITAL_ADAPTIVE_ALGORITHM_H
13 
14 #include <gnuradio/digital/api.h>
16 #include <gnuradio/math.h>
17 #include <algorithm>
18 #include <cmath>
19 #include <vector>
20 
21 namespace gr {
22 namespace digital {
23 enum class adaptive_algorithm_t { LMS, NLMS, CMA };
24 
25 class adaptive_algorithm;
26 typedef std::shared_ptr<adaptive_algorithm> adaptive_algorithm_sptr;
27 
29  : public std::enable_shared_from_this<adaptive_algorithm>
30 {
31 protected:
33  const constellation_sptr d_constellation;
34 
35 public:
36  virtual ~adaptive_algorithm() {}
37 
38  adaptive_algorithm(adaptive_algorithm_t alg_type, constellation_sptr cons)
39  : d_algorithm_type(alg_type), d_constellation(cons)
40  {
41  }
42 
43  adaptive_algorithm_sptr base() { return shared_from_this(); }
44 
45  virtual void initialize_taps(std::vector<gr_complex>& taps)
46  {
47  std::fill(taps.begin(), taps.end(), gr_complex(0.0, 0.0));
48  taps[0] = gr_complex(1.0, 0.0); // default weights, overridden by derived classes
49  }
50 
51  virtual gr_complex error_dd(gr_complex& wu, gr_complex& decision) const
52  {
53  // The `map_to_points` function will treat `decision` as an array pointer.
54  // This call is "safe" because `map_to_points` is limited by the
55  // dimensionality of the constellation. This class calls the
56  // `constellation` class default constructor, which initializes the
57  // dimensionality value to `1`. Thus, Only the single `gr_complex` value
58  // will be dereferenced.
59  d_constellation->map_to_points(d_constellation->decision_maker(&wu), &decision);
60  return decision - wu;
61  }
62 
63  virtual gr_complex error_tr(const gr_complex& wu, const gr_complex& d_n) const
64  {
65  return d_n - wu;
66  }
67 
68  virtual gr_complex update_tap(const gr_complex tap,
69  const gr_complex& in,
70  const gr_complex error,
71  const gr_complex decision) = 0;
72 
73  virtual void update_taps(gr_complex* taps,
74  const gr_complex* in,
75  const gr_complex error,
76  const gr_complex decision,
77  unsigned int num_taps)
78  {
79  // default tap update until update_taps is implemented for all the alg types
80  // Performance can be improved in the derived algorithms by having a volk-ified
81  // update_taps method
82  for (unsigned i = 0; i < num_taps; i++) {
83  taps[i] = update_tap(taps[i], in[i], error, decision);
84  }
85  }
86 };
87 
88 } // namespace digital
89 } // namespace gr
90 #endif
Definition: adaptive_algorithm.h:30
virtual gr_complex error_dd(gr_complex &wu, gr_complex &decision) const
Definition: adaptive_algorithm.h:51
const constellation_sptr d_constellation
Definition: adaptive_algorithm.h:33
virtual gr_complex error_tr(const gr_complex &wu, const gr_complex &d_n) const
Definition: adaptive_algorithm.h:63
virtual void update_taps(gr_complex *taps, const gr_complex *in, const gr_complex error, const gr_complex decision, unsigned int num_taps)
Definition: adaptive_algorithm.h:73
virtual void initialize_taps(std::vector< gr_complex > &taps)
Definition: adaptive_algorithm.h:45
virtual ~adaptive_algorithm()
Definition: adaptive_algorithm.h:36
adaptive_algorithm_sptr base()
Definition: adaptive_algorithm.h:43
virtual gr_complex update_tap(const gr_complex tap, const gr_complex &in, const gr_complex error, const gr_complex decision)=0
const adaptive_algorithm_t d_algorithm_type
Definition: adaptive_algorithm.h:32
adaptive_algorithm(adaptive_algorithm_t alg_type, constellation_sptr cons)
Definition: adaptive_algorithm.h:38
#define DIGITAL_API
Definition: gr-digital/include/gnuradio/digital/api.h:18
std::complex< float > gr_complex
Definition: gr_complex.h:15
static constexpr float taps[NSTEPS+1][NTAPS]
Definition: interpolator_taps.h:9
adaptive_algorithm_t
Definition: adaptive_algorithm.h:23
GNU Radio logging wrapper.
Definition: basic_block.h:29
PMT_API pmt_t cons(const pmt_t &x, const pmt_t &y)
Return a newly allocated pair whose car is x and whose cdr is y.