Search code examples
gnuradiognuradio-companion

Block types in GNU Radio


I am still learning GNU Radio and I have trouble understanding something about signal processing block type. I understand that if I create a block taking let say 2 samples in the input and output 4 samples, it will be an interpolator of 2.

But now, I would like to create a block which will be a framer. So, it will have two inputs and one output. The block will receives the n samples from the first input, then take m inputs from the second input and append to the samples received from input one, and then output them. In this case, my samples are supposed to be bytes.

How to proceed in this case please ? Am I taking the right path like that? Do any one know to proceed with this type of scenario?


Solution

  • Your case (input 0 and input 1 having different relative rates to the output) is not covered by the sync_block/interpolator/decimator "templates" that GNU Radio has, so you have to use the general block approach.

    Assuming you're familiar with gr_modtool¹, you can use it to add things like interpolator (relative rate >1), decimators (<1) and sync (=1) blocks:

    -t BLOCK_TYPE, --block-type=BLOCK_TYPE
                        One of sink, source, sync, decimator, interpolator,
                        general, tagged_stream, hier, noblock.
    

    But also note the general type. Using that, you can implement a block that doesn't have any restrictions on the relation between in- and output. That means that

    1. you will have to manually consume() items from the inputs, because the number of items you took from the input can no longer be derived by the number of output items, and
    2. you will have to implement a forecast method to tell the GNU Radio scheduler how much items you'll need for a given output.

    gr_modtool will give you a stub where you'll only have to add the right code!


    ¹ if you're not: It's introduced in the GNU Radio Guided Tutorials, part 3 or so, somethig that I think will be a quick and fun read to you.