Hi,

I am trying to make a flowgraph as given:

signal source --> stream2vector -->  fft -->  c2m --> msg_sink

If the size of fft is 4096, then I want to retrieve these 4096 points in
python and then do simple maths and logic based on some of the values within
these 4096 points within python.

And then based on the  result, I want to initiate another flowgraph!

Currently, there is an error between the interface between c2m and msg_sink.

The code is:

class top(gr.top_block):
        def __init__(self):
            gr.top_block.__init__(self)

            ##################################################
            # Variables
            ##################################################
            self.samp_rate = samp_rate = 32000

            ##################################################
            # Blocks
            ##################################################
            self.sigsource = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE,
1000, 10, 0)
            self.sigsource1 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE,
2000, 20, 0)
            self.sigadder = gr.add_vcc(1)

            fftsize = 4096

            mywin = window.blackmanharris(fftsize)

            fft = gr.fft_vcc(fftsize, True, mywin)

            c2m = gr.complex_to_mag(fftsize)

            s2f1 = gr.short_to_float()

            s2f2 = gr.short_to_float()

            # Vector Sink/Source

            ss2v = gr.stream_to_vector(gr.sizeof_gr_complex, fftsize)

            v2ss = gr.vector_to_stream(gr.sizeof_float, fftsize)

            # Message Settings

            self.qsize = 10

            self.msgq0 = gr.msg_queue(self.qsize) # queue amplitude

            # Message sink

            m_sink0 = gr.message_sink(gr.sizeof_float, self.msgq0, True)

            self.connect((self.sigsource, 0), (self.sigadder, 0))
            self.connect((self.sigsource1, 0), (self.sigadder, 1))

            self.connect(self.sigadder, ss2v, fft, c2m, m_sink0)


def main ():

        # Start Top Block
        tb = top()

        #Start Flowgraph
        tb.start()

        # Read first message

        amsg = tb.msgq0.delete_head() # get first amplitude message

        raw_a = amsg.to_string() # raw amplitude data

        a_data = numpy.fromstring(raw_a, numpy.float32, count =
int(amsg.arg2())) # converted amplitude data

        print "Data in sink is: ",a_data

        tb.stop()



if __name__ == '__main__':

    main ()


Regards,
from gnuradio import gr, gru, eng_notation, optfir, window
import numpy

class top(gr.top_block):
    	def __init__(self):
		gr.top_block.__init__(self)
       
	        ##################################################
	        # Variables
	        ##################################################
	        self.samp_rate = samp_rate = 32000
	
	        ##################################################
	        # Blocks
	        ##################################################
	        self.sigsource = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 10, 0)
	        self.sigsource1 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 2000, 20, 0)
	        self.sigadder = gr.add_vcc(1)
	
	        fftsize = 4096

                mywin = window.blackmanharris(fftsize)

                fft = gr.fft_vcc(fftsize, True, mywin)

                c2m = gr.complex_to_mag(fftsize)
       
                s2f1 = gr.short_to_float()

                s2f2 = gr.short_to_float()

                # Vector Sink/Source

                ss2v = gr.stream_to_vector(gr.sizeof_gr_complex, fftsize)

                v2ss = gr.vector_to_stream(gr.sizeof_float, fftsize)

                # Message Settings

                self.qsize = 10     

                self.msgq0 = gr.msg_queue(self.qsize) # queue amplitude

                # Message sink

                m_sink0 = gr.message_sink(gr.sizeof_float, self.msgq0, True)
         
	        self.connect((self.sigsource, 0), (self.sigadder, 0))
	        self.connect((self.sigsource1, 0), (self.sigadder, 1))

                self.connect(self.sigadder, ss2v, fft, c2m, m_sink0)


def main ():

        # Start Top Block
        tb = top()

        #Start Flowgraph
        tb.start()

        # Read first message

        amsg = tb.msgq0.delete_head() # get first amplitude message

        raw_a = amsg.to_string() # raw amplitude data

        a_data = numpy.fromstring(raw_a, numpy.float32, count = int(amsg.arg2())) # converted amplitude data

 	print "Data in sink is: ",a_data
   
        tb.stop()

       

if __name__ == '__main__':

    main ()
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to