Skip to content

Commit 6b45a0d

Browse files
committed
/utility/signal_probe: add max and min magnitude options
1 parent f8a5fd0 commit 6b45a0d

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

utility/MinMaxHelpers.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2024 Sean Nowlan
2+
// Copyright (c) 2014-2019 Josh Blum
3+
// SPDX-License-Identifier: BSL-1.0
4+
5+
#include <algorithm>
6+
#include <complex>
7+
8+
template <typename T>
9+
T getMin(const T& a, const T& b) {
10+
return std::min<T>(a, b);
11+
}
12+
13+
template <typename T>
14+
T getMax(const T& a, const T& b) {
15+
return std::max<T>(a, b);
16+
}
17+
18+
template <typename T>
19+
std::complex<T> getMin(const std::complex<T>& a, const std::complex<T>& b) {
20+
return std::min<T>(std::abs(a), std::abs(b));
21+
}
22+
23+
template <typename T>
24+
std::complex<T> getMax(const std::complex<T>& a, const std::complex<T>& b) {
25+
return std::max<T>(std::abs(a), std::abs(b));
26+
}

utility/SignalProbe.cpp

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <iostream>
99
#include <algorithm> //min/max
1010
#include <chrono>
11+
#include <limits>
12+
#include "MinMaxHelpers.hpp"
1113

1214
/***********************************************************************
1315
* |PothosDoc Signal Probe
@@ -20,11 +22,15 @@
2022
*
2123
* The calculation for value can be, the last seen value,
2224
* the RMS (root mean square) over the last buffer,
23-
* or the mean (average value) over the last buffer.
25+
* the mean (average value) over the last buffer,
26+
* the minimum value (real) or absolute value (complex) over the last buffer,
27+
* the maximum value (real) or absolute value (complex) over the last buffer,
28+
* the minimum absolute value (magnitude) over the last buffer,
29+
* or the maximum absolute value (magnitude) over the last buffer.
2430
*
2531
* |category /Utility
2632
* |category /Event
27-
* |keywords rms average mean
33+
* |keywords rms average mean min minimum max maximum
2834
* |alias /blocks/stream_probe
2935
*
3036
* |param dtype[Data Type] The data type consumed by the stream probe.
@@ -40,6 +46,10 @@
4046
* |option [Value] "VALUE"
4147
* |option [RMS] "RMS"
4248
* |option [Mean] "MEAN"
49+
* |option [Min] "MIN"
50+
* |option [Max] "MAX"
51+
* |option [Min Abs] "MINABS"
52+
* |option [Max Abs] "MAXABS"
4353
*
4454
* |param rate How many calculations per second?
4555
* The probe will perform a calculation at most this many times per second.
@@ -158,6 +168,53 @@ class SignalProbe : public Pothos::Block
158168
mean /= N;
159169
_value = mean;
160170
}
171+
else if (_mode == "MIN")
172+
{
173+
ProbeType minimum = std::numeric_limits<double>::max();
174+
ProbeType x_n;
175+
for (size_t n = 0; n < N; n++)
176+
{
177+
x_n = Pothos::Util::fromQ<ProbeType>(x[n], 0);
178+
minimum = getMin(minimum, x_n);
179+
}
180+
_value = minimum;
181+
}
182+
else if (_mode == "MAX")
183+
{
184+
ProbeType maximum = std::numeric_limits<double>::lowest();
185+
ProbeType x_n;
186+
for (size_t n = 0; n < N; n++)
187+
{
188+
x_n = Pothos::Util::fromQ<ProbeType>(x[n], 0);
189+
maximum = getMax(maximum, x_n);
190+
}
191+
_value = maximum;
192+
}
193+
194+
else if (_mode == "MINABS")
195+
{
196+
double minimum = std::numeric_limits<double>::max();
197+
ProbeType x_n;
198+
for (size_t n = 0; n < N; n++)
199+
{
200+
x_n = Pothos::Util::fromQ<ProbeType>(x[n], 0);
201+
const double mag = std::abs(x_n);
202+
minimum = std::min<double>(minimum, mag);
203+
}
204+
_value = minimum;
205+
}
206+
else if (_mode == "MAXABS")
207+
{
208+
double maximum = std::numeric_limits<double>::lowest();
209+
ProbeType x_n;
210+
for (size_t n = 0; n < N; n++)
211+
{
212+
x_n = Pothos::Util::fromQ<ProbeType>(x[n], 0);
213+
const double mag = std::abs(x_n);
214+
maximum = std::max<double>(maximum, mag);
215+
}
216+
_value = maximum;
217+
}
161218

162219
this->emitSignal("valueChanged", _value);
163220
}

0 commit comments

Comments
 (0)