diff --git a/PhaseEstimator.h b/PhaseEstimator.h index 6bf81c0..8e740fd 100644 --- a/PhaseEstimator.h +++ b/PhaseEstimator.h @@ -17,22 +17,17 @@ namespace mobilinkd * these errors have not affected the performance of clock * recovery. */ -template +template struct PhaseEstimator { - using float_type = T; - using samples_t = std::array; // 3 samples in length - using minmax_t = std::array; // 32 symbols in length + using float_type = FloatType; + using samples_t = std::array; // 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::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; }