1
0
Fork 0
mirror of https://github.com/hb9fxq/gr-digitalhf synced 2024-12-22 23:19:59 +00:00
gr-digitalhf/lib/nlms.cc

59 lines
1.2 KiB
C++
Raw Normal View History

2019-09-11 14:30:36 +00:00
// -*- C++ -*-
#include <cassert>
#include "nlms.hpp"
#include <volk/volk.h>
namespace gr {
namespace digitalhf {
2019-09-14 15:02:30 +00:00
filter_update::sptr nlms::make(float mu, float delta) {
return filter_update::sptr(new nlms(mu, delta));
2019-09-11 14:30:36 +00:00
}
2019-09-14 15:02:30 +00:00
nlms::nlms(float mu, float delta)
2019-09-11 14:30:36 +00:00
: _mu(mu)
2019-09-14 15:02:30 +00:00
, _delta(delta)
2019-09-11 14:30:36 +00:00
, _gain()
, _tmp()
, _t1() {
}
nlms::~nlms() {
}
void nlms::resize(size_t n) {
if (_gain.size() == n)
return;
_gain.resize(n);
_tmp.resize(n);
_t1.resize(n);
std::fill_n(_gain.begin(), n, 0);
}
void nlms::reset() {
std::fill_n(_gain.begin(), _gain.size(), 0);
}
gr_complex const* nlms::update(gr_complex const* beg,
2019-09-14 15:02:30 +00:00
gr_complex const* end) {
2019-09-11 14:30:36 +00:00
assert(end-beg > 0);
size_t const n = end - beg;
resize(n);
volk_32fc_conjugate_32fc(&_tmp[0], beg, n);
volk_32fc_magnitude_squared_32f(&_t1[0], beg, n);
2019-09-14 15:02:30 +00:00
float norm = _delta;
2019-09-11 14:30:36 +00:00
volk_32f_accumulator_s32f(&norm, &_t1[0], n);
2019-09-24 11:29:56 +00:00
volk_32f_s32f_multiply_32f((float*)&_gain[0], (float const*)&_tmp[0], std::max(0.005f, _mu/norm), 2*n);
2019-09-11 14:30:36 +00:00
2019-10-27 21:48:09 +00:00
return _gain.data();
2019-09-11 14:30:36 +00:00
}
void nlms::set_parameters(std::map<std::string, float>const & p) {
2019-09-14 15:02:30 +00:00
_mu = p.at("mu");
_delta = p.at("delta");
2019-09-11 14:30:36 +00:00
}
} // namespace digitalhf
} // namespace gr