2018-10-24 18:17:58 +00:00
|
|
|
/* -*- c++ -*- */
|
|
|
|
/*
|
|
|
|
* Copyright 2018 hcab14@mail.com.
|
|
|
|
*
|
|
|
|
* This 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.
|
|
|
|
*
|
|
|
|
* This software 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 this software; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_DIGITALHF_ADAPTIVE_DFE_IMPL_H
|
|
|
|
#define INCLUDED_DIGITALHF_ADAPTIVE_DFE_IMPL_H
|
|
|
|
|
2019-03-29 19:36:04 +00:00
|
|
|
#include <gnuradio/blocks/control_loop.h>
|
|
|
|
#include <gnuradio/blocks/rotator.h>
|
2018-10-25 16:01:24 +00:00
|
|
|
#include <gnuradio/digital/constellation.h>
|
|
|
|
#include <digitalhf/adaptive_dfe.h>
|
2018-10-24 18:17:58 +00:00
|
|
|
|
2019-09-09 14:04:06 +00:00
|
|
|
#include "filter_update.hpp"
|
2019-09-24 11:29:56 +00:00
|
|
|
#include "volk_alloc.h"
|
2019-09-09 14:04:06 +00:00
|
|
|
|
2018-10-24 18:17:58 +00:00
|
|
|
namespace gr {
|
|
|
|
namespace digitalhf {
|
|
|
|
|
2018-11-12 17:28:02 +00:00
|
|
|
class constellation_distance_filter {
|
|
|
|
public:
|
|
|
|
constellation_distance_filter(int max_time_constant=10)
|
|
|
|
: _max_time_constant(max_time_constant)
|
|
|
|
, _counter(0)
|
|
|
|
, _pwr(0) {}
|
|
|
|
|
|
|
|
void reset(int max_time_constant) {
|
|
|
|
_max_time_constant = max_time_constant;
|
|
|
|
_counter = 0;
|
|
|
|
_pwr = 0;
|
|
|
|
}
|
|
|
|
float filter(float x) {
|
|
|
|
_counter += (_counter < _max_time_constant);
|
|
|
|
float const alpha = 1.0f/_counter;
|
|
|
|
_pwr = (1-alpha)*_pwr + alpha*x;
|
|
|
|
return _pwr;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
private:
|
|
|
|
int _max_time_constant;
|
|
|
|
int _counter;
|
|
|
|
float _pwr; // filtered distance to constellation point
|
|
|
|
} ;
|
|
|
|
|
2018-10-24 18:17:58 +00:00
|
|
|
class adaptive_dfe_impl : public adaptive_dfe {
|
|
|
|
private:
|
2019-09-24 11:29:56 +00:00
|
|
|
typedef volk::vector<gr_complex> gr_complex_vec_type;
|
2019-09-09 14:04:06 +00:00
|
|
|
|
2018-10-24 18:17:58 +00:00
|
|
|
int _sps;
|
|
|
|
int _nB, _nF, _nW;
|
2018-11-12 17:28:02 +00:00
|
|
|
int _nGuard;
|
2018-10-24 18:17:58 +00:00
|
|
|
|
2018-10-26 20:06:21 +00:00
|
|
|
float _mu;
|
|
|
|
float _alpha;
|
|
|
|
|
2018-11-06 16:34:48 +00:00
|
|
|
bool _use_symbol_taps;
|
|
|
|
|
2019-09-09 15:41:20 +00:00
|
|
|
gr_complex_vec_type _tmp;
|
2019-09-09 14:04:06 +00:00
|
|
|
gr_complex_vec_type _taps_samples;
|
|
|
|
gr_complex_vec_type _taps_symbols;
|
|
|
|
gr_complex_vec_type _last_taps_samples;
|
2018-10-26 20:06:21 +00:00
|
|
|
|
2019-09-09 14:04:06 +00:00
|
|
|
gr_complex_vec_type _hist_symbols;
|
2018-10-26 20:06:21 +00:00
|
|
|
int _hist_symbol_index;
|
|
|
|
|
2018-10-25 16:01:24 +00:00
|
|
|
std::vector<gr::digital::constellation_sptr> _constellations;
|
2018-11-12 17:28:02 +00:00
|
|
|
std::vector<constellation_distance_filter> _npwr;
|
2018-10-28 15:28:36 +00:00
|
|
|
int _npwr_max_time_constant;
|
2018-10-25 16:01:24 +00:00
|
|
|
int _constellation_index;
|
2019-09-09 14:04:06 +00:00
|
|
|
std::vector<gr_complex> _symbols;
|
|
|
|
std::vector<gr_complex> _scramble; // PSK-8 scramble symbols
|
2019-05-14 20:39:57 +00:00
|
|
|
std::vector<std::array<int,8> > _scramble_xor; // signs for XOR scrambling
|
2019-09-09 14:04:06 +00:00
|
|
|
std::vector<gr_complex> _descrambled_symbols;
|
2018-10-26 20:06:21 +00:00
|
|
|
int _symbol_counter;
|
|
|
|
|
2018-10-29 15:07:20 +00:00
|
|
|
bool _save_soft_decisions;
|
|
|
|
std::vector<float> _vec_soft_decisions;
|
2018-11-12 17:28:02 +00:00
|
|
|
std::map<std::string, pmt::pmt_t> _msg_ports;
|
|
|
|
pmt::pmt_t _msg_metadata;
|
2018-10-26 20:06:21 +00:00
|
|
|
|
2019-03-29 19:36:04 +00:00
|
|
|
int _num_samples_since_filter_update;
|
2019-09-09 14:04:06 +00:00
|
|
|
gr_complex_vec_type _rotated_samples;
|
2019-03-29 19:36:04 +00:00
|
|
|
blocks::rotator _rotator;
|
|
|
|
gr::blocks::control_loop _control_loop;
|
|
|
|
|
2018-10-26 20:06:21 +00:00
|
|
|
enum state {
|
|
|
|
WAIT_FOR_PREAMBLE,
|
2018-11-12 17:28:02 +00:00
|
|
|
WAIT_FOR_FRAME_INFO,
|
2018-10-26 20:06:21 +00:00
|
|
|
DO_FILTER
|
|
|
|
} _state;
|
2018-10-24 18:17:58 +00:00
|
|
|
|
2019-09-09 14:04:06 +00:00
|
|
|
filter_update::sptr _filter_update;
|
2019-09-09 15:41:20 +00:00
|
|
|
|
2018-11-12 17:28:02 +00:00
|
|
|
void update_constellations(pmt::pmt_t );
|
|
|
|
void update_frame_info(pmt::pmt_t );
|
2018-10-29 11:25:56 +00:00
|
|
|
|
2018-11-12 17:28:02 +00:00
|
|
|
gr_complex filter(gr_complex const* start, gr_complex const* end);
|
|
|
|
int recenter_filter_taps();
|
|
|
|
void reset_filter();
|
2018-10-24 18:17:58 +00:00
|
|
|
|
2018-11-12 17:28:02 +00:00
|
|
|
void publish_frame_info();
|
|
|
|
void publish_soft_dec();
|
2018-10-27 09:36:27 +00:00
|
|
|
|
2018-10-24 18:17:58 +00:00
|
|
|
public:
|
|
|
|
adaptive_dfe_impl(int sps, // samples per symbol
|
|
|
|
int nB, // number of forward FIR taps
|
|
|
|
int nF, // number of backward FIR taps
|
|
|
|
int nW, // number of symbol taps
|
2018-10-28 15:28:36 +00:00
|
|
|
float mu,
|
2018-11-12 17:28:02 +00:00
|
|
|
float alpha);
|
2018-10-24 18:17:58 +00:00
|
|
|
virtual ~adaptive_dfe_impl();
|
|
|
|
|
|
|
|
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
|
|
|
|
|
|
|
|
virtual bool start();
|
|
|
|
virtual bool stop();
|
|
|
|
|
|
|
|
virtual int general_work(int noutput_items,
|
|
|
|
gr_vector_int &ninput_items,
|
|
|
|
gr_vector_const_void_star &input_items,
|
|
|
|
gr_vector_void_star &output_items);
|
|
|
|
|
2019-09-09 15:41:20 +00:00
|
|
|
virtual void set_mu(float mu) { _mu = mu; _filter_update->set_parameters({{"mu", mu}}); }
|
2018-11-12 17:28:02 +00:00
|
|
|
virtual void set_alpha(float alpha) { _alpha = alpha; }
|
2018-10-24 18:17:58 +00:00
|
|
|
} ;
|
|
|
|
|
|
|
|
} // namespace digitalhf
|
|
|
|
} // namespace gr
|
|
|
|
|
|
|
|
#endif /* INCLUDED_DIGITALHF_ADAPTIVE_DFE_IMPL_H */
|