Several enhancements to gr-trellis and gnuradio-examples/python/channel-coding:
[debian/gnuradio] / gnuradio-examples / python / channel-coding / test_tcm_parallel.py
index 230bf4b9842f8a2ab91846d8f4eca9b11d9f7e15..f9dcb5852607306520c10cabe11e0b97923f9e87 100755 (executable)
@@ -15,7 +15,7 @@ def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P):
     src = gr.lfsr_32k_source_s()
     src_head = gr.head (gr.sizeof_short,Kb/16*P) # packet size in shorts
     s2fsmi=gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
-    s2p = gr.stream_to_streams(2,P) # serial to parallel
+    s2p = gr.stream_to_streams(gr.sizeof_short,P) # serial to parallel
     enc = trellis.encoder_ss(f,0) # initiali state = 0
     mod = gr.chunks_to_symbols_sf(constellation,dimensionality)
 
@@ -26,11 +26,10 @@ def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P):
         add.append(gr.add_ff())
         noise.append(gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed))
 
-    
     # RX
     metrics = trellis.metrics_f(f.O(),dimensionality,constellation,trellis.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 = gr.streams_to_stream(2,P) # parallel to serial
+    p2s = gr.streams_to_stream(gr.sizeof_short,P) # parallel to serial
     fsmi2s=gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
     dst = gr.check_lfsr_32k_s()
 
@@ -90,14 +89,16 @@ def main(args):
 
     tot_s=0 # total number of transmitted shorts
     terr_s=0 # total number of shorts in error
+    terr_p=0 # total number of packets in error
     for i in range(rep):
         (s,e)=run_test(f,Kb,bitspersymbol,K,dimensionality,constellation,N0,-long(666+i),P) # run experiment with different seed to get different noise realizations
         tot_s=tot_s+s
         terr_s=terr_s+e
-        if (i%10==0) & (i>0): # display progress
-            print i,s,e,tot_s,terr_s, '%e' % ((1.0*terr_s)/tot_s)
+        terr_p=terr_p+(terr_s!=0)
+        if ((i+1)%100==0) : # display progress
+            print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s)
     # estimate of the (short or bit) error rate
-    print tot_s,terr_s, '%e' % ((1.0*terr_s)/tot_s)
+    print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s)
 
 
 if __name__ == '__main__':