コード例 #1
0
    def __init__(self):
        gr.top_block.__init__(self)

        ################################################
        ###   EL FLUJOGRAMA                          ###
        ################################################

        # Las variables usadas en el flujograma
        samp_rate = 32000
        f = 1000
        # Los bloques
        self.src = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, f, 1, 0)
        self.nse = analog.noise_source_f(analog.GR_GAUSSIAN, 0.1)
        self.add = misbloques.e_add_ff(0.5)
        # self.thr = blocks.throttle(gr.sizeof_gr_complex, samp_rate, True)
        self.snk = qtgui.time_sink_f(
            512,  # numero de muestras en la ventana del osciloscopio
            samp_rate,
            "senal promediada",  # nombre que aparece en la grafica
            1  # Nuemero de entradas del osciloscopio
        )
        # Las conexiones
        self.connect(self.src, (self.add, 0))
        self.connect(self.nse, (self.add, 1))
        #self.connect(self.add, self.thr, self.snk)
        self.connect(self.add, self.snk)
        # La configuracion para graficar
        self.pyobj = sip.wrapinstance(self.snk.pyqwidget(), Qt.QWidget)
        self.pyobj.show()
コード例 #2
0
    def __init__(self, sample_rate=32000):

        gr.top_block.__init__(self, "Top Block 22")        
        ##################################################
        # Variables
        ##################################################
        self.sample_rate = sample_rate
        print('[TopBlock22] __init__: sample_rate:', self.sample_rate)
        
        ##################################################
        # Blocks
        ##################################################
        self.blocks_add_xx = blocks.add_vff(1)
        self.audio_sink = audio.sink(32000, '', True)
        self.analog_sig_source_x_1 = analog.sig_source_f(sample_rate, analog.GR_COS_WAVE, 440, 0.4, 0)
        self.analog_sig_source_x_0 = analog.sig_source_f(sample_rate, analog.GR_COS_WAVE, 350, 0.4, 0)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0.005, -42)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx, 2))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx, 0))
        self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx, 1))
        self.connect((self.blocks_add_xx, 0), (self.audio_sink, 0))
コード例 #3
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100

        npts = 2048

        self.qapp = QtGui.QApplication(sys.argv)

        src1 = analog.sig_source_f(Rs, analog.GR_SIN_WAVE, f1, 0, 0)
        src2 = analog.noise_source_f(analog.GR_GAUSSIAN, 1)
        src = blocks.add_ff()
        thr = blocks.throttle(gr.sizeof_float, 100 * npts)
        self.snk1 = qtgui.histogram_sink_f(npts, 200, -5, 5, "Histogram")

        self.connect(src1, (src, 0))
        self.connect(src2, (src, 1))
        self.connect(src, thr, self.snk1)

        self.ctrl_win = control_box(self.snk1)
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
コード例 #4
0
    def __init__(self, noise_mag=0, alpha=0.1):
        gr.hier_block2.__init__(
            self, "Phase Noise Generator",
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.noise_mag = noise_mag
        self.alpha = alpha

        ##################################################
        # Blocks
        ##################################################
        self.filter_single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(alpha, 1)
        self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float")
        self.blocks_transcendental_0 = blocks.transcendental("cos", "float")
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, noise_mag, 42)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_noise_source_x_0, 0), (self.filter_single_pole_iir_filter_xx_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self, 0))
        self.connect((self, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0, 0))
        self.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0_0, 0))
        self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0, 0))
        self.connect((self.blocks_transcendental_0_0, 0), (self.blocks_float_to_complex_0, 1))
コード例 #5
0
ファイル: top_block.py プロジェクト: manuts/fecapi
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.sigma = sigma = 0.4
        self.max_iterations = max_iterations = 50
        self.alist_file = alist_file = "/home/manu/repos/ldpc/gr-ldpc/python/alist-files/96.3.963"
        self.samp_rate = samp_rate = 32000
        self.encoder = encoder = ldpc_encoder_bf(alist_file)
        self.decoder = decoder = ldpc_decoder_fb(alist_file, sigma, max_iterations)

        ##################################################
        # Blocks
        ##################################################
        self.generic_encoder_0 = fec.encoder(encoder, gr.sizeof_char, gr.sizeof_float)
        self.generic_decoder_0 = fec.decoder(decoder, gr.sizeof_float, gr.sizeof_char)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "/home/manu/Downloads/in.flac", False)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "/home/manu/Downloads/out.flac")
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_file_source_0, 0), (self.generic_encoder_0, 0))
        self.connect((self.generic_encoder_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.generic_decoder_0, 0))
        self.connect((self.generic_decoder_0, 0), (self.blocks_file_sink_0, 0))
コード例 #6
0
ファイル: test_sccc_turbo1.py プロジェクト: 232675/gnuradio
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed):
    tb = gr.top_block ()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality
    enc = trellis.sccc_encoder_ss(fo,0,fi,0,interleaver,K)
    mod = digital.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed)

    # RX
    dec = trellis.sccc_decoder_combined_fs(fo,0,-1,fi,0,-1,interleaver,K,IT,trellis.TRELLIS_MIN_SUM,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN,1.0)
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    #tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
    tb.connect (src,src_head,s2fsmi,enc,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    #tb.connect (add,head)
    #tb.connect (tail,fsmi2s,dst)
    tb.connect (add,dec,fsmi2s,dst)

    tb.run()

    #print enc_out.ST(), enc_in.ST()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    return (ntotal,ntotal-nright)
コード例 #7
0
    def __init__(self):
        gr.top_block.__init__(self)
        # Nuestras variables especificas
        samp_rate = 44100
        T = 1. / samp_rate
        f = 1000
        N = 128
        scr = blocks.wavfile_source('/media/Lab4/liberias/voice.wav', True)
        nse = analog.noise_source_f(analog.GR_GAUSSIAN, 0.1)
        add = SUMA.SUMA_cc()
        snk = qtgui.time_sink_f(512, samp_rate, 'señal promediada', 1)
        str2vec = blocks.stream_to_vector(gr.sizeof_float * 1, N)
        e_fft = vector.vector_fft_ff(N, T)
        average = Vectoraverage.vector_average_hob(N, 100)
        vsnk = qtgui.vector_sink_f(N, -samp_rate / 2., samp_rate / N,
                                   'frecuencia', 'Magnitud', 'FT en Magnitud',
                                   1)
        vsnk.enable_autoscale(True)
        self.connect(scr, (add, 0))
        self.connect(nse, (add, 1))
        self.connect(add, snk)
        self.connect(add, str2vec, e_fft, average, vsnk)

        #para graficar
        pyobj = sip.wrapinstance(vsnk.pyqwidget(), QtWidgets.QWidget)
        pyobj.show()
コード例 #8
0
ファイル: example1.py プロジェクト: manuts/fecapi
    def __init__(self):
        gr.top_block.__init__(self)

        ##################################################
        # Variables
        ##################################################
        self.sigma = sigma = 0.4
        self.max_iterations = max_iterations = 50
        self.alist_file = alist_file = "/home/manu/repos/ldpc/gr-ldpc/python/alist-files/96.3.963"
        self.samp_rate = samp_rate = 32000
        self.encoder = _encoder = ldpc_encoder_bf(alist_file)
        self.decoder = _decoder = ldpc_decoder_fb(alist_file, sigma, max_iterations)

        ##################################################
        # Blocks
        ##################################################
        self.generic_encoder_0 = fec.encoder(_encoder, gr.sizeof_char, gr.sizeof_float)
        self.generic_decoder_0 = fec.decoder(_decoder, gr.sizeof_float, gr.sizeof_char)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "/home/manu/Downloads/in.flac", False)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "/home/manu/Downloads/out.flac")
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_file_source_0, 0), (self.generic_encoder_0, 0))
        self.connect((self.generic_encoder_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.generic_decoder_0, 0))
        self.connect((self.generic_decoder_0, 0), (self.blocks_file_sink_0, 0))
コード例 #9
0
ファイル: SignalGenerator.py プロジェクト: ludwigf/radio
 def xInit(self, signals, noises, sinks):
 #   ------------------------------------------------------------------------
     self.sources = {}
     self.mutes = {}
     self.amps = {}
     
     #sources
     for signal in signals:
         self.sources[signal] = gr.sig_source_f(
             self.samprate, gr.GR_SIN_WAVE, 440, 0.25, 0)
         self.mutes[signal] = gr.mute_ff(True)
         self.amps[signal] = gr.multiply_const_ff(0.25)
     for noise in noises:
         self.sources[noise] = analog.noise_source_f(
             analog.GR_LAPLACIAN, 1, 0)
         self.mutes[noise] = gr.mute_ff(True)
         self.amps[noise] = gr.multiply_const_ff(0.25)
     #mixer
     if len(self.sources) > 1:
         self.adder = self.add = gr.add_vff(1)
     else:
         self.adder = gr.multiply_const_vff((1, ))
     self.level = gr.multiply_const_ff(1)
     
     #sinks
     self.sinks = sinks
         
     self.audiomute = gr.mute_ff(True)
     self.audio = audio.sink(self.samprate, "", True)
     self.udp = gr.null_sink(gr.sizeof_float)
     self.rawfile = gr.null_sink(gr.sizeof_float)
     self.wavefile = gr.null_sink(gr.sizeof_float)
