Keep M in N
Decimate a stream, keeping the first M items out of every N starting after offset items.
Also see Keep 1 in N.
Parameters
(R): Run-time adjustable
- Type
- Supported types are: complex, float, int, short, and byte
- M (R)
- Number of items to take in block of items
- N (R)
- Block size in items
- Initial Offset
- Initial item offset into the stream
Example Flowgraph
Simple Flowgraph
This is a simple demonstration: Produce a cosine with a period of 32 items. From each 32 items, only output the first 17 – leading to a "jump".
The Throttle Block is there to limit the throughput of the flow graph; because 17 is not a divider of the number of points displayed in the Qt GUI Time Sink, this makes the visualization slowly "wander:
Non-Working Consume Rate Mismatch Flowgraph
Here is an example flowgraph using the Keep M in N Block. It has a vector source with values [1,2,3,4,5,6,7,8,9,10]
repeating.
This flowgraph will not run for very long, because at some (soon) point, the "Qt GUI Time Sink" will run out of input, as the visualization sink consumes the same amount of itmes from each of its inputs. Now, to produce, say, 10000 items, the "Keep M in N" block will have to consume 10000×N/M items. With M < N (inherently!), that means that the "Keep M in N" block consumes only M items from the "Vectors Source" when the "Qt GUI Time Sink" consumes N. That means that the output buffer of the "Vector Source" gets consumed (emptied) only by M samples per N outputs of the "Keep M in N", but "Qt GUI Time Sink" needs all N (of N). So, that Source's output buffer gets "stuck at empty", while the "Keep M in N"'s output buffer gets stuck at "full", and the flow graph stalls.
In this particular example, let's assume the output buffers are all 8192 items. When "Keep M in N" has produced 5462 items, it has consumed 5462 / 2 × 5 = 13655 items from the "Vector Source"'s output buffer. At the same time, the "Qt GUI Time Sink" consumed the same amount, 5461 items, from both its inputs. So, now the buffer reader of the "Keep M in M" is 13655 - 5462 items in advance, that's 8193 items. That, however, isn't possible – there's only 8192 items "space" in that buffer. So, GNU Radio can't call the "Qt GUI Time Sink"'s work
function, because there's no items on its second input – but it can also can't produce new output from the "Keep M in N" block, because the input to that block that would be necessary to generate that output could only be generated by the "Vector Source" if its output buffer wasn't full – but it's full, and can't be emptied, because "Qt GUI Time Sink" can't be invoked. A deadlock.
The block parameters are set to:
This results in the following output:
Source Files
- C++ files
- keep_m_in_n_impl.cc]
- Header files
- keep_m_in_n_impl.h
- Public header files
- keep_m_in_n.h
- Block definition
- blocks_keep_m_in_n.block.yml