def __init__(self, ): # """ # docstring # """ gr.hier_block2.__init__(self, "viterbi_vfvb", gr.io_signature(1,1, gr.sizeof_float*120), # sizeof (<+float+>)), # Input signature gr.io_signature(1,1, gr.sizeof_char*40 )) #sizeof (<+float+>))) # Output signature #print "\nlte_viterbi_vfvb START" #tpp=gr.tag_propagation_policy() ################################# # Define blocks # Repeat input vector one time to get viterbi decoder state right (tail-biting stuff) self.rpt = gr.repeat(gr.sizeof_float*120,2) # viterbi decoder requires stream as input self.vtos = gr.vector_to_stream(1*gr.sizeof_float,120) # Correct FSM instantiation: k=num_input_bits, n=num_output_bits, Tuple[dim(k*n)] (decimal notation) self.fsm = trellis.fsm(1,3,[91,121,117]) # Values for viterbi decoder K = 80 # steps for one coding block SO = 0 # initial state SK = -1 # final state (in this case unknown, therefore -1) D = 3 # dimensionality # D = 3 follows from the fact that 1 {0,1} input symbol of the encoder produces 3 {0,1} output symbols. # (packed into one byte {0,1,...,7} ) # with NRZ coding follows: # 0 --> 1 # 1 --> -1 # This leads to the following constellation input # | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | constellation = [1,1,1,1,1,-1,1,-1,1,1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1] # print "len(constellation)/D = " + str(len(constellation)/D) + "\tfsm.O = " + str(self.fsm.O()) # Viterbi_combined input: FSM, K, SO, SK, D, TABLE, TYPE # FSM = Finite State Machine # K = number of output symbols produced by the FSM # SO = initial state of the FSM # SK = final state of the FSM (unknown in this example) # D = dimensionality # TABLE = constellation of the input symbols self.vit = trellis.viterbi_combined_fb(self.fsm,K,SO,SK,D,constellation,200) # stream output of viterbi decoder to vector self.stov2 = gr.stream_to_vector(1*gr.sizeof_char,80) # second half of the viterbi output carries desired information. (tail-biting stuff) my_map=range(40) for i in my_map: my_map[i]=i+40 self.map = lte.vector_resize_vbvb(my_map,80,40) self.connect(self,self.rpt,self.vtos,self.vit,self.stov2,self.map,self)
def setUp (self): self.tb = gr.top_block () # Read in successfully decoded live data from Matlab linf=open('/home/demel/exchange/matlab_d.txt') lintu=range(120) for i in lintu: lintu[i]=float(linf.readline()) #print lintu # source for live data self.srcl = gr.vector_source_f(lintu,False,120) # Read in .txt file with example MIB encoded + CRC checksum inf=open('/home/demel/exchange/crc.txt') self.intu=range(40) for i in self.intu: self.intu[i]=float(inf.readline()) #inf=open('/home/demel/exchange/matlab_d.txt') #intu=range(120) #for i in range(120): # intu[i]=float(inf.readline()) # Source and conversions self.src = gr.vector_source_f(self.intu,False,40) self.conv = gr.float_to_char(40,1) # Resize vector with repetition of last part # Vector to stream for encoder my_map1=range(46) for i in range(40): my_map1[i+6]=i for i in range(6): my_map1[i]=i+40 self.map1 = lte.vector_resize_vbvb(my_map1,40,46) self.vtos = gr.vector_to_stream(1*gr.sizeof_char,46) # Encoding of input data self.fsm = trellis.fsm(1,3,[91,121,117]) self.enc = trellis.encoder_bb(self.fsm,0) # unpack packed bits from encoder self.unp = gr.unpack_k_bits_bb(3) # stream to vector self.stov = gr.stream_to_vector(1*gr.sizeof_char,138) # Remove first part which contains tail-biting init stuff map2 = range(120) for i in map2: map2[i]= i+18 self.map2 = lte.vector_resize_vbvb(map2,138,120) # conversion from char to float to match input of decoder self.conv2= gr.char_to_float(120,1) ############################################### # From here on only "receiver side" processing ############################################### # like QPSK demodulation: NRZ coding. vec2=range(120) for i in vec2: vec2[i]=float(-2.0) self.mult = gr.multiply_const_vff(vec2) vec=range(120) for i in vec: vec[i]=1 self.add = gr.add_const_vff(vec) # this is the actual unit under test self.vit = lte.viterbi_vfvb() # Sinks self.snk = gr.vector_sink_b(40) self.snk2 = gr.vector_sink_f(120) # connecting blocks self.tb.connect(self.src,self.conv,self.map1,self.vtos,self.enc,self.unp) self.tb.connect(self.unp,self.stov,self.map2,self.conv2) self.tb.connect(self.conv2,self.mult,self.add) self.tb.connect(self.srcl,self.vit,self.snk) self.tb.connect(self.add,self.snk2)
def __init__(self, ): # """ # docstring # """ gr.hier_block2.__init__(self, "viterbi_vfvb", gr.io_signature(1,1, gr.sizeof_float*120), # sizeof (<+float+>)), # Input signature gr.io_signature(1,1, gr.sizeof_char*40 )) #sizeof (<+float+>))) # Output signature #print "\nlte_viterbi_vfvb START" #tpp=gr.tag_propagation_policy() ################################# # Define blocks # Repeat input vector one time to get viterbi decoder state right (tail-biting stuff) self.rpt = gr.repeat(gr.sizeof_float*120,2) # viterbi decoder requires stream as input self.vtos = gr.vector_to_stream(1*gr.sizeof_float,120) # Correct FSM instantiation: k=num_input_bits, n=num_output_bits, Tuple[dim(k*n)] (decimal notation) self.fsm = trellis.fsm(1,3,[91,121,117]) # print "\nFSM attributes" # print "FSM.I() = " + str(self.fsm.I()) # input states # print "FSM.S() = " + str(self.fsm.S()) # FSM states # print "FSM.O() = " + str(self.fsm.O()) # output states # print "FSM.NS() = " + str(self.fsm.NS()) # next states of the FSM itself # print "FSM.OS() = " + str(self.fsm.OS()) # output states # print "FSM.PS() = " + str(self.fsm.PS()) # previous states (not available in this example?) # print "FSM.PI() = " + str(self.fsm.PI()) # previous input states (not available in this example?) # print "FSM.TMi() = " + str(self.fsm.TMi()) # print "FSM.TMI() = " + str(self.fsm.TMl()) # Values for viterbi decoder K = 40 # steps for one coding block SO = 0 # initial state SK = -1 # final state (in this case unknown, therefore -1) D = 3 # dimensionality # D = 3 follows from the fact that 1 {0,1} input symbol of the encoder produces 3 {0,1} output symbols. # (packed into one byte {0,1,...,7} ) # with NRZ coding follows: # 0 --> 1 # 1 --> -1 # This leads to the following constellation input # | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | constellation = [1,1,1,1,1,-1,1,-1,1,1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1] # print "len(constellation)/D = " + str(len(constellation)/D) + "\tfsm.O = " + str(self.fsm.O()) # Viterbi_combined input: FSM, K, SO, SK, D, TABLE, TYPE # FSM = Finite State Machine # K = number of output symbols produced by the FSM # SO = initial state of the FSM # SK = final state of the FSM (unknown in this example) # D = dimensionality # TABLE = constellation of the input symbols self.vit = trellis.viterbi_combined_fb(self.fsm,K,SO,SK,D,constellation,200) # print "\nViterbi_combined_fb attributes" # print "K = " + str(self.vit.K()) # print "SO = " + str(self.vit.SO()) # initial state # print "SK = " + str(self.vit.SK()) # final state # print "D = " + str(self.vit.D()) # print "TYPE = " + str(self.vit.TYPE()) # for i in range(len(self.vit.TABLE())/D): # print "TABLE =\t" + str(self.vit.TABLE()[i*D]) + "\t" + str(self.vit.TABLE()[i*D+1]) + "\t" + str(self.vit.TABLE()[i*D+2]) # stream output of viterbi decoder to vector self.stov2 = gr.stream_to_vector(1*gr.sizeof_char,80) # second half of the viterbi output carries desired information. (tail-biting stuff) my_map=range(40) for i in my_map: my_map[i]=i+40 self.map = lte.vector_resize_vbvb(my_map,80,40) self.connect(self,self.rpt,self.vtos,self.vit,self.stov2,self.map,self)