コード例 #10
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100

        npts = 2048

        self.qapp = QtGui.QApplication(sys.argv)

        src1 = analog.sig_source_f(Rs, analog.GR_SIN_WAVE, f1, 0, 0)
        src2 = analog.noise_source_f(analog.GR_GAUSSIAN, 1)
        src  = blocks.add_ff()
        thr = blocks.throttle(gr.sizeof_float, 100*npts)
        self.snk1 = qtgui.histogram_sink_f(npts, 200, -5, 5,
                                           "Histogram")

        self.connect(src1, (src,0))
        self.connect(src2, (src,1))
        self.connect(src, thr, self.snk1)

        self.ctrl_win = control_box(self.snk1)
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
コード例 #11
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,seed):
    tb = gr.top_block ()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head (gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
    enc = trellis.encoder_ss(f,0) # initial state = 0
    # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the FSM)
    mod = digital.chunks_to_symbols_sf(tot_constellation,dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed)

    # RX
    metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s();

    tb.connect (src,src_head,s2fsmi,enc,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,metrics)
    tb.connect (metrics,va,fsmi2s,dst)

    tb.run()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    #print ntotal,nright,runlength

    return (ntotal,ntotal-nright)
コード例 #12
0
    def __init__(self):
        gr.top_block.__init__(self)
        samp_rate = 64000
        f = 2000
        N = 1024
        src = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, f, 1, 0)
        nse = analog.noise_source_f(analog.GR_GAUSSIAN, 0.1)
        add = misbloques.e_add_ff(1.0)
        snk = qtgui.time_sink_f(128, samp_rate, "senal promediada", 1)
        str2vec = blocks.stream_to_vector(gr.sizeof_float * 1, N)
        e_fft = misbloques.e_vector_fft_ff(N)
        vsnk = qtgui.vector_sink_f(N, -samp_rate / 2., samp_rate / N,
                                   "frecuencia", "Magnitud", "FT en Magnitud",
                                   1)
        vsnk.enable_autoscale(True)

        #conexiones
        self.connect(src, (add, 0))
        self.connect(nse, (add, 1))
        self.connect(add, snk)
        self.connect(add, str2vec, e_fft, vsnk)

        #graficar
        pyobjv = sip.wrapinstance(vsnk.pyqwidget(), Qt.QWidget)
        pyobj = sip.wrapinstance(snk.pyqwidget(), Qt.QWidget)
        pyobjv.show()
        pyobj.show()
コード例 #13
0
def test_pa(self, param):
    """this function run the defined test, for easier understanding"""

    tb = self.tb
    data_gain = namedtuple('data_gain', 'src out time')

    src_phase_acc =blocks.vector_source_f((np.linspace(0, param.value * param.items, param.items, endpoint=True)), False, 1, [])
    src_noise = analog.noise_source_f(analog.GR_GAUSSIAN, param.noise, 0)

    adder = blocks.add_vff(1)
    throttle = blocks.throttle(gr.sizeof_float*1, param.samp_rate,True)
    head = blocks.head(gr.sizeof_float, int (param.items))

    dst_pc_out = flaress.vector_sink_int64()
    dst_gain_out = flaress.vector_sink_int64()

    pc = ecss.phase_converter(param.N)
    gain = ecss.gain_phase_accumulator(param.reset, param.uplink, param.downlink)

    tb.connect(src_phase_acc, (adder, 0))
    tb.connect(src_noise, (adder, 1))
    tb.connect(adder, throttle)
    tb.connect(throttle, head)
    tb.connect(head, pc)
    tb.connect(pc, gain)
    tb.connect(pc, dst_pc_out)
    tb.connect(gain, dst_gain_out)

    self.tb.run()

    data_gain.src = dst_pc_out.data()
    data_gain.out = dst_gain_out.data()
    data_gain.time = np.linspace(0, (param.items * 1.0 / param.samp_rate), param.items, endpoint=False)

    return data_gain
コード例 #14
0
ファイル: top_block.py プロジェクト: ExiaHan/gr-cheatsheet
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")

        samp_rate = 32000
        self.audio = audio.sink(samp_rate, '', True)
        self.noise = analog.noise_source_f(analog.GR_GAUSSIAN, 0.1, 0)

        self.connect(self.noise, self.audio)
コード例 #15
0
ファイル: top_block.py プロジェクト: pearson78/gr-ldpc
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.sigma = sigma = 0.3
        self.samp_rate = samp_rate = 32000
        self.max_iterations = max_iterations = 50

        ##################################################
        # Blocks
        ##################################################
        self.ldpc_lh_detector_fb_0 = ldpc.lh_detector_fb()
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bf(
            ([1.0, -1.0]), 1)
        self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb(
            1, gr.GR_MSB_FIRST)
        self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb(
            1, gr.GR_MSB_FIRST)
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_char * 1, "/home/manu/Downloads/in.flac", False)
        self.blocks_file_sink_2 = blocks.file_sink(gr.sizeof_char * 1,
                                                   "/home/manu/val")
        self.blocks_file_sink_2.set_unbuffered(False)
        self.blocks_file_sink_1 = blocks.file_sink(gr.sizeof_char * 1,
                                                   "/home/manu/ref")
        self.blocks_file_sink_1.set_unbuffered(False)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1,
                                                   "/home/manu/out")
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_noise_source_x_0 = analog.noise_source_f(
            analog.GR_GAUSSIAN, sigma, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_packed_to_unpacked_xx_0, 0))
        self.connect((self.blocks_unpacked_to_packed_xx_0, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.analog_noise_source_x_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_add_xx_0, 0),
                     (self.ldpc_lh_detector_fb_0, 0))
        self.connect((self.ldpc_lh_detector_fb_0, 0),
                     (self.blocks_file_sink_2, 0))
        self.connect((self.ldpc_lh_detector_fb_0, 0),
                     (self.blocks_unpacked_to_packed_xx_0, 0))
        self.connect((self.blocks_packed_to_unpacked_xx_0, 0),
                     (self.blocks_file_sink_1, 0))
        self.connect((self.blocks_packed_to_unpacked_xx_0, 0),
                     (self.digital_chunks_to_symbols_xx_0, 0))
コード例 #16
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
    tb = gr.top_block ()


    # TX
    #packet = [0]*Kb
    #for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0
        #packet[i] = random.randint(0, 1) # random 0s and 1s
    #src = blocks.vector_source_s(packet,False)
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts
    #b2s = blocks.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
    enc = trellis.encoder_ss(f,0) # initial state = 0
    mod = digital.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed)

    # RX
    metrics = trellis.metrics_f(f.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    #s2b = blocks.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits
    #dst = blocks.vector_sink_s();
    dst = blocks.check_lfsr_32k_s()


    tb.connect (src,src_head,s2fsmi,enc,mod)
    #tb.connect (src,b2s,s2fsmi,enc,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,metrics)
    tb.connect (metrics,va,fsmi2s,dst)
    #tb.connect (metrics,va,fsmi2s,s2b,dst)


    tb.run()

    # A bit of cheating: run the program once and print the
    # final encoder state..
    # Then put it as the last argument in the viterbi block
    #print "final state = " , enc.ST()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    #ntotal = len(packet)
    #if len(dst.data()) != ntotal:
        #print "Error: not enough data\n"
    #nright = 0;
    #for i in range(ntotal):
        #if packet[i]==dst.data()[i]:
            #nright=nright+1
        #else:
            #print "Error in ", i
    return (ntotal,ntotal-nright)
コード例 #17
0
ファイル: example1.py プロジェクト: pearson78/gr-ldpc
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Example1")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.sigma = sigma = 0.5
        self.samp_rate = samp_rate = 32000
        self.max_iterations = max_iterations = 50
        self.alist_file = alist_file = "/home/manu/repos/ldpc/gr-ldpc/python/alist-files"

        ##################################################
        # Blocks
        ##################################################
        self.ldpc_ldpc_hier_encoder_bb_0 = ldpc.ldpc_hier_encoder_bb(
            "/home/manu/1920.1280.3.303/H1920.1280.3.303")
        self.ldpc_ldpc_hier_decoder_fb_0 = ldpc.ldpc_hier_decoder_fb(
            "/home/manu/1920.1280.3.303/H1920.1280.3.303", sigma,
            max_iterations)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bf(
            ([1.0, -1.0]), 1)
        self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb(
            1, gr.GR_LSB_FIRST)
        self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb(
            1, gr.GR_LSB_FIRST)
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_char * 1,
            "/home/manu/Downloads/06 - Coming Back To Life.flac", False)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1,
                                                   "/home/manu/Downloads/out",
                                                   False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_noise_source_x_0 = analog.noise_source_f(
            analog.GR_GAUSSIAN, sigma, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_packed_to_unpacked_xx_0, 0))
        self.connect((self.ldpc_ldpc_hier_decoder_fb_0, 0),
                     (self.blocks_unpacked_to_packed_xx_0, 0))
        self.connect((self.blocks_unpacked_to_packed_xx_0, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_packed_to_unpacked_xx_0, 0),
                     (self.ldpc_ldpc_hier_encoder_bb_0, 0))
        self.connect((self.ldpc_ldpc_hier_encoder_bb_0, 0),
                     (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.analog_noise_source_x_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_add_xx_0, 0),
                     (self.ldpc_ldpc_hier_decoder_fb_0, 0))
