""" Embedded Python Blocks: Each time this file is saved, GRC will instantiate the first class it finds to get ports and parameters of your block. The arguments to __init__ will be the parameters. All of them are required to have default values! """ import numpy as np from gnuradio import gr class blk(gr.sync_block): # other base classes are basic_block, decim_block, interp_block """Embedded Python Block example - a simple multiply const""" def __init__(self, center_freq=1850e6, fft_size=1024, freq_range=5e6): # only default arguments here """arguments to this function show up as parameters in GRC""" gr.sync_block.__init__( self, name='Embedded Python Block', # will show up in GRC in_sig=[np.short], out_sig=[np.float32] ) # if an attribute with the same name as a parameter is found, # a callback is registered (properties work, too). self.center_freq = center_freq self.fft_size = fft_size self.freq_range = freq_range def work(self, input_items, output_items): if (input_items[0] >= (self.fft_size/2)).all(): output_items[0][:] = (self.freq_range * (input_items[0] - self.fft_size/2) / self.fft_size + self.center_freq - self.freq_range/2) / 1e6 else: output_items[0][:] = (self.freq_range * input_items[0] / self.fft_size + self.center_freq) / 1e6 return len(output_items[0])