Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions utility/MinMaxHelpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 Sean Nowlan
// Copyright (c) 2014-2019 Josh Blum
// SPDX-License-Identifier: BSL-1.0

#pragma once

#include <algorithm>
#include <cmath> //abs
#include <complex>

template <typename T>
T getMin(const T& a, const T& b) {
return std::min<T>(a, b);
}

template <typename T>
T getMax(const T& a, const T& b) {
return std::max<T>(a, b);
}

template <typename T>
std::complex<T> getMin(const std::complex<T>& a, const std::complex<T>& b) {
return std::min<T>(std::abs(a), std::abs(b));
}

template <typename T>
std::complex<T> getMax(const std::complex<T>& a, const std::complex<T>& b) {
return std::max<T>(std::abs(a), std::abs(b));
}
61 changes: 59 additions & 2 deletions utility/SignalProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <iostream>
#include <algorithm> //min/max
#include <chrono>
#include <limits>
#include "MinMaxHelpers.hpp"

/***********************************************************************
* |PothosDoc Signal Probe
Expand All @@ -20,11 +22,15 @@
*
* The calculation for value can be, the last seen value,
* the RMS (root mean square) over the last buffer,
* or the mean (average value) over the last buffer.
* the mean (average value) over the last buffer,
* the minimum value (real) or absolute value (complex) over the last buffer,
* the maximum value (real) or absolute value (complex) over the last buffer,
* the minimum absolute value (magnitude) over the last buffer,
* or the maximum absolute value (magnitude) over the last buffer.
*
* |category /Utility
* |category /Event
* |keywords rms average mean
* |keywords rms average mean min minimum max maximum
* |alias /blocks/stream_probe
*
* |param dtype[Data Type] The data type consumed by the stream probe.
Expand All @@ -40,6 +46,10 @@
* |option [Value] "VALUE"
* |option [RMS] "RMS"
* |option [Mean] "MEAN"
* |option [Min] "MIN"
* |option [Max] "MAX"
* |option [Min Abs] "MINABS"
* |option [Max Abs] "MAXABS"
*
* |param rate How many calculations per second?
* The probe will perform a calculation at most this many times per second.
Expand Down Expand Up @@ -158,6 +168,53 @@ class SignalProbe : public Pothos::Block
mean /= N;
_value = mean;
}
else if (_mode == "MIN")
{
ProbeType minimum = std::numeric_limits<double>::max();
ProbeType x_n;
for (size_t n = 0; n < N; n++)
{
x_n = Pothos::Util::fromQ<ProbeType>(x[n], 0);
minimum = getMin(minimum, x_n);
}
_value = minimum;
}
else if (_mode == "MAX")
{
ProbeType maximum = std::numeric_limits<double>::lowest();
ProbeType x_n;
for (size_t n = 0; n < N; n++)
{
x_n = Pothos::Util::fromQ<ProbeType>(x[n], 0);
maximum = getMax(maximum, x_n);
}
_value = maximum;
}

else if (_mode == "MINABS")
{
double minimum = std::numeric_limits<double>::max();
ProbeType x_n;
for (size_t n = 0; n < N; n++)
{
x_n = Pothos::Util::fromQ<ProbeType>(x[n], 0);
const double mag = std::abs(x_n);
minimum = std::min<double>(minimum, mag);
}
_value = minimum;
}
else if (_mode == "MAXABS")
{
double maximum = std::numeric_limits<double>::lowest();
ProbeType x_n;
for (size_t n = 0; n < N; n++)
{
x_n = Pothos::Util::fromQ<ProbeType>(x[n], 0);
const double mag = std::abs(x_n);
maximum = std::max<double>(maximum, mag);
}
_value = maximum;
}

this->emitSignal("valueChanged", _value);
}
Expand Down