discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Creating a signal source block using Python


From: Gerald Baier
Subject: Re: [Discuss-gnuradio] Creating a signal source block using Python
Date: Thu, 19 Jul 2012 22:46:13 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

I was trying that earlier, however, I get this error from my code
output_items[0][:] = x #where x equals a numpy.complex64 array with a length of 32

ValueError: operands could not be broadcast together with shapes (4096) (32)
Try something like:

    n_processed = len(x)
    output_items[0][:n_processed] = x
    return n_processed

I hope that helps.

-Gerald


On Thu, Jul 19, 2012 at 2:44 PM, Josh Blum <address@hidden <mailto:address@hidden>> wrote:



    On 07/19/2012 11:28 AM, Anisha Gorur wrote:
    > It works now, thanks! It was a combination of a couple dumb
    errors on my
    > part. One last thing, I was wondering if there was a way to
    change the
    > length of output_items[0]? It is 4096 by default I believe.
    > Thanks,
    > Anisha

    The item length is basically randomly decided by the scheduler.
    However,
    you call set_output_multiple(x) and you will be guaranteed to get x*N
    items where N is an integer. Also, you dont have to actually fill all
    items, just fill the number you plan to produce.

    -josh

    >
    > On Thu, Jul 19, 2012 at 2:13 PM, Josh Blum <address@hidden
    <mailto:address@hidden>> wrote:
    >
    >>
    >>
    >> On 07/18/2012 11:32 AM, Anisha Gorur wrote:
    >>> Hello All,
    >>>
    >>> I've been attempting to create my own source block in Python.
    I have been
    >>> reading the blocks coding guide here:
    >>>
    >>
    
https://github.com/guruofquality/grextras/wiki/Blocks-Coding-Guide#wiki-work-operation-modes
    >> ,
    >>> but so far my source only outputs zeros.
    >>> An outline of my code is as follows:
    >>>
    >>> class constSource(gr.block):
    >>> def __init__(self):
    >>>                  gr.block.__init__(self, name = "signal
    source", in_sig =
    >>> None,out_sig = [numpy.complex64])
    >>>
    >>> def work(self, input_items, output_items):
    >>>                num_output_items = len(output_items[0])
    >>>
    >>>          #I put the code to create what I want to stream here,
    the code
    >>> creates a numpy.complex64 array with a length of 32. I then return
    >>> num_output_items
    >>
    >>
    >> You didnt include the code, but I am guessing that you are not
    assigning
    >> anything to the output vector?
    >>
    >> numpy array assignment look like this
    >> output_items[0][some kind of index selection] = data
    >>
    >> Look closely at how the examples do this
    >>
    >> -josh
    >>
    >>>           return num_output_items
    >>>
    >>> I then write my constSource block to a file and I try to see
    the output
    >> of
    >>> the file using a scope sink, but it is just a constant stream
    of zeros.
    >> Am
    >>
    >>
    >> _______________________________________________
    >> Discuss-gnuradio mailing list
    >> address@hidden <mailto:address@hidden>
    >> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
    >>
    >
    >
    >




--
Anisha Gorur
Class of 2012
Electrical Engineering






reply via email to

[Prev in Thread] Current Thread [Next in Thread]