Add some experimental routines.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7635 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Steven Franke 2017-04-19 12:16:10 +00:00
parent 02722a43fd
commit 7ef46cdbe0
5 changed files with 1282 additions and 1 deletions

View File

@ -324,6 +324,7 @@ set (wsjt_FSRCS
lib/bpdecode144.f90
lib/fsk4hf/bpdecode120.f90
lib/fsk4hf/bpdecode168.f90
lib/fsk4hf/bpdecode300.f90
lib/baddata.f90
lib/ccf2.f90
lib/ccf65.f90
@ -351,6 +352,7 @@ set (wsjt_FSRCS
lib/encode_msk144.f90
lib/fsk4hf/encode120.f90
lib/fsk4hf/encode168.f90
lib/fsk4hf/encode300.f90
lib/entail.f90
lib/ephem.f90
lib/extract.f90
@ -411,6 +413,7 @@ set (wsjt_FSRCS
lib/ldpcsim144.f90
lib/fsk4hf/ldpcsim120.f90
lib/fsk4hf/ldpcsim168.f90
lib/fsk4hf/ldpcsim300.f90
lib/ldpcsim40.f90
lib/libration.f90
lib/lorentzian.f90
@ -1100,6 +1103,9 @@ target_link_libraries (ldpcsim40 wsjt_fort wsjt_cxx)
add_executable (ldpcsim120 lib/fsk4hf/ldpcsim120.f90 wsjtx.rc)
target_link_libraries (ldpcsim120 wsjt_fort wsjt_cxx)
add_executable (ldpcsim300 lib/fsk4hf/ldpcsim300.f90 wsjtx.rc)
target_link_libraries (ldpcsim300 wsjt_fort wsjt_cxx)
add_executable (dbpsksim lib/fsk4hf/dbpsksim.f90 wsjtx.rc)
target_link_libraries (dbpsksim wsjt_fort wsjt_cxx)

703
lib/fsk4hf/bpdecode300.f90 Normal file
View File

@ -0,0 +1,703 @@
subroutine bpdecode300(llr,apmask,maxiterations,decoded,niterations,cw)
! A log-domain belief propagation decoder for the (300,60) code.
integer, parameter:: N=300, K=60, M=N-K
integer*1 codeword(N),cw(N),apmask(N)
integer colorder(N)
integer*1 decoded(K)
integer Nm(5,M) ! 4, or 5 bits per check
integer Mn(7,N) ! 2, 3, or 7 checks per bit
integer synd(M)
real tov(7,N)
real toc(5,M)
real tanhtoc(5,M)
real zn(N)
real llr(N)
real Tmn
integer nrw(M)
integer ncw(N)
data colorder/ &
0,1,2,3,4,5,6,7,8,9,10,11,123,12,13,14,15,16,17,18, &
19,20,21,22,23,24,25,138,26,145,27,28,29,30,31,32,33,34,35,36, &
37,154,38,39,40,41,42,43,44,144,46,47,48,49,50,51,52,53,143,54, &
125,56,57,58,124,59,120,140,157,160,55,60,61,62,156,162,141,64,65,153, &
181,183,66,170,67,68,69,130,70,164,71,72,73,74,75,63,76,77,135,78, &
79,80,176,169,82,83,84,167,180,85,136,158,129,166,175,142,134,146,121,165, &
88,89,192,90,45,91,92,93,182,189,94,95,96,173,81,97,98,178,122,126, &
132,99,100,152,186,193,101,102,151,103,104,172,159,168,150,190,147,148,201,107, &
205,177,108,198,197,174,127,109,185,110,202,87,199,171,179,187,139,137,106,131, &
206,194,112,149,155,113,128,184,196,86,114,203,212,195,208,105,188,161,163,191, &
200,209,214,204,115,218,133,111,207,117,213,216,211,217,116,215,219,220,210,221, &
118,222,223,225,224,228,226,229,231,227,233,119,234,235,232,230,237,239,236,238, &
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259, &
260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279, &
280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299/
data Mn/ &
1, 67, 0, 0, 0, 0, 0, &
2, 189, 0, 0, 0, 0, 0, &
3, 201, 0, 0, 0, 0, 0, &
4, 13, 0, 0, 0, 0, 0, &
5, 84, 0, 0, 0, 0, 0, &
6, 188, 0, 0, 0, 0, 0, &
7, 140, 0, 0, 0, 0, 0, &
8, 167, 0, 0, 0, 0, 0, &
9, 187, 0, 0, 0, 0, 0, &
10, 173, 0, 0, 0, 0, 0, &
11, 88, 0, 0, 0, 0, 0, &
12, 213, 0, 0, 0, 0, 0, &
14, 141, 0, 0, 0, 0, 0, &
15, 236, 0, 0, 0, 0, 0, &
16, 117, 0, 0, 0, 0, 0, &
17, 99, 0, 0, 0, 0, 0, &
18, 111, 0, 0, 0, 0, 0, &
19, 178, 0, 0, 0, 0, 0, &
20, 28, 0, 0, 0, 0, 0, &
21, 177, 0, 0, 0, 0, 0, &
22, 199, 0, 0, 0, 0, 0, &
23, 209, 0, 0, 0, 0, 0, &
24, 220, 0, 0, 0, 0, 0, &
25, 59, 0, 0, 0, 0, 0, &
26, 224, 0, 0, 0, 0, 0, &
27, 30, 0, 0, 0, 0, 0, &
29, 157, 0, 0, 0, 0, 0, &
31, 184, 0, 0, 0, 0, 0, &
32, 179, 0, 0, 0, 0, 0, &
33, 149, 0, 0, 0, 0, 0, &
34, 144, 0, 0, 0, 0, 0, &
35, 80, 0, 0, 0, 0, 0, &
36, 228, 0, 0, 0, 0, 0, &
37, 185, 0, 0, 0, 0, 0, &
38, 197, 0, 0, 0, 0, 0, &
39, 69, 0, 0, 0, 0, 0, &
40, 42, 0, 0, 0, 0, 0, &
41, 112, 0, 0, 0, 0, 0, &
43, 70, 0, 0, 0, 0, 0, &
44, 198, 0, 0, 0, 0, 0, &
45, 76, 0, 0, 0, 0, 0, &
46, 68, 0, 0, 0, 0, 0, &
47, 90, 0, 0, 0, 0, 0, &
48, 75, 0, 0, 0, 0, 0, &
49, 118, 0, 0, 0, 0, 0, &
50, 125, 0, 0, 0, 0, 0, &
51, 114, 0, 0, 0, 0, 0, &
52, 239, 0, 0, 0, 0, 0, &
53, 108, 0, 0, 0, 0, 0, &
54, 120, 0, 0, 0, 0, 0, &
55, 162, 0, 0, 0, 0, 0, &
56, 218, 0, 0, 0, 0, 0, &
57, 138, 0, 0, 0, 0, 0, &
58, 212, 0, 0, 0, 0, 0, &
60, 207, 0, 0, 0, 0, 0, &
61, 71, 0, 0, 0, 0, 0, &
62, 65, 0, 0, 0, 0, 0, &
63, 161, 0, 0, 0, 0, 0, &
64, 166, 0, 0, 0, 0, 0, &
66, 158, 0, 0, 0, 0, 0, &
72, 235, 0, 0, 0, 0, 0, &
73, 225, 0, 0, 0, 0, 0, &
74, 116, 0, 0, 0, 0, 0, &
77, 96, 0, 0, 0, 0, 0, &
78, 81, 0, 0, 0, 0, 0, &
79, 82, 0, 0, 0, 0, 0, &
83, 229, 0, 0, 0, 0, 0, &
85, 134, 0, 0, 0, 0, 0, &
86, 176, 0, 0, 0, 0, 0, &
87, 203, 0, 0, 0, 0, 0, &
89, 145, 0, 0, 0, 0, 0, &
91, 152, 0, 0, 0, 0, 0, &
92, 237, 0, 0, 0, 0, 0, &
93, 215, 0, 0, 0, 0, 0, &
94, 130, 0, 0, 0, 0, 0, &
95, 156, 0, 0, 0, 0, 0, &
97, 104, 0, 0, 0, 0, 0, &
98, 182, 0, 0, 0, 0, 0, &
100, 222, 0, 0, 0, 0, 0, &
101, 123, 0, 0, 0, 0, 0, &
102, 181, 0, 0, 0, 0, 0, &
103, 135, 0, 0, 0, 0, 0, &
105, 146, 0, 0, 0, 0, 0, &
106, 115, 0, 0, 0, 0, 0, &
107, 109, 0, 0, 0, 0, 0, &
110, 194, 0, 0, 0, 0, 0, &
113, 164, 0, 0, 0, 0, 0, &
119, 172, 0, 0, 0, 0, 0, &
121, 190, 0, 0, 0, 0, 0, &
122, 169, 0, 0, 0, 0, 0, &
124, 211, 0, 0, 0, 0, 0, &
126, 165, 0, 0, 0, 0, 0, &
127, 139, 0, 0, 0, 0, 0, &
128, 129, 0, 0, 0, 0, 0, &
131, 205, 0, 0, 0, 0, 0, &
132, 196, 0, 0, 0, 0, 0, &
133, 193, 0, 0, 0, 0, 0, &
136, 200, 0, 0, 0, 0, 0, &
137, 159, 0, 0, 0, 0, 0, &
142, 204, 0, 0, 0, 0, 0, &
143, 154, 0, 0, 0, 0, 0, &
147, 238, 0, 0, 0, 0, 0, &
148, 175, 0, 0, 0, 0, 0, &
150, 216, 0, 0, 0, 0, 0, &
151, 171, 0, 0, 0, 0, 0, &
153, 231, 0, 0, 0, 0, 0, &
155, 208, 0, 0, 0, 0, 0, &
160, 230, 0, 0, 0, 0, 0, &
163, 223, 0, 0, 0, 0, 0, &
168, 217, 0, 0, 0, 0, 0, &
170, 180, 0, 0, 0, 0, 0, &
174, 233, 0, 0, 0, 0, 0, &
183, 202, 0, 0, 0, 0, 0, &
186, 214, 0, 0, 0, 0, 0, &
191, 206, 0, 0, 0, 0, 0, &
192, 219, 0, 0, 0, 0, 0, &
195, 227, 0, 0, 0, 0, 0, &
210, 226, 0, 0, 0, 0, 0, &
221, 234, 0, 0, 0, 0, 0, &
232, 240, 0, 0, 0, 0, 0, &
1, 106, 0, 0, 0, 0, 0, &
2, 119, 0, 0, 0, 0, 0, &
3, 139, 0, 0, 0, 0, 0, &
4, 14, 0, 0, 0, 0, 0, &
5, 65, 0, 0, 0, 0, 0, &
6, 61, 0, 0, 0, 0, 0, &
7, 223, 0, 0, 0, 0, 0, &
8, 171, 0, 0, 0, 0, 0, &
9, 136, 0, 0, 0, 0, 0, &
10, 113, 0, 0, 0, 0, 0, &
11, 104, 0, 0, 0, 0, 0, &
12, 175, 0, 0, 0, 0, 0, &
13, 203, 0, 0, 0, 0, 0, &
15, 149, 0, 0, 0, 0, 0, &
16, 226, 0, 0, 0, 0, 0, &
17, 219, 0, 0, 0, 0, 0, &
18, 98, 0, 0, 0, 0, 0, &
19, 211, 0, 0, 0, 0, 0, &
20, 49, 0, 0, 0, 0, 0, &
21, 214, 0, 0, 0, 0, 0, &
22, 68, 0, 0, 0, 0, 0, &
23, 77, 0, 0, 0, 0, 0, &
24, 116, 0, 0, 0, 0, 0, &
25, 235, 0, 0, 0, 0, 0, &
26, 50, 0, 0, 0, 0, 0, &
27, 124, 0, 0, 0, 0, 0, &
28, 229, 0, 0, 0, 0, 0, &
29, 83, 0, 0, 0, 0, 0, &
30, 158, 0, 0, 0, 0, 0, &
31, 220, 0, 0, 0, 0, 0, &
32, 155, 0, 0, 0, 0, 0, &
33, 152, 0, 0, 0, 0, 0, &
34, 231, 0, 0, 0, 0, 0, &
35, 207, 0, 0, 0, 0, 0, &
36, 40, 0, 0, 0, 0, 0, &
37, 142, 0, 0, 0, 0, 0, &
38, 75, 0, 0, 0, 0, 0, &
39, 90, 167, 0, 0, 0, 0, &
41, 55, 125, 0, 0, 0, 0, &
42, 153, 196, 0, 0, 0, 0, &
43, 72, 112, 0, 0, 0, 0, &
44, 183, 233, 0, 0, 0, 0, &
45, 81, 178, 0, 0, 0, 0, &
46, 187, 230, 0, 0, 0, 0, &
47, 133, 176, 0, 0, 0, 0, &
48, 54, 186, 0, 0, 0, 0, &
51, 150, 224, 0, 0, 0, 0, &
52, 53, 190, 0, 0, 0, 0, &
56, 143, 228, 0, 0, 0, 0, &
57, 97, 197, 0, 0, 0, 0, &
58, 62, 89, 0, 0, 0, 0, &
59, 174, 194, 0, 0, 0, 0, &
60, 91, 93, 0, 0, 0, 0, &
63, 85, 96, 0, 0, 0, 0, &
64, 92, 205, 0, 0, 0, 0, &
66, 67, 164, 0, 0, 0, 0, &
69, 103, 159, 0, 0, 0, 0, &
70, 117, 122, 0, 0, 0, 0, &
71, 88, 160, 0, 0, 0, 0, &
73, 148, 180, 0, 0, 0, 0, &
74, 108, 109, 0, 0, 0, 0, &
76, 102, 151, 0, 0, 0, 0, &
78, 128, 206, 0, 0, 0, 0, &
79, 215, 239, 0, 0, 0, 0, &
80, 138, 221, 0, 0, 0, 0, &
82, 162, 195, 0, 0, 0, 0, &
84, 161, 184, 0, 0, 0, 0, &
86, 213, 218, 0, 0, 0, 0, &
87, 120, 240, 0, 0, 0, 0, &
94, 100, 157, 0, 0, 0, 0, &
95, 202, 217, 0, 0, 0, 0, &
99, 199, 201, 0, 0, 0, 0, &
101, 127, 225, 0, 0, 0, 0, &
105, 168, 185, 0, 0, 0, 0, &
107, 182, 237, 0, 0, 0, 0, &
110, 147, 208, 0, 0, 0, 0, &
111, 118, 172, 0, 0, 0, 0, &
114, 140, 165, 0, 0, 0, 0, &
115, 130, 141, 0, 0, 0, 0, &
121, 144, 173, 0, 0, 0, 0, &
123, 204, 209, 0, 0, 0, 0, &
126, 137, 188, 0, 0, 0, 0, &
129, 179, 189, 0, 0, 0, 0, &
131, 192, 210, 0, 0, 0, 0, &
132, 200, 238, 0, 0, 0, 0, &
134, 177, 191, 0, 0, 0, 0, &
135, 145, 222, 0, 0, 0, 0, &
146, 229, 236, 0, 0, 0, 0, &
154, 169, 232, 0, 0, 0, 0, &
124, 156, 163, 0, 0, 0, 0, &
166, 223, 234, 0, 0, 0, 0, &
1, 11, 170, 0, 0, 0, 0, &
3, 181, 227, 0, 0, 0, 0, &
193, 198, 220, 0, 0, 0, 0, &
10, 16, 212, 0, 0, 0, 0, &
42, 96, 216, 0, 0, 0, 0, &
2, 6, 215, 0, 0, 0, 0, &
4, 208, 219, 0, 0, 0, 0, &
5, 22, 35, 0, 0, 0, 0, &
7, 12, 20, 0, 0, 0, 0, &
8, 15, 75, 0, 0, 0, 0, &
9, 74, 83, 0, 0, 0, 0, &
13, 37, 50, 0, 0, 0, 0, &
14, 52, 86, 0, 0, 0, 0, &
17, 30, 177, 0, 0, 0, 0, &
18, 25, 97, 0, 0, 0, 0, &
19, 72, 157, 0, 0, 0, 0, &
21, 58, 116, 0, 0, 0, 0, &
23, 111, 226, 0, 0, 0, 0, &
24, 26, 180, 0, 0, 0, 0, &
27, 34, 39, 0, 0, 0, 0, &
28, 32, 161, 0, 0, 0, 0, &
29, 36, 60, 0, 0, 0, 0, &
31, 76, 154, 0, 0, 0, 0, &
33, 101, 238, 0, 0, 0, 0, &
38, 95, 162, 0, 0, 0, 0, &
40, 164, 183, 0, 0, 0, 0, &
41, 92, 196, 0, 0, 0, 0, &
43, 48, 99, 165, 190, 198, 204, &
44, 129, 138, 145, 160, 203, 237, &
45, 65, 66, 98, 127, 137, 146, &
46, 131, 149, 181, 211, 218, 224, &
47, 49, 55, 191, 194, 207, 232, &
51, 69, 106, 109, 119, 184, 217, &
53, 62, 104, 155, 166, 206, 231, &
54, 61, 63, 73, 118, 151, 163, &
56, 94, 110, 117, 185, 189, 214, &
57, 81, 91, 115, 173, 175, 227, &
59, 79, 103, 136, 171, 201, 212, &
24, 64, 77, 93, 202, 235, 236, &
67, 132, 142, 150, 156, 176, 222, &
68, 153, 159, 169, 170, 186, 221, &
70, 84, 89, 113, 174, 197, 205, &
71, 125, 130, 140, 158, 200, 210, &
8, 78, 143, 182, 192, 193, 216, &
23, 80, 82, 90, 108, 139, 228, &
85, 122, 123, 128, 141, 187, 188, &
25, 87, 100, 152, 209, 213, 234, &
88, 134, 147, 167, 172, 178, 239, &
18, 40, 102, 114, 133, 144, 179, &
4, 105, 108, 112, 148, 230, 240, &
29, 33, 50, 62, 107, 195, 199, &
3, 83, 113, 120, 126, 177, 216, &
11, 55, 116, 121, 135, 168, 225, &
1, 27, 28, 76, 187, 226, 233, &
2, 4, 7, 10, 22, 75, 222, &
5, 30, 131, 152, 156, 168, 215, &
6, 13, 19, 58, 196, 228, 229, &
9, 26, 144, 147, 158, 223, 240, &
12, 31, 66, 79, 92, 96, 155, &
14, 54, 103, 173, 202, 232, 238, &
15, 17, 37, 69, 129, 164, 209, &
16, 72, 91, 114, 163, 169, 237, &
20, 45, 89, 99, 143, 180, 208, &
21, 39, 60, 141, 171, 198, 234, &
21, 32, 52, 78, 95, 148, 199, &
34, 73, 84, 157, 200, 221, 236, &
35, 36, 63, 97, 105, 119, 220, &
38, 46, 93, 111, 136, 191, 203, &
41, 51, 151, 160, 213, 214, 231, &
42, 57, 65, 161, 167, 194, 204, &
43, 109, 162, 175, 189, 210, 212, &
44, 74, 100, 149, 170, 188, 197, &
47, 64, 88, 107, 122, 165, 211, &
48, 139, 179, 184, 218, 233, 239, &
49, 94, 106, 112, 138, 142, 205, &
53, 59, 102, 115, 134, 182, 225, &
56, 68, 101, 150, 166, 178, 207, &
61, 117, 126, 154, 195, 219, 224, &
67, 80, 118, 174, 185, 190, 235, &
70, 77, 86, 125, 153, 172, 193, &
32, 71, 87, 90, 98, 110, 135, &
41, 75, 81, 85, 124, 133, 201, &
82, 120, 128, 140, 159, 176, 183, &
22, 72, 104, 130, 146, 181, 217, &
25, 89, 96, 121, 132, 186, 230, &
118, 123, 145, 192, 196, 227, 240, &
1, 14, 35, 38, 114, 127, 192, &
7, 23, 43, 63, 116, 137, 206, &
2, 37, 52, 57, 64, 76, 120/
data Nm/ &
1, 121, 212, 265, 298, &
2, 122, 217, 266, 300, &
3, 123, 213, 263, 0, &
4, 124, 218, 261, 266, &
5, 125, 219, 267, 0, &
6, 126, 217, 268, 0, &
7, 127, 220, 266, 299, &
8, 128, 221, 255, 0, &
9, 129, 222, 269, 0, &
10, 130, 215, 266, 0, &
11, 131, 212, 264, 0, &
12, 132, 220, 270, 0, &
4, 133, 223, 268, 0, &
13, 124, 224, 271, 298, &
14, 134, 221, 272, 0, &
15, 135, 215, 273, 0, &
16, 136, 225, 272, 0, &
17, 137, 226, 260, 0, &
18, 138, 227, 268, 0, &
19, 139, 220, 274, 0, &
20, 140, 228, 275, 276, &
21, 141, 219, 266, 295, &
22, 142, 229, 256, 299, &
23, 143, 230, 250, 0, &
24, 144, 226, 258, 296, &
25, 145, 230, 269, 0, &
26, 146, 231, 265, 0, &
19, 147, 232, 265, 0, &
27, 148, 233, 262, 0, &
26, 149, 225, 267, 0, &
28, 150, 234, 270, 0, &
29, 151, 232, 276, 292, &
30, 152, 235, 262, 0, &
31, 153, 231, 277, 0, &
32, 154, 219, 278, 298, &
33, 155, 233, 278, 0, &
34, 156, 223, 272, 300, &
35, 157, 236, 279, 298, &
36, 158, 231, 275, 0, &
37, 155, 237, 260, 0, &
38, 159, 238, 280, 293, &
37, 160, 216, 281, 0, &
39, 161, 239, 282, 299, &
40, 162, 240, 283, 0, &
41, 163, 241, 274, 0, &
42, 164, 242, 279, 0, &
43, 165, 243, 284, 0, &
44, 166, 239, 285, 0, &
45, 139, 243, 286, 0, &
46, 145, 223, 262, 0, &
47, 167, 244, 280, 0, &
48, 168, 224, 276, 300, &
49, 168, 245, 287, 0, &
50, 166, 246, 271, 0, &
51, 159, 243, 264, 0, &
52, 169, 247, 288, 0, &
53, 170, 248, 281, 300, &
54, 171, 228, 268, 0, &
24, 172, 249, 287, 0, &
55, 173, 233, 275, 0, &
56, 126, 246, 289, 0, &
57, 171, 245, 262, 0, &
58, 174, 246, 278, 299, &
59, 175, 250, 284, 300, &
57, 125, 241, 281, 0, &
60, 176, 241, 270, 0, &
1, 176, 251, 290, 0, &
42, 141, 252, 288, 0, &
36, 177, 244, 272, 0, &
39, 178, 253, 291, 0, &
56, 179, 254, 292, 0, &
61, 161, 227, 273, 295, &
62, 180, 246, 277, 0, &
63, 181, 222, 283, 0, &
44, 157, 221, 266, 293, &
41, 182, 234, 265, 300, &
64, 142, 250, 291, 0, &
65, 183, 255, 276, 0, &
66, 184, 249, 270, 0, &
32, 185, 256, 290, 0, &
65, 163, 248, 293, 0, &
66, 186, 256, 294, 0, &
67, 148, 222, 263, 0, &
5, 187, 253, 277, 0, &
68, 174, 257, 293, 0, &
69, 188, 224, 291, 0, &
70, 189, 258, 292, 0, &
11, 179, 259, 284, 0, &
71, 171, 253, 274, 296, &
43, 158, 256, 292, 0, &
72, 173, 248, 273, 0, &
73, 175, 238, 270, 0, &
74, 173, 250, 279, 0, &
75, 190, 247, 286, 0, &
76, 191, 236, 276, 0, &
64, 174, 216, 270, 296, &
77, 170, 226, 278, 0, &
78, 137, 241, 292, 0, &
16, 192, 239, 274, 0, &
79, 190, 258, 283, 0, &
80, 193, 235, 288, 0, &
81, 182, 260, 287, 0, &
82, 177, 249, 271, 0, &
77, 131, 245, 295, 0, &
83, 194, 261, 278, 0, &
84, 121, 244, 286, 0, &
85, 195, 262, 284, 0, &
49, 181, 256, 261, 0, &
85, 181, 244, 282, 0, &
86, 196, 247, 292, 0, &
17, 197, 229, 279, 0, &
38, 161, 261, 286, 0, &
87, 130, 253, 263, 0, &
47, 198, 260, 273, 298, &
84, 199, 248, 287, 0, &
63, 143, 228, 264, 299, &
15, 178, 247, 289, 0, &
45, 197, 246, 290, 297, &
88, 122, 244, 278, 0, &
50, 189, 263, 294, 300, &
89, 200, 264, 296, 0, &
90, 178, 257, 284, 0, &
80, 201, 257, 297, 0, &
91, 146, 210, 293, 0, &
46, 159, 254, 291, 0, &
92, 202, 263, 289, 0, &
93, 193, 241, 298, 0, &
94, 183, 257, 294, 0, &
94, 203, 240, 272, 0, &
75, 199, 254, 295, 0, &
95, 204, 242, 267, 0, &
96, 205, 251, 296, 0, &
97, 165, 260, 293, 0, &
68, 206, 259, 287, 0, &
82, 207, 264, 292, 0, &
98, 129, 249, 279, 0, &
99, 202, 241, 299, 0, &
53, 185, 240, 286, 0, &
93, 123, 256, 285, 0, &
7, 198, 254, 294, 0, &
13, 199, 257, 275, 0, &
100, 156, 251, 286, 0, &
101, 169, 255, 274, 0, &
31, 200, 260, 269, 0, &
71, 207, 240, 297, 0, &
83, 208, 241, 295, 0, &
102, 196, 259, 269, 0, &
103, 180, 261, 276, 0, &
30, 134, 242, 283, 0, &
104, 167, 251, 288, 0, &
105, 182, 246, 280, 0, &
72, 152, 258, 267, 0, &
106, 160, 252, 291, 0, &
101, 209, 234, 289, 0, &
107, 151, 245, 270, 0, &
76, 210, 251, 267, 0, &
27, 190, 227, 277, 0, &
60, 149, 254, 269, 0, &
99, 177, 252, 294, 0, &
108, 179, 240, 280, 0, &
58, 187, 232, 281, 0, &
51, 186, 236, 282, 0, &
109, 210, 246, 273, 0, &
87, 176, 237, 272, 0, &
92, 198, 239, 284, 0, &
59, 211, 245, 288, 0, &
8, 158, 259, 281, 0, &
110, 194, 264, 267, 0, &
90, 209, 252, 273, 0, &
111, 212, 252, 283, 0, &
105, 128, 249, 275, 0, &
88, 197, 259, 291, 0, &
10, 200, 248, 271, 0, &
112, 172, 253, 290, 0, &
103, 132, 248, 282, 0, &
69, 165, 251, 294, 0, &
20, 206, 225, 263, 0, &
18, 163, 259, 288, 0, &
29, 203, 260, 285, 0, &
111, 180, 230, 274, 0, &
81, 213, 242, 295, 0, &
78, 195, 255, 287, 0, &
113, 162, 237, 294, 0, &
28, 187, 244, 285, 0, &
34, 194, 247, 290, 0, &
114, 166, 252, 296, 0, &
9, 164, 257, 265, 0, &
6, 202, 257, 283, 0, &
2, 203, 247, 282, 0, &
89, 168, 239, 290, 0, &
115, 206, 243, 279, 0, &
116, 204, 255, 297, 298, &
97, 214, 255, 291, 0, &
86, 172, 243, 281, 0, &
117, 186, 262, 289, 0, &
96, 160, 238, 268, 297, &
35, 170, 253, 283, 0, &
40, 214, 239, 275, 0, &
21, 192, 262, 276, 0, &
98, 205, 254, 277, 0, &
3, 192, 249, 293, 0, &
113, 191, 250, 271, 0, &
70, 133, 240, 279, 0, &
100, 201, 239, 281, 0, &
95, 175, 253, 286, 0, &
115, 183, 245, 299, 0, &
55, 154, 243, 288, 0, &
107, 196, 218, 274, 0, &
22, 201, 258, 272, 0, &
118, 204, 254, 282, 0, &
91, 138, 242, 284, 0, &
54, 215, 249, 282, 0, &
12, 188, 258, 280, 0, &
114, 140, 247, 280, 0, &
74, 184, 217, 267, 0, &
104, 216, 255, 263, 0, &
110, 191, 244, 295, 0, &
52, 188, 242, 285, 0, &
116, 136, 218, 289, 0, &
23, 150, 214, 278, 0, &
119, 185, 252, 277, 0, &
79, 207, 251, 266, 0, &
109, 127, 211, 269, 0, &
25, 167, 242, 289, 0, &
62, 193, 264, 287, 0, &
118, 135, 229, 265, 0, &
117, 213, 248, 297, 0, &
33, 169, 256, 268, 0, &
67, 147, 208, 268, 0, &
108, 164, 261, 296, 0, &
106, 153, 245, 280, 0, &
120, 209, 243, 271, 0, &
112, 162, 265, 285, 0, &
119, 211, 258, 275, 0, &
61, 144, 250, 290, 0, &
14, 208, 250, 277, 0, &
73, 195, 240, 273, 0, &
102, 205, 235, 271, 0, &
48, 184, 259, 285, 0, &
120, 189, 261, 269, 297/
data nrw/ &
5,5,4,5,4,4,5,4,4,4,4,4,4,5,4,4,4,4,4,4, &
5,5,5,4,5,4,4,4,4,4,4,5,4,4,5,4,5,5,4,4, &
5,4,5,4,4,4,4,4,4,4,4,5,4,4,4,4,5,4,4,4, &
4,4,5,5,4,4,4,4,4,4,4,5,4,4,5,5,4,4,4,4, &
4,4,4,4,4,4,4,4,5,4,4,4,4,4,4,5,4,4,4,4, &
4,4,4,4,4,4,4,4,4,4,4,4,4,5,4,5,4,5,4,5, &
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, &
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, &
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, &
4,4,4,4,4,4,4,4,4,4,4,5,4,4,4,5,4,4,4,4, &
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, &
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5/
data ncw/ &
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, &
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, &
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, &
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, &
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, &
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, &
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, &
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3, &
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, &
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, &
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, &
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,7,7, &
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, &
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, &
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7/
!ncw=3
toc=0
tov=0
tanhtoc=0
!write(*,*) llr
! initialize messages to checks
do j=1,M
do i=1,nrw(j)
toc(i,j)=llr((Nm(i,j)))
enddo
enddo
ncnt=0
do iter=0,maxiterations
! Update bit log likelihood ratios (tov=0 in iteration 0).
do i=1,N
if( apmask(i) .ne. 1 ) then
zn(i)=llr(i)+sum(tov(1:ncw(i),i))
else
zn(i)=llr(i)
endif
enddo
! Check to see if we have a codeword (check before we do any iteration).
cw=0
where( zn .gt. 0. ) cw=1
ncheck=0
do i=1,M
synd(i)=sum(cw(Nm(1:nrw(i),i)))
if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1
! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied'
enddo
!write(*,*) 'number of unsatisfied parity checks ',ncheck
if( ncheck .eq. 0 ) then ! we have a codeword - reorder the columns and return it
niterations=iter
codeword=cw(colorder+1)
decoded=codeword(M+1:N)
return
endif
if( iter.gt.0 ) then ! this code block implements an early stopping criterion
nd=ncheck-nclast
if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased
ncnt=0 ! reset counter
else
ncnt=ncnt+1
endif
! write(*,*) iter,ncheck,nd,ncnt
if( ncnt .ge. 5 .and. iter .ge. 15 .and. ncheck .gt. 50) then
niterations=-1
return
endif
endif
nclast=ncheck
! Send messages from bits to check nodes
do j=1,M
do i=1,nrw(j)
ibj=Nm(i,j)
toc(i,j)=zn(ibj)
! do kk=1,ncw(ibj) ! subtract off what the bit had received from the check
do kk=1,7 ! subtract off what the bit had received from the check
if( Mn(kk,ibj) .eq. j ) then
toc(i,j)=toc(i,j)-tov(kk,ibj)
endif
enddo
enddo
enddo
! send messages from check nodes to variable nodes
do i=1,M
tanhtoc(1:5,i)=tanh(-toc(1:5,i)/2)
enddo
do j=1,N
do i=1,ncw(j)
ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j
Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j)
call platanh(-Tmn,y)
! y=atanh(-Tmn)
tov(i,j)=2*y
enddo
enddo
enddo
niterations=-1
return
end subroutine bpdecode300

308
lib/fsk4hf/encode300.f90 Normal file
View File

@ -0,0 +1,308 @@
subroutine encode300(message,codeword)
! Encode an 60-bit message and return a 300-bit codeword.
! The generator matrix has dimensions (240,60).
! The code is a (300,60) irregular ldpc code with column weights:
! 52% column weight 2
! 27% column weight 3
! 21% column weight 7
! The code was generated using the PEG algorithm.
! After creating the codeword, the columns are re-ordered according to
! "colorder" to make the codeword compatible with the parity-check matrix
!
character*15 g(240)
integer*1 codeword(300)
integer colorder(300)
integer*1 gen(240,60)
integer*1 itmp(300)
integer*1 message(60)
integer*1 pchecks(240)
logical first
data first/.true./
data g/ &
"316fd3bb18bcefd", &
"a9c1c984f91244e", &
"9e04bd3d5d78d89", &
"f81617089621bd4", &
"12997ce2f44dbf4", &
"3ebddaf9b0fa1fc", &
"d0c114b0b0ef162", &
"f8c4f115f98bd92", &
"d0a79c0c5b8ca19", &
"477f6712f357b3b", &
"fa28b2444a7e66b", &
"bedcd4df8d95c64", &
"da30de73e57022c", &
"bc099bbb90fe09e", &
"cffc1e47e5708e8", &
"713d808563ca9a3", &
"70fcf1741d5d5d7", &
"32e80bc15112008", &
"804cef4df9b18ec", &
"3736881819d1033", &
"f4e37db7f9c5efe", &
"9e84b93d4d78d09", &
"2250c3518ec830a", &
"55a529a92e18021", &
"1cb80b14c9f6eae", &
"80c504b031ef926", &
"ece6636d0ac9c6d", &
"5d50a1690782cd0", &
"3d54a1fb30937a2", &
"ba8fe8006318041", &
"02917ce2fc45bf4", &
"abc1d984f95a44e", &
"fc05b4c4ab2d850", &
"467f7718f357b3b", &
"472cc094546c6b2", &
"fcdd94cf8c9cc64", &
"4dbc1647e970cc8", &
"6caa465c442aed1", &
"aead5af8b0da1be", &
"d8e1fa45a2e8431", &
"9d4dc4cc63abb7f", &
"9b2df6b48264637", &
"7335808563ca3a3", &
"36bf8d5cd93e6cc", &
"004ccf4db9b08ec", &
"90a71c8c598ca19", &
"f8c5d115f90bc92", &
"b95546c4e3f7934", &
"7d50a1690786cd0", &
"c90939921a0d7c6", &
"d0c504b030ef126", &
"ce3e6f9396fc542", &
"a0072a59f3707f5", &
"532d0a8fe3da1ea", &
"68b9e5cd7d142db", &
"fedc94df8c9dc64", &
"6da2465c448aed0", &
"3574aa19cb273c0", &
"1e54768c6bc6843", &
"691f65654498186", &
"fe2c92444a6ef6b", &
"9caad933e038cc4", &
"ad4e6f4defb28ec", &
"4f3d80947c6d2b2", &
"1caad933e0b8cc4", &
"b14fd3bf18bcafd", &
"ad091bbbb0f809e", &
"90b71c8c598da19", &
"f8c4d115f90bd92", &
"9d4dcccc63afb7f", &
"fa2c92444a6e76b", &
"1e14768c6bc6c43", &
"d1baf5aacb86087", &
"bdf762b92ee51c7", &
"caacec06ad8a90c", &
"804ccf4df9b08ec", &
"69e969f9da5cbd8", &
"814ccf4df9b086c", &
"cebe4f9796f4542", &
"491f65654499186", &
"8fbf5b9796f6d2a", &
"ce3e4f9396f4542", &
"47558560e7debc3", &
"94aadd33e038cc4", &
"a94eef4debb286e", &
"d8e5d115f91bcd2", &
"532d488fe3da0ab", &
"664e7bc4e23a80c", &
"94a2dd33a038cd4", &
"d8c5d115f91bc92", &
"0fef071eee60bd5", &
"9a89a09163c2b97", &
"0eaf071e6c60bd5", &
"bc0d1bbbb0fe0be", &
"f9babd3d12d0f31", &
"69a969f9da5c9d8", &
"6e4e7bc4e23a82c", &
"b0042659f3227f5", &
"2d51418f0f28347", &
"be0d5bbbb0da0be", &
"225003508ec8302", &
"8fbf4b9796f4d2a", &
"bead5af9b0da1be", &
"6ca2465c440aed1", &
"4fbc1e47ed708c8", &
"bd091bbbb0fc09e", &
"b0062259f3307f5", &
"a8072a59f3727f5", &
"a0062259f3707f5", &
"3c380b14c974eae", &
"30042659f3226f5", &
"48b9e4cd7d142db", &
"728bcd4b38308fb", &
"c0c504b031ef126", &
"314fd3bb18bcafd", &
"1c29148305faec1", &
"44c92a9c28ada63", &
"88e99b370aae32b", &
"695081690386ad8", &
"572d0a8de3da1ea", &
"467f6610f357b2b", &
"733d008563da1a3", &
"d1baf4aacb84087", &
"4315551d71c8ff0", &
"48bde4cd7d140db", &
"3ebd58f9b0da9fc", &
"51baf4aacb84083", &
"814e4f4de9b082c", &
"814ecf4de9b086c", &
"be0d1bbbb0fa0be", &
"4f7580947c792b3", &
"cdf2dce48c39c3b", &
"d8c5c115f91bc12", &
"a94e6f4debb28ee", &
"be2d5afbb0da1be", &
"cdd6dce48439c2b", &
"bebd5af9b0da1fe", &
"fa2892444a6e66b", &
"51bbf4aacb8c083", &
"baa73d81eebcd83", &
"79a2ce47f138cc9", &
"cc28cf198e6dbd4", &
"fcde94dfcc9cc64", &
"1016fcf59286717", &
"12917ce2fc4dbf4", &
"4fbc1647e9708c8", &
"3e382b1cc974fae", &
"d5bafdaad386087", &
"0fef473eee60bd5", &
"c0e504b031ee126", &
"8bbf5b9797f6d2a", &
"0eef071e6e60bd5", &
"1806fcf59386517", &
"fcdc94df8c9cc64", &
"141eca2bfa25656", &
"5fbc1767e9708e8", &
"5aa4c7803a6bdf1", &
"b14bd3b718bcafd", &
"3ebd5af9b0da1fc", &
"d0a7148c5b8ca09", &
"a94ecf4debb086e", &
"733d808563ca1a3", &
"fd9abd1d92d0f31", &
"bc091bbbb0fe09e", &
"d0c514b0b0ef122", &
"4f7d80947c7d2b3", &
"8b3f5b97b7f6d2a", &
"4fbc1767e9708c8", &
"cebf4f9796f4502", &
"9c76c880a864e67", &
"abc1c984f95244e", &
"795081690786ad8", &
"467f6710f357b3b", &
"1c380b14c9f4eae", &
"d5baf5aac386087", &
"bedc94df8c95c64", &
"553d0a8de2da1fa", &
"0315551d71d8ff0", &
"1c1eca2ffa25656", &
"d4bafdaad3c6087", &
"be2d5bfbb0da0be", &
"b0062659f3207f5", &
"5ffc1765e9708e8", &
"8d62e8bcd303e33", &
"cc08cf198e69bd4", &
"573d0a8de3da1fa", &
"cd56dce48639c2b", &
"472dc094546c2b2", &
"7950a16907868d8", &
"7283cf4b38308fb", &
"894ecf4de9b086e", &
"0f7580b47c792b3", &
"cfbf4b9796f4d0a", &
"3e380b14c974fae", &
"732d0085e3da1a3", &
"1816fcf59386717", &
"532d088fe3da1ab", &
"1c300b94c9fcaae", &
"d0a71c8c5b8ca19", &
"9e84bd3d5d78d09", &
"225083508ec830a", &
"f99abd1d12d0f31", &
"35f4aa19cb673c0", &
"cdd2dce48c39c2b", &
"0f7780b47c792bf", &
"0e33a5f114f5730", &
"bc05b4c4ab0d850", &
"1c300b14c9f4aae", &
"cfbc1e47ed708e8", &
"0f7180b47c392b3", &
"d8c7c115f91be12", &
"c09148adfa94e97", &
"9c66c880a844e67", &
"2226c13b73519f8", &
"cebf4b9796f4d02", &
"c0e706b031ee126", &
"6a6629715e53ce3", &
"73f9aa824e7d0b8", &
"473d80947c6c2b2", &
"1df140e0ddb5632", &
"473dc0945c6c2b2", &
"81b4d95f671971d", &
"663945ca758e2b6", &
"02ec3d98a2306fd", &
"5dadb0fa1275690", &
"4bb8aaa854948d0", &
"8359ba40886971c", &
"49cc3d2a2be2ee0", &
"bfdf13af137f318", &
"a1de773a2b1ff04", &
"8ff3945a2f465c7", &
"532d0087e3da1a3", &
"f3eaf7fa454d385", &
"a606aa5aeba07d9", &
"67f0627b0af8a53", &
"56698bed69d1c2c", &
"d5f420011fbf924", &
"2a8f86c810e2c62", &
"43cc1cf1208c206", &
"ee784c4900258de"/
data colorder/ &
0,1,2,3,4,5,6,7,8,9,10,11,123,12,13,14,15,16,17,18, &
19,20,21,22,23,24,25,138,26,145,27,28,29,30,31,32,33,34,35,36, &
37,154,38,39,40,41,42,43,44,144,46,47,48,49,50,51,52,53,143,54, &
125,56,57,58,124,59,120,140,157,160,55,60,61,62,156,162,141,64,65,153, &
181,183,66,170,67,68,69,130,70,164,71,72,73,74,75,63,76,77,135,78, &
79,80,176,169,82,83,84,167,180,85,136,158,129,166,175,142,134,146,121,165, &
88,89,192,90,45,91,92,93,182,189,94,95,96,173,81,97,98,178,122,126, &
132,99,100,152,186,193,101,102,151,103,104,172,159,168,150,190,147,148,201,107, &
205,177,108,198,197,174,127,109,185,110,202,87,199,171,179,187,139,137,106,131, &
206,194,112,149,155,113,128,184,196,86,114,203,212,195,208,105,188,161,163,191, &
200,209,214,204,115,218,133,111,207,117,213,216,211,217,116,215,219,220,210,221, &
118,222,223,225,224,228,226,229,231,227,233,119,234,235,232,230,237,239,236,238, &
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259, &
260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279, &
280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299/
save first,gen
if( first ) then ! fill the generator matrix
gen=0
do i=1,240
do j=1,15
read(g(i)(j:j),"(Z1)") istr
do jj=1, 4
icol=(j-1)*4+jj
if( btest(istr,4-jj) ) gen(i,icol)=1
enddo
enddo
enddo
first=.false.
endif
do i=1, 240
nsum=0
do j=1, 60
nsum=nsum+message(j)*gen(i,j)
enddo
pchecks(i)=mod(nsum,2)
enddo
itmp(1:240)=pchecks
itmp(241:300)=message(1:60)
codeword(colorder+1)=itmp(1:300)
return
end subroutine encode300

View File

@ -19,6 +19,7 @@ integer nerrtot(120),nerrdec(120),nmpcbad(60)
logical checksumok,fsk,bpsk
real*8, allocatable :: rxdata(:)
real, allocatable :: llr(:)
real dllr(120),llrd(120)
data colorder/ &
0,1,2,21,3,4,5,6,7,8,20,10,9,11,12,23,13,28,14,31, &
@ -158,7 +159,23 @@ do idb = -10, 24
! max_iterations is max number of belief propagation iterations
call bpdecode120(llr, apmask, max_iterations, decoded, niterations, cw)
n2err=0
do i=1,N
if( cw(i)*(2*codeword(i)-1.0) .lt. 0 ) n2err=n2err+1
enddo
!write(*,*) nerr,niterations,n2err
damp=0.75
ndither=0
if( niterations .lt. 0 ) then
do i=1, ndither
do in=1,N
dllr(in)=damp*gran()
enddo
llrd=llr+dllr
call bpdecode120(llrd, apmask, max_iterations, decoded, niterations, cw)
if( niterations .ge. 0 ) exit
enddo
endif
! If the decoder finds a valid codeword, niterations will be .ge. 0.
if( niterations .ge. 0 ) then

247
lib/fsk4hf/ldpcsim300.f90 Normal file
View File

@ -0,0 +1,247 @@
program ldpcsim300
! End to end test of the (300,60)/crc10 encoder and decoder.
use crc
use packjt
parameter(NRECENT=10)
character*12 recent_calls(NRECENT)
character*22 msg,msgsent,msgreceived
character*8 arg
integer*1, allocatable :: codeword(:), decoded(:), message(:)
integer*1, target:: i1Msg8BitBytes(9)
integer*1, target:: i1Dec8BitBytes(9)
integer*1 msgbits(60)
integer*1 apmask(300)
integer*1 cw(300)
integer*2 checksum
integer colorder(300)
integer nerrtot(300),nerrdec(300),nmpcbad(60)
logical checksumok,fsk,bpsk
real*8, allocatable :: rxdata(:)
real, allocatable :: llr(:)
real dllr(300),llrd(300)
data colorder/ &
0,1,2,3,4,5,6,7,8,9,10,11,123,12,13,14,15,16,17,18, &
19,20,21,22,23,24,25,138,26,145,27,28,29,30,31,32,33,34,35,36, &
37,154,38,39,40,41,42,43,44,144,46,47,48,49,50,51,52,53,143,54, &
125,56,57,58,124,59,120,140,157,160,55,60,61,62,156,162,141,64,65,153, &
181,183,66,170,67,68,69,130,70,164,71,72,73,74,75,63,76,77,135,78, &
79,80,176,169,82,83,84,167,180,85,136,158,129,166,175,142,134,146,121,165, &
88,89,192,90,45,91,92,93,182,189,94,95,96,173,81,97,98,178,122,126, &
132,99,100,152,186,193,101,102,151,103,104,172,159,168,150,190,147,148,201,107, &
205,177,108,198,197,174,127,109,185,110,202,87,199,171,179,187,139,137,106,131, &
206,194,112,149,155,113,128,184,196,86,114,203,212,195,208,105,188,161,163,191, &
200,209,214,204,115,218,133,111,207,117,213,216,211,217,116,215,219,220,210,221, &
118,222,223,225,224,228,226,229,231,227,233,119,234,235,232,230,237,239,236,238, &
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259, &
260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279, &
280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299/
do i=1,NRECENT
recent_calls(i)=' '
enddo
nerrtot=0
nerrdec=0
nmpcbad=0 ! Used to collect the number of errors in the message+crc part of the codeword
nargs=iargc()
if(nargs.ne.3) then
print*,'Usage: ldpcsim niter #trials s '
print*,'eg: ldpcsim 100 1000 0.84'
print*,'If s is negative, then value is ignored and sigma is calculated from SNR.'
return
endif
call getarg(1,arg)
read(arg,*) max_iterations
call getarg(2,arg)
read(arg,*) ntrials
call getarg(3,arg)
read(arg,*) s
fsk=.false.
bpsk=.true.
! don't count crc bits as data bits
N=300
K=60
! scale Eb/No for a (300,50) code
rate=real(50)/real(N)
write(*,*) "rate: ",rate
write(*,*) "niter= ",max_iterations," s= ",s
allocate ( codeword(N), decoded(K), message(K) )
allocate ( rxdata(N), llr(N) )
! The message should be packed into the first 7 bytes
i1Msg8BitBytes(1:6)=85
i1Msg8BitBytes(7)=64
! The CRC will be put into the last 2 bytes
i1Msg8BitBytes(8:9)=0
checksum = crc10 (c_loc (i1Msg8BitBytes), 9)
! For reference, the next 3 lines show how to check the CRC
i1Msg8BitBytes(8)=checksum/256
i1Msg8BitBytes(9)=iand (checksum,255)
checksumok = crc10_check(c_loc (i1Msg8BitBytes), 9)
if( checksumok ) write(*,*) 'Good checksum'
write(*,*) i1Msg8BitBytes(1:9)
mbit=0
do i=1, 7
i1=i1Msg8BitBytes(i)
do ibit=1,8
mbit=mbit+1
msgbits(mbit)=iand(1,ishft(i1,ibit-8))
enddo
enddo
i1=i1Msg8BitBytes(8) ! First 2 bits of crc10 are LSB of this byte
do ibit=1,2
msgbits(50+ibit)=iand(1,ishft(i1,ibit-2))
enddo
i1=i1Msg8BitBytes(9) ! Now shift in last 8 bits of the CRC
do ibit=1,8
msgbits(52+ibit)=iand(1,ishft(i1,ibit-8))
enddo
write(*,*) 'message'
write(*,'(9(8i1,1x))') msgbits
call encode300(msgbits,codeword)
call init_random_seed()
call sgran()
write(*,*) 'codeword'
write(*,'(38(8i1,1x))') codeword
write(*,*) "Es/N0 SNR2500 ngood nundetected nbadcrc sigma"
do idb = -14, 20
db=idb/2.0-1.0
! sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) ! to make db represent Eb/No
sigma=1/sqrt( 2*(10**(db/10.0)) ) ! db represents Es/No
ngood=0
nue=0
nbadcrc=0
nberr=0
do itrial=1, ntrials
! Create a realization of a noisy received word
do i=1,N
if( bpsk ) then
rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran()
elseif( fsk ) then
if( codeword(i) .eq. 1 ) then
r1=(1.0 + sigma*gran())**2 + (sigma*gran())**2
r2=(sigma*gran())**2 + (sigma*gran())**2
elseif( codeword(i) .eq. 0 ) then
r2=(1.0 + sigma*gran())**2 + (sigma*gran())**2
r1=(sigma*gran())**2 + (sigma*gran())**2
endif
rxdata(i)=0.35*(sqrt(r1)-sqrt(r2))
! rxdata(i)=0.35*(exp(r1)-exp(r2))
! rxdata(i)=0.12*(log(r1)-log(r2))
endif
enddo
nerr=0
do i=1,N
if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1
enddo
nerrtot(nerr)=nerrtot(nerr)+1
nberr=nberr+nerr
! Correct signal normalization is important for this decoder.
! rxav=sum(rxdata)/N
! rx2av=sum(rxdata*rxdata)/N
! rxsig=sqrt(rx2av-rxav*rxav)
! rxdata=rxdata/rxsig
! To match the metric to the channel, s should be set to the noise standard deviation.
! For now, set s to the value that optimizes decode probability near threshold.
! The s parameter can be tuned to trade a few tenth's dB of threshold for an order of
! magnitude in UER
if( s .lt. 0 ) then
ss=sigma
else
ss=s
endif
llr=2.0*rxdata/(ss*ss)
apmask=0
! max_iterations is max number of belief propagation iterations
call bpdecode300(llr, apmask, max_iterations, decoded, niterations, cw)
n2err=0
do i=1,N
if( cw(i)*(2*codeword(i)-1.0) .lt. 0 ) n2err=n2err+1
enddo
!write(*,*) nerr,niterations,n2err
damp=0.75
ndither=0
if( niterations .lt. 0 ) then
do i=1, ndither
do in=1,N
dllr(in)=damp*gran()
enddo
llrd=llr+dllr
call bpdecode120(llrd, apmask, max_iterations, decoded, niterations, cw)
if( niterations .ge. 0 ) exit
enddo
endif
! If the decoder finds a valid codeword, niterations will be .ge. 0.
if( niterations .ge. 0 ) then
! Check the CRC
do ibyte=1,6
itmp=0
do ibit=1,8
itmp=ishft(itmp,1)+iand(1,decoded((ibyte-1)*8+ibit))
enddo
i1Dec8BitBytes(ibyte)=itmp
enddo
i1Dec8BitBytes(7)=decoded(49)*128+decoded(50)*64
! Need to pack the received crc into bytes 8 and 9 for crc10_check
i1Dec8BitBytes(8)=decoded(51)*2+decoded(52)
i1Dec8BitBytes(9)=decoded(53)*128+decoded(54)*64+decoded(55)*32+decoded(56)*16
i1Dec8BitBytes(9)=i1Dec8BitBytes(9)+decoded(57)*8+decoded(58)*4+decoded(59)*2+decoded(60)*1
ncrcflag=0
if( crc10_check( c_loc( i1Dec8BitBytes ), 9 ) ) ncrcflag=1
if( ncrcflag .ne. 1 ) then
nbadcrc=nbadcrc+1
endif
nueflag=0
nerrmpc=0
do i=1,K ! find number of errors in message+crc part of codeword
if( msgbits(i) .ne. decoded(i) ) then
nueflag=1
nerrmpc=nerrmpc+1
endif
enddo
nmpcbad(nerrmpc)=nmpcbad(nerrmpc)+1 ! This histogram should inform our selection of CRC poly
if( ncrcflag .eq. 1 .and. nueflag .eq. 0 ) then
ngood=ngood+1
nerrdec(nerr)=nerrdec(nerr)+1
else if( ncrcflag .eq. 1 .and. nueflag .eq. 1 ) then
nue=nue+1;
endif
endif
enddo
snr2500=db+10*log10(1.03/2500.0)
pberr=real(nberr)/(real(ntrials*N))
write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,1x,i8,8x,f5.2,8x,e10.3)") db,snr2500,ngood,nue,nbadcrc,ss,pberr
enddo
open(unit=23,file='nerrhisto.dat',status='unknown')
do i=1,120
write(23,'(i4,2x,i10,i10,f10.2)') i,nerrdec(i),nerrtot(i),real(nerrdec(i))/real(nerrtot(i)+1e-10)
enddo
close(23)
open(unit=25,file='nmpcbad.dat',status='unknown')
do i=1,60
write(25,'(i4,2x,i10)') i,nmpcbad(i)
enddo
close(25)
end program ldpcsim300