I am sorry for the probably pretty basic question (and not very specific title) – still new to DSP and I have no idea what causes my problem.
I am using gnu radio companion and trying to a rather simple task: I have two signals need to decide which one is currently active, so my idea was to write a simple python block with two inputs and one output. Compute the energy of both signals and assign the stronger signal two the output.
My problem is that my output signals differs from both input signals, which seems odd to me, since I do not modify it. I appended a screenshot of 3 waterfall sinks of the two input signals and the output signal.
This is the rather simple code of the python block. Since it is so simple I honestly do not even know where I could debug. I guess my fundamental understanding of signals is still capable of improvement.
import numpy as np
from gnuradio import gr
import pmt
class blk(gr.sync_block): # other base classes are basic_block, decim_block, interp_block
def __init__(self): # only default arguments here
"""arguments to this function show up as parameters in GRC"""
gr.sync_block.__init__(
self,
name='Level 0', # will show up in GRC
in_sig=[np.complex64, np.complex64],
out_sig=[np.complex64]
)
# register message port
# self.message_port_register_out(pmt.intern('level_1'))
def work(self, input_items, output_items):
in0 = input_items[0][:]
in1 = input_items[1][:]
# check which signal has more energy
energy0 = np.sum((in0)**2)
energy1 = np.sum((in1)**2)
# if energy1 has more energy, signal's frequency is higher
if energy1 > energy0:
# send message
# self.message_port_pub(pmt.intern('level_1'), 8e5)
output_items[0][:] = in1
else:
output_items[0][:] = in0
return len(output_items[0])