def main(): tb = gr.top_block() # noise source n = mlse.randint_b(2) reshape_n = gr.stream_to_vector(1, 58*2) tb.connect(n,reshape_n) # limit experiment length head=gr.head(58*2,1) tb.connect(reshape_n, head) # modulate gsm_burstmod = gsm.gsm_modulate_burst() tb.connect(head, gsm_burstmod) random_tsc_index = mlse.randint_b(8); tb.connect(random_tsc_index, (gsm_burstmod,1)) # apply channel channel = gsm.my_channel(-100,[0.2,1,0.2]) channel_apply = gsm.apply_channel_to_vect(148, channel, 1) tb.connect(gsm_burstmod, channel_apply) # derotate derot = mlse.derotate_cc(148,4,-1) #FIXME: why -1? (not as if it matters) tb.connect(channel_apply, derot) modsink = gr.vector_sink_c(148) datasink = gr.vector_sink_b(58*2) tb.connect(derot, modsink) tb.connect(head, datasink) # mlse-decode decode = mlse.equalizer_midamble_vcb(mlse.make_packet_config_gsm()) tb.connect(derot,decode) tb.connect(random_tsc_index, (decode,1)) # ber ber = mlse.ber_vbi(58*2) tb.connect(decode, ber) tb.connect(head, (ber,1)) result_sink = gr.vector_sink_b(58*2) tb.connect(decode, result_sink) chanest_sink = gr.vector_sink_c(7) tb.connect((decode,1), chanest_sink) tb.run() tb.run() d=modsink.data() # printvect_c(d) print ber.bit_error_rate() print_bitvect( datasink.data()) print_bitvect( result_sink.data()) import operator print_bitvect( map(operator.xor, datasink.data(), result_sink.data())) printvect_c( chanest_sink.data())
def main(): tb = gr.top_block() # noise source n = mlse.randint_b(2) reshape_n = gr.stream_to_vector(1, 58 * 2) tb.connect(n, reshape_n) # limit experiment length head = gr.head(58 * 2, 1) tb.connect(reshape_n, head) # modulate gsm_burstmod = gsm.gsm_modulate_burst() tb.connect(head, gsm_burstmod) random_tsc_index = mlse.randint_b(8) tb.connect(random_tsc_index, (gsm_burstmod, 1)) # apply channel channel = gsm.my_channel(-100, [0.2, 1, 0.2]) channel_apply = gsm.apply_channel_to_vect(148, channel, 1) tb.connect(gsm_burstmod, channel_apply) # derotate derot = mlse.derotate_cc(148, 4, -1) #FIXME: why -1? (not as if it matters) tb.connect(channel_apply, derot) modsink = gr.vector_sink_c(148) datasink = gr.vector_sink_b(58 * 2) tb.connect(derot, modsink) tb.connect(head, datasink) # mlse-decode decode = mlse.equalizer_midamble_vcb(mlse.make_packet_config_gsm()) tb.connect(derot, decode) tb.connect(random_tsc_index, (decode, 1)) # ber ber = mlse.ber_vbi(58 * 2) tb.connect(decode, ber) tb.connect(head, (ber, 1)) result_sink = gr.vector_sink_b(58 * 2) tb.connect(decode, result_sink) chanest_sink = gr.vector_sink_c(7) tb.connect((decode, 1), chanest_sink) tb.run() tb.run() d = modsink.data() # printvect_c(d) print ber.bit_error_rate() print_bitvect(datasink.data()) print_bitvect(result_sink.data()) import operator print_bitvect(map(operator.xor, datasink.data(), result_sink.data())) printvect_c(chanest_sink.data())
def make_flowgraph(self): tb = gr.top_block() # noise source n = mlse.randint_b(2) reshape_n = gr.stream_to_vector(1, 58 * 2) tb.connect(n, reshape_n) # limit experiment length head = gr.head(58 * 2, self.packets) tb.connect(reshape_n, head) # modulate gsm_burstmod = gsm.gsm_modulate_burst() tb.connect(head, gsm_burstmod) random_tsc_index = mlse.randint_b(8) tb.connect(random_tsc_index, (gsm_burstmod, 1)) # apply channel channel = gsm.my_channel(self.snr, self.chan_taps) channel_apply = gsm.apply_channel_to_vect(148, channel, 3) #TODO: don't use to_vector and to_stream for the channel tb.connect(gsm_burstmod, channel_apply) # derotate derot = mlse.derotate_cc(148, 4, -1) #FIXME: why -1? (not as if it matters) tb.connect(channel_apply, derot) # mlse-decode if (self.no_decorr): decode = gsm.gsm_decode_harddecision() else: decode = mlse.equalizer_midamble_vcb(mlse.make_packet_config_gsm()) tb.connect(random_tsc_index, (decode, 1)) tb.connect(derot, decode) # ber ber = mlse.ber_vbi(58 * 2) tb.connect(decode, ber) tb.connect(head, (ber, 1)) if (not self.no_decorr): # throw away channel-estimate data chanest_sink = gr.null_sink(6 * gr.sizeof_gr_complex) tb.connect((decode, 1), chanest_sink) # export members we need self.tb = tb self.ber = ber self.head = head self.channel = channel
def make_flowgraph(self): tb = gr.top_block() # noise source n = mlse.randint_b(2) reshape_n = gr.stream_to_vector(1, 58*2) tb.connect(n,reshape_n) # limit experiment length head=gr.head(58*2,self.packets) tb.connect(reshape_n, head) # modulate gsm_burstmod = gsm.gsm_modulate_burst() tb.connect(head, gsm_burstmod) random_tsc_index = mlse.randint_b(8); tb.connect(random_tsc_index, (gsm_burstmod,1)) # apply channel channel = gsm.my_channel(self.snr, self.chan_taps) channel_apply = gsm.apply_channel_to_vect(148, channel, 3) #TODO: don't use to_vector and to_stream for the channel tb.connect(gsm_burstmod, channel_apply) # derotate derot = mlse.derotate_cc(148,4,-1) #FIXME: why -1? (not as if it matters) tb.connect(channel_apply, derot) # mlse-decode if(self.no_decorr): decode = gsm.gsm_decode_harddecision() else: decode = mlse.equalizer_midamble_vcb(mlse.make_packet_config_gsm()) tb.connect(random_tsc_index, (decode,1)) tb.connect(derot,decode) # ber ber = mlse.ber_vbi(58*2) tb.connect(decode, ber) tb.connect(head, (ber,1)) if(not self.no_decorr): # throw away channel-estimate data chanest_sink = gr.null_sink(6*gr.sizeof_gr_complex) tb.connect((decode,1), chanest_sink) # export members we need self.tb = tb self.ber = ber self.head = head self.channel = channel
def __init__(self): gr.hier_block2.__init__(self, 'gsm_decode_harddecision', gr.io_signature(1, 1, gr.sizeof_gr_complex * 148 ), gr.io_signature(1,1,58*2)) conf = mlse.make_packet_config_gsm() slice1 = conf.make_slicer(conf.PAYLOAD_FRONT) slice2 = conf.make_slicer(conf.PAYLOAD_REAR) cat = mlse.vector_concat_vv(58*gr.sizeof_gr_complex, 58*gr.sizeof_gr_complex) tostream = gr.vector_to_stream(gr.sizeof_gr_complex, 58*2) real = gr.complex_to_real() sign = gr.binary_slicer_fb() demap = gr.map_bb([1,0]) # invert 0 and 1 because in gsm 0 is mapped to +1 and 1 to -1 tovect = gr.stream_to_vector(1, 58*2) self.connect(self, slice1) self.connect(self, slice2) self.connect(slice1, (cat,0)) self.connect(slice2, (cat,1)) self.connect(cat, tostream, real, sign, demap, tovect, self)
def test_viterbi(): tb=gr.top_block() channel = [0,1,0] prellen = len(channel) - 1 data = [random.randint(0,1) for i in xrange(20+prellen)] data.extend([0,0,0]) # tailbits data.extend([0]*6) # to flush modulator # modulate datasrc = gr.vector_source_b(data) diffcode = mlse.xor_encode_bb(); nrz = gr.map_bb([1,-1]) mod = gr.gmskmod_bc(1, 0.3, 12) derot = mlse.derotate_cc(); modsink = gr.vector_sink_c(); tb.connect(datasrc, diffcode, nrz, mod, derot, modsink) tb.run() samples = modsink.data()[6:] printvect_c(samples) preload = data[:prellen] rest = data[prellen:][:20] tb=gr.top_block() conf=mlse.make_packet_config_gsm() vit = mlse.viterbi_vcb(20,len(channel),3,[1,-1])#conf.get_constellation()) chansrc = gr.vector_source_c(channel,vlen=len(channel)) preloadsrc = gr.vector_source_b(preload,vlen=len(preload)) samplesrc = gr.vector_source_c(samples,vlen=len(samples)) sink = gr.vector_sink_b(20) tb.connect(chansrc, (vit,0)) tb.connect(samplesrc, (vit,1)) tb.connect(preloadsrc, (vit,2)) tb.connect(vit, sink) tb.run() print_bitvect(preload) print_bitvect(rest) print_bitvect(sink.data())
def test_viterbi(): tb = gr.top_block() channel = [0, 1, 0] prellen = len(channel) - 1 data = [random.randint(0, 1) for i in xrange(20 + prellen)] data.extend([0, 0, 0]) # tailbits data.extend([0] * 6) # to flush modulator # modulate datasrc = gr.vector_source_b(data) diffcode = mlse.xor_encode_bb() nrz = gr.map_bb([1, -1]) mod = gr.gmskmod_bc(1, 0.3, 12) derot = mlse.derotate_cc() modsink = gr.vector_sink_c() tb.connect(datasrc, diffcode, nrz, mod, derot, modsink) tb.run() samples = modsink.data()[6:] printvect_c(samples) preload = data[:prellen] rest = data[prellen:][:20] tb = gr.top_block() conf = mlse.make_packet_config_gsm() vit = mlse.viterbi_vcb(20, len(channel), 3, [1, -1]) #conf.get_constellation()) chansrc = gr.vector_source_c(channel, vlen=len(channel)) preloadsrc = gr.vector_source_b(preload, vlen=len(preload)) samplesrc = gr.vector_source_c(samples, vlen=len(samples)) sink = gr.vector_sink_b(20) tb.connect(chansrc, (vit, 0)) tb.connect(samplesrc, (vit, 1)) tb.connect(preloadsrc, (vit, 2)) tb.connect(vit, sink) tb.run() print_bitvect(preload) print_bitvect(rest) print_bitvect(sink.data())
def __init__(self, samples_per_symbol=1): gr.hier_block2.__init__(self, 'gsm_modulate_burst', gr.io_signature2(2, 2, 58 * 2, 1), gr.io_signature(1, 1, gr.sizeof_gr_complex)) # take care of the packetizer conf = mlse.make_packet_config_gsm() self.packetbuilder = mlse.packetbuilder_midamble_vbb(conf) self.connect(self, self.packetbuilder) self.connect((self, 1), (self.packetbuilder, 1)) # tsc_index # append 8 1-bits to the packet for the idle-time between bursts. # This is necessary among others to flush the gmsk-modulator which is causal. # (We use 1-bits because that's what the gsm-standard says) # (we also only use 8 bits, because the specified value of 8.25 only works # properly with samplerates that are a multiple of 4.) self.guardbits = gr.vector_source_b((1, ) * 8, True, 8) self.guard_cat = mlse.vector_concat_vv(148, 8) self.connect(self.packetbuilder, self.guard_cat) self.connect(self.guardbits, (self.guard_cat, 1)) # we now have a vector of bits, transform that into a stream self.tostream = gr.vector_to_stream(1, 148 + 8) # do the precoding: self.diffcode = gr.diff_decoder_bb(2) self.nrz = gr.map_bb([1, -1]) self.connect(self.guard_cat, self.tostream, self.diffcode, self.nrz) # modulate self.mod = digital.gmskmod_bc(samples_per_symbol, 0.3, 8) # skip the first gmsk_length*samplerate/2 samples to make this block # acausal. # self.skiphead = gr.skiphead(gr.sizeof_gr_complex, int(samples_per_symbol*4.5)); # self.connect(self.nrz, self.mod, self.skiphead, self) self.connect(self.nrz, self.mod, self) # workaround: we need a negative delay later,
def __init__(self): gr.hier_block2.__init__( self, 'gsm_decode_harddecision', gr.io_signature(1, 1, gr.sizeof_gr_complex * 148), gr.io_signature(1, 1, 58 * 2)) conf = mlse.make_packet_config_gsm() slice1 = conf.make_slicer(conf.PAYLOAD_FRONT) slice2 = conf.make_slicer(conf.PAYLOAD_REAR) cat = mlse.vector_concat_vv(58 * gr.sizeof_gr_complex, 58 * gr.sizeof_gr_complex) tostream = gr.vector_to_stream(gr.sizeof_gr_complex, 58 * 2) real = gr.complex_to_real() sign = gr.binary_slicer_fb() demap = gr.map_bb( [1, 0]) # invert 0 and 1 because in gsm 0 is mapped to +1 and 1 to -1 tovect = gr.stream_to_vector(1, 58 * 2) self.connect(self, slice1) self.connect(self, slice2) self.connect(slice1, (cat, 0)) self.connect(slice2, (cat, 1)) self.connect(cat, tostream, real, sign, demap, tovect, self)
def __init__(self, samples_per_symbol = 1): gr.hier_block2.__init__(self, 'gsm_modulate_burst', gr.io_signature2(2,2,58*2,1), gr.io_signature(1, 1, gr.sizeof_gr_complex)) # take care of the packetizer conf = mlse.make_packet_config_gsm() self.packetbuilder = mlse.packetbuilder_midamble_vbb(conf) self.connect(self, self.packetbuilder) self.connect((self,1), (self.packetbuilder,1)) # tsc_index # append 8 1-bits to the packet for the idle-time between bursts. # This is necessary among others to flush the gmsk-modulator which is causal. # (We use 1-bits because that's what the gsm-standard says) # (we also only use 8 bits, because the specified value of 8.25 only works # properly with samplerates that are a multiple of 4.) self.guardbits = gr.vector_source_b((1,)*8,True,8) self.guard_cat = mlse.vector_concat_vv(148,8) self.connect(self.packetbuilder, self.guard_cat) self.connect(self.guardbits, (self.guard_cat,1)) # we now have a vector of bits, transform that into a stream self.tostream = gr.vector_to_stream(1, 148+8) # do the precoding: self.diffcode = gr.diff_decoder_bb(2); self.nrz = gr.map_bb([1,-1]) self.connect(self.guard_cat, self.tostream, self.diffcode, self.nrz) # modulate self.mod = digital.gmskmod_bc(samples_per_symbol, 0.3, 8) # skip the first gmsk_length*samplerate/2 samples to make this block # acausal. # self.skiphead = gr.skiphead(gr.sizeof_gr_complex, int(samples_per_symbol*4.5)); # self.connect(self.nrz, self.mod, self.skiphead, self) self.connect(self.nrz, self.mod, self) # workaround: we need a negative delay later,