// Copyright 2020 Mobilinkd LLC. #pragma once #include "IirFilter.h" #include #include #include #include #include namespace mobilinkd { template struct CarrierDetect { using result_t = std::tuple; BaseIirFilter filter_; FloatType lock_; FloatType unlock_; bool locked_ = false; CarrierDetect(std::array const& b, std::array const& a, FloatType lock_level, FloatType unlock_level) : filter_(b, a), lock_(lock_level), unlock_(unlock_level) { } result_t operator()(FloatType value) { 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); } }; } // mobilinkd