1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-21 23:55:13 -05:00

M17: Golay24 code cleanup

This commit is contained in:
f4exb 2022-07-27 23:27:01 +02:00
parent b5b6bdf825
commit 06a0f051e9
2 changed files with 17 additions and 21 deletions

View File

@ -14,27 +14,12 @@ namespace modemm17
template <size_t N = 32> template <size_t N = 32>
struct FrequencyError struct FrequencyError
{ {
using float_type = float; FrequencyError() :
using array_t = std::array<float, N>;
using filter_type = BaseIirFilter<3>;
static constexpr std::array<float, 3> evm_b{0.02008337, 0.04016673, 0.02008337};
static constexpr std::array<float, 3> evm_a{1.0, -1.56101808, 0.64135154};
array_t samples_{0};
size_t index_ = 0;
float_type accum_ = 0.0;
filter_type filter_{makeIirFilter(evm_b, evm_a)};
const float_type ZERO = 0.0;
FrequencyError()
{ {
samples_.fill(0.0); samples_.fill(0.0f);
} }
auto operator()(float_type sample) auto operator()(float sample)
{ {
float evm = 0; float evm = 0;
bool use = true; bool use = true;
@ -61,6 +46,17 @@ struct FrequencyError
return filter_(accum_ / N); return filter_(accum_ / N);
} }
private:
static constexpr std::array<float, 3> evm_b{0.02008337, 0.04016673, 0.02008337};
static constexpr std::array<float, 3> evm_a{1.0, -1.56101808, 0.64135154};
std::array<float, N> samples_;
size_t index_ = 0;
float accum_ = 0.0f;
BaseIirFilter<3> filter_{makeIirFilter(evm_b, evm_a)};
const float ZERO = 0.0f;
}; };
} // modemm17 } // modemm17

View File

@ -22,7 +22,7 @@ namespace Golay24_detail
// Need a constexpr sort. // Need a constexpr sort.
// https://stackoverflow.com/a/40030044/854133 // https://stackoverflow.com/a/40030044/854133
template<class T> template<class T>
constexpr void swap(T& l, T& r) static void swap(T& l, T& r)
{ {
T tmp = std::move(l); T tmp = std::move(l);
l = std::move(r); l = std::move(r);
@ -52,7 +52,7 @@ struct array
}; };
template <typename T, size_t N> template <typename T, size_t N>
constexpr void sort_impl(array<T, N> &array, size_t left, size_t right) static void sort_impl(array<T, N> &array, size_t left, size_t right)
{ {
if (left < right) if (left < right)
{ {
@ -70,7 +70,7 @@ constexpr void sort_impl(array<T, N> &array, size_t left, size_t right)
} }
template <typename T, size_t N> template <typename T, size_t N>
constexpr array<T, N> sort(array<T, N> array) static array<T, N> sort(array<T, N> array)
{ {
auto sorted = array; auto sorted = array;
sort_impl(sorted, 0, N); sort_impl(sorted, 0, N);