summaryrefslogtreecommitdiff
path: root/gr-trellis/src/examples
diff options
context:
space:
mode:
Diffstat (limited to 'gr-trellis/src/examples')
-rw-r--r--gr-trellis/src/examples/Makefile.am2
-rw-r--r--gr-trellis/src/examples/README24
-rwxr-xr-xgr-trellis/src/examples/test_pccc_turbo1.py119
-rwxr-xr-xgr-trellis/src/examples/test_sccc_hard.py1
-rwxr-xr-xgr-trellis/src/examples/test_sccc_soft.py1
-rwxr-xr-xgr-trellis/src/examples/test_sccc_turbo.py9
-rwxr-xr-xgr-trellis/src/examples/test_sccc_turbo1.py (renamed from gr-trellis/src/examples/test_tcm2.py)75
-rwxr-xr-xgr-trellis/src/examples/test_sccc_turbo2.py101
-rwxr-xr-xgr-trellis/src/examples/test_tcm.py30
-rwxr-xr-xgr-trellis/src/examples/test_tcm_bit.py (renamed from gr-trellis/src/examples/test_tcm1.py)32
-rwxr-xr-xgr-trellis/src/examples/test_tcm_combined.py29
-rwxr-xr-xgr-trellis/src/examples/test_tcm_parallel.py29
-rwxr-xr-xgr-trellis/src/examples/test_turbo_equalization.py1
-rwxr-xr-xgr-trellis/src/examples/test_turbo_equalization1.py1
-rwxr-xr-xgr-trellis/src/examples/test_turbo_equalization2.py1
-rwxr-xr-xgr-trellis/src/examples/test_viterbi_equalization.py1
-rwxr-xr-xgr-trellis/src/examples/test_viterbi_equalization1.py1
17 files changed, 331 insertions, 126 deletions
diff --git a/gr-trellis/src/examples/Makefile.am b/gr-trellis/src/examples/Makefile.am
index 8fb727acd..92aeadfad 100644
--- a/gr-trellis/src/examples/Makefile.am
+++ b/gr-trellis/src/examples/Makefile.am
@@ -31,8 +31,6 @@ dist_ourdata_DATA = \
dist_ourdata_SCRIPTS = \
fsm_utils.py \
test_tcm.py \
- test_tcm1.py \
- test_tcm2.py \
test_tcm_parallel.py \
test_tcm_combined.py \
test_sccc_hard.py \
diff --git a/gr-trellis/src/examples/README b/gr-trellis/src/examples/README
index d5bad85f5..bd28e3d61 100644
--- a/gr-trellis/src/examples/README
+++ b/gr-trellis/src/examples/README
@@ -6,28 +6,10 @@ fsm_utils.py contains several useful functions.
fsm_files is a directory with some FSM definitions
-If you just want to see what these programs do, run each of the following:
+If you just want to see what these programs do run them;
+in your terminal you will see something like this:
-./test_tcm.py fsm_files/awgn1o2_4.fsm 6.0 1000
-./test_tcm1.py fsm_files/awgn1o2_4.fsm 6.0 1000
-./test_tcm2.py 6.0 1000
-./test_tcm_combined.py fsm_files/awgn1o2_4.fsm 6.0 1000
-./test_tcm_parallel.py fsm_files/awgn1o2_4.fsm 6.0 1000
-
-./test_sccc_hard.py fsm_files/awgn1o2_4.fsm fsm_files/awgn2o3_4_msb.fsm 10.0 100
-./test_sccc_soft.py fsm_files/awgn1o2_4.fsm fsm_files/awgn2o3_4_msb.fsm 8.0 100
-./test_sccc_turbo.py fsm_files/awgn1o2_4.fsm fsm_files/awgn2o3_4_msb.fsm 5.0 100
-
-./test_viterbi_equalization.py 12.0 100
-./test_viterbi_equalization1.py 12.0 100
-./test_turbo_equalization1.py fsm_files/awgn1o2_4.fsm 8.0 100
-./test_turbo_equalization2.py fsm_files/awgn1o2_4.fsm 8.0 100
-
-
-In your terminal you will see something like this:
-
-
-$ ./test_tcm.py fsm_files/awgn1o2_4.fsm 6.0 1000
+$ ./test_tcm.py --esn0 6.0 --repetitions 1000
100 98 9.80e-01 102400 9 8.79e-05
200 198 9.90e-01 204800 20 9.77e-05
300 298 9.93e-01 307200 40 1.30e-04
diff --git a/gr-trellis/src/examples/test_pccc_turbo1.py b/gr-trellis/src/examples/test_pccc_turbo1.py
new file mode 100755
index 000000000..1173d0734
--- /dev/null
+++ b/gr-trellis/src/examples/test_pccc_turbo1.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+
+def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed):
+ tb = gr.top_block ()
+
+
+ # TX
+ src = gr.lfsr_32k_source_s()
+ src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts
+ s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality
+ #src = gr.vector_source_s([0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],False)
+ enc = trellis.pccc_encoder_ss(fo,0,fi,0,interleaver,K)
+ code = gr.vector_sink_s()
+ 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_in = trellis.metrics_f(fi.O()*fo.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO
+ scale = gr.multiply_const_ff(1.0/N0)
+ dec = trellis.pccc_decoder_s(fo,0,-1,fi,0,-1,interleaver,K,IT,trellis.TRELLIS_MIN_SUM)
+
+ fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
+ dst = gr.check_lfsr_32k_s()
+
+ tb.connect (src,src_head,s2fsmi,enc,mod)
+ #tb.connect (src,enc,mod)
+ #tb.connect(enc,code)
+ tb.connect (mod,(add,0))
+ tb.connect (noise,(add,1))
+ tb.connect (add,metrics_in,scale,dec,fsmi2s,dst)
+
+ tb.run()
+
+ #print code.data()
+
+ ntotal = dst.ntotal ()
+ nright = dst.nright ()
+ runlength = dst.runlength ()
+ return (ntotal,ntotal-nright)
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 5:
+ fname_out=args[0]
+ fname_in=args[1]
+ esn0_db=float(args[2]) # Es/No in dB
+ IT=int(args[3])
+ rep=int(args[4]) # number of times the experiment is run to collect enough errors
+ else:
+ sys.stderr.write ('usage: test_pccc_turbo.py fsm_name_1 fsm_fname_2 Es/No_db iterations repetitions\n')
+ sys.exit (1)
+
+ # system parameters
+ Kb=1024*16 # packet size in bits (make it multiple of 16 so it can be packed in a short)
+ fo=trellis.fsm(fname_out) # get the outer FSM specification from a file
+ fi=trellis.fsm(fname_in) # get the innner FSM specification from a file
+ bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol
+ if fo.I() != fi.I():
+ sys.stderr.write ('Incompatible input cardinality between two FSMs.\n')
+ sys.exit (1)
+ K=Kb/bitspersymbol # packet size in trellis steps
+ interleaver=trellis.interleaver(K,666) # construct a random interleaver
+ #modulation = fsm_utils.psk8 # see fsm_utlis.py for available predefined modulations
+ dimensionality = 4
+ constellation = [ 1, 0, 1, 0,\
+ 1, 0,-1, 0,\
+ 1, 0, 0, 1,\
+ 1, 0, 0,-1,\
+ -1, 0, 1, 0,\
+ -1, 0,-1, 0,\
+ -1, 0, 0, 1,\
+ -1, 0, 0,-1,\
+ 0, 1, 1, 0,\
+ 0, 1,-1, 0,\
+ 0, 1, 0, 1,\
+ 0, 1, 0,-1,\
+ 0,-1, 1, 0,\
+ 0,-1,-1, 0,\
+ 0,-1, 0, 1,\
+ 0,-1, 0,-1,] # equivalent to 2 QPSK symbols
+ if len(constellation)/dimensionality != fi.O()*fo.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
+ terr_p=0 # total number of packets in error
+ for i in range(rep):
+ (s,e)=run_test(fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,-long(666+i)) # run experiment with different seed to get different noise realizations
+ tot_s=tot_s+s
+ terr_s=terr_s+e
+ terr_p=terr_p+(terr_s!=0)
+ if ((i+1)%10==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 rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s)
+
+
+if __name__ == '__main__':
+ main (sys.argv[1:])
diff --git a/gr-trellis/src/examples/test_sccc_hard.py b/gr-trellis/src/examples/test_sccc_hard.py
index a7933a18e..1a81bc59b 100755
--- a/gr-trellis/src/examples/test_sccc_hard.py
+++ b/gr-trellis/src/examples/test_sccc_hard.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from gnuradio import gr
-from gnuradio import audio
from gnuradio import trellis
from gnuradio import eng_notation
import math
diff --git a/gr-trellis/src/examples/test_sccc_soft.py b/gr-trellis/src/examples/test_sccc_soft.py
index d96d36e3f..ea296e1e9 100755
--- a/gr-trellis/src/examples/test_sccc_soft.py
+++ b/gr-trellis/src/examples/test_sccc_soft.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from gnuradio import gr
-from gnuradio import audio
from gnuradio import trellis
from gnuradio import eng_notation
import math
diff --git a/gr-trellis/src/examples/test_sccc_turbo.py b/gr-trellis/src/examples/test_sccc_turbo.py
index f3a856de7..703ee410b 100755
--- a/gr-trellis/src/examples/test_sccc_turbo.py
+++ b/gr-trellis/src/examples/test_sccc_turbo.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from gnuradio import gr
-from gnuradio import audio
from gnuradio import trellis
from gnuradio import eng_notation
import math
@@ -92,13 +91,14 @@ def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,
def main(args):
nargs = len (args)
- if nargs == 4:
+ if nargs == 5:
fname_out=args[0]
fname_in=args[1]
esn0_db=float(args[2]) # Es/No in dB
- rep=int(args[3]) # number of times the experiment is run to collect enough errors
+ IT=int(args[3])
+ rep=int(args[4]) # number of times the experiment is run to collect enough errors
else:
- sys.stderr.write ('usage: test_tcm.py fsm_name_out fsm_fname_in Es/No_db repetitions\n')
+ sys.stderr.write ('usage: test_sccc_turbo.py fsm_name_out fsm_fname_in Es/No_db iterations repetitions\n')
sys.exit (1)
# system parameters
@@ -123,7 +123,6 @@ def main(args):
Es = Es + constellation[i]**2
Es = Es / (len(constellation)/dimensionality)
N0=Es/pow(10.0,esn0_db/10.0); # calculate noise variance
- IT = 3 # number of turbo iterations
tot_s=0 # total number of transmitted shorts
terr_s=0 # total number of shorts in error
diff --git a/gr-trellis/src/examples/test_tcm2.py b/gr-trellis/src/examples/test_sccc_turbo1.py
index e527fc5ed..8a630c0d4 100755
--- a/gr-trellis/src/examples/test_tcm2.py
+++ b/gr-trellis/src/examples/test_sccc_turbo1.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from gnuradio import gr
-from gnuradio import audio
from gnuradio import trellis
from gnuradio import eng_notation
import math
@@ -9,20 +8,15 @@ import sys
import random
import fsm_utils
-def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
- tb = gr.top_block ()
+def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed):
+ tb = gr.top_block ()
# 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
+ s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality
+ enc = trellis.sccc_encoder_ss(fo,0,fi,0,interleaver,K)
mod = gr.chunks_to_symbols_sf(constellation,dimensionality)
# CHANNEL
@@ -30,65 +24,54 @@ def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
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.
+ dec = trellis.sccc_decoder_combined_fs(fo,0,-1,fi,0,-1,interleaver,K,IT,trellis.TRELLIS_MIN_SUM,dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN,1.0)
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()
-
+ #tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
tb.connect (src,src_head,s2fsmi,enc,mod)
- #tb.connect (src,b2s,s2fsmi,enc,mod)
tb.connect (mod,(add,0))
tb.connect (noise,(add,1))
- tb.connect (add,metrics)
- tb.connect (metrics,va,fsmi2s,dst)
- #tb.connect (metrics,va,fsmi2s,s2b,dst)
-
+ #tb.connect (add,head)
+ #tb.connect (tail,fsmi2s,dst)
+ tb.connect (add,dec,fsmi2s,dst)
tb.run()
+
+ #print enc_out.ST(), enc_in.ST()
- # 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
+ if nargs == 5:
+ fname_out=args[0]
+ fname_in=args[1]
+ esn0_db=float(args[2]) # Es/No in dB
+ IT=int(args[3])
+ rep=int(args[4]) # 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.stderr.write ('usage: test_tcm.py fsm_name_out fsm_fname_in Es/No_db iterations 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
+ fo=trellis.fsm(fname_out) # get the outer FSM specification from a file
+ fi=trellis.fsm(fname_in) # get the innner FSM specification from a file
+ bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol
+ if fo.O() != fi.I():
+ sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n')
+ sys.exit (1)
K=Kb/bitspersymbol # packet size in trellis steps
- modulation = fsm_utils.psk4 # see fsm_utlis.py for available predefined modulations
+ interleaver=trellis.interleaver(K,666) # construct a random interleaver
+ modulation = fsm_utils.psk8 # see fsm_utlis.py for available predefined modulations
dimensionality = modulation[0]
constellation = modulation[1]
- if len(constellation)/dimensionality != f.O():
+ if len(constellation)/dimensionality != fi.O():
sys.stderr.write ('Incompatible FSM output cardinality and modulation size.\n')
sys.exit (1)
# calculate average symbol energy
@@ -102,11 +85,11 @@ def main(args):
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)) # run experiment with different seed to get different noise realizations
+ (s,e)=run_test(fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,-long(666+i)) # run experiment with different seed to get different noise realizations
tot_s=tot_s+s
terr_s=terr_s+e
terr_p=terr_p+(terr_s!=0)
- if ((i+1)%100==0) : # display progress
+ if ((i+1)%10==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 rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s)
diff --git a/gr-trellis/src/examples/test_sccc_turbo2.py b/gr-trellis/src/examples/test_sccc_turbo2.py
new file mode 100755
index 000000000..a47f6400e
--- /dev/null
+++ b/gr-trellis/src/examples/test_sccc_turbo2.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+
+def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed):
+ tb = gr.top_block ()
+
+ # TX
+ src = gr.lfsr_32k_source_s()
+ src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts
+ s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality
+ enc = trellis.sccc_encoder_ss(fo,0,fi,0,interleaver,K)
+ 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_in = trellis.metrics_f(fi.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO
+ scale = gr.multiply_const_ff(1.0/N0)
+ dec = trellis.sccc_decoder_s(fo,0,-1,fi,0,-1,interleaver,K,IT,trellis.TRELLIS_MIN_SUM)
+ fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
+ dst = gr.check_lfsr_32k_s()
+
+ #tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
+ tb.connect (src,src_head,s2fsmi,enc,mod)
+ tb.connect (mod,(add,0))
+ tb.connect (noise,(add,1))
+ #tb.connect (add,head)
+ #tb.connect (tail,fsmi2s,dst)
+ tb.connect (add,metrics_in,scale,dec,fsmi2s,dst)
+
+ tb.run()
+
+ #print enc_out.ST(), enc_in.ST()
+
+ ntotal = dst.ntotal ()
+ nright = dst.nright ()
+ runlength = dst.runlength ()
+ return (ntotal,ntotal-nright)
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 5:
+ fname_out=args[0]
+ fname_in=args[1]
+ esn0_db=float(args[2]) # Es/No in dB
+ IT=int(args[3])
+ rep=int(args[4]) # number of times the experiment is run to collect enough errors
+ else:
+ sys.stderr.write ('usage: test_tcm.py fsm_name_out fsm_fname_in Es/No_db iterations repetitions\n')
+ sys.exit (1)
+
+ # system parameters
+ Kb=1024*16 # packet size in bits (make it multiple of 16 so it can be packed in a short)
+ fo=trellis.fsm(fname_out) # get the outer FSM specification from a file
+ fi=trellis.fsm(fname_in) # get the innner FSM specification from a file
+ bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol
+ if fo.O() != fi.I():
+ sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n')
+ sys.exit (1)
+ K=Kb/bitspersymbol # packet size in trellis steps
+ interleaver=trellis.interleaver(K,666) # construct a random interleaver
+ modulation = fsm_utils.psk8 # see fsm_utlis.py for available predefined modulations
+ dimensionality = modulation[0]
+ constellation = modulation[1]
+ if len(constellation)/dimensionality != fi.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
+ terr_p=0 # total number of packets in error
+ for i in range(rep):
+ (s,e)=run_test(fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,-long(666+i)) # run experiment with different seed to get different noise realizations
+ tot_s=tot_s+s
+ terr_s=terr_s+e
+ terr_p=terr_p+(terr_s!=0)
+ if ((i+1)%10==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 rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s)
+
+
+if __name__ == '__main__':
+ main (sys.argv[1:])
diff --git a/gr-trellis/src/examples/test_tcm.py b/gr-trellis/src/examples/test_tcm.py
index 62e0c413a..d2e3c6271 100755
--- a/gr-trellis/src/examples/test_tcm.py
+++ b/gr-trellis/src/examples/test_tcm.py
@@ -1,13 +1,14 @@
#!/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
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
tb = gr.top_block ()
@@ -71,18 +72,25 @@ def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
-def main(args):
- nargs = len (args)
- if nargs == 3:
- fname=args[0]
- esn0_db=float(args[1]) # Es/No in dB
- rep=int(args[2]) # number of times the experiment is run to collect enough errors
- else:
- sys.stderr.write ('usage: test_tcm.py fsm_fname Es/No_db repetitions\n')
- sys.exit (1)
+def main():
+ parser = OptionParser(option_class=eng_option)
+ parser.add_option("-f", "--fsm_file", type="string", default="fsm_files/awgn1o2_4.fsm", help="Filename containing the fsm specification, e.g. -f fsm_files/awgn1o2_4.fsm (default=fsm_files/awgn1o2_4.fsm)")
+ parser.add_option("-e", "--esn0", type="eng_float", default=10.0, help="Symbol energy to noise PSD level ratio in dB, e.g., -e 10.0 (default=10.0)")
+ parser.add_option("-r", "--repetitions", type="int", default=100, help="Number of packets to be generated for the simulation, e.g., -r 100 (default=100)")
+
+ (options, args) = parser.parse_args ()
+ if len(args) != 0:
+ parser.print_help()
+ raise SystemExit, 1
+
+ fname=options.fsm_file
+ esn0_db=float(options.esn0)
+ rep=int(options.repetitions)
# system parameters
f=trellis.fsm(fname) # get the FSM specification from a file
+ # alternatively you can specify the fsm from its generator matrix
+ #f=trellis.fsm(1,2,[5,7])
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
@@ -115,4 +123,4 @@ def main(args):
if __name__ == '__main__':
- main (sys.argv[1:])
+ main()
diff --git a/gr-trellis/src/examples/test_tcm1.py b/gr-trellis/src/examples/test_tcm_bit.py
index 746bd9336..008e1e6f0 100755
--- a/gr-trellis/src/examples/test_tcm1.py
+++ b/gr-trellis/src/examples/test_tcm_bit.py
@@ -1,13 +1,15 @@
#!/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
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
tb = gr.top_block ()
@@ -74,15 +76,21 @@ def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
-def main(args):
- nargs = len (args)
- if nargs == 3:
- fname=args[0]
- esn0_db=float(args[1]) # Es/No in dB
- rep=int(args[2]) # number of times the experiment is run to collect enough errors
- else:
- sys.stderr.write ('usage: test_tcm.py fsm_fname Es/No_db repetitions\n')
- sys.exit (1)
+def main():
+ parser = OptionParser(option_class=eng_option)
+ parser.add_option("-f", "--fsm_file", type="string", default="fsm_files/awgn1o2_4.fsm", help="Filename containing the fsm specification, e.g. -f fsm_files/awgn1o2_4.fsm (default=fsm_files/awgn1o2_4.fsm)")
+ parser.add_option("-e", "--esn0", type="eng_float", default=10.0, help="Symbol energy to noise PSD level ratio in dB, e.g., -e 10.0 (default=10.0)")
+ parser.add_option("-r", "--repetitions", type="int", default=100, help="Number of packets to be generated for the simulation, e.g., -r 100 (default=100)")
+
+ (options, args) = parser.parse_args ()
+ if len(args) != 0:
+ parser.print_help()
+ raise SystemExit, 1
+
+ fname=options.fsm_file
+ esn0_db=float(options.esn0)
+ rep=int(options.repetitions)
+
# system parameters
f=trellis.fsm(fname) # get the FSM specification from a file
@@ -100,7 +108,7 @@ def main(args):
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); # noise variance
+ 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
@@ -118,4 +126,4 @@ def main(args):
if __name__ == '__main__':
- main (sys.argv[1:])
+ main()
diff --git a/gr-trellis/src/examples/test_tcm_combined.py b/gr-trellis/src/examples/test_tcm_combined.py
index d2d42b40b..f9b698ae9 100755
--- a/gr-trellis/src/examples/test_tcm_combined.py
+++ b/gr-trellis/src/examples/test_tcm_combined.py
@@ -1,12 +1,14 @@
#!/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 fsm_utils
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
tb = gr.top_block ()
@@ -52,15 +54,20 @@ def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
-def main(args):
- nargs = len (args)
- if nargs == 3:
- fname=args[0]
- esn0_db=float(args[1]) # Es/No in dB
- rep=int(args[2]) # number of times the experiment is run to collect enough errors
- else:
- sys.stderr.write ('usage: test_tcm_combined.py fsm_fname Es/No_db repetitions\n')
- sys.exit (1)
+def main():
+ parser = OptionParser(option_class=eng_option)
+ parser.add_option("-f", "--fsm_file", type="string", default="fsm_files/awgn1o2_4.fsm", help="Filename containing the fsm specification, e.g. -f fsm_files/awgn1o2_4.fsm (default=fsm_files/awgn1o2_4.fsm)")
+ parser.add_option("-e", "--esn0", type="eng_float", default=10.0, help="Symbol energy to noise PSD level ratio in dB, e.g., -e 10.0 (default=10.0)")
+ parser.add_option("-r", "--repetitions", type="int", default=100, help="Number of packets to be generated for the simulation, e.g., -r 100 (default=100)")
+
+ (options, args) = parser.parse_args ()
+ if len(args) != 0:
+ parser.print_help()
+ raise SystemExit, 1
+
+ fname=options.fsm_file
+ esn0_db=float(options.esn0)
+ rep=int(options.repetitions)
# system parameters
f=trellis.fsm(fname) # get the FSM specification from a file (will hopefully be automated in the future...)
@@ -96,5 +103,5 @@ def main(args):
if __name__ == '__main__':
- main (sys.argv[1:])
+ main()
diff --git a/gr-trellis/src/examples/test_tcm_parallel.py b/gr-trellis/src/examples/test_tcm_parallel.py
index 8e2f5a230..94761fd01 100755
--- a/gr-trellis/src/examples/test_tcm_parallel.py
+++ b/gr-trellis/src/examples/test_tcm_parallel.py
@@ -1,12 +1,14 @@
#!/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 fsm_utils
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P):
tb = gr.top_block ()
@@ -58,15 +60,20 @@ def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P):
-def main(args):
- nargs = len (args)
- if nargs == 3:
- fname=args[0]
- esn0_db=float(args[1]) # Es/No in dB
- rep=int(args[2]) # number of times the experiment is run to collect enough errors
- else:
- sys.stderr.write ('usage: test_tcm.py fsm_fname Es/No_db repetitions\n')
- sys.exit (1)
+def main():
+ parser = OptionParser(option_class=eng_option)
+ parser.add_option("-f", "--fsm_file", type="string", default="fsm_files/awgn1o2_4.fsm", help="Filename containing the fsm specification, e.g. -f fsm_files/awgn1o2_4.fsm (default=fsm_files/awgn1o2_4.fsm)")
+ parser.add_option("-e", "--esn0", type="eng_float", default=10.0, help="Symbol energy to noise PSD level ratio in dB, e.g., -e 10.0 (default=10.0)")
+ parser.add_option("-r", "--repetitions", type="int", default=100, help="Number of packets to be generated for the simulation, e.g., -r 100 (default=100)")
+
+ (options, args) = parser.parse_args ()
+ if len(args) != 0:
+ parser.print_help()
+ raise SystemExit, 1
+
+ fname=options.fsm_file
+ esn0_db=float(options.esn0)
+ rep=int(options.repetitions)
# system parameters
f=trellis.fsm(fname) # get the FSM specification from a file
@@ -102,5 +109,5 @@ def main(args):
if __name__ == '__main__':
- main (sys.argv[1:])
+ main()
diff --git a/gr-trellis/src/examples/test_turbo_equalization.py b/gr-trellis/src/examples/test_turbo_equalization.py
index 612f6951c..0bf691222 100755
--- a/gr-trellis/src/examples/test_turbo_equalization.py
+++ b/gr-trellis/src/examples/test_turbo_equalization.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from gnuradio import gr
-from gnuradio import audio
from gnuradio import trellis
from gnuradio import eng_notation
import math
diff --git a/gr-trellis/src/examples/test_turbo_equalization1.py b/gr-trellis/src/examples/test_turbo_equalization1.py
index 8d2feec8a..feae4ce89 100755
--- a/gr-trellis/src/examples/test_turbo_equalization1.py
+++ b/gr-trellis/src/examples/test_turbo_equalization1.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from gnuradio import gr
-from gnuradio import audio
from gnuradio import trellis
from gnuradio import eng_notation
import math
diff --git a/gr-trellis/src/examples/test_turbo_equalization2.py b/gr-trellis/src/examples/test_turbo_equalization2.py
index f1731016e..ff14299c6 100755
--- a/gr-trellis/src/examples/test_turbo_equalization2.py
+++ b/gr-trellis/src/examples/test_turbo_equalization2.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from gnuradio import gr
-from gnuradio import audio
from gnuradio import trellis
from gnuradio import eng_notation
import math
diff --git a/gr-trellis/src/examples/test_viterbi_equalization.py b/gr-trellis/src/examples/test_viterbi_equalization.py
index 86fc00674..eda692024 100755
--- a/gr-trellis/src/examples/test_viterbi_equalization.py
+++ b/gr-trellis/src/examples/test_viterbi_equalization.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from gnuradio import gr
-from gnuradio import audio
from gnuradio import trellis
from gnuradio import eng_notation
import math
diff --git a/gr-trellis/src/examples/test_viterbi_equalization1.py b/gr-trellis/src/examples/test_viterbi_equalization1.py
index d26f73bc0..3a65b9363 100755
--- a/gr-trellis/src/examples/test_viterbi_equalization1.py
+++ b/gr-trellis/src/examples/test_viterbi_equalization1.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from gnuradio import gr
-from gnuradio import audio
from gnuradio import trellis
from gnuradio import eng_notation
import math