2

I am building a GNURadio block in Python to convolve the input signal with a Root-raised-cosine signal. I have noticed that the input signal sent to the function general_work has a number of samples varying which is quite annoying for my purpose. Indeed, for an input signal of n_in samples and a Root-raised cosine filter of n samples, the output signal will be of length n_in+n-1 (property of convolved signals).

I cannot use an interpolation block because I do not know n_in and so I do not know the value of the interpolation factor (n_in+n-1)/n_in. So, I am using a general block of this form thanks to the gr_modtool provided :

import numpy as np
from gnuradio import gr

class Convolve(gr.basic_block):
"""
docstring for block Convolve
"""
n=45 #Number of samples in the Root-raised cosine signal
def __init__(self):
    gr.basic_block.__init__(self,
        name="Convolve",
        in_sig=[np.complex64],
        out_sig=[np.complex64])

def forecast(self, noutput_items, ninput_items_required):
    #setup size of input_items[i] for work call
    print("---------- Forecast function --------------")
    n_in = noutput_items-self.n+1
    if n_in<=0:
        ninput_items_required[0]=1
    else:
        ninput_items_required[0]=n_in
    print("n_in : ", n_in)
    print("ninput_items_required[0] : ", ninput_items_required[0])
    print("noutput_items : ", noutput_items)

def general_work(self, input_items, output_items):
    print("---------- General work function ----------------")
    output_items[0][:] = 1 #Output is not important for the example
    print("input_items[0] : ", len(input_items[0]))
    print("output_items[0] : ", len(output_items[0]))
    self.consume(0, len(input_items[0]))
    #self.consume_each(len(input_items[0]))
    return len(output_items[0])

In this example, I have chosen the number of samples of the root-raised cosine to be n=45. This prints me this in the Terminal:

---------- Forecast function --------------
('n_in : ', 4052)
('ninput_items_required[0] : ', 4052)
('noutput_items : ', 4096)
---------- Forecast function --------------
('n_in : ', 2004)
('ninput_items_required[0] : ', 2004)
('noutput_items : ', 2048)
---------- Forecast function --------------
('n_in : ', 980)
('ninput_items_required[0] : ', 980)
('noutput_items : ', 1024)
---------- Forecast function --------------
('n_in : ', 468)
('ninput_items_required[0] : ', 468)
('noutput_items : ', 512)
---------- Forecast function --------------
('n_in : ', 212)
('ninput_items_required[0] : ', 212)
('noutput_items : ', 256)
---------- Forecast function --------------
('n_in : ', 84)
('ninput_items_required[0] : ', 84)
('noutput_items : ', 128)
---------- Forecast function --------------
('n_in : ', 20)
('ninput_items_required[0] : ', 20)
('noutput_items : ', 64)
---------- Forecast function --------------
('n_in : ', -12)
('ninput_items_required[0] : ', 1)
('noutput_items : ', 32)
---------- Forecast function --------------
('n_in : ', -28)
('ninput_items_required[0] : ', 1)
('noutput_items : ', 16)
---------- Forecast function --------------
('n_in : ', -36)
('ninput_items_required[0] : ', 1)
('noutput_items : ', 8)
---------- Forecast function --------------
('n_in : ', -40)
('ninput_items_required[0] : ', 1)
('noutput_items : ', 4)
---------- Forecast function --------------
('n_in : ', -42)
('ninput_items_required[0] : ', 1)
('noutput_items : ', 2)
---------- Forecast function --------------
('n_in : ', -43)
('ninput_items_required[0] : ', 1)
('noutput_items : ', 1)
---------- Forecast function --------------
('n_in : ', 4052)
('ninput_items_required[0] : ', 4052)
('noutput_items : ', 4096)

It looks like the function Forecast is called several times to test different values of input and output lengths. It seems to work correctly but after that the general work function is called and the lengths of the input and output are in this example the same... This does not correspond to the values obtained with the Forecast function.

---------- General work function ----------------
('input_items[0] : ', 4096)
('output_items[0] : ', 4096)

Can somebody explain me why I do have same lengths signals in the general work function? How can I handle the lengths of the input and output signals more easily? Is there a more suitable way to handle the case where n_in is negative instead of this way :

    [...]
    if n_in<=0:
        ninput_items_required[0]=1
    else:
        ninput_items_required[0]=n_in
    [...]
Dylan
  • 31
  • 3

0 Answers0