Hi 

I am detecting a weak signal, so I calculate spectra with GRC's FFT block,
and then I calculate an average over hundreds of spectra by using a
self-written embedded Python block.  

Within each run of the work-function of my Python block, 'input_items'
consists of several spectra, from 2 up to about 15. I am calculating the
average until the spectrum has good enough signal-to-noise ratio. 
When calculating the average, I am continuously plotting the average spectrum 
by using 'QT GUI vector sink'. There is no need to update the plot very 
quickly, so it is enough if the 'output_items' of the work-function consists
of only one spectrum, the current average spectrum. Thus, I want to use the 
basic block as the type of my Python block. 

Below you can find the basic elements of my Python block.
The 'output_items[0]' consists of only one vector, as it should be, because 

len(output_items[0]) = 1
and 
len(output_items[0][0]) = 1024

Then flowgraph runs without errors, but the plot of the spectra (QT GUI vector 
sink) shows only a flat line, so something is wrong.

I am using Gnuradio 3.9.5.0 (Python 3.8.10) in Ubuntu 20.04.4 LTS

Cheers, Kimmo 

--------------------------------------------------------

class Main_control(gr.basic_block):

    def __init__(self, vec_length=1024,..., parameter_n=N):
                       
        gr.basic_block.__init__(self,
            name="Averaging spectra",
            in_sig =  [(np.float32, vec_length)],
            out_sig = [(np.float32, vec_length)])        

        self.vec_length = vec_length
        ...
        self.parameter_n = parameter_n
        

    def general_work(self, input_items, output_items):
        # the average spectrum is calculated here, it is given in the  
        # vector 'average_spectrum', with a length of 1024. 
        
        output_items[0] = [average_spectrum] 
        self.consume(0, len(input_items[0]))   
        return 1
        
        

Reply via email to