summaryrefslogtreecommitdiff
path: root/gr-trellis/src/examples/python
diff options
context:
space:
mode:
Diffstat (limited to 'gr-trellis/src/examples/python')
-rw-r--r--gr-trellis/src/examples/python/CMakeLists.txt64
-rw-r--r--gr-trellis/src/examples/python/README35
-rw-r--r--gr-trellis/src/examples/python/fsm_files/awgn1o2_128.fsm265
-rw-r--r--gr-trellis/src/examples/python/fsm_files/awgn1o2_16.fsm39
-rw-r--r--gr-trellis/src/examples/python/fsm_files/awgn1o2_4.fsm14
-rw-r--r--gr-trellis/src/examples/python/fsm_files/awgn1o2_8.fsm24
-rw-r--r--gr-trellis/src/examples/python/fsm_files/awgn2o3_16.fsm40
-rw-r--r--gr-trellis/src/examples/python/fsm_files/awgn2o3_4.fsm15
-rw-r--r--gr-trellis/src/examples/python/fsm_files/awgn2o3_4_msb.fsm46
-rw-r--r--gr-trellis/src/examples/python/fsm_files/awgn2o3_4_msbG.fsm60
-rw-r--r--gr-trellis/src/examples/python/fsm_files/awgn2o3_8.fsm25
-rw-r--r--gr-trellis/src/examples/python/fsm_files/awgn2o4_4.fsm36
-rw-r--r--gr-trellis/src/examples/python/fsm_files/disconnected.fsm11
-rw-r--r--gr-trellis/src/examples/python/fsm_files/irregular.fsm11
-rw-r--r--gr-trellis/src/examples/python/fsm_files/joint_16_16.fsm523
-rw-r--r--gr-trellis/src/examples/python/fsm_files/joint_4_16.fsm141
-rw-r--r--gr-trellis/src/examples/python/fsm_files/rep3.fsm8
-rw-r--r--gr-trellis/src/examples/python/fsm_files/rep5.fsm7
-rw-r--r--gr-trellis/src/examples/python/fsm_files/simple.fsm13
-rwxr-xr-xgr-trellis/src/examples/python/fsm_utils.py239
-rwxr-xr-xgr-trellis/src/examples/python/test_cpm.py154
-rwxr-xr-xgr-trellis/src/examples/python/test_pccc_turbo1.py119
-rwxr-xr-xgr-trellis/src/examples/python/test_sccc_hard.py100
-rwxr-xr-xgr-trellis/src/examples/python/test_sccc_soft.py107
-rwxr-xr-xgr-trellis/src/examples/python/test_sccc_turbo.py142
-rwxr-xr-xgr-trellis/src/examples/python/test_sccc_turbo1.py99
-rwxr-xr-xgr-trellis/src/examples/python/test_sccc_turbo2.py101
-rwxr-xr-xgr-trellis/src/examples/python/test_tcm.py126
-rwxr-xr-xgr-trellis/src/examples/python/test_tcm_bit.py129
-rwxr-xr-xgr-trellis/src/examples/python/test_tcm_combined.py107
-rwxr-xr-xgr-trellis/src/examples/python/test_tcm_parallel.py113
-rwxr-xr-xgr-trellis/src/examples/python/test_turbo_equalization.py142
-rwxr-xr-xgr-trellis/src/examples/python/test_turbo_equalization1.py146
-rwxr-xr-xgr-trellis/src/examples/python/test_turbo_equalization2.py146
-rwxr-xr-xgr-trellis/src/examples/python/test_viterbi_equalization.py93
-rwxr-xr-xgr-trellis/src/examples/python/test_viterbi_equalization1.py102
36 files changed, 3542 insertions, 0 deletions
diff --git a/gr-trellis/src/examples/python/CMakeLists.txt b/gr-trellis/src/examples/python/CMakeLists.txt
new file mode 100644
index 000000000..e2c7e70ff
--- /dev/null
+++ b/gr-trellis/src/examples/python/CMakeLists.txt
@@ -0,0 +1,64 @@
+# Copyright 2011 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+
+include(GrPython)
+
+GR_PYTHON_INSTALL(
+ PROGRAMS
+ fsm_utils.py
+ test_tcm.py
+ test_tcm_parallel.py
+ test_tcm_combined.py
+ test_sccc_hard.py
+ test_sccc_soft.py
+ test_sccc_turbo.py
+ test_viterbi_equalization1.py
+ test_viterbi_equalization.py
+ test_turbo_equalization.py
+ test_turbo_equalization1.py
+ test_turbo_equalization2.py
+ DESTINATION ${GR_PKG_TRELLIS_EXAMPLES_DIR}
+ COMPONENT "trellis_examples"
+)
+
+install(
+ FILES README
+ DESTINATION ${GR_PKG_DATA_DIR}/examples/trellis
+ COMPONENT "trellis_examples"
+)
+
+install(
+ FILES
+ fsm_files/awgn1o2_128.fsm
+ fsm_files/awgn1o2_16.fsm
+ fsm_files/awgn1o2_4.fsm
+ fsm_files/awgn1o2_8.fsm
+ fsm_files/awgn2o3_16.fsm
+ fsm_files/awgn2o3_4.fsm
+ fsm_files/awgn2o3_4_msb.fsm
+ fsm_files/awgn2o3_4_msbG.fsm
+ fsm_files/awgn2o3_8.fsm
+ fsm_files/awgn2o4_4.fsm
+ fsm_files/disconnected.fsm
+ fsm_files/rep3.fsm
+ fsm_files/rep5.fsm
+ fsm_files/simple.fsm
+ DESTINATION ${GR_PKG_TRELLIS_EXAMPLES_DIR}/fsm_files
+ COMPONENT "trellis_examples"
+)
diff --git a/gr-trellis/src/examples/python/README b/gr-trellis/src/examples/python/README
new file mode 100644
index 000000000..bd28e3d61
--- /dev/null
+++ b/gr-trellis/src/examples/python/README
@@ -0,0 +1,35 @@
+Here we have several test programs for use with the gr-trellis implementation.
+Documentation can be found in
+http://gnuradio.utah.edu/svn/gnuradio/trunk/gr-trellis/doc/gr-trellis.html
+
+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 them;
+in your terminal you will see something like this:
+
+$ ./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
+400 398 9.95e-01 409600 1074 2.62e-03
+500 498 9.96e-01 512000 1081 2.11e-03
+600 598 9.97e-01 614400 1090 1.77e-03
+700 698 9.97e-01 716800 1097 1.53e-03
+800 798 9.98e-01 819200 1107 1.35e-03
+900 898 9.98e-01 921600 1120 1.22e-03
+1000 998 9.98e-01 1024000 1129 1.10e-03
+1000 998 9.98e-01 1024000 1129 1.10e-03
+
+which gives you information about the:
+number of transmitted packets
+number of packets in error
+estimated packet error rate
+number of transmitted shorts (or symbols, or bits, depending on the specific program)
+number of shorts (or symbols, or bits) in error
+estimated short (or symbol, or bit) error rate
+
+for instance, the final number 1.10e-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
diff --git a/gr-trellis/src/examples/python/fsm_files/awgn1o2_128.fsm b/gr-trellis/src/examples/python/fsm_files/awgn1o2_128.fsm
new file mode 100644
index 000000000..bb79c59da
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/awgn1o2_128.fsm
@@ -0,0 +1,265 @@
+2 128 4
+
+0 64
+0 64
+1 65
+1 65
+2 66
+2 66
+3 67
+3 67
+4 68
+4 68
+5 69
+5 69
+6 70
+6 70
+7 71
+7 71
+8 72
+8 72
+9 73
+9 73
+10 74
+10 74
+11 75
+11 75
+12 76
+12 76
+13 77
+13 77
+14 78
+14 78
+15 79
+15 79
+16 80
+16 80
+17 81
+17 81
+18 82
+18 82
+19 83
+19 83
+20 84
+20 84
+21 85
+21 85
+22 86
+22 86
+23 87
+23 87
+24 88
+24 88
+25 89
+25 89
+26 90
+26 90
+27 91
+27 91
+28 92
+28 92
+29 93
+29 93
+30 94
+30 94
+31 95
+31 95
+32 96
+32 96
+33 97
+33 97
+34 98
+34 98
+35 99
+35 99
+36 100
+36 100
+37 101
+37 101
+38 102
+38 102
+39 103
+39 103
+40 104
+40 104
+41 105
+41 105
+42 106
+42 106
+43 107
+43 107
+44 108
+44 108
+45 109
+45 109
+46 110
+46 110
+47 111
+47 111
+48 112
+48 112
+49 113
+49 113
+50 114
+50 114
+51 115
+51 115
+52 116
+52 116
+53 117
+53 117
+54 118
+54 118
+55 119
+55 119
+56 120
+56 120
+57 121
+57 121
+58 122
+58 122
+59 123
+59 123
+60 124
+60 124
+61 125
+61 125
+62 126
+62 126
+63 127
+63 127
+
+0 3
+3 0
+1 2
+2 1
+3 0
+0 3
+2 1
+1 2
+1 2
+2 1
+0 3
+3 0
+2 1
+1 2
+3 0
+0 3
+1 2
+2 1
+0 3
+3 0
+2 1
+1 2
+3 0
+0 3
+0 3
+3 0
+1 2
+2 1
+3 0
+0 3
+2 1
+1 2
+2 1
+1 2
+3 0
+0 3
+1 2
+2 1
+0 3
+3 0
+3 0
+0 3
+2 1
+1 2
+0 3
+3 0
+1 2
+2 1
+3 0
+0 3
+2 1
+1 2
+0 3
+3 0
+1 2
+2 1
+2 1
+1 2
+3 0
+0 3
+1 2
+2 1
+0 3
+3 0
+2 1
+1 2
+3 0
+0 3
+1 2
+2 1
+0 3
+3 0
+3 0
+0 3
+2 1
+1 2
+0 3
+3 0
+1 2
+2 1
+3 0
+0 3
+2 1
+1 2
+0 3
+3 0
+1 2
+2 1
+2 1
+1 2
+3 0
+0 3
+1 2
+2 1
+0 3
+3 0
+0 3
+3 0
+1 2
+2 1
+3 0
+0 3
+2 1
+1 2
+1 2
+2 1
+0 3
+3 0
+2 1
+1 2
+3 0
+0 3
+1 2
+2 1
+0 3
+3 0
+2 1
+1 2
+3 0
+0 3
+0 3
+3 0
+1 2
+2 1
+3 0
+0 3
+2 1
+1 2
+
+
+
+GM1o2_128=[1+D+D^2+D^5+D^7 1+D^3+D^4+D^5+D^6+D^7]
+ =[11100101 10011111]
+ =[229 159]
diff --git a/gr-trellis/src/examples/python/fsm_files/awgn1o2_16.fsm b/gr-trellis/src/examples/python/fsm_files/awgn1o2_16.fsm
new file mode 100644
index 000000000..cdab41359
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/awgn1o2_16.fsm
@@ -0,0 +1,39 @@
+2 16 4
+
+0 8
+0 8
+1 9
+1 9
+2 10
+2 10
+3 11
+3 11
+4 12
+4 12
+5 13
+5 13
+6 14
+6 14
+7 15
+7 15
+
+0 3
+3 0
+1 2
+2 1
+1 2
+2 1
+0 3
+3 0
+2 1
+1 2
+3 0
+0 3
+3 0
+0 3
+2 1
+1 2
+
+
+
+GM1o2_16=[1+D+D^4 1+D^2+D^3+D^4 ] = [25,23] (decimal)
diff --git a/gr-trellis/src/examples/python/fsm_files/awgn1o2_4.fsm b/gr-trellis/src/examples/python/fsm_files/awgn1o2_4.fsm
new file mode 100644
index 000000000..fb316b5ef
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/awgn1o2_4.fsm
@@ -0,0 +1,14 @@
+2 4 4
+
+0 2
+0 2
+1 3
+1 3
+
+0 3
+3 0
+1 2
+2 1
+
+AWGN CC from Proakis-Salehi pg 779
+GM1o2_4=[1+D^2, 1+D+D^2] = [5, 7] (in decimal);
diff --git a/gr-trellis/src/examples/python/fsm_files/awgn1o2_8.fsm b/gr-trellis/src/examples/python/fsm_files/awgn1o2_8.fsm
new file mode 100644
index 000000000..604bac6c2
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/awgn1o2_8.fsm
@@ -0,0 +1,24 @@
+2 8 4
+
+0 4
+0 4
+1 5
+1 5
+2 6
+2 6
+3 7
+3 7
+
+
+0 3
+3 0
+1 2
+2 1
+3 0
+0 3
+2 1
+1 2
+
+
+1/2 8-state code (Proakis pg. 493)
+GM1o2_8=[ 1+D+D^3 1+D+D^2+D^3] =[13 , 15] (decimal)
diff --git a/gr-trellis/src/examples/python/fsm_files/awgn2o3_16.fsm b/gr-trellis/src/examples/python/fsm_files/awgn2o3_16.fsm
new file mode 100644
index 000000000..9630cd9af
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/awgn2o3_16.fsm
@@ -0,0 +1,40 @@
+4 16 8
+
+0 8 4 12
+0 8 4 12
+0 8 4 12
+0 8 4 12
+1 9 5 13
+1 9 5 13
+1 9 5 13
+1 9 5 13
+2 10 6 14
+2 10 6 14
+2 10 6 14
+2 10 6 14
+3 11 7 15
+3 11 7 15
+3 11 7 15
+3 11 7 15
+
+0 1 7 6
+6 7 1 0
+3 2 4 5
+5 4 2 3
+2 3 5 4
+4 5 3 2
+1 0 6 7
+7 6 0 1
+4 5 3 2
+2 3 5 4
+7 6 0 1
+1 0 6 7
+6 7 1 0
+0 1 7 6
+5 4 2 3
+3 2 4 5
+
+
+2/3 code generated from the awgn 1/2 code with 16 states and puncturing the 4th bit.
+d_free=
+
diff --git a/gr-trellis/src/examples/python/fsm_files/awgn2o3_4.fsm b/gr-trellis/src/examples/python/fsm_files/awgn2o3_4.fsm
new file mode 100644
index 000000000..3ac57be18
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/awgn2o3_4.fsm
@@ -0,0 +1,15 @@
+4 4 8
+
+0 1 2 3
+0 1 2 3
+0 1 2 3
+0 1 2 3
+
+0 7 4 3
+3 4 7 0
+5 2 1 6
+6 1 2 5
+
+I don't remeber how I generated this one...
+it is a bit better than awgn2o3_4_msb and worse
+than awgn2o3_4_msbG.
diff --git a/gr-trellis/src/examples/python/fsm_files/awgn2o3_4_msb.fsm b/gr-trellis/src/examples/python/fsm_files/awgn2o3_4_msb.fsm
new file mode 100644
index 000000000..551b71101
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/awgn2o3_4_msb.fsm
@@ -0,0 +1,46 @@
+4 4 8
+
+0 1 2 3
+0 1 2 3
+0 1 2 3
+0 1 2 3
+
+0 5 3 6
+4 1 7 2
+7 2 4 1
+3 6 0 5
+
+
+This is generated by the 1/2 AWGN code (5 7) operated twice, ie,
+(xk+1 xki) [xk-1 xk-2] -> [xk+1 xki].
+We also puncture the first (MSB) bit.
+This code is worse than awgn2o3_4_msbG and slightly worse than
+awgn2o3_4, BUT seems to be a good innner code for sctcm (with 8PSK natural).
+
+intermediate states:
+
+00 21 02 23
+00 21 02 23
+10 31 12 33
+10 31 12 33
+
+output before puncturing:
+
+00 31 03 32
+30 01 33 02
+13 22 10 21
+23 12 20 11
+
+output after punturing the MSB:
+
+00 11 03 12
+10 01 13 02
+13 02 10 01
+03 12 00 11
+
+and in decimal:
+
+0 5 3 6
+4 1 7 2
+7 2 4 1
+3 6 0 5
diff --git a/gr-trellis/src/examples/python/fsm_files/awgn2o3_4_msbG.fsm b/gr-trellis/src/examples/python/fsm_files/awgn2o3_4_msbG.fsm
new file mode 100644
index 000000000..8956c53da
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/awgn2o3_4_msbG.fsm
@@ -0,0 +1,60 @@
+4 4 8
+
+0 1 2 3
+0 1 2 3
+0 1 2 3
+0 1 2 3
+
+0 4 2 6
+5 1 3 7
+3 7 5 1
+
+
+This is generated by the 1/2 AWGN code (5 7) operated twice, ie,
+(xk+1 xki) [xk-1 xk-2] -> [xk+1 xki].
+We also puncture the first (MSB) bit and Gray map the symbols.
+
+intermediate states:
+
+00 21 02 23
+00 21 02 23
+10 31 12 33
+10 31 12 33
+
+output before puncturing:
+
+00 31 03 32
+30 01 33 02
+13 22 10 21
+23 12 20 11
+
+output after punturing the MSB:
+
+00 11 03 12
+10 01 13 02
+13 02 10 01
+03 12 00 11
+
+and in decimal:
+
+0 5 3 6
+4 1 7 2
+7 2 4 1
+3 6 0 5
+
+After Gray mapping:
+label -> phase
+0 -> 0
+1 -> 0
+2 -> 7
+3 -> 2
+4 -> 5
+5 -> 4
+6 -> 6
+7 -> 3
+
+0 4 2 6
+5 1 3 7
+3 7 5 1
+2 6 0 4
+
diff --git a/gr-trellis/src/examples/python/fsm_files/awgn2o3_8.fsm b/gr-trellis/src/examples/python/fsm_files/awgn2o3_8.fsm
new file mode 100644
index 000000000..34deeb68c
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/awgn2o3_8.fsm
@@ -0,0 +1,25 @@
+4 8 8
+
+0 4 2 6
+0 4 2 6
+0 4 2 6
+0 4 2 6
+1 5 3 7
+1 5 3 7
+1 5 3 7
+1 5 3 7
+
+
+0 1 7 6
+6 7 1 0
+3 2 4 5
+5 4 2 3
+6 7 1 0
+0 1 7 6
+5 4 2 3
+3 2 4 5
+
+
+
+This is generated by the 1/2 8-state AWGN code (15 17) by puncturing the fourth bit.
+--> d_free=???
diff --git a/gr-trellis/src/examples/python/fsm_files/awgn2o4_4.fsm b/gr-trellis/src/examples/python/fsm_files/awgn2o4_4.fsm
new file mode 100644
index 000000000..a895be896
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/awgn2o4_4.fsm
@@ -0,0 +1,36 @@
+4 4 16
+
+0 1 2 3
+0 1 2 3
+0 1 2 3
+0 1 2 3
+
+ 0 13 3 14
+12 1 15 2
+ 7 10 4 9
+11 6 8 5
+
+
+This is generated by the 1/2 AWGN code (5 7) operated twice, ie,
+(xk+1 xki) [xk-1 xk-2] -> [xk+1 xki].
+
+intermediate states:
+
+00 21 02 23
+00 21 02 23
+10 31 12 33
+10 31 12 33
+
+output:
+
+00 31 03 32
+30 01 33 02
+13 22 10 21
+23 12 20 11
+
+and in decimal:
+
+ 0 13 3 14
+12 1 15 2
+ 7 10 4 9
+11 6 8 5
diff --git a/gr-trellis/src/examples/python/fsm_files/disconnected.fsm b/gr-trellis/src/examples/python/fsm_files/disconnected.fsm
new file mode 100644
index 000000000..847963e7b
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/disconnected.fsm
@@ -0,0 +1,11 @@
+1 4 1
+
+1
+0
+3
+2
+
+0
+0
+0
+0
diff --git a/gr-trellis/src/examples/python/fsm_files/irregular.fsm b/gr-trellis/src/examples/python/fsm_files/irregular.fsm
new file mode 100644
index 000000000..80b82b889
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/irregular.fsm
@@ -0,0 +1,11 @@
+2 2 2
+
+0 0
+0 1
+
+0 1
+0 1
+
+
+useless irregular FSM for testing. state 0 has 3 incoming edges and state
+1 has 1 incoming edge.
diff --git a/gr-trellis/src/examples/python/fsm_files/joint_16_16.fsm b/gr-trellis/src/examples/python/fsm_files/joint_16_16.fsm
new file mode 100644
index 000000000..3dae314b6
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/joint_16_16.fsm
@@ -0,0 +1,523 @@
+4 256 16
+
+0 8 128 136
+0 8 128 136
+1 9 129 137
+1 9 129 137
+2 10 130 138
+2 10 130 138
+3 11 131 139
+3 11 131 139
+4 12 132 140
+4 12 132 140
+5 13 133 141
+5 13 133 141
+6 14 134 142
+6 14 134 142
+7 15 135 143
+7 15 135 143
+0 8 128 136
+0 8 128 136
+1 9 129 137
+1 9 129 137
+2 10 130 138
+2 10 130 138
+3 11 131 139
+3 11 131 139
+4 12 132 140
+4 12 132 140
+5 13 133 141
+5 13 133 141
+6 14 134 142
+6 14 134 142
+7 15 135 143
+7 15 135 143
+16 24 144 152
+16 24 144 152
+17 25 145 153
+17 25 145 153
+18 26 146 154
+18 26 146 154
+19 27 147 155
+19 27 147 155
+20 28 148 156
+20 28 148 156
+21 29 149 157
+21 29 149 157
+22 30 150 158
+22 30 150 158
+23 31 151 159
+23 31 151 159
+16 24 144 152
+16 24 144 152
+17 25 145 153
+17 25 145 153
+18 26 146 154
+18 26 146 154
+19 27 147 155
+19 27 147 155
+20 28 148 156
+20 28 148 156
+21 29 149 157
+21 29 149 157
+22 30 150 158
+22 30 150 158
+23 31 151 159
+23 31 151 159
+32 40 160 168
+32 40 160 168
+33 41 161 169
+33 41 161 169
+34 42 162 170
+34 42 162 170
+35 43 163 171
+35 43 163 171
+36 44 164 172
+36 44 164 172
+37 45 165 173
+37 45 165 173
+38 46 166 174
+38 46 166 174
+39 47 167 175
+39 47 167 175
+32 40 160 168
+32 40 160 168
+33 41 161 169
+33 41 161 169
+34 42 162 170
+34 42 162 170
+35 43 163 171
+35 43 163 171
+36 44 164 172
+36 44 164 172
+37 45 165 173
+37 45 165 173
+38 46 166 174
+38 46 166 174
+39 47 167 175
+39 47 167 175
+48 56 176 184
+48 56 176 184
+49 57 177 185
+49 57 177 185
+50 58 178 186
+50 58 178 186
+51 59 179 187
+51 59 179 187
+52 60 180 188
+52 60 180 188
+53 61 181 189
+53 61 181 189
+54 62 182 190
+54 62 182 190
+55 63 183 191
+55 63 183 191
+48 56 176 184
+48 56 176 184
+49 57 177 185
+49 57 177 185
+50 58 178 186
+50 58 178 186
+51 59 179 187
+51 59 179 187
+52 60 180 188
+52 60 180 188
+53 61 181 189
+53 61 181 189
+54 62 182 190
+54 62 182 190
+55 63 183 191
+55 63 183 191
+64 72 192 200
+64 72 192 200
+65 73 193 201
+65 73 193 201
+66 74 194 202
+66 74 194 202
+67 75 195 203
+67 75 195 203
+68 76 196 204
+68 76 196 204
+69 77 197 205
+69 77 197 205
+70 78 198 206
+70 78 198 206
+71 79 199 207
+71 79 199 207
+64 72 192 200
+64 72 192 200
+65 73 193 201
+65 73 193 201
+66 74 194 202
+66 74 194 202
+67 75 195 203
+67 75 195 203
+68 76 196 204
+68 76 196 204
+69 77 197 205
+69 77 197 205
+70 78 198 206
+70 78 198 206
+71 79 199 207
+71 79 199 207
+80 88 208 216
+80 88 208 216
+81 89 209 217
+81 89 209 217
+82 90 210 218
+82 90 210 218
+83 91 211 219
+83 91 211 219
+84 92 212 220
+84 92 212 220
+85 93 213 221
+85 93 213 221
+86 94 214 222
+86 94 214 222
+87 95 215 223
+87 95 215 223
+80 88 208 216
+80 88 208 216
+81 89 209 217
+81 89 209 217
+82 90 210 218
+82 90 210 218
+83 91 211 219
+83 91 211 219
+84 92 212 220
+84 92 212 220
+85 93 213 221
+85 93 213 221
+86 94 214 222
+86 94 214 222
+87 95 215 223
+87 95 215 223
+96 104 224 232
+96 104 224 232
+97 105 225 233
+97 105 225 233
+98 106 226 234
+98 106 226 234
+99 107 227 235
+99 107 227 235
+100 108 228 236
+100 108 228 236
+101 109 229 237
+101 109 229 237
+102 110 230 238
+102 110 230 238
+103 111 231 239
+103 111 231 239
+96 104 224 232
+96 104 224 232
+97 105 225 233
+97 105 225 233
+98 106 226 234
+98 106 226 234
+99 107 227 235
+99 107 227 235
+100 108 228 236
+100 108 228 236
+101 109 229 237
+101 109 229 237
+102 110 230 238
+102 110 230 238
+103 111 231 239
+103 111 231 239
+112 120 240 248
+112 120 240 248
+113 121 241 249
+113 121 241 249
+114 122 242 250
+114 122 242 250
+115 123 243 251
+115 123 243 251
+116 124 244 252
+116 124 244 252
+117 125 245 253
+117 125 245 253
+118 126 246 254
+118 126 246 254
+119 127 247 255
+119 127 247 255
+112 120 240 248
+112 120 240 248
+113 121 241 249
+113 121 241 249
+114 122 242 250
+114 122 242 250
+115 123 243 251
+115 123 243 251
+116 124 244 252
+116 124 244 252
+117 125 245 253
+117 125 245 253
+118 126 246 254
+118 126 246 254
+119 127 247 255
+119 127 247 255
+
+0 3 12 15
+3 0 15 12
+1 2 13 14
+2 1 14 13
+1 2 13 14
+2 1 14 13
+0 3 12 15
+3 0 15 12
+2 1 14 13
+1 2 13 14
+3 0 15 12
+0 3 12 15
+3 0 15 12
+0 3 12 15
+2 1 14 13
+1 2 13 14
+12 15 0 3
+15 12 3 0
+13 14 1 2
+14 13 2 1
+13 14 1 2
+14 13 2 1
+12 15 0 3
+15 12 3 0
+14 13 2 1
+13 14 1 2
+15 12 3 0
+12 15 0 3
+15 12 3 0
+12 15 0 3
+14 13 2 1
+13 14 1 2
+4 7 8 11
+7 4 11 8
+5 6 9 10
+6 5 10 9
+5 6 9 10
+6 5 10 9
+4 7 8 11
+7 4 11 8
+6 5 10 9
+5 6 9 10
+7 4 11 8
+4 7 8 11
+7 4 11 8
+4 7 8 11
+6 5 10 9
+5 6 9 10
+8 11 4 7
+11 8 7 4
+9 10 5 6
+10 9 6 5
+9 10 5 6
+10 9 6 5
+8 11 4 7
+11 8 7 4
+10 9 6 5
+9 10 5 6
+11 8 7 4
+8 11 4 7
+11 8 7 4
+8 11 4 7
+10 9 6 5
+9 10 5 6
+4 7 8 11
+7 4 11 8
+5 6 9 10
+6 5 10 9
+5 6 9 10
+6 5 10 9
+4 7 8 11
+7 4 11 8
+6 5 10 9
+5 6 9 10
+7 4 11 8
+4 7 8 11
+7 4 11 8
+4 7 8 11
+6 5 10 9
+5 6 9 10
+8 11 4 7
+11 8 7 4
+9 10 5 6
+10 9 6 5
+9 10 5 6
+10 9 6 5
+8 11 4 7
+11 8 7 4
+10 9 6 5
+9 10 5 6
+11 8 7 4
+8 11 4 7
+11 8 7 4
+8 11 4 7
+10 9 6 5
+9 10 5 6
+0 3 12 15
+3 0 15 12
+1 2 13 14
+2 1 14 13
+1 2 13 14
+2 1 14 13
+0 3 12 15
+3 0 15 12
+2 1 14 13
+1 2 13 14
+3 0 15 12
+0 3 12 15
+3 0 15 12
+0 3 12 15
+2 1 14 13
+1 2 13 14
+12 15 0 3
+15 12 3 0
+13 14 1 2
+14 13 2 1
+13 14 1 2
+14 13 2 1
+12 15 0 3
+15 12 3 0
+14 13 2 1
+13 14 1 2
+15 12 3 0
+12 15 0 3
+15 12 3 0
+12 15 0 3
+14 13 2 1
+13 14 1 2
+8 11 4 7
+11 8 7 4
+9 10 5 6
+10 9 6 5
+9 10 5 6
+10 9 6 5
+8 11 4 7
+11 8 7 4
+10 9 6 5
+9 10 5 6
+11 8 7 4
+8 11 4 7
+11 8 7 4
+8 11 4 7
+10 9 6 5
+9 10 5 6
+4 7 8 11
+7 4 11 8
+5 6 9 10
+6 5 10 9
+5 6 9 10
+6 5 10 9
+4 7 8 11
+7 4 11 8
+6 5 10 9
+5 6 9 10
+7 4 11 8
+4 7 8 11
+7 4 11 8
+4 7 8 11
+6 5 10 9
+5 6 9 10
+12 15 0 3
+15 12 3 0
+13 14 1 2
+14 13 2 1
+13 14 1 2
+14 13 2 1
+12 15 0 3
+15 12 3 0
+14 13 2 1
+13 14 1 2
+15 12 3 0
+12 15 0 3
+15 12 3 0
+12 15 0 3
+14 13 2 1
+13 14 1 2
+0 3 12 15
+3 0 15 12
+1 2 13 14
+2 1 14 13
+1 2 13 14
+2 1 14 13
+0 3 12 15
+3 0 15 12
+2 1 14 13
+1 2 13 14
+3 0 15 12
+0 3 12 15
+3 0 15 12
+0 3 12 15
+2 1 14 13
+1 2 13 14
+12 15 0 3
+15 12 3 0
+13 14 1 2
+14 13 2 1
+13 14 1 2
+14 13 2 1
+12 15 0 3
+15 12 3 0
+14 13 2 1
+13 14 1 2
+15 12 3 0
+12 15 0 3
+15 12 3 0
+12 15 0 3
+14 13 2 1
+13 14 1 2
+0 3 12 15
+3 0 15 12
+1 2 13 14
+2 1 14 13
+1 2 13 14
+2 1 14 13
+0 3 12 15
+3 0 15 12
+2 1 14 13
+1 2 13 14
+3 0 15 12
+0 3 12 15
+3 0 15 12
+0 3 12 15
+2 1 14 13
+1 2 13 14
+8 11 4 7
+11 8 7 4
+9 10 5 6
+10 9 6 5
+9 10 5 6
+10 9 6 5
+8 11 4 7
+11 8 7 4
+10 9 6 5
+9 10 5 6
+11 8 7 4
+8 11 4 7
+11 8 7 4
+8 11 4 7
+10 9 6 5
+9 10 5 6
+4 7 8 11
+7 4 11 8
+5 6 9 10
+6 5 10 9
+5 6 9 10
+6 5 10 9
+4 7 8 11
+7 4 11 8
+6 5 10 9
+5 6 9 10
+7 4 11 8
+4 7 8 11
+7 4 11 8
+4 7 8 11
+6 5 10 9
+5 6 9 10
+
+This is the joint trellis of two trellises described in awgn1o2_16.fsm
+It is useful for application of joint decoding...
+It can be generated in python as follows:
+> import trellis
+> f1=trellis.fsm('awgn1o2_16.fsm')
+> f=trellis.fsm(f1,f1)
+> f.write_fsm_txt('joint_16_16.fsm')
diff --git a/gr-trellis/src/examples/python/fsm_files/joint_4_16.fsm b/gr-trellis/src/examples/python/fsm_files/joint_4_16.fsm
new file mode 100644
index 000000000..8f2cdab81
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/joint_4_16.fsm
@@ -0,0 +1,141 @@
+4 64 16
+
+0 8 32 40
+0 8 32 40
+1 9 33 41
+1 9 33 41
+2 10 34 42
+2 10 34 42
+3 11 35 43
+3 11 35 43
+4 12 36 44
+4 12 36 44
+5 13 37 45
+5 13 37 45
+6 14 38 46
+6 14 38 46
+7 15 39 47
+7 15 39 47
+0 8 32 40
+0 8 32 40
+1 9 33 41
+1 9 33 41
+2 10 34 42
+2 10 34 42
+3 11 35 43
+3 11 35 43
+4 12 36 44
+4 12 36 44
+5 13 37 45
+5 13 37 45
+6 14 38 46
+6 14 38 46
+7 15 39 47
+7 15 39 47
+16 24 48 56
+16 24 48 56
+17 25 49 57
+17 25 49 57
+18 26 50 58
+18 26 50 58
+19 27 51 59
+19 27 51 59
+20 28 52 60
+20 28 52 60
+21 29 53 61
+21 29 53 61
+22 30 54 62
+22 30 54 62
+23 31 55 63
+23 31 55 63
+16 24 48 56
+16 24 48 56
+17 25 49 57
+17 25 49 57
+18 26 50 58
+18 26 50 58
+19 27 51 59
+19 27 51 59
+20 28 52 60
+20 28 52 60
+21 29 53 61
+21 29 53 61
+22 30 54 62
+22 30 54 62
+23 31 55 63
+23 31 55 63
+
+0 3 12 15
+3 0 15 12
+1 2 13 14
+2 1 14 13
+1 2 13 14
+2 1 14 13
+0 3 12 15
+3 0 15 12
+2 1 14 13
+1 2 13 14
+3 0 15 12
+0 3 12 15
+3 0 15 12
+0 3 12 15
+2 1 14 13
+1 2 13 14
+12 15 0 3
+15 12 3 0
+13 14 1 2
+14 13 2 1
+13 14 1 2
+14 13 2 1
+12 15 0 3
+15 12 3 0
+14 13 2 1
+13 14 1 2
+15 12 3 0
+12 15 0 3
+15 12 3 0
+12 15 0 3
+14 13 2 1
+13 14 1 2
+4 7 8 11
+7 4 11 8
+5 6 9 10
+6 5 10 9
+5 6 9 10
+6 5 10 9
+4 7 8 11
+7 4 11 8
+6 5 10 9
+5 6 9 10
+7 4 11 8
+4 7 8 11
+7 4 11 8
+4 7 8 11
+6 5 10 9
+5 6 9 10
+8 11 4 7
+11 8 7 4
+9 10 5 6
+10 9 6 5
+9 10 5 6
+10 9 6 5
+8 11 4 7
+11 8 7 4
+10 9 6 5
+9 10 5 6
+11 8 7 4
+8 11 4 7
+11 8 7 4
+8 11 4 7
+10 9 6 5
+9 10 5 6
+
+This is the joint trellis of two trellises described in awgn1o2_4.fsm and awgn1o2_16.fsm
+It is useful for application of joint decoding...
+It can be generated in python as follows:
+> import trellis
+> f1=trellis.fsm('awgn1o2_4.fsm')
+> f2=trellis.fsm('awgn1o2_16.fsm')
+> f=trellis.fsm(f1,f2)
+> f.write_fsm_txt('joint_4_16.fsm')
+
diff --git a/gr-trellis/src/examples/python/fsm_files/rep3.fsm b/gr-trellis/src/examples/python/fsm_files/rep3.fsm
new file mode 100644
index 000000000..ef1bd1f02
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/rep3.fsm
@@ -0,0 +1,8 @@
+2 1 8
+
+0 0
+
+0 7
+
+1/3 repetition code (with binary input).
+There is only one state, since this is essentially a memoryless system.
diff --git a/gr-trellis/src/examples/python/fsm_files/rep5.fsm b/gr-trellis/src/examples/python/fsm_files/rep5.fsm
new file mode 100644
index 000000000..2aa5d77cf
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/rep5.fsm
@@ -0,0 +1,7 @@
+2 1 32
+
+0 0
+
+0 31
+
+1/5 repetition code
diff --git a/gr-trellis/src/examples/python/fsm_files/simple.fsm b/gr-trellis/src/examples/python/fsm_files/simple.fsm
new file mode 100644
index 000000000..f27f6b4b0
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_files/simple.fsm
@@ -0,0 +1,13 @@
+1 4 1
+
+1
+2
+3
+0
+
+0
+0
+0
+0
+
+essentially this fsm has no inputs and no outputs; it just cycles through all 4 states.
diff --git a/gr-trellis/src/examples/python/fsm_utils.py b/gr-trellis/src/examples/python/fsm_utils.py
new file mode 100755
index 000000000..e9243f899
--- /dev/null
+++ b/gr-trellis/src/examples/python/fsm_utils.py
@@ -0,0 +1,239 @@
+#!/usr/bin/env python
+#
+# Copyright 2004 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+
+import re
+import math
+import sys
+import operator
+import numpy
+
+from gnuradio import trellis
+
+try:
+ import scipy.linalg
+except ImportError:
+ print "Error: Program requires scipy (see: www.scipy.org)."
+ sys.exit(1)
+
+
+
+######################################################################
+# Decimal to any base conversion.
+# Convert 'num' to a list of 'l' numbers representing 'num'
+# to base 'base' (most significant symbol first).
+######################################################################
+def dec2base(num,base,l):
+ s=range(l)
+ n=num
+ for i in range(l):
+ s[l-i-1]=n%base
+ n=int(n/base)
+ if n!=0:
+ print 'Number ', num, ' requires more than ', l, 'digits.'
+ return s
+
+
+######################################################################
+# Conversion from any base to decimal.
+# Convert a list 's' of symbols to a decimal number
+# (most significant symbol first)
+######################################################################
+def base2dec(s,base):
+ num=0
+ for i in range(len(s)):
+ num=num*base+s[i]
+ return num
+
+
+
+
+######################################################################
+# 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.
+# This table is used by the 'metrics' block to translate
+# channel outputs to metrics for use with the Viterbi algorithm.
+# Limitations: currently supports only one-dimensional modulations.
+######################################################################
+def make_isi_lookup(mod,channel,normalize):
+ dim=mod[0]
+ constellation = mod[1]
+
+ if normalize:
+ p = 0
+ for i in range(len(channel)):
+ p = p + channel[i]**2
+ for i in range(len(channel)):
+ channel[i] = channel[i]/math.sqrt(p)
+
+ lookup=range(len(constellation)**len(channel))
+ for o in range(len(constellation)**len(channel)):
+ ss=dec2base(o,len(constellation),len(channel))
+ ll=0
+ for i in range(len(channel)):
+ ll=ll+constellation[ss[i]]*channel[i]
+ lookup[o]=ll
+ return (1,lookup)
+
+
+
+
+
+
+######################################################################
+# Automatically generate the signals appropriate for CPM
+# decomposition.
+# This decomposition is based on the paper by B. Rimoldi
+# "A decomposition approach to CPM", IEEE Trans. Info Theory, March 1988
+# See also my own notes at http://www.eecs.umich.edu/~anastas/docs/cpm.pdf
+######################################################################
+def make_cpm_signals(K,P,M,L,q,frac):
+
+ Q=numpy.size(q)/L
+ h=(1.0*K)/P
+ f0=-h*(M-1)/2
+ dt=0.0; # maybe start at t=0.5
+ t=(dt+numpy.arange(0,Q))/Q
+ qq=numpy.zeros(Q)
+ for m in range(L):
+ qq=qq + q[m*Q:m*Q+Q]
+ w=math.pi*h*(M-1)*t-2*math.pi*h*(M-1)*qq+math.pi*h*(L-1)*(M-1)
+
+ X=(M**L)*P
+ PSI=numpy.empty((X,Q))
+ for x in range(X):
+ xv=dec2base(x/P,M,L)
+ xv=numpy.append(xv, x%P)
+ qq1=numpy.zeros(Q)
+ for m in range(L):
+ qq1=qq1+xv[m]*q[m*Q:m*Q+Q]
+ psi=2*math.pi*h*xv[-1]+4*math.pi*h*qq1+w
+ #print psi
+ PSI[x]=psi
+ PSI = numpy.transpose(PSI)
+ SS=numpy.exp(1j*PSI) # contains all signals as columns
+ #print SS
+
+
+ # Now we need to orthogonalize the signals
+ F = scipy.linalg.orth(SS) # find an orthonormal basis for SS
+ #print numpy.dot(numpy.transpose(F.conjugate()),F) # check for orthonormality
+ S = numpy.dot(numpy.transpose(F.conjugate()),SS)
+ #print F
+ #print S
+
+ # We only want to keep those dimensions that contain most
+ # of the energy of the overall constellation (eg, frac=0.9 ==> 90%)
+ # evaluate mean energy in each dimension
+ E=numpy.sum(numpy.absolute(S)**2,axis=1)/Q
+ E=E/numpy.sum(E)
+ #print E
+ Es = -numpy.sort(-E)
+ Esi = numpy.argsort(-E)
+ #print Es
+ #print Esi
+ Ecum=numpy.cumsum(Es)
+ #print Ecum
+ v0=numpy.searchsorted(Ecum,frac)
+ N = v0+1
+ #print v0
+ #print Esi[0:v0+1]
+ Ff=numpy.transpose(numpy.transpose(F)[Esi[0:v0+1]])
+ #print Ff
+ Sf = S[Esi[0:v0+1]]
+ #print Sf
+
+
+ return (f0,SS,S,F,Sf,Ff,N)
+ #return f0
+
+
+
+
+######################################################################
+# A list of common modulations.
+# Format: (dimensionality,constellation)
+######################################################################
+pam2 = (1,[-1, 1])
+pam4 = (1,[-3, -1, 3, 1]) # includes Gray mapping
+pam8 = (1,[-7, -5, -3, -1, 1, 3, 5, 7])
+
+psk4=(2,[1, 0, \
+ 0, 1, \
+ 0, -1,\
+ -1, 0]) # includes Gray mapping
+psk8=(2,[math.cos(2*math.pi*0/8), math.sin(2*math.pi*0/8), \
+ math.cos(2*math.pi*1/8), math.sin(2*math.pi*1/8), \
+ math.cos(2*math.pi*2/8), math.sin(2*math.pi*2/8), \
+ math.cos(2*math.pi*3/8), math.sin(2*math.pi*3/8), \
+ math.cos(2*math.pi*4/8), math.sin(2*math.pi*4/8), \
+ math.cos(2*math.pi*5/8), math.sin(2*math.pi*5/8), \
+ math.cos(2*math.pi*6/8), math.sin(2*math.pi*6/8), \
+ math.cos(2*math.pi*7/8), math.sin(2*math.pi*7/8)])
+
+orth2 = (2,[1, 0, \
+ 0, 1])
+orth4=(4,[1, 0, 0, 0, \
+ 0, 1, 0, 0, \
+ 0, 0, 1, 0, \
+ 0, 0, 0, 1])
+
+######################################################################
+# A list of channels to be tested
+######################################################################
+
+# C test channel (J. Proakis, Digital Communications, McGraw-Hill Inc., 2001)
+c_channel = [0.227, 0.460, 0.688, 0.460, 0.227]
+
+
+
+
+
+
+
+
+
+
+if __name__ == '__main__':
+ f1=trellis.fsm('fsm_files/awgn1o2_4.fsm')
+ #f2=trellis.fsm('fsm_files/awgn2o3_4.fsm')
+ #print f1.I(), f1.S(), f1.O()
+ #print f1.NS()
+ #print f1.OS()
+ #print f2.I(), f2.S(), f2.O()
+ #print f2.NS()
+ #print f2.OS()
+ ##f1.write_trellis_svg('f1.svg',4)
+ #f2.write_trellis_svg('f2.svg',4)
+ #f=fsm_concatenate(f1,f2)
+ #f=fsm_radix(f1,2)
+
+ #print "----------\n"
+ #print f.I(), f.S(), f.O()
+ #print f.NS()
+ #print f.OS()
+ #f.write_trellis_svg('f.svg',4)
+
+ q=numpy.arange(0,8)/(2.0*8)
+ (f0,SS,S,F,Sf,Ff,N) = make_cpm_signals(1,2,2,1,q,0.99)
+
diff --git a/gr-trellis/src/examples/python/test_cpm.py b/gr-trellis/src/examples/python/test_cpm.py
new file mode 100755
index 000000000..06d54b1a6
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_cpm.py
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+##################################################
+# Gnuradio Python Flow Graph
+# Title: CPM test
+# Author: Achilleas Anastasopoulos
+# Description: gnuradio flow graph
+# Generated: Thu Feb 19 23:16:23 2009
+##################################################
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+from gnuradio.gr import firdes
+from grc_gnuradio import blks2 as grc_blks2
+import math
+import numpy
+import fsm_utils
+from gnuradio import trellis
+
+try:
+ import scipy.stats
+except ImportError:
+ print "Error: Program requires scipy (see: www.scipy.org)."
+ sys.exit(1)
+
+def run_test(seed,blocksize):
+ tb = gr.top_block()
+
+ ##################################################
+ # Variables
+ ##################################################
+ M = 2
+ K = 1
+ P = 2
+ h = (1.0*K)/P
+ L = 3
+ Q = 4
+ frac = 0.99
+ f = trellis.fsm(P,M,L)
+
+ # CPFSK signals
+ #p = numpy.ones(Q)/(2.0)
+ #q = numpy.cumsum(p)/(1.0*Q)
+
+ # GMSK signals
+ BT=0.3;
+ tt=numpy.arange(0,L*Q)/(1.0*Q)-L/2.0;
+ #print tt
+ p=(0.5*scipy.stats.erfc(2*math.pi*BT*(tt-0.5)/math.sqrt(math.log(2.0))/math.sqrt(2.0))-0.5*scipy.stats.erfc(2*math.pi*BT*(tt+0.5)/math.sqrt(math.log(2.0))/math.sqrt(2.0)))/2.0;
+ p=p/sum(p)*Q/2.0;
+ #print p
+ q=numpy.cumsum(p)/Q;
+ q=q/q[-1]/2.0;
+ #print q
+
+ (f0T,SS,S,F,Sf,Ff,N) = fsm_utils.make_cpm_signals(K,P,M,L,q,frac)
+ #print N
+ #print Ff
+ Ffa = numpy.insert(Ff,Q,numpy.zeros(N),axis=0)
+ #print Ffa
+ MF = numpy.fliplr(numpy.transpose(Ffa))
+ #print MF
+ E = numpy.sum(numpy.abs(Sf)**2,axis=0)
+ Es = numpy.sum(E)/f.O()
+ #print Es
+
+ constellation = numpy.reshape(numpy.transpose(Sf),N*f.O())
+ #print Ff
+ #print Sf
+ #print constellation
+ #print numpy.max(numpy.abs(SS - numpy.dot(Ff , Sf)))
+
+ EsN0_db = 10.0
+ N0 = Es * 10.0**(-(1.0*EsN0_db)/10.0)
+ #N0 = 0.0
+ #print N0
+ head = 4
+ tail = 4
+ numpy.random.seed(seed*666)
+ data = numpy.random.randint(0, M, head+blocksize+tail+1)
+ #data = numpy.zeros(blocksize+1+head+tail,'int')
+ for i in range(head):
+ data[i]=0
+ for i in range(tail+1):
+ data[-i]=0
+
+
+
+ ##################################################
+ # Blocks
+ ##################################################
+ random_source_x_0 = gr.vector_source_b(data.tolist(), False)
+ gr_chunks_to_symbols_xx_0 = gr.chunks_to_symbols_bf((-1, 1), 1)
+ gr_interp_fir_filter_xxx_0 = gr.interp_fir_filter_fff(Q, p)
+ gr_frequency_modulator_fc_0 = gr.frequency_modulator_fc(2*math.pi*h*(1.0/Q))
+
+ gr_add_vxx_0 = gr.add_vcc(1)
+ gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, (N0/2.0)**0.5, -long(seed))
+
+ gr_multiply_vxx_0 = gr.multiply_vcc(1)
+ gr_sig_source_x_0 = gr.sig_source_c(Q, gr.GR_COS_WAVE, -f0T, 1, 0)
+ # only works for N=2, do it manually for N>2...
+ gr_fir_filter_xxx_0_0 = gr.fir_filter_ccc(Q, MF[0].conjugate())
+ gr_fir_filter_xxx_0_0_0 = gr.fir_filter_ccc(Q, MF[1].conjugate())
+ gr_streams_to_stream_0 = gr.streams_to_stream(gr.sizeof_gr_complex*1, int(N))
+ gr_skiphead_0 = gr.skiphead(gr.sizeof_gr_complex*1, int(N*(1+0)))
+ viterbi = trellis.viterbi_combined_cb(f, head+blocksize+tail, 0, -1, int(N),
+ constellation, digital.TRELLIS_EUCLIDEAN)
+
+ gr_vector_sink_x_0 = gr.vector_sink_b()
+
+ ##################################################
+ # Connections
+ ##################################################
+ tb.connect((random_source_x_0, 0), (gr_chunks_to_symbols_xx_0, 0))
+ tb.connect((gr_chunks_to_symbols_xx_0, 0), (gr_interp_fir_filter_xxx_0, 0))
+ tb.connect((gr_interp_fir_filter_xxx_0, 0), (gr_frequency_modulator_fc_0, 0))
+ tb.connect((gr_frequency_modulator_fc_0, 0), (gr_add_vxx_0, 0))
+ tb.connect((gr_noise_source_x_0, 0), (gr_add_vxx_0, 1))
+ tb.connect((gr_add_vxx_0, 0), (gr_multiply_vxx_0, 0))
+ tb.connect((gr_sig_source_x_0, 0), (gr_multiply_vxx_0, 1))
+ tb.connect((gr_multiply_vxx_0, 0), (gr_fir_filter_xxx_0_0, 0))
+ tb.connect((gr_multiply_vxx_0, 0), (gr_fir_filter_xxx_0_0_0, 0))
+ tb.connect((gr_fir_filter_xxx_0_0, 0), (gr_streams_to_stream_0, 0))
+ tb.connect((gr_fir_filter_xxx_0_0_0, 0), (gr_streams_to_stream_0, 1))
+ tb.connect((gr_streams_to_stream_0, 0), (gr_skiphead_0, 0))
+ tb.connect((gr_skiphead_0, 0), (viterbi, 0))
+ tb.connect((viterbi, 0), (gr_vector_sink_x_0, 0))
+
+
+ tb.run()
+ dataest = gr_vector_sink_x_0.data()
+ #print data
+ #print numpy.array(dataest)
+ perr = 0
+ err = 0
+ for i in range(blocksize):
+ if data[head+i] != dataest[head+i]:
+ #print i
+ err += 1
+ if err != 0 :
+ perr = 1
+ return (err,perr)
+
+if __name__ == '__main__':
+ blocksize = 1000
+ ss=0
+ ee=0
+ for i in range(10000):
+ (s,e) = run_test(i,blocksize)
+ ss += s
+ ee += e
+ if (i+1) % 100 == 0:
+ print i+1,ss,ee,(1.0*ss)/(i+1)/(1.0*blocksize),(1.0*ee)/(i+1)
+ print i+1,ss,ee,(1.0*ss)/(i+1)/(1.0*blocksize),(1.0*ee)/(i+1)
diff --git a/gr-trellis/src/examples/python/test_pccc_turbo1.py b/gr-trellis/src/examples/python/test_pccc_turbo1.py
new file mode 100755
index 000000000..7f1ea26ae
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_pccc_turbo1.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+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,digital.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/python/test_sccc_hard.py b/gr-trellis/src/examples/python/test_sccc_hard.py
new file mode 100755
index 000000000..e732ac2c0
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_sccc_hard.py
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+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,N0,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_out = trellis.encoder_ss(fo,0) # initial state = 0
+ inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
+ enc_in = trellis.encoder_ss(fi,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_in = trellis.metrics_f(fi.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner Viterbi
+ va_in = trellis.viterbi_s(fi,K,0,-1) # Put -1 if the Initial/Final states are not set.
+ deinter = trellis.permutation(interleaver.K(),interleaver.DEINTER(),1,gr.sizeof_short)
+ metrics_out = trellis.metrics_s(fo.O(),1,[0,1,2,3],digital.TRELLIS_HARD_SYMBOL) # data preprocessing to generate metrics for outer Viterbi (hard decisions)
+ va_out = trellis.viterbi_s(fo,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
+ dst = gr.check_lfsr_32k_s()
+
+ tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
+ tb.connect (mod,(add,0))
+ tb.connect (noise,(add,1))
+ tb.connect (add,metrics_in)
+ tb.connect (metrics_in,va_in,deinter,metrics_out,va_out,fsmi2s,dst)
+
+ tb.run()
+
+ ntotal = dst.ntotal ()
+ nright = dst.nright ()
+ runlength = dst.runlength ()
+ return (ntotal,ntotal-nright)
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 4:
+ 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
+ else:
+ sys.stderr.write ('usage: test_tcm.py fsm_name_out fsm_fname_in Es/No_db 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,N0,-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
+ 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/python/test_sccc_soft.py b/gr-trellis/src/examples/python/test_sccc_soft.py
new file mode 100755
index 000000000..1c71e4ca7
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_sccc_soft.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+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,N0,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_out = trellis.encoder_ss(fo,0) # initial state = 0
+ inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
+ enc_in = trellis.encoder_ss(fi,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_in = trellis.metrics_f(fi.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner Viterbi
+ gnd = gr.vector_source_f([0],True);
+ siso_in = trellis.siso_f(fi,K,0,-1,True,False,trellis.TRELLIS_MIN_SUM) # Put -1 if the Initial/Final states are not set.
+ deinter = trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float)
+ va_out = trellis.viterbi_s(fo,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
+ dst = gr.check_lfsr_32k_s()
+
+ tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
+ tb.connect (mod,(add,0))
+ tb.connect (noise,(add,1))
+ tb.connect (add,metrics_in)
+ tb.connect (gnd,(siso_in,0))
+ tb.connect (metrics_in,(siso_in,1))
+ tb.connect (siso_in,deinter,va_out,fsmi2s,dst)
+
+ tb.run()
+
+ ntotal = dst.ntotal ()
+ nright = dst.nright ()
+ runlength = dst.runlength ()
+ return (ntotal,ntotal-nright)
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 4:
+ 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
+ else:
+ sys.stderr.write ('usage: test_tcm.py fsm_name_out fsm_fname_in Es/No_db 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,N0,-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
+ 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/python/test_sccc_turbo.py b/gr-trellis/src/examples/python/test_sccc_turbo.py
new file mode 100755
index 000000000..b1007a864
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_sccc_turbo.py
@@ -0,0 +1,142 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+
+
+def make_rx(tb,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,type):
+ metrics_in = trellis.metrics_f(fi.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner Viterbi
+ scale = gr.multiply_const_ff(1.0/N0)
+ gnd = gr.vector_source_f([0],True);
+
+ inter=[]
+ deinter=[]
+ siso_in=[]
+ siso_out=[]
+
+ # generate all blocks
+ for it in range(IT):
+ inter.append( trellis.permutation(interleaver.K(),interleaver.INTER(),fi.I(),gr.sizeof_float) )
+ siso_in.append( trellis.siso_f(fi,K,0,-1,True,False,type) )
+ deinter.append( trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float) )
+ if it < IT-1:
+ siso_out.append( trellis.siso_f(fo,K,0,-1,False,True,type) )
+ else:
+ siso_out.append( trellis.viterbi_s(fo,K,0,-1) ) # no soft outputs needed
+
+ # connect first stage
+ tb.connect (gnd,inter[0])
+ tb.connect (metrics_in,scale)
+ tb.connect (scale,(siso_in[0],1))
+
+ # connect the rest
+ for it in range(IT):
+ if it < IT-1:
+ tb.connect (metrics_in,(siso_in[it+1],1))
+ tb.connect (siso_in[it],deinter[it],(siso_out[it],1))
+ tb.connect (gnd,(siso_out[it],0))
+ tb.connect (siso_out[it],inter[it+1])
+ tb.connect (inter[it],(siso_in[it],0))
+ else:
+ tb.connect (siso_in[it],deinter[it],siso_out[it])
+ tb.connect (inter[it],(siso_in[it],0))
+
+ return (metrics_in,siso_out[IT-1])
+
+
+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_out = trellis.encoder_ss(fo,0) # initial state = 0
+ inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
+ enc_in = trellis.encoder_ss(fi,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
+ (head,tail) = make_rx(tb,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM)
+ #(head,tail) = make_rx(tb,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_SUM_PRODUCT)
+ 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 (mod,(add,0))
+ tb.connect (noise,(add,1))
+ tb.connect (add,head)
+ tb.connect (tail,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_sccc_turbo.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/python/test_sccc_turbo1.py b/gr-trellis/src/examples/python/test_sccc_turbo1.py
new file mode 100755
index 000000000..ad2ed6bf9
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_sccc_turbo1.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+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
+ dec = trellis.sccc_decoder_combined_fs(fo,0,-1,fi,0,-1,interleaver,K,IT,trellis.TRELLIS_MIN_SUM,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN,1.0)
+ 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,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/python/test_sccc_turbo2.py b/gr-trellis/src/examples/python/test_sccc_turbo2.py
new file mode 100755
index 000000000..fdb92adc8
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_sccc_turbo2.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+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,digital.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/python/test_tcm.py b/gr-trellis/src/examples/python/test_tcm.py
new file mode 100755
index 000000000..62fd5135e
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_tcm.py
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+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 ()
+
+
+ # 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,digital.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()
+
+
+ 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.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():
+ 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
+ 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
+ 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
+ tot_s=tot_s+s
+ terr_s=terr_s+e
+ 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 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()
diff --git a/gr-trellis/src/examples/python/test_tcm_bit.py b/gr-trellis/src/examples/python/test_tcm_bit.py
new file mode 100755
index 000000000..cc5caefbc
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_tcm_bit.py
@@ -0,0 +1,129 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+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 ()
+
+ # TX
+ packet = [0]*Kb
+ # this for loop is TOO slow!!!
+ 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,digital.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();
+
+
+ #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.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;
+ # this for loop is TOO slow!!!
+ 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():
+ 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
+ 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
+ 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
+ tot_s=tot_s+s
+ terr_s=terr_s+e
+ terr_p=terr_p+(terr_s!=0)
+ if ((i+1)%1==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()
diff --git a/gr-trellis/src/examples/python/test_tcm_combined.py b/gr-trellis/src/examples/python/test_tcm_combined.py
new file mode 100755
index 000000000..55a3043b8
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_tcm_combined.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+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 ()
+
+ # 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 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
+ va = trellis.viterbi_combined_fs(f,K,0,-1,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # 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
+ dst = gr.check_lfsr_32k_s();
+
+
+ tb.connect (src,src_head,s2fsmi,enc,mod)
+ tb.connect (mod,(add,0))
+ tb.connect (noise,(add,1))
+ tb.connect (add,va,fsmi2s,dst)
+
+
+ tb.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 ()
+
+ return (ntotal,ntotal-nright)
+
+
+
+
+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...)
+ Kb=1024*16 # packet size in bits (make it multiple of 16)
+ 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_utils.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); # 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(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
+ 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 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()
+
diff --git a/gr-trellis/src/examples/python/test_tcm_parallel.py b/gr-trellis/src/examples/python/test_tcm_parallel.py
new file mode 100755
index 000000000..2b722c09e
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_tcm_parallel.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+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 ()
+
+ # TX
+ 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(gr.sizeof_short,P) # serial to parallel
+ enc = trellis.encoder_ss(f,0) # initiali state = 0
+ mod = gr.chunks_to_symbols_sf(constellation,dimensionality)
+
+ # CHANNEL
+ add=[]
+ noise=[]
+ for i in range(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,digital.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(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()
+
+ tb.connect (src,src_head,s2fsmi,s2p)
+ for i in range(P):
+ tb.connect ((s2p,i),(enc,i),(mod,i))
+ tb.connect ((mod,i),(add[i],0))
+ tb.connect (noise[i],(add[i],1))
+ tb.connect (add[i],(metrics,i))
+ tb.connect ((metrics,i),(va,i),(p2s,i))
+ tb.connect (p2s,fsmi2s,dst)
+
+
+ tb.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 ()
+
+ return (ntotal,ntotal-nright)
+
+
+
+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
+ P=4 # how many parallel streams?
+ 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
+ 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
+ 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 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()
+
diff --git a/gr-trellis/src/examples/python/test_turbo_equalization.py b/gr-trellis/src/examples/python/test_turbo_equalization.py
new file mode 100755
index 000000000..6fa6749f0
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_turbo_equalization.py
@@ -0,0 +1,142 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+from gnuradio import eng_notation
+import math
+import sys
+import fsm_utils
+
+
+def make_rx(tb,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,type):
+ metrics_in = trellis.metrics_f(fi.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO
+ scale = gr.multiply_const_ff(1.0/N0)
+ gnd = gr.vector_source_f([0],True);
+
+ inter=[]
+ deinter=[]
+ siso_in=[]
+ siso_out=[]
+
+ # generate all blocks
+ for it in range(IT):
+ inter.append( trellis.permutation(interleaver.K(),interleaver.INTER(),fi.I(),gr.sizeof_float) )
+ siso_in.append( trellis.siso_f(fi,K,0,-1,True,False,type) )
+ deinter.append( trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float) )
+ if it < IT-1:
+ siso_out.append( trellis.siso_f(fo,K,0,-1,False,True,type) )
+ else:
+ siso_out.append( trellis.viterbi_s(fo,K,0,-1) ) # no soft outputs needed
+
+ # connect first stage
+ tb.connect (gnd,inter[0])
+ tb.connect (metrics_in,scale)
+ tb.connect (scale,(siso_in[0],1))
+
+ # connect the rest
+ for it in range(IT):
+ if it < IT-1:
+ tb.connect (metrics_in,(siso_in[it+1],1))
+ tb.connect (siso_in[it],deinter[it],(siso_out[it],1))
+ tb.connect (gnd,(siso_out[it],0))
+ tb.connect (siso_out[it],inter[it+1])
+ tb.connect (inter[it],(siso_in[it],0))
+ else:
+ tb.connect (siso_in[it],deinter[it],siso_out[it])
+ tb.connect (inter[it],(siso_in[it],0))
+
+ return (metrics_in,siso_out[IT-1])
+
+
+def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,tot_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 iouter FSM input cardinality
+ enc_out = trellis.encoder_ss(fo,0) # initial state = 0
+ inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
+ enc_in = trellis.encoder_ss(fi,0) # initial state = 0
+ # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the innner FSM)
+ mod = gr.chunks_to_symbols_sf(tot_constellation,dimensionality)
+
+ # CHANNEL
+ add = gr.add_ff()
+ noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)
+
+ # RX
+ (head,tail) = make_rx(tb,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,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 (mod,(add,0))
+ tb.connect (noise,(add,1))
+ tb.connect (add,head)
+ tb.connect (tail,fsmi2s,dst)
+
+ tb.run()
+
+ ntotal = dst.ntotal ()
+ nright = dst.nright ()
+ runlength = dst.runlength ()
+ #print ntotal,nright,runlength
+
+ return (ntotal,ntotal-nright)
+
+
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 3:
+ fname_out=args[0]
+ esn0_db=float(args[1])
+ rep=int(args[2])
+ else:
+ sys.stderr.write ('usage: test_turbo_equalization.py fsm_name_out Es/No_db repetitions\n')
+ sys.exit (1)
+
+ # system parameters
+ Kb=64*16 # packet size in bits (multiple of 16)
+ modulation = fsm_utils.pam4 # see fsm_utlis.py for available predefined modulations
+ channel = fsm_utils.c_channel # see fsm_utlis.py for available predefined test channels
+ fo=trellis.fsm(fname_out) # get the outer FSM specification from a file
+ fi=trellis.fsm(len(modulation[1]),len(channel)) # generate the FSM automatically
+ if fo.O() != fi.I():
+ sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n')
+ sys.exit (1)
+ bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol
+ K=Kb/bitspersymbol # packet size in trellis steps
+ print 'size = ',K
+ interleaver=trellis.interleaver(K,666) # construct a random interleaver
+ tot_channel = fsm_utils.make_isi_lookup(modulation,channel,True) # generate the lookup table (normalize energy to 1)
+ dimensionality = tot_channel[0]
+ tot_constellation = tot_channel[1]
+ if len(tot_constellation)/dimensionality != fi.O():
+ sys.stderr.write ('Incompatible FSM output cardinality and lookup table size.\n')
+ sys.exit (1)
+ N0=pow(10.0,-esn0_db/10.0); # 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
+ 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,tot_constellation,1,N0,IT,-long(666+i)) # run experiment with different seed to get different noise realizations
+ print s
+ 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/python/test_turbo_equalization1.py b/gr-trellis/src/examples/python/test_turbo_equalization1.py
new file mode 100755
index 000000000..15a8f6809
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_turbo_equalization1.py
@@ -0,0 +1,146 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def make_rx(tb,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,type):
+ metrics_in = trellis.metrics_f(fi.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO
+ scale = gr.multiply_const_ff(1.0/N0)
+ gnd = gr.vector_source_f([0],True);
+
+ inter=[]
+ deinter=[]
+ siso_in=[]
+ siso_out=[]
+
+ # generate all blocks
+ for it in range(IT):
+ inter.append( trellis.permutation(interleaver.K(),interleaver.INTER(),fi.I(),gr.sizeof_float) )
+ siso_in.append( trellis.siso_f(fi,K,0,-1,True,False,type) )
+ deinter.append( trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float) )
+ if it < IT-1:
+ siso_out.append( trellis.siso_f(fo,K,0,-1,False,True,type) )
+ else:
+ siso_out.append( trellis.viterbi_s(fo,K,0,-1) ) # no soft outputs needed
+
+ # connect first stage
+ tb.connect (gnd,inter[0])
+ tb.connect (metrics_in,scale)
+ tb.connect (scale,(siso_in[0],1))
+
+ # connect the rest
+ for it in range(IT):
+ if it < IT-1:
+ tb.connect (scale,(siso_in[it+1],1))
+ tb.connect (siso_in[it],deinter[it],(siso_out[it],1))
+ tb.connect (gnd,(siso_out[it],0))
+ tb.connect (siso_out[it],inter[it+1])
+ tb.connect (inter[it],(siso_in[it],0))
+ else:
+ tb.connect (siso_in[it],deinter[it],siso_out[it])
+ tb.connect (inter[it],(siso_in[it],0))
+
+ return (metrics_in,siso_out[IT-1])
+
+
+def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,Es,N0,IT,seed):
+ tb = gr.top_block ()
+ L = len(channel)
+
+ # TX
+ # this for loop is TOO slow in python!!!
+ packet = [0]*(K)
+ random.seed(seed)
+ for i in range(len(packet)):
+ packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols
+ src = gr.vector_source_s(packet,False)
+ enc_out = trellis.encoder_ss(fo,0) # initial state = 0
+ inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
+ mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0])
+
+ # CHANNEL
+ isi = gr.fir_filter_fff(1,channel)
+ add = gr.add_ff()
+ noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)
+
+ # RX
+ (head,tail) = make_rx(tb,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM)
+ dst = gr.vector_sink_s();
+
+ tb.connect (src,enc_out,inter,mod)
+ tb.connect (mod,isi,(add,0))
+ tb.connect (noise,(add,1))
+ tb.connect (add,head)
+ tb.connect (tail,dst)
+
+ tb.run()
+
+ data = dst.data()
+ ntotal = len(data)
+ nright=0
+ for i in range(ntotal):
+ if packet[i]==data[i]:
+ nright=nright+1
+ #else:
+ #print "Error in ", i
+
+ return (ntotal,ntotal-nright)
+
+
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 3:
+ fname_out=args[0]
+ esn0_db=float(args[1])
+ rep=int(args[2])
+ else:
+ sys.stderr.write ('usage: test_turbo_equalization.py fsm_name_out Es/No_db repetitions\n')
+ sys.exit (1)
+
+ # system parameters
+ Kb=64*16 # packet size in bits (multiple of 16)
+ modulation = fsm_utils.pam4 # see fsm_utlis.py for available predefined modulations
+ channel = fsm_utils.c_channel # see fsm_utlis.py for available predefined test channels
+ fo=trellis.fsm(fname_out) # get the outer FSM specification from a file
+ fi=trellis.fsm(len(modulation[1]),len(channel)) # generate the FSM automatically
+ if fo.O() != fi.I():
+ sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n')
+ sys.exit (1)
+ bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol
+ K=Kb/bitspersymbol # packet size in trellis steps
+ interleaver=trellis.interleaver(K,666) # construct a random interleaver
+ tot_channel = fsm_utils.make_isi_lookup(modulation,channel,True) # generate the lookup table (normalize energy to 1)
+ dimensionality = tot_channel[0]
+ tot_constellation = tot_channel[1]
+ if len(tot_constellation)/dimensionality != fi.O():
+ sys.stderr.write ('Incompatible FSM output cardinality and lookup table size.\n')
+ sys.exit (1)
+ N0=pow(10.0,-esn0_db/10.0); # 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
+ terr_p=0 # total number of packets in error
+
+ for i in range(rep):
+ (s,e)=run_test(fo,fi,interleaver,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,1,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/python/test_turbo_equalization2.py b/gr-trellis/src/examples/python/test_turbo_equalization2.py
new file mode 100755
index 000000000..7e4341cba
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_turbo_equalization2.py
@@ -0,0 +1,146 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def make_rx(tb,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,type):
+ scale = gr.multiply_const_ff(math.sqrt(1.0/N0))
+ gnd = gr.vector_source_f([0],True);
+
+ inter=[]
+ deinter=[]
+ siso_in=[]
+ siso_out=[]
+
+ # generate all blocks
+ for it in range(IT):
+ inter.append( trellis.permutation(interleaver.K(),interleaver.INTER(),fi.I(),gr.sizeof_float) )
+ siso_in.append( trellis.siso_combined_f(fi,K,0,-1,True,False,type,dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) )
+ deinter.append( trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float) )
+ if it < IT-1:
+ siso_out.append( trellis.siso_f(fo,K,0,-1,False,True,type) )
+ else:
+ siso_out.append( trellis.viterbi_s(fo,K,0,-1) ) # no soft outputs needed
+
+ # connect first stage
+ tb.connect (gnd,inter[0])
+ tb.connect (scale,(siso_in[0],1))
+
+ # connect the rest
+ for it in range(IT):
+ if it < IT-1:
+ tb.connect (scale,(siso_in[it+1],1))
+ tb.connect (siso_in[it],deinter[it],(siso_out[it],1))
+ tb.connect (gnd,(siso_out[it],0))
+ tb.connect (siso_out[it],inter[it+1])
+ tb.connect (inter[it],(siso_in[it],0))
+ else:
+ tb.connect (siso_in[it],deinter[it],siso_out[it])
+ tb.connect (inter[it],(siso_in[it],0))
+
+ return (scale,siso_out[IT-1])
+
+
+def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,Es,N0,IT,seed):
+ tb = gr.top_block ()
+ L = len(channel)
+
+ # TX
+ # this for loop is TOO slow in python!!!
+ packet = [0]*(K)
+ random.seed(seed)
+ for i in range(len(packet)):
+ packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols
+ src = gr.vector_source_s(packet,False)
+ enc_out = trellis.encoder_ss(fo,0) # initial state = 0
+ inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
+ mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0])
+
+ # CHANNEL
+ isi = gr.fir_filter_fff(1,channel)
+ add = gr.add_ff()
+ noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)
+
+ # RX
+ (head,tail) = make_rx(tb,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM)
+ dst = gr.vector_sink_s();
+
+ tb.connect (src,enc_out,inter,mod)
+ tb.connect (mod,isi,(add,0))
+ tb.connect (noise,(add,1))
+ tb.connect (add,head)
+ tb.connect (tail,dst)
+
+ tb.run()
+
+ data = dst.data()
+ ntotal = len(data)
+ nright=0
+ for i in range(ntotal):
+ if packet[i]==data[i]:
+ nright=nright+1
+ #else:
+ #print "Error in ", i
+
+ return (ntotal,ntotal-nright)
+
+
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 3:
+ fname_out=args[0]
+ esn0_db=float(args[1])
+ rep=int(args[2])
+ else:
+ sys.stderr.write ('usage: test_turbo_equalization.py fsm_name_out Es/No_db repetitions\n')
+ sys.exit (1)
+
+ # system parameters
+ Kb=64*16 # packet size in bits (multiple of 16)
+ modulation = fsm_utils.pam4 # see fsm_utlis.py for available predefined modulations
+ channel = fsm_utils.c_channel # see fsm_utlis.py for available predefined test channels
+ fo=trellis.fsm(fname_out) # get the outer FSM specification from a file
+ fi=trellis.fsm(len(modulation[1]),len(channel)) # generate the FSM automatically
+ if fo.O() != fi.I():
+ sys.stderr.write ('Incompatible cardinality between outer and inner FSM.\n')
+ sys.exit (1)
+ bitspersymbol = int(round(math.log(fo.I())/math.log(2))) # bits per FSM input symbol
+ K=Kb/bitspersymbol # packet size in trellis steps
+ interleaver=trellis.interleaver(K,666) # construct a random interleaver
+ tot_channel = fsm_utils.make_isi_lookup(modulation,channel,True) # generate the lookup table (normalize energy to 1)
+ dimensionality = tot_channel[0]
+ N0=pow(10.0,-esn0_db/10.0); # noise variance
+ tot_constellation =[0]*len(tot_channel[1])
+ for i in range(len(tot_channel[1])):
+ tot_constellation[i] = tot_channel[1][i] * math.sqrt(1.0/N0)
+ if len(tot_constellation)/dimensionality != fi.O():
+ sys.stderr.write ('Incompatible FSM output cardinality and lookup table size.\n')
+ sys.exit (1)
+ IT = 3 # number of turbo iterations
+
+ 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,channel,modulation,dimensionality,tot_constellation,1,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/python/test_viterbi_equalization.py b/gr-trellis/src/examples/python/test_viterbi_equalization.py
new file mode 100755
index 000000000..d290a0d0a
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_viterbi_equalization.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+from gnuradio import eng_notation
+import math
+import sys
+import fsm_utils
+
+def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,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 FSM input cardinality
+ enc = trellis.encoder_ss(f,0) # initial state = 0
+ # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the FSM)
+ mod = gr.chunks_to_symbols_sf(tot_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,tot_constellation,digital.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
+ dst = gr.check_lfsr_32k_s();
+
+ tb.connect (src,src_head,s2fsmi,enc,mod)
+ tb.connect (mod,(add,0))
+ tb.connect (noise,(add,1))
+ tb.connect (add,metrics)
+ tb.connect (metrics,va,fsmi2s,dst)
+
+ tb.run()
+
+ ntotal = dst.ntotal ()
+ nright = dst.nright ()
+ runlength = dst.runlength ()
+ #print ntotal,nright,runlength
+
+ return (ntotal,ntotal-nright)
+
+
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 2:
+ esn0_db=float(args[0])
+ rep=int(args[1])
+ else:
+ sys.stderr.write ('usage: test_viterbi_equalization.py Es/No_db repetitions\n')
+ sys.exit (1)
+
+ # system parameters
+ Kb=128*16 # packet size in bits (multiple of 16)
+ modulation = fsm_utils.pam4 # see fsm_utlis.py for available predefined modulations
+ channel = fsm_utils.c_channel # see fsm_utlis.py for available predefined test channels
+ f=trellis.fsm(len(modulation[1]),len(channel)) # generate the FSM automatically
+ bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol
+ K=Kb/bitspersymbol # packet size in trellis steps
+
+ tot_channel = fsm_utils.make_isi_lookup(modulation,channel,True) # generate the lookup table (normalize energy to 1)
+ dimensionality = tot_channel[0]
+ tot_constellation = tot_channel[1]
+ N0=pow(10.0,-esn0_db/10.0); # noise variance
+ if len(tot_constellation)/dimensionality != f.O():
+ sys.stderr.write ('Incompatible FSM output cardinality and lookup table size.\n')
+ sys.exit (1)
+
+
+ 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,tot_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
+ 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 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/python/test_viterbi_equalization1.py b/gr-trellis/src/examples/python/test_viterbi_equalization1.py
new file mode 100755
index 000000000..41f777551
--- /dev/null
+++ b/gr-trellis/src/examples/python/test_viterbi_equalization1.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import trellis, digital
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def run_test (f,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,N0,seed):
+ tb = gr.top_block ()
+ L = len(channel)
+
+ # TX
+ # this for loop is TOO slow in python!!!
+ packet = [0]*(K+2*L)
+ random.seed(seed)
+ for i in range(len(packet)):
+ packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols
+ for i in range(L): # first/last L symbols set to 0
+ packet[i] = 0
+ packet[len(packet)-i-1] = 0
+ src = gr.vector_source_s(packet,False)
+ mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0])
+
+ # CHANNEL
+ isi = gr.fir_filter_fff(1,channel)
+ add = gr.add_ff()
+ noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)
+
+ # RX
+ skip = gr.skiphead(gr.sizeof_float, L) # skip the first L samples since you know they are coming from the L zero symbols
+ #metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
+ #va = trellis.viterbi_s(f,K+L,-1,0) # Put -1 if the Initial/Final states are not set.
+ va = trellis.viterbi_combined_fs(f,K+L,0,0,dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # using viterbi_combined_fs instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application...
+ dst = gr.vector_sink_s()
+
+ tb.connect (src,mod)
+ tb.connect (mod,isi,(add,0))
+ tb.connect (noise,(add,1))
+ #tb.connect (add,metrics)
+ #tb.connect (metrics,va,dst)
+ tb.connect (add,skip,va,dst)
+
+ tb.run()
+
+ data = dst.data()
+ ntotal = len(data) - L
+ nright=0
+ for i in range(ntotal):
+ if packet[i+L]==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])
+ rep=int(args[1])
+ else:
+ sys.stderr.write ('usage: test_viterbi_equalization1.py Es/No_db repetitions\n')
+ sys.exit (1)
+
+ # system parameters
+ Kb=128*16 # packet size in bits (multiple of 16)
+ modulation = fsm_utils.pam4 # see fsm_utlis.py for available predefined modulations
+ channel = fsm_utils.c_channel # see fsm_utlis.py for available predefined test channels
+ f=trellis.fsm(len(modulation[1]),len(channel)) # generate the FSM automatically
+ bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol
+ K=Kb/bitspersymbol # packet size in trellis steps
+
+ tot_channel = fsm_utils.make_isi_lookup(modulation,channel,True) # generate the lookup table (normalize energy to 1)
+ dimensionality = tot_channel[0]
+ tot_constellation = tot_channel[1]
+ N0=pow(10.0,-esn0_db/10.0); # noise variance
+ if len(tot_constellation)/dimensionality != f.O():
+ sys.stderr.write ('Incompatible FSM output cardinality and lookup table size.\n')
+ sys.exit (1)
+
+ 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,channel,modulation,dimensionality,tot_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
+ 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 symbol) 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:])