Skip to content

Commit bb554fa

Browse files
argilomormj
authored andcommitted
blocks: Add exponential distribution to Message Strobe Random-Delay
Signed-off-by: Clayton Smith <[email protected]>
1 parent 99ef9a7 commit bb554fa

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

gr-blocks/grc/blocks_message_strobe_random.block.yml

+4-9
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ parameters:
1010
- id: dist
1111
label: Distribution
1212
dtype: enum
13-
options: [blocks.STROBE_POISSON, blocks.STROBE_UNIFORM, blocks.STROBE_GAUSSIAN]
14-
option_labels: [Poisson, Uniform, Gaussian]
13+
options: [blocks.STROBE_EXPONENTIAL, blocks.STROBE_UNIFORM, blocks.STROBE_GAUSSIAN, blocks.STROBE_POISSON]
14+
option_labels: [Exponential, Uniform, Gaussian, Poisson]
1515
- id: mean
1616
label: Mean (ms)
1717
dtype: real
1818
default: '1000'
1919
- id: std
20-
label: Std (ms)
20+
label: ${ 'Max. Deviation (ms)' if dist == 'blocks.STROBE_UNIFORM' else 'Std. Deviation (ms)' }
2121
dtype: real
2222
default: '100'
23+
hide: ${ 'none' if dist in ('blocks.STROBE_UNIFORM', 'blocks.STROBE_GAUSSIAN') else 'all' }
2324

2425
inputs:
2526
- domain: message
@@ -42,10 +43,4 @@ templates:
4243
- set_mean(${mean})
4344
- set_std(${std})
4445

45-
documentation: |-
46-
Please note some peculiarities below:
47-
- poisson does not care about your std
48-
- gaussian operates as expected
49-
- uniform is actually of the range (mean-std, mean+std) - thus we are lying and it is not actually an std here
50-
5146
file_format: 1

