summaryrefslogtreecommitdiff
path: root/gr-trellis
diff options
context:
space:
mode:
Diffstat (limited to 'gr-trellis')
-rw-r--r--gr-trellis/src/Makefile.am2
-rw-r--r--gr-trellis/src/examples/Makefile.am56
-rw-r--r--gr-trellis/src/examples/README53
-rw-r--r--gr-trellis/src/examples/fsm_files/Makefile.am41
-rw-r--r--gr-trellis/src/examples/fsm_files/awgn1o2_128.fsm265
-rw-r--r--gr-trellis/src/examples/fsm_files/awgn1o2_16.fsm39
-rw-r--r--gr-trellis/src/examples/fsm_files/awgn1o2_4.fsm14
-rw-r--r--gr-trellis/src/examples/fsm_files/awgn1o2_8.fsm24
-rw-r--r--gr-trellis/src/examples/fsm_files/awgn2o3_16.fsm40
-rw-r--r--gr-trellis/src/examples/fsm_files/awgn2o3_4.fsm15
-rw-r--r--gr-trellis/src/examples/fsm_files/awgn2o3_4_msb.fsm46
-rw-r--r--gr-trellis/src/examples/fsm_files/awgn2o3_4_msbG.fsm60
-rw-r--r--gr-trellis/src/examples/fsm_files/awgn2o3_8.fsm25
-rw-r--r--gr-trellis/src/examples/fsm_files/awgn2o4_4.fsm36
-rw-r--r--gr-trellis/src/examples/fsm_files/disconnected.fsm11
-rw-r--r--gr-trellis/src/examples/fsm_files/irregular.fsm11
-rw-r--r--gr-trellis/src/examples/fsm_files/rep3.fsm8
-rw-r--r--gr-trellis/src/examples/fsm_files/rep5.fsm7
-rw-r--r--gr-trellis/src/examples/fsm_files/simple.fsm13
-rwxr-xr-xgr-trellis/src/examples/fsm_utils.py213
-rwxr-xr-xgr-trellis/src/examples/test_sccc_hard.py101
-rwxr-xr-xgr-trellis/src/examples/test_sccc_soft.py108
-rwxr-xr-xgr-trellis/src/examples/test_sccc_turbo.py143
-rwxr-xr-xgr-trellis/src/examples/test_tcm.py118
-rwxr-xr-xgr-trellis/src/examples/test_tcm1.py121
-rwxr-xr-xgr-trellis/src/examples/test_tcm2.py116
-rwxr-xr-xgr-trellis/src/examples/test_tcm_combined.py100
-rwxr-xr-xgr-trellis/src/examples/test_tcm_parallel.py106
-rwxr-xr-xgr-trellis/src/examples/test_turbo_equalization.py143
-rwxr-xr-xgr-trellis/src/examples/test_turbo_equalization1.py147
-rwxr-xr-xgr-trellis/src/examples/test_turbo_equalization2.py147
-rwxr-xr-xgr-trellis/src/examples/test_viterbi_equalization.py94
-rwxr-xr-xgr-trellis/src/examples/test_viterbi_equalization1.py103
33 files changed, 2525 insertions, 1 deletions
diff --git a/gr-trellis/src/Makefile.am b/gr-trellis/src/Makefile.am
index e3f0399eb..41f525b0b 100644
--- a/gr-trellis/src/Makefile.am
+++ b/gr-trellis/src/Makefile.am
@@ -19,4 +19,4 @@
# Boston, MA 02110-1301, USA.
#
-SUBDIRS = lib python
+SUBDIRS = lib python examples
diff --git a/gr-trellis/src/examples/Makefile.am b/gr-trellis/src/examples/Makefile.am
new file mode 100644
index 000000000..21003991f
--- /dev/null
+++ b/gr-trellis/src/examples/Makefile.am
@@ -0,0 +1,56 @@
+#
+# 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.
+#
+
+include $(top_srcdir)/Makefile.common
+
+SUBDIRS = fsm_files
+
+EXTRA_DIST = \
+ README \
+ fsm_utils.py \
+ test_tcm.py \
+ test_tcm1.py \
+ test_tcm2.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
+
+
+ourdatadir = $(exampledir)/trellis
+ourdata_DATA = $(EXTRA_DIST)
+
+# Make example scripts with #! executable
+install-data-local:
+ for i in `find $(ourdatadir) -type f ! -perm 755`; do \
+ if head -1 $$i | grep -q '^#!'; then \
+ chmod 755 $$i; \
+ echo "made executable: $$i"; \
+ fi; \
+ done
+
+MOSTLYCLEANFILES = *.pyc
diff --git a/gr-trellis/src/examples/README b/gr-trellis/src/examples/README
new file mode 100644
index 000000000..d5bad85f5
--- /dev/null
+++ b/gr-trellis/src/examples/README
@@ -0,0 +1,53 @@
+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 each of the following:
+
+./test_tcm.py fsm_files/awgn1o2_4.fsm 6.0 1000
+./test_tcm1.py fsm_files/awgn1o2_4.fsm 6.0 1000
+./test_tcm2.py 6.0 1000
+./test_tcm_combined.py fsm_files/awgn1o2_4.fsm 6.0 1000
+./test_tcm_parallel.py fsm_files/awgn1o2_4.fsm 6.0 1000
+
+./test_sccc_hard.py fsm_files/awgn1o2_4.fsm fsm_files/awgn2o3_4_msb.fsm 10.0 100
+./test_sccc_soft.py fsm_files/awgn1o2_4.fsm fsm_files/awgn2o3_4_msb.fsm 8.0 100
+./test_sccc_turbo.py fsm_files/awgn1o2_4.fsm fsm_files/awgn2o3_4_msb.fsm 5.0 100
+
+./test_viterbi_equalization.py 12.0 100
+./test_viterbi_equalization1.py 12.0 100
+./test_turbo_equalization1.py fsm_files/awgn1o2_4.fsm 8.0 100
+./test_turbo_equalization2.py fsm_files/awgn1o2_4.fsm 8.0 100
+
+
+In your terminal you will see something like this:
+
+
+$ ./test_tcm.py fsm_files/awgn1o2_4.fsm 6.0 1000
+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/fsm_files/Makefile.am b/gr-trellis/src/examples/fsm_files/Makefile.am
new file mode 100644
index 000000000..1414d7978
--- /dev/null
+++ b/gr-trellis/src/examples/fsm_files/Makefile.am
@@ -0,0 +1,41 @@
+#
+# 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.
+#
+
+include $(top_srcdir)/Makefile.common
+
+EXTRA_DIST = \
+ awgn1o2_128.fsm \
+ awgn1o2_16.fsm \
+ awgn1o2_4.fsm \
+ awgn1o2_8.fsm \
+ awgn2o3_16.fsm \
+ awgn2o3_4.fsm \
+ awgn2o3_4_msb.fsm \
+ awgn2o3_4_msbG.fsm \
+ awgn2o3_8.fsm \
+ awgn2o4_4.fsm \
+ disconnected.fsm \
+ rep3.fsm \
+ rep5.fsm \
+ simple.fsm
+
+ourdatadir = $(exampledir)/trellis/fsm_files
+ourdata_DATA = $(EXTRA_DIST)
diff --git a/gr-trellis/src/examples/fsm_files/awgn1o2_128.fsm b/gr-trellis/src/examples/fsm_files/awgn1o2_128.fsm
new file mode 100644
index 000000000..bb79c59da
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/awgn1o2_16.fsm b/gr-trellis/src/examples/fsm_files/awgn1o2_16.fsm
new file mode 100644
index 000000000..cdab41359
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/awgn1o2_4.fsm b/gr-trellis/src/examples/fsm_files/awgn1o2_4.fsm
new file mode 100644
index 000000000..fb316b5ef
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/awgn1o2_8.fsm b/gr-trellis/src/examples/fsm_files/awgn1o2_8.fsm
new file mode 100644
index 000000000..604bac6c2
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/awgn2o3_16.fsm b/gr-trellis/src/examples/fsm_files/awgn2o3_16.fsm
new file mode 100644
index 000000000..9630cd9af
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/awgn2o3_4.fsm b/gr-trellis/src/examples/fsm_files/awgn2o3_4.fsm
new file mode 100644
index 000000000..3ac57be18
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/awgn2o3_4_msb.fsm b/gr-trellis/src/examples/fsm_files/awgn2o3_4_msb.fsm
new file mode 100644
index 000000000..551b71101
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/awgn2o3_4_msbG.fsm b/gr-trellis/src/examples/fsm_files/awgn2o3_4_msbG.fsm
new file mode 100644
index 000000000..8956c53da
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/awgn2o3_8.fsm b/gr-trellis/src/examples/fsm_files/awgn2o3_8.fsm
new file mode 100644
index 000000000..34deeb68c
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/awgn2o4_4.fsm b/gr-trellis/src/examples/fsm_files/awgn2o4_4.fsm
new file mode 100644
index 000000000..a895be896
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/disconnected.fsm b/gr-trellis/src/examples/fsm_files/disconnected.fsm
new file mode 100644
index 000000000..847963e7b
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/irregular.fsm b/gr-trellis/src/examples/fsm_files/irregular.fsm
new file mode 100644
index 000000000..80b82b889
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/rep3.fsm b/gr-trellis/src/examples/fsm_files/rep3.fsm
new file mode 100644
index 000000000..ef1bd1f02
--- /dev/null
+++ b/gr-trellis/src/examples/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/fsm_files/rep5.fsm b/gr-trellis/src/examples/fsm_files/rep5.fsm
new file mode 100644
index 000000000..581858ec1
--- /dev/null
+++ b/gr-trellis/src/examples/fsm_files/rep5.fsm
@@ -0,0 +1,7 @@
+2 1 8
+
+0 0
+
+0 7
+
+1/3 repetiotion code
diff --git a/gr-trellis/src/examples/fsm_files/simple.fsm b/gr-trellis/src/examples/fsm_files/simple.fsm
new file mode 100644
index 000000000..07fb0852f
--- /dev/null
+++ b/gr-trellis/src/examples/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 ijust cycles through all 4 states.
diff --git a/gr-trellis/src/examples/fsm_utils.py b/gr-trellis/src/examples/fsm_utils.py
new file mode 100755
index 000000000..1b011246c
--- /dev/null
+++ b/gr-trellis/src/examples/fsm_utils.py
@@ -0,0 +1,213 @@
+#!/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
+
+from gnuradio import trellis
+
+
+
+######################################################################
+# 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
+
+
+######################################################################
+# Generate a new FSM representing the concatenation of two FSMs
+######################################################################
+def fsm_concatenate(f1,f2):
+ if f1.O() > f2.I():
+ print "Not compatible FSMs\n"
+ I=f1.I()
+ S=f1.S()*f2.S()
+ O=f2.O()
+ nsm=list([0]*I*S)
+ osm=list([0]*I*S)
+ for s1 in range(f1.S()):
+ for s2 in range(f2.S()):
+ for i in range(f1.I()):
+ ns1=f1.NS()[s1*f1.I()+i]
+ o1=f1.OS()[s1*f1.I()+i]
+ ns2=f2.NS()[s2*f2.I()+o1]
+ o2=f2.OS()[s2*f2.I()+o1]
+
+ s=s1*f2.S()+s2
+ ns=ns1*f2.S()+ns2
+ nsm[s*I+i]=ns
+ osm[s*I+i]=o2
+
+
+ f=trellis.fsm(I,S,O,nsm,osm)
+ return f
+
+######################################################################
+# Generate a new FSM representing n stages through the original FSM
+######################################################################
+def fsm_radix(f,n):
+ I=f.I()**n
+ S=f.S()
+ O=f.O()**n
+ nsm=list([0]*I*S)
+ osm=list([0]*I*S)
+ for s in range(f.S()):
+ for i in range(I):
+ ii=dec2base(i,f.I(),n)
+ oo=list([0]*n)
+ ns=s
+ for k in range(n):
+ oo[k]=f.OS()[ns*f.I()+ii[k]]
+ ns=f.NS()[ns*f.I()+ii[k]]
+
+ nsm[s*I+i]=ns
+ osm[s*I+i]=base2dec(oo,f.O())
+
+
+ f=trellis.fsm(I,S,O,nsm,osm)
+ return f
+
+
+
+
+######################################################################
+# 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)
+
+
+
+
+
+
+######################################################################
+# 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)
+
diff --git a/gr-trellis/src/examples/test_sccc_hard.py b/gr-trellis/src/examples/test_sccc_hard.py
new file mode 100755
index 000000000..d634282fe
--- /dev/null
+++ b/gr-trellis/src/examples/test_sccc_hard.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
+ fg = gr.flow_graph ()
+
+
+ # 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,trellis.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],trellis.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()
+
+ fg.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
+ fg.connect (mod,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,metrics_in)
+ fg.connect (metrics_in,va_in,deinter,metrics_out,va_out,fsmi2s,dst)
+
+ fg.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/test_sccc_soft.py b/gr-trellis/src/examples/test_sccc_soft.py
new file mode 100755
index 000000000..23e6553ca
--- /dev/null
+++ b/gr-trellis/src/examples/test_sccc_soft.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+
+
+
+def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
+ fg = gr.flow_graph ()
+
+
+ # 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,trellis.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()
+
+ fg.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
+ fg.connect (mod,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,metrics_in)
+ fg.connect (gnd,(siso_in,0))
+ fg.connect (metrics_in,(siso_in,1))
+ fg.connect (siso_in,deinter,va_out,fsmi2s,dst)
+
+ fg.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/test_sccc_turbo.py b/gr-trellis/src/examples/test_sccc_turbo.py
new file mode 100755
index 000000000..f67fb0922
--- /dev/null
+++ b/gr-trellis/src/examples/test_sccc_turbo.py
@@ -0,0 +1,143 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+
+
+def make_rx(fg,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,type):
+ metrics_in = trellis.metrics_f(fi.O(),dimensionality,constellation,trellis.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
+ fg.connect (gnd,inter[0])
+ fg.connect (metrics_in,scale)
+ fg.connect (scale,(siso_in[0],1))
+
+ # connect the rest
+ for it in range(IT):
+ if it < IT-1:
+ fg.connect (metrics_in,(siso_in[it+1],1))
+ fg.connect (siso_in[it],deinter[it],(siso_out[it],1))
+ fg.connect (gnd,(siso_out[it],0))
+ fg.connect (siso_out[it],inter[it+1])
+ fg.connect (inter[it],(siso_in[it],0))
+ else:
+ fg.connect (siso_in[it],deinter[it],siso_out[it])
+ fg.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):
+ fg = gr.flow_graph ()
+
+
+ # 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(fg,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM)
+ #(head,tail) = make_rx(fg,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()
+
+ fg.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
+ fg.connect (mod,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,head)
+ fg.connect (tail,fsmi2s,dst)
+
+ fg.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 == 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
+ 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,constellation,Es,N0,IT,-long(666+i)) # run experiment with different seed to get different noise realizations
+ tot_s=tot_s+s
+ terr_s=terr_s+e
+ terr_p=terr_p+(terr_s!=0)
+ if ((i+1)%10==0): # display progress
+ print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s)
+ # estimate of the (short or bit) error rate
+ print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_s,terr_s, '%.2e' % ((1.0*terr_s)/tot_s)
+
+
+if __name__ == '__main__':
+ main (sys.argv[1:])
diff --git a/gr-trellis/src/examples/test_tcm.py b/gr-trellis/src/examples/test_tcm.py
new file mode 100755
index 000000000..f22501558
--- /dev/null
+++ b/gr-trellis/src/examples/test_tcm.py
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
+ fg = gr.flow_graph ()
+
+
+ # TX
+ #packet = [0]*Kb
+ #for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0
+ #packet[i] = random.randint(0, 1) # random 0s and 1s
+ #src = gr.vector_source_s(packet,False)
+ src = gr.lfsr_32k_source_s()
+ src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts
+ #b2s = gr.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts
+ s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
+ enc = trellis.encoder_ss(f,0) # initial state = 0
+ mod = gr.chunks_to_symbols_sf(constellation,dimensionality)
+
+ # CHANNEL
+ add = gr.add_ff()
+ noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)
+
+ # RX
+ metrics = trellis.metrics_f(f.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
+ va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
+ fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
+ #s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits
+ #dst = gr.vector_sink_s();
+ dst = gr.check_lfsr_32k_s()
+
+
+ fg.connect (src,src_head,s2fsmi,enc,mod)
+ #fg.connect (src,b2s,s2fsmi,enc,mod)
+ fg.connect (mod,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,metrics)
+ fg.connect (metrics,va,fsmi2s,dst)
+ #fg.connect (metrics,va,fsmi2s,s2b,dst)
+
+
+ fg.run()
+
+ # A bit of cheating: run the program once and print the
+ # final encoder state..
+ # Then put it as the last argument in the viterbi block
+ #print "final state = " , enc.ST()
+
+ ntotal = dst.ntotal ()
+ nright = dst.nright ()
+ runlength = dst.runlength ()
+ #ntotal = len(packet)
+ #if len(dst.data()) != ntotal:
+ #print "Error: not enough data\n"
+ #nright = 0;
+ #for i in range(ntotal):
+ #if packet[i]==dst.data()[i]:
+ #nright=nright+1
+ #else:
+ #print "Error in ", i
+ return (ntotal,ntotal-nright)
+
+
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 3:
+ fname=args[0]
+ esn0_db=float(args[1]) # Es/No in dB
+ rep=int(args[2]) # number of times the experiment is run to collect enough errors
+ else:
+ sys.stderr.write ('usage: test_tcm.py fsm_fname Es/No_db repetitions\n')
+ sys.exit (1)
+
+ # 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)%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/test_tcm1.py b/gr-trellis/src/examples/test_tcm1.py
new file mode 100755
index 000000000..66d7131e3
--- /dev/null
+++ b/gr-trellis/src/examples/test_tcm1.py
@@ -0,0 +1,121 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
+ fg = gr.flow_graph ()
+
+ # TX
+ packet = [0]*Kb
+ # 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,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
+ va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
+ fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
+ s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits
+ dst = gr.vector_sink_s();
+ #dst = gr.check_lfsr_32k_s();
+
+
+ #fg.connect (src,src_head,s2fsmi,enc,mod)
+ fg.connect (src,b2s,s2fsmi,enc,mod)
+ fg.connect (mod,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,metrics)
+ #fg.connect (metrics,va,fsmi2s,dst)
+ fg.connect (metrics,va,fsmi2s,s2b,dst)
+
+
+ fg.run()
+
+ # A bit of cheating: run the program once and print the
+ # final encoder state..
+ # Then put it as the last argument in the viterbi block
+ #print "final state = " , enc.ST()
+
+ #ntotal = dst.ntotal ()
+ #nright = dst.nright ()
+ #runlength = dst.runlength ()
+ ntotal = len(packet)
+ if len(dst.data()) != ntotal:
+ print "Error: not enough data\n"
+ nright = 0;
+ # 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(args):
+ nargs = len (args)
+ if nargs == 3:
+ fname=args[0]
+ esn0_db=float(args[1]) # Es/No in dB
+ rep=int(args[2]) # number of times the experiment is run to collect enough errors
+ else:
+ sys.stderr.write ('usage: test_tcm.py fsm_fname Es/No_db repetitions\n')
+ sys.exit (1)
+
+ # 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); # 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 (sys.argv[1:])
diff --git a/gr-trellis/src/examples/test_tcm2.py b/gr-trellis/src/examples/test_tcm2.py
new file mode 100755
index 000000000..9680909ea
--- /dev/null
+++ b/gr-trellis/src/examples/test_tcm2.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
+ fg = gr.flow_graph ()
+
+
+ # TX
+ #packet = [0]*Kb
+ #for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0
+ #packet[i] = random.randint(0, 1) # random 0s and 1s
+ #src = gr.vector_source_s(packet,False)
+ src = gr.lfsr_32k_source_s()
+ src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts
+ #b2s = gr.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts
+ s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
+ enc = trellis.encoder_ss(f,0) # initial state = 0
+ mod = gr.chunks_to_symbols_sf(constellation,dimensionality)
+
+ # CHANNEL
+ add = gr.add_ff()
+ noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)
+
+ # RX
+ metrics = trellis.metrics_f(f.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
+ va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
+ fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
+ #s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits
+ #dst = gr.vector_sink_s();
+ dst = gr.check_lfsr_32k_s()
+
+
+ fg.connect (src,src_head,s2fsmi,enc,mod)
+ #fg.connect (src,b2s,s2fsmi,enc,mod)
+ fg.connect (mod,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,metrics)
+ fg.connect (metrics,va,fsmi2s,dst)
+ #fg.connect (metrics,va,fsmi2s,s2b,dst)
+
+
+ fg.run()
+
+ # A bit of cheating: run the program once and print the
+ # final encoder state..
+ # Then put it as the last argument in the viterbi block
+ #print "final state = " , enc.ST()
+
+ ntotal = dst.ntotal ()
+ nright = dst.nright ()
+ runlength = dst.runlength ()
+ #ntotal = len(packet)
+ #if len(dst.data()) != ntotal:
+ #print "Error: not enough data\n"
+ #nright = 0;
+ #for i in range(ntotal):
+ #if packet[i]==dst.data()[i]:
+ #nright=nright+1
+ #else:
+ #print "Error in ", i
+ return (ntotal,ntotal-nright)
+
+
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 2:
+ esn0_db=float(args[0]) # Es/No in dB
+ rep=int(args[1]) # number of times the experiment is run to collect enough errors
+ else:
+ sys.stderr.write ('usage: test_tcm2.py Es/No_db repetitions\n')
+ sys.exit (1)
+
+ # system parameters
+ f=trellis.fsm(1,2,[5,7]) # generate FSM specification from the generator matrix
+ Kb=1024*16 # packet size in bits (make it multiple of 16 so it can be packed in a short)
+ bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol
+ K=Kb/bitspersymbol # packet size in trellis steps
+ modulation = fsm_utils.psk4 # see fsm_utlis.py for available predefined modulations
+ dimensionality = modulation[0]
+ constellation = modulation[1]
+ if len(constellation)/dimensionality != f.O():
+ sys.stderr.write ('Incompatible FSM output cardinality and modulation size.\n')
+ sys.exit (1)
+ # calculate average symbol energy
+ Es = 0
+ for i in range(len(constellation)):
+ Es = Es + constellation[i]**2
+ Es = Es / (len(constellation)/dimensionality)
+ N0=Es/pow(10.0,esn0_db/10.0); # calculate noise variance
+
+ tot_s=0 # total number of transmitted shorts
+ terr_s=0 # total number of shorts in error
+ 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 (sys.argv[1:])
diff --git a/gr-trellis/src/examples/test_tcm_combined.py b/gr-trellis/src/examples/test_tcm_combined.py
new file mode 100755
index 000000000..92e020bea
--- /dev/null
+++ b/gr-trellis/src/examples/test_tcm_combined.py
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import fsm_utils
+
+def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
+ fg = gr.flow_graph ()
+
+ # 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,trellis.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();
+
+
+ fg.connect (src,src_head,s2fsmi,enc,mod)
+ fg.connect (mod,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,va,fsmi2s,dst)
+
+
+ fg.run()
+
+ # A bit of cheating: run the program once and print the
+ # final encoder state..
+ # Then put it as the last argument in the viterbi block
+ #print "final state = " , enc.ST()
+
+ ntotal = dst.ntotal ()
+ nright = dst.nright ()
+ runlength = dst.runlength ()
+
+ return (ntotal,ntotal-nright)
+
+
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 3:
+ fname=args[0]
+ esn0_db=float(args[1]) # Es/No in dB
+ rep=int(args[2]) # number of times the experiment is run to collect enough errors
+ else:
+ sys.stderr.write ('usage: test_tcm_combined.py fsm_fname Es/No_db repetitions\n')
+ sys.exit (1)
+
+ # 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 (sys.argv[1:])
+
diff --git a/gr-trellis/src/examples/test_tcm_parallel.py b/gr-trellis/src/examples/test_tcm_parallel.py
new file mode 100755
index 000000000..f9dcb5852
--- /dev/null
+++ b/gr-trellis/src/examples/test_tcm_parallel.py
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import fsm_utils
+
+def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P):
+ fg = gr.flow_graph ()
+
+ # 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,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
+ va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
+ p2s = gr.streams_to_stream(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()
+
+ fg.connect (src,src_head,s2fsmi,s2p)
+ for i in range(P):
+ fg.connect ((s2p,i),(enc,i),(mod,i))
+ fg.connect ((mod,i),(add[i],0))
+ fg.connect (noise[i],(add[i],1))
+ fg.connect (add[i],(metrics,i))
+ fg.connect ((metrics,i),(va,i),(p2s,i))
+ fg.connect (p2s,fsmi2s,dst)
+
+
+ fg.run()
+
+ # A bit of cheating: run the program once and print the
+ # final encoder state.
+ # Then put it as the last argument in the viterbi block
+ #print "final state = " , enc.ST()
+
+ ntotal = dst.ntotal ()
+ nright = dst.nright ()
+ runlength = dst.runlength ()
+
+ return (ntotal,ntotal-nright)
+
+
+
+def main(args):
+ nargs = len (args)
+ if nargs == 3:
+ fname=args[0]
+ esn0_db=float(args[1]) # Es/No in dB
+ rep=int(args[2]) # number of times the experiment is run to collect enough errors
+ else:
+ sys.stderr.write ('usage: test_tcm.py fsm_fname Es/No_db repetitions\n')
+ sys.exit (1)
+
+ # 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 (sys.argv[1:])
+
diff --git a/gr-trellis/src/examples/test_turbo_equalization.py b/gr-trellis/src/examples/test_turbo_equalization.py
new file mode 100755
index 000000000..ff0497e2b
--- /dev/null
+++ b/gr-trellis/src/examples/test_turbo_equalization.py
@@ -0,0 +1,143 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import fsm_utils
+
+
+def make_rx(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,type):
+ metrics_in = trellis.metrics_f(fi.O(),dimensionality,tot_constellation,trellis.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
+ fg.connect (gnd,inter[0])
+ fg.connect (metrics_in,scale)
+ fg.connect (scale,(siso_in[0],1))
+
+ # connect the rest
+ for it in range(IT):
+ if it < IT-1:
+ fg.connect (metrics_in,(siso_in[it+1],1))
+ fg.connect (siso_in[it],deinter[it],(siso_out[it],1))
+ fg.connect (gnd,(siso_out[it],0))
+ fg.connect (siso_out[it],inter[it+1])
+ fg.connect (inter[it],(siso_in[it],0))
+ else:
+ fg.connect (siso_in[it],deinter[it],siso_out[it])
+ fg.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):
+ fg = gr.flow_graph ()
+
+ # 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(fg,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();
+
+ fg.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
+ fg.connect (mod,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,head)
+ fg.connect (tail,fsmi2s,dst)
+
+ fg.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/test_turbo_equalization1.py b/gr-trellis/src/examples/test_turbo_equalization1.py
new file mode 100755
index 000000000..5afd5ba66
--- /dev/null
+++ b/gr-trellis/src/examples/test_turbo_equalization1.py
@@ -0,0 +1,147 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def make_rx(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,type):
+ metrics_in = trellis.metrics_f(fi.O(),dimensionality,tot_constellation,trellis.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
+ fg.connect (gnd,inter[0])
+ fg.connect (metrics_in,scale)
+ fg.connect (scale,(siso_in[0],1))
+
+ # connect the rest
+ for it in range(IT):
+ if it < IT-1:
+ fg.connect (scale,(siso_in[it+1],1))
+ fg.connect (siso_in[it],deinter[it],(siso_out[it],1))
+ fg.connect (gnd,(siso_out[it],0))
+ fg.connect (siso_out[it],inter[it+1])
+ fg.connect (inter[it],(siso_in[it],0))
+ else:
+ fg.connect (siso_in[it],deinter[it],siso_out[it])
+ fg.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):
+ fg = gr.flow_graph ()
+ 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(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM)
+ dst = gr.vector_sink_s();
+
+ fg.connect (src,enc_out,inter,mod)
+ fg.connect (mod,isi,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,head)
+ fg.connect (tail,dst)
+
+ fg.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/test_turbo_equalization2.py b/gr-trellis/src/examples/test_turbo_equalization2.py
new file mode 100755
index 000000000..7e252d6d1
--- /dev/null
+++ b/gr-trellis/src/examples/test_turbo_equalization2.py
@@ -0,0 +1,147 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def make_rx(fg,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,trellis.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
+ fg.connect (gnd,inter[0])
+ fg.connect (scale,(siso_in[0],1))
+
+ # connect the rest
+ for it in range(IT):
+ if it < IT-1:
+ fg.connect (scale,(siso_in[it+1],1))
+ fg.connect (siso_in[it],deinter[it],(siso_out[it],1))
+ fg.connect (gnd,(siso_out[it],0))
+ fg.connect (siso_out[it],inter[it+1])
+ fg.connect (inter[it],(siso_in[it],0))
+ else:
+ fg.connect (siso_in[it],deinter[it],siso_out[it])
+ fg.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):
+ fg = gr.flow_graph ()
+ 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(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM)
+ dst = gr.vector_sink_s();
+
+ fg.connect (src,enc_out,inter,mod)
+ fg.connect (mod,isi,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,head)
+ fg.connect (tail,dst)
+
+ fg.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/test_viterbi_equalization.py b/gr-trellis/src/examples/test_viterbi_equalization.py
new file mode 100755
index 000000000..24545e3b0
--- /dev/null
+++ b/gr-trellis/src/examples/test_viterbi_equalization.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import fsm_utils
+
+def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,seed):
+ fg = gr.flow_graph ()
+
+ # 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,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
+ va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
+ fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
+ dst = gr.check_lfsr_32k_s();
+
+ fg.connect (src,src_head,s2fsmi,enc,mod)
+ fg.connect (mod,(add,0))
+ fg.connect (noise,(add,1))
+ fg.connect (add,metrics)
+ fg.connect (metrics,va,fsmi2s,dst)
+
+ fg.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/test_viterbi_equalization1.py b/gr-trellis/src/examples/test_viterbi_equalization1.py
new file mode 100755
index 000000000..002d41a76
--- /dev/null
+++ b/gr-trellis/src/examples/test_viterbi_equalization1.py
@@ -0,0 +1,103 @@
+#!/usr/bin/env python
+
+from gnuradio import gr
+from gnuradio import audio
+from gnuradio import trellis
+from gnuradio import eng_notation
+import math
+import sys
+import random
+import fsm_utils
+
+def run_test (f,Kb,bitspersymbol,K,channel,modulation,dimensionality,tot_constellation,N0,seed):
+ fg = gr.flow_graph ()
+ 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,trellis.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,trellis.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()
+
+ fg.connect (src,mod)
+ fg.connect (mod,isi,(add,0))
+ fg.connect (noise,(add,1))
+ #fg.connect (add,metrics)
+ #fg.connect (metrics,va,dst)
+ fg.connect (add,skip,va,dst)
+
+ fg.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:])