sdrangel/modemm17/FrequencyError.h

63 wiersze
1.1 KiB
C
Czysty Zwykły widok Historia

2022-07-20 07:07:00 +00:00
// Copyright 2020 Mobilinkd LLC.
#pragma once
#include "IirFilter.h"
#include <array>
#include <algorithm>
#include <numeric>
2022-07-04 21:03:07 +00:00
namespace modemm17
{
template <size_t N = 32>
struct FrequencyError
{
2022-07-27 21:27:01 +00:00
FrequencyError() :
{
2022-07-27 21:27:01 +00:00
samples_.fill(0.0f);
}
2022-07-27 21:27:01 +00:00
auto operator()(float sample)
{
float evm = 0;
bool use = true;
if (sample > 2)
{
evm = sample - 3;
}
else if (sample >= -2)
{
use = false;
}
else
{
evm = sample + 3;
}
if (use)
{
accum_ = accum_ - samples_[index_] + evm;
samples_[index_++] = evm;
if (index_ == N) index_ = 0;
}
return filter_(accum_ / N);
}
2022-07-27 21:27:01 +00:00
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;
};
2022-07-04 21:03:07 +00:00
} // modemm17