gr-blocks/include/gnuradio/blocks/message_strobe_random.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ namespace blocks {
2323
typedef enum {
2424
STROBE_POISSON = 1,
2525
STROBE_GAUSSIAN = 2,
26-
STROBE_UNIFORM = 3
26+
STROBE_UNIFORM = 3,
27+
STROBE_EXPONENTIAL = 4
2728
} message_strobe_random_distribution_t;
2829

2930
/*!
@@ -32,8 +33,8 @@ typedef enum {
3233
*
3334
* \details
3435
35-
* Takes a PMT message and sends it out every at random
36-
* intervals. The interval is basedon a random distribution, \p
36+
* Takes a PMT message and sends it out at random
37+
* intervals. The interval is based on a random distribution, \p
3738
* dist, with specified mean (\p mean_ms) and variance (\p
3839
* std_ms). Useful for testing/debugging the message system.
3940
*/
@@ -49,9 +50,13 @@ class BLOCKS_API message_strobe_random : virtual public block
4950
* mean_ms and standard deviation \p std_ms.
5051
*
5152
* \param msg The message to send as a PMT.
52-
* \param dist The random distribution from which to draw events.
53-
* \param mean_ms The mean of the distribution.
54-
* \param std_ms The standard deviation of the distribution.
53+
* \param dist The random distribution from which to draw the time between
54+
* events.
55+
* \param mean_ms The mean of the distribution, in milliseconds.
56+
* \param std_ms The standard deviation of the Gaussian distribution,
57+
* or the maximum absolute deviation of the Uniform
58+
* distribution, in milliseconds. This argument is ignored
59+
* for other distributions.
5560
*/
5661
static sptr make(pmt::pmt_t msg,
5762
message_strobe_random_distribution_t dist,

gr-blocks/lib/message_strobe_random_impl.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ message_strobe_random_impl::message_strobe_random_impl(
4444
pd(d_mean_ms),
4545
nd(d_mean_ms, d_std_ms),
4646
ud(d_mean_ms - d_std_ms, d_mean_ms + d_std_ms),
47+
ed(1.0f / d_mean_ms),
4748
d_finished(false),
4849
d_msg(msg),
4950
d_port(pmt::mp("strobe"))
@@ -62,6 +63,7 @@ void message_strobe_random_impl::set_mean(float mean_ms)
6263
pd = std::poisson_distribution<>(d_mean_ms);
6364
nd = std::normal_distribution<>(d_mean_ms, d_std_ms);
6465
ud = std::uniform_real_distribution<>(d_mean_ms - d_std_ms, d_mean_ms + d_std_ms);
66+
ed = std::exponential_distribution<>(1.0f / d_mean_ms);
6567
}
6668

6769
float message_strobe_random_impl::mean() const { return d_mean_ms; }
@@ -77,12 +79,13 @@ long message_strobe_random_impl::next_delay()
7779
{
7880
switch (d_dist) {
7981
case STROBE_POISSON:
80-
// return d_variate_poisson->operator()();
8182
return static_cast<long>(pd(d_rng));
8283
case STROBE_GAUSSIAN:
8384
return static_cast<long>(nd(d_rng));
8485
case STROBE_UNIFORM:
8586
return static_cast<long>(ud(d_rng));
87+
case STROBE_EXPONENTIAL:
88+
return static_cast<long>(ed(d_rng));
8689
default:
8790
throw std::runtime_error(
8891
"message_strobe_random_impl::d_distribution is very unhappy with you");

gr-blocks/lib/message_strobe_random_impl.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class BLOCKS_API message_strobe_random_impl : public message_strobe_random
2929
std::poisson_distribution<> pd; //(d_mean_ms);
3030
std::normal_distribution<> nd; //(d_mean_ms, d_std_ms);
3131
std::uniform_real_distribution<> ud; //(d_mean_ms - d_std_ms, d_mean_ms + d_std_ms);
32+
std::exponential_distribution<> ed; //(1.0f / d_mean_ms);
3233
gr::thread::thread d_thread;
3334
std::atomic<bool> d_finished;
3435
pmt::pmt_t d_msg;

gr-blocks/python/blocks/bindings/message_strobe_random_python.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/* BINDTOOL_GEN_AUTOMATIC(0) */
1515
/* BINDTOOL_USE_PYGCCXML(0) */
1616
/* BINDTOOL_HEADER_FILE(message_strobe_random.h) */
17-
/* BINDTOOL_HEADER_FILE_HASH(a759e6e0483f67da0e1a9bdf8344f16e) */
17+
/* BINDTOOL_HEADER_FILE_HASH(baaacfe399a27ddc18d1012195ac4d34) */
1818
/***********************************************************************************/
1919

2020
#include <pybind11/complex.h>
@@ -86,9 +86,10 @@ void bind_message_strobe_random(py::module& m)
8686

8787
py::enum_<::gr::blocks::message_strobe_random_distribution_t>(
8888
m, "message_strobe_random_distribution_t")
89-
.value("STROBE_POISSON", ::gr::blocks::STROBE_POISSON) // 1
90-
.value("STROBE_GAUSSIAN", ::gr::blocks::STROBE_GAUSSIAN) // 2
91-
.value("STROBE_UNIFORM", ::gr::blocks::STROBE_UNIFORM) // 3
89+
.value("STROBE_POISSON", ::gr::blocks::STROBE_POISSON) // 1
90+
.value("STROBE_GAUSSIAN", ::gr::blocks::STROBE_GAUSSIAN) // 2
91+
.value("STROBE_UNIFORM", ::gr::blocks::STROBE_UNIFORM) // 3
92+
.value("STROBE_EXPONENTIAL", ::gr::blocks::STROBE_EXPONENTIAL) // 4
9293
.export_values();
9394

9495
py::implicitly_convertible<int, ::gr::blocks::message_strobe_random_distribution_t>();

gr-zeromq/examples/zmq_msg.grc

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ blocks:
4545
affinity: ''
4646
alias: ''
4747
comment: ''
48-
dist: blocks.STROBE_POISSON
48+
dist: blocks.STROBE_EXPONENTIAL
4949
maxoutbuf: '0'
5050
mean: '100'
5151
minoutbuf: '0'

0 commit comments

Comments
 (0)