コード例 #18
0
    def __init__(self, doc):
        gr.top_block.__init__(self, "Top Block")
        self.doc = doc
        self.widget_lst = []
        self.plot_lst = []

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

        ##################################################
        # Blocks
        ##################################################
        self.bokehgui_waterfall_sink_f_proc_0 = bokehgui.waterfall_sink_f_proc(
                1024, firdes.WIN_BLACKMAN_hARRIS, 0, samp_rate / 2,
                "Waterfall Sink")
        self.bokehgui_waterfall_sink_f_0 = bokehgui.waterfall_sink_f(self.doc,
                                                                     self.plot_lst,
                                                                     self.bokehgui_waterfall_sink_f_proc_0)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1,
                                                 samp_rate, True)
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate,
                                                         analog.GR_COS_WAVE,
                                                         5000, 3, 0)
        self.analog_noise_source_x_0 = analog.noise_source_f(
                analog.GR_GAUSSIAN, 0.001, 0)
        self.blocks_add_xx_0 = blocks.add_vff(1)

        ##################################################
        # Customizing the plot
        ##################################################
        self.bokehgui_waterfall_sink_f_0.initialize(
                                            legend_list = ['Signal (5000 Hz)'],
                                            update_time = 100)

        self.bokehgui_waterfall_sink_f_0.set_x_label('Frequency (Hz)')
        self.bokehgui_waterfall_sink_f_0.set_y_label('Time')
        self.bokehgui_waterfall_sink_f_0.set_layout(1, 1, 1, 1)

        self.doc.add_root(bokehgui.BokehLayout.create_layout(self.plot_lst))
        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_add_xx_0, 0))
        #        self.connect((self.analog_sig_source_x_1, 0),
        # (self.blocks_add_xx_0, 0))
        self.connect((self.analog_noise_source_x_0, 0),
                     (self.blocks_add_xx_0, 1))
        #        self.connect((self.analog_noise_source_x_1, 0),
        # (self.blocks_add_xx_1, 1))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0, 0))
        #        self.connect((self.blocks_add_xx_1, 0),
        # (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.bokehgui_waterfall_sink_f_proc_0, 0))
コード例 #19
0
    def __init__(self,
                 generic_encoder=0,
                 generic_decoder=0,
                 esno=0,
                 samp_rate=3200000,
                 threading="capillary",
                 puncpat='11',
                 seed=0):
        gr.hier_block2.__init__(self, "fec_test",
                                gr.io_signature(1, 1, gr.sizeof_char * 1),
                                gr.io_signature(2, 2, gr.sizeof_char * 1))

        self.generic_encoder = generic_encoder
        self.generic_decoder = generic_decoder
        self.esno = esno
        self.samp_rate = samp_rate
        self.threading = threading
        self.puncpat = puncpat

        self.map_bb = digital.map_bb(([-1, 1]))
        self.b2f = blocks.char_to_float(1, 1)

        self.unpack8 = blocks.unpack_k_bits_bb(8)
        self.pack8 = blocks.pack_k_bits_bb(8)

        self.encoder = extended_encoder(encoder_obj_list=generic_encoder,
                                        threading=threading,
                                        puncpat=puncpat)

        self.decoder = extended_decoder(decoder_obj_list=generic_decoder,
                                        threading=threading,
                                        ann=None,
                                        puncpat=puncpat,
                                        integration_period=10000,
                                        rotator=None)

        noise = math.sqrt((10.0**(-esno / 10.0)) / 2.0)
        #self.fastnoise = analog.fastnoise_source_f(analog.GR_GAUSSIAN, noise, seed, 8192)
        self.fastnoise = analog.noise_source_f(analog.GR_GAUSSIAN, noise, seed)
        self.addnoise = blocks.add_ff(1)

        # Send packed input directly to the second output
        self.copy_packed = blocks.copy(gr.sizeof_char)
        self.connect(self, self.copy_packed)
        self.connect(self.copy_packed, (self, 1))

        # Unpack inputl encode, convert to +/-1, add noise, decode, repack
        self.connect(self, self.unpack8)
        self.connect(self.unpack8, self.encoder)
        self.connect(self.encoder, self.map_bb)
        self.connect(self.map_bb, self.b2f)
        self.connect(self.b2f, (self.addnoise, 0))
        self.connect(self.fastnoise, (self.addnoise, 1))
        self.connect(self.addnoise, self.decoder)
        self.connect(self.decoder, self.pack8)
        self.connect(self.pack8, (self, 0))
コード例 #20
0
ファイル: qa_noise.py プロジェクト: 0x7678/gnuradio-wg-grc
    def test_002(self):
        # Test get methods
        set_type = analog.GR_GAUSSIAN
        set_ampl = 10
        op = analog.noise_source_f(set_type, set_ampl, 10)
        get_type = op.type()
        get_ampl = op.amplitude()

        self.assertEqual(get_type, set_type)
        self.assertEqual(get_ampl, set_ampl)
コード例 #21
0
    def test_002(self):
        # Test get methods
        set_type = analog.GR_GAUSSIAN
        set_ampl = 10
        op = analog.noise_source_f(set_type, set_ampl, 10)
        get_type = op.type()
        get_ampl = op.amplitude()

        self.assertEqual(get_type, set_type)
        self.assertEqual(get_ampl, set_ampl)
コード例 #22
0
    def __init__(self, seconds=40):
        gr.top_block.__init__(self, "Noise")

        ##################################################
        # Parameters
        ##################################################
        self.seconds = seconds

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 44100

        ##################################################
        # Blocks
        ##################################################
        self.low_pass_filter_0 = filter.fir_filter_fff(
            1, firdes.low_pass(1, samp_rate, 300, 500, firdes.WIN_HAMMING,
                               6.76))
        self.blocks_wavfile_sink_0 = blocks.wavfile_sink(
            '/tmp/noise.wav', 1, samp_rate, 16)
        self.blocks_head_0 = blocks.head(gr.sizeof_float * 1,
                                         int(samp_rate * seconds))
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_sig_source_x_0 = analog.sig_source_f(
            samp_rate, analog.GR_COS_WAVE, 60, 0.1, 0.2)
        self.analog_noise_source_x_0_0 = analog.noise_source_f(
            analog.GR_UNIFORM, 0.05, 1)
        self.analog_noise_source_x_0 = analog.noise_source_f(
            analog.GR_UNIFORM, 0.01, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.analog_noise_source_x_0_0, 0),
                     (self.low_pass_filter_0, 0))
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_add_xx_0, 2))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_head_0, 0))
        self.connect((self.blocks_head_0, 0), (self.blocks_wavfile_sink_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.blocks_add_xx_0, 0))
コード例 #23
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

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

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
        	self.GetWin(),
        	unit='Units',
        	minval=-100,
        	maxval=100,
        	factor=1.0,
        	decimal_places=10,
        	ref_level=0,
        	sample_rate=samp_rate,
        	number_rate=15,
        	average=False,
        	avg_alpha=None,
        	label='Number Plot',
        	peak_hold=False,
        	show_gauge=True,
        )
        self.Add(self.wxgui_numbersink2_0.win)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
        self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
        self.blocks_float_to_char_1 = blocks.float_to_char(1, 1)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blks2_error_rate_0 = grc_blks2.error_rate(
        	type='BER',
        	win_size=1000,
        	bits_per_symbol=8,
        )
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 10000, 1, 0)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0.125, 0)



        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_float_to_char_1, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blks2_error_rate_0, 0), (self.wxgui_numbersink2_0, 0))
        self.connect((self.blocks_float_to_char_0, 0), (self.blks2_error_rate_0, 0))
        self.connect((self.blocks_float_to_char_1, 0), (self.blks2_error_rate_0, 1))
        self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_float_to_char_0, 0))
コード例 #24
0
ファイル: channel.py プロジェクト: camihera333/GNURadio
    def __init__(self, k=4.0, tchannel=1, voltage=0):
        gr.hier_block2.__init__(
            self,
            "channel",
            gr.io_signature(1, 1, gr.sizeof_float * 1),
            gr.io_signature(1, 1, gr.sizeof_float * 1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.k = k
        self.tchannel = tchannel
        self.voltage = voltage

        ##################################################
        # Blocks
        ##################################################
        self.channels_fading_model_0_0 = channels.fading_model(
            8, 5 / 32000, False, 4.0, 0)
        self.channels_fading_model_0 = channels.fading_model(
            8, 5 / 32000, True, k, 0)
        self.blocks_float_to_complex_0_0 = blocks.float_to_complex(1)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_complex_to_float_0_0_0 = blocks.complex_to_float(1)
        self.blocks_complex_to_float_0 = blocks.complex_to_float(1)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_noise_source_x_0 = analog.noise_source_f(
            analog.GR_GAUSSIAN, voltage, 0)
        self.Multiplexer_mux_0 = Multiplexer.mux(tchannel)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.Multiplexer_mux_0, 0), (self, 0))
        self.connect((self.analog_noise_source_x_0, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.Multiplexer_mux_0, 0))
        self.connect((self.blocks_complex_to_float_0, 0),
                     (self.Multiplexer_mux_0, 2))
        self.connect((self.blocks_complex_to_float_0_0_0, 0),
                     (self.Multiplexer_mux_0, 1))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.channels_fading_model_0_0, 0))
        self.connect((self.blocks_float_to_complex_0_0, 0),
                     (self.channels_fading_model_0, 0))
        self.connect((self.channels_fading_model_0, 0),
                     (self.blocks_complex_to_float_0_0_0, 0))
        self.connect((self.channels_fading_model_0_0, 0),
                     (self.blocks_complex_to_float_0, 0))
        self.connect((self, 0), (self.blocks_add_xx_0, 1))
        self.connect((self, 0), (self.blocks_float_to_complex_0, 0))
        self.connect((self, 0), (self.blocks_float_to_complex_0_0, 0))
