# Continuous and Discrete data combine

**URL:** <https://www.ruby-forum.com/t/continuous-and-discrete-data-combine/234816>\
**Category:** GNU Radio\
**Created:** [August 7, 2014, 12:56pm UTC](https://www.ruby-forum.com/t/continuous-and-discrete-data-combine/234816 "2014-08-07T12:56:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [August 7, 2014, 12:56pm UTC](https://www.ruby-forum.com/t/continuous-and-discrete-data-combine/234816/1 "2014-08-07T12:56:21Z")

</div>

Hello,

Is there any way to combine continuous block (like audio source) and  
discrete block (like message source) ? Question 1

I using add block to add them together, but it failed. It work well when  
the discrete block output data like continuous block but discrete block  
means there is not output data continuous, it output data when something  
trigger.

Can I write a block which input is message and output is like float, and  
output will always generate like 32k samples but input doesn’t have 32k  
samples suppose this block is sync. Is there any solution ? Question 2

Question 1 is the main problem and Question 2 is I think it is a  
solution  
but not sure it work.

Thanks,

Jeff Guo

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 7, 2014, 1:08pm UTC](https://www.ruby-forum.com/t/continuous-and-discrete-data-combine/234816/2 "2014-08-07T13:08:15Z")

</div>

On 08/07/2014 12:54 PM, 奕佑 wrote:

> Hello,
> 
> Is there any way to combine continuous block (like audio source) and  
> discrete block (like message source) ? Question 1

Combine how? You can do that in your own blocks, sure. Maybe stream tags  
are what you want?

> I using add block to add them together, but it failed. It work well when  
> the discrete block output data like continuous block but discrete block  
> means there is not output data continuous, it output data when something  
> trigger.
> 
> Can I write a block which input is message and output is like float, and  
> output will always generate like 32k samples but input doesn’t have 32k  
> samples suppose this block is sync. Is there any solution ? Question 2

You can write a block who’s input is message and output is float. I  
didn’t really understand the rest of the question.

M

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 7, 2014, 2:54pm UTC](https://www.ruby-forum.com/t/continuous-and-discrete-data-combine/234816/3 "2014-08-07T14:54:51Z")

</div>

Hello Martin,

If you create a block which input is message and output is float. And  
message is arrive discrete just like packet in network, I want the block  
output port will output 0 when no message arrive at input port. Can I do  
that?

Why I ask this question is that I a while ago I trying to create a  
communication system which I defined and there has two kinds of channel  
one  
is control channel and the other one is message channel like the GSM  
system  
I think so, and I’m using FDD. And control channel is using gmsk  
modulation  
and message channel is using fm modulation because I just want to  
transmit  
audio, I using enough BW to avoid aliasing. After gmsk mod and fm mod, I  
add them together but result failed, because add block in gnuradio will  
wait when two input data and add one-by-one so if if port one data is  
much  
more then port two, and the add will hold port one data and wait port  
two  
data then add one-by-one.

I have recreate the same situation and past in the mail, it is python  
file  
and can test it to check the problem

Here is my setting : I have two source one is audio source and the other  
is  
packet, and I add it together and output to audio sink. Important audio  
source will generate data when program start. The first 5 second no  
packet  
is send. After 5 second packet source will send 1000 packets, meantime,  
speaker have sound, and if you have say something in first 5 seconds,  
you  
will hear what you say in the first 5 second now.

* * *

#!/usr/bin/env python  
##################################################

# Gnuradio Python Flow Graph

# Title: Top Block

# Generated: Thu Aug 7 20:16:29 2014

##################################################

from gnuradio import eng\_notation  
from gnuradio import gr  
from gnuradio.eng\_option import eng\_option  
from gnuradio.filter import firdes  
from optparse import OptionParser  
from gnuradio import digital  
from gnuradio import audio  
from gnuradio import blocks  
from time import sleep

class top\_block(gr.top\_block):

```
def __init__ (self):
    gr.top_block. __init__ (self, "Top Block1")

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

    ##################################################
    # Blocks
    ##################################################
    self.digital_gmsk_mod_0 = digital.gmsk_mod( 

```

samples\_per\_symbol=2,  
bt=0.35, verbose=False, log=False, )  
self.digital\_mod\_pkts\_0 =  
digital.mod\_pkts(self.digital\_gmsk\_mod\_0,  
access\_code=None, msgq\_limit=4, pad\_for\_usrp=False)  
self.audio\_source\_0 = audio.source(samp\_rate, “”, True)  
self.audio\_sink\_0 = audio.sink(samp\_rate, “”, True)  
self.blocks\_add\_xx\_0 = blocks.add\_vcc(1)  
self.blocks\_float\_to\_complex\_0 = blocks.float\_to\_complex(1)  
self.blocks\_complex\_to\_real\_0 = blocks.complex\_to\_real(1)  
self.blocks\_multiply\_const\_vxx\_0 =  
blocks.multiply\_const\_vcc((0.01,  
))

```
    ##################################################
    # Connections
    ##################################################
    self.connect((self.blocks_add_xx_0, 0),

```

(self.blocks\_complex\_to\_real\_0, 0))  
self.connect((self.blocks\_complex\_to\_real\_0, 0),  
(self.audio\_sink\_0, 0))  
self.connect((self.audio\_source\_0, 0),  
(self.blocks\_float\_to\_complex\_0, 0))  
self.connect((self.audio\_source\_0, 0),  
(self.blocks\_float\_to\_complex\_0, 1))  
self.connect((self.blocks\_float\_to\_complex\_0, 0),  
(self.blocks\_add\_xx\_0, 0))  
self.connect((self.digital\_mod\_pkts\_0, 0),  
(self.blocks\_multiply\_const\_vxx\_0, 0), (self.blocks\_add\_xx\_0, 1))

```
def send_pkt(self, payload='', eof=False):
    self.digital_mod_pkts_0.send_pkt(payload, eof)

```

if **name** == ‘ **main** ’:  
parser = OptionParser(option\_class=eng\_option, usage=“%prog:  
[options]”)  
(options, args) = parser.parse\_args()  
tb = top\_block()  
tb.start()  
sleep(5)  
for i in range(0, 1000):  
tb.send\_pkt(‘a’)  
raw\_input('Press Enter to quit: ')  
tb.stop()  
tb.wait()

* * *

Jeff Guo

2014-08-07 19:07 GMT+08:00 Martin B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 7, 2014, 4:19pm UTC](https://www.ruby-forum.com/t/continuous-and-discrete-data-combine/234816/4 "2014-08-07T16:19:22Z")

</div>

Hi,

> If you have a hardware sink or source involved though, this is _never_ the  
> correct approach, since you will end up with two competing clocks, and that  
> will, over a longer time, lead to over- or underflows. You can solve this  
> issue by either using a hardware sink that accepts bursts of data, so you  
> don’t have to zero pad, or by having a block that passes through input  
> samples (e.g. from a constant 0 source) and adds message-generated samples  
> when they occur.

Unfortunately that’s sometimes the only approach.

If you have a PFB synthesizer that create many parallel channels, then  
relying on the sink block burst capability won’t work …  
Or for cases where if you don’t have a packet to TX, then you should  
TX a ‘filler’ frame rather than 0.

That limitation is pretty much a show stopper when you try to  
implement TDMA system TX on gnuradio … ☹

For RX the streamtags now allow a good way to split them in packets,  
but for TX that’s not sufficient.  
Blocks should be able to get a notion of time provided by an external  
device. And also monitor the buffer levels.

Cheers,

```
Sylvain

```

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 7, 2014, 6:03pm UTC](https://www.ruby-forum.com/t/continuous-and-discrete-data-combine/234816/5 "2014-08-07T18:03:32Z")

</div>

Hello,

I just remember my DSP teacher told me that the digital signal sample  
rate  
mean nothing in digital world, but in the “real” word it is important  
and  
sample rate is we assign the meaning to a group of data and we can to  
like  
fft or something needs time. So it’s my fault. Thank you for remind me  
zero  
padding, and I “think” I can create a block like source, because like  
signal source can set the sample rate and I also create a block can set  
sampling rate and give it a function that accept packet. Also I can try  
bursts data, I never done before. Using constant 0 source I think I  
doesn’t  
work because after add message-generated the output data also same as  
message-generated.

If I just connect message-generated to sink, it worked well. This  
problem  
will show up when discrete source and continuous source at a same time  
and  
trying to combine them together.

This question is from my project, but it’s finish. My solution is let  
the  
message-generated floating and when I need to send packet I lock the  
flow  
graph and reconfigure the connect and unlock, after sending the packet  
also  
reconfigure them.

Recently, I want to do not only physical layer but data link layer or  
upper  
layer and this problem just come to my mind. If I using gnu radio like  
ethernet it work well because usurp sink will send data when it get  
them.  
But I want to create a system, so I cannot avoid to facing this problem.  
Thanks for answering my question, help me a lot.

Sincerely,

Jeff Guo

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 7, 2014, 3:53pm UTC](https://www.ruby-forum.com/t/continuous-and-discrete-data-combine/234816/6 "2014-08-07T15:53:46Z")

</div>

Hi ??,  
this question reveals that you have not considered GNU Radio to not be  
bound by real time.  
As samples are “bare numbers”, they don’t have a time. Thus, GNU Radio  
nor any of the blocks involved care about how much time has passed in  
the real world. Thus, for your block, while no message occurs time  
“does not pass”. And you can only generate samples in the work function.

Therefore, yes, it can be done, but you’ll have to calculate in your  
work how many samples you wanted to produce in the time since the last  
call to work.

If you have a hardware sink or source involved though, this is _never_  
the correct approach, since you will end up with two competing clocks,  
and that will, over a longer time, lead to over- or underflows. You can  
solve this issue by either using a hardware sink that accepts bursts of  
data, so you don’t have to zero pad, or by having a block that passes  
through input samples (e.g. from a constant 0 source) and adds  
message-generated samples when they occur.

Greetings,  
Marcus
