I am trying to create a block that compare 2 values from a vector source and return the maximum index. In general, my vector source will be a set of values [0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0]. I will compare the first two values. The expected result should be 1. When i tried to run the code, it returns with index error: index 1 is out of bound for axis 0 with size 1. Where does this error come from?
Is there any way to check the array size within GNUradio? Thanks in advance
class blk(gr.sync_block): # other base classes are basic_block, decim_block, interp_block
def __init__(self, FFT_size = 32, subchannel1 = 0, subchannel2 = 1): # only default arguments here
"""arguments to this function show up as parameters in GRC"""
gr.sync_block.__init__(
self,
name='Peak Detection', # will show up in GRC
in_sig=[(np.float32, FFT_size)],
out_sig=[np.float32]
)
# if an attribute with the same name as a parameter is found,
# a callback is registered (properties work, too).
self.FFT_size = FFT_size
self.subchannel1 = subchannel1
self.subchannel2 = subchannel2
def work(self, input_items, output_items):
for portIndex in range(len(input_items)):
for vectorIndex in range(len(input_items[0])):
channel1 = input_items[0][self.subchannel1]
channel2 = input_items[0][self.subchannel2]
for sampleIndex in range(len(input_items[0][vectorIndex])):
array = [channel1[sampleIndex], channel2[sampleIndex]]
output_items[0][:] = np.argmax(array)
return len(output_items[0])