コード例 #25
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 200

        npts = 2048

        self.qapp = QtWidgets.QApplication(sys.argv)

        src1 = analog.sig_source_f(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_f(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src = blocks.add_ff()
        thr = blocks.throttle(gr.sizeof_float, 100 * npts)
        noise = analog.noise_source_f(analog.GR_GAUSSIAN, 0.001)
        add = blocks.add_ff()
        self.snk1 = qtgui.time_sink_f(npts, Rs, "Complex Time Example", 3,
                                      None)

        self.connect(src1, (src, 0))
        self.connect(src2, (src, 1))
        self.connect(src, thr, (add, 0))
        self.connect(noise, (add, 1))
        self.connect(add, self.snk1)
        self.connect(src1, (self.snk1, 1))
        self.connect(src2, (self.snk1, 2))

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt = self.snk1.qwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt5.QtWidgets.QWidget
        pyWin = sip.wrapinstance(pyQt, QtWidgets.QWidget)

        # Example of using signal/slot to set the title of a curve
        # FIXME: update for Qt5
        #pyWin.setLineLabel.connect(pyWin.setLineLabel)
        #pyWin.emit(QtCore.SIGNAL("setLineLabel(int, QString)"), 0, "Re{sum}")
        self.snk1.set_line_label(0, "Re{sum}")
        self.snk1.set_line_label(1, "src1")
        self.snk1.set_line_label(2, "src2")

        # Can also set the color of a curve
        #self.snk1.set_color(5, "blue")

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
コード例 #26
0
ファイル: bm_noise.py プロジェクト: phi-psi/gr-benchmark
    def run_noise_source_f(self):
        ntype = analog.GR_GAUSSIAN
        ampl = 10
        seed = 0

        self.blocks = []
        self.tb = gr.top_block()
        self.blocks.append(analog.noise_source_f(ntype, ampl, seed))
        self.blocks.append(blocks.head(gr.sizeof_float, self.N))
        self.blocks.append(blocks.null_sink(gr.sizeof_float))
        self.tb.connect(*self.blocks)
        self.tb.run()
コード例 #27
0
ファイル: bm_noise.py プロジェクト: WindyCitySDR/gr-ofdm
    def run_noise_source_f(self):
        ntype = analog.GR_GAUSSIAN
        ampl = 10
        seed = 0

        self.blocks = []
        self.tb = gr.top_block()
        self.blocks.append(analog.noise_source_f(ntype, ampl, seed))
        self.blocks.append(blocks.head(gr.sizeof_float, self.N))
        self.blocks.append(blocks.null_sink(gr.sizeof_float))
        self.tb.connect(*self.blocks)
        self.tb.run()
コード例 #28
0
ファイル: pyqt_time_f.py プロジェクト: danbar/gnuradio
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 200

        npts = 2048

        self.qapp = QtWidgets.QApplication(sys.argv)

        src1 = analog.sig_source_f(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_f(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src  = blocks.add_ff()
        thr = blocks.throttle(gr.sizeof_float, 100*npts)
        noise = analog.noise_source_f(analog.GR_GAUSSIAN, 0.001)
        add = blocks.add_ff()
        self.snk1 = qtgui.time_sink_f(npts, Rs,
                                      "Complex Time Example", 3)

        self.connect(src1, (src,0))
        self.connect(src2, (src,1))
        self.connect(src, thr, (add,0))
        self.connect(noise, (add,1))
        self.connect(add, self.snk1)
        self.connect(src1, (self.snk1, 1))
        self.connect(src2, (self.snk1, 2))

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt5.QtWidgets.QWidget
        pyWin = sip.wrapinstance(pyQt, QtWidgets.QWidget)

        # Example of using signal/slot to set the title of a curve
        # FIXME: update for Qt5
        #pyWin.setLineLabel.connect(pyWin.setLineLabel)
        #pyWin.emit(QtCore.SIGNAL("setLineLabel(int, QString)"), 0, "Re{sum}")
        self.snk1.set_line_label(0, "Re{sum}")
        self.snk1.set_line_label(1, "src1")
        self.snk1.set_line_label(2, "src2")

        # Can also set the color of a curve
        #self.snk1.set_color(5, "blue")

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
コード例 #29
0
def run_test(f, Kb, bitspersymbol, K, channel, modulation, dimensionality,
             tot_constellation, N0, seed):
    tb = gr.top_block()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0] * (K + 2 * L)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1)  # random symbols
    for i in range(L):  # first/last L symbols set to 0
        packet[i] = 0
        packet[len(packet) - i - 1] = 0
    src = blocks.vector_source_s(packet, False)
    mod = digital.chunks_to_symbols_sf(modulation[1], modulation[0])

    # CHANNEL
    isi = filter.fir_filter_fff(1, channel)
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    skip = blocks.skiphead(
        gr.sizeof_float, L
    )  # skip the first L samples since you know they are coming from the L zero symbols
    #metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    #va = trellis.viterbi_s(f,K+L,0,0) # Put -1 if the Initial/Final states are not set.
    va = trellis.viterbi_combined_s(
        f, K + L, 0, 0, dimensionality, tot_constellation,
        digital.TRELLIS_EUCLIDEAN
    )  # using viterbi_combined_s instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application...
    dst = blocks.vector_sink_s()

    tb.connect(src, mod)
    tb.connect(mod, isi, (add, 0))
    tb.connect(noise, (add, 1))
    #tb.connect (add,metrics)
    #tb.connect (metrics,va,dst)
    tb.connect(add, skip, va, dst)

    tb.run()

    data = dst.data()
    ntotal = len(data) - L
    nright = 0
    for i in range(ntotal):
        if packet[i + L] == data[i]:
            nright = nright + 1
        #else:
        #print "Error in ", i

    return (ntotal, ntotal - nright)
コード例 #30
0
    def __init__(self,
                 channel_shift_hz=0,
                 random_source_seed=0,
                 sample_rate=0,
                 symbol_rate=1):
        gr.hier_block2.__init__(
            self,
            "Hurdle2 Fm",
            gr.io_signature(0, 0, 0),
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.channel_shift_hz = channel_shift_hz
        self.random_source_seed = random_source_seed
        self.sample_rate = sample_rate
        self.symbol_rate = symbol_rate

        ##################################################
        # Blocks
        ##################################################
        self.low_pass_filter_0_0_0_0 = filter.interp_fir_filter_ccf(
            5,
            firdes.low_pass(1, sample_rate, symbol_rate * 5, symbol_rate,
                            firdes.WIN_HAMMING, 6.76))

        self.blocks_multiply_xx_0_0_0 = blocks.multiply_vcc(1)

        self.analog_wfm_tx_0 = analog.wfm_tx(
            audio_rate=10000,
            quad_rate=600000,
            tau=75e-6,
            max_dev=50e3,
        )
        self.analog_sig_source_x_0_0 = analog.sig_source_c(
            sample_rate, analog.GR_COS_WAVE, channel_shift_hz, 1, 0)
        self.analog_noise_source_x_1 = analog.noise_source_f(
            analog.GR_GAUSSIAN, 0.3, random_source_seed)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_1, 0),
                     (self.analog_wfm_tx_0, 0))
        self.connect((self.analog_sig_source_x_0_0, 0),
                     (self.blocks_multiply_xx_0_0_0, 1))
        self.connect((self.analog_wfm_tx_0, 0),
                     (self.low_pass_filter_0_0_0_0, 0))
        self.connect((self.blocks_multiply_xx_0_0_0, 0), (self, 0))
        self.connect((self.low_pass_filter_0_0_0_0, 0),
                     (self.blocks_multiply_xx_0_0_0, 0))
コード例 #31
0
def run_test(f, Kb, bitspersymbol, K, channel, modulation, dimensionality, tot_constellation, N0, seed):
    tb = gr.top_block()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0] * (K + 2 * L)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2 ** bitspersymbol - 1)  # random symbols
    for i in range(L):  # first/last L symbols set to 0
        packet[i] = 0
        packet[len(packet) - i - 1] = 0
    src = blocks.vector_source_s(packet, False)
    mod = digital.chunks_to_symbols_sf(modulation[1], modulation[0])

    # CHANNEL
    isi = filter.fir_filter_fff(1, channel)
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    skip = blocks.skiphead(
        gr.sizeof_float, L
    )  # skip the first L samples since you know they are coming from the L zero symbols
    # metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    # va = trellis.viterbi_s(f,K+L,0,0) # Put -1 if the Initial/Final states are not set.
    va = trellis.viterbi_combined_s(
        f, K + L, 0, 0, dimensionality, tot_constellation, digital.TRELLIS_EUCLIDEAN
    )  # using viterbi_combined_s instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application...
    dst = blocks.vector_sink_s()

    tb.connect(src, mod)
    tb.connect(mod, isi, (add, 0))
    tb.connect(noise, (add, 1))
    # tb.connect (add,metrics)
    # tb.connect (metrics,va,dst)
    tb.connect(add, skip, va, dst)

    tb.run()

    data = dst.data()
    ntotal = len(data) - L
    nright = 0
    for i in range(ntotal):
        if packet[i + L] == data[i]:
            nright = nright + 1
        # else:
        # print "Error in ", i

    return (ntotal, ntotal - nright)
