commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r3312 - gnuradio/branches/developers/anastas/wip/gnura


From: anastas
Subject: [Commit-gnuradio] r3312 - gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding
Date: Wed, 16 Aug 2006 11:06:33 -0600 (MDT)

Author: anastas
Date: 2006-08-16 11:06:33 -0600 (Wed, 16 Aug 2006)
New Revision: 3312

Added:
   
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/test_tcm2.py
Modified:
   
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/README
   
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/fsm_utils.py
   
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/test_sccc_turbo.py
Log:
clean up

Modified: 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/README
===================================================================
--- 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/README
     2006-08-16 16:58:21 UTC (rev 3311)
+++ 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/README
     2006-08-16 17:06:33 UTC (rev 3312)
@@ -10,6 +10,7 @@
 
 ./test_tcm.py fsm_files/awgn1o2_4.fsm 10.0 1000
 ./test_tcm1.py fsm_files/awgn1o2_4.fsm 10.0 1000
+./test_tcm2.py 10.0 1000
 ./test_tcm_combined.py fsm_files/awgn1o2_4.fsm 10.0 1000
 ./test_tcm_parallel.py fsm_files/awgn1o2_4.fsm 10.0 1000
 ./test_sccc_hard.py fsm_files/awgn1o2_4.fsm fsm_files/awgn1o2_4.fsm 10.0 1000
@@ -30,6 +31,6 @@
 900 1024 0 922624 1120 1.213929e-03
 1024000 1129 1.102539e-03
 
-1.102539e-03 is the error rate estimates by sending 1000 packets of
-1024x16 bits each using an 1/2 4-state convolutional code and QPSK
+1.102539e-03 is the error rate estimate by sending 1000 packets of
+1024 shorts each, using an 1/2 4-state convolutional code and QPSK
 modulation through an AWGN with Es/N0 = 6.0 dB

Modified: 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/fsm_utils.py
===================================================================
--- 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/fsm_utils.py
       2006-08-16 16:58:21 UTC (rev 3311)
+++ 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/fsm_utils.py
       2006-08-16 17:06:33 UTC (rev 3312)
@@ -60,102 +60,7 @@
 
 
 
-
-
 ######################################################################
-# Automaticaly generate the FSM structure for a binary feed-forward
-# convolutional code.
-# Input: k x n generator matrix (decimal representation)
-######################################################################
-def make_fsm_bin_cc_ff(k,n,GM):
-    mem=[[]]*k
-    max_mem_x=[-1]*k
-    max_mem = -1
-    for i in range(k):
-        memr=[0]*n
-        for j in range(n):
-            if GM[i][j]==0:
-                memr[j]=-1
-            else:
-                memr[j]=int(math.log(GM[i][j],2))
-            if memr[j]>max_mem_x[i]:
-                max_mem_x[i]=memr[j]
-            if memr[j]>max_mem:
-                max_mem=memr[j]
-        mem[i]=memr
-
-    sum_max_mem = 0
-    for i in range(k):
-       sum_max_mem = sum_max_mem+max_mem_x[i] 
-        
-
-    #print mem
-    #print max_mem_x
-    #print max_mem
-    #print sum_max_mem
-
-    I=2**k
-    S=2**sum_max_mem
-    O=2**n
-
-    #print I, S, O
-
-    NS=[0]*S*I;
-    OS=[0]*S*I;
-    for s in range(S):
-        for i in range(I):
-            ss=dec2base(s,2,sum_max_mem)
-            ind=0
-            ss_r=[]
-            for kk in range(k):
-                ss1 = [0]*max_mem
-                ss1[0:max_mem_x[kk]] = ss[ind:ind+max_mem_x[kk]]
-                ss_r.append(ss1)
-                ind=ind+max_mem_x[kk]
-            ii=dec2base(i,2,k)
-
-            tt_r = ss_r
-            for kk in range(k):
-                tt_r[kk].insert(0,ii[kk])
-            #print tt_r
-
-            ns_r = []
-            for kk in range(k):
-                ns_r.append(tt_r[kk][0:max_mem])
-
-            ns=[]
-            for kk in range(k):
-                ns = ns + ns_r[kk][0:max_mem_x[kk]]
-            NS[s*I+i]=base2dec(ns,2);
-
-            out_r=[0]*n
-            for nn in range(n):
-                out=0;
-                for kk in range(k):
-                    c=[0]*max_mem
-                    gm = dec2base(GM[kk][nn],2,max_mem_x[kk]+1)
-                    gm.reverse()
-                    c[0:len(gm)] = gm
-                    sy = 0
-                    for m in range(len(c)):
-                        sy = sy + c[m]*tt_r[kk][m];
-                    out=operator.mod(out+sy,2);
-                out_r[nn]=out;
-            out_r.reverse()
-            OS[s*I+i] = base2dec(out_r,2);
-    
-    #O=max(max(OS))+1;
-    print I, S, O
-    print NS
-    print OS
-
-    return (I,S,O,NS,OS)
-
-
-
-
-
-######################################################################
 # Automatically generate the lookup table that maps the FSM outputs
 # to channel inputs corresponding to a channel 'channel' and a modulation
 # 'mod'. Optional normalization of channel to unit energy.

