mirror of
https://github.com/hb9fxq/gr-digitalhf
synced 2024-12-21 23:09:59 +00:00
volk::vector
This commit is contained in:
parent
48b1f4a669
commit
95cb14d38e
|
@ -232,9 +232,9 @@ bool adaptive_dfe_impl::start()
|
|||
GR_LOG_DEBUG(d_logger,str(boost::format("adaptive_dfe_impl::start() nB=%d nF=%d mu=%f alpha=%f")
|
||||
% _nB % _nF % _mu % _alpha));
|
||||
_filter_update = lms::make(_mu);
|
||||
//_filter_update = nlms::make(0.5f, 1.0f);
|
||||
//_filter_update = rls::make(0.001f, 0.9f); // not stable
|
||||
//_filter_update = kalman_exp::make(1.0f, 0.9f); // too slow
|
||||
// _filter_update = nlms::make(0.5f, 1.0f);
|
||||
// _filter_update = rls::make(0.001f, 0.9f); // not stable
|
||||
// _filter_update = kalman_exp::make(1.0f, 0.9f); // too slow
|
||||
// _filter_update = kalman_hsu::make(0.02f, 0.1f); // not stable
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <digitalhf/adaptive_dfe.h>
|
||||
|
||||
#include "filter_update.hpp"
|
||||
#include "volk_allocator.hpp"
|
||||
#include "volk_alloc.h"
|
||||
|
||||
namespace gr {
|
||||
namespace digitalhf {
|
||||
|
@ -59,7 +59,7 @@ private:
|
|||
|
||||
class adaptive_dfe_impl : public adaptive_dfe {
|
||||
private:
|
||||
typedef std::vector<gr_complex, volk_allocator<gr_complex> > gr_complex_vec_type;
|
||||
typedef volk::vector<gr_complex> gr_complex_vec_type;
|
||||
|
||||
int _sps;
|
||||
int _nB, _nF, _nW;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "filter_update.hpp"
|
||||
#include "volk_allocator.hpp"
|
||||
#include "volk_alloc.h"
|
||||
|
||||
// see
|
||||
// [1] https://open.library.ubc.ca/collections/ubctheses/831/items/1.0096286
|
||||
|
@ -30,7 +30,7 @@ protected:
|
|||
private:
|
||||
kalman_exp(float r, float lambda);
|
||||
|
||||
typedef std::vector<gr_complex, volk_allocator<gr_complex> > vec_type;
|
||||
typedef volk::vector<gr_complex> vec_type;
|
||||
float _lambda;
|
||||
float _r;
|
||||
vec_type _gain;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "filter_update.hpp"
|
||||
#include "volk_allocator.hpp"
|
||||
#include "volk_alloc.h"
|
||||
|
||||
|
||||
namespace gr {
|
||||
|
@ -40,8 +40,8 @@ protected:
|
|||
private:
|
||||
kalman_hsu(float q, float e);
|
||||
|
||||
typedef std::vector<gr_complex, volk_allocator<gr_complex > > complex_vec_type;
|
||||
typedef std::vector<float, volk_allocator<float> > real_vec_type;
|
||||
typedef volk::vector<gr_complex> complex_vec_type;
|
||||
typedef volk::vector<float> real_vec_type;
|
||||
float _q;
|
||||
float _e;
|
||||
complex_vec_type _g; // n -- kaman gain
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "filter_update.hpp"
|
||||
#include "volk_allocator.hpp"
|
||||
#include "volk/volk_alloc.h"
|
||||
|
||||
|
||||
namespace gr {
|
||||
|
@ -28,7 +28,7 @@ protected:
|
|||
private:
|
||||
lms(float mu);
|
||||
|
||||
typedef std::vector<gr_complex, volk_allocator<gr_complex> > vec_type;
|
||||
typedef volk::vector<gr_complex> vec_type;
|
||||
float _mu;
|
||||
vec_type _gain;
|
||||
vec_type _tmp;
|
||||
|
|
|
@ -44,7 +44,7 @@ gr_complex const* nlms::update(gr_complex const* beg,
|
|||
volk_32fc_magnitude_squared_32f(&_t1[0], beg, n);
|
||||
float norm = _delta;
|
||||
volk_32f_accumulator_s32f(&norm, &_t1[0], n);
|
||||
volk_32f_s32f_multiply_32f((float*)&_gain[0], (float const*)&_tmp[0], std::max(0.006f, _mu/norm), 2*n);
|
||||
volk_32f_s32f_multiply_32f((float*)&_gain[0], (float const*)&_tmp[0], std::max(0.005f, _mu/norm), 2*n);
|
||||
|
||||
return &_gain.front();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "filter_update.hpp"
|
||||
#include "volk_allocator.hpp"
|
||||
#include "volk_alloc.h"
|
||||
|
||||
|
||||
namespace gr {
|
||||
|
@ -28,8 +28,8 @@ protected:
|
|||
private:
|
||||
nlms(float mu, float delta);
|
||||
|
||||
typedef std::vector<gr_complex, volk_allocator<gr_complex> > complex_vec_type;
|
||||
typedef std::vector<float, volk_allocator<float> > real_vec_type;
|
||||
typedef volk::vector<gr_complex> complex_vec_type;
|
||||
typedef volk::vector<float> real_vec_type;
|
||||
float _mu;
|
||||
float _delta;
|
||||
complex_vec_type _gain;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "filter_update.hpp"
|
||||
#include "volk_allocator.hpp"
|
||||
#include "volk_alloc.h"
|
||||
|
||||
|
||||
namespace gr {
|
||||
|
@ -28,7 +28,7 @@ protected:
|
|||
private:
|
||||
rls(float delta, float lambda);
|
||||
|
||||
typedef std::vector<gr_complex, volk_allocator<gr_complex> > vec_type;
|
||||
typedef volk::vector<gr_complex> vec_type;
|
||||
float _delta;
|
||||
float _lambda;
|
||||
vec_type _gain;
|
||||
|
|
80
lib/volk_alloc.h
Normal file
80
lib/volk_alloc.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
/* -*- C++ -*- */
|
||||
/*
|
||||
* Copyright 2019 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_VOLK_ALLOC_H
|
||||
#define INCLUDED_VOLK_ALLOC_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <new>
|
||||
#include <vector>
|
||||
|
||||
#include <volk/volk.h>
|
||||
|
||||
namespace volk {
|
||||
|
||||
/*!
|
||||
* \brief C++11 allocator using volk_malloc and volk_free
|
||||
*
|
||||
* \details
|
||||
* adapted from https://en.cppreference.com/w/cpp/named_req/Alloc
|
||||
*/
|
||||
template <class T>
|
||||
struct alloc {
|
||||
typedef T value_type;
|
||||
|
||||
alloc() = default;
|
||||
|
||||
template <class U> constexpr alloc(alloc<U> const&) noexcept {}
|
||||
|
||||
T* allocate(std::size_t n) {
|
||||
if (n > std::numeric_limits<std::size_t>::max() / sizeof(T)) throw std::bad_alloc();
|
||||
|
||||
if (auto p = static_cast<T*>(volk_malloc(n*sizeof(T), volk_get_alignment())))
|
||||
return p;
|
||||
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
void deallocate(T* p, std::size_t) noexcept { volk_free(p); }
|
||||
|
||||
} ;
|
||||
|
||||
template <class T, class U>
|
||||
bool operator==(alloc<T> const&, alloc<U> const&) { return true; }
|
||||
|
||||
template <class T, class U>
|
||||
bool operator!=(alloc<T> const&, alloc<U> const&) { return false; }
|
||||
|
||||
|
||||
/*!
|
||||
* \brief type alias for std::vector using volk::alloc
|
||||
*
|
||||
* \details
|
||||
* example code:
|
||||
* volk::vector<float> v(100); // vector using volk_malloc, volk_free
|
||||
*/
|
||||
template<class T>
|
||||
using vector = std::vector<T, alloc<T> >;
|
||||
|
||||
} // namespace volk
|
||||
#endif // INCLUDED_VOLK_ALLOC_H
|
|
@ -1,43 +0,0 @@
|
|||
// -*- c++ -*-
|
||||
|
||||
#ifndef _LIB_VOLK_ALLOCATOR_HPP_
|
||||
#define _LIB_VOLK_ALLOCATOR_HPP_
|
||||
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <volk/volk.h>
|
||||
|
||||
namespace gr {
|
||||
namespace digitalhf {
|
||||
|
||||
// see https://en.cppreference.com/w/cpp/named_req/Allocator
|
||||
template <class T>
|
||||
struct volk_allocator {
|
||||
typedef T value_type;
|
||||
|
||||
volk_allocator() = default;
|
||||
|
||||
template <class U> constexpr volk_allocator(const volk_allocator<U>&) noexcept {}
|
||||
|
||||
T* allocate(std::size_t n) {
|
||||
if (n > std::numeric_limits<std::size_t>::max() / sizeof(T)) throw std::bad_alloc();
|
||||
|
||||
if (auto p = static_cast<T*>(volk_malloc(n*sizeof(T), volk_get_alignment())))
|
||||
return p;
|
||||
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
void deallocate(T* p, std::size_t) noexcept { volk_free(p); }
|
||||
|
||||
} ;
|
||||
|
||||
template <class T, class U>
|
||||
bool operator==(const volk_allocator<T>&, const volk_allocator<U>&) { return true; }
|
||||
|
||||
template <class T, class U>
|
||||
bool operator!=(const volk_allocator<T>&, const volk_allocator<U>&) { return false; }
|
||||
|
||||
} // namespace digitalhf
|
||||
} // namespace gr
|
||||
#endif // _LIB_VOLK_ALLOCATOR_HPP_
|
Loading…
Reference in a new issue