コード例 #32
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        fft_size = 256

        # build our flow graph
        input_rate = 100 * 20.48e3

        # Generate a complex sinusoid
        #src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 100*2e3, 1)
        src1 = gr.sig_source_c(input_rate, gr.GR_CONST_WAVE, 100 * 5.75e3, 1)
        noise1 = analog.noise_source_c(analog.GR_UNIFORM, 1.0 / 10)
        add1 = blocks.add_cc()

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        thr1 = blocks.throttle(gr.sizeof_gr_complex, input_rate)

        sink1 = fft_sink_c(panel,
                           title="Complex Data",
                           fft_size=fft_size,
                           sample_rate=input_rate,
                           baseband_freq=100e3,
                           ref_level=0,
                           y_per_div=20,
                           y_divs=10)
        vbox.Add(sink1.win, 1, wx.EXPAND)

        self.connect(src1, (add1, 0))
        self.connect(noise1, (add1, 1))
        self.connect(add1, thr1, sink1)

        #src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 100*2e3, 1)
        src2 = gr.sig_source_f(input_rate, gr.GR_CONST_WAVE, 100 * 5.75e3, 1)
        noise2 = analog.noise_source_f(analog.GR_UNIFORM, 1.0 / 10)
        add2 = blocks.add_ff()

        thr2 = gr.throttle(gr.sizeof_float, input_rate)
        sink2 = fft_sink_f(panel,
                           title="Real Data",
                           fft_size=fft_size * 2,
                           sample_rate=input_rate,
                           baseband_freq=100e3,
                           ref_level=0,
                           y_per_div=20,
                           y_divs=10)
        vbox.Add(sink2.win, 1, wx.EXPAND)

        self.connect(src2, (add2, 0))
        self.connect(noise2, (add2, 1))
        self.connect(add2, thr2, sink2)
コード例 #33
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality,
             constellation, N0, seed):
    tb = gr.top_block()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short, Kb / 16)  # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(
        bitspersymbol, gr.GR_MSB_FIRST
    )  # unpack shorts to symbols compatible with the outer FSM input cardinality
    enc_out = trellis.encoder_ss(fo, 0)  # initial state = 0
    inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1,
                                gr.sizeof_short)
    enc_in = trellis.encoder_ss(fi, 0)  # initial state = 0
    mod = digital.chunks_to_symbols_sf(constellation, dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    metrics_in = trellis.metrics_f(
        fi.O(), dimensionality, constellation, digital.TRELLIS_EUCLIDEAN
    )  # data preprocessing to generate metrics for innner Viterbi
    gnd = blocks.vector_source_f([0], True)
    siso_in = trellis.siso_f(
        fi, K, 0, -1, True, False, trellis.TRELLIS_MIN_SUM
    )  # Put -1 if the Initial/Final states are not set.
    deinter = trellis.permutation(interleaver.K(), interleaver.DEINTER(),
                                  fi.I(), gr.sizeof_float)
    va_out = trellis.viterbi_s(
        fo, K, 0, -1)  # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect(src, src_head, s2fsmi, enc_out, inter, enc_in, mod)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, metrics_in)
    tb.connect(gnd, (siso_in, 0))
    tb.connect(metrics_in, (siso_in, 1))
    tb.connect(siso_in, deinter, va_out, fsmi2s, dst)

    tb.run()

    ntotal = dst.ntotal()
    nright = dst.nright()
    runlength = dst.runlength()
    return (ntotal, ntotal - nright)
コード例 #34
0
ファイル: fec_test.py プロジェクト: 0x7678/gnuradio-wg-grc
    def __init__(self, generic_encoder=0, generic_decoder=0, esno=0,
                 samp_rate=3200000, threading="capillary", puncpat='11',
                 seed=0):
        gr.hier_block2.__init__(self, "fec_test",
                                gr.io_signature(1, 1, gr.sizeof_char*1),
                                gr.io_signature(2, 2, gr.sizeof_char*1))

        self.generic_encoder = generic_encoder
        self.generic_decoder = generic_decoder
        self.esno = esno
        self.samp_rate = samp_rate
        self.threading = threading
        self.puncpat = puncpat

        self.map_bb = digital.map_bb(([-1, 1]))
        self.b2f = blocks.char_to_float(1, 1)

        self.unpack8 = blocks.unpack_k_bits_bb(8)
        self.pack8 = blocks.pack_k_bits_bb(8)

        self.encoder = extended_encoder(encoder_obj_list=generic_encoder,
                                        threading=threading,
                                        puncpat=puncpat)

        self.decoder = extended_decoder(decoder_obj_list=generic_decoder,
                                        threading=threading,
                                        ann=None, puncpat=puncpat,
                                        integration_period=10000, rotator=None)

        noise = math.sqrt((10.0**(-esno/10.0))/2.0)
        #self.fastnoise = analog.fastnoise_source_f(analog.GR_GAUSSIAN, noise, seed, 8192)
        self.fastnoise = analog.noise_source_f(analog.GR_GAUSSIAN, noise, seed)
        self.addnoise = blocks.add_ff(1)

        # Send packed input directly to the second output
        self.copy_packed = blocks.copy(gr.sizeof_char)
        self.connect(self, self.copy_packed)
        self.connect(self.copy_packed, (self, 1))

        # Unpack inputl encode, convert to +/-1, add noise, decode, repack
        self.connect(self, self.unpack8)
        self.connect(self.unpack8, self.encoder)
        self.connect(self.encoder, self.map_bb)
        self.connect(self.map_bb, self.b2f)
        self.connect(self.b2f, (self.addnoise, 0))
        self.connect(self.fastnoise, (self.addnoise,1))
        self.connect(self.addnoise, self.decoder)
        self.connect(self.decoder, self.pack8)
        self.connect(self.pack8, (self, 0))
コード例 #35
0
def run_test(f, Kb, bitspersymbol, K, dimensionality, constellation, N0, seed):
    tb = gr.top_block()

    # TX
    numpy.random.seed(-seed)
    packet = numpy.random.randint(0, 2, Kb)  # create Kb random bits
    packet[Kb - 10:Kb] = 0
    packet[0:Kb] = 0
    src = blocks.vector_source_s(packet.tolist(), False)
    b2s = blocks.unpacked_to_packed_ss(1,
                                       gr.GR_MSB_FIRST)  # pack bits in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(
        bitspersymbol, gr.GR_MSB_FIRST
    )  # unpack shorts to symbols compatible with the FSM input cardinality
    enc = trellis.encoder_ss(f, 0)  # initial state = 0
    mod = digital.chunks_to_symbols_sf(constellation, dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2),
                                  long(seed))

    # RX
    va = trellis.viterbi_combined_fs(
        f, K, 0, 0, dimensionality, constellation, digital.TRELLIS_EUCLIDEAN
    )  # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    s2b = blocks.packed_to_unpacked_ss(
        1, gr.GR_MSB_FIRST)  # unpack shorts to bits
    dst = blocks.vector_sink_s()

    tb.connect(src, b2s, s2fsmi, enc, mod)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, va, fsmi2s, s2b, dst)

    tb.run()

    # A bit of cheating: run the program once and print the
    # final encoder state..
    # Then put it as the last argument in the viterbi block
    #print "final state = " , enc.ST()

    if len(dst.data()) != len(packet):
        print "Error: not enough data:", len(dst.data()), len(packet)
    ntotal = len(packet)
    nwrong = sum(abs(packet - numpy.array(dst.data())))
    return (ntotal, nwrong, abs(packet - numpy.array(dst.data())))
コード例 #36
0
    def __init__(self):
        gr.top_block.__init__(self)

        ################################################
        ###   EL FLUJOGRAMA                          ###
        ################################################

        # Las variables usadas en el flujograma
        samp_rate = 32000
        f = 1000
        N = 128
        # Los bloques
        src = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, f, 1, 0)
        nse = analog.noise_source_f(analog.GR_GAUSSIAN, 0.1)
        add = bloques.e_add_ff(1.0)
        snk = qtgui.time_sink_f(
            512,  # numero de muestras en la ventana del osciloscopio
            samp_rate,
            "senal promediada",  # nombre que aparece en la grafica
            1  # Nuemero de entradas del osciloscopio
        )
        str2vec = blocks.stream_to_vector(gr.sizeof_float * 1, N)

        e_fft = bloques.e_vector_fft_ff(N)
        vsnk = qtgui.vector_sink_f(
            N,
            -samp_rate / 2.,
            samp_rate / N,
            "frecuencia",
            "Magnitud",
            "FT en Magnitud",
            1  # Number of inputs
        )
        vsnk.enable_autoscale(True)

        average = bloques.vector_average_hob(N, 10)

        # Las conexiones
        self.connect(src, (add, 0))
        self.connect(nse, (add, 1))
        self.connect(add, snk)
        self.connect(add, str2vec, e_fft, average, vsnk)

        # La configuracion para graficar
        pyobj1 = sip.wrapinstance(vsnk.pyqwidget(), Qt.QWidget)
        pyobj2 = sip.wrapinstance(snk.pyqwidget(), Qt.QWidget)
        pyobj1.show()
        pyobj2.show()
