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/Blo..., 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 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 I missing a key part of creating a source block? Also, the reason I don't use a file source is that the stream I am trying to create is dependent upon the time of day, so pulling it from a file source will mean that it is delayed somewhat. I will eventually want to transmit this data as well, not just put it in a file sink. Thanks, Anisha
on 2012-07-18 20:33
on 2012-07-19 09:48
On Wed, Jul 18, 2012 at 02:32:28PM -0400, Anisha Gorur wrote: > 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 I > missing a key part of creating a source block? Also, the reason I don't use a > file source is that the stream I am trying to create is dependent upon the time > of day, so pulling it from a file source will mean that it is delayed somewhat. > I will eventually want to transmit this data as well, not just put it in a file > sink. GrExtras is really a test to figure out who's amazing at Python. I already failed once (same prob): http://lists.gnu.org/archive/html/discuss-gnuradio... MB -- Karlsruhe Institute of Technology (KIT) Communications Engineering Lab (CEL) Dipl.-Ing. Martin Braun Research Associate Kaiserstraße 12 Building 05.01 76131 Karlsruhe Phone: +49 721 608-43790 Fax: +49 721 608-46071 www.cel.kit.edu KIT -- University of the State of Baden-Württemberg and National Laboratory of the Helmholtz Association
on 2012-07-19 16:31
Thanks for the response! I can now see that output_items is getting properly filled, however, when I try to display the file, I'm still getting zero. Besides a throttle is there a way to control the frequency of the random numbers or whatever source I am creating? Thanks, Anisha
on 2012-07-19 20:14
On 07/18/2012 11:32 AM, Anisha Gorur wrote: > 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
on 2012-07-19 20:29
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
on 2012-07-19 20:45
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 2012-07-19 21:55
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)
on 2012-07-19 22:04
Sorry, just to clarify, I get that error unless I fill output_items completely, no matter the length of x. Thanks, Anisha
on 2012-07-19 22:47
> 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
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.