Wed Jul 2 02:23:48 2014 options author window_size 1280, 1024 category Custom comment description _enabled True _coordinate (10, 10) _rotation 0 generate_options qt_gui hier_block_src_path .: id Embedded_Python_Example_IIR_Filter max_nouts 0 qt_qss_theme realtime_scheduling run_command {python} -u {filename} run_options prompt run True thread_safe_setters title variable comment _enabled True _coordinate (200, 28) _rotation 0 id samp_rate value 32E3 analog_noise_source_x amp 1 alias comment affinity _enabled True _coordinate (16, 136) _rotation 0 id analog_noise_source_x_0 maxoutbuf 0 minoutbuf 0 noise_type analog.GR_GAUSSIAN type float seed 0 blocks_throttle alias comment affinity _enabled True _coordinate (192, 148) _rotation 0 id blocks_throttle_0 ignoretag True maxoutbuf 0 minoutbuf 0 samples_per_second samp_rate type float vlen 1 epy_block alias _io_cache ('Embedded Python Block', 'blk', [('example_param', '1')], [('0', 'float')], [('0', 'float')], 'Embedded Python Block example - a simple multiply const', ['example_param']) _source_code """ 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, example_param=1): # 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.float32], 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 self.set_history(4) #Example: The comand set_history(4) appends the previous 4-1=3 items to the input buffer (input_items), while the 4'th item is the current value. Therefore, #input_items[0][3] is the beginning of the current input stream. #input_items[0][2] is one input older than the current input stream. #input_items[0][1] is one input older than input_items[0][2] #input_items[0][0] is one input older than input_items[0][1] self.outputbuffer = [0,0,0] #This is a local array that I define to store old output values. I need to set this up since there is not a set_history function to access old outputs (at least I cannot find such a function in GNU radio). self.feedforward_taps= 0.0736, 0.2208, 0.2208, 0.0736 #feedforward taps of IIR filter self.feedbacktaps= 1.0000, -0.9761, 0.8568, -0.2919 #feedback taps of IIR filter def work(self, input_items, output_items): #Here I create a new list called output_items_with_history, which appends the previous 3 items to the current output_items. The properties of this new list are as follows: #output_items_with_history[3] is the beginning of the current output stream. #output_items_with_history[2] is one output older than the current output stream. #output_items_with_history[1] is one output older than output_items_with_history[2] #output_items_with_history[0] is one input older than output_items_with_history[1] #To create output_items_with_history, I tried doing the following command: #output_items_with_history=self.outputbuffer+output_items[0][:]... but it doesn't work, so I came up with the following non-elegant way to create output_items_with_history: output_items_with_history=[0] output_items_with_history.extend(self.outputbuffer) output_items_with_history.extend(output_items[0][:]) output_items_with_history=output_items_with_history[1:] #Implement IIR difference equation to filter. Keep in mind that output_items_with_history[3] is the beginning of the current output stream, and input_items[0][3] is the beginning of the current input stream. for i in range(0, len(output_items_with_history)-3): output_items_with_history[i+3]=input_items[0][i+3]*self.feedforward_taps[0]+input_items[0][i+2]*self.feedforward_taps[1]+input_items[0][i+1]*self.feedforward_taps[2]+input_items[0][i]*self.feedforward_taps[3]-output_items_with_history[i+2]*self.feedbacktaps[1]-output_items_with_history[i+1]*self.feedbacktaps[2]-output_items_with_history[i]*self.feedbacktaps[3] output_items[0][:]=output_items_with_history[3:] #Populate our output_items array end_of_the_road=len(output_items[0]) #length of output item vector self.outputbuffer[2]=output_items[0][end_of_the_road-1] #The last element of the outputbuffer is the last output item self.outputbuffer[1]=output_items[0][end_of_the_road-2]#The second to last element of the outputbuffer is the second to last output item self.outputbuffer[0]=output_items[0][end_of_the_road-3] #The third to last element of the outputbuffer is the third to last output item return len(output_items[0]) comment _enabled 1 example_param 1 _coordinate (368, 68) _rotation 0 id epy_block_0 iir_filter_xxx alias comment affinity _enabled 1 fftaps 0.0736, 0.2208, 0.2208, 0.0736 fbtaps 1.0000, -0.9761, 0.8568, -0.2919 _coordinate (368, 204) _rotation 0 id iir_filter_xxx_0 maxoutbuf 0 minoutbuf 0 oldstyle False type ffd qtgui_freq_sink_x autoscale True average 0.05 axislabels True bw samp_rate alias fc 0 comment ctrlpanel False affinity _enabled True fftsize 1024*4 _coordinate (632, 128) gui_hint _rotation 0 grid True id qtgui_freq_sink_x_0 legend True alpha1 1.0 color1 "blue" label1 width1 1 alpha10 1.0 color10 "dark blue" label10 width10 1 alpha2 1.0 color2 "red" label2 width2 1 alpha3 1.0 color3 "green" label3 width3 1 alpha4 1.0 color4 "black" label4 width4 1 alpha5 1.0 color5 "cyan" label5 width5 1 alpha6 1.0 color6 "magenta" label6 width6 1 alpha7 1.0 color7 "yellow" label7 width7 1 alpha8 1.0 color8 "dark red" label8 width8 1 alpha9 1.0 color9 "dark green" label9 width9 1 maxoutbuf 0 minoutbuf 0 name "" nconnections 2 showports True freqhalf True tr_chan 0 tr_level 0.0 tr_mode qtgui.TRIG_MODE_FREE tr_tag "" type float update_time 0.10 wintype firdes.WIN_BLACKMAN_hARRIS label Relative Gain ymax 10 ymin -140 units dB analog_noise_source_x_0 blocks_throttle_0 0 0 blocks_throttle_0 epy_block_0 0 0 blocks_throttle_0 iir_filter_xxx_0 0 0 epy_block_0 qtgui_freq_sink_x_0 0 0 iir_filter_xxx_0 qtgui_freq_sink_x_0 0 1