コード例 #37
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality,
             constellation, Es, N0, IT, seed):
    tb = gr.top_block()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short, Kb / 16)  # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(
        bitspersymbol, gr.GR_MSB_FIRST
    )  # unpack shorts to symbols compatible with the outer FSM input cardinality
    #src = blocks.vector_source_s([0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],False)
    enc = trellis.pccc_encoder_ss(fo, 0, fi, 0, interleaver, K)
    code = blocks.vector_sink_s()
    mod = digital.chunks_to_symbols_sf(constellation, dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    metrics_in = trellis.metrics_f(
        fi.O() * fo.O(), dimensionality, constellation,
        digital.TRELLIS_EUCLIDEAN
    )  # data preprocessing to generate metrics for innner SISO
    scale = blocks.multiply_const_ff(1.0 / N0)
    dec = trellis.pccc_decoder_s(fo, 0, -1, fi, 0, -1, interleaver, K, IT,
                                 trellis.TRELLIS_MIN_SUM)

    fsmi2s = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect(src, src_head, s2fsmi, enc, mod)
    #tb.connect (src,enc,mod)
    #tb.connect(enc,code)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, metrics_in, scale, dec, fsmi2s, dst)

    tb.run()

    #print code.data()

    ntotal = dst.ntotal()
    nright = dst.nright()
    runlength = dst.runlength()
    return (ntotal, ntotal - nright)
コード例 #38
0
ファイル: test_awgn.py プロジェクト: manuts/gr-ldpc
    def __init__(self, fname, epsilon, max_iterations):
        gr.top_block.__init__(self)

        self.src = blocks.vector_source_b(())
#        self.encoder = ldpc.ldpc_encoder_bf(fname)
#        self.decoder = ldpc.ldpc_decoder_fb(fname, epsilon, max_iterations)
#        self.encoder = ldpc.ldpc_encoder_bb(fname)
#        self.decoder = ldpc.ldpc_decoder_bb(fname, epsilon, max_iterations)
#        self.K = self.encoder.get_K()
#        self.N = self.encoder.get_N()
        self.K = 100
        self.N = 100
        print self.K
        print self.N
        copy = ldpc.copy_bb(self.K)
        self.dst = blocks.vector_sink_b()
        fsink1 = blocks.file_sink(gr.sizeof_char*self.K, "in")
        fsink1.set_unbuffered(False)
        fsink2 = blocks.file_sink(gr.sizeof_char*self.K, "out")
        fsink2.set_unbuffered(False)
#        fsink3 = blocks.file_sink(gr.sizeof_float*1, "encout")
#        fsink3.set_unbuffered(False)
        fsink3 = blocks.file_sink(gr.sizeof_char*self.N, "encout")
        fsink3.set_unbuffered(False)

        inFile = "/home/manu/Downloads/in.flac"
        outFile = "/home/manu/out.flac"
        source = blocks.file_source(gr.sizeof_char*self.K, inFile, False)
        sink = blocks.file_sink(gr.sizeof_char*self.K, outFile)
        unpack2pack = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        pack2unpack = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        rsource= blocks.vector_source_b(map(int, np.random.randint(0x00, 0x02, 1000)), True)


#        str2Kvec = blocks.stream_to_vector(1, self.K)
#        str2Nvec = blocks.stream_to_vector(4, self.N)
#        Kvec2str = blocks.vector_to_stream(1, self.K)
#        Nvec2str = blocks.vector_to_stream(4, self.N)
        str2Kvec = blocks.stream_to_vector(1, self.K)
        str2Nvec = blocks.stream_to_vector(1, self.N)
        Kvec2str = blocks.vector_to_stream(1, self.K)
        Nvec2str = blocks.vector_to_stream(1, self.N)

        self.noise = analog.noise_source_f(analog.GR_GAUSSIAN, epsilon, 0)
        self.adder = blocks.add_vff(1)

        self.connect(source, copy, sink)
コード例 #39
0
    def __init__(self, fname, epsilon, max_iterations):
        gr.top_block.__init__(self)

        self.src = blocks.vector_source_b(())
        #        self.encoder = ldpc.ldpc_encoder_bf(fname)
        #        self.decoder = ldpc.ldpc_decoder_fb(fname, epsilon, max_iterations)
        #        self.encoder = ldpc.ldpc_encoder_bb(fname)
        #        self.decoder = ldpc.ldpc_decoder_bb(fname, epsilon, max_iterations)
        #        self.K = self.encoder.get_K()
        #        self.N = self.encoder.get_N()
        self.K = 100
        self.N = 100
        print self.K
        print self.N
        copy = ldpc.copy_bb(self.K)
        self.dst = blocks.vector_sink_b()
        fsink1 = blocks.file_sink(gr.sizeof_char * self.K, "in")
        fsink1.set_unbuffered(False)
        fsink2 = blocks.file_sink(gr.sizeof_char * self.K, "out")
        fsink2.set_unbuffered(False)
        #        fsink3 = blocks.file_sink(gr.sizeof_float*1, "encout")
        #        fsink3.set_unbuffered(False)
        fsink3 = blocks.file_sink(gr.sizeof_char * self.N, "encout")
        fsink3.set_unbuffered(False)

        inFile = "/home/manu/Downloads/in.flac"
        outFile = "/home/manu/out.flac"
        source = blocks.file_source(gr.sizeof_char * self.K, inFile, False)
        sink = blocks.file_sink(gr.sizeof_char * self.K, outFile)
        unpack2pack = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        pack2unpack = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        rsource = blocks.vector_source_b(
            map(int, np.random.randint(0x00, 0x02, 1000)), True)

        #        str2Kvec = blocks.stream_to_vector(1, self.K)
        #        str2Nvec = blocks.stream_to_vector(4, self.N)
        #        Kvec2str = blocks.vector_to_stream(1, self.K)
        #        Nvec2str = blocks.vector_to_stream(4, self.N)
        str2Kvec = blocks.stream_to_vector(1, self.K)
        str2Nvec = blocks.stream_to_vector(1, self.N)
        Kvec2str = blocks.vector_to_stream(1, self.K)
        Nvec2str = blocks.vector_to_stream(1, self.N)

        self.noise = analog.noise_source_f(analog.GR_GAUSSIAN, epsilon, 0)
        self.adder = blocks.add_vff(1)

        self.connect(source, copy, sink)
コード例 #40
0
    def __init__(self):
        gr.top_block.__init__(self, "Control Port")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Control Port")
        qtgui.util.check_set_qss()
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "control_port")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

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

        ##################################################
        # Blocks
        ##################################################
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1,
                                                 samp_rate, True)
        self.blocks_ctrlport_monitor_performance_0 = not True or monitor(
            "gr-perf-monitorx")
        self.blocks_ctrlport_monitor_0 = not True or monitor()
        self.audio_sink_0 = audio.sink(samp_rate, '', True)
        self.analog_noise_source_x_0 = analog.noise_source_f(
            analog.GR_GAUSSIAN, 0.1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.audio_sink_0, 0))
