Testing block written in block

Hi

I’m new to GNU radio and is trying to develop my own block. I want to
develop a block that intake a vector and out put sum of the vector
elements. I used the out of tree module and followed tutorial using
python code. How should be the arguments of blocks.vector_source_f to be
given if i am inputting vector stream of four integers is used. the
python code and test file is given below.

Code:

def init(self, in_arg):
gr.sync_block.init(self,
name=“sream_ff”,
in_sig=[(numpy.float32, 4)],
out_sig=[numpy.float32])
def work(self, input_items, output_items):
in0 = input_items[0]
out = output_items[0]
# <+signal processing here+>
out[:] = sum(in0)*in_arg
return len(output_items[0])

Test code:

def test_001_t (self):
src_data = (([1,1,1,1],4), ([1,2,3,4],4))
expected_result = (8, 20)
src = blocks.vector_source_f(src_data)
fxn = sream_ff(2)
snk = blocks.vector_sink_f()
# set up fg
self.tb.connect(src, fxn)
self.tb.connect(fxn, snk)
self.tb.run ()
# check data
result_data = snk.data ()
self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)

Hi Sreena,

a few quick remarks:

  • where does in_arg come from?
  • in0 should be seen as a vector of vectors. It’s often useful to “print
    in0.shape”, if in0 is a numpy array
  • potential mistake: just returning len(input_items[0]). Be very aware
    of what the return value of a work call should be (i.e. the number of
    items produced). I think you meant to calculate but one sum, is that
    right?

Greetings,
Marcus

On Wed, Jun 18, 2014 at 4:57 PM, sreena p h [email protected] wrote:

Hi

I’m new to GNU radio and is trying to develop my own block. I want to
develop a block that intake a vector and out put sum of the vector
elements. I used the out of tree module and followed tutorial using python
code. How should be the arguments of blocks.vector_source_f to be given if
i am inputting vector stream of four integers is used. the python code and
test file is given below.

Does your intake vectors have fixed-length or variable length?

If they are variable length, then your sream_ff block won’t be very
useful
in graphical GRC flowgraph, because there the vector streams are usually
fixed-length.

If they are fixed-length, then your problem could be easily solved; just
create sream_ff as a decimator block.

From: [email protected]n.invalid
[mailto:[email protected]n.invalid] On
Behalf Of Activecat
Sent: Wednesday, June 18, 2014 5:59 AM
To: [email protected]
Cc: sreena p h
Subject: Re: [Discuss-gnuradio] testing block written in block

On Wed, Jun 18, 2014 at 4:57 PM, sreena p h
<[email protected]mailto:[email protected]> wrote:
Hi

I’m new to GNU radio and is trying to develop my own block. I want to
develop a block that intake a vector and out put sum of the vector
elements. I used the out of tree module and followed tutorial using
python code. How should be the arguments of blocks.vector_source_f to be
given if i am inputting vector stream of four integers is used. the
python code and test file is given below.

Does your intake vectors have fixed-length or variable length?

If they are variable length, then your sream_ff block won’t be very
useful in graphical GRC flowgraph, because there the vector streams are
usually fixed-length.
If they are fixed-length, then your problem could be easily solved; just
create sream_ff as a decimator block.

If you’d rather use stock GR blocks or you would like a flowgraph with
identical functionality, you can hook up a Vector to Stream block (with
num_items=vector_length) to an Integrate block (with
decimation=vector_length).


vector_length = 10
self.vec2stream = blocks.vector_to_stream(gr.sizeof_gr_complex,
vector_length)
self.integrate = blocks.integrate_cc(vector_length)
self.connect((self.vec2stream, 0), (self.integrate, 0))

Sean

On Wed, Jun 18, 2014 at 9:14 PM, Nowlan, Sean
[email protected]
wrote:

Sean

I agree, that the Integrate block is a decimator block that implement
this
perfectly.
Just that she may want to use integrate_ff rather than integrate_cc,
depending on her needs.
Also we are assuming that the intake vectors are fixed in length.

int
integrate_ff_impl::work(int noutput_items,
          gr_vector_const_void_star &input_items,
          gr_vector_void_star &output_items)
{
  const float *in = (const float *)input_items[0];
  float *out = (float *)output_items[0];

  for (int i = 0; i < noutput_items; i++) {
    out[i] = (float)0;
    for (int j = 0; j < d_decim; j++)
      out[i] += in[i*d_decim+j];
  }

  return noutput_items;
}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs