I encountered a problem when *blocks.head() *object doesn't terminate
flowgraph execution when I used *digital.generic_mod()* object inside the
same flowgraph. The problem was also described here:
https://dsp.stackexchange.com/questions/75371/gnu-radio-head-block-doesnt-finish-simulation?noredirect=1#comment160051_75371.
Is there any reason that those blocks are not compatible with themselves? I
encountered the same issue while writing the code from the scratch:

from gnuradio import gr
from gnuradio import blocks
from gnuradio import analog
from gnuradio import digital
import numpy as np
import matplotlib.pyplot as plt



class transmitter_base(gr.hier_block2):
    def __init__(self, samples_count):
        # constructor my class
        # call constructor for parent class
        gr.hier_block2.__init__(self, name="transmitter_base",
input_signature=gr.io_signature(0,0,0),
output_signature=gr.io_signature(1,1,gr.sizeof_gr_complex))
        # Create random bits generator for modulator input - output of the
random generator should by unsigned char
        self.bits_generator = analog.random_uniform_source_b(0, 256,
np.random.randint(low = -2_147_483_647, high = 2_147_483_647)) # return and
int from range [0, 256)
        self.limiter = blocks.head(gr.sizeof_gr_complex, samples_count)

        # self.connect(self.src, self.head, self) Note: connect in derived
class
class bpsk_transmitter(transmitter_base):
    def __init__(self,samples_count, sps, alpha):
        transmitter_base.__init__(self, samples_count)
        # Here declare blocks that based on bit sequence generate BPSK
waveform
        # self.mod = digital.generic_mod()
        self.mod = digital.generic_mod(digital.constellation_bpsk(), False,
sps, False, alpha, True, False, False)
        self.connect(self.bits_generator,self.mod, self.limiter, self)

def main():
    my_bpsk_modulator = bpsk_transmitter(1000, 8, 0.35)
    sink = blocks.vector_sink_c()
    tb = gr.top_block()
    tb.connect(my_bpsk_modulator, sink)
    tb.run()
    raw_output_vector = np.array(sink.data(), dtype=np.complex64)
    plt.plot(np.real(raw_output_vector))
    plt.plot(np.imag(raw_output_vector))

if  __name__ == '__main__':
    main()

Kind regards,

Marcin Puchlik

Reply via email to