Modified: 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/test_sccc_turbo.py
===================================================================
--- 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/test_sccc_turbo.py
 2006-08-16 16:58:21 UTC (rev 3311)
+++ 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/test_sccc_turbo.py
 2006-08-16 17:06:33 UTC (rev 3312)
@@ -119,7 +119,7 @@
         Es = Es + constellation[i]**2
     Es = Es / (len(constellation)/dimensionality)
     N0=Es/pow(10.0,esn0_db/10.0); # calculate noise variance
-    IT = 2 # number of turbo iterations
+    IT = 3 # number of turbo iterations
     
     tot_s=0 # total number of transmitted shorts
     terr_s=0 # total number of shorts in error

Added: 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/test_tcm2.py
===================================================================
--- 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/test_tcm2.py
                               (rev 0)
+++ 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/test_tcm2.py
       2006-08-16 17:06:33 UTC (rev 3312)
@@ -0,0 +1,114 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
+    fg = gr.flow_graph ()
+
+
+    # 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 = gr.vector_source_s(packet,False)
+    src = gr.lfsr_32k_source_s()
+    src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts
+    #b2s = gr.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts
+    s2fsmi = gr.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 = gr.chunks_to_symbols_sf(constellation,dimensionality)
+
+    # CHANNEL
+    add = gr.add_ff()
+    noise = 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.
+    fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack 
FSM input symbols to shorts
+    #s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits
+    #dst = gr.vector_sink_s(); 
+    dst = gr.check_lfsr_32k_s()
+    
+
+    fg.connect (src,src_head,s2fsmi,enc,mod)
+    #fg.connect (src,b2s,s2fsmi,enc,mod)
+    fg.connect (mod,(add,0))
+    fg.connect (noise,(add,1))
+    fg.connect (add,metrics)
+    fg.connect (metrics,va,fsmi2s,dst)
+    #fg.connect (metrics,va,fsmi2s,s2b,dst)
+    
+
+    fg.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)
+
+
+
+
+def main(args):
+    nargs = len (args)
+    if nargs == 2:
+        esn0_db=float(args[0]) # Es/No in dB
+        rep=int(args[1]) # number of times the experiment is run to collect 
enough errors
+    else:
+        sys.stderr.write ('usage: test_tcm2.py Es/No_db  repetitions\n')
+        sys.exit (1)
+
+    # system parameters
+    f=trellis.fsm(1,2,[5,7]) # generate FSM specification from the generator 
matrix
+    Kb=1024*16  # packet size in bits (make it multiple of 16 so it can be 
packed in a short)
+    bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM 
input symbol
+    K=Kb/bitspersymbol # packet size in trellis steps
+    modulation = fsm_utils.psk4 # see fsm_utlis.py for available predefined 
modulations
+    dimensionality = modulation[0]
+    constellation = modulation[1] 
+    if len(constellation)/dimensionality != f.O():
+        sys.stderr.write ('Incompatible FSM output cardinality and modulation 
size.\n')
+        sys.exit (1)
+    # calculate average symbol energy
+    Es = 0
+    for i in range(len(constellation)):
+        Es = Es + constellation[i]**2
+    Es = Es / (len(constellation)/dimensionality)
+    N0=Es/pow(10.0,esn0_db/10.0); # calculate noise variance
+    
+    tot_s=0 # total number of transmitted shorts
+    terr_s=0 # total number of shorts in error
+    for i in range(rep):
+        
(s,e)=run_test(f,Kb,bitspersymbol,K,dimensionality,constellation,N0,-long(666+i))
 # run experiment with different seed to get different noise realizations
+        tot_s=tot_s+s
+        terr_s=terr_s+e
+        if (i%100==0) & (i>0): # display progress
+            print i,s,e,tot_s,terr_s, '%e' % ((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)
+
+
+if __name__ == '__main__':
+    main (sys.argv[1:])


Property changes on: 
gnuradio/branches/developers/anastas/wip/gnuradio-examples/python/channel-coding/test_tcm2.py
___________________________________________________________________
Name: svn:executable
   + *





reply via email to

[Prev in Thread] Current Thread [Next in Thread]