Forum: GNU Radio testing block written in block

61affa9cfec00aa4c05bcb475fc64326?d=identicon&s=25 sreena p h (Guest)
on 2014-06-18 11:01
(Received via mailing list)
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)
D17685d174fee4ca258c75cce7bc2202?d=identicon&s=25 Marcus Müller (Guest)
on 2014-06-18 11:31
(Received via mailing list)
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
739a038d5a03d5448114b3615e2caedc?d=identicon&s=25 Activecat K. (activecat_k)
on 2014-06-18 12:01
(Received via mailing list)
On Wed, Jun 18, 2014 at 4:57 PM, sreena p h <sreena_ph@yahoo.in> 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.
2474e637cd95190b38f78b5655f795e2?d=identicon&s=25 Nowlan, Sean (Guest)
on 2014-06-18 15:15
(Received via mailing list)
From: discuss-gnuradio-bounces+sean.nowlan=gtri.gatech.edu@gnu.org
[mailto:discuss-gnuradio-bounces+sean.nowlan=gtri.gatech.edu@gnu.org] On
Behalf Of Activecat
Sent: Wednesday, June 18, 2014 5:59 AM
To: discuss-gnuradio@gnu.org
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
<sreena_ph@yahoo.in<mailto:sreena_ph@yahoo.in>> 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
739a038d5a03d5448114b3615e2caedc?d=identicon&s=25 Activecat K. (activecat_k)
on 2014-06-19 05:37
(Received via mailing list)
On Wed, Jun 18, 2014 at 9:14 PM, Nowlan, Sean
<Sean.Nowlan@gtri.gatech.edu>
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;
    }
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.