2017-02-21 10:35:18 +00:00
|
|
|
/*!
|
|
|
|
* \file pulse_blanking_cc.cc
|
2017-08-24 17:21:24 +00:00
|
|
|
* \brief Implements a pulse blanking algorithm
|
2017-02-21 10:35:18 +00:00
|
|
|
* \author Javier Arribas (jarribas(at)cttc.es)
|
2017-08-24 17:21:24 +00:00
|
|
|
* Antonio Ramos (antonio.ramosdet(at)gmail.com)
|
2017-02-21 10:35:18 +00:00
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2019-07-26 10:38:20 +00:00
|
|
|
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
|
2017-02-21 10:35:18 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2017-02-21 10:35:18 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pulse_blanking_cc.h"
|
2017-10-19 18:51:30 +00:00
|
|
|
#include <boost/math/distributions/chi_squared.hpp>
|
2017-02-21 10:35:18 +00:00
|
|
|
#include <gnuradio/io_signature.h>
|
|
|
|
#include <volk/volk.h>
|
2019-08-17 11:56:54 +00:00
|
|
|
#include <algorithm>
|
2017-02-27 14:22:47 +00:00
|
|
|
|
2017-07-12 07:12:56 +00:00
|
|
|
|
2018-08-13 23:32:06 +00:00
|
|
|
pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int32_t length_,
|
|
|
|
int32_t n_segments_est, int32_t n_segments_reset)
|
2017-02-21 10:35:18 +00:00
|
|
|
{
|
2017-07-12 07:12:56 +00:00
|
|
|
return pulse_blanking_cc_sptr(new pulse_blanking_cc(pfa, length_, n_segments_est, n_segments_reset));
|
2017-02-21 10:35:18 +00:00
|
|
|
}
|
|
|
|
|
2017-10-16 18:17:32 +00:00
|
|
|
|
2018-04-29 11:26:21 +00:00
|
|
|
pulse_blanking_cc::pulse_blanking_cc(float pfa,
|
2018-08-13 23:32:06 +00:00
|
|
|
int32_t length_,
|
|
|
|
int32_t n_segments_est,
|
|
|
|
int32_t n_segments_reset) : gr::block("pulse_blanking_cc",
|
|
|
|
gr::io_signature::make(1, 1, sizeof(gr_complex)),
|
|
|
|
gr::io_signature::make(1, 1, sizeof(gr_complex)))
|
2017-02-21 10:35:18 +00:00
|
|
|
{
|
2018-08-13 23:32:06 +00:00
|
|
|
const int32_t alignment_multiple = volk_get_alignment() / sizeof(gr_complex);
|
2017-02-21 10:35:18 +00:00
|
|
|
set_alignment(std::max(1, alignment_multiple));
|
2017-07-10 10:53:26 +00:00
|
|
|
this->pfa = pfa;
|
|
|
|
this->length_ = length_;
|
|
|
|
last_filtered = false;
|
|
|
|
n_segments = 0;
|
2017-07-12 07:12:56 +00:00
|
|
|
this->n_segments_est = n_segments_est;
|
|
|
|
this->n_segments_reset = n_segments_reset;
|
2017-07-10 10:53:26 +00:00
|
|
|
noise_power_estimation = 0.0;
|
2017-10-16 18:35:06 +00:00
|
|
|
n_deg_fred = 2 * length_;
|
2017-07-10 10:53:26 +00:00
|
|
|
boost::math::chi_squared_distribution<float> my_dist_(n_deg_fred);
|
|
|
|
thres_ = boost::math::quantile(boost::math::complement(my_dist_, pfa));
|
2020-06-25 09:58:01 +00:00
|
|
|
zeros_ = volk_gnsssdr::vector<gr_complex>(length_);
|
2017-07-10 10:53:26 +00:00
|
|
|
}
|
2017-02-21 10:35:18 +00:00
|
|
|
|
2018-04-29 11:26:21 +00:00
|
|
|
|
2017-10-16 14:36:51 +00:00
|
|
|
void pulse_blanking_cc::forecast(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items_required)
|
|
|
|
{
|
2018-12-09 21:00:09 +00:00
|
|
|
for (int &aux : ninput_items_required)
|
2017-10-17 09:44:23 +00:00
|
|
|
{
|
2018-12-03 17:03:25 +00:00
|
|
|
aux = length_;
|
2017-10-17 09:44:23 +00:00
|
|
|
}
|
2017-10-16 14:36:51 +00:00
|
|
|
}
|
|
|
|
|
2018-04-29 11:26:21 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
int pulse_blanking_cc::general_work(int noutput_items, gr_vector_int &ninput_items __attribute__((unused)),
|
|
|
|
gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
|
2017-02-21 10:35:18 +00:00
|
|
|
{
|
2018-12-03 15:25:11 +00:00
|
|
|
const auto *in = reinterpret_cast<const gr_complex *>(input_items[0]);
|
|
|
|
auto *out = reinterpret_cast<gr_complex *>(output_items[0]);
|
2020-06-25 09:58:01 +00:00
|
|
|
auto magnitude = volk_gnsssdr::vector<float>(noutput_items);
|
|
|
|
volk_32fc_magnitude_squared_32f(magnitude.data(), in, noutput_items);
|
2018-08-13 23:32:06 +00:00
|
|
|
int32_t sample_index = 0;
|
2017-07-10 10:53:26 +00:00
|
|
|
float segment_energy;
|
2018-03-03 01:03:39 +00:00
|
|
|
while ((sample_index + length_) < noutput_items)
|
2017-07-10 10:53:26 +00:00
|
|
|
{
|
2020-06-25 09:58:01 +00:00
|
|
|
volk_32f_accumulator_s32f(&segment_energy, (magnitude.data() + sample_index), length_);
|
2018-03-03 01:03:39 +00:00
|
|
|
if ((n_segments < n_segments_est) && (last_filtered == false))
|
2017-10-16 18:17:32 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
noise_power_estimation = (static_cast<float>(n_segments) * noise_power_estimation + segment_energy / static_cast<float>(n_deg_fred)) / static_cast<float>(n_segments + 1);
|
2017-10-16 18:35:06 +00:00
|
|
|
memcpy(out, in, sizeof(gr_complex) * length_);
|
2017-10-16 18:17:32 +00:00
|
|
|
}
|
2017-07-10 10:53:26 +00:00
|
|
|
else
|
2017-02-27 14:22:47 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if ((segment_energy / noise_power_estimation) > thres_)
|
2017-10-16 18:17:32 +00:00
|
|
|
{
|
2020-06-25 09:58:01 +00:00
|
|
|
memcpy(out, zeros_.data(), sizeof(gr_complex) * length_);
|
2017-10-16 18:17:32 +00:00
|
|
|
last_filtered = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-16 18:35:06 +00:00
|
|
|
memcpy(out, in, sizeof(gr_complex) * length_);
|
2017-10-16 18:17:32 +00:00
|
|
|
last_filtered = false;
|
|
|
|
if (n_segments > n_segments_reset)
|
|
|
|
{
|
|
|
|
n_segments = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-02-27 14:22:47 +00:00
|
|
|
}
|
2017-10-16 18:35:06 +00:00
|
|
|
in += length_;
|
|
|
|
out += length_;
|
|
|
|
sample_index += length_;
|
2017-10-16 18:17:32 +00:00
|
|
|
n_segments++;
|
2017-02-21 10:35:18 +00:00
|
|
|
}
|
2017-07-10 10:53:26 +00:00
|
|
|
consume_each(sample_index);
|
2018-03-03 01:03:39 +00:00
|
|
|
return sample_index;
|
2017-02-21 10:35:18 +00:00
|
|
|
}
|