コード例 #41
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P):
    tb = gr.top_block ()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short,Kb/16*P) # packet size in shorts
    s2fsmi=blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
    s2p = blocks.stream_to_streams(gr.sizeof_short,P) # serial to parallel
    enc = trellis.encoder_ss(f,0) # initiali state = 0
    mod = digital.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add=[]
    noise=[]
    for i in range(P):
        add.append(blocks.add_ff())
        noise.append(analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed))

    # RX
    metrics = trellis.metrics_f(f.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
    p2s = blocks.streams_to_stream(gr.sizeof_short,P) # parallel to serial
    fsmi2s=blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect (src,src_head,s2fsmi,s2p)
    for i in range(P):
        tb.connect ((s2p,i),(enc,i),(mod,i))
        tb.connect ((mod,i),(add[i],0))
        tb.connect (noise[i],(add[i],1))
        tb.connect (add[i],(metrics,i))
        tb.connect ((metrics,i),(va,i),(p2s,i))
    tb.connect (p2s,fsmi2s,dst)


    tb.run()

    # A bit of cheating: run the program once and print the
    # final encoder state.
    # Then put it as the last argument in the viterbi block
    #print "final state = " , enc.ST()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()

    return (ntotal,ntotal-nright)
コード例 #42
0
    def run_with_frame_len(self, frame_len):
        self.tb = gr.top_block()
        noise = analog.noise_source_f(analog.GR_GAUSSIAN, 1, 0)
        head = blocks.head(gr.sizeof_float, self.n_frames * frame_len)
        tag = blocks.stream_to_tagged_stream(gr.sizeof_float, 1, frame_len, "packet_len")
        stream2pdu = blocks.tagged_stream_to_pdu(blocks.float_t, 'packet_len')
        
        viterbi = fec.cc_decoder.make(frame_len//2, 7, 2, [79,-109], 0, -1, fec.CC_TERMINATED, False)
        cc_decoder = fec.async_decoder(viterbi, False, False, frame_len)
        
        self.tb.connect(noise, head, tag, stream2pdu)
        self.tb.msg_connect((stream2pdu, 'pdus'), (cc_decoder, 'in'))
        
        self.tb.run()
        # the test is considered successful if it hasn't segfaulted or aborted

        self.tb = None
コード例 #43
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, channel, modulation,
             dimensionality, tot_constellation, Es, N0, IT, seed):
    tb = gr.top_block()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0] * (K)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1)  # random symbols
    src = blocks.vector_source_s(packet, False)
    enc_out = trellis.encoder_ss(fo, 0)  # initial state = 0
    inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1,
                                gr.sizeof_short)
    mod = digital.chunks_to_symbols_sf(modulation[1], modulation[0])

    # CHANNEL
    isi = filter.fir_filter_fff(1, channel)
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    (head, tail) = make_rx(tb, fo, fi, dimensionality, tot_constellation, K,
                           interleaver, IT, Es, N0, trellis.TRELLIS_MIN_SUM)
    dst = blocks.vector_sink_s()

    tb.connect(src, enc_out, inter, mod)
    tb.connect(mod, isi, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, head)
    tb.connect(tail, dst)

    tb.run()

    data = dst.data()
    ntotal = len(data)
    nright = 0
    for i in range(ntotal):
        if packet[i] == data[i]:
            nright = nright + 1
        #else:
        #print "Error in ", i

    return (ntotal, ntotal - nright)
コード例 #44
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.sample_rate = 5000000
        self.ampl = 0.1
        self.freq = 100000000

        self.uhd_usrp_sink_0 = uhd.usrp_sink(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_sink_0.set_samp_rate(self.sample_rate)
        self.uhd_usrp_sink_0.set_center_freq(self.freq, 0)
        self.uhd_usrp_sink_0.set_gain(90, 0)
        self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
        self.uhd_usrp_sink_0.set_bandwidth(100e3, 0)
        self.analog_wfm_tx_0 = analog.wfm_tx(
            audio_rate=32000,
            quad_rate=640000,
            tau=75e-6,
            max_dev=75e3,
        )

        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 1, 0)

        def freq_jump():
            while 1:
                if self.freq < 108000000:
                    self.set_freq( self.freq + 5000000)
                else:
                    self.set_freq(88000000)
                print "Jump!"
                time.sleep(0.2)

        jump_thread = threading.Thread(target=freq_jump)

        jump_thread.daemon = True
        jump_thread.start()

        self.connect((self.analog_wfm_tx_0, 0), (self.uhd_usrp_sink_0, 0))
        self.connect((self.analog_noise_source_x_0, 0), (self.analog_wfm_tx_0, 0))
コード例 #45
0
ファイル: test_tcm.py プロジェクト: danbar/gnuradio
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
    tb = gr.top_block ()

    # TX
    numpy.random.seed(-seed)
    packet = numpy.random.randint(0,2,Kb) # create Kb random bits
    packet[Kb-10:Kb]=0
    packet[0:Kb]=0
    src = blocks.vector_source_s(packet.tolist(),False)
    b2s = blocks.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
    enc = trellis.encoder_ss(f,0) # initial state = 0
    mod = digital.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0 / 2),int(seed))

    # RX
    va = trellis.viterbi_combined_fs(f,K,0,0,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    s2b = blocks.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits
    dst = blocks.vector_sink_s();


    tb.connect (src,b2s,s2fsmi,enc,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,va,fsmi2s,s2b,dst)


    tb.run()

    # A bit of cheating: run the program once and print the
    # final encoder state..
    # Then put it as the last argument in the viterbi block
    #print "final state = " , enc.ST()

    if len(dst.data()) != len(packet):
        print("Error: not enough data:", len(dst.data()), len(packet))
    ntotal=len(packet)
    nwrong = sum(abs(packet-numpy.array(dst.data())));
    return (ntotal,nwrong,abs(packet-numpy.array(dst.data())))
コード例 #46
0
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,Es,N0,IT,seed):
    tb = gr.top_block ()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0]*(K)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols
    src = blocks.vector_source_s(packet,False)
    enc_out = trellis.encoder_ss(fo,0) # initial state = 0
    inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
    mod = digital.chunks_to_symbols_sf(modulation[1],modulation[0])

    # CHANNEL
    isi = filter.fir_filter_fff(1,channel)
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed)

    # RX
    (head,tail) = make_rx(tb,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM)
    dst = blocks.vector_sink_s();

    tb.connect (src,enc_out,inter,mod)
    tb.connect (mod,isi,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,head)
    tb.connect (tail,dst)

    tb.run()

    data = dst.data()
    ntotal = len(data)
    nright=0
    for i in range(ntotal):
        if packet[i]==data[i]:
            nright=nright+1
        #else:
            #print "Error in ", i

    return (ntotal,ntotal-nright)
コード例 #47
0
ファイル: pyqt_example_f.py プロジェクト: 232675/gnuradio
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 1000
        f2 = 2000

        fftsize = 2048

        self.qapp = QtGui.QApplication(sys.argv)

        src1 = analog.sig_source_f(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_f(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src  = blocks.add_ff()
        thr = blocks.throttle(gr.sizeof_float, 100*fftsize)
        noise = analog.noise_source_f(analog.GR_GAUSSIAN, 0.001)
        add = blocks.add_ff()
        self.snk1 = qtgui.sink_f(fftsize, filter.firdes.WIN_BLACKMAN_hARRIS,
                                 0, Rs,
                                 "Float Signal Example",
                                 True, True, True, False)

        self.connect(src1, (src,0))
        self.connect(src2, (src,1))
        self.connect(src, thr, (add,0))
        self.connect(noise, (add,1))
        self.connect(add, self.snk1)

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        self.main_box = dialog_box(pyWin, self.ctrl_win)

        self.main_box.show()
コード例 #48
0
ファイル: fftsink_nongl.py プロジェクト: Andy-Vuong/gnuradio
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        fft_size = 256

        # build our flow graph
        input_rate = 100*20.48e3

        # Generate a complex sinusoid
        #src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 100*2e3, 1)
        src1 = gr.sig_source_c (input_rate, gr.GR_CONST_WAVE, 100*5.75e3, 1)
        noise1 = analog.noise_source_c(analog.GR_UNIFORM, 1.0/10)
        add1 = blocks.add_cc()

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        thr1 = blocks.throttle(gr.sizeof_gr_complex, input_rate)

        sink1 = fft_sink_c(panel, title="Complex Data", fft_size=fft_size,
                           sample_rate=input_rate, baseband_freq=100e3,
                           ref_level=0, y_per_div=20, y_divs=10)
        vbox.Add(sink1.win, 1, wx.EXPAND)

        self.connect(src1, (add1,0))
        self.connect(noise1, (add1,1))
        self.connect(add1, thr1, sink1)

        #src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 100*2e3, 1)
        src2 = gr.sig_source_f (input_rate, gr.GR_CONST_WAVE, 100*5.75e3, 1)
        noise2 = analog.noise_source_f(analog.GR_UNIFORM, 1.0/10)
        add2 = blocks.add_ff()

        thr2 = gr.throttle(gr.sizeof_float, input_rate)
        sink2 = fft_sink_f (panel, title="Real Data", fft_size=fft_size*2,
                            sample_rate=input_rate, baseband_freq=100e3,
                            ref_level=0, y_per_div=20, y_divs=10)
        vbox.Add (sink2.win, 1, wx.EXPAND)

        self.connect(src2, (add2,0))
        self.connect(noise2, (add2,1))
        self.connect(add2, thr2, sink2)
コード例 #49
0
ファイル: top_block.py プロジェクト: manuts/gr-ldpc
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.sigma = sigma = 0.3
        self.samp_rate = samp_rate = 32000
        self.max_iterations = max_iterations = 50

        ##################################################
        # Blocks
        ##################################################
        self.ldpc_lh_detector_fb_0 = ldpc.lh_detector_fb()
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bf(([1.0, -1.0]), 1)
        self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "/home/manu/Downloads/in.flac", False)
        self.blocks_file_sink_2 = blocks.file_sink(gr.sizeof_char*1, "/home/manu/val")
        self.blocks_file_sink_2.set_unbuffered(False)
        self.blocks_file_sink_1 = blocks.file_sink(gr.sizeof_char*1, "/home/manu/ref")
        self.blocks_file_sink_1.set_unbuffered(False)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "/home/manu/out")
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, sigma, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0), (self.blocks_packed_to_unpacked_xx_0, 0))
        self.connect((self.blocks_unpacked_to_packed_xx_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.ldpc_lh_detector_fb_0, 0))
        self.connect((self.ldpc_lh_detector_fb_0, 0), (self.blocks_file_sink_2, 0))
        self.connect((self.ldpc_lh_detector_fb_0, 0), (self.blocks_unpacked_to_packed_xx_0, 0))
        self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.blocks_file_sink_1, 0))
        self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))
