From e836a283bd4c7799166b2c0bb3383df13f3d10e6 Mon Sep 17 00:00:00 2001 From: Markus Schmidl Date: Sat, 18 May 2024 16:56:33 +0200 Subject: [PATCH] do averaging over one second for the signal stregth --- README.md | 3 +-- include/config.h | 11 +++-------- src/tetra-receiver.cpp | 15 +++++---------- test/config_test.cpp | 4 ---- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 36e7498..26bd5a5 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Therefore this application supports multiple stages of decimation. The config has mandatory global arguments `CenterFrequency`, `DeviceString` and `SampleRate` for the SDR. The optional argumens `RFGain`, `IFGain` and `BBGain` are for setting the gains of the SDR, by default these are zero. -Specify an optional table with the name `Prometheus` and the values `Host`, `Port` and `PollInterval` to send metrics about the currently received signal strength to a prometheus server. +Specify an optional table with the name `Prometheus` and the values `Host` and `Port` to send metrics about the currently received signal strength to a prometheus server. If a table specifies `Frequency`, `Host` and `Port`, the signal is directly decoded from the SDR. If it is specified in a subtable, it is decoded from the decimated signal described by the associtated table. @@ -58,7 +58,6 @@ BBGain = unsigned int (default 0) [Prometheus] Host = "string" (default 127.0.0.1) Port = unsigned int (default 9010) -PollInterval = unsigned int (in seconds) [DecimateA] Frequency = unsigned int diff --git a/include/config.h b/include/config.h index 35bb775..d6a5a57 100644 --- a/include/config.h +++ b/include/config.h @@ -148,19 +148,15 @@ class Prometheus { const std::string host_; /// the port to which prometheus is sending data to const uint16_t port_; - /// the polling interval of prometheus - unsigned int polling_interval_; Prometheus() = delete; /// The prometheus exporter to we want to send the metrics /// \param host the host to which prometheus is sending data /// \param port the port to which prometheus is sending data - /// \param polling_interval the interval at which data is sent - Prometheus(std::string host, const uint16_t port, const unsigned polling_interval) + Prometheus(std::string host, const uint16_t port) : host_(std::move(host)) - , port_(port) - , polling_interval_(polling_interval){}; + , port_(port){}; }; class TopLevel { @@ -222,9 +218,8 @@ template <> struct from> { static auto from_toml(const value& v) -> std::unique_ptr { const std::string prometheus_host = find_or(v, "Host", config::kDefaultPrometheusHost); const uint16_t prometheus_port = find_or(v, "Port", config::kDefaultPrometheusPort); - const unsigned int polling_interval = find(v, "PollInterval"); - return std::make_unique(prometheus_host, prometheus_port, polling_interval); + return std::make_unique(prometheus_host, prometheus_port); } }; diff --git a/src/tetra-receiver.cpp b/src/tetra-receiver.cpp index 86bc7c2..97caa5a 100644 --- a/src/tetra-receiver.cpp +++ b/src/tetra-receiver.cpp @@ -50,8 +50,6 @@ class ApplicationData { gr::top_block_sptr tb = nullptr; /// the optional prometheus exporter std::shared_ptr exporter = nullptr; - /// the polling interval of the exporter - unsigned int polling_interval = 0; }; class GnuradioBuilder { @@ -111,14 +109,12 @@ class GnuradioBuilder { {{"frequency", std::to_string(stream.spectrum_.center_frequency_)}, {"name", stream.name_}}); auto mag_squared = gr::blocks::complex_to_mag_squared::make(); - // low pass filter the signal based on the polling interval so we adhear to nyquist - double cutoff_freq = 1.0 / static_cast(2 * app_data.polling_interval); - auto downsampler_taps = - gr::filter::firdes::low_pass(/*gain=*/1.0, /*sampling_freq=*/stream.spectrum_.sample_rate_, - /*cutoff_freq=*/cutoff_freq, /*transition_width=*/cutoff_freq * 0.2); + // averaging filter over one second + unsigned tap_size = stream.spectrum_.sample_rate_; + std::vector averaging_filter(/*count=*/tap_size, /*alloc=*/1.0 / tap_size); // do not decimate directly to the final frequency, since there will be some jitter - unsigned decimation = stream.spectrum_.sample_rate_ * app_data.polling_interval / 10; - auto fir = gr::filter::fir_filter_fff::make(/*decimation=*/decimation, downsampler_taps); + unsigned decimation = tap_size / 10; + auto fir = gr::filter::fir_filter_fff::make(/*decimation=*/decimation, averaging_filter); auto populator = gr::prometheus::PrometheusGaugePopulator::make(/*gauge=*/stream_signal_strength); tb->connect(xlat, 0, mag_squared, 0); @@ -161,7 +157,6 @@ class GnuradioBuilder { if (top.prometheus_) { std::string prometheus_addr = top.prometheus_->host_ + ":" + std::to_string(top.prometheus_->port_); app_data.exporter = std::make_shared(prometheus_addr); - app_data.polling_interval = top.prometheus_->polling_interval_; } // setup osmosdr source diff --git a/test/config_test.cpp b/test/config_test.cpp index 29da6b7..8ad3f0f 100644 --- a/test/config_test.cpp +++ b/test/config_test.cpp @@ -101,7 +101,6 @@ TEST(config /*unused*/, TopLevel_prometheus_default /*unused*/) { SampleRate = 60000 [Prometheus] - PollInterval = 10 )"_toml; const config::TopLevel t = toml::get(config_object); @@ -111,7 +110,6 @@ TEST(config /*unused*/, TopLevel_prometheus_default /*unused*/) { EXPECT_EQ(t.prometheus_->host_, config::kDefaultPrometheusHost); EXPECT_EQ(t.prometheus_->port_, config::kDefaultPrometheusPort); - EXPECT_EQ(t.prometheus_->polling_interval_, 10); } TEST(config /*unused*/, TopLevel_prometheus_set /*unused*/) { @@ -123,7 +121,6 @@ TEST(config /*unused*/, TopLevel_prometheus_set /*unused*/) { [Prometheus] Host = "127.0.0.2" Port = 4200 - PollInterval = 20 )"_toml; const config::TopLevel t = toml::get(config_object); @@ -133,7 +130,6 @@ TEST(config /*unused*/, TopLevel_prometheus_set /*unused*/) { EXPECT_EQ(t.prometheus_->host_, "127.0.0.2"); EXPECT_EQ(t.prometheus_->port_, 4200); - EXPECT_EQ(t.prometheus_->polling_interval_, 20); } TEST(config /*unused*/, TopLevel_valid_parser /*unused*/) {