I'm trying to implement a Python block that will take a signal (complex64
array of 1,024 values) and return a float32 array that includes the max,
min, and mean of the norm for the complex values.

So something with an input array of 1,024 complex elements and an output
array of 3 float elements. From my reading so far, I think I can use an
embedded basic Python block:

class blk(gr.basic_block):  # other base classes are basic_block,
> decim_block, interp_block
>     """Embedded Python Block example"""
>
>     def __init__(self, example_param=1.0):  # only default arguments here
>         """arguments to this function show up as parameters in GRC"""
>         gr.basic_block.__init__(
>             self,
>             name='Embedded Python Block',   # will show up in GRC
>             in_sig=[np.complex64],
>             out_sig=[np.float32]
>         )
>         # if an attribute with the same name as a parameter is found,
>         # a callback is registered (properties work, too).
>         self.example_param = example_param
>
>     def forecast(self, noutput_items, ninput_items_required=1024):
>         for i in range(len(ninput_items_required)):
>             ninput_items_required[i] = 1024
>
>     def general_work(self, input_items, output_items):
>
>         output_items[0] = np.zeros(3)
>         output_items[0][:] = [np.min(np.abs(input_items[0])),
> np.max(np.abs(input_items[0])), np.mean(np.abs(input_items[0]))]
>
>         print('{}: {}'.format(len(input_items[0]), output_items[0]))
>
>         return len(output_items[0])
>

This code runs. The print statement shows me that the data is getting in
(8,191 elements) and that it is correctly calculating the output_items[0]
vector.  However, when I try to hook up the output of the block to a GRC
number sink or time scope, I don't see anything at all. So it doesn't seem
to be passing anything back for another block to use.

Is there a better way for me to do this?  My intention is to turn this
simple block into a more complicated block that finds open channels from a
complex spectrum. So I'd be taking a 1,024 complex input and returning an
output with the open center frequency, bandwidth, and probability of being
unoccupied. Maybe the block can just pass messages back instead of an array
of values??

Thanks.
-Tony
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to