2022-07-20 07:07:00 +00:00
|
|
|
// Copyright 2020 Mobilinkd LLC.
|
2022-06-07 01:22:18 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "IirFilter.h"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <numeric>
|
|
|
|
#include <cmath>
|
|
|
|
#include <tuple>
|
|
|
|
|
2022-07-04 21:03:07 +00:00
|
|
|
namespace modemm17
|
2022-06-07 01:22:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
struct CarrierDetect
|
|
|
|
{
|
2022-06-09 18:12:35 +00:00
|
|
|
using result_t = std::tuple<bool, float>;
|
2022-06-07 01:22:18 +00:00
|
|
|
|
2022-06-09 18:12:35 +00:00
|
|
|
BaseIirFilter<3> filter_;
|
|
|
|
float lock_;
|
|
|
|
float unlock_;
|
2022-06-07 01:22:18 +00:00
|
|
|
bool locked_ = false;
|
|
|
|
|
2022-06-09 18:12:35 +00:00
|
|
|
CarrierDetect(std::array<float, 3> const& b, std::array<float, 3> const& a, float lock_level, float unlock_level)
|
2022-06-07 01:22:18 +00:00
|
|
|
: filter_(b, a), lock_(lock_level), unlock_(unlock_level)
|
|
|
|
{
|
|
|
|
}
|
2022-06-09 18:12:35 +00:00
|
|
|
|
|
|
|
result_t operator()(float value)
|
2022-06-07 01:22:18 +00:00
|
|
|
{
|
|
|
|
auto filtered = filter_(std::abs(value));
|
|
|
|
if (locked_ && (filtered > unlock_)) locked_ = false;
|
|
|
|
else if (!locked_ && (filtered < lock_)) locked_ = true;
|
|
|
|
|
|
|
|
return std::make_tuple(locked_, filtered);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-04 21:03:07 +00:00
|
|
|
} // modemm17
|