kopia lustrzana https://github.com/mobilinkd/m17-cxx-demod
Simplify PhaseEstimator.
rodzic
091e423d98
commit
b4c99648b9
|
|
@ -17,22 +17,17 @@ namespace mobilinkd
|
|||
* these errors have not affected the performance of clock
|
||||
* recovery.
|
||||
*/
|
||||
template <typename T>
|
||||
template <typename FloatType>
|
||||
struct PhaseEstimator
|
||||
{
|
||||
using float_type = T;
|
||||
using samples_t = std::array<float_type, 3>; // 3 samples in length
|
||||
using minmax_t = std::array<float_type, 32>; // 32 symbols in length
|
||||
using float_type = FloatType;
|
||||
using samples_t = std::array<FloatType, 3>; // 3 samples in length
|
||||
|
||||
float_type dx_;
|
||||
minmax_t symbols_{0};
|
||||
size_t index_ = 0;
|
||||
|
||||
PhaseEstimator(float_type sample_rate, float_type symbol_rate)
|
||||
PhaseEstimator(FloatType sample_rate, FloatType symbol_rate)
|
||||
: dx_(2.0 * symbol_rate / sample_rate)
|
||||
{
|
||||
symbols_.fill(0.0);
|
||||
}
|
||||
{}
|
||||
|
||||
/**
|
||||
* This performs a rolling estimate of the phase.
|
||||
|
|
@ -43,21 +38,11 @@ struct PhaseEstimator
|
|||
float_type operator()(const samples_t& samples)
|
||||
{
|
||||
assert(dx_ > 0.0);
|
||||
|
||||
symbols_[index_++] = samples[1];
|
||||
|
||||
if (index_ == std::tuple_size<minmax_t>::value) index_ = 0;
|
||||
|
||||
auto symbol_min = *std::min_element(std::begin(symbols_), std::end(symbols_));
|
||||
auto symbol_max = *std::max_element(std::begin(symbols_), std::end(symbols_));
|
||||
|
||||
auto y_scale = (symbol_max - symbol_min) * 0.5;
|
||||
auto dy = y_scale != 0 ? (samples.at(2) - samples.at(0)) / y_scale : 0;
|
||||
|
||||
auto ratio = dy / dx_;
|
||||
|
||||
auto ratio = ((samples.at(2) - samples.at(0)) / 3) / dx_;
|
||||
// Clamp +/-5.
|
||||
ratio = std::min(float_type(5.0), ratio);
|
||||
ratio = std::max(float_type(-5.0), ratio);
|
||||
ratio = std::min(FloatType(5.0), ratio);
|
||||
ratio = std::max(FloatType(-5.0), ratio);
|
||||
|
||||
return ratio;
|
||||
}
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue