@@ -543,3 +543,49 @@ def viterbi_decode(coded_bits, trellis, tb_depth=None, decoding_type='hard'):
543543 current_number_states = 1
544544
545545 return decoded_bits [0 :len (decoded_bits )- tb_depth - 1 ]
546+
547+ def puncturing (message , punct_vec ):
548+ '''
549+ Applying of the punctured procedure.
550+ Parameters
551+ ----------
552+ message: input message {0,1}
553+ punct_vec: puncturing vector {0,1}
554+ Returns
555+ -------
556+ punctured: output punctured vector {0,1}
557+ '''
558+ shift = 0
559+ N = len (punct_vec )
560+ punctured = []
561+ for idx , item in enumerate (message ):
562+ if punct_vec [idx - shift * N ] == 1 :
563+ punctured .append (item )
564+ if idx % N == 0 :
565+ shift = shift + 1
566+ return np .array (punctured )
567+
568+ def depuncturing (punctured , punct_vec , shouldbe ):
569+ '''
570+ Applying of the inserting zeros procedure.
571+ Parameters
572+ ----------
573+ punctured: input punctured message {0,1}
574+ punct_vec: puncturing vector {0,1}
575+ shouldbe: length of the initial message (before puncturing)
576+ Returns
577+ -------
578+ depunctured: output vector {0,1}
579+ '''
580+ shift = 0
581+ shift2 = 0
582+ N = len (punct_vec )
583+ depunctured = np .zeros ((shouldbe ,))
584+ for idx , item in enumerate (depunctured ):
585+ if punct_vec [idx - shift * N ] == 1 :
586+ depunctured [idx ] = float (punctured [idx - shift2 ])
587+ else :
588+ shift2 = shift2 + 1
589+ if idx % N == 0 :
590+ shift = shift + 1 ;
591+ return depunctured
0 commit comments