3

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?

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94

2 Answers2

3

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.
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • Thank you for this reply. Actually I'm using `gr_modtool`, and it is a great tool. But also, I think that I should try to have a better understanding of how the scheduler manage the input and output items via the `Work()` and `general_work()` methods. – Eva Aleksey Mar 29 '16 at 20:46
1

Considering that the question was asked 4 years ago and that there has been many changes in GNU Radio since then, I want to add to the answer that now this is possible to do with the Patterned Interleaver block.

patterned_interleaver_image

This block works the following way: it receives inputs in the ports to the left and outputs a single interleaved pattern in the port that is to the right. So let's imagine a block with 2 inputs, V1 and V2:

V1 = [0,1,0,0,1,1]

V2 = [1,1,1,0,1,0]

Suppose we want the output to be the first 2 bits of V1 followed by the first 2 bits of V2 followed by the next 2 bits of V1 and then the next 2 bits of V2 and so on...that is, we want the output to be

Vo = [0,1,1,1,0,0,1,0,1,1,1,0].

In order to accomplish this we go to the properties of the Patterned Interleaver block which looks like this:

patterned_interleaver_properties

The Pattern field allows us to control the order in which the bits in the input ports will be interleaved. By default they are in [0,0,1,1] meaning that the block will take 2 bits from input port 0 followed by 2 bits from input port 1. The corresponding output will be

[0,1,1,1,0,0,1,0,1,1,1,0],

that is, the first 2 bits of V1 followed by the first 2 bits of V2 and then the next 2 bits of V1, etc.

Let's see another example. In case the Pattern field is set to [0,0,1,1,1,0] the output will be 2 bits from input port 0 followed by 3 bits from input port 1 and then 1 bit from input port 0. In the output we will obtain [0,1,1,1,1,0,0,1,0,1,0,0].

Lastly, the Pattern field is also used to determine the number of input ports. If the Pattern field is [0,0,1,2] we will see that another input port is added to the block.

patterned_interleaver_3_inputs