コード例 #50
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, tot_constellation, Es, N0, IT, seed):
    tb = gr.top_block()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short, Kb / 16)  # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(
        bitspersymbol, gr.GR_MSB_FIRST
    )  # unpack shorts to symbols compatible with the iouter FSM input cardinality
    enc_out = trellis.encoder_ss(fo, 0)  # initial state = 0
    inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1, gr.sizeof_short)
    enc_in = trellis.encoder_ss(fi, 0)  # initial state = 0
    # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the innner FSM)
    mod = digital.chunks_to_symbols_sf(tot_constellation, dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    (head, tail) = make_rx(
        tb, fo, fi, dimensionality, tot_constellation, K, interleaver, IT, Es, N0, trellis.TRELLIS_MIN_SUM
    )
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect(src, src_head, s2fsmi, enc_out, inter, enc_in, mod)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, head)
    tb.connect(tail, fsmi2s, dst)

    tb.run()

    ntotal = dst.ntotal()
    nright = dst.nright()
    runlength = dst.runlength()
    # print ntotal,nright,runlength

    return (ntotal, ntotal - nright)
コード例 #51
0
ファイル: test_pccc_turbo1.py プロジェクト: 232675/gnuradio
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed):
    tb = gr.top_block ()


    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head (gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality
    #src = blocks.vector_source_s([0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],False)
    enc = trellis.pccc_encoder_ss(fo,0,fi,0,interleaver,K)
    code = blocks.vector_sink_s()
    mod = digital.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed)

    # RX
    metrics_in = trellis.metrics_f(fi.O()*fo.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO
    scale = blocks.multiply_const_ff(1.0/N0)
    dec = trellis.pccc_decoder_s(fo,0,-1,fi,0,-1,interleaver,K,IT,trellis.TRELLIS_MIN_SUM)

    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect (src,src_head,s2fsmi,enc,mod)
    #tb.connect (src,enc,mod)
    #tb.connect(enc,code)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,metrics_in,scale,dec,fsmi2s,dst)

    tb.run()

    #print code.data()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    return (ntotal,ntotal-nright)
コード例 #52
0
ファイル: test_sccc_soft.py プロジェクト: 232675/gnuradio
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
    tb = gr.top_block ()


    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head (gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality
    enc_out = trellis.encoder_ss(fo,0) # initial state = 0
    inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
    enc_in = trellis.encoder_ss(fi,0) # initial state = 0
    mod = digital.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed)

    # RX
    metrics_in = trellis.metrics_f(fi.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner Viterbi
    gnd = blocks.vector_source_f([0],True);
    siso_in = trellis.siso_f(fi,K,0,-1,True,False,trellis.TRELLIS_MIN_SUM) # Put -1 if the Initial/Final states are not set.
    deinter = trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float)
    va_out = trellis.viterbi_s(fo,K,0,-1) # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,metrics_in)
    tb.connect (gnd,(siso_in,0))
    tb.connect (metrics_in,(siso_in,1))
    tb.connect (siso_in,deinter,va_out,fsmi2s,dst)

    tb.run()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    return (ntotal,ntotal-nright)
コード例 #53
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
    tb = gr.top_block ()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
    enc = trellis.encoder_ss(f,0) # initial state = 0
    mod = digital.chunks_to_symbols_sf(constellation,dimensionality)


    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed)


    # RX
    va = trellis.viterbi_combined_fs(f,K,0,-1,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s();


    tb.connect (src,src_head,s2fsmi,enc,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,va,fsmi2s,dst)


    tb.run()

    # A bit of cheating: run the program once and print the
    # final encoder state..
    # Then put it as the last argument in the viterbi block
    #print "final state = " , enc.ST()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()

    return (ntotal,ntotal-nright)
コード例 #54
0
    def __init__(self, N, fs, bw, tw, atten, D):
        gr.top_block.__init__(self)

        self._nsamps = N
        self._fs = fs
        self._bw = bw
        self._tw = tw
        self._at = atten
        self._decim = D
        taps = filter.firdes.low_pass_2(1, self._fs, self._bw, self._tw, self._at)
        print "Num. Taps: ", len(taps)

        self.src  = analog.noise_source_f(analog.GR_GAUSSIAN, 1)
        self.head = blocks.head(gr.sizeof_float, self._nsamps)

        self.filt0 = filter.fir_filter_fff(self._decim, taps)

        self.vsnk_src = blocks.vector_sink_f()
        self.vsnk_out = blocks.vector_sink_f()

        self.connect(self.src, self.head, self.vsnk_src)
        self.connect(self.head, self.filt0, self.vsnk_out)
コード例 #55
0
ファイル: FH.py プロジェクト: acarmon2/GNU-Radio-Examples
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Jammer")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 5000000
        self.Freq = Freq = 105.9e6

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
        	",".join(("", "")),
        	uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_0.set_center_freq(Freq, 0)
        self.uhd_usrp_sink_0.set_gain(90, 0)
        self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
        self.uhd_usrp_sink_0.set_bandwidth(100e3, 0)
        self.analog_wfm_tx_0 = analog.wfm_tx(
        	audio_rate=32000,
        	quad_rate=640000,
        	tau=75e-6,
        	max_dev=75e3,
        )
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_wfm_tx_0, 0), (self.uhd_usrp_sink_0, 0))
        self.connect((self.analog_noise_source_x_0, 0), (self.analog_wfm_tx_0, 0))
コード例 #56
0
ファイル: example1.py プロジェクト: manuts/gr-ldpc
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Example1")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.sigma = sigma = 0.5
        self.samp_rate = samp_rate = 32000
        self.max_iterations = max_iterations = 50
        self.alist_file = alist_file = "/home/manu/repos/ldpc/gr-ldpc/python/alist-files"

        ##################################################
        # Blocks
        ##################################################
        self.ldpc_ldpc_hier_encoder_bb_0 = ldpc.ldpc_hier_encoder_bb("/home/manu/1920.1280.3.303/H1920.1280.3.303")
        self.ldpc_ldpc_hier_decoder_fb_0 = ldpc.ldpc_hier_decoder_fb("/home/manu/1920.1280.3.303/H1920.1280.3.303", sigma, max_iterations)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bf(([1.0, -1.0]), 1)
        self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
        self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb(1, gr.GR_LSB_FIRST)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "/home/manu/Downloads/06 - Coming Back To Life.flac", False)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "/home/manu/Downloads/out", False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, sigma, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0), (self.blocks_packed_to_unpacked_xx_0, 0))
        self.connect((self.ldpc_ldpc_hier_decoder_fb_0, 0), (self.blocks_unpacked_to_packed_xx_0, 0))
        self.connect((self.blocks_unpacked_to_packed_xx_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.ldpc_ldpc_hier_encoder_bb_0, 0))
        self.connect((self.ldpc_ldpc_hier_encoder_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_add_xx_0, 0), (self.ldpc_ldpc_hier_decoder_fb_0, 0))
コード例 #57
0
ファイル: test_bsc.py プロジェクト: manuts/gr-ldpc
 def __init__(self, fname, epsilon, max_iterations):
     gr.top_block.__init__(self)
     self.src = blocks.vector_source_b(())
     print "initializing encoder"
     self.encoder = ldpc.ldpc_encoder_bb(fname)
     print "encoder initialized"
     self.K = self.encoder.get_K()
     self.N = self.encoder.get_N()
     print self.K
     print self.N
     str2Kvec = blocks.stream_to_vector(1, self.K)
     chk2symb = digital.chunks_to_symbols_bf(([1, -1]), 1)
     str2Nvec = blocks.stream_to_vector(4, self.N)
     self.channel = ldpc.bsc_bb(self.N, epsilon)
     self.decoder = ldpc.ldpc_decoder_bb(fname, epsilon, max_iterations)
     print "decoder initialized"
     self.noise = analog.noise_source_f(analog.GR_GAUSSIAN, epsilon, 0)
     self.adder = blocks.add_vff(1)
     Kvec2str = blocks.vector_to_stream(1, self.K)
     Nvec2str = blocks.vector_to_stream(4, self.N)
     self.dst = blocks.vector_sink_b()
     self.connect(self.src, str2Kvec, self.encoder, self.channel,
             self.decoder, Kvec2str, self.dst)
コード例 #58
0
ファイル: FH.py プロジェクト: acarmon2/GNU-Radio-Examples
    def __init__(self):
        gr.top_block.__init__(self)

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 5000000
        self.Freq = Freq = 105.9e6

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_0.set_center_freq(Freq, 0)
        self.uhd_usrp_sink_0.set_gain(90, 0)
        self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
        self.uhd_usrp_sink_0.set_bandwidth(100e3, 0)
        self.analog_wfm_tx_0 = analog.wfm_tx(
            audio_rate=32000,
            quad_rate=640000,
            tau=75e-6,
            max_dev=75e3,
        )
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_wfm_tx_0, 0), (self.uhd_usrp_sink_0, 0))
        self.connect((self.analog_noise_source_x_0, 0), (self.analog_wfm_tx_0, 0))