Skip to content

Commit

Permalink
do averaging over one second for the signal stregth
Browse files Browse the repository at this point in the history
  • Loading branch information
marenz2569 committed May 18, 2024
1 parent a7c1129 commit e836a28
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
11 changes: 3 additions & 8 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -222,9 +218,8 @@ template <> struct from<std::unique_ptr<config::Prometheus>> {
static auto from_toml(const value& v) -> std::unique_ptr<config::Prometheus> {
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<unsigned int>(v, "PollInterval");

return std::make_unique<config::Prometheus>(prometheus_host, prometheus_port, polling_interval);
return std::make_unique<config::Prometheus>(prometheus_host, prometheus_port);
}
};

Expand Down
15 changes: 5 additions & 10 deletions src/tetra-receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class ApplicationData {
gr::top_block_sptr tb = nullptr;
/// the optional prometheus exporter
std::shared_ptr<PrometheusExporter> exporter = nullptr;
/// the polling interval of the exporter
unsigned int polling_interval = 0;
};

class GnuradioBuilder {
Expand Down Expand Up @@ -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<double>(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<float> 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);
Expand Down Expand Up @@ -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<PrometheusExporter>(prometheus_addr);
app_data.polling_interval = top.prometheus_->polling_interval_;
}

// setup osmosdr source
Expand Down
4 changes: 0 additions & 4 deletions test/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ TEST(config /*unused*/, TopLevel_prometheus_default /*unused*/) {
SampleRate = 60000
[Prometheus]
PollInterval = 10
)"_toml;

const config::TopLevel t = toml::get<config::TopLevel>(config_object);
Expand All @@ -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*/) {
Expand All @@ -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::TopLevel>(config_object);
Expand All @@ -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*/) {
Expand Down

0 comments on commit e836a28

Please sign in to comment.