diff options
author | Achilleas Anastasopoulos <anastas@umich.edu> | 2014-10-01 18:22:53 -0400 |
---|---|---|
committer | Achilleas Anastasopoulos <anastas@umich.edu> | 2014-10-08 12:46:21 -0400 |
commit | be8e888f80934a884287f0ec9eb62dd0d2b7f5e5 (patch) | |
tree | dc3406eb0a25bb3171458bfded74cfe192a775a5 /gr-trellis/examples/python | |
parent | 46e9dfed237990da20b5fb054b7fd33b1c152b4a (diff) |
Updated documentation and grc/python examples in gr-trellis.
Removed weird pyhton examples and made them grc files.
Diffstat (limited to 'gr-trellis/examples/python')
33 files changed, 755 insertions, 2022 deletions
diff --git a/gr-trellis/examples/python/CMakeLists.txt b/gr-trellis/examples/python/CMakeLists.txt index e2c7e70ff7..0e27a9540d 100644 --- a/gr-trellis/examples/python/CMakeLists.txt +++ b/gr-trellis/examples/python/CMakeLists.txt @@ -21,18 +21,8 @@ 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 + test_cpm.py DESTINATION ${GR_PKG_TRELLIS_EXAMPLES_DIR} COMPONENT "trellis_examples" ) @@ -50,15 +40,29 @@ install( fsm_files/awgn1o2_4.fsm fsm_files/awgn1o2_8.fsm fsm_files/awgn2o3_16.fsm + fsm_files/awgn2o3_16ungerboecka.fsm + fsm_files/awgn2o3_16ungerboeck.fsm + fsm_files/awgn2o3_32ungerboecka.fsm + fsm_files/awgn2o3_32ungerboeck.fsm fsm_files/awgn2o3_4.fsm fsm_files/awgn2o3_4_msb.fsm fsm_files/awgn2o3_4_msbG.fsm + fsm_files/awgn2o3_4ungerboecka.fsm + fsm_files/awgn2o3_4ungerboeck.fsm + fsm_files/awgn2o3_64ungerboecka.fsm + fsm_files/awgn2o3_64ungerboeck.fsm fsm_files/awgn2o3_8.fsm + fsm_files/awgn2o3_8ungerboecka.fsm + fsm_files/awgn2o3_8ungerboeck.fsm fsm_files/awgn2o4_4.fsm fsm_files/disconnected.fsm + fsm_files/irregular.fsm + fsm_files/joint_16_16.fsm + fsm_files/joint_4_16.fsm fsm_files/rep3.fsm fsm_files/rep5.fsm fsm_files/simple.fsm + fsm_files/uncoded4.fsm DESTINATION ${GR_PKG_TRELLIS_EXAMPLES_DIR}/fsm_files COMPONENT "trellis_examples" ) diff --git a/gr-trellis/examples/python/README b/gr-trellis/examples/python/README index 155b0a9416..8b4e0f0abb 100644 --- a/gr-trellis/examples/python/README +++ b/gr-trellis/examples/python/README @@ -2,8 +2,6 @@ Here we have several test programs for use with the gr-trellis implementation. Documentation can be found in http://gnuradio.org/doc/doxygen/group__trellis__coding__blk.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; @@ -26,10 +24,12 @@ 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 +number of transmitted symbols, or bits, depending on the specific program +number of symbols, or bits in error +estimated 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 + +There is a similar example in the ../grc/ directory diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_16ungerboeck.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_16ungerboeck.fsm new file mode 100644 index 0000000000..70ead4f17a --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_16ungerboeck.fsm @@ -0,0 +1,50 @@ +4 16 8
+
+0 1 2 3
+4 5 6 7
+8 9 10 11
+12 13 14 15
+0 1 2 3
+4 5 6 7
+8 9 10 11
+12 13 14 15
+0 1 2 3
+4 5 6 7
+8 9 10 11
+12 13 14 15
+0 1 2 3
+4 5 6 7
+8 9 10 11
+12 13 14 15
+
+
+0 4 2 6
+1 5 3 7
+4 0 6 2
+5 1 7 3
+2 6 0 4
+3 7 1 5
+6 2 4 0
+7 3 5 1
+4 0 6 2
+5 1 7 3
+0 4 2 6
+1 5 3 7
+6 2 4 0
+7 3 5 1
+2 6 0 4
+3 7 1 5
+
+This is the rate 2/3 Ungerboeck code with 16 states for 8-PSK (natural mapping).
+The states are defined in Ungerboeck's way.
+
+d_free^2 = 2.274^2 Es --> 7.13 dB (so gain of 4.13 dB over uncoded QPSK)
+
+Parity check matrix in octal: [16 04 23]
+
+Generator Matrix:
+
+[ D 1+D+D^2 0
+ 1+D^2 D^2 D]
+
+
diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_16ungerboecka.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_16ungerboecka.fsm new file mode 100644 index 0000000000..523384362f --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_16ungerboecka.fsm @@ -0,0 +1,48 @@ +4 16 8
+
+0 8 2 10
+0 8 2 10
+1 9 3 11
+1 9 3 11
+0 8 2 10
+0 8 2 10
+1 9 3 11
+1 9 3 11
+4 12 6 14
+4 12 6 14
+5 13 7 15
+5 13 7 15
+4 12 6 14
+4 12 6 14
+5 13 7 15
+5 13 7 15
+
+
+0 6 2 4
+2 4 0 6
+6 0 4 2
+4 2 6 0
+4 2 6 0
+6 0 4 2
+2 4 0 6
+0 6 2 4
+1 7 3 5
+3 5 1 7
+7 1 5 3
+5 3 7 1
+5 3 7 1
+7 1 5 3
+3 5 1 7
+1 7 3 5
+
+This is the rate 2/3 Ungerboeck code with 16 states for 8-PSK (natural mapping).
+The states are defined in typical way.
+
+d_free^2 = 2.274^2Es --> 7.13 dB (so gain of 4.13 dB over uncoded QPSK)
+
+Parity check matrix in octal: [16 04 23]
+
+Generator Matrix:
+
+[ D 1+D+D^2 0
+ 1+D^2 D^2 D]
diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_32ungerboeck.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_32ungerboeck.fsm new file mode 100644 index 0000000000..a00f9c2e8d --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_32ungerboeck.fsm @@ -0,0 +1,83 @@ +4 32 8
+
+0 16 1 17
+0 16 1 17
+0 16 1 17
+0 16 1 17
+2 18 3 19
+2 18 3 19
+2 18 3 19
+2 18 3 19
+4 20 5 21
+4 20 5 21
+4 20 5 21
+4 20 5 21
+6 22 7 23
+6 22 7 23
+6 22 7 23
+6 22 7 23
+8 24 9 25
+8 24 9 25
+8 24 9 25
+8 24 9 25
+10 26 11 27
+10 26 11 27
+10 26 11 27
+10 26 11 27
+12 28 13 29
+12 28 13 29
+12 28 13 29
+12 28 13 29
+14 30 15 31
+14 30 15 31
+14 30 15 31
+14 30 15 31
+
+
+
+
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+5 1 7 3
+1 5 3 7
+7 3 5 1
+3 7 1 5
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+4 0 6 2
+0 4 2 6
+6 2 4 0
+2 6 0 4
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+4 0 6 2
+0 4 2 6
+6 2 4 0
+2 6 0 4
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+5 1 7 3
+1 5 3 7
+7 3 5 1
+3 7 1 5
+
+This is the rate 2/3 Ungerboeck code with 32 states for 8-PSK (natural mapping).
+The states are defined in typical way.
+
+d_free^2 = 2.405^2 Es --> 7.59 dB (so gain of 4.59 dB over uncoded QPSK)
+
+Parity check matrix in octal: [34 16 45]
+
+Generator Matrix:
+
+[ 1 D 0
+ D^4 D^2+1 D^3+D^2+D]
+
diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_32ungerboecka.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_32ungerboecka.fsm new file mode 100644 index 0000000000..b2e6ebdf44 --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_32ungerboecka.fsm @@ -0,0 +1,84 @@ +4 32 8
+0 16 1 17
+0 16 1 17
+0 16 1 17
+0 16 1 17
+2 18 3 19
+2 18 3 19
+2 18 3 19
+2 18 3 19
+4 20 5 21
+4 20 5 21
+4 20 5 21
+4 20 5 21
+6 22 7 23
+6 22 7 23
+6 22 7 23
+6 22 7 23
+8 24 9 25
+8 24 9 25
+8 24 9 25
+8 24 9 25
+10 26 11 27
+10 26 11 27
+10 26 11 27
+10 26 11 27
+12 28 13 29
+12 28 13 29
+12 28 13 29
+12 28 13 29
+14 30 15 31
+14 30 15 31
+14 30 15 31
+14 30 15 31
+
+
+
+
+
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+3 7 1 5
+7 3 5 1
+1 5 3 7
+5 1 7 3
+2 6 0 4
+6 2 4 0
+0 4 2 6
+4 0 6 2
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+2 6 0 4
+6 2 4 0
+0 4 2 6
+4 0 6 2
+3 7 1 5
+7 3 5 1
+1 5 3 7
+5 1 7 3
+
+This is the rate 2/3 Ungerboeck code with 32 states for 8-PSK (natural mapping).
+The states are defined in typical way.
+
+d_free^2 = 2.405^2 Es --> 7.59 dB (so gain of 4.59 dB over uncoded QPSK)
+
+Parity check matrix in octal: [34 16 45]
+
+Generator Matrix:
+
+[ 1 D 0
+ D^4+D 1 D^3+D^2+D]
+
+
diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_4_msb.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_4_msb.fsm index d834c52718..ff6e2a763b 100644 --- a/gr-trellis/examples/python/fsm_files/awgn2o3_4_msb.fsm +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_4_msb.fsm @@ -12,7 +12,7 @@ This is generated by the 1/2 AWGN code (5 7) operated twice, ie, -(xk+1 xki) [xk-1 xk-2] -> [xk+1 xki]. +(xk+1 xk) [xk-1 xk-2] -> [xk+1 xk]. 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). diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_4_msbG.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_4_msbG.fsm index 8956c53da2..54f9cbc3cc 100644 --- a/gr-trellis/examples/python/fsm_files/awgn2o3_4_msbG.fsm +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_4_msbG.fsm @@ -11,7 +11,7 @@ This is generated by the 1/2 AWGN code (5 7) operated twice, ie, -(xk+1 xki) [xk-1 xk-2] -> [xk+1 xki]. +(xk+1 xk) [xk-1 xk-2] -> [xk+1 xk]. We also puncture the first (MSB) bit and Gray map the symbols. intermediate states: @@ -45,7 +45,7 @@ and in decimal: After Gray mapping: label -> phase 0 -> 0 -1 -> 0 +1 -> 1 2 -> 7 3 -> 2 4 -> 5 diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_4ungerboeck.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_4ungerboeck.fsm new file mode 100644 index 0000000000..160f4ea30f --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_4ungerboeck.fsm @@ -0,0 +1,26 @@ +4 4 8 + +0 0 1 1 +2 2 3 3 +0 0 1 1 +2 2 3 3 + + +0 4 2 6 +1 5 3 7 +2 6 0 4 +3 7 1 5 + + + +This is the Ungerboeck code for 8-PSK (natural mapping). +The states are defined in Ungerboeck's way. + +d_free^2=4 Es -> 3.0 dB over uncoded QPSK + +Parity check matrix in octal: [0 2 5] + +Generator matrix: + +[1 0 0 + 0 1+D^2 D] diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_4ungerboecka.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_4ungerboecka.fsm new file mode 100644 index 0000000000..d9c210a0e9 --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_4ungerboecka.fsm @@ -0,0 +1,23 @@ +4 4 8 + +0 2 0 2 +0 2 0 2 +1 3 1 3 +1 3 1 3 + +0 2 4 6 +2 0 6 4 +1 3 5 7 +3 1 7 5 + +This is the rate 2/3 Ungerboeck's code with 4 states. +The states are defined in typical way. + +d_free^2=4 Es -> 3.0 dB over uncoded QPSK + +Parity check matrix in octal: [0 2 5] + +Generator matrix: + +[1 0 0 + 0 1+D^2 D] diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_64ungerboeck.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_64ungerboeck.fsm new file mode 100644 index 0000000000..62c75c31c1 --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_64ungerboeck.fsm @@ -0,0 +1,150 @@ +4 64 8
+
+
+0 32 1 33
+0 32 1 33
+0 32 1 33
+0 32 1 33
+2 34 3 35
+2 34 3 35
+2 34 3 35
+2 34 3 35
+4 36 5 37
+4 36 5 37
+4 36 5 37
+4 36 5 37
+6 38 7 39
+6 38 7 39
+6 38 7 39
+6 38 7 39
+8 40 9 41
+8 40 9 41
+8 40 9 41
+8 40 9 41
+10 42 11 43
+10 42 11 43
+10 42 11 43
+10 42 11 43
+12 44 13 45
+12 44 13 45
+12 44 13 45
+12 44 13 45
+14 46 15 47
+14 46 15 47
+14 46 15 47
+14 46 15 47
+16 48 17 49
+16 48 17 49
+16 48 17 49
+16 48 17 49
+18 50 19 51
+18 50 19 51
+18 50 19 51
+18 50 19 51
+20 52 21 53
+20 52 21 53
+20 52 21 53
+20 52 21 53
+22 54 23 55
+22 54 23 55
+22 54 23 55
+22 54 23 55
+24 56 25 57
+24 56 25 57
+24 56 25 57
+24 56 25 57
+26 58 27 59
+26 58 27 59
+26 58 27 59
+26 58 27 59
+28 60 29 61
+28 60 29 61
+28 60 29 61
+28 60 29 61
+30 62 31 63
+30 62 31 63
+30 62 31 63
+30 62 31 63
+
+
+
+
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+3 7 1 5
+7 3 5 1
+1 5 3 7
+5 1 7 3
+2 6 0 4
+6 2 4 0
+0 4 2 6
+4 0 6 2
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+2 6 0 4
+6 2 4 0
+0 4 2 6
+4 0 6 2
+3 7 1 5
+7 3 5 1
+1 5 3 7
+5 1 7 3
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+2 6 0 4
+6 2 4 0
+0 4 2 6
+4 0 6 2
+3 7 1 5
+7 3 5 1
+1 5 3 7
+5 1 7 3
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+3 7 1 5
+7 3 5 1
+1 5 3 7
+5 1 7 3
+2 6 0 4
+6 2 4 0
+0 4 2 6
+4 0 6 2
+
+
+This is the rate 2/3 Ungerboeck code with 64 states for 8-PSK (natural mapping).
+The states are defined in typical way.
+
+d_free^2 = 2.52^2 Es --> 8.01 dB (so gain of 5.01 dB over uncoded QPSK)
+
+parity check matrix in octal: [074 036 105]
+
+generator matrix:
+
+[1 D 0
+ D^5 D^2+1 D^4+D^3+D^2+D]
+
+
diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_64ungerboecka.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_64ungerboecka.fsm new file mode 100644 index 0000000000..137091f1f6 --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_64ungerboecka.fsm @@ -0,0 +1,154 @@ +4 64 8
+
+
+0 32 1 33
+0 32 1 33
+0 32 1 33
+0 32 1 33
+2 34 3 35
+2 34 3 35
+2 34 3 35
+2 34 3 35
+4 36 5 37
+4 36 5 37
+4 36 5 37
+4 36 5 37
+6 38 7 39
+6 38 7 39
+6 38 7 39
+6 38 7 39
+8 40 9 41
+8 40 9 41
+8 40 9 41
+8 40 9 41
+10 42 11 43
+10 42 11 43
+10 42 11 43
+10 42 11 43
+12 44 13 45
+12 44 13 45
+12 44 13 45
+12 44 13 45
+14 46 15 47
+14 46 15 47
+14 46 15 47
+14 46 15 47
+16 48 17 49
+16 48 17 49
+16 48 17 49
+16 48 17 49
+18 50 19 51
+18 50 19 51
+18 50 19 51
+18 50 19 51
+20 52 21 53
+20 52 21 53
+20 52 21 53
+20 52 21 53
+22 54 23 55
+22 54 23 55
+22 54 23 55
+22 54 23 55
+24 56 25 57
+24 56 25 57
+24 56 25 57
+24 56 25 57
+26 58 27 59
+26 58 27 59
+26 58 27 59
+26 58 27 59
+28 60 29 61
+28 60 29 61
+28 60 29 61
+28 60 29 61
+30 62 31 63
+30 62 31 63
+30 62 31 63
+30 62 31 63
+
+
+
+
+
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+5 1 7 3
+1 5 3 7
+7 3 5 1
+3 7 1 5
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+4 0 6 2
+0 4 2 6
+6 2 4 0
+2 6 0 4
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+4 0 6 2
+0 4 2 6
+6 2 4 0
+2 6 0 4
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+5 1 7 3
+1 5 3 7
+7 3 5 1
+3 7 1 5
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+4 0 6 2
+0 4 2 6
+6 2 4 0
+2 6 0 4
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+5 1 7 3
+1 5 3 7
+7 3 5 1
+3 7 1 5
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+5 1 7 3
+1 5 3 7
+7 3 5 1
+3 7 1 5
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+4 0 6 2
+0 4 2 6
+6 2 4 0
+2 6 0 4
+
+
+
+
+
+This is the rate 2/3 Ungerboeck code with 64 states for 8-PSK (natural mapping).
+The states are defined in typical way.
+
+d_free^2 = 2.52^2 Es --> 8.01 dB (so gain of 5.01 dB over uncoded QPSK)
+
+parity check matrix in octal: [074 036 105]
+
+generator matrix:
+
+[1 D 0
+ D^5+D 1 D^4+D^3+D^2+D]
+
+
diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_8.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_8.fsm index 34deeb68cb..6ace4f5e14 100644 --- a/gr-trellis/examples/python/fsm_files/awgn2o3_8.fsm +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_8.fsm @@ -21,5 +21,6 @@ -This is generated by the 1/2 8-state AWGN code (15 17) by puncturing the fourth bit. +This is generated by the 1/2 8-state AWGN code (15 17) by operating it twice and +puncturing the fourth bit. --> d_free=??? diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_8ungerboeck.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_8ungerboeck.fsm new file mode 100644 index 0000000000..e2f08eba25 --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_8ungerboeck.fsm @@ -0,0 +1,35 @@ +4 8 8 + +0 1 2 3 +4 5 6 7 +0 1 2 3 +4 5 6 7 +0 1 2 3 +4 5 6 7 +0 1 2 3 +4 5 6 7 + + +0 4 2 6 +1 5 3 7 +4 0 6 2 +5 1 7 3 +2 6 0 4 +3 7 1 5 +6 2 4 0 +7 3 5 1 + + + +This is the rate 2/3 Ungerboeck code with 8-states for 8-PSK (natural mapping). +The states are defined in Ungerboeck's way. + +d_free^2 = 4.585 Es --> 6.6 dB (so gain of 3.6 dB over uncoded QPSK) + +Parity check matrix in octal: [04 02 11] + +Generator Matrix: + +[ 1 D 0 + D^2 1 D] + diff --git a/gr-trellis/examples/python/fsm_files/awgn2o3_8ungerboecka.fsm b/gr-trellis/examples/python/fsm_files/awgn2o3_8ungerboecka.fsm new file mode 100644 index 0000000000..2425e6a01a --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/awgn2o3_8ungerboecka.fsm @@ -0,0 +1,32 @@ +4 8 8
+
+0 4 1 5
+0 4 1 5
+0 4 1 5
+0 4 1 5
+2 6 3 7
+2 6 3 7
+2 6 3 7
+2 6 3 7
+
+0 4 2 6
+4 0 6 2
+2 6 0 4
+6 2 4 0
+1 5 3 7
+5 1 7 3
+3 7 1 5
+7 3 5 1
+
+This is the rate 2/3 Ungerboeck code with 8-states for 8-PSK (natural mapping).
+The states are defined in typical way.
+
+d_free^2 = 4.585 Es --> 6.6 dB (so gain of 3.6 dB over uncoded QPSK)
+
+Parity check matrix in octal: [04 02 11]
+
+Generator Matrix:
+
+[ 1 D 0
+ D^2 1 D]
+
diff --git a/gr-trellis/examples/python/fsm_files/uncoded4.fsm b/gr-trellis/examples/python/fsm_files/uncoded4.fsm new file mode 100644 index 0000000000..67cb12ce8f --- /dev/null +++ b/gr-trellis/examples/python/fsm_files/uncoded4.fsm @@ -0,0 +1,7 @@ +4 1 4 + +0 0 0 0 + +0 1 2 3 + +uncoded 4-ary transmission diff --git a/gr-trellis/examples/python/fsm_utils.py b/gr-trellis/examples/python/fsm_utils.py deleted file mode 100755 index 06855ea775..0000000000 --- a/gr-trellis/examples/python/fsm_utils.py +++ /dev/null @@ -1,239 +0,0 @@ -#!/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/examples/python/test_cpm.py b/gr-trellis/examples/python/test_cpm.py index 3f5cfc4587..6fe25ec68c 100755 --- a/gr-trellis/examples/python/test_cpm.py +++ b/gr-trellis/examples/python/test_cpm.py @@ -12,8 +12,8 @@ from gnuradio import trellis, digital, filter, blocks from grc_gnuradio import blks2 as grc_blks2 import math import numpy -import fsm_utils from gnuradio import trellis +from gnuradio.trellis import fsm_utils try: from gnuradio import analog @@ -43,8 +43,9 @@ def run_test(seed,blocksize): f = trellis.fsm(P,M,L) # CPFSK signals - #p = numpy.ones(Q)/(2.0) - #q = numpy.cumsum(p)/(1.0*Q) + #p = numpy.ones(L*Q) + #q = numpy.cumsum(p) + #q = q/q[-1]/2.0; # GMSK signals BT=0.3; diff --git a/gr-trellis/examples/python/test_pccc_turbo1.py b/gr-trellis/examples/python/test_pccc_turbo1.py deleted file mode 100755 index 7104aa5039..0000000000 --- a/gr-trellis/examples/python/test_pccc_turbo1.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed): - tb = gr.top_block () - - - # TX - src = blocks.lfsr_32k_source_s() - src_head = blocks.head (gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality - #src = blocks.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 = blocks.vector_sink_s() - mod = digital.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = blocks.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/examples/python/test_sccc_hard.py b/gr-trellis/examples/python/test_sccc_hard.py deleted file mode 100755 index 83393df4dc..0000000000 --- a/gr-trellis/examples/python/test_sccc_hard.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): - tb = gr.top_block () - - - # TX - src = blocks.lfsr_32k_source_s() - src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = blocks.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/examples/python/test_sccc_soft.py b/gr-trellis/examples/python/test_sccc_soft.py deleted file mode 100755 index 25d26e0025..0000000000 --- a/gr-trellis/examples/python/test_sccc_soft.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): - tb = gr.top_block () - - - # TX - src = blocks.lfsr_32k_source_s() - src_head = blocks.head (gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = blocks.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/examples/python/test_sccc_turbo.py b/gr-trellis/examples/python/test_sccc_turbo.py deleted file mode 100755 index 08004e8a0d..0000000000 --- a/gr-trellis/examples/python/test_sccc_turbo.py +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -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 = blocks.multiply_const_ff(1.0/N0) - gnd = blocks.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 = blocks.lfsr_32k_source_s() - src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = blocks.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/examples/python/test_sccc_turbo1.py b/gr-trellis/examples/python/test_sccc_turbo1.py deleted file mode 100755 index 528a79d011..0000000000 --- a/gr-trellis/examples/python/test_sccc_turbo1.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed): - tb = gr.top_block () - - # TX - src = blocks.lfsr_32k_source_s() - src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = blocks.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/examples/python/test_sccc_turbo2.py b/gr-trellis/examples/python/test_sccc_turbo2.py deleted file mode 100755 index d7f26c4e13..0000000000 --- a/gr-trellis/examples/python/test_sccc_turbo2.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed): - tb = gr.top_block () - - # TX - src = blocks.lfsr_32k_source_s() - src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = blocks.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/examples/python/test_tcm.py b/gr-trellis/examples/python/test_tcm.py index bf9710aa1c..dfc565616e 100755 --- a/gr-trellis/examples/python/test_tcm.py +++ b/gr-trellis/examples/python/test_tcm.py @@ -6,9 +6,10 @@ from gnuradio import eng_notation import math import sys import random -import fsm_utils +from gnuradio.trellis import fsm_utils from gnuradio.eng_option import eng_option from optparse import OptionParser +import numpy try: from gnuradio import analog @@ -19,39 +20,32 @@ except ImportError: 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 = blocks.vector_source_s(packet,False) - src = blocks.lfsr_32k_source_s() - src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts - #b2s = blocks.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts + numpy.random.seed(-seed) + packet = numpy.random.randint(0,2,Kb) # create Kb random bits + packet[Kb-10:Kb]=0 + packet[0:Kb]=0 + src = blocks.vector_source_s(packet.tolist(),False) + b2s = blocks.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality) # CHANNEL add = blocks.add_ff() - noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed) + noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),long(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. + va = trellis.viterbi_combined_fs(f,K,0,0,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set. fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - #s2b = blocks.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits - #dst = blocks.vector_sink_s(); - dst = blocks.check_lfsr_32k_s() + s2b = blocks.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits + dst = blocks.vector_sink_s(); - tb.connect (src,src_head,s2fsmi,enc,mod) - #tb.connect (src,b2s,s2fsmi,enc,mod) + tb.connect (src,b2s,s2fsmi,enc,mod) tb.connect (mod,(add,0)) tb.connect (noise,(add,1)) - tb.connect (add,metrics) - tb.connect (metrics,va,fsmi2s,dst) - #tb.connect (metrics,va,fsmi2s,s2b,dst) + tb.connect (add,va,fsmi2s,s2b,dst) tb.run() @@ -61,19 +55,11 @@ def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): # 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) + if len(dst.data()) != len(packet): + print "Error: not enough data:", len(dst.data()), len(packet) + ntotal=len(packet) + nwrong = sum(abs(packet-numpy.array(dst.data()))); + return (ntotal,nwrong,abs(packet-numpy.array(dst.data()))) @@ -113,20 +99,26 @@ def main(): 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 + tot_b=0 # total number of transmitted bits + terr_b=0 # total number of bits 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) + (b,e,pattern)=run_test(f,Kb,bitspersymbol,K,dimensionality,constellation,N0,-(666+i)) # run experiment with different seed to get different noise realizations + tot_b=tot_b+b + terr_b=terr_b+e + terr_p=terr_p+(e!=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) + print i+1,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_b,terr_b, '%.2e' % ((1.0*terr_b)/tot_b) + if e!=0: + print "rep=",i, e + for k in range(Kb): + if pattern[k]!=0: + print k + # estimate of the bit error rate + print rep,terr_p, '%.2e' % ((1.0*terr_p)/(i+1)),tot_b,terr_b, '%.2e' % ((1.0*terr_b)/tot_b) if __name__ == '__main__': main() + diff --git a/gr-trellis/examples/python/test_tcm_bit.py b/gr-trellis/examples/python/test_tcm_bit.py deleted file mode 100755 index 7880f0ea53..0000000000 --- a/gr-trellis/examples/python/test_tcm_bit.py +++ /dev/null @@ -1,134 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -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 - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -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 = blocks.vector_source_s(packet,False) - #src = blocks.lfsr_32k_source_s() - #src_head = blocks.head (gr.sizeof_short,Kb/16) # packet size in shorts - b2s = blocks.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts - s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality) - - - # CHANNEL - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - s2b = blocks.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits - dst = blocks.vector_sink_s(); - #dst = blocks.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/examples/python/test_tcm_combined.py b/gr-trellis/examples/python/test_tcm_combined.py deleted file mode 100755 index 697e3cc64a..0000000000 --- a/gr-trellis/examples/python/test_tcm_combined.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -from gnuradio import eng_notation -import math -import sys -import fsm_utils -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed): - tb = gr.top_block () - - # TX - src = blocks.lfsr_32k_source_s() - src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality) - - - # CHANNEL - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = blocks.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/examples/python/test_tcm_parallel.py b/gr-trellis/examples/python/test_tcm_parallel.py deleted file mode 100755 index b30c80811f..0000000000 --- a/gr-trellis/examples/python/test_tcm_parallel.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -from gnuradio import eng_notation -import math -import sys -import fsm_utils -from gnuradio.eng_option import eng_option -from optparse import OptionParser - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P): - tb = gr.top_block () - - # TX - src = blocks.lfsr_32k_source_s() - src_head = blocks.head(gr.sizeof_short,Kb/16*P) # packet size in shorts - s2fsmi=blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality - s2p = blocks.stream_to_streams(gr.sizeof_short,P) # serial to parallel - enc = trellis.encoder_ss(f,0) # initiali state = 0 - mod = digital.chunks_to_symbols_sf(constellation,dimensionality) - - # CHANNEL - add=[] - noise=[] - for i in range(P): - add.append(blocks.add_ff()) - noise.append(analog.noise_source_f(analog.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 = blocks.streams_to_stream(gr.sizeof_short,P) # parallel to serial - fsmi2s=blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = blocks.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/examples/python/test_turbo_equalization.py b/gr-trellis/examples/python/test_turbo_equalization.py deleted file mode 100755 index b2d58a6014..0000000000 --- a/gr-trellis/examples/python/test_turbo_equalization.py +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -from gnuradio import eng_notation -import math -import sys -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -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 = blocks.multiply_const_ff(1.0/N0) - gnd = blocks.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 = blocks.lfsr_32k_source_s() - src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(tot_constellation,dimensionality) - - # CHANNEL - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = blocks.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/examples/python/test_turbo_equalization1.py b/gr-trellis/examples/python/test_turbo_equalization1.py deleted file mode 100755 index 5ff21ec757..0000000000 --- a/gr-trellis/examples/python/test_turbo_equalization1.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, filter, blocks -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -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 = blocks.multiply_const_ff(1.0/N0) - gnd = blocks.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 = blocks.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 = digital.chunks_to_symbols_sf(modulation[1],modulation[0]) - - # CHANNEL - isi = filter.fir_filter_fff(1,channel) - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.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/examples/python/test_turbo_equalization2.py b/gr-trellis/examples/python/test_turbo_equalization2.py deleted file mode 100755 index c2af9fbfca..0000000000 --- a/gr-trellis/examples/python/test_turbo_equalization2.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, filter, blocks -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -def make_rx(tb,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,type): - scale = blocks.multiply_const_ff(math.sqrt(1.0/N0)) - gnd = blocks.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 = blocks.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 = digital.chunks_to_symbols_sf(modulation[1],modulation[0]) - - # CHANNEL - isi = filter.fir_filter_fff(1,channel) - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.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/examples/python/test_viterbi_equalization.py b/gr-trellis/examples/python/test_viterbi_equalization.py deleted file mode 100755 index 987f171b2a..0000000000 --- a/gr-trellis/examples/python/test_viterbi_equalization.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, blocks -from gnuradio import eng_notation -import math -import sys -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,seed): - tb = gr.top_block () - - # TX - src = blocks.lfsr_32k_source_s() - src_head = blocks.head (gr.sizeof_short,Kb/16) # packet size in shorts - s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(tot_constellation,dimensionality) - - # CHANNEL - add = blocks.add_ff() - noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts - dst = blocks.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/examples/python/test_viterbi_equalization1.py b/gr-trellis/examples/python/test_viterbi_equalization1.py deleted file mode 100755 index baa6a27f1b..0000000000 --- a/gr-trellis/examples/python/test_viterbi_equalization1.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python - -from gnuradio import gr -from gnuradio import trellis, digital, filter, blocks -from gnuradio import eng_notation -import math -import sys -import random -import fsm_utils - -try: - from gnuradio import analog -except ImportError: - sys.stderr.write("Error: Program requires gr-analog.\n") - sys.exit(1) - -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 = blocks.vector_source_s(packet,False) - mod = digital.chunks_to_symbols_sf(modulation[1],modulation[0]) - - # CHANNEL - isi = filter.fir_filter_fff(1,channel) - add = blockss.add_ff() - noise = analog.noise_source_f(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed) - - # RX - skip = blocks.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 = blocks.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:]) |