GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
adaptive_algorithm_nlms.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_NLMS_H
12 #define INCLUDED_DIGITAL_ADAPTIVE_ALGORITHM_NLMS_H
13 
15 #include <volk/volk.h>
16 
17 namespace gr {
18 namespace digital {
19 
21 {
22 public:
23  typedef std::shared_ptr<adaptive_algorithm_nlms> sptr;
24 
25 private:
26  const float d_step_size;
27 
28 protected:
29  adaptive_algorithm_nlms(constellation_sptr cons, float step_size)
30  : adaptive_algorithm(adaptive_algorithm_t::NLMS, cons), d_step_size(step_size)
31  {
32  }
33 
34 public:
35  static sptr make(constellation_sptr cons, float step_size)
36  {
38  new adaptive_algorithm_nlms(cons, step_size));
39  }
40 
42  const gr_complex& in,
43  const gr_complex error,
44  const gr_complex decision) override
45  {
46  throw std::runtime_error(
47  "NLMS can only update all taps at once, single tap update is not valid");
48  }
49 
51  const gr_complex* in,
52  const gr_complex error,
53  const gr_complex decision,
54  unsigned int num_taps) override
55  {
56  gr_complex dp;
57  volk_32fc_x2_conjugate_dot_prod_32fc(&dp, in, in, num_taps);
58  float magsq = real(dp);
59  float norm_step_size = d_step_size / magsq;
60 
61  for (unsigned i = 0; i < num_taps; i++) {
62  taps[i] = conj(conj(taps[i]) + norm_step_size * in[i] * conj(error));
63  }
64  }
65 
67 
68  void initialize_taps(std::vector<gr_complex>& taps) override
69  {
70  std::fill(taps.begin(), taps.end(), gr_complex(0.0, 0.0));
71  }
72 };
73 
74 } // namespace digital
75 } // namespace gr
76 
77 #endif
Definition: adaptive_algorithm_nlms.h:21
~adaptive_algorithm_nlms() override
Definition: adaptive_algorithm_nlms.h:66
static sptr make(constellation_sptr cons, float step_size)
Definition: adaptive_algorithm_nlms.h:35
adaptive_algorithm_nlms(constellation_sptr cons, float step_size)
Definition: adaptive_algorithm_nlms.h:29
gr_complex update_tap(const gr_complex tap, const gr_complex &in, const gr_complex error, const gr_complex decision) override
Definition: adaptive_algorithm_nlms.h:41
void initialize_taps(std::vector< gr_complex > &taps) override
Definition: adaptive_algorithm_nlms.h:68
std::shared_ptr< adaptive_algorithm_nlms > sptr
Definition: adaptive_algorithm_nlms.h:23
void update_taps(gr_complex *taps, const gr_complex *in, const gr_complex error, const gr_complex decision, unsigned int num_taps) override
Definition: adaptive_algorithm_nlms.h:50
Definition: adaptive_algorithm.h:30
#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.