Forum: GNU Radio Handling Messages

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
799af3731924b50bcfd74a41e5c813fa?d=identicon&s=25 ali siddiqi (Guest)
on 2009-05-21 06:38
(Received via mailing list)
Attachment: msg_pd.py (2 KB)
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,
799af3731924b50bcfd74a41e5c813fa?d=identicon&s=25 ali siddiqi (Guest)
on 2009-05-21 17:35
(Received via mailing list)
Attachment: msg_pd.py (2 KB)
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,
781e96b7bd64e8833d71e3914cb1594a?d=identicon&s=25 Michael Dickens (Guest)
on 2009-05-21 20:06
(Received via mailing list)
Hi Ali - I think the issue is that the output of the C2M is of
item_size 'fftsize', whereas the message_sink has item_size of
'gr.sizeof_float'.  Try incorporating the 'gr.vector_to_stream' you
created between the C2M and the message_sink. - MLD
This topic is locked and can not be replied to.