GNU Radio C++ API Reference: adaptive_algorithm.h Source File

| GNU Radio C++ API Reference 3.10.12.0 The Free & Open Software Radio Ecosystem |

Loading...
Searching...
No Matches
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>
15#include <gnuradio/digital/constellation.h>
16#include <gnuradio/math.h>
17#include <algorithm>
18#include <cmath>
19#include <vector>
20
21namespace gr {
22 namespace digital {
23 enum class adaptive_algorithm_t { LMS, NLMS, CMA };
24
25class adaptive_algorithm;
26typedef std::shared_ptr<adaptive_algorithm> adaptive_algorithm_sptr;
27
28 class DIGITAL_API adaptive_algorithm
29 : public std::enable_shared_from_this<adaptive_algorithm>
30{
31protected:
32 const adaptive_algorithm_t d_algorithm_type;
33 const constellation_sptr d_constellation;
34
35public:
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
gr::digital::adaptive_algorithm::error_dd
virtual gr_complex error_dd(gr_complex &wu, gr_complex &decision) const
Definition adaptive_algorithm.h:51
gr::digital::adaptive_algorithm::d_constellation
const constellation_sptr d_constellation
Definition adaptive_algorithm.h:33
gr::digital::adaptive_algorithm::error_tr
virtual gr_complex error_tr(const gr_complex &wu, const gr_complex &d_n) const
Definition adaptive_algorithm.h:63
gr::digital::adaptive_algorithm::update_taps
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
gr::digital::adaptive_algorithm::initialize_taps
virtual void initialize_taps(std::vector< gr_complex > &taps)
Definition adaptive_algorithm.h:45
gr::digital::adaptive_algorithm::~adaptive_algorithm
virtual ~adaptive_algorithm()
Definition adaptive_algorithm.h:36
gr::digital::adaptive_algorithm::base
adaptive_algorithm_sptr base()
Definition adaptive_algorithm.h:43
gr::digital::adaptive_algorithm::update_tap
virtual gr_complex update_tap(const gr_complex tap, const gr_complex &in, const gr_complex error, const gr_complex decision)=0
gr::digital::adaptive_algorithm::d_algorithm_type
const adaptive_algorithm_t d_algorithm_type
Definition adaptive_algorithm.h:32
gr::digital::adaptive_algorithm::adaptive_algorithm
adaptive_algorithm(adaptive_algorithm_t alg_type, constellation_sptr cons)
Definition adaptive_algorithm.h:38
constellation.h
api.h
DIGITAL_API
#define DIGITAL_API
Definition gr-digital/include/gnuradio/digital/api.h:18
gr_complex
std::complex< float > gr_complex
Definition gr_complex.h:15
math.h
gr::digital
Definition adaptive_algorithm.h:22
gr::digital::adaptive_algorithm_t
adaptive_algorithm_t
Definition adaptive_algorithm.h:23
gr::digital::adaptive_algorithm_t::CMA
@ CMA
Definition adaptive_algorithm.h:23
gr::digital::adaptive_algorithm_t::LMS
@ LMS
Definition adaptive_algorithm.h:23
gr::digital::adaptive_algorithm_t::NLMS
@ NLMS
Definition adaptive_algorithm.h:23
gr
GNU Radio logging wrapper.
Definition basic_block.h:29