From 37f727ac0746fd85504aa46c1f023c09b3eff33a Mon Sep 17 00:00:00 2001 From: hibby Date: Fri, 16 Feb 2018 15:17:14 +0000 Subject: New upstream version 1.8.0+repack --- lib/CQnnnCAT.txt | 39 + lib/DXped_pseudo_code.txt | 71 + lib/Fast_Modes.txt | 395 +++ lib/Makefile | 71 + lib/Makefile.jt65 | 84 + lib/Makefile.jt65_Win | 76 + lib/Makefile.jt65_osx | 74 + lib/Makefile.jt9w | 58 + lib/Makefile.jt9w_Win | 58 + lib/Makefile.msk | 71 + lib/Makefile.mskWin | 75 + lib/addit.f90 | 83 + lib/afc65b.f90 | 5 +- lib/afc9.f90 | 8 +- lib/allsim.f90 | 78 + lib/ana64.f90 | 24 + lib/ana932.f90 | 21 + lib/analytic.f90 | 72 +- lib/astro.f90 | 21 +- lib/astro0.f90 | 41 +- lib/astrosub.f90 | 69 +- lib/avecho.f90 | 116 + lib/averms.f90 | 20 + lib/avg4.f90 | 2 + lib/azdist.f90 | 26 +- lib/baddata.f90 | 6 +- lib/badmsg.f90 | 46 + lib/bpdecode144.f90 | 348 ++ lib/bpdecode40.f90 | 148 + lib/bpskmetrics.dat | 256 -- lib/calibrate.f90 | 96 + lib/ccf2.f90 | 17 +- lib/chkcall.f90 | 58 + lib/chkfft.f90 | 2 + lib/chkfft3.f90 | 17 +- lib/chkmsg.f90 | 6 +- lib/code426.f90 | 62 + lib/constants.f90 | 10 +- lib/contest72.f90 | 89 + lib/count4.f90 | 54 + lib/crc.f90 | 37 + lib/crc10.cpp | 31 + lib/crc12.cpp | 31 + lib/dcoord.f90 | 40 - lib/decjt9.f90 | 146 - lib/decode4.f90 | 112 + lib/decode65a.f90 | 151 +- lib/decode65b.f90 | 22 +- lib/decode9w.f90 | 49 + lib/decode_rs.c | 2 +- lib/decoder.f90 | 441 ++- lib/deep24.f90 | 182 - lib/deep4.f90 | 169 + lib/degrade_snr.f90 | 21 + lib/demod64a.f90 | 125 +- lib/dot.f90 | 11 - lib/downsam9.f90 | 35 +- lib/encode232.f90 | 2 +- lib/encode4.f90 | 20 + lib/encode_msk144.f90 | 111 + lib/encode_msk40.f90 | 46 + lib/ephem.f90 | 85 + lib/extract.F90 | 120 - lib/extract.f90 | 156 + lib/extract4.f90 | 130 +- lib/extractmessage144.f90 | 51 + lib/f77_wisdom.f90 | 45 - lib/fano232.f90 | 14 +- lib/fast9.f90 | 191 ++ lib/fast_decode.f90 | 97 + lib/fcal.f90 | 117 + lib/fchisq.f90 | 7 +- lib/fchisq0.f90 | 23 + lib/fchisq65.f90 | 22 +- lib/fer | 41 + lib/fer65.f90 | 195 ++ lib/fersum.f90 | 72 + lib/fil3c.f90 | 72 + lib/fil6521.f90 | 5 +- lib/filbig.f90 | 1 + lib/fillcom.f90 | 37 - lib/fitcal.f90 | 34 + lib/fix_contest_msg.f90 | 32 + lib/fixwav.f90 | 66 + lib/flat1.f90 | 10 +- lib/flat1a.f90 | 29 + lib/flat1b.f90 | 29 + lib/flat4.f90 | 55 +- lib/fmeasure.f90 | 75 + lib/fmtave.f90 | 64 + lib/foldspec9f.f90 | 30 + lib/fqso_first.f90 | 32 + lib/freqcal.f90 | 84 + lib/fsk4hf/Makefile | 50 + lib/fsk4hf/Makefile.win | 84 + lib/fsk4hf/baseline.f90 | 48 + lib/fsk4hf/bpdecode120.f90 | 306 ++ lib/fsk4hf/bpdecode168.f90 | 380 ++ lib/fsk4hf/bpdecode174.f90 | 401 +++ lib/fsk4hf/bpdecode300.f90 | 708 ++++ lib/fsk4hf/chkcrc10.f90 | 27 + lib/fsk4hf/chkcrc12.f90 | 27 + lib/fsk4hf/chkcrc12a.f90 | 24 + lib/fsk4hf/cpolyfit.f90 | 76 + lib/fsk4hf/cpolyfitw.f90 | 68 + lib/fsk4hf/dbpsksim.f90 | 241 ++ lib/fsk4hf/dopspread.f90 | 62 + lib/fsk4hf/encode120.f90 | 116 + lib/fsk4hf/encode168.f90 | 141 + lib/fsk4hf/encode174.f90 | 50 + lib/fsk4hf/encode300.f90 | 308 ++ lib/fsk4hf/extractmessage168.f90 | 48 + lib/fsk4hf/extractmessage174.f90 | 48 + lib/fsk4hf/fftw3.f90 | 64 + lib/fsk4hf/four2a.f90 | 115 + lib/fsk4hf/fsk4hf.f90 | 145 + lib/fsk4hf/fsk4sim.f90 | 185 + lib/fsk4hf/ft8_downsample.f90 | 42 + lib/fsk4hf/ft8_params.f90 | 12 + lib/fsk4hf/ft8apset.f90 | 31 + lib/fsk4hf/ft8b.f90 | 437 +++ lib/fsk4hf/ft8d.f90 | 63 + lib/fsk4hf/ft8sim.f90 | 126 + lib/fsk4hf/genbpsk.f90 | 44 + lib/fsk4hf/genfsk4.f90 | 36 + lib/fsk4hf/genfsk4hf.f90 | 51 + lib/fsk4hf/genft8.f90 | 56 + lib/fsk4hf/genft8refsig.f90 | 22 + lib/fsk4hf/genmskhf.f90 | 126 + lib/fsk4hf/genwspr5.f90 | 107 + lib/fsk4hf/genwspr_fsk8.f90 | 45 + lib/fsk4hf/genwsprlf.f90 | 137 + lib/fsk4hf/getfc1.f90 | 58 + lib/fsk4hf/getfc1w.f90 | 47 + lib/fsk4hf/getfc2.f90 | 74 + lib/fsk4hf/getfc2w.f90 | 82 + lib/fsk4hf/gran.c | 28 + lib/fsk4hf/ldpc_174_87_params.f90 | 102 + lib/fsk4hf/ldpc_300_60_params.f90 | 262 ++ lib/fsk4hf/ldpcsim120.f90 | 238 ++ lib/fsk4hf/ldpcsim168.f90 | 233 ++ lib/fsk4hf/ldpcsim174.f90 | 238 ++ lib/fsk4hf/ldpcsim300.f90 | 252 ++ lib/fsk4hf/mskhfsim.f90 | 194 ++ lib/fsk4hf/msksoftsym.f90 | 81 + lib/fsk4hf/msksoftsymw.f90 | 78 + lib/fsk4hf/osd174.f90 | 377 ++ lib/fsk4hf/osd300.f90 | 184 + lib/fsk4hf/polyfit4.f90 | 109 + lib/fsk4hf/spec4.f90 | 35 + lib/fsk4hf/spec8.f90 | 31 + lib/fsk4hf/subtractft8.f90 | 61 + lib/fsk4hf/sync8.f90 | 151 + lib/fsk4hf/sync8d.f90 | 54 + lib/fsk4hf/tweak1.f90 | 23 + lib/fsk4hf/twkfreq1.f90 | 26 + lib/fsk4hf/watterson.f90 | 62 + lib/fsk4hf/wavhdr.f90 | 110 + lib/fsk4hf/wspr5_downsample.f90 | 29 + lib/fsk4hf/wspr5_wav.f90 | 48 + lib/fsk4hf/wspr5d.f90 | 217 ++ lib/fsk4hf/wspr5d_exp.f90 | 499 +++ lib/fsk4hf/wspr5sim.f90 | 111 + lib/fsk4hf/wspr_fsk8_downsample.f90 | 27 + lib/fsk4hf/wspr_fsk8_params.f90 | 14 + lib/fsk4hf/wspr_fsk8_sim.f90 | 107 + lib/fsk4hf/wspr_fsk8_wav.f90 | 44 + lib/fsk4hf/wspr_fsk8d.f90 | 196 ++ lib/fsk4hf/wsprlf.f90 | 110 + lib/fsk4hf/wsprlf_params.f90 | 14 + lib/fsk4hf/wsprlfsim.f90 | 285 ++ lib/ft8_decode.f90 | 139 + lib/ftrsd/Makefile | 53 + lib/ftrsd/Makefile.sfrsd | 30 + lib/ftrsd/Makefile.sfrsd3 | 38 + lib/ftrsd/decode_rs.c | 268 ++ lib/ftrsd/encode_rs.c | 47 + lib/ftrsd/extract2.f90 | 145 + lib/ftrsd/ftrsd2.c | 213 ++ lib/ftrsd/ftrsd_paper/JT65B_EME.png | Bin 0 -> 35719 bytes lib/ftrsd/ftrsd_paper/Makefile | 40 + lib/ftrsd/ftrsd_paper/binomial.c | 69 + lib/ftrsd/ftrsd_paper/binomial_subs.c | 55 + lib/ftrsd/ftrsd_paper/bmdata-rf.dat | 11 + lib/ftrsd/ftrsd_paper/bmdata.dat | 8 + lib/ftrsd/ftrsd_paper/bmtheory25.dat | 43 + lib/ftrsd/ftrsd_paper/bmtheory40.dat | 43 + lib/ftrsd/ftrsd_paper/bmtheory43.dat | 43 + lib/ftrsd/ftrsd_paper/bodide.f90 | 54 + lib/ftrsd/ftrsd_paper/bodide.lab | 4 + lib/ftrsd/ftrsd_paper/fig_bodide.gnuplot | 24 + lib/ftrsd/ftrsd_paper/fig_ntrials_vs_nhard.gnuplot | 14 + lib/ftrsd/ftrsd_paper/fig_psuccess.gnuplot | 25 + lib/ftrsd/ftrsd_paper/fig_psuccess.pdf | Bin 0 -> 26687 bytes lib/ftrsd/ftrsd_paper/fig_subtracted.tiff | Bin 0 -> 512012 bytes lib/ftrsd/ftrsd_paper/fig_waterfall.png | Bin 0 -> 257654 bytes lib/ftrsd/ftrsd_paper/fig_waterfall.tiff | Bin 0 -> 538486 bytes lib/ftrsd/ftrsd_paper/fig_wer.gnuplot | 23 + lib/ftrsd/ftrsd_paper/fig_wer.pdf | Bin 0 -> 32859 bytes lib/ftrsd/ftrsd_paper/fig_wer2.gnuplot | 23 + lib/ftrsd/ftrsd_paper/fig_wer3.gnuplot | 21 + lib/ftrsd/ftrsd_paper/ftdata-10.dat | 10 + lib/ftrsd/ftrsd_paper/ftdata-100.dat | 10 + lib/ftrsd/ftrsd_paper/ftdata-1000.dat | 9 + lib/ftrsd/ftrsd_paper/ftdata-10000.dat | 11 + lib/ftrsd/ftrsd_paper/ftdata-100000.dat | 11 + lib/ftrsd/ftrsd_paper/ftrsd.lyx | 3289 ++++++++++++++++++ lib/ftrsd/ftrsd_paper/kvasd-12.dat | 8 + lib/ftrsd/ftrsd_paper/kvasd-15.dat | 9 + lib/ftrsd/ftrsd_paper/kvasd-8.dat | 8 + lib/ftrsd/ftrsd_paper/mfsk.f90 | 33 + lib/ftrsd/ftrsd_paper/prob.f90 | 41 + lib/ftrsd/ftrsd_paper/psuccess.lab | 14 + lib/ftrsd/ftrsd_paper/stats-100000-24db-3.dat | 930 +++++ lib/ftrsd/ftrsd_paper/stats_0.0 | 27 + lib/ftrsd/ftrsd_paper/stats_0.2 | 27 + lib/ftrsd/ftrsd_paper/stats_1.0 | 27 + lib/ftrsd/ftrsd_paper/wer.lab | 0 lib/ftrsd/ftrsd_paper/wer2.lab | 7 + lib/ftrsd/init_rs.c | 119 + lib/ftrsd/int.h | 54 + lib/ftrsd/rs2.h | 16 + lib/ftrsd/rsdtest.f90 | 34 + lib/ftrsd/sfrsd.c | 137 + lib/ftrsd/sfrsd2.h | 3 + lib/ftrsd/sfrsd3.c | 243 ++ lib/gen4.f90 | 43 + lib/gen65.f90 | 87 +- lib/gen9.f90 | 65 + lib/geniscat.f90 | 55 + lib/genjt9.f90 | 55 - lib/genmet.f90 | 2 + lib/genmsk144.f90 | 147 + lib/genmsk40.f90 | 66 + lib/genmsk_short.f90 | 66 + lib/genqra64.f90 | 57 + lib/genwspr.f90 | 30 + lib/geocentric.f90 | 17 - lib/geodist.f90 | 9 + lib/getmet24.f90 | 52 - lib/getmet4.f90 | 56 + lib/getpfx1.f90 | 100 - lib/getpfx2.f90 | 24 - lib/go_chkfft.cmd | 1 + lib/golay24_table.c | 28 + lib/grayline.f90 | 32 + lib/grid2k.f90 | 12 - lib/grid2n.f90 | 10 - lib/hash.f90 | 10 + lib/hashing.f90 | 10 + lib/hint65.f90 | 166 + lib/hspec.f90 | 106 + lib/image.f90 | 336 ++ lib/indexx.f90 | 98 +- lib/init_random_seed.c | 82 + lib/init_random_seed.f90 | 55 + lib/init_random_seed.h | 20 + lib/init_rs.c | 2 - lib/inter_wspr.f90 | 45 + lib/interleave24.f90 | 43 - lib/interleave4.f90 | 43 + lib/ipcomm.cpp | 10 +- lib/iscat.f90 | 206 ++ lib/iso_c_utilities.f90 | 87 + lib/jplsubs.f | 899 +++++ lib/jt4.f90 | 26 + lib/jt4_decode.f90 | 420 +++ lib/jt4a.f90 | 2 + lib/jt4code.f90 | 50 + lib/jt4sim.f90 | 181 + lib/jt65.f90 | 210 +- lib/jt65_decode.f90 | 494 +++ lib/jt65_mod.f90 | 13 + lib/jt65_test.f90 | 81 + lib/jt65a.f90 | 105 - lib/jt65code.f90 | 205 +- lib/jt65sim.f90 | 271 ++ lib/jt9.f90 | 299 +- lib/jt9_decode.f90 | 172 + lib/jt9a.f90 | 38 +- lib/jt9b.f90 | 12 - lib/jt9c.f90 | 23 - lib/jt9code.f90 | 155 +- lib/jt9com.f90 | 55 + lib/jt9fano.f90 | 9 +- lib/jt9sim.f90 | 9 +- lib/jt9w.f90 | 28 + lib/jtmsg.f90 | 131 + lib/k2grid.f90 | 12 - lib/ldpc/COPYRIGHT | 15 + lib/ldpc/LDPC-install | 28 + lib/ldpc/LGPL | 463 +++ lib/ldpc/Makefile | 115 + lib/ldpc/Makefile.msk_osx | 39 + lib/ldpc/README | 6 + lib/ldpc/alist-to-pchk.c | 168 + lib/ldpc/alloc.c | 42 + lib/ldpc/alloc.h | 18 + lib/ldpc/blockio.c | 85 + lib/ldpc/blockio.h | 19 + lib/ldpc/channel.c | 99 + lib/ldpc/channel.h | 32 + lib/ldpc/channel.html | 182 + lib/ldpc/check.c | 177 + lib/ldpc/check.h | 25 + lib/ldpc/dec.c | 420 +++ lib/ldpc/dec.h | 43 + lib/ldpc/decode-detail.html | 99 + lib/ldpc/decode.c | 384 +++ lib/ldpc/decoding.html | 342 ++ lib/ldpc/dep-H.html | 85 + lib/ldpc/distrib.c | 188 + lib/ldpc/distrib.h | 49 + lib/ldpc/enc.c | 173 + lib/ldpc/enc.h | 19 + lib/ldpc/encode.c | 195 ++ lib/ldpc/encoding.html | 283 ++ lib/ldpc/ex-dep | 60 + lib/ldpc/ex-dep-out | 224 ++ lib/ldpc/ex-ham7a | 38 + lib/ldpc/ex-ham7a-out | 33 + lib/ldpc/ex-ham7b | 21 + lib/ldpc/ex-ham7b-out | 15 + lib/ldpc/ex-ldpc-encode | 45 + lib/ldpc/ex-ldpc-encode-out | 47 + lib/ldpc/ex-ldpc36-1000a | 50 + lib/ldpc/ex-ldpc36-1000a-out | 57 + lib/ldpc/ex-ldpc36-5000a | 44 + lib/ldpc/ex-ldpc36-5000a-out | 54 + lib/ldpc/ex-ldpcvar-5000a | 46 + lib/ldpc/ex-ldpcvar-5000a-out | 54 + lib/ldpc/ex-wrong-model | 124 + lib/ldpc/ex-wrong-model-out | 163 + lib/ldpc/examples.html | 87 + lib/ldpc/extract.c | 112 + lib/ldpc/github.html | 67 + lib/ldpc/index.html | 89 + lib/ldpc/install.html | 82 + lib/ldpc/intio.c | 110 + lib/ldpc/intio.h | 17 + lib/ldpc/jtmode_codes/jtmskcode.results | 12 + lib/ldpc/jtmode_codes/peg-128-80-denev20.gen | Bin 0 -> 1817 bytes lib/ldpc/jtmode_codes/peg-128-80-denev20.pchk | Bin 0 -> 2312 bytes lib/ldpc/jtmode_codes/peg-128-80-denev7.gen | Bin 0 -> 1793 bytes lib/ldpc/jtmode_codes/peg-128-80-denev7.pchk | Bin 0 -> 1892 bytes lib/ldpc/jtmode_codes/peg-128-80-reg3.gen | Bin 0 -> 2069 bytes lib/ldpc/jtmode_codes/peg-128-80-reg3.pchk | Bin 0 -> 1744 bytes lib/ldpc/jtmode_codes/peg-128-80-reg4.gen | Bin 0 -> 2417 bytes lib/ldpc/jtmode_codes/peg-128-80-reg4.pchk | Bin 0 -> 2256 bytes lib/ldpc/jtmode_codes/peg-198-72-irreg-8x3-2x4.gen | Bin 0 -> 5821 bytes .../jtmode_codes/peg-198-72-irreg-8x3-2x4.pchk | Bin 0 -> 3052 bytes lib/ldpc/jtmode_codes/peg-198-72-reg3.gen | Bin 0 -> 5397 bytes lib/ldpc/jtmode_codes/peg-198-72-reg3.pchk | Bin 0 -> 2896 bytes lib/ldpc/jtmode_codes/peg-198-72-reg4.gen | Bin 0 -> 7305 bytes lib/ldpc/jtmode_codes/peg-198-72-reg4.pchk | Bin 0 -> 3688 bytes lib/ldpc/make-gen.c | 350 ++ lib/ldpc/make-ldpc.c | 415 +++ lib/ldpc/make-pchk.c | 93 + lib/ldpc/mod2convert-test-out | 9 + lib/ldpc/mod2convert-test.c | 80 + lib/ldpc/mod2convert.c | 83 + lib/ldpc/mod2convert.h | 18 + lib/ldpc/mod2convert.html | 51 + lib/ldpc/mod2dense-test-out | 699 ++++ lib/ldpc/mod2dense-test.c | 560 +++ lib/ldpc/mod2dense.c | 754 ++++ lib/ldpc/mod2dense.h | 113 + lib/ldpc/mod2dense.html | 487 +++ lib/ldpc/mod2sparse-test-out | 431 +++ lib/ldpc/mod2sparse-test.c | 378 ++ lib/ldpc/mod2sparse.c | 1365 ++++++++ lib/ldpc/mod2sparse.h | 147 + lib/ldpc/mod2sparse.html | 719 ++++ lib/ldpc/modify.html | 125 + lib/ldpc/modules.html | 89 + lib/ldpc/msksim.f90 | 76 + lib/ldpc/open.c | 50 + lib/ldpc/open.h | 16 + lib/ldpc/pchk-to-alist.c | 166 + lib/ldpc/pchk.html | 371 ++ lib/ldpc/peg/128-64-reg4.deg | 4 + lib/ldpc/peg/BigGirth.C | 573 ++++ lib/ldpc/peg/BigGirth.h | 54 + lib/ldpc/peg/CodeName | 68 + lib/ldpc/peg/CyclesOfGraph.C | 237 ++ lib/ldpc/peg/CyclesOfGraph.h | 40 + lib/ldpc/peg/DenEvl_11.deg | 3 + lib/ldpc/peg/DenEvl_15.deg | 3 + lib/ldpc/peg/DenEvl_20.deg | 4 + lib/ldpc/peg/DenEvl_7.deg | 3 + lib/ldpc/peg/DenEvl_9.deg | 3 + lib/ldpc/peg/MainPEG.C | 200 ++ lib/ldpc/peg/Makefile | 29 + lib/ldpc/peg/Random.C | 101 + lib/ldpc/peg/Random.h | 29 + lib/ldpc/peg/Reg_2.deg | 3 + lib/ldpc/peg/Reg_3.deg | 3 + lib/ldpc/peg/Reg_4.deg | 3 + lib/ldpc/peg/ldpc-peg-128-80.alist | 180 + lib/ldpc/peg/peg-128-64-reg4.alist | 196 ++ lib/ldpc/peg/peg-128-64-reg4.code | 67 + lib/ldpc/peg/peg-128-72-reg4.alist | 188 + lib/ldpc/peg/peg-128-72-reg4.code | 59 + lib/ldpc/peg/peg-128-80-reg3.alist | 180 + lib/ldpc/peg/peg-128-80-reg3.code | 51 + lib/ldpc/peg/peg-128-80-reg4.alist | 180 + lib/ldpc/peg/peg-128-80-reg4.code | 51 + lib/ldpc/peg/peg-144-72-reg4.alist | 220 ++ lib/ldpc/peg/peg-144-72-reg4.code | 75 + lib/ldpc/peg/peg2alist | 37 + lib/ldpc/peg/peg_128_80.pchk | 51 + lib/ldpc/peg/sfpeg1.code | 51 + lib/ldpc/peg/sfpeg1.deg | 3 + lib/ldpc/peg/sfpeg2.alist | 180 + lib/ldpc/peg/sfpeg2.code | 51 + lib/ldpc/peg/sfpeg2.deg | 3 + lib/ldpc/peg/sfpeg3.alist | 180 + lib/ldpc/peg/sfpeg3.code | 51 + lib/ldpc/peg/sfpeg3.deg | 3 + lib/ldpc/print-gen.c | 139 + lib/ldpc/print-pchk.c | 114 + lib/ldpc/progs.html | 80 + lib/ldpc/rand-src.c | 86 + lib/ldpc/rand-test.c | 266 ++ lib/ldpc/rand.c | 567 +++ lib/ldpc/rand.h | 54 + lib/ldpc/rand.html | 306 ++ lib/ldpc/randfile | Bin 0 -> 100000 bytes lib/ldpc/rcode.c | 217 ++ lib/ldpc/rcode.h | 37 + lib/ldpc/refs.html | 58 + lib/ldpc/release.html | 244 ++ lib/ldpc/run-examples | 12 + lib/ldpc/sparse-LU.html | 90 + lib/ldpc/sparse-encode.pdf | Bin 0 -> 185688 bytes lib/ldpc/support.html | 100 + lib/ldpc/transmit.c | 170 + lib/ldpc/verify.c | 254 ++ lib/ldpc32_table.c | 30 + lib/ldpcsim144.f90 | 175 + lib/ldpcsim40.f90 | 138 + lib/libration.f90 | 38 + lib/lorentzian.f90 | 102 + lib/lpf1.f90 | 29 + lib/makepings.f90 | 26 + lib/mixlpf.f90 | 25 + lib/moon2.f90 | 166 - lib/moondop.f90 | 72 - lib/moondopjpl.f90 | 43 + lib/msk144_freq_search.f90 | 50 + lib/msk144code.f90 | 70 + lib/msk144d2.f90 | 138 + lib/msk144decodeframe.f90 | 107 + lib/msk144sd.f90 | 197 ++ lib/msk144signalquality.f90 | 219 ++ lib/msk144sim.f90 | 99 + lib/msk144spd.f90 | 197 ++ lib/msk144sync.f90 | 101 + lib/msk40_freq_search.f90 | 53 + lib/msk40decodeframe.f90 | 169 + lib/msk40spd.f90 | 199 ++ lib/msk40sync.f90 | 103 + lib/mskber.f90 | 146 + lib/mskdt.f90 | 78 + lib/mskrtd.f90 | 258 ++ lib/n2grid.f90 | 14 - lib/nchar.f90 | 23 - lib/nfft.out | 3613 +++++++++----------- lib/noisegen.f90 | 3 + lib/packbits.f90 | 21 - lib/packcall.f90 | 79 - lib/packdxcc.f90 | 64 - lib/packgrid.f90 | 76 - lib/packjt.f90 | 1026 ++++++ lib/packmsg.f90 | 119 - lib/packtext.f90 | 47 - lib/pctile.f90 | 6 +- lib/peakdt9.f90 | 16 +- lib/peakup.f90 | 16 +- lib/pfx.f90 | 2 +- lib/pfxdump.f90 | 13 - lib/polfit.f90 | 72 - lib/polyfit.f90 | 72 + lib/prcom.f90 | 1 + lib/ps24.f90 | 27 - lib/ps4.f90 | 27 + lib/psk_parse.f90 | 108 + lib/qra/qra64/Makefile.Win | 30 + lib/qra/qra64/fadengauss.c | 302 ++ lib/qra/qra64/fadenlorentz.c | 304 ++ lib/qra/qra64/main.c | 746 ++++ lib/qra/qra64/qra64.c | 1121 ++++++ lib/qra/qra64/qra64.h | 269 ++ lib/qra/qra64/qra64_all.c | 1050 ++++++ lib/qra/qra64/qra64_subs.c | 65 + lib/qra/qra64/qra64example.txt | 88 + lib/qra/qra64/qra64sim.f90 | 170 + lib/qra/qracodes/Makefile.Win | 33 + lib/qra/qracodes/ebno10000.txt | 7 + lib/qra/qracodes/ebnovalues.txt | 15 + lib/qra/qracodes/ebnovaluesfast.txt | 11 + lib/qra/qracodes/main.c | 737 ++++ lib/qra/qracodes/normrnd.c | 82 + lib/qra/qracodes/normrnd.h | 51 + lib/qra/qracodes/npfwht.c | 216 ++ lib/qra/qracodes/npfwht.h | 45 + lib/qra/qracodes/pdmath.c | 385 +++ lib/qra/qracodes/pdmath.h | 85 + lib/qra/qracodes/qra12_63_64_irr_b.c | 534 +++ lib/qra/qracodes/qra12_63_64_irr_b.h | 39 + lib/qra/qracodes/qra13_64_64_irr_e.c | 534 +++ lib/qra/qracodes/qra13_64_64_irr_e.h | 39 + lib/qra/qracodes/qracodes.c | 474 +++ lib/qra/qracodes/qracodes.h | 79 + lib/qra64a.f90 | 158 + lib/qra64code.f90 | 66 + lib/qratest.f90 | 54 + lib/readwav.f90 | 71 + lib/rectify_msk.f90 | 64 + lib/refspectrum.f90 | 159 + lib/s3avg.f90 | 60 - lib/savec2.f90 | 55 + lib/setup65.f90 | 2 +- lib/sfrsd.f90 | 121 + lib/sgran.c | 7 + lib/sh65.f90 | 89 + lib/sh65snr.f90 | 36 + lib/shell.f90 | 27 + lib/slasubs.f | 3396 ++++++++++++++++++ lib/slope.f90 | 80 +- lib/smo.f90 | 10 +- lib/smolorentz.f90 | 42 + lib/softsym.f90 | 18 +- lib/softsym9f.f90 | 55 + lib/softsym9w.f90 | 126 + lib/sort.f90 | 9 + lib/spec64.f90 | 42 + lib/spec9f.f90 | 30 + lib/stats.f90 | 66 + lib/stdmsg.f90 | 20 +- lib/subtract65.f90 | 112 + lib/symspec.f90 | 62 +- lib/sync24.f90 | 179 - lib/sync4.f90 | 179 + lib/sync64.f90 | 165 + lib/sync65.f90 | 92 + lib/sync9.f90 | 2 + lib/sync9f.f90 | 55 + lib/sync9w.f90 | 81 + lib/synciscat.f90 | 185 + lib/syncmsk.f90 | 304 ++ lib/t6.f90 | 56 + lib/test_init_random_seed.f90 | 8 + lib/testfast9.f90 | 42 + lib/testmsg.f90 | 145 + lib/timefft.f90 | 2 + lib/timer.f90 | 200 -- lib/timer_C_wrapper.f90 | 57 + lib/timer_common.inc | 3 + lib/timer_impl.f90 | 262 ++ lib/timer_module.f90 | 24 + lib/timf2.f90 | 142 + lib/tm2.f90 | 14 - lib/to_contest_msg.f90 | 27 + lib/toxyz.f90 | 25 - lib/tweak1.f90 | 23 + lib/unpackbits.f90 | 22 - lib/unpackcall.f90 | 138 - lib/unpackgrid.f90 | 45 - lib/unpackmsg.f90 | 108 - lib/unpackmsg144.f90 | 117 + lib/unpacktext.f90 | 35 - lib/update_hasharray.f90 | 25 + lib/update_recent_calls.f90 | 19 + lib/vit213.c | 221 ++ lib/vit216.c | 2 +- lib/wav11.f90 | 27 + lib/wav12.f90 | 49 + lib/wavhdr.f90 | 72 + lib/wqdecode.f90 | 338 ++ lib/wqencode.f90 | 66 + lib/wsjt24.f90 | 181 - lib/wsjt24d.f90 | 43 - lib/wsjt_modes.txt | 68 + lib/wspr_downsample.f90 | 76 + lib/wsprcode/go.sh | 1 + lib/wsprcode/nhash.c | 384 +++ lib/wsprcode/wspr_old_subs.f90 | 937 +++++ lib/wsprcode/wsprcode.f90 | 158 + lib/wsprd/Makefile | 34 + lib/wsprd/Makefile.MinGW | 30 + lib/wsprd/Makefile.win32 | 40 + lib/wsprd/README | 54 + lib/wsprd/WSPRcode.f90 | 132 + lib/wsprd/fano.c | 239 ++ lib/wsprd/fano.h | 39 + lib/wsprd/fftw3.h | 410 +++ lib/wsprd/genmet.f90 | 50 + lib/wsprd/gran.c | 28 + lib/wsprd/jelinek.c | 163 + lib/wsprd/jelinek.h | 26 + lib/wsprd/metric_tables.c | 138 + lib/wsprd/mettab.c | 76 + lib/wsprd/nhash.c | 372 ++ lib/wsprd/nhash.h | 21 + lib/wsprd/t2.f90 | 11 + lib/wsprd/tab.c | 41 + lib/wsprd/test_wspr.f90 | 61 + lib/wsprd/unpk.c.obsolete | 124 + lib/wsprd/wsprd.c | 1290 +++++++ lib/wsprd/wsprd_stats.txt | 24 + lib/wsprd/wsprd_utils.c | 339 ++ lib/wsprd/wsprd_utils.h | 29 + lib/wsprd/wsprsim.c | 207 ++ lib/wsprd/wsprsim_utils.c | 311 ++ lib/wsprd/wsprsim_utils.h | 28 + lib/xcor.f90 | 73 + lib/xcor24.f90 | 94 - lib/xcor4.f90 | 95 + lib/zplt.f90 | 112 + 620 files changed, 73545 insertions(+), 6240 deletions(-) create mode 100644 lib/CQnnnCAT.txt create mode 100644 lib/DXped_pseudo_code.txt create mode 100644 lib/Fast_Modes.txt create mode 100644 lib/Makefile create mode 100644 lib/Makefile.jt65 create mode 100644 lib/Makefile.jt65_Win create mode 100644 lib/Makefile.jt65_osx create mode 100644 lib/Makefile.jt9w create mode 100644 lib/Makefile.jt9w_Win create mode 100644 lib/Makefile.msk create mode 100644 lib/Makefile.mskWin create mode 100644 lib/addit.f90 create mode 100644 lib/allsim.f90 create mode 100644 lib/ana64.f90 create mode 100644 lib/ana932.f90 create mode 100644 lib/avecho.f90 create mode 100644 lib/averms.f90 create mode 100644 lib/avg4.f90 create mode 100644 lib/badmsg.f90 create mode 100644 lib/bpdecode144.f90 create mode 100644 lib/bpdecode40.f90 delete mode 100644 lib/bpskmetrics.dat create mode 100644 lib/calibrate.f90 create mode 100644 lib/chkcall.f90 create mode 100644 lib/code426.f90 create mode 100644 lib/contest72.f90 create mode 100644 lib/count4.f90 create mode 100644 lib/crc.f90 create mode 100644 lib/crc10.cpp create mode 100644 lib/crc12.cpp delete mode 100644 lib/dcoord.f90 delete mode 100644 lib/decjt9.f90 create mode 100644 lib/decode4.f90 create mode 100644 lib/decode9w.f90 delete mode 100644 lib/deep24.f90 create mode 100644 lib/deep4.f90 create mode 100644 lib/degrade_snr.f90 delete mode 100644 lib/dot.f90 create mode 100644 lib/encode4.f90 create mode 100644 lib/encode_msk144.f90 create mode 100644 lib/encode_msk40.f90 create mode 100644 lib/ephem.f90 delete mode 100644 lib/extract.F90 create mode 100644 lib/extract.f90 create mode 100644 lib/extractmessage144.f90 delete mode 100644 lib/f77_wisdom.f90 create mode 100644 lib/fast9.f90 create mode 100644 lib/fast_decode.f90 create mode 100644 lib/fcal.f90 create mode 100644 lib/fchisq0.f90 create mode 100755 lib/fer create mode 100644 lib/fer65.f90 create mode 100644 lib/fersum.f90 create mode 100644 lib/fil3c.f90 delete mode 100644 lib/fillcom.f90 create mode 100644 lib/fitcal.f90 create mode 100644 lib/fix_contest_msg.f90 create mode 100644 lib/fixwav.f90 create mode 100644 lib/flat1a.f90 create mode 100644 lib/flat1b.f90 create mode 100644 lib/fmeasure.f90 create mode 100644 lib/fmtave.f90 create mode 100644 lib/foldspec9f.f90 create mode 100644 lib/fqso_first.f90 create mode 100644 lib/freqcal.f90 create mode 100644 lib/fsk4hf/Makefile create mode 100644 lib/fsk4hf/Makefile.win create mode 100644 lib/fsk4hf/baseline.f90 create mode 100644 lib/fsk4hf/bpdecode120.f90 create mode 100644 lib/fsk4hf/bpdecode168.f90 create mode 100644 lib/fsk4hf/bpdecode174.f90 create mode 100644 lib/fsk4hf/bpdecode300.f90 create mode 100644 lib/fsk4hf/chkcrc10.f90 create mode 100644 lib/fsk4hf/chkcrc12.f90 create mode 100644 lib/fsk4hf/chkcrc12a.f90 create mode 100644 lib/fsk4hf/cpolyfit.f90 create mode 100644 lib/fsk4hf/cpolyfitw.f90 create mode 100644 lib/fsk4hf/dbpsksim.f90 create mode 100644 lib/fsk4hf/dopspread.f90 create mode 100644 lib/fsk4hf/encode120.f90 create mode 100644 lib/fsk4hf/encode168.f90 create mode 100644 lib/fsk4hf/encode174.f90 create mode 100644 lib/fsk4hf/encode300.f90 create mode 100644 lib/fsk4hf/extractmessage168.f90 create mode 100644 lib/fsk4hf/extractmessage174.f90 create mode 100644 lib/fsk4hf/fftw3.f90 create mode 100644 lib/fsk4hf/four2a.f90 create mode 100644 lib/fsk4hf/fsk4hf.f90 create mode 100644 lib/fsk4hf/fsk4sim.f90 create mode 100644 lib/fsk4hf/ft8_downsample.f90 create mode 100644 lib/fsk4hf/ft8_params.f90 create mode 100644 lib/fsk4hf/ft8apset.f90 create mode 100644 lib/fsk4hf/ft8b.f90 create mode 100644 lib/fsk4hf/ft8d.f90 create mode 100644 lib/fsk4hf/ft8sim.f90 create mode 100644 lib/fsk4hf/genbpsk.f90 create mode 100644 lib/fsk4hf/genfsk4.f90 create mode 100644 lib/fsk4hf/genfsk4hf.f90 create mode 100644 lib/fsk4hf/genft8.f90 create mode 100644 lib/fsk4hf/genft8refsig.f90 create mode 100644 lib/fsk4hf/genmskhf.f90 create mode 100644 lib/fsk4hf/genwspr5.f90 create mode 100644 lib/fsk4hf/genwspr_fsk8.f90 create mode 100644 lib/fsk4hf/genwsprlf.f90 create mode 100644 lib/fsk4hf/getfc1.f90 create mode 100644 lib/fsk4hf/getfc1w.f90 create mode 100644 lib/fsk4hf/getfc2.f90 create mode 100644 lib/fsk4hf/getfc2w.f90 create mode 100644 lib/fsk4hf/gran.c create mode 100644 lib/fsk4hf/ldpc_174_87_params.f90 create mode 100644 lib/fsk4hf/ldpc_300_60_params.f90 create mode 100644 lib/fsk4hf/ldpcsim120.f90 create mode 100644 lib/fsk4hf/ldpcsim168.f90 create mode 100644 lib/fsk4hf/ldpcsim174.f90 create mode 100644 lib/fsk4hf/ldpcsim300.f90 create mode 100644 lib/fsk4hf/mskhfsim.f90 create mode 100644 lib/fsk4hf/msksoftsym.f90 create mode 100644 lib/fsk4hf/msksoftsymw.f90 create mode 100644 lib/fsk4hf/osd174.f90 create mode 100644 lib/fsk4hf/osd300.f90 create mode 100644 lib/fsk4hf/polyfit4.f90 create mode 100644 lib/fsk4hf/spec4.f90 create mode 100644 lib/fsk4hf/spec8.f90 create mode 100644 lib/fsk4hf/subtractft8.f90 create mode 100644 lib/fsk4hf/sync8.f90 create mode 100644 lib/fsk4hf/sync8d.f90 create mode 100644 lib/fsk4hf/tweak1.f90 create mode 100644 lib/fsk4hf/twkfreq1.f90 create mode 100644 lib/fsk4hf/watterson.f90 create mode 100644 lib/fsk4hf/wavhdr.f90 create mode 100644 lib/fsk4hf/wspr5_downsample.f90 create mode 100644 lib/fsk4hf/wspr5_wav.f90 create mode 100644 lib/fsk4hf/wspr5d.f90 create mode 100644 lib/fsk4hf/wspr5d_exp.f90 create mode 100644 lib/fsk4hf/wspr5sim.f90 create mode 100644 lib/fsk4hf/wspr_fsk8_downsample.f90 create mode 100644 lib/fsk4hf/wspr_fsk8_params.f90 create mode 100644 lib/fsk4hf/wspr_fsk8_sim.f90 create mode 100644 lib/fsk4hf/wspr_fsk8_wav.f90 create mode 100644 lib/fsk4hf/wspr_fsk8d.f90 create mode 100644 lib/fsk4hf/wsprlf.f90 create mode 100644 lib/fsk4hf/wsprlf_params.f90 create mode 100644 lib/fsk4hf/wsprlfsim.f90 create mode 100644 lib/ft8_decode.f90 create mode 100644 lib/ftrsd/Makefile create mode 100644 lib/ftrsd/Makefile.sfrsd create mode 100644 lib/ftrsd/Makefile.sfrsd3 create mode 100644 lib/ftrsd/decode_rs.c create mode 100644 lib/ftrsd/encode_rs.c create mode 100644 lib/ftrsd/extract2.f90 create mode 100644 lib/ftrsd/ftrsd2.c create mode 100644 lib/ftrsd/ftrsd_paper/JT65B_EME.png create mode 100644 lib/ftrsd/ftrsd_paper/Makefile create mode 100644 lib/ftrsd/ftrsd_paper/binomial.c create mode 100644 lib/ftrsd/ftrsd_paper/binomial_subs.c create mode 100644 lib/ftrsd/ftrsd_paper/bmdata-rf.dat create mode 100644 lib/ftrsd/ftrsd_paper/bmdata.dat create mode 100644 lib/ftrsd/ftrsd_paper/bmtheory25.dat create mode 100644 lib/ftrsd/ftrsd_paper/bmtheory40.dat create mode 100644 lib/ftrsd/ftrsd_paper/bmtheory43.dat create mode 100644 lib/ftrsd/ftrsd_paper/bodide.f90 create mode 100644 lib/ftrsd/ftrsd_paper/bodide.lab create mode 100644 lib/ftrsd/ftrsd_paper/fig_bodide.gnuplot create mode 100644 lib/ftrsd/ftrsd_paper/fig_ntrials_vs_nhard.gnuplot create mode 100644 lib/ftrsd/ftrsd_paper/fig_psuccess.gnuplot create mode 100644 lib/ftrsd/ftrsd_paper/fig_psuccess.pdf create mode 100644 lib/ftrsd/ftrsd_paper/fig_subtracted.tiff create mode 100644 lib/ftrsd/ftrsd_paper/fig_waterfall.png create mode 100644 lib/ftrsd/ftrsd_paper/fig_waterfall.tiff create mode 100644 lib/ftrsd/ftrsd_paper/fig_wer.gnuplot create mode 100644 lib/ftrsd/ftrsd_paper/fig_wer.pdf create mode 100644 lib/ftrsd/ftrsd_paper/fig_wer2.gnuplot create mode 100644 lib/ftrsd/ftrsd_paper/fig_wer3.gnuplot create mode 100644 lib/ftrsd/ftrsd_paper/ftdata-10.dat create mode 100644 lib/ftrsd/ftrsd_paper/ftdata-100.dat create mode 100644 lib/ftrsd/ftrsd_paper/ftdata-1000.dat create mode 100644 lib/ftrsd/ftrsd_paper/ftdata-10000.dat create mode 100644 lib/ftrsd/ftrsd_paper/ftdata-100000.dat create mode 100644 lib/ftrsd/ftrsd_paper/ftrsd.lyx create mode 100644 lib/ftrsd/ftrsd_paper/kvasd-12.dat create mode 100644 lib/ftrsd/ftrsd_paper/kvasd-15.dat create mode 100644 lib/ftrsd/ftrsd_paper/kvasd-8.dat create mode 100644 lib/ftrsd/ftrsd_paper/mfsk.f90 create mode 100644 lib/ftrsd/ftrsd_paper/prob.f90 create mode 100644 lib/ftrsd/ftrsd_paper/psuccess.lab create mode 100644 lib/ftrsd/ftrsd_paper/stats-100000-24db-3.dat create mode 100644 lib/ftrsd/ftrsd_paper/stats_0.0 create mode 100644 lib/ftrsd/ftrsd_paper/stats_0.2 create mode 100644 lib/ftrsd/ftrsd_paper/stats_1.0 create mode 100644 lib/ftrsd/ftrsd_paper/wer.lab create mode 100644 lib/ftrsd/ftrsd_paper/wer2.lab create mode 100644 lib/ftrsd/init_rs.c create mode 100644 lib/ftrsd/int.h create mode 100644 lib/ftrsd/rs2.h create mode 100644 lib/ftrsd/rsdtest.f90 create mode 100644 lib/ftrsd/sfrsd.c create mode 100644 lib/ftrsd/sfrsd2.h create mode 100644 lib/ftrsd/sfrsd3.c create mode 100644 lib/gen4.f90 create mode 100644 lib/gen9.f90 create mode 100644 lib/geniscat.f90 delete mode 100644 lib/genjt9.f90 create mode 100644 lib/genmsk144.f90 create mode 100644 lib/genmsk40.f90 create mode 100644 lib/genmsk_short.f90 create mode 100644 lib/genqra64.f90 create mode 100644 lib/genwspr.f90 delete mode 100644 lib/geocentric.f90 delete mode 100644 lib/getmet24.f90 create mode 100644 lib/getmet4.f90 delete mode 100644 lib/getpfx1.f90 delete mode 100644 lib/getpfx2.f90 create mode 100644 lib/go_chkfft.cmd create mode 100644 lib/golay24_table.c create mode 100644 lib/grayline.f90 delete mode 100644 lib/grid2k.f90 delete mode 100644 lib/grid2n.f90 create mode 100644 lib/hash.f90 create mode 100644 lib/hashing.f90 create mode 100644 lib/hint65.f90 create mode 100644 lib/hspec.f90 create mode 100644 lib/image.f90 create mode 100644 lib/init_random_seed.c create mode 100644 lib/init_random_seed.f90 create mode 100644 lib/init_random_seed.h create mode 100644 lib/inter_wspr.f90 delete mode 100644 lib/interleave24.f90 create mode 100644 lib/interleave4.f90 create mode 100644 lib/iscat.f90 create mode 100644 lib/iso_c_utilities.f90 create mode 100644 lib/jplsubs.f create mode 100644 lib/jt4.f90 create mode 100644 lib/jt4_decode.f90 create mode 100644 lib/jt4a.f90 create mode 100644 lib/jt4code.f90 create mode 100644 lib/jt4sim.f90 create mode 100644 lib/jt65_decode.f90 create mode 100644 lib/jt65_mod.f90 create mode 100644 lib/jt65_test.f90 delete mode 100644 lib/jt65a.f90 create mode 100644 lib/jt65sim.f90 create mode 100644 lib/jt9_decode.f90 delete mode 100644 lib/jt9b.f90 delete mode 100644 lib/jt9c.f90 create mode 100644 lib/jt9com.f90 create mode 100644 lib/jt9w.f90 create mode 100644 lib/jtmsg.f90 delete mode 100644 lib/k2grid.f90 create mode 100755 lib/ldpc/COPYRIGHT create mode 100755 lib/ldpc/LDPC-install create mode 100755 lib/ldpc/LGPL create mode 100755 lib/ldpc/Makefile create mode 100644 lib/ldpc/Makefile.msk_osx create mode 100755 lib/ldpc/README create mode 100755 lib/ldpc/alist-to-pchk.c create mode 100755 lib/ldpc/alloc.c create mode 100755 lib/ldpc/alloc.h create mode 100755 lib/ldpc/blockio.c create mode 100755 lib/ldpc/blockio.h create mode 100755 lib/ldpc/channel.c create mode 100755 lib/ldpc/channel.h create mode 100755 lib/ldpc/channel.html create mode 100755 lib/ldpc/check.c create mode 100755 lib/ldpc/check.h create mode 100755 lib/ldpc/dec.c create mode 100755 lib/ldpc/dec.h create mode 100755 lib/ldpc/decode-detail.html create mode 100755 lib/ldpc/decode.c create mode 100755 lib/ldpc/decoding.html create mode 100755 lib/ldpc/dep-H.html create mode 100755 lib/ldpc/distrib.c create mode 100755 lib/ldpc/distrib.h create mode 100755 lib/ldpc/enc.c create mode 100755 lib/ldpc/enc.h create mode 100755 lib/ldpc/encode.c create mode 100755 lib/ldpc/encoding.html create mode 100755 lib/ldpc/ex-dep create mode 100755 lib/ldpc/ex-dep-out create mode 100755 lib/ldpc/ex-ham7a create mode 100755 lib/ldpc/ex-ham7a-out create mode 100755 lib/ldpc/ex-ham7b create mode 100755 lib/ldpc/ex-ham7b-out create mode 100755 lib/ldpc/ex-ldpc-encode create mode 100755 lib/ldpc/ex-ldpc-encode-out create mode 100755 lib/ldpc/ex-ldpc36-1000a create mode 100755 lib/ldpc/ex-ldpc36-1000a-out create mode 100755 lib/ldpc/ex-ldpc36-5000a create mode 100755 lib/ldpc/ex-ldpc36-5000a-out create mode 100755 lib/ldpc/ex-ldpcvar-5000a create mode 100755 lib/ldpc/ex-ldpcvar-5000a-out create mode 100755 lib/ldpc/ex-wrong-model create mode 100755 lib/ldpc/ex-wrong-model-out create mode 100755 lib/ldpc/examples.html create mode 100755 lib/ldpc/extract.c create mode 100755 lib/ldpc/github.html create mode 100755 lib/ldpc/index.html create mode 100755 lib/ldpc/install.html create mode 100755 lib/ldpc/intio.c create mode 100755 lib/ldpc/intio.h create mode 100644 lib/ldpc/jtmode_codes/jtmskcode.results create mode 100644 lib/ldpc/jtmode_codes/peg-128-80-denev20.gen create mode 100644 lib/ldpc/jtmode_codes/peg-128-80-denev20.pchk create mode 100644 lib/ldpc/jtmode_codes/peg-128-80-denev7.gen create mode 100644 lib/ldpc/jtmode_codes/peg-128-80-denev7.pchk create mode 100644 lib/ldpc/jtmode_codes/peg-128-80-reg3.gen create mode 100644 lib/ldpc/jtmode_codes/peg-128-80-reg3.pchk create mode 100644 lib/ldpc/jtmode_codes/peg-128-80-reg4.gen create mode 100644 lib/ldpc/jtmode_codes/peg-128-80-reg4.pchk create mode 100644 lib/ldpc/jtmode_codes/peg-198-72-irreg-8x3-2x4.gen create mode 100644 lib/ldpc/jtmode_codes/peg-198-72-irreg-8x3-2x4.pchk create mode 100644 lib/ldpc/jtmode_codes/peg-198-72-reg3.gen create mode 100644 lib/ldpc/jtmode_codes/peg-198-72-reg3.pchk create mode 100644 lib/ldpc/jtmode_codes/peg-198-72-reg4.gen create mode 100644 lib/ldpc/jtmode_codes/peg-198-72-reg4.pchk create mode 100755 lib/ldpc/make-gen.c create mode 100755 lib/ldpc/make-ldpc.c create mode 100755 lib/ldpc/make-pchk.c create mode 100755 lib/ldpc/mod2convert-test-out create mode 100755 lib/ldpc/mod2convert-test.c create mode 100755 lib/ldpc/mod2convert.c create mode 100755 lib/ldpc/mod2convert.h create mode 100755 lib/ldpc/mod2convert.html create mode 100755 lib/ldpc/mod2dense-test-out create mode 100755 lib/ldpc/mod2dense-test.c create mode 100755 lib/ldpc/mod2dense.c create mode 100755 lib/ldpc/mod2dense.h create mode 100755 lib/ldpc/mod2dense.html create mode 100755 lib/ldpc/mod2sparse-test-out create mode 100755 lib/ldpc/mod2sparse-test.c create mode 100755 lib/ldpc/mod2sparse.c create mode 100755 lib/ldpc/mod2sparse.h create mode 100755 lib/ldpc/mod2sparse.html create mode 100755 lib/ldpc/modify.html create mode 100755 lib/ldpc/modules.html create mode 100644 lib/ldpc/msksim.f90 create mode 100755 lib/ldpc/open.c create mode 100755 lib/ldpc/open.h create mode 100755 lib/ldpc/pchk-to-alist.c create mode 100755 lib/ldpc/pchk.html create mode 100644 lib/ldpc/peg/128-64-reg4.deg create mode 100644 lib/ldpc/peg/BigGirth.C create mode 100644 lib/ldpc/peg/BigGirth.h create mode 100644 lib/ldpc/peg/CodeName create mode 100644 lib/ldpc/peg/CyclesOfGraph.C create mode 100644 lib/ldpc/peg/CyclesOfGraph.h create mode 100644 lib/ldpc/peg/DenEvl_11.deg create mode 100644 lib/ldpc/peg/DenEvl_15.deg create mode 100644 lib/ldpc/peg/DenEvl_20.deg create mode 100644 lib/ldpc/peg/DenEvl_7.deg create mode 100644 lib/ldpc/peg/DenEvl_9.deg create mode 100644 lib/ldpc/peg/MainPEG.C create mode 100644 lib/ldpc/peg/Makefile create mode 100644 lib/ldpc/peg/Random.C create mode 100644 lib/ldpc/peg/Random.h create mode 100644 lib/ldpc/peg/Reg_2.deg create mode 100644 lib/ldpc/peg/Reg_3.deg create mode 100644 lib/ldpc/peg/Reg_4.deg create mode 100644 lib/ldpc/peg/ldpc-peg-128-80.alist create mode 100644 lib/ldpc/peg/peg-128-64-reg4.alist create mode 100644 lib/ldpc/peg/peg-128-64-reg4.code create mode 100644 lib/ldpc/peg/peg-128-72-reg4.alist create mode 100644 lib/ldpc/peg/peg-128-72-reg4.code create mode 100644 lib/ldpc/peg/peg-128-80-reg3.alist create mode 100644 lib/ldpc/peg/peg-128-80-reg3.code create mode 100644 lib/ldpc/peg/peg-128-80-reg4.alist create mode 100644 lib/ldpc/peg/peg-128-80-reg4.code create mode 100644 lib/ldpc/peg/peg-144-72-reg4.alist create mode 100644 lib/ldpc/peg/peg-144-72-reg4.code create mode 100755 lib/ldpc/peg/peg2alist create mode 100644 lib/ldpc/peg/peg_128_80.pchk create mode 100644 lib/ldpc/peg/sfpeg1.code create mode 100644 lib/ldpc/peg/sfpeg1.deg create mode 100644 lib/ldpc/peg/sfpeg2.alist create mode 100644 lib/ldpc/peg/sfpeg2.code create mode 100644 lib/ldpc/peg/sfpeg2.deg create mode 100644 lib/ldpc/peg/sfpeg3.alist create mode 100644 lib/ldpc/peg/sfpeg3.code create mode 100644 lib/ldpc/peg/sfpeg3.deg create mode 100755 lib/ldpc/print-gen.c create mode 100755 lib/ldpc/print-pchk.c create mode 100755 lib/ldpc/progs.html create mode 100755 lib/ldpc/rand-src.c create mode 100755 lib/ldpc/rand-test.c create mode 100755 lib/ldpc/rand.c create mode 100755 lib/ldpc/rand.h create mode 100755 lib/ldpc/rand.html create mode 100755 lib/ldpc/randfile create mode 100755 lib/ldpc/rcode.c create mode 100755 lib/ldpc/rcode.h create mode 100755 lib/ldpc/refs.html create mode 100755 lib/ldpc/release.html create mode 100755 lib/ldpc/run-examples create mode 100755 lib/ldpc/sparse-LU.html create mode 100755 lib/ldpc/sparse-encode.pdf create mode 100755 lib/ldpc/support.html create mode 100755 lib/ldpc/transmit.c create mode 100755 lib/ldpc/verify.c create mode 100644 lib/ldpc32_table.c create mode 100644 lib/ldpcsim144.f90 create mode 100644 lib/ldpcsim40.f90 create mode 100644 lib/libration.f90 create mode 100644 lib/lorentzian.f90 create mode 100644 lib/lpf1.f90 create mode 100644 lib/makepings.f90 create mode 100644 lib/mixlpf.f90 delete mode 100644 lib/moon2.f90 delete mode 100644 lib/moondop.f90 create mode 100644 lib/moondopjpl.f90 create mode 100644 lib/msk144_freq_search.f90 create mode 100644 lib/msk144code.f90 create mode 100644 lib/msk144d2.f90 create mode 100644 lib/msk144decodeframe.f90 create mode 100644 lib/msk144sd.f90 create mode 100644 lib/msk144signalquality.f90 create mode 100644 lib/msk144sim.f90 create mode 100644 lib/msk144spd.f90 create mode 100644 lib/msk144sync.f90 create mode 100644 lib/msk40_freq_search.f90 create mode 100644 lib/msk40decodeframe.f90 create mode 100644 lib/msk40spd.f90 create mode 100644 lib/msk40sync.f90 create mode 100644 lib/mskber.f90 create mode 100644 lib/mskdt.f90 create mode 100644 lib/mskrtd.f90 delete mode 100644 lib/n2grid.f90 delete mode 100644 lib/nchar.f90 delete mode 100644 lib/packbits.f90 delete mode 100644 lib/packcall.f90 delete mode 100644 lib/packdxcc.f90 delete mode 100644 lib/packgrid.f90 create mode 100644 lib/packjt.f90 delete mode 100644 lib/packmsg.f90 delete mode 100644 lib/packtext.f90 delete mode 100644 lib/pfxdump.f90 delete mode 100644 lib/polfit.f90 create mode 100644 lib/polyfit.f90 create mode 100644 lib/prcom.f90 delete mode 100644 lib/ps24.f90 create mode 100644 lib/ps4.f90 create mode 100644 lib/psk_parse.f90 create mode 100644 lib/qra/qra64/Makefile.Win create mode 100644 lib/qra/qra64/fadengauss.c create mode 100644 lib/qra/qra64/fadenlorentz.c create mode 100644 lib/qra/qra64/main.c create mode 100644 lib/qra/qra64/qra64.c create mode 100644 lib/qra/qra64/qra64.h create mode 100644 lib/qra/qra64/qra64_all.c create mode 100644 lib/qra/qra64/qra64_subs.c create mode 100644 lib/qra/qra64/qra64example.txt create mode 100644 lib/qra/qra64/qra64sim.f90 create mode 100644 lib/qra/qracodes/Makefile.Win create mode 100644 lib/qra/qracodes/ebno10000.txt create mode 100644 lib/qra/qracodes/ebnovalues.txt create mode 100644 lib/qra/qracodes/ebnovaluesfast.txt create mode 100644 lib/qra/qracodes/main.c create mode 100644 lib/qra/qracodes/normrnd.c create mode 100644 lib/qra/qracodes/normrnd.h create mode 100644 lib/qra/qracodes/npfwht.c create mode 100644 lib/qra/qracodes/npfwht.h create mode 100644 lib/qra/qracodes/pdmath.c create mode 100644 lib/qra/qracodes/pdmath.h create mode 100644 lib/qra/qracodes/qra12_63_64_irr_b.c create mode 100644 lib/qra/qracodes/qra12_63_64_irr_b.h create mode 100644 lib/qra/qracodes/qra13_64_64_irr_e.c create mode 100644 lib/qra/qracodes/qra13_64_64_irr_e.h create mode 100644 lib/qra/qracodes/qracodes.c create mode 100644 lib/qra/qracodes/qracodes.h create mode 100644 lib/qra64a.f90 create mode 100644 lib/qra64code.f90 create mode 100644 lib/qratest.f90 create mode 100644 lib/readwav.f90 create mode 100644 lib/rectify_msk.f90 create mode 100644 lib/refspectrum.f90 delete mode 100644 lib/s3avg.f90 create mode 100644 lib/savec2.f90 create mode 100644 lib/sfrsd.f90 create mode 100644 lib/sgran.c create mode 100644 lib/sh65.f90 create mode 100644 lib/sh65snr.f90 create mode 100644 lib/shell.f90 create mode 100644 lib/slasubs.f create mode 100644 lib/smolorentz.f90 create mode 100644 lib/softsym9f.f90 create mode 100644 lib/softsym9w.f90 create mode 100644 lib/spec64.f90 create mode 100644 lib/spec9f.f90 create mode 100644 lib/stats.f90 create mode 100644 lib/subtract65.f90 delete mode 100644 lib/sync24.f90 create mode 100644 lib/sync4.f90 create mode 100644 lib/sync64.f90 create mode 100644 lib/sync65.f90 create mode 100644 lib/sync9f.f90 create mode 100644 lib/sync9w.f90 create mode 100644 lib/synciscat.f90 create mode 100644 lib/syncmsk.f90 create mode 100644 lib/t6.f90 create mode 100644 lib/test_init_random_seed.f90 create mode 100644 lib/testfast9.f90 create mode 100644 lib/testmsg.f90 delete mode 100644 lib/timer.f90 create mode 100644 lib/timer_C_wrapper.f90 create mode 100644 lib/timer_common.inc create mode 100644 lib/timer_impl.f90 create mode 100644 lib/timer_module.f90 create mode 100644 lib/timf2.f90 delete mode 100644 lib/tm2.f90 create mode 100644 lib/to_contest_msg.f90 delete mode 100644 lib/toxyz.f90 create mode 100644 lib/tweak1.f90 delete mode 100644 lib/unpackbits.f90 delete mode 100644 lib/unpackcall.f90 delete mode 100644 lib/unpackgrid.f90 delete mode 100644 lib/unpackmsg.f90 create mode 100644 lib/unpackmsg144.f90 delete mode 100644 lib/unpacktext.f90 create mode 100644 lib/update_hasharray.f90 create mode 100644 lib/update_recent_calls.f90 create mode 100644 lib/vit213.c create mode 100644 lib/wav11.f90 create mode 100644 lib/wav12.f90 create mode 100644 lib/wqdecode.f90 create mode 100644 lib/wqencode.f90 delete mode 100644 lib/wsjt24.f90 delete mode 100644 lib/wsjt24d.f90 create mode 100644 lib/wsjt_modes.txt create mode 100644 lib/wspr_downsample.f90 create mode 100644 lib/wsprcode/go.sh create mode 100644 lib/wsprcode/nhash.c create mode 100644 lib/wsprcode/wspr_old_subs.f90 create mode 100644 lib/wsprcode/wsprcode.f90 create mode 100644 lib/wsprd/Makefile create mode 100644 lib/wsprd/Makefile.MinGW create mode 100644 lib/wsprd/Makefile.win32 create mode 100755 lib/wsprd/README create mode 100644 lib/wsprd/WSPRcode.f90 create mode 100644 lib/wsprd/fano.c create mode 100644 lib/wsprd/fano.h create mode 100644 lib/wsprd/fftw3.h create mode 100644 lib/wsprd/genmet.f90 create mode 100644 lib/wsprd/gran.c create mode 100644 lib/wsprd/jelinek.c create mode 100644 lib/wsprd/jelinek.h create mode 100644 lib/wsprd/metric_tables.c create mode 100644 lib/wsprd/mettab.c create mode 100644 lib/wsprd/nhash.c create mode 100644 lib/wsprd/nhash.h create mode 100644 lib/wsprd/t2.f90 create mode 100644 lib/wsprd/tab.c create mode 100644 lib/wsprd/test_wspr.f90 create mode 100644 lib/wsprd/unpk.c.obsolete create mode 100644 lib/wsprd/wsprd.c create mode 100644 lib/wsprd/wsprd_stats.txt create mode 100644 lib/wsprd/wsprd_utils.c create mode 100644 lib/wsprd/wsprd_utils.h create mode 100644 lib/wsprd/wsprsim.c create mode 100644 lib/wsprd/wsprsim_utils.c create mode 100644 lib/wsprd/wsprsim_utils.h create mode 100644 lib/xcor.f90 delete mode 100644 lib/xcor24.f90 create mode 100644 lib/xcor4.f90 create mode 100644 lib/zplt.f90 (limited to 'lib') diff --git a/lib/CQnnnCAT.txt b/lib/CQnnnCAT.txt new file mode 100644 index 00000000..d7e92d01 --- /dev/null +++ b/lib/CQnnnCAT.txt @@ -0,0 +1,39 @@ +Before using the new "CQ nnn ..." feature in JTMSK mode, I suggest +performing the following tests of the necessary CAT control for your +radio. (I'm assuming that you already have some experience with +JTMSK.) + +TEST 1: +-------------------------------------------------------------------------- +1. Start WSJT-X +2. Settings: "Enable VHF/UHF/Microwave features, "Rx frequency offset + with 'CQ nnn ...'", Split=Rig, or Split="Fake it" +3. Main screen settings: Band=50.280, mode=JTMSK, T/R=15 s +4. Activate CQRx, set CQ Rx=265 + ==> Rx dial should now read 50.265 and Tx6 should be queued +5. Click "Enable Tx" + ==> Tx sequences should occur at 50.280, Rx at 50.265 + +With most rigs, this test should work with Split configured as either +"Rig" or "Fake it". + +TEST 2: +-------------------------------------------------------------------------- +1. Start WSJT-X +2. Settings: MyCall=K1JT, "Enable VHF/UHF/Microwave features, + "Rx frequency offset with 'CQ nnn ...'", Split=Rig or "Fake it" +4. Main screen settings: Band=50.280, mode=JTMSK, T/R=15 s +5. Open file 150826_120515.wav + ==> see decoded message "K1JT VE1SKY FN74" +6. Click "Monitor" to restart monitoring +7. Activate CQRx, set CQ Rx=265 + ==> Rx dial should now read 50.265; Tx6 should be queued +8. Click "Enable Tx" + ==> Tx sequences should occur at 50.280, Rx at 50.265 +9. After the start of a transmission, double-click on the decoded message + "K1JT VE1SKY FN74" + ==> Tx2 should be generated and queued; transmission will pause + briefly, Tx freq changed to 50.265, then Tx resumed. + +The test file is posted at +http://physics.princeton.edu/pulsar/K1JT/150826_120515.wav diff --git a/lib/DXped_pseudo_code.txt b/lib/DXped_pseudo_code.txt new file mode 100644 index 00000000..081bfda7 --- /dev/null +++ b/lib/DXped_pseudo_code.txt @@ -0,0 +1,71 @@ +Auto-Sequencing algorithm for DXpedition station: + +Start: + CQMsg = "CQ KH1DX" (or "CQ UP KH1DX", "CQ 116 KH1DX", etc.) + TxMsg = CQMsg + Ntry = 0 + QCALL = "" # Callsign of current QSO partner + go to Transmit + +Transmit: + TX # (... takes 13.6 s) + go to Receive + +Receive: + RX # (... takes ~14 s) + N = number of decodes # RxMsg[i], i=1,N + if(N == 0) + go to Transmit + J = index of a reply from current QCALL # RxMsg[J] = "KH1DX QCALL R" + + if(QCALL == "") # No QSO in progress + Select new QCALL # Op chooses a caller + if(QCALL == "") + TxMsg = CQMsg # No callers, we'll CQ again + else # QSO in progress + if(J >= 1) # Expected message was received + log the QSO with QCALL + QCALL = "" + Select new QCALL # Op chooses a new caller + if(QCALL != "") + TxMsg = "73 NOW QCALL " # Start a new QSO + else + TxMsg = "73 " + CQMsg # No callers, we'll CQ again + else + Ntry = Ntry + 1 # Expected msg not received + if(Ntry <= NtryMax) + go to Transmit # Ask for a repeat + else + QCALL = "" # Max tries exceeded, abort this QSO + Select new QCALL # Choose a new caller + if(QCALL != "") + TxMsg = "NIL NOW QCALL " # Start a new QSO + else + TxMsg = "NIL " + CQMSG # No callers, we'll CQ again + go to Transmit + + +Auto-Sequencing algorithm for those calling the DXpedition: + +Start: + TxMsg = "KH1DX MyCall" + InQSO = false + +Transmit: + TX # (... takes 13.6 s) + go to Receive + +Receive: + RX # (... takes ~14 s) + if(RxMsg[i] contains "MyCall ") + InQSO = true + TxMsg = "KH1DX MyCall R" + go to Transmit + + if(RxMsg[i] contains "") + TxEnable = false + go to Receive + + if(RxMsg[i] contains "CQ KH1DX") + TxEnable = true + go to Transmit diff --git a/lib/Fast_Modes.txt b/lib/Fast_Modes.txt new file mode 100644 index 00000000..da6e27b9 --- /dev/null +++ b/lib/Fast_Modes.txt @@ -0,0 +1,395 @@ + Fast Modes in WSJT-X + -------------------- + +####################################################################### + +IMPORTANT - IMPORTANT - IMPORTANT - IMPORTANT - IMPORTANT - IMPORTANT + +Third-party individuals (i.e., others not part of the WSJT development +team) have been compiling WSJT-X from the open source code and making +unauthorized "releases" of their builds. I do NOT reccommend use of +unauthorized builds on the air. If a program revision has been released +in an official way, you will see it listed here. + +If you operate with an unauthorized "rXXXX" code revisions in our +experimental code branch you have no idea what you've got. Quite +possibly, the program was built from an intermediate temporary "save" +of various files, and was not even supposed to produce a usable +program. Your observetions about what works or does not work are then +worse than useless -- they waste your time and ours. + +So please, PLEASE, *PLEASE*: use *authorized*, "released* revisions +of this still-in-development software, like the revisions described here. + +*ALSO:* If you choose to try an experimental release of JTMSK, please +accept the responsibility of reporting on your results. You can send +reports to the "wsjtgroup" reflector, wsjtgroup@yahoogroups.com, or +email them directly to me. All suggestions for improvements are +welcome! + +Bug reports should include details on how to reproduce the undesirable +program behavior. Reports on decoding performance are especially +useful when accompanied by example *.wav files with signals that +you think should have decoded, but did not. + +####################################################################### + +September 18, 2015 +----------------- + +New alpha release of experimental WSJT-X v1.6.1, r5910 +------------------------------------------------------ +Changes since revision 5889 include the following: + +1. Improved behavior for auto-QSY with "CQ nnn ..." feature. (May not +be exactly correct, yet, for all radios. Please report if you find +problems with your rig.) + +2. Allow optional use of Wide Graph in fast modes. + +3. Add UTC labels to Fast Graph spectrograms. + +4. Display correct DXCC entiry for "CQ nnn ..." messages. + +5. Implement "Save Decoded" for fast modes. + +6. Select Tx6 when "CQ Rx nnn" is enabled. + +7. Fix bug in setting of TRperiod after switch to ISCAT mode. + +8. Display proper symbol '&' in Tx messages in JTMSK mode. + + +To download this alpha release for Windows, paste the following link +into your browser: +http://physics.princeton.edu/pulsar/K1JT/wsjtx-1.6.1-r5910-win32.exe + + -- 73, Joe, K1JT + +####################################################################### + +September 12, 2015 +----------------- + +New alpha release of experimental WSJT-X v1.6.1, r5889 +------------------------------------------------------ + +A principal new feature in this release is designed to promote the use +of an agreed "calling frequency" for transmissions of the form + + CQ 265 K1ABC FN42 + +signifying that K1ABC will listen for replies on 50.265 (or 144.265, +or whatever) and will complete the QSO there. The feature uses the +rig-control features of WSJT-X to handle the necessary frequency +switching. + +########################################################################## +Changes since revision 5865 include the following: + +1. New features that allow automatic rig control when you transmit or +respond to messages of the form "CQ 265 K1ABC FN42" on an agreed +calling frequency. This feature should be especially useful for +meteor scatter. + +2. Yellow-highlighted "Tx" messages in the right text window are now +properly labeled with 6-digit UTC (hhmmss) in all fast modes. + +3. Fixed a bug (introduced in r5865) that inhibited transmitting in +JT4 mode. + +4. Fixed a bug that caused Wide Graph to continue issuing green +separator lines at short (e.g. 15 s) intervals after you have switched +to a slow mode. + +5. Fixed several more GUI appearance bugs associated with changing +modes or submodes. + +6. Fixed a bug in which double-clicking on the Fast Graph could cause +program crashes. + +7. Fixed a bug that sometimes caused "high tones" to be emitted in +JTMSK mode. + +####################################################################### +Here's a brief description of how to use the "CQ nnn ..." features. + +1. On program startup, go to the Settings | General tab and tick the +box labeled 'Rx frequency offset with "CQ nnn ..."' + +2. Select JTMSK mode and 50.280 (or your some other agreed calling +frequency) from the drop-down band menu. Remember that this menu is +not pre-populated with preferred frequencies for all modes on all +bands. Use Settings | Frequencies to add your desired modes and +frequencies to the list. + +3. Tick the unlabeled checkbox just under the "Report: spinner to +activate the "CQ Rx nnn" spinner. Set this control to your desired +QSO frequency in kHz above the nominal band edge. On 6 meters, for +example, "265" means "50.265". + +4. Your transceiver dial frequency should now show 50.265. Changes to +the "CQ Rx nnn" spinner value should be reflected immediately in the +transceiver dial frequency, the displayed value on the WSJT-X main +screen, and in Tx message #6, the "CQ nnn... " message. + +5. When you transmit the Tx6 message, the Tx frequency will be set at +the calling frequency. Otherwise (when receiving, or when +transmitting any of the messages Tx1 through Tx5) the offset frequency +(50.265 in my example) will be used. + +6. If you double-click on a received "CQ nnn ..." message on the +calling frequency, your rig will QSY to specified response frequency, +e.g. 50.265, for both Rx and Tx. + +7. To go back to listening on the calling frequency, uncheck the box +that activated the "CQ Rx nnn" spinner. + +####################################################################### + +Fair warning: I have not yet tested all possible combinations of +"Split Operation" configuration (i.e., "None", "Rig", and "Fake it"). +If you normally use Split operation, that should be OK for the "CQ +nnn ..." feature. + + +As always, please report any bugs that you find in r5889, including +pertinent details on your settings and the exact series of steps +required to reproduce the bug. + + +To download this alpha release for Windows, paste the following link +into your browser: +http://physics.princeton.edu/pulsar/K1JT/wsjtx-1.6.1-r5889-win32.exe + + + -- 73, Joe, K1JT + +####################################################################### + +New alpha release of experimental WSJT-X v1.6.1, r5865 +------------------------------------------------------ + +This alpha release of WSJT-X includes major improvements to the JTMSK +decoder. Changes since revision 5823 include the following: + +1. On-screen controls labeled "Rx nnnn Hz" and "F Tol" (Rx frequency +and tolerance) now function as expected in JTMSK mode. The frequency +search range can be up to 500 Hz, but note that sensitivity is +necessarily reduced for signals off frequency by more than about 250 +Hz. Normally you should leave Rx Freq set at 1500 Hz; suitable values +for F Tol are 100 to 500 Hz. + +2. The JTMSK decoder now makes good use of strong, short pings (as +short as 0.1 s) as well as weak pings several times longer. + +3. Improved calculation of S/N and frequency of decoded signals. + +4. Unified appearance of window titles on all non-modal windows. + +5. CW ID is disabled (for now, at least) when operating in any of the +WSJT fast modes. + +6. In WSPR mode, display of "Receiving ... " messages is +disabled when band-hopping is not in use. + +7. Fixed several bugs affecting status and visibility of certain +on-screen controls after changes in operating mode. + +8. Fixed a bug allowing display of duplicate decodes for the same +signal. + +9. Fixed a bug preventing compilation on 64-bit systems, and cleaned +up some harmless compiler warnings. + +####################################################################### + Summary Description of JTMSK Protocol + +JTMSK uses the same standard message structure as slow modes JT4, JT9, +and JT65. User information is "source encoded" to 72 bits. A 15-bit +CRC is appended and a convolutional code with constraint length K=13 +and rate r=1/2 is applied, making a total of (72+15+12)*2 = 198 +information bits. Three copies of the "Barker-11" code and three +even-parity bits are added for synchronization, making a total of +198+33+3 = 234 channel symbols. Modulation uses a constant-envelope, +continuous-phase "minimum-shift keying" (MSK) waveform, with tone +frequencies of 1000 and 2000 Hz. + +####################################################################### + +To download this alpha release for Windows, paste the following link +into your browser: +http://physics.princeton.edu/pulsar/K1JT/wsjtx-1.6.1-r5865-win32.exe + + -- 73, Joe, K1JT + +August 28, 2015 +--------------- + +New release of experimental WSJT-X v1.6.1, r5823 +------------------------------------------------ + +To download for Windows, paste the following link into your browser: +http://physics.princeton.edu/pulsar/K1JT/wsjtx-1.6.1-r5823-win32.exe + +This experimental version of WSJT-X introduces a new fast mode called +JTMSK. The letters MS, of course, imply meteor scatter; the three +letters MSK mean "Minimum Shift Keying", the modulation scheme used in +this mode. + +Revision 5823 also includes a number of (mostly minor) bug fixes +relative to r5789. + +IMPORTANT: If you choose to try JTMSK, please accept the +responsibility of reporting on your results. You can send reports to +the "wsjtgroup" reflector, wsjtgroup@yahoogroups.com or email them +directly to me. All suggestions for improvements are welcome! Bug +reports should include details on how to reproduce the undesirable +program behavior. + +The present JTMSK decoder has been optimized for short pings. It does +not yet do a wide search for proper frequency alignment; you and your +QSO partner need to be "on frequency" to within +/- 100 Hz or better. +The decoder does not (yet) attempt to make optimal use of weak, slowly +varying signals. These and other characteristics may be improved in +coming revisions. + +KNOWN BUG: At present you should use T/R sequence lengths 15 s in +JTMSK mode. If you have a program crash, open Windows Task Manager, +select the "Processes" tab, right-click on wsjtx.exe, and select "End +Process Tree". Then restart the program. + +I view JTMSK as a candidate for replacing both FSK441 and JTMS for all +meteor scatter work. JTMSK has the major advantage of including +strong forward error correction (FEC), similar in usage to the schemes +used for many years in JT4, JT9, and JT65. The structure of user +messages and the format of minimal QSOs is also identical to those +other modes. But JTMSK is very fast, transmitting its full encoded +message content in 0.117 s, in a 2 kHz bandwidth. JTMSK therefore +makes much better use of short pings than (for example) JT9H can do. + +The Tx waveform of JTMSK has been carefully designed to have a number +of desirable features. All messages are exactly the same length: 72 +bits of user information are followed by a 15-bit CRC and encoded into +198 channel bits with a convolutional code (constraint length K=13, +rate r=1/2). Three sequences of the "Barker-11" code are added, along +with three parity bits, making a total of 234 channel bits in each +message. The MSK symbols for these bits are transmitted at 2000 baud, +and the full encoded message is repeated every 117 ms. + +A summary description of modulation parameters for all WSJT(-X) modes +is shown in a table posted here: +http://physics.princeton.edu/pulsar/K1JT/wsjt_modes.txt and +illustrated graphically here: +http://physics.princeton.edu/pulsar/K1JT/wsjt_modes.pdf + + -- 73, Joe, K1jT + +August 15, 2015 +--------------- + +New release of experimental WSJT-X v1.6.1, r5789 + +Changes since WSJT-X v1.6.1, revision 5779: + +1. Major speedup (5x) of fast-JT9 decoder. +2. Corrected logic for Auto-Sequencing operation. +3. Stop after sending 73 five times in auto-sequence mode. +4. Add an "Auto-Level" control to Fast Graph window. +5. Send fast-mode decodes to PSKreporter web site. +6. Support automatic logging via JTAlert-X. +7. Send fast-mode output to file ALL.TXT. +8. Better definition of dB levels for fast-JT9 signals. +9. Rationalize the GUI behavior when changing mode, submode, fast/slow + status, and T/R period. +10. Correct a flaw in the display of multiple decodes in a single + fast-JT9 sequence. +11. Fix minor bugs reported by G3WDG, ND0B, OZ1PIF, and others. + +To download for Windows, paste the following link into your browser: +http://physics.princeton.edu/pulsar/K1JT/wsjtx-1.6.1-r5789-win32.exe + +Please keep in mind that this is an experimental version of WSJT-X. +Bug reports and other feedback will be much appreciated, and will help +to make the program better! + + -- 73, Joe, K1JT + + +August 11, 2015 +--------------- + +Since its origin in the dark ages (ca. 2001) WSJT has supported "fast" +modes (designed for meteor scatter, etc.) and "slow" modes (optimized +for EME and other weak-signal propagation types). The most recent new +mode, JT9, now has *both* fast and slow submodes. + +JT9A (the "original" JT9) is like JT65 and JT4: its T/R sequences are +one minute long, and its primary goal is best possible sensitivity for +very weak, approximately steady signals. The new experimental JT9 +submodes use the same message structure, encoding, and modulation type +(9-tone FSK) as JT9A, but wider tone spacing and (optionally) faster +keying rates. + +You can download an experimental version of WSJT-X (v1.6.1, r5779) here: +http://physics.princeton.edu/pulsar/K1JT/wsjtx-1.6.1-r5779-win32.exe + +The fast submodes currently being tested, JT9E - JT9H, have been found +highly effective for meteors and ionoscatter propagation on 6 and 10 +meters. Sensitivity is similar to ISCAT, or slightly better. +Decoding is much more reliable, because the JT9 protocol includes +strong forward error correction. Decoding results are like those for +all the WSJT "slow" modes: you should see messages exactly as they +were transmitted, or nothing at all. A potential side benefit is +automatic reporting of decodes to PSKreporter. + +For details on the modulation parameters of the JT9 submodes, see the +table posted at +http://physics.princeton.edu/pulsar/K1JT/wsjt_modes.txt. + +WSJT-X v1.6.1 r5779 has the following changes from r5769: + +1. Numerous bug fixes +2. Double-click on decoded message now behaves properly +3. Faster decoding (further optimization still to come) +4. Decoded text is highlighted as in WSJT-X slow modes +5. Optional auto-sequencing + +Fair warning: auto-sequencing is basically functional, but scarcely +tested. Please watch what it is doing, and tell us how you think it +should be improved! + +If you use WSJT-X also for other modes and other purposes, you may +want to save several different sets of configuration settings. In +that case it's convenient to use the "-r xxx" option and start the +program from a command-prompt window. For example: + +C:\Users\joe> cd \wsjt\wsjtx\bin +C:\WSJT\wsjtx\bin> wsjtx -r xxx + +... where "xxx" can be anything you like, for example "ISCAT", +"FAST9", etc. + +Proper configuration for the JT9 fast modes includes the following +settings: + +On the Settings | General tab: + + - check "Enable VHF/UHF/Microwave features" + +Main window settings: + + - Mode JT9 + - Tx 700 Hz + - Rx 700 Hz + - Sync 0 + - Submode G ... or E, F, and H (H not legal in US on 10m) + - Tick "Fast" + - T/R 30 s (also 5, 10, 15 s) + - FTol 500 + +Please keep in mind that this is an experimental version of WSJT-X. +It still has some rough edges, and no doubt some bugs. Your feedback +will be much appreciated, and will help to make the program better! + + -- 73, Joe, K1JT diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 00000000..c4d6279a --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,71 @@ +CC = gcc +CXX = g++ +FC = gfortran + +FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion +CFLAGS = -O2 -I. + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +#all: qratest.exe tplt.exe +all: qra64d.exe + +OBJS1 = qratest.o qra64a.o ana64.o sync64a.o four2a.o smo.o smo121.o averms.o \ + timer_module.o packjt.o twkfreq.o spec64.o fmtmsg.o pctile.o \ + grid2deg.o deg2grid.o shell.o badmsg.o qra64_subs.o \ + qracodes.o npfwht.o pdmath.o qra12_63_64_irr_b.o \ + qra13_64_64_irr_e.o qra64.o image.o \ + zplt64a.o zplt64b.o lorentzian.o fchisq0.o peakup.o sync64.o + +qra64_subs.o: qra/qra64/qra64_subs.c + gcc -c -O2 -o qra64_subs.o qra/qra64/qra64_subs.c + +qracodes.o: qra/qracodes/qracodes.c + gcc -c -O2 -o qracodes.o qra/qracodes/qracodes.c + +qra64.o: qra/qra64/qra64.c + gcc -c -O2 -o qra64.o qra/qra64/qra64.c + +npfwht.o: qra/qracodes/npfwht.c + gcc -c -O2 -o npfwht.o qra/qracodes/npfwht.c + +pdmath.o: qra/qracodes/pdmath.c + gcc -c -O2 -o pdmath.o qra/qracodes/pdmath.c + +qra12_63_64_irr_b.o: qra/qracodes/qra12_63_64_irr_b.c + gcc -c -O2 -o qra12_63_64_irr_b.o qra/qracodes/qra12_63_64_irr_b.c + +qra13_64_64_irr_e.o: qra/qracodes/qra13_64_64_irr_e.c + gcc -c -O2 -o qra13_64_64_irr_e.o qra/qracodes/qra13_64_64_irr_e.c + +qratest.exe: $(OBJS1) + $(FC) -o qratest.exe $(OBJS1) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS2 = tplt.o zplt64.o image.o +tplt.exe: $(OBJS2) + $(FC) -o tplt.exe $(OBJS2) + +OBJS3 = qra64d.o sync64a.o four2a.o smo.o smo121.o averms.o \ + timer_module.o packjt.o twkfreq.o spec64.o fmtmsg.o pctile.o \ + grid2deg.o deg2grid.o shell.o badmsg.o qra64_subs.o \ + qracodes.o npfwht.o pdmath.o qra12_63_64_irr_b.o \ + qra13_64_64_irr_e.o qra64.o image.o \ + zplt64a.o zplt64b.o lorentzian.o fchisq0.o peakup.o sync64.o + +qra64d.exe: $(OBJS3) + $(FC) -o qra64d.exe $(OBJS3) C:\JTSDK\fftw3f\libfftw3f-3.dll + +.PHONY : clean + +clean: + $(RM) *.o qratest.exe tplt.exe diff --git a/lib/Makefile.jt65 b/lib/Makefile.jt65 new file mode 100644 index 00000000..7409b5c1 --- /dev/null +++ b/lib/Makefile.jt65 @@ -0,0 +1,84 @@ +# Set paths +EXE_DIR = ../../wsjtx_exp_install_latest +QT_DIR = /usr/include/qt5 +INCPATH = -I${QT_DIR} -I${QT_DIR}/QtCore + +CC = gcc +CXX = g++ +FC = gfortran +AR = ar cr +MKDIR = mkdir -p +CP = cp +RANLIB = ranlib +RM = rm -f + +FFLAGS = -I/opt/local/include -O3 -funroll-loops -Wall -Wno-conversion -fno-second-underscore -DUNIX +CFLAGS = -I. -fbounds-check -fPIE + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: libjt9.a jt65 jt65sim t3 + +OBJS1 = astrosub.o astro0.o astro.o sun.o coord.o tmoonsub.o \ + fmtmsg.o deg2grid.o\ + prog_args.o options.o pctile.o graycode.o sort.o chkmsg.o \ + igray.o fftw3mod.o packjt.o\ + four2a.o grid2deg.o wisdom.o \ + symspec.o analytic.o db.o \ + encode232.o interleave9.o\ + entail.o fano232.o gran.o sync9.o \ + fil3.o decoder.o fqso_first.o \ + twkfreq.o symspec2.o shell.o sync65.o peakup.o slope.o xcor.o\ + chkss2.o zplot9.o flat1.o flat2.o \ + symspec65.o flat65.o ccf65.o decode65a.o \ + filbig.o fil6521.o afc65b.o decode65b.o setup65.o \ + extract.o fchisq65.o demod64a.o chkhist.o interleave63.o ccf2.o \ + move.o indexx.o graycode65.o twkfreq65.o smo.o smo121.o \ + wrapkarn.o init_rs.o encode_rs.o decode_rs.o gen65.o fil4.o \ + flat4.o determ.o baddata.o subtract65.o + +libjt9.a: $(OBJS1) + $(AR) libjt9.a $(OBJS1) + $(RANLIB) libjt9.a + +OBJS7 = jt65.o +jt65: $(OBJS7) libjt9.a libsfrsd.a + $(FC) -o jt65 $(OBJS7) -L. -L/opt/local/lib -L./sfrsd2 -ljt9 -lsfrsd -lfftw3f_threads -lfftw3f + $(CP) jt65 $(EXE_DIR) + +OBJS2 = jt65sim.o wavhdr.o +jt65sim: $(OBJS2) libjt9.a + $(FC) -o jt65sim $(OBJS2) -L. -L/opt/local/lib -ljt9 -lfftw3f + $(CP) jt65sim $(EXE_DIR) + +OBJS3 = t3.o +t3: $(OBJS3) libjt9.a + $(FC) -o t3 $(OBJS3) -L. -L/opt/local/lib -ljt9 + +OBJS6 = jt65code.o +jt65code: $(OBJS6) libjt9.a + $(FC) -o jt65code $(OBJS6) libjt9.a + +init_rs.o: init_rs.c + $(CC) -c -DBIGSYM=1 -o init_rs.o init_rs.c + +encode_rs.o: encode_rs.c + $(CC) -c -DBIGSYM=1 -o encode_rs.o encode_rs.c + +decode_rs.o: decode_rs.c + $(CC) -c -DBIGSYM=1 -o decode_rs.o decode_rs.c + +.PHONY : clean + +clean: + $(RM) *.o libjt9.a jt65 diff --git a/lib/Makefile.jt65_Win b/lib/Makefile.jt65_Win new file mode 100644 index 00000000..08a4d22c --- /dev/null +++ b/lib/Makefile.jt65_Win @@ -0,0 +1,76 @@ +# Set paths +EXE_DIR = C:/JTSDK/wsjtx_exp/install/Debug/bin +QT_DIR = /usr/include/qt5 +INCPATH = -I${QT_DIR} -I${QT_DIR}/QtCore + +CC = gcc +CXX = g++ +FC = gfortran +AR = ar cr +MKDIR = mkdir -p +CP = cp +RANLIB = ranlib +RM = rm -f + +FFLAGS = -O2 -Wall -Wno-conversion -fno-second-underscore +CFLAGS = -I. -fbounds-check -fPIE -DBIGSYM + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: libjt9.a jt65 jt65sim + +OBJS1 = astrosub.o astro0.o astro.o sun.o coord.o tmoonsub.o \ + fmtmsg.o deg2grid.o\ + prog_args.o options.o pctile.o graycode.o sort.o chkmsg.o \ + igray.o fftw3mod.o packjt.o\ + four2a.o grid2deg.o wisdom.o \ + symspec.o analytic.o db.o \ + encode232.o interleave9.o \ + entail.o fano232.o gran.o sync9.o decjt9.o \ + fil3.o decoder.o timer.o exp_decode65.o fqso_first.o \ + twkfreq.o symspec2.o shell.o sync65.o peakup.o slope.o xcor.o\ + fillcom.o chkss2.o zplot9.o flat1.o flat2.o \ + jt65a.o symspec65.o flat65.o ccf65.o decode65a.o \ + filbig.o fil6521.o afc65b.o decode65b.o setup65.o \ + extract.o fchisq65.o demod64a.o chkhist.o interleave63.o ccf2.o \ + move.o indexx.o graycode65.o twkfreq65.o smo.o smo121.o \ + wrapkarn.o init_rs.o encode_rs.o decode_rs.o gen65.o fil4.o \ + flat4.o determ.o baddata.o subtract65.o + +libjt9.a: $(OBJS1) + $(AR) libjt9.a $(OBJS1) + $(RANLIB) libjt9.a + +OBJS7 = jt65.o +jt65: $(OBJS7) libjt9.a libsfrsd.a + $(FC) -o jt65 $(OBJS7) -L. -L./sfrsd2 -ljt9 -lsfrsd \ + C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS2 = jt65sim.o wavhdr.o +jt65sim: $(OBJS2) libjt9.a + $(FC) -o jt65sim $(OBJS2) -L. -ljt9 C:\JTSDK\fftw3f\libfftw3f-3.dll + $(CP) jt65sim.exe $(EXE_DIR) + +init_rs.o: init_rs.c + $(CC) -c -DBIGSYM=1 -o init_rs.o init_rs.c + +encode_rs.o: encode_rs.c + $(CC) -c -DBIGSYM=1 -o encode_rs.o encode_rs.c + +decode_rs.o: decode_rs.c + $(CC) -c -DBIGSYM=1 -o decode_rs.o decode_rs.c + +.PHONY : clean + +clean: + $(RM) *.o libjt9.a jt65 diff --git a/lib/Makefile.jt65_osx b/lib/Makefile.jt65_osx new file mode 100644 index 00000000..c831e70f --- /dev/null +++ b/lib/Makefile.jt65_osx @@ -0,0 +1,74 @@ +# Set paths +EXE_DIR = ../../wsjtx_install + +CC = clang +CXX = g++ +FC = gfortran +AR = ar cr +MKDIR = mkdir -p +CP = cp +RANLIB = ranlib +RM = rm -f + +FFLAGS = -I/opt/local/include -Wall -Wno-conversion -fno-second-underscore -DUNIX +CFLAGS = -I. -fbounds-check -fPIE + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: libjt9.a jt65 jt65sim + +OBJS1 = astrosub.o astro0.o astro.o sun.o coord.o tmoonsub.o \ + fmtmsg.o deg2grid.o\ + prog_args.o options.o pctile.o graycode.o sort.o chkmsg.o \ + igray.o fftw3mod.o packjt.o\ + four2a.o grid2deg.o wisdom.o \ + symspec.o analytic.o db.o \ + encode232.o interleave9.o\ + entail.o fano232.o sgran.o gran.o sync9.o decjt9.o \ + fil3.o decoder.o timer.o exp_decode65.o fqso_first.o\ + twkfreq.o symspec2.o shell.o sync65.o peakup.o slope.o xcor.o\ + fillcom.o chkss2.o zplot9.o flat1.o flat2.o \ + jt65a.o symspec65.o flat65.o ccf65.o decode65a.o \ + filbig.o fil6521.o afc65b.o decode65b.o setup65.o \ + extract.o fchisq65.o demod64a.o chkhist.o interleave63.o ccf2.o \ + move.o indexx.o graycode65.o twkfreq65.o smo.o smo121.o \ + wrapkarn.o init_rs.o encode_rs.o decode_rs.o gen65.o fil4.o \ + flat4.o determ.o baddata.o subtract65.o + +libjt9.a: $(OBJS1) + $(AR) libjt9.a $(OBJS1) + $(RANLIB) libjt9.a + +OBJS7 = jt65.o +jt65: $(OBJS7) libjt9.a libftrsd.a + $(FC) -o jt65 $(OBJS7) -L. -L/opt/local/lib -L./ftrsd -ljt9 -lftrsd -lfftw3f_threads -lfftw3f + $(CP) jt65 $(EXE_DIR) + +OBJS2 = jt65sim.o wavhdr.o +jt65sim: $(OBJS2) libjt9.a + $(FC) -o jt65sim $(OBJS2) -L. -L/opt/local/lib -ljt9 -lfftw3f + $(CP) jt65sim $(EXE_DIR) + +init_rs.o: init_rs.c + $(CC) -c -DBIGSYM=1 -o init_rs.o init_rs.c + +encode_rs.o: encode_rs.c + $(CC) -c -DBIGSYM=1 -o encode_rs.o encode_rs.c + +decode_rs.o: decode_rs.c + $(CC) -c -DBIGSYM=1 -o decode_rs.o decode_rs.c + +.PHONY : clean + +clean: + $(RM) *.o libjt9.a jt65 diff --git a/lib/Makefile.jt9w b/lib/Makefile.jt9w new file mode 100644 index 00000000..db7bd548 --- /dev/null +++ b/lib/Makefile.jt9w @@ -0,0 +1,58 @@ + +# Set paths +EXE_DIR = ..\\..\\wsjtx_install +QT_DIR = C:/wsjt-env/Qt5/5.2.1/mingw48_32 +FFTW3_DIR = .. + +INCPATH = -I${QT_DIR}/include/QtCore -I${QT_DIR}/include + +# Compilers +CC = gcc +CXX = g++ +FC = gfortran +AR = ar cr +RANLIB = ranlib +MKDIR = mkdir -p +CP = cp +RM = rm -f + +FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion +CFLAGS = -O2 -I. + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: jt9w + +OBJS1 = jt9w.o smo.o sync9w.o pctile.o shell.o lorentzian.o fchisq0.o \ + softsym9w.o four2a.o interleave9.o jt9fano.o fano232.o packjt.o \ + deg2grid.o grid2deg.o fmtmsg.o db.o decode9w.o + +jt9w: $(OBJS1) + $(FC) -o jt9w $(OBJS1) -lfftw3f + +OBJS2 = t1.o four2a.o db.o +t1: $(OBJS2) + $(FC) -o t1 $(OBJS2) -lfftw3f + +OBJS3 = t2.o four2a.o db.o +t2: $(OBJS3) + $(FC) -o t2 $(OBJS3) -lfftw3f + +OBJS4 = t3.o four2a.o db.o +t3: $(OBJS4) + $(FC) -o t3 $(OBJS4) -lfftw3f + +.PHONY : clean + +clean: + $(RM) *.o JTMSKcode JTMSKcode.exe diff --git a/lib/Makefile.jt9w_Win b/lib/Makefile.jt9w_Win new file mode 100644 index 00000000..28dbe304 --- /dev/null +++ b/lib/Makefile.jt9w_Win @@ -0,0 +1,58 @@ + +# Set paths +EXE_DIR = ..\\..\\wsjtx_install +QT_DIR = C:/wsjt-env/Qt5/5.2.1/mingw48_32 +FFTW3_DIR = .. + +INCPATH = -I${QT_DIR}/include/QtCore -I${QT_DIR}/include + +# Compilers +CC = gcc +CXX = g++ +FC = gfortran +AR = ar cr +RANLIB = ranlib +MKDIR = mkdir -p +CP = cp +RM = rm -f + +FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion +CFLAGS = -O2 -I. + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: jt9w + +OBJS1 = jt9w.o smo.o sync9w.o pctile.o shell.o lorentzian.o fchisq0.o \ + softsym9w.o four2a.o interleave9.o jt9fano.o fano232.o packjt.o \ + deg2grid.o grid2deg.o fmtmsg.o db.o decode9w.o + +jt9w: $(OBJS1) + $(FC) -o jt9w $(OBJS1) -lfftw3f + +OBJS2 = t1.o four2a.o db.o +t1: $(OBJS2) + $(FC) -o t1 $(OBJS2) -lfftw3f + +OBJS3 = t2.o four2a.o db.o +t2: $(OBJS3) + $(FC) -o t2 $(OBJS3) -lfftw3f + +OBJS4 = t3.o +t3: $(OBJS4) + $(FC) -o t3 $(OBJS4) -L. -ljt9 C:\JTSDK\fftw3f\libfftw3f-3.dll + +.PHONY : clean + +clean: + $(RM) *.o JTMSKcode JTMSKcode.exe diff --git a/lib/Makefile.msk b/lib/Makefile.msk new file mode 100644 index 00000000..333b36ca --- /dev/null +++ b/lib/Makefile.msk @@ -0,0 +1,71 @@ + +# Set paths +EXE_DIR = ..\\..\\wsjtx_install +QT_DIR = C:/wsjt-env/Qt5/5.2.1/mingw48_32 +FFTW3_DIR = .. + +INCPATH = -I${QT_DIR}/include/QtCore -I${QT_DIR}/include + +# Compilers +CC = gcc +CXX = g++ +FC = gfortran +AR = ar cr +RANLIB = ranlib +MKDIR = mkdir -p +CP = cp +RM = rm -f + +FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion +CFLAGS = -O2 -I. + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +#all: jt9code JTMSKcode +all: jtmsk JTMSKcode + +OBJS4 = jt9code.o packjt.o fmtmsg.o gen9.o deg2grid.o grid2deg.o \ + entail.o encode232.o interleave9.o graycode.o igray.o +jt9code: $(OBJS4) + $(FC) -o jt9code $(OBJS4) + +OBJS5 = JTMSKcode.o packjt.o fmtmsg.o genmsk.o deg2grid.o grid2deg.o \ + entail.o nhash.o tab.o vit213.o +JTMSKcode: $(OBJS5) + $(FC) -o JTMSKcode $(OBJS5) + +OBJS6 = jtmsk.o jtmsk.o analytic.o four2a.o db.o mskdf.o pctile.o \ + sort.o tweak1.o syncmsk.o genmsk.o packjt.o fmtmsg.o indexx.o \ + deg2grid.o grid2deg.o entail.o nhash.o tab.o vit213.o +jtmsk: $(OBJS6) + $(FC) -o jtmsk $(OBJS6) -lfftw3f + +OBJS1 = t1.o four2a.o db.o +t1: $(OBJS1) + $(FC) -o t1 $(OBJS1) -lfftw3f + +OBJS2 = t2.o four2a.o db.o +t2: $(OBJS2) + $(FC) -o t2 $(OBJS2) -lfftw3f + +OBJS6 = t6.o four2a.o db.o +t6: $(OBJS6) + $(FC) -o t6 $(OBJS6) -lfftw3f + +nhash.o: wsprd/nhash.h wsprd/nhash.c + $(CC) -c -O2 wsprd/nhash.c + +.PHONY : clean + +clean: + $(RM) *.o JTMSKcode JTMSKcode.exe diff --git a/lib/Makefile.mskWin b/lib/Makefile.mskWin new file mode 100644 index 00000000..9d5e6e62 --- /dev/null +++ b/lib/Makefile.mskWin @@ -0,0 +1,75 @@ + +# Set paths +EXE_DIR = ..\\..\\wsjtx_install +QT_DIR = C:/wsjt-env/Qt5/5.2.1/mingw48_32 +FFTW3_DIR = .. + +INCPATH = -I${QT_DIR}/include/QtCore -I${QT_DIR}/include + +# Compilers +CC = gcc +CXX = g++ +FC = gfortran +AR = ar cr +RANLIB = ranlib +MKDIR = mkdir -p +CP = cp +RM = rm -f + +FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion +CFLAGS = -O2 -I. + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +#all: jt9code JTMSKcode.exe +all: jtmsk.exe JTMSKsim.exe JTMSKcode.exe fixwav.exe + +OBJS3 = JTMSKsim.o wavhdr.o gran.o four2a.o db.o +JTMSKsim.exe: $(OBJS3) + $(FC) -o JTMSKsim.exe $(OBJS3) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS4 = jt9code.o packjt.o fmtmsg.o gen9.o deg2grid.o grid2deg.o \ + entail.o encode232.o interleave9.o graycode.o igray.o +jt9code: $(OBJS4) + $(FC) -o jt9code $(OBJS4) + +OBJS5 = JTMSKcode.o packjt.o fmtmsg.o genmsk.o deg2grid.o grid2deg.o \ + entail.o tab.o vit213.o hashing.o nhash.o +JTMSKcode.exe: $(OBJS5) + $(FC) -o JTMSKcode.exe $(OBJS5) + +OBJS6 = jtmsk.o analytic.o four2a.o db.o pctile.o \ + shell.o tweak1.o syncmsk.o genmsk.o packjt.o fmtmsg.o indexx.o \ + deg2grid.o grid2deg.o entail.o hashing.o nhash.o tab.o vit213.o \ + mskdt.o rectify_msk.o timer.o jtmsk_decode.o genmsk_short.o \ + jtmsk_short.o golay24_table.o hash.o + +jtmsk.exe: $(OBJS6) + $(FC) -o jtmsk.exe $(OBJS6) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS1 = fixwav.o wavhdr.o +fixwav.exe: $(OBJS1) + $(FC) -o fixwav.exe $(OBJS1) + +OBJS2 = t2.o four2a.o db.o +t2: $(OBJS2) + $(FC) -o t2 $(OBJS2) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS6 = t6.o four2a.o db.o +t6: $(OBJS6) + $(FC) -o t6 $(OBJS6) C:\JTSDK\fftw3f\libfftw3f-3.dll + +.PHONY : clean + +clean: + $(RM) *.o JTMSKcode JTMSKcode.exe diff --git a/lib/addit.f90 b/lib/addit.f90 new file mode 100644 index 00000000..48082833 --- /dev/null +++ b/lib/addit.f90 @@ -0,0 +1,83 @@ +subroutine addit(itone,nfsample,nsym,nsps,ifreq,sig,dat) + + integer itone(nsym) + real dat(60*12000) + real*8 f,dt,twopi,phi,dphi,baud,fsample,freq,tsym,t + + tsym=nsps*1.d0/nfsample !Symbol duration + baud=1.d0/tsym + fsample=12000.d0 !Sample rate (Hz) + dt=1.d0/fsample !Sample interval (s) + twopi=8.d0*atan(1.d0) + dphi=0. + + iters=1 + if(nsym.eq.79) iters=2 + do iter=1,iters + f=ifreq + phi=0. + ntot=nsym*tsym/dt + k=12000 !Start audio at t = 1.0 s + t=0. + if(nsym.eq.79) k=12000 + (iter-1)*12000*30 !Special case for FT8 + isym0=-1 + do i=1,ntot + t=t+dt + isym=nint(t/tsym) + 1 + if(isym.ne.isym0) then + freq=f + itone(isym)*baud + dphi=twopi*freq*dt + isym0=isym + endif + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + k=k+1 + dat(k)=dat(k) + sig*sin(xphi) + enddo + enddo + + return +end subroutine addit + +subroutine addcw(icw,ncw,ifreq,sig,dat) + + integer icw(ncw) + real dat(60*12000) + real s(60*12000) + real x(60*12000) + real y(60*12000) + real*8 dt,twopi,phi,dphi,fsample,tdit,t + + wpm=25.0 + nspd=nint(1.2*12000.0/wpm) + fsample=12000.d0 !Sample rate (Hz) + dt=1.d0/fsample !Sample interval (s) + tdit=nspd*dt + twopi=8.d0*atan(1.d0) + dphi=twopi*ifreq*dt + phi=0. + k=12000 !Start audio at t = 1.0 s + t=0. + npts=60*12000 + x=0. + do i=1,npts + t=t+dt + j=nint(t/tdit) + 1 + j=mod(j-1,ncw) + 1 + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + k=k+1 + x(k)=icw(j) + s(k)=sin(xphi) + if(t.ge.59.5) exit + enddo + + nadd=0.004/dt + call smo(x,npts,y,nadd) + y=y/nadd + dat=dat + sig*y*s + + return +end subroutine addcw diff --git a/lib/afc65b.f90 b/lib/afc65b.f90 index 848ba853..a43f88ab 100644 --- a/lib/afc65b.f90 +++ b/lib/afc65b.f90 @@ -11,9 +11,8 @@ subroutine afc65b(cx,npts,fsample,nflip,a,ccfbest,dtbest) a(4)=0. deltaa(1)=2.0 deltaa(2)=2.0 - deltaa(3)=2.0 - deltaa(4)=0.05 - nterms=3 !Maybe 2 is enough? + deltaa(3)=1.0 + nterms=2 !Maybe 2 is enough? ! Start the iteration chisqr=0. diff --git a/lib/afc9.f90 b/lib/afc9.f90 index 44323738..dd106aa4 100644 --- a/lib/afc9.f90 +++ b/lib/afc9.f90 @@ -1,7 +1,8 @@ subroutine afc9(c3a,npts,fsample,a,syncpk) - complex c3a(0:npts-1) - complex c3(0:1360-1) + parameter (NZ2=1512) + complex c3a(0:NZ2-1) + complex c3(0:NZ2-1) real a(3),deltaa(3) a(1)=0. !f0 @@ -53,13 +54,14 @@ subroutine afc9(c3a,npts,fsample,a,syncpk) enddo if(a(3).ne.a3) call shft(c3a,a(3),a3,c3) chisqr=fchisq(c3,npts,fsample,a) +! write(*,4000) 0,0,a,-chisqr if(chisqr/chisqr0.gt.0.99) exit chisqr0=chisqr enddo syncpk=-chisqr c3a=c3 -! write(*,4001) a,-chisq2 +! write(*,4001) a,syncpk !4001 format(3x,3f10.4,f11.3) return diff --git a/lib/allsim.f90 b/lib/allsim.f90 new file mode 100644 index 00000000..2d948b64 --- /dev/null +++ b/lib/allsim.f90 @@ -0,0 +1,78 @@ +program allsim + +! Generate simulated data for WSJT-X slow modes: JT4, JT9, JT65, QRA64, +! and WSPR. Also unmodulated carrier and 20 WPM CW. + + + use wavhdr + use packjt + parameter (NMAX=60*12000) + type(hdr) h + integer*2 iwave(NMAX) !Generated waveform (no noise) + integer itone(206) !Channel symbols (values 0-8) + integer icw(250) + integer*1 msgbits(87) + logical*1 bcontest + real*4 dat(NMAX) + character message*22,msgsent*22,arg*8,mygrid*6 + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: allsim ' + go to 999 + endif + + call getarg(1,arg) + read(arg,*) snrdb !S/N in dB (2500 hz reference BW) + + message='CQ KA2ABC FN20' + mygrid='FN20 ' + bcontest=.false. + rmsdb=25. + rms=10.0**(0.05*rmsdb) + sig=10.0**(0.05*snrdb) + npts=NMAX + + call init_random_seed() !Seed Fortran RANDOM_NUMBER generator + call sgran() !Seed C rand generator (used in gran) + + h=default_header(12000,npts) + open(10,file='000000_0000.wav',access='stream',status='unknown') + do i=1,npts !Generate gaussian noise + dat(i)=gran() + enddo + + itone=0 + call addit(itone,12000,85,6912,400,sig,dat) !Unmodulated carrier + + call morse('CQ CQ DE KA2ABC KA2ABC',icw,ncw) +! print*,ncw +! write(*,3001) icw(1:ncw) +!3001 format(50i1) + call addcw(icw,ncw,600,sig,dat) !CW + + call genwspr(message,msgsent,itone) + call addit(itone,12000,86,8192,800,sig,dat) !WSPR (only 59 s of data) + + call gen9(message,0,msgsent,itone,itype) + call addit(itone,12000,85,6912,1000,sig,dat) !JT9 + + call gen4(message,0,msgsent,itone,itype) + call addit(itone,11025,206,2520,1200,sig,dat) !JT4 + + i3bit=0 ! ### TEMPORARY ??? ### + call genft8(message,mygrid,bcontest,i3bit,msgsent,msgbits,itone) + call addit(itone,12000,79,1920,1400,sig,dat) !FT8 + + call genqra64(message,0,msgsent,itone,itype) + call addit(itone,12000,84,6912,1600,sig,dat) !QRA64 + + call gen65(message,0,msgsent,itone,itype) + call addit(itone,11025,126,4096,1800,sig,dat) !JT65 + + iwave(1:npts)=nint(rms*dat(1:npts)) + + write(10) h,iwave(1:npts) + close(10) + +999 end program allsim diff --git a/lib/ana64.f90 b/lib/ana64.f90 new file mode 100644 index 00000000..5681ee17 --- /dev/null +++ b/lib/ana64.f90 @@ -0,0 +1,24 @@ +subroutine ana64(dd,npts,c0) + + use timer_module, only: timer + + parameter (NMAX=60*12000) !Max size of raw data at 12000 Hz + parameter (NSPS=3456) !Samples per symbol at 6000 Hz + parameter (NSPC=7*NSPS) !Samples per Costas array + real dd(NMAX) !Raw data + complex c0(0:720000) !Complex spectrum of dd() + save + + nfft1=672000 + nfft2=nfft1/2 + df1=12000.0/nfft1 + fac=2.0/nfft1 + c0(0:npts-1)=fac*dd(1:npts) + c0(npts:nfft1)=0. + call four2a(c0,nfft1,1,-1,1) !Forward c2c FFT + c0(nfft2/2+1:nfft2)=0. + c0(0)=0.5*c0(0) + call four2a(c0,nfft2,1,1,1) !Inverse c2c FFT; c0 is analytic sig + + return +end subroutine ana64 diff --git a/lib/ana932.f90 b/lib/ana932.f90 new file mode 100644 index 00000000..2665b7a1 --- /dev/null +++ b/lib/ana932.f90 @@ -0,0 +1,21 @@ +subroutine ana932(dat,npts0,cdat,npts) + + real dat(npts0) + complex cdat(262145) + + n=log(float(npts0))/log(2.0) + nfft1=2**(n+1) + nfft2=9*nfft1/32 + df932=11025.0/nfft1 + fac=2.0/nfft1 + do i=1,npts0/2 + cdat(i)=fac*cmplx(dat(2*i-1),dat(2*i)) + enddo + cdat(npts0/2+1:nfft1/2)=0. + call four2a(cdat,nfft1,1,-1,0) !Forward r2c FFT + call four2a(cdat,nfft2,1,1,1) !Inverse c2c FFT + npts=npts0*9.0/32.0 !Downsampled data length + npts2=npts + + return +end subroutine ana932 diff --git a/lib/analytic.f90 b/lib/analytic.f90 index 33d5fc74..253692f5 100644 --- a/lib/analytic.f90 +++ b/lib/analytic.f90 @@ -1,25 +1,75 @@ -subroutine analytic(d,npts,nfft,s,c) +subroutine analytic(d,npts,nfft,c,pc,beq) ! Convert real data to analytic signal - parameter (NFFTMAX=128*1024) - real d(npts) - real s(npts) - complex c(NFFTMAX) + parameter (NFFTMAX=1024*1024) + real d(npts) ! passband signal + real h(NFFTMAX/2) ! real BPF magnitude + real*8 pc(5),pclast(5) ! static phase coeffs + real*8 ac(5),aclast(5) ! amp coeffs + real*8 fp + + complex corr(NFFTMAX/2) ! complex frequency-dependent correction + complex c(NFFTMAX) ! analytic signal + + logical*1 beq ! boolean static equalizer flag + + data nfft0/0/ + data aclast/0.0,0.0,0.0,0.0,0.0/ + data pclast/0.0,0.0,0.0,0.0,0.0/ +! data ac/1.0,0.05532,0.11438,0.12918,0.09274/ ! amp coeffs for TS2000 + data ac/1.0,0.0,0.0,0.0,0.0/ + + save corr,nfft0,h,ac,aclast,pclast,pi,t,beta + + df=12000.0/nfft nh=nfft/2 + if( nfft.ne.nfft0 ) then + pi=4.0*atan(1.0) + t=1.0/2000.0 + beta=0.1 + do i=1,nh+1 + ff=(i-1)*df + f=ff-1500.0 + h(i)=1.0 + if(abs(f).gt.(1-beta)/(2*t) .and. abs(f).le.(1+beta)/(2*t)) then + h(i)=h(i)*0.5*(1+cos((pi*t/beta )*(abs(f)-(1-beta)/(2*t)))) + elseif( abs(f) .gt. (1+beta)/(2*t) ) then + h(i)=0.0 + endif + enddo + nfft0=nfft + endif + + if( any(aclast .ne. ac) .or. any(pclast .ne. pc) ) then + aclast=ac + pclast=pc +! write(*,3001) pc +!3001 format('Phase coeffs:',5f12.6) + do i=1,nh+1 + ff=(i-1)*df + f=ff-1500.0 + fp=f/1000.0 + corr(i)=ac(1)+fp*(ac(2)+fp*(ac(3)+fp*(ac(4)+fp*ac(5)))) + pd=fp*fp*(pc(3)+fp*(pc(4)+fp*pc(5))) ! ignore 1st two terms + corr(i)=corr(i)*cmplx(cos(pd),sin(pd)) + enddo + endif + fac=2.0/nfft c(1:npts)=fac*d(1:npts) c(npts+1:nfft)=0. call four2a(c,nfft,1,-1,1) !Forward c2c FFT - do i=1,nh - s(i)=real(c(i))**2 + aimag(c(i))**2 - enddo + if( beq ) then + c(1:nh+1)=h(1:nh+1)*corr(1:nh+1)*c(1:nh+1) + else + c(1:nh+1)=h(1:nh+1)*c(1:nh+1) + endif - c(1)=0.5*c(1) - c(nh+2:nfft)=0. + c(1)=0.5*c(1) !Half of DC term + c(nh+2:nfft)=0. !Zero the negative frequencies call four2a(c,nfft,1,1,1) !Inverse c2c FFT - return end subroutine analytic diff --git a/lib/astro.f90 b/lib/astro.f90 index 56711f35..c1d1b5a6 100644 --- a/lib/astro.f90 +++ b/lib/astro.f90 @@ -1,4 +1,4 @@ -subroutine astro(nyear,month,nday,uth,nfreq,Mygrid, & +subroutine astro(nyear,month,nday,uth,freq8,Mygrid, & NStation,MoonDX,AzSun,ElSun,AzMoon0,ElMoon0, & ntsky,doppler00,doppler,dbMoon,RAMoon,DecMoon,HA,Dgrd,sd, & poloffset,xnr,day,lon,lat,LST,techo) @@ -7,6 +7,7 @@ subroutine astro(nyear,month,nday,uth,nfreq,Mygrid, & ! NB: may want to smooth the Tsky map to 10 degrees or so. character*6 MyGrid,HisGrid + real*8 freq8 real LST real lat,lon integer*2 nt144(180) @@ -41,12 +42,11 @@ subroutine astro(nyear,month,nday,uth,nfreq,Mygrid, & call sun(nyear,month,nday,uth,lon,lat,RASun,DecSun,LST, & AzSun,ElSun,mjd,day) - freq=nfreq*1.e6 - if(nfreq.eq.2) freq=1.8e6 - if(nfreq.eq.4) freq=3.5e6 - - call MoonDop(nyear,month,nday,uth,lon,lat,RAMoon,DecMoon, & - LST,HA,AzMoon,ElMoon,vr,dist) + call MoonDopJPL(nyear,month,nday,uth,lon,lat,RAMoon,DecMoon, & + LST,HA,AzMoon,ElMoon,vr,techo) + RAMoon=rad*RAMoon + DecMoon=rad*DecMoon + dist=2.99792458d5*techo/2.d0 ! Compute spatial polarization offset xx=sin(lat/rad)*cos(ElMoon/rad) - cos(lat/rad)* & @@ -55,14 +55,13 @@ subroutine astro(nyear,month,nday,uth,nfreq,Mygrid, & if(NStation.eq.1) poloffset1=rad*atan2(yy,xx) if(NStation.eq.2) poloffset2=rad*atan2(yy,xx) - techo=2.0 * dist/2.99792458e5 !Echo delay time - doppler=-freq*vr/2.99792458e5 !One-way Doppler + doppler=-freq8*vr/2.99792458e5 !One-way Doppler call coord(0.,0.,-1.570796,1.161639,RAMoon/rad,DecMoon/rad,el,eb) longecl_half=nint(rad*el/2.0) if(longecl_half.lt.1 .or. longecl_half.gt.180) longecl_half=180 t144=nt144(longecl_half) - tsky=(t144-2.7)*(144.0/nfreq)**2.6 + 2.7 !Tsky for obs freq + tsky=(t144-2.7)*(144.0d6/freq8)**2.6 + 2.7 !Tsky for obs freq xdop(NStation)=doppler if(NStation.eq.2) then @@ -88,7 +87,7 @@ subroutine astro(nyear,month,nday,uth,nfreq,Mygrid, & endif tr=80.0 !Good preamp - tskymin=13.0*(408.0/nfreq)**2.6 !Cold sky temperature + tskymin=13.0*(408.0d6/freq8)**2.6 !Cold sky temperature tsysmin=tskymin+tr tsys=tsky+tr dgrd=-10.0*log10(tsys/tsysmin) + dbMoon diff --git a/lib/astro0.f90 b/lib/astro0.f90 index fe047d46..9eebab9d 100644 --- a/lib/astro0.f90 +++ b/lib/astro0.f90 @@ -1,37 +1,41 @@ -subroutine astro0(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, & +subroutine astro0(nyear,month,nday,uth8,freq8,mygrid,hisgrid, & AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, & - width1,width2,w501,w502,xlst8,techo8) + width1,width2,xlst8,techo8) parameter (DEGS=57.2957795130823d0) character*6 mygrid,hisgrid real*8 AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8 real*8 dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,xnr8,dfdt,dfdt0,dt - real*8 sd8,poloffset8,day8,width1,width2,w501,w502,xlst8 - real*8 uth8,techo8 + real*8 sd8,poloffset8,width1,width2,xlst8 + real*8 uth8,techo8,freq8 + real*8 xl,b + common/librcom/xl(2),b(2) data uth8z/0.d0/ save uth=uth8 - call astro(nyear,month,nday,uth,nfreq,hisgrid,2,1, & + call astro(nyear,month,nday,uth,freq8,hisgrid,2,1, & AzSun,ElSun,AzMoon,ElMoon,ntsky,doppler00,doppler, & dbMoon,RAMoon,DecMoon,HA,Dgrd,sd,poloffset,xnr, & day,xlon2,xlat2,xlst,techo) AzMoonB8=AzMoon ElMoonB8=ElMoon - call astro(nyear,month,nday,uth,nfreq,mygrid,1,1, & + xl2=xl(1) + xl2a=xl(2) + b2=b(1) + b2a=b(2) + call astro(nyear,month,nday,uth,freq8,mygrid,1,1, & AzSun,ElSun,AzMoon,ElMoon,ntsky,doppler00,doppler, & dbMoon,RAMoon,DecMoon,HA,Dgrd,sd,poloffset,xnr, & day,xlon1,xlat1,xlst,techo) - - day8=day - xlst8=xlst + xl1=xl(1) + xl1a=xl(2) + b1=b(1) + b1a=b(2) techo8=techo - call tm2(day8,xlat1,xlon1,xl1,b1) - call tm2(day8,xlat2,xlon2,xl2,b2) - call tm2(day8+1.d0/1440.0,xlat1,xlon1,xl1a,b1a) - call tm2(day8+1.d0/1440.0,xlat2,xlon2,xl2a,b2a) - fghz=0.001*nfreq + + fghz=1.d-9*freq8 dldt1=DEGS*(xl1a-xl1) dbdt1=DEGS*(b1a-b1) dldt2=DEGS*(xl2a-xl2) @@ -41,14 +45,6 @@ subroutine astro0(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, & rate2=sqrt((dldt1+dldt2)**2 + (dbdt1+dbdt2)**2) width2=0.5*6741*fghz*rate2 - fbend=0.7 - a2=0.0045*log(fghz/fbend)/log(1.05) - if(fghz.lt.fbend) a2=0.0 - f50=0.19 * (fghz/fbend)**a2 - if(f50.gt.1.0) f50=1.0 - w501=f50*width1 - w502=f50*width2 - AzSun8=AzSun ElSun8=ElSun AzMoon8=AzMoon @@ -57,6 +53,7 @@ subroutine astro0(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, & RAMoon8=RAMoon/15.0 DecMoon8=DecMoon HA8=HA + xlst8=xlst Dgrd8=Dgrd sd8=sd poloffset8=poloffset diff --git a/lib/astrosub.f90 b/lib/astrosub.f90 index 9dccd29f..49551ce3 100644 --- a/lib/astrosub.f90 +++ b/lib/astrosub.f90 @@ -1,14 +1,55 @@ -subroutine astrosub(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, & - AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & - RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8,techo8) - - implicit real*8 (a-h,o-z) - character*6 mygrid,hisgrid - - call astro0(nyear,month,nday,uth8,nfreq,mygrid,hisgrid, & - AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & - dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, & - width1,width2,w501,w502,xlst8,techo8) - - return -end subroutine astrosub +subroutine astrosub(nyear,month,nday,uth8,freq8,mygrid,hisgrid, & + AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & + RAMoon8,DecMoon8,Dgrd8,poloffset8,xnr8,techo8,width1,width2,bTx, & + AzElFileName,jpleph) + + implicit real*8 (a-h,o-z) + character*6 mygrid,hisgrid,c1*1 + character*6 AzElFileName*(*),jpleph*(*) + character*256 jpleph_file_name + logical*1 bTx + common/jplcom/jpleph_file_name + + jpleph_file_name=jpleph + + call astro0(nyear,month,nday,uth8,freq8,mygrid,hisgrid, & + AzSun8,ElSun8,AzMoon8,ElMoon8,AzMoonB8,ElMoonB8,ntsky,ndop,ndop00, & + dbMoon8,RAMoon8,DecMoon8,HA8,Dgrd8,sd8,poloffset8,xnr8,dfdt,dfdt0, & + width1,width2,xlst8,techo8) + + if (len_trim(AzElFileName) .eq. 0) go to 999 + imin=60*uth8 + isec=3600*uth8 + ih=uth8 + im=mod(imin,60) + is=mod(isec,60) + open(15,file=AzElFileName,status='unknown',err=900) + c1='R' + nRx=1 + if(bTx) then + c1='T' + nRx=0 + endif + AzAux=0. + ElAux=0. + nfreq=freq8/1000000 + doppler=ndop + doppler00=ndop00 + write(15,1010,err=10) ih,im,is,AzMoon8,ElMoon8, & + ih,im,is,AzSun8,ElSun8, & + ih,im,is,AzAux,ElAux, & + nfreq,doppler,dfdt,doppler00,dfdt0,c1 +! TXFirst,TRPeriod,poloffset,Dgrd,xnr,ave,rms,nRx +1010 format( & + i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Moon'/ & + i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Sun'/ & + i2.2,':',i2.2,':',i2.2,',',f5.1,',',f5.1,',Source'/ & + i5,',',f8.1,',',f8.2,',',f8.1,',',f8.2,',Doppler, ',a1) +! i1,',',i3,',',f8.1,','f8.1,',',f8.1,',',f12.3,',',f12.3,',',i1,',RPol') +10 close(15) + go to 999 + +900 print*,'Error opening azel.dat' + +999 return +end subroutine astrosub diff --git a/lib/avecho.f90 b/lib/avecho.f90 new file mode 100644 index 00000000..9ee79982 --- /dev/null +++ b/lib/avecho.f90 @@ -0,0 +1,116 @@ +subroutine avecho(id2,ndop,nfrit,nqual,f1,xlevel,sigdb,snr,dfreq,width) + + integer TXLENGTH + parameter (TXLENGTH=27648) !27*1024 + parameter (NFFT=32768,NH=NFFT/2) + parameter (NZ=4096) + integer*2 id2(34560) !Buffer for Rx data + real sa(NZ) !Avg spectrum relative to initial Doppler echo freq + real sb(NZ) !Avg spectrum with Dither and changing Doppler removed + integer nsum !Number of integrations + real dop0 !Doppler shift for initial integration (Hz) + real dop !Doppler shift for current integration (Hz) + real s(8192) + real x(NFFT) + integer ipkv(1) + complex c(0:NH) + equivalence (x,c),(ipk,ipkv) + common/echocom/nclearave,nsum,blue(NZ),red(NZ) + save dop0,sa,sb + + dop=ndop + sq=0. + do i=1,TXLENGTH + x(i)=id2(i) + sq=sq + x(i)*x(i) + enddo + xlevel=10.0*log10(sq/TXLENGTH) + + if(nclearave.ne.0) nsum=0 + if(nsum.eq.0) then + dop0=dop !Remember the initial Doppler + sa=0. !Clear the average arrays + sb=0. + endif + + x(TXLENGTH+1:)=0. + x=x/TXLENGTH + call four2a(x,NFFT,1,-1,0) + df=12000.0/NFFT + do i=1,8192 !Get spectrum 0 - 3 kHz + s(i)=real(c(i))**2 + aimag(c(i))**2 + enddo + + fnominal=1500.0 !Nominal audio frequency w/o doppler or dither + ia=nint((fnominal+dop0-nfrit)/df) + ib=nint((f1+dop-nfrit)/df) + if(ia.lt.600 .or. ib.lt.600) go to 900 + if(ia.gt.7590 .or. ib.gt.7590) go to 900 + + nsum=nsum+1 + + do i=1,NZ + sa(i)=sa(i) + s(ia+i-2048) !Center at initial doppler freq + sb(i)=sb(i) + s(ib+i-2048) !Center at expected echo freq + enddo + + call pctile(sb,200,50,r0) + call pctile(sb(1800),200,50,r1) + + sum=0. + sq=0. + do i=1,NZ + y=r0 + (r1-r0)*(i-100.0)/1800.0 + blue(i)=sa(i)/y + red(i)=sb(i)/y + if(i.le.500 .or. i.ge.3597) then + sum=sum+red(i) + sq=sq + (red(i)-1.0)**2 + endif + enddo + ave=sum/1000.0 + rms=sqrt(sq/1000.0) + + redmax=maxval(red) + ipkv=maxloc(red) + fac=10.0/max(redmax,10.0) + dfreq=(ipk-2048)*df + snr=(redmax-ave)/rms + + sigdb=-99.0 + if(ave.gt.0.0) sigdb=10.0*log10(redmax/ave - 1.0) - 35.7 + + nqual=0 + if(nsum.ge.2 .and. nsum.lt.4) nqual=(snr-4)/5 + if(nsum.ge.4 .and. nsum.lt.8) nqual=(snr-3)/4 + if(nsum.ge.8 .and. nsum.lt.12) nqual=(snr-3)/3 + if(nsum.ge.12) nqual=(snr-2.5)/2.5 + if(nqual.lt.0) nqual=0 + if(nqual.gt.10) nqual=10 + +! Scale for plotting + blue=fac*blue + red=fac*red + + sum=0. + do i=ipk,ipk+300 + if(i.gt.NZ) exit + if(red(i).lt.1.0) exit + sum=sum+(red(i)-1.0) + enddo + do i=ipk-1,ipk-300,-1 + if(i.lt.1) exit + if(red(i).lt.1.0) exit + sum=sum+(red(i)-1.0) + enddo + bins=sum/(red(ipk)-1.0) + width=df*bins + nsmo=max(0.0,0.25*bins) + + do i=1,nsmo + call smo121(red,NZ) + call smo121(blue,NZ) + enddo + +900 return +end subroutine avecho diff --git a/lib/averms.f90 b/lib/averms.f90 new file mode 100644 index 00000000..904004c8 --- /dev/null +++ b/lib/averms.f90 @@ -0,0 +1,20 @@ +subroutine averms(x,n,nskip,ave,rms) + real x(n) + integer ipk(1) + + ns=0 + s=0. + sq=0. + ipk=maxloc(x) + do i=1,n + if(abs(i-ipk(1)).gt.nskip) then + s=s + x(i) + sq=sq + x(i)**2 + ns=ns+1 + endif + enddo + ave=s/ns + rms=sqrt(sq/ns - ave*ave) + + return +end subroutine averms diff --git a/lib/avg4.f90 b/lib/avg4.f90 new file mode 100644 index 00000000..fc37ec05 --- /dev/null +++ b/lib/avg4.f90 @@ -0,0 +1,2 @@ + ! The contents of this file have been migrated to lib/jt4_decode.f90 + diff --git a/lib/azdist.f90 b/lib/azdist.f90 index 528801f4..d7eb9063 100644 --- a/lib/azdist.f90 +++ b/lib/azdist.f90 @@ -1,5 +1,6 @@ -subroutine azdist(MyGrid,HisGrid,utch,nAz,nEl,nDmiles,nDkm,nHotAz,nHotABetter) +subroutine azdist(grid1,grid2,utch,nAz,nEl,nDmiles,nDkm,nHotAz,nHotABetter) + character*(*) grid1,grid2 character*6 MyGrid,HisGrid,mygrid0,hisgrid0 real*8 utch,utch0 logical HotABetter,IamEast @@ -11,6 +12,11 @@ subroutine azdist(MyGrid,HisGrid,utch,nAz,nEl,nDmiles,nDkm,nHotAz,nHotABetter) data mygrid0/" "/,hisgrid0/" "/,utch0/-999.d0/ save + MyGrid=grid1 + HisGrid=grid2 + if(ichar(grid1(5:5)).eq.0) MyGrid(5:6)=' ' + if(ichar(grid2(5:5)).eq.0) HisGrid(5:6)=' ' + if(MyGrid.eq.HisGrid) then naz=0 nel=0 @@ -43,9 +49,25 @@ subroutine azdist(MyGrid,HisGrid,utch,nAz,nEl,nDmiles,nDkm,nHotAz,nHotABetter) HotABetter=.true. go to 900 endif - call grid2deg(MyGrid,dlong1,dlat1) call grid2deg(HisGrid,dlong2,dlat2) + eps=1.e-6 + Az=0. + Dmiles=0. + Dkm=0.0 + El=0. + HotA=0. + HotB=0. + HotABetter=.true. + if(abs(dlat1-dlat2).lt.eps .and. abs(dlong1-dlong2).lt.eps) go to 900 + + difflong=mod(dlong1-dlong2+720.0,360.0) + if(abs(dlat1+dlat2).lt.eps .and. abs(difflong-180.0).lt.eps) then +! Antipodes + Dkm=20400 + go to 900 + endif + call geodist(dlat1,dlong1,dlat2,dlong2,Az,Baz,Dkm) ndkm=Dkm/100 diff --git a/lib/baddata.f90 b/lib/baddata.f90 index edacc1d5..378de8d6 100644 --- a/lib/baddata.f90 +++ b/lib/baddata.f90 @@ -15,8 +15,10 @@ logical function baddata(id2,nz) sq=sq + x*x enddo rms=sqrt(sq/nadd) - smin=min(smin,rms) - smax=max(smax,rms) + if(i.gt.6) then + smin=min(smin,rms) + smax=max(smax,rms) + endif enddo sratio=smax/(smin+1.e-30) diff --git a/lib/badmsg.f90 b/lib/badmsg.f90 new file mode 100644 index 00000000..1ebc1251 --- /dev/null +++ b/lib/badmsg.f90 @@ -0,0 +1,46 @@ +subroutine badmsg(irc,dat,nc1,nc2,ng2) + +! Get rid of a few QRA64 false decodes that cannot be correct messages. + + integer dat(12) !Decoded message (as 12 integers) + + ic1=ishft(dat(1),22) + ishft(dat(2),16) + ishft(dat(3),10)+ & + ishft(dat(4),4) + iand(ishft(dat(5),-2),15) + +! Test for "......" or "CQ 000" + if(ic1.eq.262177560 .or. ic1.eq.262177563) then + irc=-1 + return + endif + + ic2=ishft(iand(dat(5),3),26) + ishft(dat(6),20) + & + ishft(dat(7),14) + ishft(dat(8),8) + ishft(dat(9),2) + & + iand(ishft(dat(10),-4),3) + + ig=ishft(iand(dat(10),15),12) + ishft(dat(11),6) + dat(12) + +! Test for blank, -01 to -30, R-01 to R-30, RO, RRR, 73 + if(ig.ge.32401 .and. ig.le.32464) return + + if(ig.ge.14220 .and. ig.le.14229) return !-41 to -50 + if(ig.ge.14040 .and. ig.le.14049) return !-31 to -40 + + if(ig.ge.13320 .and. ig.le.13329) return !+00 to +09 + if(ig.ge.13140 .and. ig.le.13149) return !+10 to +19 + if(ig.ge.12960 .and. ig.le.12969) return !+20 to +29 + if(ig.ge.12780 .and. ig.le.12789) return !+30 to +39 + if(ig.ge.12600 .and. ig.le.12609) return !+40 to +49 + + if(ig.ge.12420 .and. ig.le.12429) return !R-41 to R-50 + if(ig.ge.12240 .and. ig.le.12249) return !R-31 to R-40 + + if(ig.ge.11520 .and. ig.le.11529) return !R+00 to R+09 + if(ig.ge.11340 .and. ig.le.11349) return !R+10 to R+19 + if(ig.ge.11160 .and. ig.le.11169) return !R+20 to R+29 + if(ig.ge.10980 .and. ig.le.10989) return !R+30 to R+39 + if(ig.ge.10800 .and. ig.le.10809) return !R+40 to R+49 + + if(ic1.eq.nc1 .and. ic2.eq.nc2 .and. ng2.ne.32401 .and. ig.ne.ng2) irc=-1 + + return +end subroutine badmsg diff --git a/lib/bpdecode144.f90 b/lib/bpdecode144.f90 new file mode 100644 index 00000000..8cbf9120 --- /dev/null +++ b/lib/bpdecode144.f90 @@ -0,0 +1,348 @@ +subroutine pltanh(x,y) + isign=+1 + z=x + if( x.lt.0 ) then + isign=-1 + z=abs(x) + endif + if( z.le. 0.8 ) then + y=0.83*x + return + elseif( z.le. 1.6 ) then + y=isign*(0.322*z+0.4064) + return + elseif( z.le. 3.0 ) then + y=isign*(0.0524*z+0.8378) + return + elseif( z.lt. 7.0 ) then + y=isign*(0.0012*z+0.9914) + return + else + y=isign*0.9998 + return + endif +end subroutine pltanh + +subroutine platanh(x,y) + isign=+1 + z=x + if( x.lt.0 ) then + isign=-1 + z=abs(x) + endif + if( z.le. 0.664 ) then + y=x/0.83 + return + elseif( z.le. 0.9217 ) then + y=isign*(z-0.4064)/0.322 + return + elseif( z.le. 0.9951 ) then + y=isign*(z-0.8378)/0.0524 + return + elseif( z.le. 0.9998 ) then + y=isign*(z-0.9914)/0.0012 + return + else + y=isign*7.0 + return + endif +end subroutine platanh + +subroutine bpdecode144(llr,maxiterations,decoded,niterations) +! +! A log-domain belief propagation decoder for the msk144 code. +! The code is a regular (128,80) code with column weight 3 and row weight 8. +! k9an August, 2016 +! +integer, parameter:: N=128, K=80, M=N-K +integer*1 codeword(N),cw(N) +integer*1 colorder(N) +integer*1 decoded(K) +integer Nm(8,M) ! 8 bits per check +integer Mn(3,N) ! 3 checks per bit +integer synd(M) +real tov(3,N) ! single precision seems to be adequate in log-domain +real toc(8,M) +real tanhtoc(8,M) +real zn(N) +real llr(N) +real Tmn + +data colorder/0,1,2,3,4,5,6,7,8,9, & + 10,11,12,13,14,15,24,26,29,30, & + 32,43,44,47,60,77,79,97,101,111, & + 96,38,64,53,93,34,59,94,74,90, & + 108,123,85,57,70,25,69,62,48,49, & + 50,51,52,33,54,55,56,21,58,36, & + 16,61,23,63,20,65,66,67,68,46, & + 22,71,72,73,31,75,76,45,78,17, & + 80,81,82,83,84,42,86,87,88,89, & + 39,91,92,35,37,95,19,27,98,99, & + 100,28,102,103,104,105,106,107,40,109, & + 110,18,112,113,114,115,116,117,118,119, & + 120,121,122,41,124,125,126,127/ + +data Mn/ & + 1, 14, 38, & + 2, 4, 41, & + 3, 19, 39, & + 5, 29, 34, & + 6, 35, 40, & + 7, 20, 45, & + 8, 28, 48, & + 9, 22, 25, & + 10, 24, 36, & + 11, 12, 37, & + 13, 43, 44, & + 15, 18, 46, & + 16, 17, 47, & + 21, 32, 33, & + 23, 30, 31, & + 26, 27, 42, & + 1, 12, 46, & + 2, 36, 38, & + 3, 5, 10, & + 4, 9, 23, & + 6, 13, 39, & + 7, 15, 17, & + 8, 18, 27, & + 11, 33, 40, & + 14, 28, 44, & + 16, 29, 31, & + 19, 20, 22, & + 21, 30, 42, & + 24, 26, 47, & + 25, 37, 48, & + 32, 34, 45, & + 8, 35, 41, & + 12, 31, 43, & + 1, 19, 21, & + 2, 43, 45, & + 3, 4, 11, & + 5, 18, 33, & + 6, 25, 47, & + 7, 28, 30, & + 9, 14, 34, & + 10, 35, 42, & + 13, 15, 22, & + 16, 37, 38, & + 17, 41, 44, & + 20, 24, 29, & + 18, 23, 39, & + 12, 26, 32, & + 27, 38, 40, & + 15, 36, 48, & + 2, 30, 46, & + 1, 4, 13, & + 3, 28, 32, & + 5, 43, 47, & + 6, 34, 46, & + 7, 9, 40, & + 8, 11, 45, & + 10, 17, 23, & + 14, 31, 35, & + 16, 22, 42, & + 19, 37, 44, & + 20, 33, 48, & + 21, 24, 41, & + 25, 27, 29, & + 26, 39, 48, & + 19, 31, 36, & + 1, 5, 7, & + 2, 29, 39, & + 3, 16, 46, & + 4, 26, 37, & + 6, 28, 45, & + 8, 22, 33, & + 9, 21, 43, & + 10, 25, 38, & + 11, 14, 24, & + 12, 17, 40, & + 13, 27, 30, & + 15, 32, 35, & + 18, 44, 47, & + 20, 23, 36, & + 34, 41, 42, & + 1, 32, 48, & + 2, 3, 33, & + 4, 29, 42, & + 5, 14, 37, & + 6, 7, 36, & + 8, 9, 39, & + 10, 13, 19, & + 11, 18, 30, & + 12, 16, 20, & + 15, 29, 44, & + 17, 34, 38, & + 6, 21, 22, & + 23, 32, 40, & + 24, 27, 46, & + 25, 41, 45, & + 7, 26, 43, & + 28, 31, 47, & + 20, 35, 38, & + 1, 33, 41, & + 2, 42, 44, & + 3, 23, 48, & + 4, 31, 45, & + 5, 8, 30, & + 9, 16, 36, & + 10, 40, 47, & + 11, 17, 46, & + 12, 21, 34, & + 13, 24, 28, & + 14, 18, 43, & + 15, 25, 26, & + 19, 27, 35, & + 22, 37, 39, & + 1, 16, 18, & + 2, 6, 20, & + 3, 30, 43, & + 4, 28, 33, & + 5, 22, 23, & + 7, 39, 42, & + 8, 12, 38, & + 9, 35, 46, & + 10, 27, 32, & + 11, 15, 34, & + 13, 36, 37, & + 14, 41, 47, & + 17, 21, 25, & + 19, 29, 45, & + 24, 31, 48, & + 26, 40, 44/ + +data Nm/ & + 1, 17, 34, 51, 66, 81, 99, 113, & + 2, 18, 35, 50, 67, 82, 100, 114, & + 3, 19, 36, 52, 68, 82, 101, 115, & + 2, 20, 36, 51, 69, 83, 102, 116, & + 4, 19, 37, 53, 66, 84, 103, 117, & + 5, 21, 38, 54, 70, 85, 92, 114, & + 6, 22, 39, 55, 66, 85, 96, 118, & + 7, 23, 32, 56, 71, 86, 103, 119, & + 8, 20, 40, 55, 72, 86, 104, 120, & + 9, 19, 41, 57, 73, 87, 105, 121, & + 10, 24, 36, 56, 74, 88, 106, 122, & + 10, 17, 33, 47, 75, 89, 107, 119, & + 11, 21, 42, 51, 76, 87, 108, 123, & + 1, 25, 40, 58, 74, 84, 109, 124, & + 12, 22, 42, 49, 77, 90, 110, 122, & + 13, 26, 43, 59, 68, 89, 104, 113, & + 13, 22, 44, 57, 75, 91, 106, 125, & + 12, 23, 37, 46, 78, 88, 109, 113, & + 3, 27, 34, 60, 65, 87, 111, 126, & + 6, 27, 45, 61, 79, 89, 98, 114, & + 14, 28, 34, 62, 72, 92, 107, 125, & + 8, 27, 42, 59, 71, 92, 112, 117, & + 15, 20, 46, 57, 79, 93, 101, 117, & + 9, 29, 45, 62, 74, 94, 108, 127, & + 8, 30, 38, 63, 73, 95, 110, 125, & + 16, 29, 47, 64, 69, 96, 110, 128, & + 16, 23, 48, 63, 76, 94, 111, 121, & + 7, 25, 39, 52, 70, 97, 108, 116, & + 4, 26, 45, 63, 67, 83, 90, 126, & + 15, 28, 39, 50, 76, 88, 103, 115, & + 15, 26, 33, 58, 65, 97, 102, 127, & + 14, 31, 47, 52, 77, 81, 93, 121, & + 14, 24, 37, 61, 71, 82, 99, 116, & + 4, 31, 40, 54, 80, 91, 107, 122, & + 5, 32, 41, 58, 77, 98, 111, 120, & + 9, 18, 49, 65, 79, 85, 104, 123, & + 10, 30, 43, 60, 69, 84, 112, 123, & + 1, 18, 43, 48, 73, 91, 98, 119, & + 3, 21, 46, 64, 67, 86, 112, 118, & + 5, 24, 48, 55, 75, 93, 105, 128, & + 2, 32, 44, 62, 80, 95, 99, 124, & + 16, 28, 41, 59, 80, 83, 100, 118, & + 11, 33, 35, 53, 72, 96, 109, 115, & + 11, 25, 44, 60, 78, 90, 100, 128, & + 6, 31, 35, 56, 70, 95, 102, 126, & + 12, 17, 50, 54, 68, 94, 106, 120, & + 13, 29, 38, 53, 78, 97, 105, 124, & + 7, 30, 49, 61, 64, 81, 101, 127/ + +nrw=8 +ncw=3 + +toc=0 +tov=0 +tanhtoc=0 + +! initial messages to checks +do j=1,M + do i=1,nrw + toc(i,j)=llr((Nm(i,j))) + enddo +enddo + +ncnt=0 + +do iter=0,maxiterations + +! Update bit log likelihood ratios + do i=1,N + zn(i)=llr(i)+sum(tov(1:ncw,i)) + enddo + +! Check to see if we have a codeword + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(:,i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 + enddo + + if( ncheck .eq. 0 ) then ! we have a codeword + 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. 3 .and. iter .ge. 5 .and. ncheck .gt. 10) then + niterations=-1 + return + endif + endif + nclast=ncheck + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,ncw ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then ! Mn(3,128) + 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:nrw,i)=tanh(-toc(1:nrw,i)/2) + enddo + + do j=1,N + do i=1,ncw + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(:,ichk),mask=Nm(:,ichk).ne.j) + call platanh(-Tmn,y) + tov(i,j)=2*y + enddo + enddo + +enddo +niterations=-1 +end subroutine bpdecode144 diff --git a/lib/bpdecode40.f90 b/lib/bpdecode40.f90 new file mode 100644 index 00000000..3a35bab4 --- /dev/null +++ b/lib/bpdecode40.f90 @@ -0,0 +1,148 @@ +subroutine bpdecode40(llr,maxiterations,decoded,niterations) +! +! A log-domain belief propagation decoder for the msk40 code. +! The code is a regular (32,16) code with column weight 3, row weights 5,6,7. +! k9an August, 2016 +! +integer, parameter:: N=32, K=16, M=N-K +integer*1 codeword(N),cw(N) +integer*1 colorder(N) +integer*1 decoded(K) +integer Nm(7,M) ! 5,6 or 7 bits per check +integer Mn(3,N) ! 3 checks per bit +integer synd(M) +real tov(3,N) +real toc(7,M) +real tanhtoc(7,M) +real zn(N) +real llr(N) +real Tmn +integer nrw(M) + +data colorder/ & + 4, 1, 2, 3, 0, 8, 6, 10, & + 13, 28, 20, 23, 17, 15, 27, 25, & + 16, 12, 18, 19, 7, 21, 22, 11, & + 24, 5, 26, 14, 9, 29, 30, 31/ + +data Mn/ & + 1, 6, 13, & + 2, 3, 14, & + 4, 8, 15, & + 5, 11, 12, & + 7, 10, 16, & + 6, 9, 15, & + 1, 11, 16, & + 2, 4, 5, & + 3, 7, 9, & + 8, 10, 12, & + 8, 13, 14, & + 1, 4, 12, & + 2, 6, 10, & + 3, 11, 15, & + 5, 9, 14, & + 7, 13, 15, & + 12, 14, 16, & + 1, 2, 8, & + 3, 5, 6, & + 4, 9, 11, & + 1, 7, 14, & + 5, 10, 13, & + 3, 4, 16, & + 2, 15, 16, & + 6, 7, 12, & + 7, 8, 11, & + 1, 9, 10, & + 2, 11, 13, & + 3, 12, 13, & + 4, 6, 14, & + 1, 5, 15, & + 8, 9, 16/ + +data Nm/ & +1, 7, 12, 18, 21, 27, 31, & +2, 8, 13, 18, 24, 28, 0, & +2, 9, 14, 19, 23, 29, 0, & +3, 8, 12, 20, 23, 30, 0, & +4, 8, 15, 19, 22, 31, 0, & +1, 6, 13, 19, 25, 30, 0, & +5, 9, 16, 21, 25, 26, 0, & +3, 10, 11, 18, 26, 32, 0, & +6, 9, 15, 20, 27, 32, 0,& +5, 10, 13, 22, 27, 0, 0, & +4, 7, 14, 20, 26, 28, 0, & +4, 10, 12, 17, 25, 29, 0, & +1, 11, 16, 22, 28, 29, 0, & +2, 11, 15, 17, 21, 30, 0, & +3, 6, 14, 16, 24, 31, 0, & +5, 7, 17, 23, 24, 32, 0/ + +data nrw/7,6,6,6,6,6,6,6,6,5,6,6,6,6,6,6/ + +ncw=3 + +toc=0 +tov=0 +tanhtoc=0 + +! initialize messages to checks +do j=1,M + do i=1,nrw(j) + toc(i,j)=llr((Nm(i,j))) + enddo +enddo + +do iter=0,maxiterations + +! Update bit log likelihood ratios (tov=0 in iteration 0). + do i=1,N + zn(i)=llr(i)+sum(tov(1:ncw,i)) + 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 + enddo + + 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 + +! 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 ! 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:7,i)=tanh(-toc(1:7,i)/2) + enddo + + do j=1,N + do i=1,ncw + 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) + tov(i,j)=2*y + enddo + enddo + +enddo +niterations=-1 +return +end subroutine bpdecode40 diff --git a/lib/bpskmetrics.dat b/lib/bpskmetrics.dat deleted file mode 100644 index 4073e578..00000000 --- a/lib/bpskmetrics.dat +++ /dev/null @@ -1,256 +0,0 @@ - -12.8 1.000 -9.966 1.000000 0.000000 - -12.7 1.000 -9.966 1.000000 0.000000 - -12.6 1.000 -9.966 1.000000 0.000000 - -12.5 1.000 -9.966 1.000000 0.000000 - -12.4 1.000 -9.966 1.000000 0.000000 - -12.3 1.000 -9.966 1.000000 0.000000 - -12.2 1.000 -9.966 1.000000 0.000000 - -12.1 1.000 -9.966 1.000000 0.000000 - -12.0 1.000 -9.966 1.000000 0.000000 - -11.9 1.000 -9.966 1.000000 0.000000 - -11.8 1.000 -9.966 1.000000 0.000000 - -11.7 1.000 -9.966 1.000000 0.000000 - -11.6 1.000 -9.966 1.000000 0.000000 - -11.5 1.000 -9.966 1.000000 0.000000 - -11.4 1.000 -9.966 1.000000 0.000000 - -11.3 1.000 -9.966 1.000000 0.000000 - -11.2 1.000 -9.966 1.000000 0.000000 - -11.1 1.000 -9.966 1.000000 0.000000 - -11.0 1.000 -9.966 1.000000 0.000000 - -10.9 1.000 -9.966 1.000000 0.000000 - -10.8 1.000 -9.966 1.000000 0.000000 - -10.7 1.000 -9.966 1.000000 0.000000 - -10.6 1.000 -9.966 1.000000 0.000000 - -10.5 1.000 -9.966 1.000000 0.000000 - -10.4 1.000 -9.966 1.000000 0.000000 - -10.3 1.000 -9.966 1.000000 0.000000 - -10.2 1.000 -9.966 1.000000 0.000000 - -10.1 1.000 -9.966 1.000000 0.000000 - -10.0 1.000 -9.966 1.000000 0.000000 - -9.9 1.000 -9.966 1.000000 0.000000 - -9.8 1.000 -9.966 1.000000 0.000000 - -9.7 1.000 -9.966 1.000000 0.000000 - -9.6 1.000 -9.966 1.000000 0.000000 - -9.5 1.000 -9.966 1.000000 0.000000 - -9.4 1.000 -9.966 1.000000 0.000000 - -9.3 1.000 -9.966 1.000000 0.000000 - -9.2 1.000 -9.966 1.000000 0.000000 - -9.1 1.000 -9.966 1.000000 0.000000 - -9.0 1.000 -9.966 1.000000 0.000000 - -8.9 1.000 -9.966 1.000000 0.000000 - -8.8 1.000 -9.966 1.000000 0.000000 - -8.7 1.000 -9.966 1.000000 0.000000 - -8.6 1.000 -9.966 1.000000 0.000000 - -8.5 1.000 -9.966 1.000000 0.000000 - -8.4 1.000 -9.966 1.000000 0.000000 - -8.3 1.000 -9.966 1.000000 0.000000 - -8.2 1.000 -9.966 1.000000 0.000000 - -8.1 1.000 -9.966 1.000000 0.000000 - -8.0 1.000 -9.966 1.000000 0.000000 - -7.9 1.000 -9.966 1.000000 0.000000 - -7.8 1.000 -9.966 1.000000 0.000000 - -7.7 1.000 -9.966 1.000000 0.000000 - -7.6 1.000 -9.966 1.000000 0.000000 - -7.5 1.000 -9.966 1.000000 0.000000 - -7.4 1.000 -9.966 1.000000 0.000000 - -7.3 1.000 -9.966 1.000000 0.000000 - -7.2 1.000 -9.966 1.000000 0.000000 - -7.1 1.000 -9.966 1.000000 0.000000 - -7.0 1.000 -9.966 1.000000 0.000000 - -6.9 1.000 -9.966 1.000000 0.000000 - -6.8 1.000 -9.966 1.000000 0.000000 - -6.7 1.000 -9.966 1.000000 0.000000 - -6.6 1.000 -9.966 1.000000 0.000000 - -6.5 1.000 -9.966 1.000000 0.000000 - -6.4 1.000 -9.966 1.000000 0.000000 - -6.3 1.000 -9.966 1.000000 0.000000 - -6.2 1.000 -9.966 1.000000 0.000000 - -6.1 1.000 -9.966 1.000000 0.000000 - -6.0 1.000 -9.966 1.000000 0.000000 - -5.9 1.000 -9.966 1.000000 0.000000 - -5.8 1.000 -9.966 1.000000 0.000000 - -5.7 1.000 -9.966 1.000000 0.000000 - -5.6 1.000 -9.966 1.000000 0.000000 - -5.5 1.000 -9.966 1.000000 0.000000 - -5.4 1.000 -9.966 1.000000 0.000000 - -5.3 1.000 -9.966 1.000000 0.000000 - -5.2 1.000 -9.966 1.000000 0.000000 - -5.1 1.000 -9.966 1.000000 0.000000 - -5.0 1.000 -9.966 1.000000 0.000000 - -4.9 1.000 -9.966 1.000000 0.000000 - -4.8 1.000 -9.966 1.000000 0.000000 - -4.7 1.000 -9.966 1.000000 0.000000 - -4.6 1.000 -9.966 1.000000 0.000000 - -4.5 1.000 -9.966 1.000000 0.000000 - -4.4 1.000 -9.966 1.000000 0.000000 - -4.3 1.000 -9.966 1.000000 0.000000 - -4.2 1.000 -9.966 1.000000 0.000000 - -4.1 1.000 -9.966 1.000000 0.000000 - -4.0 1.000 -9.966 1.000000 0.000000 - -3.9 1.000 -9.966 1.000000 0.000000 - -3.8 1.000 -9.966 1.000000 0.000000 - -3.7 1.000 -9.966 1.000000 0.000000 - -3.6 1.000 -9.966 1.000000 0.000000 - -3.5 1.000 -9.966 1.000000 0.000000 - -3.4 1.000 -9.966 1.000000 0.000000 - -3.3 1.000 -9.966 1.000000 0.000000 - -3.2 1.000 -9.966 1.000000 0.000000 - -3.1 1.000 -9.966 1.000000 0.000000 - -3.0 1.000 -9.966 1.000000 0.000000 - -2.9 1.000 -9.966 1.000000 0.000000 - -2.8 1.000 -9.966 0.999955 0.000045 - -2.7 1.000 -9.966 0.999968 0.000032 - -2.6 1.000 -9.966 0.999909 0.000091 - -2.5 1.000 -9.966 0.999983 0.000017 - -2.4 1.000 -9.966 0.999937 0.000063 - -2.3 1.000 -9.966 0.999914 0.000086 - -2.2 1.000 -9.966 0.999813 0.000187 - -2.1 1.000 -9.966 0.999775 0.000225 - -2.0 1.000 -9.966 0.999671 0.000329 - -1.9 0.999 -9.966 0.999531 0.000469 - -1.8 0.999 -9.308 0.999211 0.000789 - -1.7 0.998 -8.893 0.998948 0.001052 - -1.6 0.998 -8.191 0.998290 0.001710 - -1.5 0.996 -7.655 0.997519 0.002481 - -1.4 0.994 -7.037 0.996192 0.003808 - -1.3 0.992 -6.513 0.994525 0.005475 - -1.2 0.988 -5.931 0.991804 0.008196 - -1.1 0.982 -5.359 0.987816 0.012184 - -1.0 0.974 -4.789 0.981916 0.018084 - -0.9 0.961 -4.217 0.973110 0.026890 - -0.8 0.942 -3.672 0.960785 0.039215 - -0.7 0.915 -3.123 0.942613 0.057387 - -0.6 0.874 -2.582 0.916477 0.083523 - -0.5 0.816 -2.062 0.880296 0.119704 - -0.4 0.734 -1.573 0.831905 0.168095 - -0.3 0.619 -1.109 0.768168 0.231832 - -0.2 0.465 -0.690 0.690103 0.309897 - -0.1 0.260 -0.317 0.598759 0.401241 - 0.0 0.000 0.000 0.500000 0.500000 - 0.1 -0.317 0.260 0.401241 0.598759 - 0.2 -0.690 0.465 0.309897 0.690103 - 0.3 -1.109 0.619 0.231832 0.768168 - 0.4 -1.573 0.734 0.168095 0.831905 - 0.5 -2.062 0.816 0.119704 0.880296 - 0.6 -2.582 0.874 0.083523 0.916477 - 0.7 -3.123 0.915 0.057387 0.942613 - 0.8 -3.672 0.942 0.039215 0.960785 - 0.9 -4.217 0.961 0.026890 0.973110 - 1.0 -4.789 0.974 0.018084 0.981916 - 1.1 -5.359 0.982 0.012184 0.987816 - 1.2 -5.931 0.988 0.008196 0.991804 - 1.3 -6.513 0.992 0.005475 0.994525 - 1.4 -7.037 0.994 0.003808 0.996192 - 1.5 -7.655 0.996 0.002481 0.997519 - 1.6 -8.191 0.998 0.001710 0.998290 - 1.7 -8.893 0.998 0.001052 0.998948 - 1.8 -9.308 0.999 0.000789 0.999211 - 1.9 -9.966 0.999 0.000469 0.999531 - 2.0 -9.966 1.000 0.000329 0.999671 - 2.1 -9.966 1.000 0.000225 0.999775 - 2.2 -9.966 1.000 0.000187 0.999813 - 2.3 -9.966 1.000 0.000086 0.999914 - 2.4 -9.966 1.000 0.000063 0.999937 - 2.5 -9.966 1.000 0.000017 0.999983 - 2.6 -9.966 1.000 0.000091 0.999909 - 2.7 -9.966 1.000 0.000032 0.999968 - 2.8 -9.966 1.000 0.000045 0.999955 - 2.9 -9.966 1.000 0.000000 1.000000 - 3.0 -9.966 1.000 0.000000 1.000000 - 3.1 -9.966 1.000 0.000000 1.000000 - 3.2 -9.966 1.000 0.000000 1.000000 - 3.3 -9.966 1.000 0.000000 1.000000 - 3.4 -9.966 1.000 0.000000 1.000000 - 3.5 -9.966 1.000 0.000000 1.000000 - 3.6 -9.966 1.000 0.000000 1.000000 - 3.7 -9.966 1.000 0.000000 1.000000 - 3.8 -9.966 1.000 0.000000 1.000000 - 3.9 -9.966 1.000 0.000000 1.000000 - 4.0 -9.966 1.000 0.000000 1.000000 - 4.1 -9.966 1.000 0.000000 1.000000 - 4.2 -9.966 1.000 0.000000 1.000000 - 4.3 -9.966 1.000 0.000000 1.000000 - 4.4 -9.966 1.000 0.000000 1.000000 - 4.5 -9.966 1.000 0.000000 1.000000 - 4.6 -9.966 1.000 0.000000 1.000000 - 4.7 -9.966 1.000 0.000000 1.000000 - 4.8 -9.966 1.000 0.000000 1.000000 - 4.9 -9.966 1.000 0.000000 1.000000 - 5.0 -9.966 1.000 0.000000 1.000000 - 5.1 -9.966 1.000 0.000000 1.000000 - 5.2 -9.966 1.000 0.000000 1.000000 - 5.3 -9.966 1.000 0.000000 1.000000 - 5.4 -9.966 1.000 0.000000 1.000000 - 5.5 -9.966 1.000 0.000000 1.000000 - 5.6 -9.966 1.000 0.000000 1.000000 - 5.7 -9.966 1.000 0.000000 1.000000 - 5.8 -9.966 1.000 0.000000 1.000000 - 5.9 -9.966 1.000 0.000000 1.000000 - 6.0 -9.966 1.000 0.000000 1.000000 - 6.1 -9.966 1.000 0.000000 1.000000 - 6.2 -9.966 1.000 0.000000 1.000000 - 6.3 -9.966 1.000 0.000000 1.000000 - 6.4 -9.966 1.000 0.000000 1.000000 - 6.5 -9.966 1.000 0.000000 1.000000 - 6.6 -9.966 1.000 0.000000 1.000000 - 6.7 -9.966 1.000 0.000000 1.000000 - 6.8 -9.966 1.000 0.000000 1.000000 - 6.9 -9.966 1.000 0.000000 1.000000 - 7.0 -9.966 1.000 0.000000 1.000000 - 7.1 -9.966 1.000 0.000000 1.000000 - 7.2 -9.966 1.000 0.000000 1.000000 - 7.3 -9.966 1.000 0.000000 1.000000 - 7.4 -9.966 1.000 0.000000 1.000000 - 7.5 -9.966 1.000 0.000000 1.000000 - 7.6 -9.966 1.000 0.000000 1.000000 - 7.7 -9.966 1.000 0.000000 1.000000 - 7.8 -9.966 1.000 0.000000 1.000000 - 7.9 -9.966 1.000 0.000000 1.000000 - 8.0 -9.966 1.000 0.000000 1.000000 - 8.1 -9.966 1.000 0.000000 1.000000 - 8.2 -9.966 1.000 0.000000 1.000000 - 8.3 -9.966 1.000 0.000000 1.000000 - 8.4 -9.966 1.000 0.000000 1.000000 - 8.5 -9.966 1.000 0.000000 1.000000 - 8.6 -9.966 1.000 0.000000 1.000000 - 8.7 -9.966 1.000 0.000000 1.000000 - 8.8 -9.966 1.000 0.000000 1.000000 - 8.9 -9.966 1.000 0.000000 1.000000 - 9.0 -9.966 1.000 0.000000 1.000000 - 9.1 -9.966 1.000 0.000000 1.000000 - 9.2 -9.966 1.000 0.000000 1.000000 - 9.3 -9.966 1.000 0.000000 1.000000 - 9.4 -9.966 1.000 0.000000 1.000000 - 9.5 -9.966 1.000 0.000000 1.000000 - 9.6 -9.966 1.000 0.000000 1.000000 - 9.7 -9.966 1.000 0.000000 1.000000 - 9.8 -9.966 1.000 0.000000 1.000000 - 9.9 -9.966 1.000 0.000000 1.000000 - 10.0 -9.966 1.000 0.000000 1.000000 - 10.1 -9.966 1.000 0.000000 1.000000 - 10.2 -9.966 1.000 0.000000 1.000000 - 10.3 -9.966 1.000 0.000000 1.000000 - 10.4 -9.966 1.000 0.000000 1.000000 - 10.5 -9.966 1.000 0.000000 1.000000 - 10.6 -9.966 1.000 0.000000 1.000000 - 10.7 -9.966 1.000 0.000000 1.000000 - 10.8 -9.966 1.000 0.000000 1.000000 - 10.9 -9.966 1.000 0.000000 1.000000 - 11.0 -9.966 1.000 0.000000 1.000000 - 11.1 -9.966 1.000 0.000000 1.000000 - 11.2 -9.966 1.000 0.000000 1.000000 - 11.3 -9.966 1.000 0.000000 1.000000 - 11.4 -9.966 1.000 0.000000 1.000000 - 11.5 -9.966 1.000 0.000000 1.000000 - 11.6 -9.966 1.000 0.000000 1.000000 - 11.7 -9.966 1.000 0.000000 1.000000 - 11.8 -9.966 1.000 0.000000 1.000000 - 11.9 -9.966 1.000 0.000000 1.000000 - 12.0 -9.966 1.000 0.000000 1.000000 - 12.1 -9.966 1.000 0.000000 1.000000 - 12.2 -9.966 1.000 0.000000 1.000000 - 12.3 -9.966 1.000 0.000000 1.000000 - 12.4 -9.966 1.000 0.000000 1.000000 - 12.5 -9.966 1.000 0.000000 1.000000 - 12.6 -9.966 1.000 0.000000 1.000000 - 12.7 -9.966 1.000 0.000000 1.000000 diff --git a/lib/calibrate.f90 b/lib/calibrate.f90 new file mode 100644 index 00000000..a27c400a --- /dev/null +++ b/lib/calibrate.f90 @@ -0,0 +1,96 @@ +subroutine calibrate(data_dir,iz,a,b,rms,sigmaa,sigmab,irc) + +! Average groups of frequency-calibration measurements, then fit a +! straight line for slope and intercept. + + parameter (NZ=1000) + implicit real*8 (a-h,o-z) + character*(*) data_dir + character*256 infile,outfile + character*8 cutc,cutc1 + character*1 c1 + real*8 fd(NZ),deltaf(NZ),r(NZ),rmsd(NZ) + integer nn(NZ) + + infile=trim(data_dir)//'fmt.all' + outfile=trim(data_dir)//'fcal2.out' + + open(10,file=trim(infile),status='old',err=996) + open(12,file=trim(outfile),status='unknown',err=997) + + nkhz0=0 + sum=0.d0 + sumsq=0.d0 + n=0 + j=0 + do i=1,99999 + read(10,*,end=10,err=995) cutc,nkHz,ncal,noffset,faudio,df,dblevel,snr + if((nkHz.ne.nkHz0) .and. i.ne.1) then + ave=sum/n + rms=0.d0 + if(n.gt.1) then + rms=sqrt(abs(sumsq - sum*sum/n)/(n-1.d0)) + endif + fMHz=0.001d0*nkHz0 + j=j+1 + fd(j)=fMHz + deltaf(j)=ave + r(j)=0.d0 + rmsd(j)=rms + nn(j)=n + sum=0.d0 + sumsq=0.d0 + n=0 + endif + dial_error=faudio-noffset + sum=sum + dial_error + sumsq=sumsq + dial_error**2 + n=n+1 + if(n.eq.1) then + cutc1=cutc + ncal0=ncal + endif + nkHz0=nkHz + enddo + +10 ave=sum/n + rms=0.d0 + if(n.gt.0) then + rms=sqrt((sumsq - sum*sum/n)/(n-1.d0)) + endif + fMHz=0.001d0*nkHz + j=j+1 + fd(j)=fMHz + deltaf(j)=ave + r(j)=0.d0 + rmsd(j)=rms + nn(j)=n + iz=j + if(iz.lt.2) go to 998 + + call fitcal(fd,deltaf,r,iz,a,b,sigmaa,sigmab,rms) + + write(12,1002) +1002 format(' Freq DF Meas Freq N rms Resid'/ & + ' (MHz) (Hz) (MHz) (Hz) (Hz)'/ & + '----------------------------------------------------') + irc=0 + do i=1,iz + fm=fd(i) + 1.d-6*deltaf(i) + c1=' ' + if(rmsd(i).gt.1.0d0) c1='*' + write(12,1012) fd(i),deltaf(i),fm,nn(i),rmsd(i),r(i),c1 +1012 format(f8.3,f9.3,f14.9,i4,f7.2,f9.3,1x,a1) + enddo + go to 999 + +995 irc=-4; iz=i; go to 999 +996 irc=-1; go to 999 +997 irc=-2; go to 999 +998 irc=-3 +999 continue + close(10) + close(12) + + return +end subroutine calibrate diff --git a/lib/ccf2.f90 b/lib/ccf2.f90 index 4e74a52e..194608d1 100644 --- a/lib/ccf2.f90 +++ b/lib/ccf2.f90 @@ -1,7 +1,6 @@ -subroutine ccf2(ss,nz,nflip,ccfbest,lagpk) +subroutine ccf2(ss,nz,nflip,ccfbest,xlagpk) - parameter (LAGMAX=60) -! parameter (LAGMAX=200) + parameter (LAGMIN=-86,LAGMAX=258) real ss(nz) real ccf(-LAGMAX:LAGMAX) integer npr(126) @@ -18,15 +17,15 @@ subroutine ccf2(ss,nz,nflip,ccfbest,lagpk) save ccfbest=0. - lag1=-LAGMAX + lag1=LAGMIN lag2=LAGMAX do lag=lag1,lag2 s0=0. s1=0. do i=1,126 - j=2*(8*i + 43) + lag + j=16*(i-1)+1 + lag if(j.ge.1 .and. j.le.nz-8) then - x=ss(j)+ss(j+8) !Add two half-symbol contributions + x=ss(j) if(npr(i).eq.0) then s0=s0 + x else @@ -38,8 +37,12 @@ subroutine ccf2(ss,nz,nflip,ccfbest,lagpk) if(ccf(lag).gt.ccfbest) then ccfbest=ccf(lag) lagpk=lag + xlagpk=lagpk endif enddo - + if( lagpk.gt.-LAGMAX .and. lagpk.lt.LAGMAX) then + call peakup(ccf(lagpk-1),ccf(lagpk),ccf(lagpk+1),dx) + xlagpk=lagpk+dx + endif return end subroutine ccf2 diff --git a/lib/chkcall.f90 b/lib/chkcall.f90 new file mode 100644 index 00000000..23900748 --- /dev/null +++ b/lib/chkcall.f90 @@ -0,0 +1,58 @@ +subroutine chkcall(w,bc,cok) + +! Check "w" to see if it could be a valid standard callsign or a valid +! compound callsign. +! Return base call "bc" and a logical "cok" indicator. + + character w*13 !A putative callsign + character bc*6 !Base call (tentative) + character c*1 + logical cok,isdigit,isletter + + isdigit(c)=(ichar(c).ge.ichar('0')) .and. (ichar(c).le.ichar('9')) + isletter(c)=(ichar(c).ge.ichar('A')) .and. (ichar(c).le.ichar('Z')) + + cok=.true. + bc=w(1:6) + n1=len_trim(w) + if(n1.gt.11) go to 100 + if(index(w,'.').ge.1) go to 100 + if(index(w,'+').ge.1) go to 100 + if(index(w,'-').ge.1) go to 100 + if(index(w,'?').ge.1) go to 100 + if(n1.gt.6 .and. index(w,'/').le.0) go to 100 + + i0=index(w,'/') + if(max(i0-1,n1-i0).gt.6) go to 100 !Base call must be < 7 characters + if(i0.ge.2 .and. i0.le.n1-1) then !Extract base call from compound call + if(i0-1.le.n1-i0) bc=w(i0+1:n1)//' ' + if(i0-1.gt.n1-i0) bc=w(1:i0-1)//' ' + endif + + nbc=len_trim(bc) + if(nbc.gt.6) go to 100 !Base call should have no more than 6 characters + +! One of first two characters (c1 or c2) must be a letter + if((.not.isletter(bc(1:1))) .and. (.not.isletter(bc(2:2)))) go to 100 + if(bc(1:1).eq.'Q') go to 100 !Calls don't start with Q + +! Must have a digit in 2nd or 3rd position + i1=0 + if(isdigit(bc(2:2))) i1=2 + if(isdigit(bc(3:3))) i1=3 + if(i1.eq.0) go to 100 + +! Callsign must have a suffix of 1-3 letters + if(i1.eq.nbc) go to 100 + n=0 + do i=i1+1,nbc + j=ichar(bc(i:i)) + if(j.lt.ichar('A') .or. j.gt.ichar('Z')) go to 100 + n=n+1 + enddo + if(n.ge.1 .and. n.le.3) go to 200 + +100 cok=.false. + +200 return +end subroutine chkcall diff --git a/lib/chkfft.f90 b/lib/chkfft.f90 index 84208a91..f0ab4e8a 100644 --- a/lib/chkfft.f90 +++ b/lib/chkfft.f90 @@ -42,6 +42,8 @@ program chkfft call getarg(5,arg) read(arg,*) npatience + call sgran() + if(list) write(*,1000) infile,nr,nw,ncomplex,npatience 1000 format(/'infile: ',a12,' nr:',i2,' nw',i2,' nc:',i2,' np:',i2/) if(.not.list) write(*,1002) nfft,nr,nw,ncomplex,npatience diff --git a/lib/chkfft3.f90 b/lib/chkfft3.f90 index d42203a8..cb9df062 100644 --- a/lib/chkfft3.f90 +++ b/lib/chkfft3.f90 @@ -56,13 +56,15 @@ program chkfft if(npatience.eq.4) nflags=FFTW_EXHAUSTIVE open(12,file='chkfft.out',status='unknown') - open(13,file='fftwf_wisdom.dat',status='unknown') if(nr.ne.0) then - call import_wisdom_from_file(isuccess,13) - if(isuccess.eq.0) then + isuccess=fftwf_import_wisdom_from_filename('fftwf_wisdom.dat'//char(0)) + if(isuccess.eq.1) then write(*,1010) -1010 format('Failed to import FFTW wisdom.') +1010 format('Imported FFTW wisdom.') + else + write(*,1012) +1012 format('Failed to import FFTW wisdom.') go to 999 endif endif @@ -164,10 +166,9 @@ program chkfft 900 continue if(nw.eq.1) then - rewind 13 - call export_wisdom_to_file(13) -! write(*,1070) -!1070 format(/'Exported FFTW wisdom') + ierr=fftwf_export_wisdom_to_filename('fftwf_wisdom.dat'//char(0)) + write(*,1070) +1070 format(/'Exported FFTW wisdom') endif call fftwf_destroy_plan(plan1) diff --git a/lib/chkmsg.f90 b/lib/chkmsg.f90 index 72e0cccb..ad0b5a13 100644 --- a/lib/chkmsg.f90 +++ b/lib/chkmsg.f90 @@ -23,9 +23,9 @@ subroutine chkmsg(message,cok,nspecial,flip) endif endif - if(message(1:3).eq.'RO ') nspecial=2 - if(message(1:4).eq.'RRR ') nspecial=3 - if(message(1:3).eq.'73 ') nspecial=4 + if(message.eq.'RO ') nspecial=2 + if(message.eq.'RRR ') nspecial=3 + if(message.eq.'73 ') nspecial=4 return end subroutine chkmsg diff --git a/lib/code426.f90 b/lib/code426.f90 new file mode 100644 index 00000000..111c5492 --- /dev/null +++ b/lib/code426.f90 @@ -0,0 +1,62 @@ +program code426 + + parameter (MZ=26) !Number of 4-FSK symbols + parameter (JZMAX=64) !Desired number of codewords + integer ic(MZ,JZMAX),icsave(MZ) + real c(MZ) + character*12 arg + + nargs=iargc() + if(nargs.ne.2) then + print*,'Usage: code426 ' + print*,'Example: code426 64 10000000' + go to 999 + endif + call getarg(1,arg) + read(arg,*) nmsgs + call getarg(2,arg) + read(arg,*) iters + + call init_random_seed() + + open(13,file='code426.out',status='unknown') + + write(*,1002) nmsgs,iters + write(13,1002) nmsgs,iters +1002 format('Nmsgs:',i4,' Iters:',i10/(66('-'))) + + do i=1,MZ !Create 4 mutually orthogonal codewords + ic(i,1)=mod(i-1,4) + ic(i,2)=mod(i,4) + ic(i,3)=mod(i+1,4) + ic(i,4)=mod(i+2,4) + enddo + + do j=1,4 !Write them out + write(*,1000) j,MZ,ic(1:MZ,j) + write(13,1000) j,MZ,ic(1:MZ,j) +1000 format(2i5,3x,26i2) + enddo + + do j=5,nmsgs !Find codewords up to j=nmsgs with maximum + npk=0 !distance from all the rest + do i=1,iters + call random_number(c) !Generate a random codeword candidate + ic(1:MZ,j)=int(4*c) !Convert real to integer +! nd=MZ +! do k=1,j-1 !Test candidate against all others in list +! n=count(ic(1:MZ,j).ne.ic(1:MZ,k)) +! nd=min(n,nd) +! enddo + call dist426(ic,j,mind) + if(mind.gt.npk) then + npk=mind + icsave=ic(1:MZ,j) !Best candidate so far, save it +! if(npk.ge.19) exit !It won't get any better... + endif + enddo + write(*,1000) j,npk,ic(1:MZ,j) + write(13,1000) j,npk,ic(1:MZ,j) + enddo + +999 end program code426 diff --git a/lib/constants.f90 b/lib/constants.f90 index 2acf6bbd..ea872e8a 100644 --- a/lib/constants.f90 +++ b/lib/constants.f90 @@ -1,5 +1,5 @@ - parameter (NTMAX=120) - parameter (NMAX=NTMAX*12000) !Total sample intervals per 30 minutes - parameter (NDMAX=NTMAX*1500) !Sample intervals at 1500 Hz rate - parameter (NSMAX=6827) !Max length of saved spectra - parameter (MAXFFT3=16384) + integer, parameter :: NTMAX=300 + integer, parameter :: NMAX=NTMAX*12000 !Total sample intervals (one minute) + integer, parameter :: NDMAX=NTMAX*1500 !Sample intervals at 1500 Hz rate + integer, parameter :: NSMAX=6827 !Max length of saved spectra + integer, parameter :: MAXFFT3=16384 diff --git a/lib/contest72.f90 b/lib/contest72.f90 new file mode 100644 index 00000000..f637c432 --- /dev/null +++ b/lib/contest72.f90 @@ -0,0 +1,89 @@ +program contest72 + + use packjt + integer dat(12) + logical text,bcontest,ok + character*22 msg,msg0,msg1 + character*72 ct1,ct2 + character*12 callsign1,callsign2 + character*1 c0 + character*42 c + character*6 mygrid + data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ +-./?'/ + data bcontest/.true./ + data mygrid/"EM48 "/ + +! itype Message Type +!-------------------- +! 1 Standardd message +! 2 Type 1 prefix +! 3 Type 1 suffix +! 4 Type 2 prefix +! 5 Type 2 suffix +! 6 Free text +! -1 Does not decode correctly + + nargs=iargc() + if(nargs.eq.0) open(10,file='contest_msgs.txt',status='old') + + nn=0 + do imsg=1,9999 + if(nargs.eq.1) then + if(imsg.gt.1) exit + call getarg(1,msg0) + else + read(10,1001,end=999) msg0 +1001 format(a22) + endif + msg=msg0 + call packmsg(msg,dat,itype,bcontest) + call unpackmsg(dat,msg1,bcontest,mygrid) + ok=msg1.eq.msg0 + if(msg0.eq.' ') then + write(*,1002) + else + if(jt_c2(1:1).eq.'W') msg0=' '//msg0(1:20) + nn=nn+1 + write(*,1002) nn,msg0,ok,jt_itype,jt_nc1,jt_nc2,jt_ng,jt_k1,jt_k2 +1002 format(i1,'. ',a22,L2,i2,2i10,i6,2i8) + if(index(msg1,' 73 ').gt.4) nn=0 + endif + if(.not.ok) print*,msg0,msg1 + if(itype.lt.0 .or. itype.eq.6) cycle + + if(msg(1:3).eq.'CQ ') then + m=2 + write(ct1,1010) dat +1010 format(12b6.6) +! write(*,1014) ct1 +1014 format(a72) + cycle + endif + + i1=index(msg,'<') + if(i1.eq.1) then + m=0 + cycle + endif + + if(i.ge.5) then + m=3 + cycle + endif + + if(msg(1:6).eq.'73 CQ ') then + m=4 + cycle + endif + + call packmsg(msg,dat,itype,.false.) + write(ct1,1010) dat + call packtext(msg,nc1,nc2,ng,.false.,'') +! write(ct2,1012) nc1,nc2,ng+32768 +!1012 format(2b28.28,b16.16) +! write(*,1014) ct1 +! write(*,1014) ct2 +! write(*,1014) + enddo + +999 end program contest72 diff --git a/lib/count4.f90 b/lib/count4.f90 new file mode 100644 index 00000000..3c8c5ddc --- /dev/null +++ b/lib/count4.f90 @@ -0,0 +1,54 @@ +program count4 + + parameter(NMAX=1000) + character*47 line + real snr(NMAX) + real dt(NMAX) + real f(NMAX) + + open(10,file='/users/joe/appdata/local/wsjt-x/all.txt',status='old') + + read(10,1000,end=10) line +1000 format(a47) + + nsync1=0 + nsync2=0 + n1=0 + n2=0 + nerr=0 + + do i=1,99999 + read(10,1000,end=10) line + if(line(47:47).ne.' ') cycle !Skip average decodes + if(line(20:20).eq.'*') nsync1=nsync1+1 + if(line(20:20).eq.'#') nsync2=nsync2+1 + if(line(22:34).eq.'CQ K1ABC FN42') then + n2=n2+1 !Correlation decode + read(line,1002) snr(n2),dt(n2),f(n2) +1002 format(4x,f4.0,f5.2,f5.0) + if(line(42:42).eq.'*') n1=n1+1 !Convolutional decode + else + if(line(22:34).ne.' ') nerr=nerr+1 + endif + enddo + +10 call stats(snr,n2,snrave,snrdev) + call stats(dt,n2,dtave,dtdev) + call stats(f,n2,fave,fdev) + +write(*,1010) nsync1,nsync2,n1,n2,nerr,snrave,dtave,fave,snrdev,dtdev,fdev +1010 format(5i5,f7.1,f7.2,f7.0/25x,f7.1,f7.2,f7.0) + +end program count4 + +subroutine stats(x,nz,ave,rms) + real x(nz) + + ave=0. + rms=0. + if(nz.gt.0) ave=sum(x)/nz + x=x-ave + if(nz.gt.1) rms=sqrt(dot_product(x,x)/(nz-1)) + + return +end subroutine stats diff --git a/lib/crc.f90 b/lib/crc.f90 new file mode 100644 index 00000000..6e5c262e --- /dev/null +++ b/lib/crc.f90 @@ -0,0 +1,37 @@ +module crc + use, intrinsic :: iso_c_binding, only: c_int, c_loc, c_int8_t, c_bool, c_short + interface + function crc12 (data, length) bind (C, name="crc12") + use, intrinsic :: iso_c_binding, only: c_short, c_ptr, c_int + implicit none + integer (c_short) :: crc12 + type (c_ptr), value :: data + integer (c_int), value :: length + end function crc12 + + function crc12_check (data, length) bind (C, name="crc12_check") + use, intrinsic :: iso_c_binding, only: c_bool, c_ptr, c_int + implicit none + logical (c_bool) :: crc12_check + type (c_ptr), value :: data + integer (c_int), value :: length + end function crc12_check + + function crc10 (data, length) bind (C, name="crc10") + use, intrinsic :: iso_c_binding, only: c_short, c_ptr, c_int + implicit none + integer (c_short) :: crc10 + type (c_ptr), value :: data + integer (c_int), value :: length + end function crc10 + + function crc10_check (data, length) bind (C, name="crc10_check") + use, intrinsic :: iso_c_binding, only: c_bool, c_ptr, c_int + implicit none + logical (c_bool) :: crc10_check + type (c_ptr), value :: data + integer (c_int), value :: length + end function crc10_check + + end interface +end module crc diff --git a/lib/crc10.cpp b/lib/crc10.cpp new file mode 100644 index 00000000..93f66493 --- /dev/null +++ b/lib/crc10.cpp @@ -0,0 +1,31 @@ +#include +#include + +extern "C" +{ + short crc10 (unsigned char const * data, int length); + bool crc10_check (unsigned char const * data, int length); +} + +#define POLY 0x08f + +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define TRUNCATED_POLYNOMIAL POLY +#else +namespace +{ + unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; +} +#endif + +// assumes CRC is last 16 bits of the data and is set to zero +// caller should assign the returned CRC into the message in big endian byte order +short crc10 (unsigned char const * data, int length) +{ + return boost::augmented_crc<10, TRUNCATED_POLYNOMIAL> (data, length); +} + +bool crc10_check (unsigned char const * data, int length) +{ + return !boost::augmented_crc<10, TRUNCATED_POLYNOMIAL> (data, length); +} diff --git a/lib/crc12.cpp b/lib/crc12.cpp new file mode 100644 index 00000000..44e50fe7 --- /dev/null +++ b/lib/crc12.cpp @@ -0,0 +1,31 @@ +#include +#include + +extern "C" +{ + short crc12 (unsigned char const * data, int length); + bool crc12_check (unsigned char const * data, int length); +} + +#define POLY 0xc06 + +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define TRUNCATED_POLYNOMIAL POLY +#else +namespace +{ + unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; +} +#endif + +// assumes CRC is last 16 bits of the data and is set to zero +// caller should assign the returned CRC into the message in big endian byte order +short crc12 (unsigned char const * data, int length) +{ + return boost::augmented_crc<12, TRUNCATED_POLYNOMIAL> (data, length); +} + +bool crc12_check (unsigned char const * data, int length) +{ + return !boost::augmented_crc<12, TRUNCATED_POLYNOMIAL> (data, length); +} diff --git a/lib/dcoord.f90 b/lib/dcoord.f90 deleted file mode 100644 index 683be0a0..00000000 --- a/lib/dcoord.f90 +++ /dev/null @@ -1,40 +0,0 @@ -SUBROUTINE DCOORD(A0,B0,AP,BP,A1,B1,A2,B2) - - implicit real*8 (a-h,o-z) -! Examples: -! 1. From ha,dec to az,el: -! call coord(pi,pio2-lat,0.,lat,ha,dec,az,el) -! 2. From az,el to ha,dec: -! call coord(pi,pio2-lat,0.,lat,az,el,ha,dec) -! 3. From ra,dec to l,b -! call coord(4.635594495,-0.504691042,3.355395488,0.478220215, -! ra,dec,l,b) -! 4. From l,b to ra,dec -! call coord(1.705981071d0,-1.050357016d0,2.146800277d0, -! 0.478220215d0,l,b,ra,dec) -! 5. From ecliptic latitude (eb) and longitude (el) to ra, dec: -! call coord(0.d0,0.d0,-pio2,pio2-23.443*pi/180,ra,dec,el,eb) - - SB0=sin(B0) - CB0=cos(B0) - SBP=sin(BP) - CBP=cos(BP) - SB1=sin(B1) - CB1=cos(B1) - SB2=SBP*SB1 + CBP*CB1*cos(AP-A1) - CB2=SQRT(1.D0-SB2**2) - B2=atan(SB2/CB2) - SAA=sin(AP-A1)*CB1/CB2 - CAA=(SB1-SB2*SBP)/(CB2*CBP) - CBB=SB0/CBP - SBB=sin(AP-A0)*CB0 - SA2=SAA*CBB-CAA*SBB - CA2=CAA*CBB+SAA*SBB - TA2O2=0.0 !Shut up compiler warnings. -db - IF(CA2.LE.0.D0) TA2O2=(1.D0-CA2)/SA2 - IF(CA2.GT.0.D0) TA2O2=SA2/(1.D0+CA2) - A2=2.D0*atan(TA2O2) - IF(A2.LT.0.D0) A2=A2+6.2831853071795864D0 - - RETURN -END SUBROUTINE DCOORD diff --git a/lib/decjt9.f90 b/lib/decjt9.f90 deleted file mode 100644 index 0f549803..00000000 --- a/lib/decjt9.f90 +++ /dev/null @@ -1,146 +0,0 @@ -subroutine decjt9(ss,id2,nutc,nfqso,newdat,npts8,nfa,nfsplit,nfb,ntol, & - nzhsym,nagain,ndepth,nmode) - - include 'constants.f90' - real ss(184,NSMAX) - character*22 msg - character*500 infile - real*4 ccfred(NSMAX) - real*4 red2(NSMAX) - logical ccfok(NSMAX) - logical done(NSMAX) - integer*2 id2(NTMAX*12000) - integer*1 i1SoftSymbols(207) - common/decstats/num65,numbm,numkv,num9,numfano,infile - save ccfred,red2 - - nsynced=0 - ndecoded=0 - nsps=6912 !Params for JT9-1 - df3=1500.0/2048.0 - - tstep=0.5*nsps/12000.0 !Half-symbol step (seconds) - done=.false. - - nf0=0 - nf1=nfa - if(nmode.eq.65+9) nf1=nfsplit - ia=max(1,nint((nf1-nf0)/df3)) - ib=min(NSMAX,nint((nfb-nf0)/df3)) - lag1=-int(2.5/tstep + 0.9999) - lag2=int(5.0/tstep + 0.9999) - if(newdat.ne.0) then - call timer('sync9 ',0) - call sync9(ss,nzhsym,lag1,lag2,ia,ib,ccfred,red2,ipk) - call timer('sync9 ',1) - endif - - nsps8=nsps/8 - df8=1500.0/nsps8 - dblim=db(864.0/nsps8) - 26.2 - - do nqd=1,0,-1 - limit=5000 - ccflim=3.0 - red2lim=1.6 - schklim=2.2 - if(ndepth.eq.2) then - limit=10000 - ccflim=2.7 - endif - if(ndepth.ge.3 .or. nqd.eq.1) then - limit=30000 - ccflim=2.5 - schklim=2.0 - endif - if(nagain.ne.0) then - limit=100000 - ccflim=2.4 - schklim=1.8 - endif - ccfok=.false. - - if(nqd.eq.1) then - nfa1=nfqso-ntol - nfb1=nfqso+ntol - ia=max(1,nint((nfa1-nf0)/df3)) - ib=min(NSMAX,nint((nfb1-nf0)/df3)) - ccfok(ia:ib)=(ccfred(ia:ib).gt.(ccflim-2.0)) .and. & - (red2(ia:ib).gt.(red2lim-1.0)) - ia1=ia - ib1=ib - else - nfa1=nf1 - nfb1=nfb - ia=max(1,nint((nfa1-nf0)/df3)) - ib=min(NSMAX,nint((nfb1-nf0)/df3)) - do i=ia,ib - ccfok(i)=ccfred(i).gt.ccflim .and. red2(i).gt.red2lim - enddo - ccfok(ia1:ib1)=.false. - endif - - fgood=0. - do i=ia,ib - if(done(i) .or. (.not.ccfok(i))) cycle - f=(i-1)*df3 - if(nqd.eq.1 .or. & - (ccfred(i).ge.ccflim .and. abs(f-fgood).gt.10.0*df8)) then - - if(nqd.eq.0) nfreqs0=nfreqs0+1 - if(nqd.eq.1) nfreqs1=nfreqs1+1 - - call timer('softsym ',0) - fpk=nf0 + df3*(i-1) - call softsym(id2,npts8,nsps8,newdat,fpk,syncpk,snrdb,xdt, & - freq,drift,a3,schk,i1SoftSymbols) - call timer('softsym ',1) - - sync=(syncpk+1)/4.0 - if(nqd.eq.1 .and. ((sync.lt.0.5) .or. (schk.lt.1.0))) cycle - if(nqd.ne.1 .and. ((sync.lt.1.0) .or. (schk.lt.1.5))) cycle - - call timer('jt9fano ',0) - call jt9fano(i1SoftSymbols,limit,nlim,msg) - call timer('jt9fano ',1) - - if(sync.lt.0.0 .or. snrdb.lt.dblim-2.0) sync=0.0 - nsync=int(sync) - if(nsync.gt.10) nsync=10 - nsnr=nint(snrdb) - ndrift=nint(drift/df3) - num9=num9+1 - - if(msg.ne.' ') then - numfano=numfano+1 - if(nqd.eq.0) ndecodes0=ndecodes0+1 - if(nqd.eq.1) ndecodes1=ndecodes1+1 - -!$omp critical(decode_results) ! serialize writes - see also jt65a.f90 - write(*,1000) nutc,nsnr,xdt,nint(freq),msg -1000 format(i4.4,i4,f5.1,i5,1x,'@',1x,a22) -! i1=index(infile,'.wav') -! write(*,1000) infile(i1-11:i1-1),nsnr,xdt,nint(freq),msg, & -! schk,drift,a3,nlim -!1000 format(a11,i4,f5.1,i5,1x,'@',1x,a22,3f6.1,i6) - write(13,1002) nutc,nsync,nsnr,xdt,freq,ndrift,msg -1002 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a22,' JT9') - call flush(6) - call flush(13) -!$omp end critical(decode_results) - - iaa=max(1,i-1) - ibb=min(NSMAX,i+22) - fgood=f - nsynced=1 - ndecoded=1 - ccfok(iaa:ibb)=.false. - done(iaa:ibb)=.true. - endif - endif - enddo - if(nagain.ne.0) exit - enddo - - return -end subroutine decjt9 diff --git a/lib/decode4.f90 b/lib/decode4.f90 new file mode 100644 index 00000000..e0596ed1 --- /dev/null +++ b/lib/decode4.f90 @@ -0,0 +1,112 @@ +subroutine decode4(dat,npts,dtx,nfreq,flip,mode4,ndepth,neme,minw, & + mycall,hiscall,hisgrid,decoded,nfano,deepbest,qbest,ichbest) + +! Decodes JT4 data, assuming that DT and DF have already been determined. +! Input dat(npts) has already been downsampled by 2: rate = 11025/2. +! ### NB: this initial downsampling should be removed in WSJT-X, since +! it restricts the useful bandwidth to < 2.7 kHz. + + use jt4 + real dat(npts) !Raw data + character decoded*22,deepmsg*22,deepbest*22 + character*12 mycall,hiscall + character*6 hisgrid + real*8 dt,df,phi,f0,dphi,twopi,phi1,dphi1 + complex*16 cz,cz1,c0,c1 + real*4 sym(207) + + twopi=8*atan(1.d0) + dt=2.d0/11025 !Sample interval (2x downsampled data) + df=11025.d0/2520.d0 !Tone separation for JT4A mode + nsym=206 + amp=15.0 + istart=nint((dtx+0.8)/dt) !Start index for synced FFTs + if(istart.lt.0) istart=0 + nchips=0 + qbest=0. + qtop=0. + deepmsg=' ' + ichbest=-1 + c0=0. + k=istart + phi=0.d0 + phi1=0.d0 + + ich1=minw+1 + do ich=1,7 + if(nch(ich).le.mode4) ich2=ich + enddo + + do ich=ich1,ich2 + nchips=min(nch(ich),70) + nspchip=1260/nchips + k=istart + phi=0.d0 + phi1=0.d0 + fac2=1.e-8 * sqrt(float(mode4)) + do j=1,nsym+1 + if(flip.gt.0.0) then + f0=nfreq + (npr(j))*mode4*df + f1=nfreq + (2+npr(j))*mode4*df + else + f0=nfreq + (1-npr(j))*mode4*df + f1=nfreq + (3-npr(j))*mode4*df + endif + dphi=twopi*dt*f0 + dphi1=twopi*dt*f1 + sq0=0. + sq1=0. + do nc=1,nchips + phi=0.d0 + phi1=0.d0 + c0=0. + c1=0. + do i=1,nspchip + k=k+1 + phi=phi+dphi + phi1=phi1+dphi1 + cz=dcmplx(cos(phi),-sin(phi)) + cz1=dcmplx(cos(phi1),-sin(phi1)) + if(k.le.npts) then + c0=c0 + dat(k)*cz + c1=c1 + dat(k)*cz1 + endif + enddo + sq0=sq0 + real(c0)**2 + aimag(c0)**2 + sq1=sq1 + real(c1)**2 + aimag(c1)**2 + enddo + sq0=fac2*sq0 + sq1=fac2*sq1 + rsym=amp*(sq1-sq0) + if(j.ge.1) then + rsymbol(j,ich)=rsym + sym(j)=rsym + endif + enddo + + call extract4(sym,ncount,decoded) !Do the convolutional decode + nfano=0 + if(ncount.ge.0) then + nfano=1 + ichbest=ich + exit + endif + + qual=0. !Now try deep search +! if(ndepth.ge.1) then + if(iand(ndepth,32).eq.32) then + call deep4(sym(2),neme,flip,mycall,hiscall,hisgrid,deepmsg,qual) + if(qual.gt.qbest) then + qbest=qual + deepbest=deepmsg + ichbest=ich + endif + endif + enddo + if(qbest.gt.qtop) then + qtop=qbest + endif + qual=qbest + + return +end subroutine decode4 diff --git a/lib/decode65a.f90 b/lib/decode65a.f90 index 031c48fa..5ad31677 100644 --- a/lib/decode65a.f90 +++ b/lib/decode65a.f90 @@ -1,95 +1,158 @@ -subroutine decode65a(dd,npts,newdat,nqd,f0,nflip,mode65,sync2,a,dt, & - nbmkv,nhist,decoded) +subroutine decode65a(dd,npts,newdat,nqd,f0,nflip,mode65,ntrials, & + naggressive,ndepth,ntol,mycall,hiscall,hisgrid,nexp_decode, & + bVHF,sync2,a,dt,nft,nspecial,qual,nhist,nsmo,decoded) ! Apply AFC corrections to a candidate JT65 signal, then decode it. + use jt65_mod + use timer_module, only: timer + parameter (NMAX=60*12000) !Samples per 60 s real*4 dd(NMAX) !92 MB: raw data from Linrad timf2 - complex cx(NMAX/8) !Data at 1378.125 samples/s + complex cx(NMAX/8) !Data at 1378.125 sps + complex cx1(NMAX/8) !Data at 1378.125 sps, offset by 355.3 Hz complex c5x(NMAX/32) !Data at 344.53125 Hz complex c5a(512) real s2(66,126) real a(5) - logical first - character decoded*22 - data first/.true./,jjjmin/1000/,jjjmax/-1000/ - data nhz0/-9999999/ + logical bVHF,first + character decoded*22,decoded_best*22 + character mycall*12,hiscall*12,hisgrid*6 + character*27 cr + data first/.true./,jjjmin/1000/,jjjmax/-1000/,cr/'(C) 2016, Joe Taylor - K1JT'/ save ! Mix sync tone to baseband, low-pass filter, downsample to 1378.125 Hz - dt00=dt call timer('filbig ',0) call filbig(dd,npts,f0,newdat,cx,n5,sq0) + if(mode65.eq.4) call filbig(dd,npts,f0+355.297852,newdat,cx1,n5,sq0) call timer('filbig ',1) - ! NB: cx has sample rate 12000*77125/672000 = 1378.125 Hz -! Find best DF, f1, f2, and DT. Start by downsampling to 344.53125 Hz +! Check for a shorthand message + if(bVHF .and. mode65.ne.101) then + call sh65(cx,n5,mode65,ntol,xdf,nspecial,sync2) + if(nspecial.gt.0) then + a=0. + a(1)=xdf + nflip=0 + endif + endif + if(nflip.eq.0) go to 900 + +! Find best DF, drift, curvature, and DT. Start by downsampling to 344.53125 Hz call timer('fil6521 ',0) -! Add some zeros at start of c5 arrays -- empirical fix for negative DT's - nadd=1089 - c5x(:nadd)=0. - call fil6521(cx,n5,c5x(nadd+1),n6) - n6=n6+nadd + call fil6521(cx,n5,c5x,n6) call timer('fil6521 ',1) fsample=1378.125/4. - a(5)=dt00 - i0=nint((a(5)+0.5)*fsample) - 2 + nadd - if(i0.lt.1) then -! write(23,*) 'i0 too small in decode1a:',i0,f0,a(5),fsample,nadd -! flush(23) - i0=1 - endif - nz=n6+1-i0 -! We're looking only at sync tone here... so why not downsample by another -! factor of 1/8, say? Should be a significant execution speed-up. call timer('afc65b ',0) -! Best fit for DF, f1, and f2 - call afc65b(c5x(i0),nz,fsample,nflip,a,ccfbest,dtbest) +! Best fit for DF, drift, banana-coefficient, and dt. fsample = 344.53125 S/s + dtbest=dt + call afc65b(c5x,n6,fsample,nflip,a,ccfbest,dtbest) call timer('afc65b ',1) - + dtbest=dtbest+0.003628 !Remove decimation filter and coh. integrator delay + dt=dtbest !Return new, improved estimate of dt sync2=3.7e-4*ccfbest/sq0 !Constant is empirical + if(mode65.eq.4) cx=cx1 ! Apply AFC corrections to the time-domain signal ! Now we are back to using the 1378.125 Hz sample rate, enough to ! accommodate the full JT65C bandwidth. - + a(3)=0 call timer('twkfreq ',0) call twkfreq65(cx,n5,a) call timer('twkfreq ',1) -! Compute spectrum for each half symbol. -! Adding or subtracting a small number (e.g., 5) to j may make it decode.\ -! NB: might want to try computing full-symbol spectra (nfft=512, even for -! submodes B and C). - +! Compute spectrum for each symbol. nsym=126 nfft=512 - j=(dt00+dtbest+2.685)*1378.125 - if(j.lt.0) j=0 + df=1378.125/nfft + j=int(dtbest*1378.125) call timer('sh_ffts ',0) + c5a=cmplx(0.0,0.0) do k=1,nsym do i=1,nfft j=j+1 - c5a(i)=cx(j) + if(j.ge.1 .and. j.le.NMAX/8) then + c5a(i)=cx(j) + else + c5a(i)=0. + endif enddo call four2a(c5a,nfft,1,1,1) - do i=1,66 + do i=1,512 jj=i - if(mode65.eq.2) jj=2*i-1 - if(mode65.eq.4) jj=4*i-3 - s2(i,k)=real(c5a(jj))**2 + aimag(c5a(jj))**2 + if(i.gt.256) jj=i-512 + s1(jj,k)=real(c5a(i))**2 + aimag(c5a(i))**2 enddo enddo call timer('sh_ffts ',1) call timer('dec65b ',0) - call decode65b(s2,nflip,mode65,nqd,nbmkv,nhist,decoded) - dt=dt00 + dtbest + 1.7 + qualbest=0. + qual0=-1.e30 + minsmo=0 + maxsmo=0 + if(mode65.ge.2 .and. mode65.ne.101) then + minsmo=nint(width/df) + maxsmo=2*minsmo + endif + nn=0 + do ismo=minsmo,maxsmo + if(ismo.gt.0) then + do j=1,126 + call smo121(s1(-255,j),512) + if(j.eq.1) nn=nn+1 + if(nn.ge.4) then + call smo121(s1(-255,j),512) + if(j.eq.1) nn=nn+1 + endif + enddo + endif + + do i=1,66 + jj=i + if(mode65.eq.2) jj=2*i-1 + if(mode65.eq.4) then + ff=4*(i-1)*df - 355.297852 + jj=nint(ff/df)+1 + endif + s2(i,1:126)=s1(jj,1:126) + enddo + + nadd=ismo !### ??? ### + call decode65b(s2,nflip,nadd,mode65,ntrials,naggressive,ndepth, & + mycall,hiscall,hisgrid,nexp_decode,nqd,nft,qual,nhist,decoded) + + if(nft.eq.1) then + nsmo=ismo + param(9)=nsmo + nsum=1 + exit + else if(nft.eq.2) then + if(qual.gt.qualbest) then + decoded_best=decoded + qualbest=qual + nnbest=nn + nsmobest=ismo + endif + endif + if(qual.lt.qual0) exit + qual0=qual + enddo + + if(nft.eq.2) then + decoded=decoded_best + qual=qualbest + nsmo=nsmobest + param(9)=nsmo + nn=nnbest + endif + call timer('dec65b ',1) - return +900 return end subroutine decode65a diff --git a/lib/decode65b.f90 b/lib/decode65b.f90 index f4040497..821286d0 100644 --- a/lib/decode65b.f90 +++ b/lib/decode65b.f90 @@ -1,34 +1,32 @@ -subroutine decode65b(s2,nflip,mode65,nqd,nbmkv,nhist,decoded) +subroutine decode65b(s2,nflip,nadd,mode65,ntrials,naggressive,ndepth, & + mycall,hiscall,hisgrid,nexp_decode,nqd,nft,qual,nhist,decoded) + use jt65_mod real s2(66,126) real s3(64,63) - logical first,ltext + logical ltext character decoded*22 - common/prcom/pr(126),mdat(126),mref(126,2),mdat2(126),mref2(126,2) - data first/.true./ + character mycall*12,hiscall*12,hisgrid*6 save - if(first) call setup65 - first=.false. - + if(nqd.eq.-99) stop !Silence compiler warning do j=1,63 k=mdat(j) !Points to data symbol if(nflip.lt.0) k=mdat2(j) do i=1,64 s3(i,j)=s2(i+2,k) enddo - k=mdat2(j) !Points to data symbol - if(nflip.lt.0) k=mdat(j) enddo - nadd=mode65 - call extract(s3,nadd,nqd,ncount,nhist,decoded,ltext,nbmkv) !Extract message + call extract(s3,nadd,mode65,ntrials,naggressive,ndepth,nflip,mycall, & + hiscall,hisgrid,nexp_decode,ncount,nhist,decoded,ltext,nft,qual) + ! Suppress "birdie messages" and other garbage decodes: if(decoded(1:7).eq.'000AAA ') ncount=-1 if(decoded(1:7).eq.'0L6MWK ') ncount=-1 if(nflip.lt.0 .and. ltext) ncount=-1 if(ncount.lt.0) then - nbmkv=0 + nft=0 decoded=' ' endif diff --git a/lib/decode9w.f90 b/lib/decode9w.f90 new file mode 100644 index 00000000..54c22722 --- /dev/null +++ b/lib/decode9w.f90 @@ -0,0 +1,49 @@ +subroutine decode9w(nfqso,ntol,nsubmode,ss,id2,sync,nsnr,xdt1,f0,decoded) + +! Decode a weak signal in a wide/slow JT9 submode. + + parameter (NSMAX=6827,NZMAX=60*12000) + real ss(184,NSMAX) !Symbol spectra at 1/2-symbol steps + real ccfred(NSMAX) !Best sync vs frequency + real ccfblue(-9:18) !Sync vs time at best frequency + real a(5) !Fitted Lorentzian params + integer*2 id2(NZMAX) !Raw 16-bit data + integer*1 i1SoftSymbols(207) !Binary soft symbols + character*22 decoded !Decoded message + + df=12000.0/16384.0 !Bin spacing in ss() + nsps=6912 !Samples per 9-FSK symbol + tstep=nsps*0.5/12000.0 !Half-symbol duration + npts=52*12000 + limit=10000 !Fano timeout parameter + + ia=max(1,nint((nfqso-ntol)/df)) !Start frequency bin + ib=min(NSMAX,nint((nfqso+ntol)/df)) !End frequency bin + lag1=-int(2.5/tstep + 0.9999) !Start lag + lag2=int(5.0/tstep + 0.9999) !End lag + nhsym=184 !Number of half-symbols + +! First sync pass finds approximate Doppler spread; second pass does a +! good Lorentzian fit to determine frequency f0. + do iter=1,2 + nadd=3 + if(iter.eq.2) nadd=2*nint(0.375*a(4)) + 1 + call sync9w(ss,nhsym,lag1,lag2,ia,ib,ccfred,ccfblue,ipk,lagpk,nadd) + sum1=sum(ccfblue) - ccfblue(lagpk-1)-ccfblue(lagpk) -ccfblue(lagpk+1) + sq=dot_product(ccfblue,ccfblue) - ccfblue(lagpk-1)**2 - & + ccfblue(lagpk)**2 - ccfblue(lagpk+1)**2 + base=sum1/25.0 + rms=sqrt(sq/24.0) + sync=(ccfblue(lagpk)-base)/rms + nsnr=nint(db(sync)-29.7) + xdt0=lagpk*tstep + call lorentzian(ccfred(ia),ib-ia+1,a) + f0=(ia+a(3))*df + ccfblue=(ccfblue-base)/rms + enddo + + call softsym9w(id2,npts,xdt0,f0,a(4)*df,nsubmode,xdt1-1.05,i1softsymbols) + call jt9fano(i1softsymbols,limit,nlim,decoded) + + return +end subroutine decode9w diff --git a/lib/decode_rs.c b/lib/decode_rs.c index ac85eddd..53b441d3 100644 --- a/lib/decode_rs.c +++ b/lib/decode_rs.c @@ -7,9 +7,9 @@ #include #endif +#include #include -//#define NULL ((void *)0) #define min(a,b) ((a) < (b) ? (a) : (b)) #ifdef FIXED diff --git a/lib/decoder.f90 b/lib/decoder.f90 index 7dfe64a1..c913cdb1 100644 --- a/lib/decoder.f90 +++ b/lib/decoder.f90 @@ -1,96 +1,429 @@ -subroutine decoder(ss,id2) +subroutine multimode_decoder(ss,id2,params,nfsample) - use prog_args !$ use omp_lib + use prog_args + use timer_module, only: timer + use jt4_decode + use jt65_decode + use jt9_decode + use ft8_decode + + include 'jt9com.f90' + include 'timer_common.inc' + + type, extends(jt4_decoder) :: counting_jt4_decoder + integer :: decoded + end type counting_jt4_decoder + + type, extends(jt65_decoder) :: counting_jt65_decoder + integer :: decoded + end type counting_jt65_decoder + + type, extends(jt9_decoder) :: counting_jt9_decoder + integer :: decoded + end type counting_jt9_decoder + + type, extends(ft8_decoder) :: counting_ft8_decoder + integer :: decoded + end type counting_ft8_decoder - include 'constants.f90' real ss(184,NSMAX) - character*20 datetime - logical baddata + logical baddata,newdat65,newdat9,single_decode,bVHF,bad0,newdat integer*2 id2(NTMAX*12000) + type(params_block) :: params real*4 dd(NTMAX*12000) - common/npar/nutc,ndiskdat,ntrperiod,nfqso,newdat,npts8,nfa,nfsplit,nfb, & - ntol,kin,nzhsym,nsave,nagain,ndepth,ntxmode,nmode,datetime - common/tracer/limtrace,lu - integer onlevel(0:10) - common/tracer_priv/level,onlevel - !$omp threadprivate(/tracer_priv/) save + type(counting_jt4_decoder) :: my_jt4 + type(counting_jt65_decoder) :: my_jt65 + type(counting_jt9_decoder) :: my_jt9 + type(counting_ft8_decoder) :: my_ft8 - rms=sqrt(dot_product(float(id2(300000:310000)), & - float(id2(300000:310000)))/10000.0) - if(rms.lt.2.0) go to 800 - - nfreqs0=0 - nfreqs1=0 - ndecodes0=0 - ndecodes1=0 + ! initialize decode counts + my_jt4%decoded = 0 + my_jt65%decoded = 0 + my_jt9%decoded = 0 + my_ft8%decoded = 0 - if (nagain .eq. 0) then - open(13,file=trim(temp_dir)//'/decoded.txt',status='unknown') + single_decode=iand(params%nexp_decode,32).ne.0 + bVHF=iand(params%nexp_decode,64).ne.0 + if(mod(params%nranera,2).eq.0) ntrials=10**(params%nranera/2) + if(mod(params%nranera,2).eq.1) ntrials=3*10**(params%nranera/2) + if(params%nranera.eq.0) ntrials=0 + + nfail=0 +10 if (params%nagain) then + open(13,file=trim(temp_dir)//'/decoded.txt',status='unknown', & + position='append',iostat=ios) else - open(13,file=trim(temp_dir)//'/decoded.txt',status='unknown', & - position='append') + open(13,file=trim(temp_dir)//'/decoded.txt',status='unknown', & + iostat=ios) end if - open(22,file=trim(temp_dir)//'/kvasd.dat',access='direct',recl=1024, & + if(ios.ne.0) then + nfail=nfail+1 + if(nfail.le.3) then + call sleep_msec(10) + go to 10 + endif + endif + + if(params%nmode.eq.8) then +! We're in FT8 mode + call timer('decft8 ',0) + newdat=params%newdat + call my_ft8%decode(ft8_decoded,id2,params%nQSOProgress,params%nfqso, & + params%nftx,newdat,params%nutc,params%nfa,params%nfb, & + params%nexp_decode,params%ndepth,logical(params%nagain), & + logical(params%lapon),params%napwid,params%mycall, & + params%mygrid,params%hiscall,params%hisgrid) + call timer('decft8 ',1) + go to 800 + endif + + rms=sqrt(dot_product(float(id2(300000:310000)), & + float(id2(300000:310000)))/10000.0) + if(rms.lt.2.0) go to 800 + +! Zap data at start that might come from T/R switching transient? + nadd=100 + k=0 + bad0=.false. + do i=1,240 + sq=0. + do n=1,nadd + k=k+1 + sq=sq + float(id2(k))**2 + enddo + rms=sqrt(sq/nadd) + if(rms.gt.10000.0) then + bad0=.true. + kbad=k + rmsbad=rms + endif + enddo + if(bad0) then + nz=min(NTMAX*12000,kbad+100) +! id2(1:nz)=0 ! temporarily disabled as it can breaak the JT9 decoder, maybe others + endif + + if(params%nmode.eq.4 .or. params%nmode.eq.65) open(14,file=trim(temp_dir)// & + '/avemsg.txt',status='unknown') + if(params%nmode.eq.164) open(17,file=trim(temp_dir)//'/red.dat', & status='unknown') + if(params%nmode.eq.4) then + jz=52*nfsample + if(params%newdat) then + if(nfsample.eq.12000) call wav11(id2,jz,dd) + if(nfsample.eq.11025) dd(1:jz)=id2(1:jz) + endif + call my_jt4%decode(jt4_decoded,dd,jz,params%nutc,params%nfqso, & + params%ntol,params%emedelay,params%dttol,logical(params%nagain), & + params%ndepth,logical(params%nclearave),params%minsync, & + params%minw,params%nsubmode,params%mycall,params%hiscall, & + params%hisgrid,params%nlist,params%listutc,jt4_average) + go to 800 + endif + npts65=52*12000 + if(params%nmode.eq.164) npts65=54*12000 if(baddata(id2,npts65)) then nsynced=0 ndecoded=0 go to 800 endif + + ntol65=params%ntol !### is this OK? ### + newdat65=params%newdat + newdat9=params%newdat - ntol65=20 - newdat65=newdat - newdat9=newdat +!$call omp_set_dynamic(.true.) +!$omp parallel sections num_threads(2) copyin(/timer_private/) shared(ndecoded) if(.true.) !iif() needed on Mac - !$ call omp_set_dynamic(.true.) - !$omp parallel sections num_threads(2) copyin(/tracer_priv/) shared(ndecoded) if(.true.) !iif() needed on Mac +!$omp section + if(params%nmode.eq.65 .or. params%nmode.eq.164 .or. & + (params%nmode.eq.(65+9) .and. params%ntxmode.eq.65)) then +! We're in JT65 or QRA64 mode, or should do JT65 first - !$omp section - if(nmode.eq.65 .or. (nmode.gt.65 .and. ntxmode.eq.65)) then -! We're decoding JT65 or should do this mode first - if(newdat65.ne.0) dd(1:npts65)=id2(1:npts65) - nf1=nfa - nf2=nfb + if(newdat65) dd(1:npts65)=id2(1:npts65) + nf1=params%nfa + nf2=params%nfb call timer('jt65a ',0) - call jt65a(dd,npts65,newdat65,nutc,nf1,nf2,nfqso,ntol65,nagain,ndecoded) + call my_jt65%decode(jt65_decoded,dd,npts65,newdat65,params%nutc, & + nf1,nf2,params%nfqso,ntol65,params%nsubmode,params%minsync, & + logical(params%nagain),params%n2pass,logical(params%nrobust), & + ntrials,params%naggressive,params%ndepth,params%emedelay, & + logical(params%nclearave),params%mycall,params%hiscall, & + params%hisgrid,params%nexp_decode) call timer('jt65a ',1) - else -! We're decoding JT9 or should do this mode first + + else if(params%nmode.eq.9 .or. (params%nmode.eq.(65+9) .and. params%ntxmode.eq.9)) then +! We're in JT9 mode, or should do JT9 first call timer('decjt9 ',0) - call decjt9(ss,id2,nutc,nfqso,newdat9,npts8,nfa,nfsplit,nfb,ntol,nzhsym, & - nagain,ndepth,nmode) + call my_jt9%decode(jt9_decoded,ss,id2,params%nfqso, & + newdat9,params%npts8,params%nfa,params%nfsplit,params%nfb, & + params%ntol,params%nzhsym,logical(params%nagain),params%ndepth, & + params%nmode,params%nsubmode,params%nexp_decode) call timer('decjt9 ',1) endif - !$omp section - if(nmode.gt.65) then ! do the other mode in dual mode - if (ntxmode.eq.9) then - if(newdat65.ne.0) dd(1:npts65)=id2(1:npts65) - nf1=nfa - nf2=nfb +!$omp section + if(params%nmode.eq.(65+9)) then !Do the other mode (we're in dual mode) + if (params%ntxmode.eq.9) then + if(newdat65) dd(1:npts65)=id2(1:npts65) + nf1=params%nfa + nf2=params%nfb call timer('jt65a ',0) - call jt65a(dd,npts65,newdat65,nutc,nf1,nf2,nfqso,ntol65,nagain,ndecoded) + call my_jt65%decode(jt65_decoded,dd,npts65,newdat65,params%nutc, & + nf1,nf2,params%nfqso,ntol65,params%nsubmode,params%minsync, & + logical(params%nagain),params%n2pass,logical(params%nrobust), & + ntrials,params%naggressive,params%ndepth,params%emedelay, & + logical(params%nclearave),params%mycall,params%hiscall, & + params%hisgrid,params%nexp_decode) call timer('jt65a ',1) else call timer('decjt9 ',0) - call decjt9(ss,id2,nutc,nfqso,newdat9,npts8,nfa,nfsplit,nfb,ntol, & - nzhsym,nagain,ndepth,nmode) + call my_jt9%decode(jt9_decoded,ss,id2,params%nfqso, & + newdat9,params%npts8,params%nfa,params%nfsplit,params%nfb, & + params%ntol,params%nzhsym,logical(params%nagain), & + params%ndepth,params%nmode,params%nsubmode,params%nexp_decode) call timer('decjt9 ',1) end if endif - !$omp end parallel sections +!$omp end parallel sections ! JT65 is not yet producing info for nsynced, ndecoded. -800 write(*,1010) nsynced,ndecoded +800 ndecoded = my_jt4%decoded + my_jt65%decoded + my_jt9%decoded + my_ft8%decoded + write(*,1010) nsynced,ndecoded 1010 format('',2i4) call flush(6) - close(13) - close(22) + close(13) + if(params%nmode.eq.4 .or. params%nmode.eq.65) close(14) return -end subroutine decoder + +contains + + subroutine jt4_decoded(this,snr,dt,freq,have_sync,sync,is_deep, & + decoded0,qual,ich,is_average,ave) + implicit none + class(jt4_decoder), intent(inout) :: this + integer, intent(in) :: snr + real, intent(in) :: dt + integer, intent(in) :: freq + logical, intent(in) :: have_sync + logical, intent(in) :: is_deep + character(len=1), intent(in) :: sync + character(len=22), intent(in) :: decoded0 + real, intent(in) :: qual + integer, intent(in) :: ich + logical, intent(in) :: is_average + integer, intent(in) :: ave + + character*22 decoded + character*3 cflags + + if(ich.eq.-99) stop !Silence compiler warning + if (have_sync) then + decoded=decoded0 + cflags=' ' + if(decoded.ne.' ') cflags='f ' + if(is_deep) then + cflags(1:2)='d1' + write(cflags(3:3),'(i1)') min(int(qual),9) + if(qual.ge.10.0) cflags(3:3)='*' + if(qual.lt.3.0) decoded(22:22)='?' + endif + if(is_average) then + write(cflags(2:2),'(i1)') min(ave,9) + if(ave.ge.10) cflags(2:2)='*' + endif + write(*,1000) params%nutc,snr,dt,freq,sync,decoded,cflags +1000 format(i4.4,i4,f5.1,i5,1x,'$',a1,1x,a22,1x,a3) + else + write(*,1000) params%nutc,snr,dt,freq + end if + + select type(this) + type is (counting_jt4_decoder) + this%decoded = this%decoded + 1 + end select + end subroutine jt4_decoded + + subroutine jt4_average (this, used, utc, sync, dt, freq, flip) + implicit none + class(jt4_decoder), intent(inout) :: this + logical, intent(in) :: used + integer, intent(in) :: utc + real, intent(in) :: sync + real, intent(in) :: dt + integer, intent(in) :: freq + logical, intent(in) :: flip + character(len=1) :: cused, csync + + cused = '.' + csync = '*' + if (used) cused = '$' + if (flip) csync = '$' + write(14,1000) cused,utc,sync,dt,freq,csync +1000 format(a1,i5.4,f6.1,f6.2,i6,1x,a1) + end subroutine jt4_average + + subroutine jt65_decoded(this,sync,snr,dt,freq,drift,nflip,width, & + decoded0,ft,qual,nsmo,nsum,minsync) + + use jt65_decode + implicit none + + class(jt65_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + integer, intent(in) :: freq + integer, intent(in) :: drift + integer, intent(in) :: nflip + real, intent(in) :: width + character(len=22), intent(in) :: decoded0 + integer, intent(in) :: ft + integer, intent(in) :: qual + integer, intent(in) :: nsmo + integer, intent(in) :: nsum + integer, intent(in) :: minsync + + integer i,nft + logical is_deep,is_average + character decoded*22,csync*2,cflags*3 + + if(width.eq.-9999.0) stop !Silence compiler warning +!$omp critical(decode_results) + decoded=decoded0 + cflags=' ' + is_deep=ft.eq.2 + + if(ft.ge.80) then !QRA64 mode + nft=ft-100 + csync=': ' + if(sync-3.4.ge.float(minsync) .or. nft.ge.0) csync=':*' + if(nft.lt.0) then + write(*,1009) params%nutc,snr,dt,freq,csync,decoded + else + write(*,1009) params%nutc,snr,dt,freq,csync,decoded,nft +1009 format(i4.4,i4,f5.1,i5,1x,a2,1x,a22,i2) + endif + write(13,1011) params%nutc,nint(sync),snr,dt,float(freq),drift, & + decoded,nft +1011 format(i4.4,i4,i5,f6.2,f8.0,i4,3x,a22,' QRA64',i3) + go to 100 + endif + + if(ft.eq.0 .and. minsync.ge.0 .and. int(sync).lt.minsync) then + write(*,1010) params%nutc,snr,dt,freq + else + is_average=nsum.ge.2 + if(bVHF .and. ft.gt.0) then + cflags='f ' + if(is_deep) then + cflags(1:2)='d1' + write(cflags(3:3),'(i1)') min(qual,9) + if(qual.ge.10) cflags(3:3)='*' + if(qual.lt.3) decoded(22:22)='?' + endif + if(is_average) then + write(cflags(2:2),'(i1)') min(nsum,9) + if(nsum.ge.10) cflags(2:2)='*' + endif + endif + csync='# ' + i=0 + if(bVHF .and. nflip.ne.0 .and. & + sync.ge.max(0.0,float(minsync))) then + csync='#*' + if(nflip.eq.-1) then + csync='##' + if(decoded.ne.' ') then + do i=22,1,-1 + if(decoded(i:i).ne.' ') exit + enddo + if(i.gt.18) i=18 + decoded(i+2:i+4)='OOO' + endif + endif + endif + write(*,1010) params%nutc,snr,dt,freq,csync,decoded,cflags +1010 format(i4.4,i4,f5.1,i5,1x,a2,1x,a22,1x,a3) + endif + write(13,1012) params%nutc,nint(sync),snr,dt,float(freq),drift, & + decoded,ft,nsum,nsmo +1012 format(i4.4,i4,i5,f6.2,f8.0,i4,3x,a22,' JT65',3i3) + +100 call flush(6) + +!$omp end critical(decode_results) + select type(this) + type is (counting_jt65_decoder) + this%decoded = this%decoded + 1 + end select + end subroutine jt65_decoded + + subroutine jt9_decoded (this, sync, snr, dt, freq, drift, decoded) + use jt9_decode + implicit none + + class(jt9_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + real, intent(in) :: freq + integer, intent(in) :: drift + character(len=22), intent(in) :: decoded + + !$omp critical(decode_results) + write(*,1000) params%nutc,snr,dt,nint(freq),decoded +1000 format(i4.4,i4,f5.1,i5,1x,'@ ',1x,a22) + write(13,1002) params%nutc,nint(sync),snr,dt,freq,drift,decoded +1002 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a22,' JT9') + call flush(6) + !$omp end critical(decode_results) + select type(this) + type is (counting_jt9_decoder) + this%decoded = this%decoded + 1 + end select + end subroutine jt9_decoded + + subroutine ft8_decoded (this,sync,snr,dt,freq,decoded,nap,qual) + use ft8_decode + implicit none + + class(ft8_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=22), intent(in) :: decoded + integer, intent(in) :: nap + real, intent(in) :: qual + character*2 annot + character*22 decoded0 + + decoded0=decoded + annot=' ' + if(nap.ne.0) then + write(annot,'(a1,i1)') 'a',nap + if(qual.lt.0.17) decoded0(22:22)='?' + endif + write(*,1000) params%nutc,snr,dt,nint(freq),decoded0,annot +1000 format(i6.6,i4,f5.1,i5,' ~ ',1x,a22,1x,a2) + write(13,1002) params%nutc,nint(sync),snr,dt,freq,0,decoded0 +1002 format(i6.6,i4,i5,f6.1,f8.0,i4,3x,a22,' FT8') + call flush(6) + call flush(13) + + select type(this) + type is (counting_ft8_decoder) + this%decoded = this%decoded + 1 + end select + + return + end subroutine ft8_decoded + +end subroutine multimode_decoder diff --git a/lib/deep24.f90 b/lib/deep24.f90 deleted file mode 100644 index 70a69ae7..00000000 --- a/lib/deep24.f90 +++ /dev/null @@ -1,182 +0,0 @@ -subroutine deep24(sym,neme,flip,mycall,hiscall,hisgrid,decoded,qual) - -! Have barely begun converting this from JT65 to JT4 - - parameter (MAXCALLS=7000,MAXRPT=63) - real*4 sym(206) - character callsign*12,grid*4,message*22,hisgrid*6,c*1,ceme*3 - character*12 mycall,hiscall - character mycall0*12,hiscall0*12,hisgrid0*6 - character*22 decoded - character*22 testmsg(2*MAXCALLS + 2 + MAXRPT) - character*15 callgrid(MAXCALLS) - character*180 line - character*4 rpt(MAXRPT) - integer ncode(206) - real*4 code(206,2*MAXCALLS + 2 + MAXRPT) - real pp(2*MAXCALLS + 2 + MAXRPT) -! common/c3com/ mcall3a - - data neme0/-99/ - data rpt/'-01','-02','-03','-04','-05', & - '-06','-07','-08','-09','-10', & - '-11','-12','-13','-14','-15', & - '-16','-17','-18','-19','-20', & - '-21','-22','-23','-24','-25', & - '-26','-27','-28','-29','-30', & - 'R-01','R-02','R-03','R-04','R-05', & - 'R-06','R-07','R-08','R-09','R-10', & - 'R-11','R-12','R-13','R-14','R-15', & - 'R-16','R-17','R-18','R-19','R-20', & - 'R-21','R-22','R-23','R-24','R-25', & - 'R-26','R-27','R-28','R-29','R-30', & - 'RO','RRR','73'/ - save - - if(mycall.eq.mycall0 .and. hiscall.eq.hiscall0 .and. & - hisgrid.eq.hisgrid0 .and. mcall3a.eq.0 .and. neme.eq.neme0) go to 30 - - mcall3a=0 - rewind 23 - k=0 - icall=0 - do n=1,MAXCALLS - if(n.eq.1) then - callsign=hiscall - do i=4,12 - if(ichar(callsign(i:i)).eq.0) callsign(i:i)=' ' - enddo - grid=hisgrid(1:4) - if(ichar(grid(3:3)).eq.0) grid(3:3)=' ' - if(ichar(grid(4:4)).eq.0) grid(4:4)=' ' - else - read(23,1002,end=20) line -1002 format (A80) - if(line(1:4).eq.'ZZZZ') go to 20 - if(line(1:2).eq.'//') go to 10 - i1=index(line,',') - if(i1.lt.4) go to 10 - i2=index(line(i1+1:),',') - if(i2.lt.5) go to 10 - i2=i2+i1 - i3=index(line(i2+1:),',') - if(i3.lt.1) i3=index(line(i2+1:),' ') - i3=i2+i3 - callsign=line(1:i1-1) - grid=line(i1+1:i2-1) - ceme=line(i2+1:i3-1) - if(neme.eq.1 .and. ceme.ne.'EME') go to 10 - endif - - icall=icall+1 - j1=index(mycall,' ') - 1 - if(j1.le.-1) j1=12 - if(j1.lt.3) j1=6 - j2=index(callsign,' ') - 1 - if(j2.le.-1) j2=12 - if(j2.lt.3) j2=6 - j3=index(mycall,'/') ! j3>0 means compound mycall - j4=index(callsign,'/') ! j4>0 means compound hiscall - callgrid(icall)=callsign(1:j2) - - mz=1 -! Allow MyCall + HisCall + rpt (?) - if(n.eq.1 .and. j3.lt.1 .and. j4.lt.1 .and. & - flip.gt.0.0 .and. callsign(1:6).ne.' ') mz=MAXRPT+1 - do m=1,mz - if(m.gt.1) grid=rpt(m-1) - if(j3.lt.1 .and.j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid - message=mycall(1:j1)//' '//callgrid(icall) - k=k+1 - testmsg(k)=message - call encode4(message,ncode) - code(1:206,k)=2*ncode(1:206)-1 - if(n.ge.2) then -! Insert CQ message - if(j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid - message='CQ '//callgrid(icall) - k=k+1 - testmsg(k)=message - call encode4(message,ncode) - code(1:206,k)=2*ncode(1:206)-1 - endif - enddo -10 continue - enddo - -20 continue - ntot=k - neme0=neme - -30 mycall0=mycall - hiscall0=hiscall - hisgrid0=hisgrid - - sq=0. - do j=1,206 - sq=sq + sym(j)**2 - enddo - rms=sqrt(sq/206.0) - sym=sym/rms - - p1=-1.e30 - p2=-1.e30 - do k=1,ntot - pp(k)=0. -! Test all messages if flip=+1; skip the CQ messages if flip=-1. - if(flip.gt.0.0 .or. testmsg(k)(1:3).ne.'CQ ') then - p=0. - do j=1,206 - i=code(j,k)+1 - p=p + code(j,k)*sym(j) - enddo - pp(k)=p - if(p.gt.p1) then - p1=p - ip1=k - endif - endif - enddo - - do i=1,ntot - if(pp(i).gt.p2 .and. pp(i).ne.p1) p2=pp(i) - enddo - -! ### DO NOT REMOVE ### -! rewind 77 -! write(77,*) p1,p2 -! ### Works OK without it (in both Windows and Linux) if compiled -! ### without optimization. However, in Windows this is a colossal -! ### pain because of the way F2PY wants to run the compile step. - - - bias=1.1*p2 -! if(mode65.eq.1) bias=max(1.12*p2,0.335) -! if(mode65.eq.2) bias=max(1.08*p2,0.405) -! if(mode65.ge.4) bias=max(1.04*p2,0.505) - - if(p2.eq.p1 .and. p1.ne.-1.e30) stop 'Error in deep24' - qual=10.0*(p1-bias) - - decoded=' ' - c=' ' - - if(qual.gt.1.0) then - if(qual.lt.6.0) c='?' - decoded=testmsg(ip1) - else - qual=0. - endif - decoded(22:22)=c - -! Make sure everything is upper case. - do i=1,22 - if(decoded(i:i).ge.'a' .and. decoded(i:i).le.'z') & - decoded(i:i)=char(ichar(decoded(i:i))-32) - enddo - -! write(*,3010) p1,p2,p1-p2,p1/p2,qual,decoded -!3010 format('DS:',5f9.1,2x,a22) - - return -end subroutine deep24 diff --git a/lib/deep4.f90 b/lib/deep4.f90 new file mode 100644 index 00000000..05f6732d --- /dev/null +++ b/lib/deep4.f90 @@ -0,0 +1,169 @@ +subroutine deep4(sym0,neme,flip,mycall,hiscall,hisgrid,decoded,qual) + +! Deep search routine for JT4 + + use prog_args + parameter (MAXCALLS=7000,MAXRPT=63) + real*4 sym0(206),sym(206) + character callsign*12,grid*4,message*22,hisgrid*6,ceme*3 + character*12 mycall,hiscall + character mycall0*12,hiscall0*12,hisgrid0*6 + character*22 decoded + character*22 testmsg(2*MAXCALLS + 2 + MAXRPT) + character*15 callgrid(MAXCALLS) + character*180 line + character*4 rpt(MAXRPT) + integer ncode(206) + real*4 code(206,2*MAXCALLS + 2 + MAXRPT) + real pp(2*MAXCALLS + 2 + MAXRPT) + data neme0/-99/ + data rpt/'-01','-02','-03','-04','-05', & + '-06','-07','-08','-09','-10', & + '-11','-12','-13','-14','-15', & + '-16','-17','-18','-19','-20', & + '-21','-22','-23','-24','-25', & + '-26','-27','-28','-29','-30', & + 'R-01','R-02','R-03','R-04','R-05', & + 'R-06','R-07','R-08','R-09','R-10', & + 'R-11','R-12','R-13','R-14','R-15', & + 'R-16','R-17','R-18','R-19','R-20', & + 'R-21','R-22','R-23','R-24','R-25', & + 'R-26','R-27','R-28','R-29','R-30', & + 'RO','RRR','73'/ + save mycall0,hiscall0,hisgrid0,neme0,ntot,code,testmsg + + sym=sym0 + if(mycall.eq.mycall0 .and. hiscall.eq.hiscall0 .and. & + hisgrid.eq.hisgrid0 .and. neme.eq.neme0) go to 30 + + open(23,file=trim(data_dir)//'/CALL3.TXT',status='unknown') + k=0 + icall=0 + do n=1,MAXCALLS + if(n.eq.1) then + callsign=hiscall + do i=4,12 + if(ichar(callsign(i:i)).eq.0) callsign(i:i)=' ' + enddo + grid=hisgrid(1:4) + if(ichar(grid(3:3)).eq.0) grid(3:3)=' ' + if(ichar(grid(4:4)).eq.0) grid(4:4)=' ' + else + read(23,1002,end=20) line +1002 format (A80) + if(line(1:4).eq.'ZZZZ') go to 20 + if(line(1:2).eq.'//') go to 10 + i1=index(line,',') + if(i1.lt.4) go to 10 + i2=index(line(i1+1:),',') + if(i2.lt.5) go to 10 + i2=i2+i1 + i3=index(line(i2+1:),',') + if(i3.lt.1) i3=index(line(i2+1:),' ') + i3=i2+i3 + callsign=line(1:i1-1) + grid=line(i1+1:i2-1) + ceme=line(i2+1:i3-1) + if(neme.eq.1 .and. ceme.ne.'EME') go to 10 + endif + + icall=icall+1 + j1=index(mycall,' ') - 1 + if(j1.le.-1) j1=12 + if(j1.lt.3) j1=6 + j2=index(callsign,' ') - 1 + if(j2.le.-1) j2=12 + if(j2.lt.3) j2=6 + j3=index(mycall,'/') ! j3>0 means compound mycall + j4=index(callsign,'/') ! j4>0 means compound hiscall + callgrid(icall)=callsign(1:j2) + + mz=1 +! Allow MyCall + HisCall + rpt (?) + if(n.eq.1 .and. j3.lt.1 .and. j4.lt.1 .and. callsign(1:6).ne.' ') & + mz=MAXRPT+1 + do m=1,mz + if(m.gt.1) grid=rpt(m-1) + if(j3.lt.1 .and.j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid + message=mycall(1:j1)//' '//callgrid(icall) + k=k+1 + testmsg(k)=message + call encode4(message,ncode) + code(1:206,k)=2*ncode(1:206)-1 + if(n.ge.2) then +! Insert CQ message + if(j4.lt.1) callgrid(icall)=callsign(1:j2)//' '//grid + message='CQ '//callgrid(icall) + k=k+1 + testmsg(k)=message + call encode4(message,ncode) + code(1:206,k)=2*ncode(1:206)-1 + endif + enddo +10 continue + enddo + +20 continue + close(23) + ntot=k + +30 mycall0=mycall + hiscall0=hiscall + hisgrid0=hisgrid + neme0=neme + + sq=0. + do j=1,206 + sq=sq + sym(j)**2 + enddo + rms=sqrt(sq/206.0) + sym=sym/rms + + p1=-1.e30 + p2=-1.e30 + do k=1,ntot + pp(k)=0. +! Should re-instate the following: +! if(k.ge.2 .and. k.le.64 .and. flip.gt.0.0) cycle +! Test all messages if flip=+1; skip the CQ messages if flip=-1. + if(flip.gt.0.0 .or. testmsg(k)(1:3).ne.'CQ ') then + p=0. + do j=1,206 + p=p + code(j,k)*sym(j) + enddo + pp(k)=p + if(p.gt.p1) then + p1=p + ip1=k + endif + endif + enddo + + do i=1,ntot + if(pp(i).gt.p2 .and. testmsg(i).ne.testmsg(ip1)) p2=pp(i) + enddo + + qual=p1-max(1.15*p2,70.0) + +! ### DO NOT REMOVE ### + rewind 77 + if(ip1.ge.1 .and. ip1.le.2*MAXCALLS+2+MAXRPT) write(77,1001) p1,p2,ntot, & + rms,qual,ip1,testmsg(ip1) +1001 format(2f8.2,i8,2f8.2,i6,2x,a22) + call flush(77) + + if(qual.gt.1.0) then + decoded=testmsg(ip1) + else + decoded=' ' + qual=0. + endif + +! Make sure everything is upper case. + do i=1,22 + if(decoded(i:i).ge.'a' .and. decoded(i:i).le.'z') & + decoded(i:i)=char(ichar(decoded(i:i))-32) + enddo + + return +end subroutine deep4 diff --git a/lib/degrade_snr.f90 b/lib/degrade_snr.f90 new file mode 100644 index 00000000..fd5db5f1 --- /dev/null +++ b/lib/degrade_snr.f90 @@ -0,0 +1,21 @@ +subroutine degrade_snr(d2,npts,db,bw) + +! Degrade S/N by specified number of dB. + + integer*2 d2(npts) + + p0=0. + do i=1,npts + x=d2(i) + p0=p0 + x*x + enddo + p0=p0/npts + if(bw.gt.0.0) p0=p0*6000.0/bw + s=sqrt(p0*(10.0**(0.1*db) - 1.0)) + fac=sqrt(p0/(p0+s*s)) + do i=1,npts + d2(i)=nint(fac*(d2(i) + s*gran())) + enddo + + return +end subroutine degrade_snr diff --git a/lib/demod64a.f90 b/lib/demod64a.f90 index 452140a2..4eaf0c1d 100644 --- a/lib/demod64a.f90 +++ b/lib/demod64a.f90 @@ -1,62 +1,63 @@ -subroutine demod64a(s3,nadd,afac1,mrsym,mrprob,mr2sym,mr2prob,ntest,nlow) - -! Demodulate the 64-bin spectra for each of 63 symbols in a frame. - -! Parameters -! nadd number of spectra already summed -! mrsym most reliable symbol value -! mr2sym second most likely symbol value -! mrprob probability that mrsym was the transmitted value -! mr2prob probability that mr2sym was the transmitted value - - implicit real*8 (a-h,o-z) - real*4 s3(64,63),afac1 - real*8 fs(64) - integer mrsym(63),mrprob(63),mr2sym(63),mr2prob(63) - - if(nadd.eq.-999) return - afac=afac1 * float(nadd)**0.64 - scale=255.999 - -! Compute average spectral value - ave=sum(s3)/(64.*63.) - i1=1 !Silence warning - i2=1 - -! Compute probabilities for most reliable symbol values - do j=1,63 - s1=-1.e30 - fsum=0. - do i=1,64 - x=min(afac*s3(i,j)/ave,50.d0) - fs(i)=exp(x) - fsum=fsum+fs(i) - if(s3(i,j).gt.s1) then - s1=s3(i,j) - i1=i !Most reliable - endif - enddo - - s2=-1.e30 - do i=1,64 - if(i.ne.i1 .and. s3(i,j).gt.s2) then - s2=s3(i,j) - i2=i !Second most reliable - endif - enddo - p1=fs(i1)/fsum !Normalized probabilities - p2=fs(i2)/fsum - mrsym(j)=i1-1 - mr2sym(j)=i2-1 - mrprob(j)=scale*p1 - mr2prob(j)=scale*p2 - enddo - - nlow=0 - do j=1,63 - if(mrprob(j).le.5) nlow=nlow+1 - enddo - ntest=sum(mrprob)/63.0 - - return -end subroutine demod64a +subroutine demod64a(s3,nadd,afac1,mrsym,mrprob,mr2sym,mr2prob,ntest,nlow) + +! Demodulate the 64-bin spectra for each of 63 symbols in a frame. + +! Parameters +! nadd number of spectra already summed +! mrsym most reliable symbol value +! mr2sym second most likely symbol value +! mrprob probability that mrsym was the transmitted value +! mr2prob probability that mr2sym was the transmitted value + + implicit real*8 (a-h,o-z) + real*4 s3(64,63),afac1 + real*8 fs(64) + integer mrsym(63),mrprob(63),mr2sym(63),mr2prob(63) + + if(nadd.eq.-999) return + afac=afac1 * float(nadd)**0.64 + scale=255.999 + +! Compute average spectral value + ave=sum(s3)/(64.*63.) + i1=1 !Silence warning + i2=1 + +! Compute probabilities for most reliable symbol values + do j=1,63 + s1=-1.e30 + psum=0. + do i=1,64 + x=min(afac*s3(i,j)/ave,50.d0) + fs(i)=exp(x) + psum=psum+s3(i,j) + if(s3(i,j).gt.s1) then + s1=s3(i,j) + i1=i !Most reliable + endif + enddo + if(psum.eq.0.0) psum=1.e-6 + + s2=-1.e30 + do i=1,64 + if(i.ne.i1 .and. s3(i,j).gt.s2) then + s2=s3(i,j) + i2=i !Second most reliable + endif + enddo + p1=s1/psum !Symbol metrics for ftrsd + p2=s2/psum + mrsym(j)=i1-1 + mr2sym(j)=i2-1 + mrprob(j)=scale*p1 + mr2prob(j)=scale*p2 + enddo + + nlow=0 + do j=1,63 + if(mrprob(j).le.5) nlow=nlow+1 + enddo + ntest=sum(mrprob) + + return +end subroutine demod64a diff --git a/lib/dot.f90 b/lib/dot.f90 deleted file mode 100644 index a68c5bd1..00000000 --- a/lib/dot.f90 +++ /dev/null @@ -1,11 +0,0 @@ -real*8 function dot(x,y) - - real*8 x(3),y(3) - - dot=0.d0 - do i=1,3 - dot=dot+x(i)*y(i) - enddo - - return -end function dot diff --git a/lib/downsam9.f90 b/lib/downsam9.f90 index 520ffa57..7cd1962a 100644 --- a/lib/downsam9.f90 +++ b/lib/downsam9.f90 @@ -1,28 +1,31 @@ -subroutine downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2,nz2) +subroutine downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2) !Downsample from id2() into c2() so as to yield nspsd samples per symbol, !mixing from fpk down to zero frequency. The downsample factor is 432. use, intrinsic :: iso_c_binding use FFTW3 + use timer_module, only: timer include 'constants.f90' integer(C_SIZE_T) NMAX1 - parameter (NMAX1=604800) + parameter (NMAX1=653184) + parameter (NFFT1=653184,NFFT2=1512) type(C_PTR) :: plan !Pointers plan for big FFT integer*2 id2(0:8*npts8-1) + logical, intent(inout) :: newdat real*4, pointer :: x1(:) - complex c1(0:NMAX1/2) - complex c2(0:1440-1) + complex c1(0:NFFT1/2) + complex c2(0:NFFT2-1) real s(5000) logical first common/patience/npatience,nthreads data first/.true./ save plan,first,c1,s,x1 - nfft1=NMAX1 !Forward FFT length - df1=12000.0/nfft1 + df1=12000.0/NFFT1 npts=8*npts8 + if(npts.gt.NFFT1) npts=NFFT1 !### Fix! ### if(first) then nflags=FFTW_ESTIMATE @@ -37,16 +40,16 @@ subroutine downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2,nz2) call c_f_pointer(plan,x1,[NMAX1]) x1(0:NMAX1-1) => x1 !remap bounds call fftwf_plan_with_nthreads(nthreads) - plan=fftwf_plan_dft_r2c_1d(nfft1,x1,c1,nflags) + plan=fftwf_plan_dft_r2c_1d(NFFT1,x1,c1,nflags) call fftwf_plan_with_nthreads(1) !$omp end critical(fftw) first=.false. endif - if(newdat.eq.1) then + if(newdat) then x1(0:npts-1)=id2(0:npts-1) - x1(npts:nfft1-1)=0. !Zero the rest of x1 + x1(npts:NFFT1-1)=0. !Zero the rest of x1 call timer('FFTbig9 ',0) call fftwf_execute_dft_r2c(plan,x1,c1) call timer('FFTbig9 ',1) @@ -60,12 +63,11 @@ subroutine downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2,nz2) s(i)=s(i)+real(c1(j))**2 + aimag(c1(j))**2 enddo enddo - newdat=0 + newdat=.false. endif - ndown=8*nsps8/nspsd !Downsample factor - nfft2=nfft1/ndown !Backward FFT length - nh2=nfft2/2 + ndown=8*nsps8/nspsd !Downsample factor = 432 + nh2=NFFT2/2 nf=nint(fpk) i0=int(fpk/df1) @@ -75,13 +77,12 @@ subroutine downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2,nz2) call pctile(s(ia),ib-ia+1,40,avenoise) fac=sqrt(1.0/avenoise) - do i=0,nfft2-1 + do i=0,NFFT2-1 j=i0+i - if(i.gt.nh2) j=j-nfft2 + if(i.gt.nh2) j=j-NFFT2 c2(i)=fac*c1(j) enddo - call four2a(c2,nfft2,1,1,1) !FFT back to time domain - nz2=8*npts8/ndown + call four2a(c2,NFFT2,1,1,1) !FFT back to time domain return end subroutine downsam9 diff --git a/lib/encode232.f90 b/lib/encode232.f90 index bc904b48..491f204a 100644 --- a/lib/encode232.f90 +++ b/lib/encode232.f90 @@ -3,7 +3,7 @@ subroutine encode232(dat,nsym,symbol) ! Convolutional encoder for a K=32, r=1/2 code. integer*1 dat(13) !User data, packed 8 bits per byte - integer*1 symbol(500) !Channel symbols, one bit per byte + integer*1 symbol(206) !Channel symbols, one bit per byte integer*1 i1 include 'conv232.f90' diff --git a/lib/encode4.f90 b/lib/encode4.f90 new file mode 100644 index 00000000..4e73699b --- /dev/null +++ b/lib/encode4.f90 @@ -0,0 +1,20 @@ +subroutine encode4(message,ncode) + + use packjt + parameter (MAXCALLS=7000,MAXRPT=63) + integer ncode(206) + character*22 message !Message to be generated + character*3 cok !' ' or 'OOO' + integer dgen(13) + integer*1 data0(13),symbol(216) + + call chkmsg(message,cok,nspecial,flip) + call packmsg(message,dgen,itype,.false.) !Pack 72-bit message into 12 six-bit symbols + call entail(dgen,data0) + call encode232(data0,206,symbol) !Convolutional encoding + call interleave4(symbol,1) !Apply JT4 interleaving + do i=1,206 + ncode(i)=symbol(i) + enddo + +end subroutine encode4 diff --git a/lib/encode_msk144.f90 b/lib/encode_msk144.f90 new file mode 100644 index 00000000..4e4d8968 --- /dev/null +++ b/lib/encode_msk144.f90 @@ -0,0 +1,111 @@ +subroutine encode_msk144(message,codeword) +! Encode an 80-bit message and return a 128-bit codeword. +! The generator matrix has dimensions (48,80). +! The code is a (128,80) regular ldpc code with column weight 3. +! 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 stored in Radford Neal's "pchk" format. +! +character*20 g(48) +integer*1 codeword(128) +integer*1 colorder(128) +integer*1 gen144(48,80) +integer*1 itmp(128) +integer*1 message(80) +integer*1 pchecks(48) +logical first +data first/.true./ +data g/ & !parity-check generator matrix for (128,80) code + "24084000800020008000", & + "b39678f7ccdb1baf5f4c", & + "10001000400408012000", & + "08104000100002010800", & + "dc9c18f61ea0e4b7f05c", & + "42c040160909ca002c00", & + "cc50b52b9a80db0d7f9e", & + "dde5ace80780bae74740", & + "00800080020000890080", & + "01020040010400400040", & + "20008010020000100030", & + "80400008004000040050", & + "a4b397810915126f5604", & + "04040100001040200008", & + "00800006000888000800", & + "00010c00000104040001", & + "cc7cd7d953cdc204eba0", & + "0094abe7dd146beb16ce", & + "5af2aec8c7b051c7544a", & + "14040508801840200088", & + "7392f5e720f8f5a62c1e", & + "503cc2a06bff4e684ec9", & + "5a2efd46f1efbb513b80", & + "ac06e9513fd411f1de03", & + "16a31be3dd3082ca2bd6", & + "28542e0daf62fe1d9332", & + "00210c002001540c0401", & + "0ed90d56f84298706a98", & + "939670f7ecdf9baf4f4c", & + "cfe41dec47a433e66240", & + "16d2179c2d5888222630", & + "408000160108ca002800", & + "808000830a00018900a0", & + "9ae2ed8ef3afbf8c3a52", & + "5aaafd86f3efbfc83b02", & + "f39658f68cdb0baf1f4c", & + "9414bb6495106261366a", & + "71ba18670c08411bf682", & + "7298f1a7217cf5c62e5e", & + "86d7a4864396a981369b", & + "a8042c01ae22fe191362", & + "9235ae108b2d60d0e306", & + "dfe5ade807a03be74640", & + "d2451588e6e27ccd9bc4", & + "12b51ae39d20e2ea3bde", & + "a49387810d95136fd604", & + "467e7578e51d5b3b8a0e", & + "f6ad1ac7cc3aaa3fe580"/ + +data colorder/0,1,2,3,4,5,6,7,8,9, & + 10,11,12,13,14,15,24,26,29,30, & + 32,43,44,47,60,77,79,97,101,111, & + 96,38,64,53,93,34,59,94,74,90, & + 108,123,85,57,70,25,69,62,48,49, & + 50,51,52,33,54,55,56,21,58,36, & + 16,61,23,63,20,65,66,67,68,46, & + 22,71,72,73,31,75,76,45,78,17, & + 80,81,82,83,84,42,86,87,88,89, & + 39,91,92,35,37,95,19,27,98,99, & + 100,28,102,103,104,105,106,107,40,109, & + 110,18,112,113,114,115,116,117,118,119, & + 120,121,122,41,124,125,126,127/ + +save first,gen144 + +if( first ) then ! fill the generator matrix + gen144=0 + do i=1,48 + do j=1,5 + read(g(i)( (j-1)*4+1:(j-1)*4+4 ),"(Z4)") istr + do jj=1,16 + icol=(j-1)*16+jj + if( btest(istr,16-jj) ) gen144(i,icol)=1 + enddo + enddo + enddo +first=.false. +endif + +do i=1,48 + nsum=0 + do j=1,80 + nsum=nsum+message(j)*gen144(i,j) + enddo + pchecks(i)=mod(nsum,2) +enddo +itmp(1:48)=pchecks +itmp(49:128)=message(1:80) +codeword(colorder+1)=itmp(1:128) + +return +end subroutine encode_msk144 diff --git a/lib/encode_msk40.f90 b/lib/encode_msk40.f90 new file mode 100644 index 00000000..9c53255b --- /dev/null +++ b/lib/encode_msk40.f90 @@ -0,0 +1,46 @@ +subroutine encode_msk40(message,codeword) +! Encode a 16-bit message and return a 32-bit codeword. +! The code is a (32,16) regular ldpc code with column weight 3. +! 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 stored in Radford Neal's "pchk" format. +! +integer*1 codeword(32) +integer*1 colorder(32) +integer g(16) +integer*1 gen40(16,16) +integer*1 itmp(32) +integer*1 message(16) +integer*1 pchecks(16) +logical first +data first/.true./ +data g/Z'4428',Z'5a6b',Z'1b04',Z'2c12',Z'60c4',Z'1071',Z'be6a',Z'36dd', & + Z'c580',Z'ad9a',Z'eca2',Z'7843',Z'332e',Z'a685',Z'5906',Z'1efe'/ +data colorder/4,1,2,3,0,8,6,10,13,28,20,23,17,15,27,25, & + 16,12,18,19,7,21,22,11,24,5,26,14,9,29,30,31/ +save first,gen40 + +if( first ) then ! fill the generator matrix + gen40=0 + do i=1,16 + do j=1,16 + if( btest(g(i),16-j) ) gen40(i,j)=1 + enddo + enddo + first=.false. +endif + +do i=1,16 + nsum=0 + do j=1,16 + nsum=nsum+message(j)*gen40(i,j) + enddo + pchecks(i)=mod(nsum,2) +enddo +itmp(1:16)=pchecks +itmp(17:32)=message(1:16) +codeword(colorder+1)=itmp(1:32) + +return +end subroutine encode_msk40 diff --git a/lib/ephem.f90 b/lib/ephem.f90 new file mode 100644 index 00000000..a24ddbd0 --- /dev/null +++ b/lib/ephem.f90 @@ -0,0 +1,85 @@ +subroutine ephem(mjd0,dut,east_long,geodetic_lat,height,nspecial, & + RA,Dec,Az,El,techo,dop,fspread_1GHz,vr) + + implicit real*8 (a-h,o-z) + real*8 jd !Time of observationa as a Julian Date + real*8 mjd,mjd0 !Modified Julian Date + real*8 prec(3,3) !Precession matrix, J2000 to Date + real*8 rmatn(3,3) !Nutation matrix + real*8 rme2000(6) !Vector from Earth center to Moon, JD2000 + real*8 rmeDate(6) !Vector from Earth center to Moon at Date + real*8 rmeTrue(6) !Include nutation + real*8 raeTrue(6) !Vector from Earth center to Obs at Date + real*8 rmaTrue(6) !Vector from Obs to Moon at Date + logical km,bary !Set km=.true. to get km, km/s from ephemeris + common/stcomx/km,bary,pvsun(6) !Common used in JPL subroutines + common/librcom/xl(2),b(2) + + twopi=8.d0*atan(1.d0) !Define some constants + rad=360.d0/twopi + clight=2.99792458d5 + au2km=0.1495978706910000d9 + pi=0.5d0*twopi + pio2=0.5d0*pi + km=.true. + freq=1000.0d6 + + do jj=1,2 + mjd=mjd0 + if(jj.eq.1) mjd=mjd - 1.d0/1440.d0 + djutc=mjd + jd=2400000.5d0 + mjd + djtt=mjd + sla_DTT(jd)/86400.d0 + ttjd=jd + sla_DTT(jd)/86400.d0 + + if(nspecial.ne.8) then + call pleph(ttjd,10,3,rme2000) !RME (J2000) from JPL ephemeris + + year=2000.d0 + (jd-2451545.d0)/365.25d0 + call sla_PREC (2000.0d0, year, prec) !Get precession matrix + rmeDate(1:3)=matmul(prec,rme2000(1:3)) !Moon geocentric xyz at Date + rmeDate(4:6)=matmul(prec,rme2000(4:6)) !Moon geocentric vel at Date + else + call sla_DMOON(djtt,rmeDate) !No JPL ephemeris, use DMOON + rmeDate=rmeDate*au2km + endif + + if(nspecial.eq.7) then + rmeTrue=rmeDate + else +!Nutation to true equinox of Date + call sla_NUT(djtt,rmatn) + call sla_DMXV(rmatn,rmeDate,rmeTrue) + call sla_DMXV(rmatn,rmeDate(4),rmeTrue(4)) + endif + +! Local Apparent Sidereal Time: + djut1=djutc + dut/86400.d0 + if(nspecial.eq.6) djut1=djutc + xlast=sla_DRANRM(sla_GMST(djut1) + sla_EQEQX(djtt) + east_long) + call sla_PVOBS(geodetic_lat,height,xlast,raeTrue) + rmaTrue=rmeTrue - raeTrue*au2km + + if(nspecial.ne.2) then +! Allow for planetary aberration + tl=499.004782D0*SQRT(rmaTrue(1)**2 + rmaTrue(2)**2 + rmaTrue(3)**2) + rmaTrue(1:3)=rmaTrue(1:3)-tl*rmaTrue(4:6)/au2km + endif + +!Topocentric RA, Dec, dist, velocity + call sla_DC62S(rmaTrue,RA,Dec,dist,RAdot,DECdot,vr) + dop=-2.d0 * freq * vr/clight !EME doppler shift + techo=2.d0*dist/clight !Echo delay time (s) + call libration(jd,RA,Dec,xl(jj),b(jj)) + enddo + + fspread_1GHz=0.0d0 + dldt=57.2957795131*(xl(2)-xl(1)) + dbdt=57.2957795131*(b(2)-b(1)) + rate=sqrt((2*dldt)**2 + (2*dbdt)**2) + fspread_1GHz=0.5*6741*rate + + call sla_DE2H(xlast-RA,Dec,geodetic_lat,Az,El) + + return +end subroutine ephem diff --git a/lib/extract.F90 b/lib/extract.F90 deleted file mode 100644 index 4760aa33..00000000 --- a/lib/extract.F90 +++ /dev/null @@ -1,120 +0,0 @@ -subroutine extract(s3,nadd,nqd,ncount,nhist,decoded,ltext,nbmkv) - -! Input: -! s3 64-point spectra for each of 63 data symbols -! nadd number of spectra summed into s3 -! nqd 0/1 to indicate decode attempt at QSO frequency - -! Output: -! ncount number of symbols requiring correction -! nhist maximum number of identical symbol values -! decoded decoded message (if ncount >=0) -! ltext true if decoded message is free text -! nbmkv 0=no decode; 1=BM decode; 2=KV decode - - use prog_args !shm_key, exe_dir, data_dir - - real s3(64,63) - character decoded*22 - integer dat4(12) - integer mrsym(63),mr2sym(63),mrprob(63),mr2prob(63) - logical nokv,ltext - common/decstats/num65,numbm,numkv,num9,numfano - data nokv/.false./,nsec1/0/ - save - - nbirdie=7 - npct=40 - afac1=10.1 - xlambda=7.999 - if(nqd.eq.1) xlambda=11.999 !Increase depth at QSO frequency - nbmkv=0 - nfail=0 - decoded=' ' - call pctile(s3,4032,npct,base) - s3=s3/base - -! Get most reliable and second-most-reliable symbol values, and their -! probabilities -1 call demod64a(s3,nadd,afac1,mrsym,mrprob,mr2sym,mr2prob,ntest,nlow) - if(ntest.lt.100) then - ncount=-999 !Flag and reject bad data - go to 900 - endif - - call chkhist(mrsym,nhist,ipk) !Test for birdies and QRM - if(nhist.ge.nbirdie) then - nfail=nfail+1 - call pctile(s3,4032,npct,base) - s3(ipk,1:63)=base - if(nfail.gt.30) then - decoded=' ' - ncount=-1 - go to 900 - endif - go to 1 - endif - - call graycode65(mrsym,63,-1) !Remove gray code and interleaving - call interleave63(mrsym,-1) !from most reliable symbols - call interleave63(mrprob,-1) - num65=num65+1 - -! Decode using Berlekamp-Massey algorithm - call timer('rs_decod',0) - call rs_decode(mrsym,0,0,dat4,ncount) - call timer('rs_decod',1) - if(ncount.ge.0) then - call unpackmsg(dat4,decoded) - if(iand(dat4(10),8).ne.0) ltext=.true. - nbmkv=1 - go to 900 - endif - -! Berlekamp-Massey algorithm failed, try Koetter-Vardy - if(nokv) go to 900 - - maxe=8 !Max KV errors in 12 most reliable symbols - call graycode65(mr2sym,63,-1) !Remove gray code and interleaving - call interleave63(mr2sym,-1) !from second-most-reliable symbols - call interleave63(mr2prob,-1) - - nsec1=nsec1+1 - dat4=0 - write(22,rec=1) nsec1,xlambda,maxe,200,mrsym,mrprob,mr2sym,mr2prob - write(22,rec=2) -1,-1,dat4 - call flush(22) - call timer('kvasd ',0) - -#ifdef WIN32 - iret=system('""'//trim(exe_dir)//'/kvasd" "'//trim(temp_dir)//'/kvasd.dat" >"'//trim(temp_dir)//'/dev_null""') -#else - iret=system('"'//trim(exe_dir)//'/kvasd" "'//trim(temp_dir)//'/kvasd.dat" >/dev/null') -#endif - - call timer('kvasd ',1) - if(iret.ne.0) then - if(.not.nokv) write(*,1000) iret -1000 format('Error in KV decoder, or no KV decoder present.',i12) -! nokv=.true. - go to 900 - endif - - read(22,rec=2,err=900) nsec2,ncount,dat4 - j=nsec2 !Silence compiler warning - decoded=' ' - ltext=.false. - if(ncount.ge.0) then - call unpackmsg(dat4,decoded) !Unpack the user message - if(index(decoded,'...... ').gt.0) then - ncount=-1 - go to 900 - endif - if(iand(dat4(10),8).ne.0) ltext=.true. - nbmkv=2 - endif - -900 continue - - return -end subroutine extract diff --git a/lib/extract.f90 b/lib/extract.f90 new file mode 100644 index 00000000..3e7fa6fe --- /dev/null +++ b/lib/extract.f90 @@ -0,0 +1,156 @@ +subroutine extract(s3,nadd,mode65,ntrials,naggressive,ndepth,nflip, & + mycall_12,hiscall_12,hisgrid,nexp_decode,ncount,nhist,decoded, & + ltext,nft,qual) + +! Input: +! s3 64-point spectra for each of 63 data symbols +! nadd number of spectra summed into s3 +! nqd 0/1 to indicate decode attempt at QSO frequency + +! Output: +! ncount number of symbols requiring correction (-1 for no KV decode) +! nhist maximum number of identical symbol values +! decoded decoded message (if ncount >=0) +! ltext true if decoded message is free text +! nft 0=no decode; 1=FT decode; 2=hinted decode + + use prog_args !shm_key, exe_dir, data_dir + use packjt + use jt65_mod + use timer_module, only: timer + + real s3(64,63) + character decoded*22 + character*12 mycall_12,hiscall_12 + character*6 mycall,hiscall,hisgrid + integer dat4(12) + integer mrsym(63),mr2sym(63),mrprob(63),mr2prob(63) + integer correct(63),tmp(63) + logical ltext + common/chansyms65/correct + save + + if(mode65.eq.-99) stop !Silence compiler warning + mycall=mycall_12(1:6) + hiscall=hiscall_12(1:6) + qual=0. + nbirdie=20 + npct=50 + afac1=1.1 + nft=0 + nfail=0 + decoded=' ' + call pctile(s3,4032,npct,base) + s3=s3/base + s3a=s3 !### + +! Get most reliable and second-most-reliable symbol values, and their +! probabilities +1 call demod64a(s3,nadd,afac1,mrsym,mrprob,mr2sym,mr2prob,ntest,nlow) + + call chkhist(mrsym,nhist,ipk) !Test for birdies and QRM + if(nhist.ge.nbirdie) then + nfail=nfail+1 + call pctile(s3,4032,npct,base) + s3(ipk,1:63)=base + if(nfail.gt.30) then + decoded=' ' + ncount=-1 + go to 900 + endif + go to 1 + endif + + mrs=mrsym + mrs2=mr2sym + + call graycode65(mrsym,63,-1) !Remove gray code + call interleave63(mrsym,-1) !Remove interleaving + call interleave63(mrprob,-1) + + call graycode65(mr2sym,63,-1) !Remove gray code and interleaving + call interleave63(mr2sym,-1) !from second-most-reliable symbols + call interleave63(mr2prob,-1) + ntry=0 + + call timer('ftrsd ',0) + param=0 + call ftrsd2(mrsym,mrprob,mr2sym,mr2prob,ntrials,correct,param,ntry) + call timer('ftrsd ',1) + ncandidates=param(0) + nhard=param(1) + nsoft=param(2) + nerased=param(3) + rtt=0.001*param(4) + ntotal=param(5) + qual=0.001*param(7) + nd0=81 + r0=0.87 + if(naggressive.eq.10) then + nd0=83 + r0=0.90 + endif + if(ntotal.le.nd0 .and. rtt.le.r0) nft=1 + + if(nft.eq.0 .and. iand(ndepth,32).eq.32) then + qmin=2.0 - 0.1*naggressive + call timer('hint65 ',0) + call hint65(s3,mrs,mrs2,nadd,nflip,mycall,hiscall,hisgrid,qual,decoded) + if(qual.ge.qmin) then + nft=2 + ncount=0 + else + decoded=' ' + ntry=0 + endif + call timer('hint65 ',1) + go to 900 + endif + + ncount=-1 + decoded=' ' + ltext=.false. + if(nft.gt.0) then +! Turn the corrected symbol array into channel symbols for subtraction; +! pass it back to jt65a via common block "chansyms65". + do i=1,12 + dat4(i)=correct(13-i) + enddo + do i=1,63 + tmp(i)=correct(64-i) + enddo + correct(1:63)=tmp(1:63) + call interleave63(correct,63,1) + call graycode65(correct,63,1) + call unpackmsg(dat4,decoded,.false.,' ') !Unpack the user message + ncount=0 + if(iand(dat4(10),8).ne.0) ltext=.true. + endif +900 continue + if(nft.eq.1 .and. nhard.lt.0) decoded=' ' + + return +end subroutine extract + +subroutine getpp(workdat,p) + + use jt65_mod + integer workdat(63) + integer a(63) + + a(1:63)=workdat(63:1:-1) + call interleave63(a,1) + call graycode(a,63,1,a) + + psum=0. + do j=1,63 + i=a(j)+1 + x=s3a(i,j) + s3a(i,j)=0. + psum=psum + x + s3a(i,j)=x + enddo + p=psum/63.0 + + return +end subroutine getpp diff --git a/lib/extract4.f90 b/lib/extract4.f90 index 06229460..46c317c2 100644 --- a/lib/extract4.f90 +++ b/lib/extract4.f90 @@ -1,61 +1,69 @@ -subroutine extract4(sym,nadd,ncount,decoded) - - real sym(207) - character decoded*22, submode*1 - character*72 c72 - integer*1 symbol(207) - integer*1 data1(13) !Decoded data (8-bit bytes) - integer data4a(9) !Decoded data (8-bit bytes) - integer data4(12) !Decoded data (6-bit bytes) - integer mettab(0:255,0:1) !Metric table - logical first - data first/.true./ - save first,mettab - - if(first) then - call getmet24(mode,mettab) - first=.false. - endif - - do j=1,207 - r=sym(j) + 128. - if(r.gt.255.0) r=255.0 - if(r.lt.0.0) r=0.0 - i4=nint(r) - if(i4.gt.127) i4=i4-256 - symbol(j)=i4 - enddo - - nbits=72+31 - ndelta=50 - limit=100000 - ncycles=0 - ncount=-1 - decoded=' ' - submode=' ' - - call interleave24(symbol(2),-1) !Remove the interleaving - call fano232(symbol(2),nbits,mettab,ndelta,limit,data1,ncycles,metric,ncount) - nlim=ncycles/nbits - - if(ncount.ge.0) then - do i=1,9 - i4=data1(i) - if(i4.lt.0) i4=i4+256 - data4a(i)=i4 - enddo - write(c72,1100) (data4a(i),i=1,9) -1100 format(9b8.8) - read(c72,1102) data4 -1102 format(12b6) - - call unpackmsg(data4,decoded) - submode=char(ichar('A')+ich-1) - if(decoded(1:6).eq.'000AAA') then - decoded='***WRONG MODE?***' - ncount=-1 - endif - endif - - return -end subroutine extract4 +subroutine extract4(sym0,ncount,decoded) + + use packjt + real sym0(207) + real sym(207) + character decoded*22 + character*72 c72 + integer*1 symbol(207) + integer*1 data1(13) !Decoded data (8-bit bytes) + integer data4a(9) !Decoded data (8-bit bytes) + integer data4(12) !Decoded data (6-bit bytes) + integer mettab(-128:127,0:1) !Metric table + logical first + data first/.true./ + save first,mettab,ndelta + + if(first) then + call getmet4(mettab,ndelta) + first=.false. + endif + +!### Optimize these params: ... + amp=30.0 + limit=10000 + + ave0=sum(sym0)/207.0 + sym=sym0-ave0 + sq=dot_product(sym,sym) + rms0=sqrt(sq/206.0) + sym=sym/rms0 + + do j=1,207 + n=nint(amp*sym(j)) + if(n.lt.-127) n=-127 + if(n.gt.127) n=127 + symbol(j)=n + enddo + + nbits=72 + ncycles=0 + ncount=-1 + decoded=' ' + call interleave4(symbol(2),-1) !Remove the interleaving + call fano232(symbol(2),nbits+31,mettab,ndelta,limit,data1, & + ncycles,metric,ncount) + nlim=ncycles/(nbits+31) + +!### Make usage here like that in jt9fano... + if(ncount.ge.0) then + do i=1,9 + i4=data1(i) + if(i4.lt.0) i4=i4+256 + data4a(i)=i4 + enddo + write(c72,1100) (data4a(i),i=1,9) +1100 format(9b8.8) + read(c72,1102) data4 +1102 format(12b6) + + call unpackmsg(data4,decoded,.false.,' ') + if(decoded(1:6).eq.'000AAA') then +! decoded='***WRONG MODE?***' + decoded=' ' + ncount=-1 + endif + endif + + return +end subroutine extract4 diff --git a/lib/extractmessage144.f90 b/lib/extractmessage144.f90 new file mode 100644 index 00000000..a5dadb0b --- /dev/null +++ b/lib/extractmessage144.f90 @@ -0,0 +1,51 @@ +subroutine extractmessage144(decoded,msgreceived,nhashflag,recent_calls,nrecent) + use iso_c_binding, only: c_loc,c_size_t + use packjt + use hashing + + character*22 msgreceived + character*12 call1,call2 + character*12 recent_calls(nrecent) + integer*1 decoded(80) + integer*1, target:: i1Dec8BitBytes(10) + integer*1 i1hashdec + integer*4 i4Dec6BitWords(12) + +! Collapse 80 decoded bits to 10 bytes. Bytes 1-9 are the message, byte 10 is the hash + do ibyte=1,10 + itmp=0 + do ibit=1,8 + itmp=ishft(itmp,1)+iand(1,decoded((ibyte-1)*8+ibit)) + enddo + i1Dec8BitBytes(ibyte)=itmp + enddo + +! Calculate the hash using the first 9 bytes. + ihashdec=nhash(c_loc(i1Dec8BitBytes),int(9,c_size_t),146) + ihashdec=2*iand(ihashdec,255) + +! Compare calculated hash with received byte 10 - if they agree, keep the message. + i1hashdec=ihashdec + if( i1hashdec .eq. i1Dec8BitBytes(10) ) then +! Good hash --- unpack 72-bit message + do ibyte=1,12 + itmp=0 + do ibit=1,6 + itmp=ishft(itmp,1)+iand(1,decoded((ibyte-1)*6+ibit)) + enddo + i4Dec6BitWords(ibyte)=itmp + enddo + call unpackmsg144(i4Dec6BitWords,msgreceived,call1,call2) + nhashflag=1 + if( call1(1:2) .ne. 'CQ' .and. call1(1:2) .ne. ' ' ) then + call update_recent_calls(call1,recent_calls,nrecent) + endif + if( call2(1:2) .ne. ' ' ) then + call update_recent_calls(call2,recent_calls,nrecent) + endif + else + msgreceived=' ' + nhashflag=-1 + endif + return + end subroutine extractmessage144 diff --git a/lib/f77_wisdom.f90 b/lib/f77_wisdom.f90 deleted file mode 100644 index 39bdff8e..00000000 --- a/lib/f77_wisdom.f90 +++ /dev/null @@ -1,45 +0,0 @@ -subroutine write_char(c, iunit) - character c - integer iunit - write(iunit,1000) c -1000 format(a,$) -end subroutine write_char - -subroutine export_wisdom_to_file(iunit) - integer iunit - external write_char -! call dfftw_export_wisdom(write_char, iunit) - call sfftw_export_wisdom(write_char, iunit) -end subroutine export_wisdom_to_file - -subroutine read_char(ic, iunit) - integer ic - integer iunit - character*256 buf - save buf - integer ibuf - data ibuf/257/ - save ibuf - if (ibuf .lt. 257) then - ic = ichar(buf(ibuf:ibuf)) - ibuf = ibuf + 1 - return - endif - read(iunit,1000,end=10) buf -1000 format(a256) - ic = ichar(buf(1:1)) - ibuf = 2 - return -10 ic = -1 - ibuf = 257 - rewind iunit - return -end subroutine read_char - -subroutine import_wisdom_from_file(isuccess, iunit) - integer isuccess - integer iunit - external read_char -! call dfftw_import_wisdom(isuccess, read_char, iunit) - call sfftw_import_wisdom(isuccess, read_char, iunit) -end subroutine import_wisdom_from_file diff --git a/lib/fano232.f90 b/lib/fano232.f90 index 21906daa..dc3c639f 100644 --- a/lib/fano232.f90 +++ b/lib/fano232.f90 @@ -9,14 +9,14 @@ subroutine fano232(symbol,nbits,mettab,ndelta,maxcycles,dat, & parameter (MAXBYTES=(MAXBITS+7)/8) integer*1 symbol(0:2*MAXBITS-1) !Soft symbols (as unsigned i*1) integer*1 dat(MAXBYTES) !Decoded user data, 8 bits per byte - integer mettab(-128:127,0:1) !Metric table + integer mettab(-128:127,0:1) !Metric table ! These were the "node" structure in Karn's C code: - integer nstate(0:MAXBITS-1) !Encoder state of next node - integer gamma(0:MAXBITS-1) !Cumulative metric to this node - integer metrics(0:3,0:MAXBITS-1) !Metrics indexed by all possible Tx syms - integer tm(0:1,0:MAXBITS-1) !Sorted metrics for current hypotheses - integer ii(0:MAXBITS-1) !Current branch being tested + integer nstate(0:MAXBITS) !Encoder state of next node + integer gamma(0:MAXBITS) !Cumulative metric to this node + integer metrics(0:3,0:MAXBITS) !Metrics indexed by all possible Tx syms + integer tm(0:1,0:MAXBITS) !Sorted metrics for current hypotheses + integer ii(0:MAXBITS) !Current branch being tested logical noback include 'conv232.f90' !Polynomials defined here @@ -69,7 +69,7 @@ subroutine fano232(symbol,nbits,mettab,ndelta,maxcycles,dat, & gamma(np+1)=ngamma !Move forward nstate(np+1)=ishft(nstate(np),1) np=np+1 - if(np.eq.nbits-1) go to 100 !We're done! + if(np.eq.nbits) go to 100 !We're done! n=iand(nstate(np),npoly1) n=ieor(n,ishft(n,-16)) diff --git a/lib/fast9.f90 b/lib/fast9.f90 new file mode 100644 index 00000000..12148624 --- /dev/null +++ b/lib/fast9.f90 @@ -0,0 +1,191 @@ +subroutine fast9(id2,narg,line) + +! Decoder for "fast9" modes, JT9E to JT9H. + + parameter (NMAX=30*12000,NSAVE=500) + integer*2 id2(0:NMAX) + integer narg(0:14) + integer*1 i1SoftSymbols(207) + integer*1 i1save(207,NSAVE) + integer indx(NSAVE) + integer*8 count0,count1,clkfreq + real s1(720000) !To reserve space. Logically s1(nq,jz) + real s2(240,340) !Symbol spectra at quarter-symbol steps + real ss2(0:8,85) !Folded symbol spectra + real ss3(0:7,69) !Folded spectra without sync symbols + real s(1500) + real ccfsave(NSAVE) + real t0save(NSAVE) + real t1save(NSAVE) + real freqSave(NSAVE) + real t(6) + character*22 msg !Decoded message + character*80 line(100) + data nsubmode0/-1/,ntot/0/ + save s1,nsubmode0,ntot + +! Parameters from GUI are in narg(): + nutc=narg(0) !UTC + npts=min(narg(1),NMAX) !Number of samples in id2 (12000 Hz) + nsubmode=narg(2) !0=A 1=B 2=C 3=D 4=E 5=F 6=G 7=H + if(nsubmode.lt.4) go to 900 + newdat=narg(3) !1==> new data, compute symbol spectra + minsync=narg(4) !Lower sync limit + npick=narg(5) + t0=0.001*narg(6) + t1=0.001*narg(7) + maxlines=narg(8) !Max # of decodes to return to caller + nmode=narg(9) + nrxfreq=narg(10) !Targer Rx audio frequency (Hz) + ntol=narg(11) !Search range, +/- ntol (Hz) + + tmid=npts*0.5/12000.0 + line(1:100)(1:1)=char(0) + s=0 + s2=0 + nsps=60 * 2**(7-nsubmode) !Samples per sysbol + nfft=2*nsps !FFT size + nh=nfft/2 + nq=nfft/4 + istep=nsps/4 !Symbol spectra at quarter-symbol steps + jz=npts/istep + df=12000.0/nfft !FFT bin width + db1=db(2500.0/df) + nfa=max(200,nrxfreq-ntol) !Lower frequency limit + nfb=min(nrxfreq+ntol,2500) !Upper frequency limit + nline=0 + t=0. + + if(newdat.eq.1 .or. nsubmode.ne.nsubmode0) then + call system_clock(count0,clkfreq) + call spec9f(id2,npts,nsps,s1,jz,nq) !Compute symbol spectra, s1 + call system_clock(count1,clkfreq) + t(1)=t(1)+float(count1-count0)/float(clkfreq) + endif + + nsubmode0=nsubmode + tmsg=nsps*85.0/12000.0 + limit=2000 + nlen0=0 + i1=0 + i2=0 + ccfsave=0. + do ilength=1,14 + nlen=1.4142136**(ilength-1) + if(nlen.gt.jz/340) nlen=jz/340 + if(nlen.eq.nlen0) cycle + nlen0=nlen + + db0=db(float(nlen)) + jlen=nlen*340 + jstep=jlen/4 !### Is this about right? ### + if(nsubmode.ge.6) jstep=jlen/2 + + do ja=1,jz-jlen,jstep + jb=ja+jlen-1 + call system_clock(count0,clkfreq) + call foldspec9f(s1,nq,jz,ja,jb,s2) !Fold symbol spectra into s2 + call system_clock(count1,clkfreq) + t(2)=t(2)+float(count1-count0)/float(clkfreq) + +! Find sync; put sync'ed symbol spectra into ss2 and ss3 +! Might want to do a peakup in DT and DF, then re-compute symbol spectra. + + call system_clock(count0,clkfreq) + call sync9f(s2,nq,nfa,nfb,ss2,ss3,lagpk,ipk,ccfbest) + call system_clock(count1,clkfreq) + t(3)=t(3)+float(count1-count0)/float(clkfreq) + + i1=i1+1 + if(ccfbest.lt.30.0) cycle + call system_clock(count0,clkfreq) + call softsym9f(ss2,ss3,i1SoftSymbols) !Compute soft symbols + call system_clock(count1,clkfreq) + t(4)=t(4)+float(count1-count0)/float(clkfreq) + + i2=i2+1 + ccfsave(i2)=ccfbest + i1save(1:207,i2)=i1SoftSymbols + t0=(ja-1)*istep/12000.0 + t1=(jb-1)*istep/12000.0 + t0save(i2)=t0 + t1save(i2)=t1 + freq=ipk*df + freqSave(i2)=freq + enddo + enddo + nsaved=i2 + + ccfsave(1:nsaved)=-ccfsave(1:nsaved) + call system_clock(count0,clkfreq) + indx=0 + call indexx(ccfsave,nsaved,indx) + call system_clock(count1,clkfreq) + t(5)=t(5)+float(count1-count0)/float(clkfreq) + + ccfsave(1:nsaved)=-ccfsave(1:nsaved) + + do iter=1,2 +! do isave=1,nsaved + do isave=1,50 + i2=indx(isave) + if(i2.lt.1 .or. i2.gt.nsaved) cycle !### Why needed? ### + t0=t0save(i2) + t1=t1save(i2) + if(iter.eq.1 .and. t1.lt.tmid) cycle + if(iter.eq.2 .and. t1.ge.tmid) cycle + ccfbest=ccfsave(i2) + i1SoftSymbols=i1save(1:207,i2) + freq=freqSave(i2) + call system_clock(count0,clkfreq) + call jt9fano(i1SoftSymbols,limit,nlim,msg) !Invoke Fano decoder + call system_clock(count1,clkfreq) + t(6)=t(6)+float(count1-count0)/float(clkfreq) + + i=t0*12000.0 + kz=(t1-t0)/0.02 + smax=0. + do k=1,kz + sq=0. + do n=1,240 + i=i+1 + x=id2(i) + sq=sq+x*x + enddo + s(k)=sq/240. + smax=max(s(k),smax) + enddo + call pctile(s,kz,35,base) + snr=smax/(1.1*base) - 1.0 + nsnr=-20 + if(snr.gt.0.0) nsnr=nint(db(snr)) + +! write(72,3002) nutc,iter,isave,nlen,tmid,t0,t1,ccfbest, & +! nint(freq),nlim,msg +!3002 format(i6.6,i1,i4,i3,4f6.1,i5,i7,1x,a22) + + if(msg.ne.' ') then + +! Display multiple decodes only if they differ: + do n=1,nline + if(index(line(n),msg).gt.1) go to 100 + enddo +!### Might want to use decoded message to get a complete estimate of S/N. + nline=nline+1 + write(line(nline),1000) nutc,nsnr,t0,nint(freq),msg,char(0) +1000 format(i6.6,i4,f5.1,i5,1x,'@ ',1x,a22,a1) + ntot=ntot+1 +! write(70,5001) nsaved,isave,nline,maxlines,ntot,nutc,msg +!5001 format(5i5,i7.6,1x,a22) + if(nline.ge.maxlines) go to 900 + endif +100 continue + enddo + enddo + +900 continue +! write(*,6001) t,t(6)/sum(t) +!6001 format(7f10.3) + + return +end subroutine fast9 diff --git a/lib/fast_decode.f90 b/lib/fast_decode.f90 new file mode 100644 index 00000000..eebb7310 --- /dev/null +++ b/lib/fast_decode.f90 @@ -0,0 +1,97 @@ +subroutine fast_decode(id2,narg,ntrperiod,line,mycall_12, & + hiscall_12) + + parameter (NMAX=30*12000) + integer*2 id2(NMAX) + integer*2 id2a(NMAX) + integer*2 id2b(NMAX) + integer narg(0:14) + real dat(30*12000) + complex cdat(262145),cdat2(262145) + real psavg(450) + logical pick,first + character*6 cfile6 + character*80 line(100) + character*12 mycall_12,hiscall_12 + character*6 mycall,hiscall + data first/.true./,nutca/0/,nutcb/0/ + save npts,cdat,cdat2,id2a,id2b,nutca,nutcb + + if(first) then + id2a=0 + id2b=0 + first=.false. + endif + + mycall=mycall_12(1:6) + hiscall=hiscall_12(1:6) + nutc=narg(0) + ndat0=narg(1) + nsubmode=narg(2) + newdat=narg(3) + minsync=narg(4) + npick=narg(5) + t0=0.001*narg(6) + t1=0.001*narg(7) + tmid=0.5*(t0+t1) + maxlines=narg(8) + nmode=narg(9) + nrxfreq=narg(10) + ntol=narg(11) + nhashcalls=narg(12) + + line(1:100)(1:1)=char(0) + if(t0.gt.float(ntrperiod)) go to 900 + if(t0.gt.t1) go to 900 + + if(nmode.eq.102) then + call fast9(id2,narg,line) + go to 900 + endif + + if(newdat.eq.1) then + cdat2=cdat + ndat=ndat0 + call wav11(id2,ndat,dat) + nzz=11025*ntrperiod + if(ndat.lt.nzz) dat(ndat+1:nzz)=0.0 + ndat=min(ndat,30*11025) + call ana932(dat,ndat,cdat,npts) !Make downsampled analytic signal + endif + +! Now cdat() is the downsampled analytic signal. +! New sample rate = fsample = BW = 11025 * (9/32) = 3100.78125 Hz +! NB: npts, nsps, etc., are all reduced by 9/32 + + write(cfile6,'(i6.6)') nutc + nfreeze=1 + mousedf=0 + mousebutton=0 + mode4=1 + if(nsubmode.eq.1) mode4=2 + nafc=0 + ndebug=0 + t2=0. + ia=1 + ib=npts + pick=.false. + + if(npick.gt.0) then + pick=.true. + dt=1.0/11025.0 * (32.0/9.0) + ia=t0/dt + 1. + ib=t1/dt + 1. + t2=t0 + endif + jz=ib-ia+1 + line(1:100)(1:1)=char(0) + if(npick.eq.2) then + call iscat(cdat2(ia),jz,3,40,t2,pick,cfile6,minsync,ntol,NFreeze, & + MouseDF,mousebutton,mode4,nafc,ndebug,psavg,nmax,nlines,line) + else + call iscat(cdat(ia),jz,3,40,t2,pick,cfile6,minsync,ntol,NFreeze, & + MouseDF,mousebutton,mode4,nafc,ndebug,psavg,maxlines,nlines,line) + endif + +900 return +end subroutine fast_decode diff --git a/lib/fcal.f90 b/lib/fcal.f90 new file mode 100644 index 00000000..701e9fad --- /dev/null +++ b/lib/fcal.f90 @@ -0,0 +1,117 @@ +program fcal + +! Compute Intercept (A) and Slope (B) for a series of FreqCal measurements. + parameter(NZ=1000) + implicit real*8 (a-h,o-z) + real*8 fd(NZ),deltaf(NZ),r(NZ) + character infile*50 + character line*80 + character cutc*8 + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: fcal ' + print*,'Example: fcal fmtave.out' + go to 999 + endif + call getarg(1,infile) + + open(10,file=infile,status='old',err=997) + open(12,file='fcal.out',status='unknown') + open(13,file='fcal.plt',status='unknown') + + i=0 + do j=1,9999 + read(10,1000,end=10) line +1000 format(a80) + i0=index(line,' 0 ') + i1=index(line,' 1 ') + if(i0.le.0 .and. i1.le.0) then + read(line,*,err=5) f,df + ncal=1 + i=i+1 + fd(i)=f + deltaf(i)=df + else if(i1.gt.0) then + i=i+1 + read(line,*,err=5) f,df,ncal,nn,rr,cutc + fd(i)=f + deltaf(i)=df + r(i)=0.d0 + endif +5 continue + enddo + +10 iz=i + if(iz.lt.2) go to 998 + call fit(fd,deltaf,r,iz,a,b,sigmaa,sigmab,rms) + + write(*,1002) +1002 format(' Freq DF Meas Freq Resid'/ & + ' (MHz) (Hz) (MHz) (Hz)'/ & + '-----------------------------------------') + do i=1,iz + fm=fd(i) + 1.d-6*deltaf(i) + calfac=1.d0 + 1.d-6*deltaf(i)/fd(i) + write(*,1010) fd(i),deltaf(i),fm,r(i) + write(13,1010) fd(i),deltaf(i),fm,r(i) +1010 format(f8.3,f9.3,f14.9,f9.3,2x,a6) + enddo + calfac=1.d0 + 1.d-6*b + err=1.d-6*sigmab + + if(iz.ge.3) then + write(*,1100) a,b,rms +1100 format(/'A:',f8.2,' Hz B:',f9.4,' ppm StdDev:',f7.3,' Hz') + if(iz.gt.2) write(*,1110) sigmaa,sigmab +1110 format('err:',f6.2,9x,f9.4,23x,f13.9) + else + write(*,1120) a,b +1120 format(/'A:',f8.2,' Hz B:',f9.4) + endif + + write(12,1130) a,b +1130 format(f10.4) + + go to 999 + +997 print*,'Cannot open input file: ',infile + go to 999 +998 print*,'Input file must contain at least 2 valid measurement pairs' + +999 end program fcal + +subroutine fit(x,y,r,iz,a,b,sigmaa,sigmab,rms) + implicit real*8 (a-h,o-z) + real*8 x(iz),y(iz),r(iz) + + sx=0.d0 + sy=0.d0 + sxy=0.d0 + sx2=0.d0 + do i=1,iz + sx=sx + x(i) + sy=sy + y(i) + sxy=sxy + x(i)*y(i) + sx2=sx2 + x(i)*x(i) + enddo + delta=iz*sx2 - sx*sx + a=(sx2*sy - sx*sxy)/delta + b=(iz*sxy - sx*sy)/delta + + sq=0.d0 + do i=1,iz + r(i)=y(i) - (a + b*x(i)) + sq=sq + r(i)**2 + enddo + rms=0. + sigmaa=0. + sigmab=0. + if(iz.ge.3) then + rms=sqrt(sq/(iz-2)) + sigmaa=sqrt(rms*rms*sx2/delta) + sigmab=sqrt(iz*rms*rms/delta) + endif + + return +end subroutine fit diff --git a/lib/fchisq.f90 b/lib/fchisq.f90 index 6eb8b6b6..1aa2b0bb 100644 --- a/lib/fchisq.f90 +++ b/lib/fchisq.f90 @@ -34,8 +34,11 @@ real function fchisq(c3,npts,fsample,a) sum0=sum0+pp endif enddo - sync=sum1/10000.0 - fchisq=-sync + sync_4992=(sum1/16.0)/(sum0/69.0) - 1.0 !r4992 + sync_4993=sum1/10000.0 !r4993+ +! write(80,3001) 1.e-5*sum1,1.e-5*sum0,sync_4992,sync_4993,sync +!3001 format(5f11.4) + fchisq=-sync_4993 return end function fchisq diff --git a/lib/fchisq0.f90 b/lib/fchisq0.f90 new file mode 100644 index 00000000..2c62f275 --- /dev/null +++ b/lib/fchisq0.f90 @@ -0,0 +1,23 @@ +real function fchisq0(y,npts,a) + + real y(npts),a(4) + +! rewind 51 + chisq = 0. + do i=1,npts + x=i + z=(x-a(3))/(0.5*a(4)) + yfit=a(1) + if(abs(z).lt.3.0) then + d=1.0 + z*z + yfit=a(1) + a(2) * (1.0/d - 0.1) + endif + chisq=chisq + (y(i) - yfit)**2 +! write(51,3001) i,y(i),yfit,y(i)-yfit +!3001 format(i5,3f10.4) + enddo + fchisq0=chisq + + return +end function fchisq0 + diff --git a/lib/fchisq65.f90 b/lib/fchisq65.f90 index b91444e5..3c624143 100644 --- a/lib/fchisq65.f90 +++ b/lib/fchisq65.f90 @@ -1,5 +1,7 @@ real function fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) + use timer_module, only: timer + parameter (NMAX=60*12000) !Samples per 60 s complex cx(npts) real a(5) @@ -17,7 +19,7 @@ real function fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) nout=ndiv*npts/nsps dtstep=1.0/(ndiv*baud) !Time per output step - if(a(1).ne.a1 .or. a(2).ne.a2 .or. a(3).ne.a3) then + if(a(1).ne.a1 .or. a(2).ne.a2 .or. a(3).ne.a3) then a1=a(1) a2=a(2) a3=a(3) @@ -32,36 +34,34 @@ real function fchisq65(cx,npts,fsample,nflip,a,ccfmax,dtmax) if(mod(i,100).eq.1) then p2=1.5*x*x - 0.5 dphi=(a(1) + x*a(2) + p2*a(3)) * (twopi/fsample) - wstep=cmplx(cos(dphi),sin(dphi)) + wstep=cmplx(cos(dphi),sin(dphi)) endif w=w*wstep csx(i)=csx(i-1) + w*cx(i) enddo endif -! Compute 1/2-symbol powers at 1/16-symbol steps. +! Compute whole-symbol powers at 1/16-symbol steps. fac=1.e-4 - do i=1,nout - j=i*nsps/ndiv - k=j-nsph + j=nsps+(i-1)*nsps/16 !steps by 8 samples (1/16 of a symbol) + k=j-nsps ss(i)=0. - if(k.ge.1) then - z=csx(j)-csx(k) + if(k.ge.0 .and. j.le.npts) then + z=csx(j)-csx(k) ! difference over span of 128 pts ss(i)=fac*(real(z)**2 + aimag(z)**2) endif enddo ccfmax=0. call timer('ccf2 ',0) - call ccf2(ss,nout,nflip,ccf,lagpk) + call ccf2(ss,nout,nflip,ccf,xlagpk) call timer('ccf2 ',1) if(ccf.gt.ccfmax) then ccfmax=ccf - dtmax=lagpk*dtstep + dtmax=xlagpk*dtstep endif fchisq65=-ccfmax - call timer('fchisq65',1) return diff --git a/lib/fer b/lib/fer new file mode 100755 index 00000000..7a74bf2a --- /dev/null +++ b/lib/fer @@ -0,0 +1,41 @@ +#!/bin/bash + +# jt65 end-to-end simulator. Run enough cases to get a given +# number of successful decodes or a given number of errors +# For better performance, copy this script and jt65, jt65sim +# executables to a ramdisk and run from there. + +mode=C +spread=4.0 + +for i in `seq 0 21`; +do +nruns=0 +ndecodes=0 +ngood=0 +nbad=0 +snr=$((-25+$i)) +#while [ $[ $nruns - $ngood ] -lt 200 ] +#while [ $ngood -lt 200 ] +while [ $nruns -lt 1000 ] +do + rm 000000_0001.wav + ./jt65sim -m $mode -n 1 -d $spread -s \\$snr > /dev/null + rm decoded.txt + ./jt65 -m $mode -a 10 -f 1500 -n 1000 -s 000000_0001.wav > decoded.txt + if [ -e decoded.txt ]; then + nd=$( wc -l < decoded.txt ) + ng=$( grep "K1ABC" decoded.txt | wc -l ) + nb=$[$nd-$ng] + ndecodes=$[$ndecodes + $nd] + ngood=$[$ngood + $ng] + nbad=$[$nbad + $nb] + fi + nruns=$[$nruns + 1] + nmissed=$[$nruns-$ngood] + pe=$( echo "scale=5; $nmissed/$nruns" | bc -l ) + ps=$( echo "scale=5; $ngood/$nruns" | bc -l ) + echo -en snr: $snr nruns: $nruns ndecodes: $ndecodes ngood: $ngood nbad: $nbad nmissed: $nmissed wer: $pe success: $ps"\r" +done +echo snr: $snr nruns: $nruns ndecodes: $ndecodes ngood: $ngood nbad: $nbad nmissed: $nmissed wer: $pe success: $ps +done diff --git a/lib/fer65.f90 b/lib/fer65.f90 new file mode 100644 index 00000000..1284fb54 --- /dev/null +++ b/lib/fer65.f90 @@ -0,0 +1,195 @@ +program fer65 + +! End-to-end simulator for testing JT65. + +! Options +! jt65sim jt65 +!---------------------------------------------------------------- +! -a aggressive +! -d Doppler spread -d depth +! -f Number of files -f freq +! -m (sub)mode -m (sub)mode +! -n number of generated sigs -n ntrials +! -t Time offset (s) -r robust sync +! -p Do not seed random #s -c mycall +! -x hiscall +! -g hisgrid +! -X hinted-decode flags +! -s S/N in 2500 Hz -s single-decode mode + + implicit real*8 (a-h,o-z) + real*8 s(7),sq(7) + character arg*12,cmnd*100,decoded*22,submode*1,csync*1,f1*15,f2*15 + character*12 outfile + logical syncok + + nargs=iargc() + if(nargs.ne.7) then + print*,'Usage: fer65 submode fspread snr1 snr2 Navg DS iters' + print*,'Example: fer65 C 3.0 -28 -12 8 1 1000' + go to 999 + endif + + call getarg(1,submode) + call getarg(2,arg) + read(arg,*) d + call getarg(3,arg) + read(arg,*) snr1 + call getarg(4,arg) + read(arg,*) snr2 + call getarg(5,arg) + read(arg,*) navg + call getarg(6,arg) + read(arg,*) nds + call getarg(7,arg) + read(arg,*) iters + + write(outfile,1001) submode,d,navg,nds +1001 format(a1,f6.2,'_',i2.2,'_',i1) + if(outfile(2:2).eq.' ') outfile(2:2)='0' + if(outfile(3:3).eq.' ') outfile(3:3)='0' + + ndepth=3 + if(navg.gt.1) ndepth=ndepth+16 + if(nds.ne.0) ndepth=ndepth+32 + + dfmax=3 + if(submode.eq.'b' .or. submode.eq.'B') dfmax=6 + if(submode.eq.'c' .or. submode.eq.'C') dfmax=11 + + ntrials=1000 + naggressive=10 + + open(20,file=outfile,status='unknown') + open(21,file='fer65.21',status='unknown') + + write(20,1000) submode,iters,ntrials,naggressive,d,ndepth,navg,nds +1000 format(/'JT65',a1,' Iters:',i5,' T:',i6,' Aggr:',i3, & + ' Dop:',f6.2,' Depth:',i2,' Navg:',i3,' DS:',i2) + write(20,1002) +1002 format(/' dB nsync ngood nbad sync dsnr ', & + 'DT Freq Nsum Width'/85('-')) + flush(20) + + do isnr=0,20 + snr=snr1+isnr + if(snr.gt.snr2) exit + nsync=0 + ngood=0 + nbad=0 + s=0. + sq=0. + do iter=1,iters + write(cmnd,1010) submode,d,snr,navg +1010 format('./jt65sim -n 1 -m ',a1,' -d',f7.2,' -s \\',f5.1,' -f',i3,' >devnull') + call unlink('000000_????.wav') + call system(cmnd) + if(navg.gt.1) then + do i=navg,2,-1 + j=2*i-1 + write(f1,1011) i + write(f2,1011) j +1011 format('000000_',i4.4,'.wav') + call rename(f1,f2) + enddo + endif + call unlink('decoded.txt') + call unlink('fort.13') + isync=0 + nsnr=0 + dt=0. + nfreq=0 + ndrift=0 + nwidth=0 + cmnd='./jt65 -m A -a 10 -c K1ABC -f 1500 -n 1000 -d 5 -s 000000_????.wav > decoded.txt' + cmnd(11:11)=submode + write(cmnd(47:48),'(i2)') ndepth + call system(cmnd) + open(13,file='fort.13',status='old',err=20) + do i=1,navg + read(13,1012) nutc,isync,nsnr,dt,nfreq,ndrift,nwidth,decoded, & + nft,nsum,nsmo +1012 format(i4,i4,i5,f6.2,i5,i4,i3,1x,a22,5x,3i3) + if(nft.gt.0) exit + enddo + close(13) + syncok=abs(dt).lt.0.2 .and. float(abs(nfreq-1500)).lt.dfmax + csync=' ' + if(syncok) csync='*' + write(21,1014) nutc,isync,nsnr,dt,nfreq,ndrift,nwidth, & + nft,nsum,nsmo,csync,decoded(1:16),nft,nsum,nsmo +1014 format(i4,i4,i5,f6.2,i5,i4,3x,4i3,1x,a1,1x,a16,i2,2i3) + flush(21) + + if(syncok) then + nsync=nsync+1 + s(1)=s(1) + isync + sq(1)=sq(1) + isync*isync + s(6)=s(6) + nwidth + sq(6)=sq(6) + nwidth*nwidth + if(decoded.eq.'K1ABC W9XYZ EN37 ') then + ngood=ngood+1 + s(2)=s(2) + nsnr + s(3)=s(3) + dt + s(4)=s(4) + nfreq + s(5)=s(5) + ndrift + s(7)=s(7) + nsum + + sq(2)=sq(2) + nsnr*nsnr + sq(3)=sq(3) + dt*dt + sq(4)=sq(4) + nfreq*nfreq + sq(5)=sq(5) + ndrift*ndrift + sq(7)=sq(7) + nsum*nsum + else if(decoded.ne.' ') then + nbad=nbad+1 + print*,'Nbad:',nbad,decoded + endif + endif +20 continue + fsync=float(nsync)/iter + fgood=float(ngood)/iter + fbad=float(nbad)/iter + write(*,1020) nint(snr),iter,isync,nsnr,dt,nfreq,ndrift,nwidth,fsync, & + fgood,fbad,decoded(1:16),nft,nsum,nsmo +1020 format(i3,i5,i3,i4,f6.2,i5,i3,i3,2f6.3,f7.4,1x,a16,i2,2i3) + enddo + + if(nsync.ge.1) then + xsync=s(1)/nsync + xwidth=s(6)/nsync + endif + esync=0. + if(nsync.ge.2) then + esync=sqrt(sq(1)/nsync - xsync**2) + ewidth=sqrt(sq(6)/nsync - xwidth**2) + endif + + if(ngood.ge.1) then + xsnr=s(2)/ngood + xdt=s(3)/ngood + xfreq=s(4)/ngood + xdrift=s(5)/ngood + xsum=s(7)/ngood + endif + if(ngood.ge.2) then + esnr=sqrt(sq(2)/ngood - xsnr**2) + edt=sqrt(sq(3)/ngood - xdt**2) + efreq=sqrt(sq(4)/ngood - xfreq**2) + edrift=sqrt(sq(5)/ngood - xdrift**2) + esum=sqrt(sq(7)/ngood - xsum**2) + endif + + dsnr=xsnr-snr + dfreq=xfreq-1500.0 + if(ngood.eq.0) then + dsnr=0. + dfreq=0. + endif + write(20,1100) snr,nsync,ngood,nbad,xsync,esync,dsnr,esnr, & + xdt,edt,dfreq,efreq,xsum,esum,xwidth,ewidth +1100 format(f5.1,2i6,i4,2f6.1,f6.1,f5.1,f6.2,f5.2,6f5.1) + flush(20) + if(ngood.ge.int(0.99*iters)) exit + enddo + +999 end program fer65 diff --git a/lib/fersum.f90 b/lib/fersum.f90 new file mode 100644 index 00000000..4a99561e --- /dev/null +++ b/lib/fersum.f90 @@ -0,0 +1,72 @@ +program fersum + + character mode*5 + character infile*40 + real dop(0:9) + real thresh(0:9,12),threshsync(0:9,12) + data dop/0.25,0.5,1.0,2.0,4.0,8.0,16.0,32.0,64.0,128.0/ + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: fersum ' + go to 999 + endif + call getarg(1,infile) + open(10,file=infile,status='old') + thresh=0. + threshsync=0. + + do iblk=1,999 +1 read(10,1002,end=100) mode,iters,ntot,naggr,d,navg,nds +1002 format(a5,8x,i5,4x,i6,7x,i3,6x,f6.2,17x,i3,5x,i2) + write(33,*) iblk,mode + if(mode.eq.' ') go to 1 + read(10,1002) + read(10,1002) + read(10,1002) + + nsync0=0 + ngood0=0 + xsum0=0. + do n=1,99 + read(10,1010,end=100) snr,nsync,ngood,nbad,xsync,esync,dsnr,esnr, & + xdt,edt,dfreq,efreq,xsum,esum,xwidth,ewidth +1010 format(f5.1,2i6i4,2f6.1,f6.1,f5.1,f6.2,f5.2,6f5.1) + if(snr.eq.0.0) exit + if(mode(5:5).eq.'A') nmode=1 + if(mode(5:5).eq.'B') nmode=2 + if(mode(5:5).eq.'C') nmode=3 + j=nint(log(d)/log(2.0) + 2.0) + if(navg.eq.1 .and. nds.eq.0) k=nmode + if(navg.eq.1 .and. nds.eq.1) k=nmode+3 + if(navg.gt.1 .and. nds.eq.0) k=nmode+6 + if(navg.gt.1 .and. nds.eq.1) k=nmode+9 + if(nsync0.le.iters/2 .and. nsync.ge.iters/2) then + threshsync(j,k)=snr-float(nsync-iters/2)/(nsync-nsync0) + endif + if(ngood0.le.iters/2 .and. ngood.ge.iters/2) then + threshold=snr-float(ngood-iters/2)/(ngood-ngood0) + xsumavg=max(1.0,0.5*(xsum0+xsum)) +! write(*,1020) mode,iters,ntot,naggr,d,navg,nds,threshold,xsumavg +!1020 format(a5,i7,i7,i3,f7.2,i3,i3,f7.1,f6.1) + thresh(j,k)=threshold + endif + nsync0=nsync + ngood0=ngood + xsum0=xsum + enddo + enddo + +100 write(12,1100) +1100 format(' ') + do i=0,9 + write(12,1110) dop(i),thresh(i,1:12) +1110 format(f6.2,13f6.1) + enddo + + write(12,1110) + do i=0,9 + write(12,1110) dop(i),threshsync(i,1:12) + enddo + +999 end program fersum diff --git a/lib/fil3c.f90 b/lib/fil3c.f90 new file mode 100644 index 00000000..6000253f --- /dev/null +++ b/lib/fil3c.f90 @@ -0,0 +1,72 @@ +subroutine fil3c(c1,n1,c2,n2) + +! FIR complex-to-complex low-pass filter designed with ScopeFIR +! +!----------------------------------------------- +! fsample (Hz) 12000 Input sample rate +! Ntaps 113 Number of filter taps +! fc (Hz) 500 Cutoff frequency +! fstop (Hz) 750 Lower limit of stopband +! Ripple (dB) 0.2 Ripple in passband +! Stop Atten (dB) 50 Stopband attenuation +! fout (Hz) 1500 Output sample rate + +! Suggest calling with n1 = 8*n2 + 105, where n2 is the desired number +! of 1500 Hz output samples. + + parameter (NTAPS=113) + parameter (NH=NTAPS/2) + parameter (NDOWN=8) !Downsample ratio = 1/8 + complex c1(n1) + complex c2(n1/NDOWN) + complex z + +! Filter coefficients: + real a(-NH:NH) + data a/ & + -0.001818142144,-0.000939132050,-0.001044063556,-0.001042685542, & + -0.000908957610,-0.000628132309,-0.000202701465, 0.000346307629, & + 0.000978154552, 0.001634336295, 0.002243121592, 0.002726064379, & + 0.003006201675, 0.003018055983, 0.002717699575, 0.002091546534, & + 0.001162489032,-0.000007904811,-0.001321554806,-0.002649908053, & + -0.003843608784,-0.004747338068,-0.005218967042,-0.005148229529, & + -0.004470167307,-0.003177923811,-0.001335998901, 0.000915924193, & + 0.003386100636, 0.005818719744, 0.007939147967, 0.009465071347, & + 0.010145641899, 0.009787447819, 0.008285915754, 0.005645995244, & + 0.001995842303,-0.002410369720,-0.007202515555,-0.011916811719, & + -0.016028350845,-0.018993391440,-0.020297455955,-0.019503792208, & + -0.016298136197,-0.010526834635,-0.002223837363, 0.008378305829, & + 0.020854478160, 0.034608532659, 0.048909701463, 0.062944127288, & + 0.075874892030, 0.086903764340, 0.095332017649, 0.100619428175, & + 0.102420526192, 0.100619428175, 0.095332017649, 0.086903764340, & + 0.075874892030, 0.062944127288, 0.048909701463, 0.034608532659, & + 0.020854478160, 0.008378305829,-0.002223837363,-0.010526834635, & + -0.016298136197,-0.019503792208,-0.020297455955,-0.018993391440, & + -0.016028350845,-0.011916811719,-0.007202515555,-0.002410369720, & + 0.001995842303, 0.005645995244, 0.008285915754, 0.009787447819, & + 0.010145641899, 0.009465071347, 0.007939147967, 0.005818719744, & + 0.003386100636, 0.000915924193,-0.001335998901,-0.003177923811, & + -0.004470167307,-0.005148229529,-0.005218967042,-0.004747338068, & + -0.003843608784,-0.002649908053,-0.001321554806,-0.000007904811, & + 0.001162489032, 0.002091546534, 0.002717699575, 0.003018055983, & + 0.003006201675, 0.002726064379, 0.002243121592, 0.001634336295, & + 0.000978154552, 0.000346307629,-0.000202701465,-0.000628132309, & + -0.000908957610,-0.001042685542,-0.001044063556,-0.000939132050, & + -0.001818142144/ + save a + + n2=(n1-NTAPS+NDOWN)/NDOWN + k0=NH-NDOWN+1 + +! Loop over all output samples + do i=1,n2 + z=0. + k=k0 + NDOWN*i + do j=-NH,NH + z=z + c1(j+k)*a(j) + enddo + c2(i)=z + enddo + + return +end subroutine fil3c diff --git a/lib/fil6521.f90 b/lib/fil6521.f90 index 6e78e63a..ef4b5435 100644 --- a/lib/fil6521.f90 +++ b/lib/fil6521.f90 @@ -19,14 +19,15 @@ subroutine fil6521(c1,n1,c2,n2) complex c2(n1/NDOWN) ! Filter coefficients: - real a(-NH:NH) + real a(-NH:NH+NTAPS/3) data a/ & -0.011958606980,-0.013888627387,-0.015601306443,-0.010602249570, & 0.003804023436, 0.028320058273, 0.060903935217, 0.096841904411, & 0.129639871228, 0.152644580853, 0.160917511283, 0.152644580853, & 0.129639871228, 0.096841904411, 0.060903935217, 0.028320058273, & 0.003804023436,-0.010602249570,-0.015601306443,-0.013888627387, & - -0.011958606980/ + -0.011958606980,1.43370769e-019,2.64031087e-006,6.25548654e+028, & + 2.44565251e+020,4.74227538e+030,10497312.0e0000,7.74079654e-039/ n2=(n1-NTAPS+NDOWN)/NDOWN k0=NH-NDOWN+1 diff --git a/lib/filbig.f90 b/lib/filbig.f90 index bb1ea52a..26a5edf5 100644 --- a/lib/filbig.f90 +++ b/lib/filbig.f90 @@ -5,6 +5,7 @@ subroutine filbig(dd,npts,f0,newdat,c4a,n4,sq0) use, intrinsic :: iso_c_binding use FFTW3 + use timer_module, only: timer parameter (NSZ=3413) parameter (NFFT1=672000,NFFT2=77175) diff --git a/lib/fillcom.f90 b/lib/fillcom.f90 deleted file mode 100644 index f6523786..00000000 --- a/lib/fillcom.f90 +++ /dev/null @@ -1,37 +0,0 @@ -subroutine fillcom(nutc0,ndepth0,nrxfreq,mode,tx9,flow,fsplit,fhigh) - character*20 datetime - integer mode,flow,fsplit,fhigh - logical tx9 - common/npar/nutc,ndiskdat,ntrperiod,nfqso,newdat,npts8,nfa,nfsplit,nfb, & - ntol,kin,nzhsym,nsave,nagain,ndepth,ntxmode,nmode,datetime - save - - nutc=nutc0 - ndiskdat=1 - ntrperiod=60 - nfqso=nrxfreq - newdat=1 - npts8=74736 - nfa=flow - nfsplit=fsplit - nfb=fhigh - ntol=3 - kin=1024 - nzhsym=173 - nsave=0 - ndepth=ndepth0 - if (tx9) then - ntxmode=9 - else - ntxmode=65 - end if - if (mode.lt.9) then - nmode=65+9 - else - nmode=mode - end if - datetime="2013-Apr-16 15:13" - if(mode.eq.9 .and. nfsplit.ne.2700) nfa=nfsplit - - return -end subroutine fillcom diff --git a/lib/fitcal.f90 b/lib/fitcal.f90 new file mode 100644 index 00000000..f85ccf45 --- /dev/null +++ b/lib/fitcal.f90 @@ -0,0 +1,34 @@ +subroutine fitcal(x,y,r,iz,a,b,sigmaa,sigmab,rms) + implicit real*8 (a-h,o-z) + real*8 x(iz),y(iz),r(iz) + + sx=0.d0 + sy=0.d0 + sxy=0.d0 + sx2=0.d0 + do i=1,iz + sx=sx + x(i) + sy=sy + y(i) + sxy=sxy + x(i)*y(i) + sx2=sx2 + x(i)*x(i) + enddo + delta=iz*sx2 - sx*sx + a=(sx2*sy - sx*sxy)/delta + b=(iz*sxy - sx*sy)/delta + + sq=0.d0 + do i=1,iz + r(i)=y(i) - (a + b*x(i)) + sq=sq + r(i)**2 + enddo + rms=0. + sigmaa=0. + sigmab=0. + if(iz.ge.3) then + rms=sqrt(sq/(iz-2)) + sigmaa=sqrt(rms*rms*sx2/delta) + sigmab=sqrt(iz*rms*rms/delta) + endif + + return +end subroutine fitcal diff --git a/lib/fix_contest_msg.f90 b/lib/fix_contest_msg.f90 new file mode 100644 index 00000000..8c0345e8 --- /dev/null +++ b/lib/fix_contest_msg.f90 @@ -0,0 +1,32 @@ +subroutine fix_contest_msg(mygrid,msg) + +! If distance from mygrid to grid1 is more thsn 10000 km, change "grid1" +! to "R grid2" where grid2 is the antipodes of grid1. + + character*6 mygrid + character*22 msg + character*6 g1,g2 + logical isgrid + + isgrid(g1)=g1(1:1).ge.'A' .and. g1(1:1).le.'R' .and. g1(2:2).ge.'A' .and. & + g1(2:2).le.'R' .and. g1(3:3).ge.'0' .and. g1(3:3).le.'9' .and. & + g1(4:4).ge.'0' .and. g1(4:4).le.'9' .and. g1(1:4).ne.'RR73' + + n=len(trim(msg)) + if(n.lt.4) return + + g1=msg(n-3:n)//' ' + if(isgrid(g1)) then + call azdist(mygrid,g1,0.d0,nAz,nEl,nDmiles,nDkm,nHotAz,nHotABetter) + if(ndkm.gt.10000) then + call grid2deg(g1,dlong,dlat) + dlong=dlong+180.0 + if(dlong.gt.180.0) dlong=dlong-360.0 + dlat=-dlat + call deg2grid(dlong,dlat,g2) + msg=msg(1:n-4)//'R '//g2(1:4) + endif + endif + + return +end subroutine fix_contest_msg diff --git a/lib/fixwav.f90 b/lib/fixwav.f90 new file mode 100644 index 00000000..da113d24 --- /dev/null +++ b/lib/fixwav.f90 @@ -0,0 +1,66 @@ +program fixwav + + use wavhdr + parameter (NBANDS=23,NMODES=11) + parameter(NMAX=120*12000) + type(hdr) h + integer*2 id2(NMAX),id(4) + character*8 mode,mode0 + character*6 band + character*12 arg + character*80 infile + character*1 c + logical ok + + nargs=iargc() + if(nargs.ne.1 .and. nargs.ne.5) then + print*,'Usage: fixwav [fMHz mode submode TRperiod] infile' + go to 999 + endif + call getarg(1,infile) + if(nargs.eq.1) go to 10 + read(infile,*) fMHz + call getarg(2,mode0) + call getarg(3,arg) + nsubmode0=-1 + do i=1,8 + if(arg(1:1).eq.char(ichar('A')-1+i)) nsubmode0=i + enddo + if(nsubmode0.lt.0) read(arg,*) nsubmode0 + call getarg(4,arg) + read(arg,*) ntrperiod0 + call getarg(5,infile) + +10 open(10,file=infile,status='old',access='stream') + read(10) h + npts=h%ndata/2 + nfsample=h%nsamrate + read(10) id2(1:npts) + write(*,1002) h%nchan2,h%nbitsam2,h%nsamrate,npts +1002 format('Channels:',i2,' Bits/sample:',i3,' Sample rate:',i6, & + ' Npts:',i8) + + call get_wsjtx_wav_params(id2,band,mode,nsubmode,ntrperiod,ok) + if(nfsample.ne.11025 .and. nfsample.ne.12000) ok=.false. + if(ok) write(*,1010) band,ntrperiod,mode,char(ichar('A')-1+id2(3)) +1010 format('Band: ',a6,' T/R period:',i4,' Mode: ',a8,1x,a1) + + if(.not.ok) write(*,'(a)') 'File has no valid WSJT-X params.' + if(ok .and. nargs.eq.1) go to 999 + + write(*,'(a)',advance='no') 'Do you want to add or change them? (Y/N): ' + read*,c + if(c.ne.'y' .and. c.ne.'Y') go to 999 + + print*,fMHz,mode0,nsubmode0,ntrperiod0 + call set_wsjtx_wav_params(fMHz,mode0,nsubmode0,ntrperiod0,id2) + band="" + mode="" + nsubmode=0 + ntrperiod=0 + call get_wsjtx_wav_params(id2,band,mode,nsubmode,ntrperiod,ok) + write(*,1010) band,ntrperiod,mode,char(ichar('A')-1+id2(3)) + rewind 10 + write(10) h,id2(1:npts) + +999 end program fixwav diff --git a/lib/flat1.f90 b/lib/flat1.f90 index b9dfdd1d..1de8b95c 100644 --- a/lib/flat1.f90 +++ b/lib/flat1.f90 @@ -12,14 +12,10 @@ subroutine flat1(savg,iz,nsmo,syellow) call pctile(savg(i-nsmo/2),nsmo,50,x(i)) x(i-nh:i+nh-1)=x(i) enddo - do i=1,ia-1 - x(i)=x(ia) - enddo - do i=ib+1,iz - x(i)=x(ib) - enddo + x(1:ia-1)=x(ia) + x(ib+1:iz)=x(ib) - x0=0.001*maxval(x(1:iz)) + x0=0.001*maxval(x(iz/10:(9*iz)/10)) syellow(1:iz)=savg(1:iz)/(x(1:iz)+x0) return diff --git a/lib/flat1a.f90 b/lib/flat1a.f90 new file mode 100644 index 00000000..b5c0b202 --- /dev/null +++ b/lib/flat1a.f90 @@ -0,0 +1,29 @@ +subroutine flat1a(psavg,nsmo,s2,nh,nsteps,nhmax,nsmax) + + real psavg(nh) + real s2(nhmax,nsmax) + real x(8192) + + ia=nsmo/2 + 1 + ib=nh - nsmo/2 - 1 + do i=ia,ib + call pctile(psavg(i-nsmo/2),nsmo,50,x(i)) + enddo + do i=1,ia-1 + x(i)=x(ia) + enddo + do i=ib+1,nh + x(i)=x(ib) + enddo + + do i=1,nh + psavg(i)=psavg(i)/x(i) + do j=1,nsteps + s2(i,j)=s2(i,j)/x(i) + enddo + enddo + + return +end subroutine flat1a + + diff --git a/lib/flat1b.f90 b/lib/flat1b.f90 new file mode 100644 index 00000000..bc22b855 --- /dev/null +++ b/lib/flat1b.f90 @@ -0,0 +1,29 @@ +subroutine flat1b(psavg,nsmo,s2,nh,nsteps,nhmax,nsmax) + + real psavg(nh) + real s2(nhmax,nsmax) + real x(8192) + + ia=nsmo/2 + 1 + ib=nh - nsmo/2 - 1 + do i=ia,ib + call pctile(psavg(i-nsmo/2),nsmo,50,x(i)) + enddo + do i=1,ia-1 + x(i)=x(ia) + enddo + do i=ib+1,nh + x(i)=x(ib) + enddo + + do i=1,nh + psavg(i)=psavg(i)/x(i) + do j=1,nsteps + s2(i,j)=s2(i,j)/x(i) + enddo + enddo + + return +end subroutine flat1b + + diff --git a/lib/flat4.f90 b/lib/flat4.f90 index fd96a3ab..faf15459 100644 --- a/lib/flat4.f90 +++ b/lib/flat4.f90 @@ -1,4 +1,4 @@ -subroutine flat4(s,npts,nflatten) +subroutine flat4(s,npts0,nflatten) ! Flatten a spectrum for optimum display ! Input: s(npts) Linear scale in power @@ -12,39 +12,42 @@ subroutine flat4(s,npts,nflatten) real*8 x(1000),y(1000),a(5) data nseg/10/,npct/10/ + npts=min(6827,npts0) if(s(1).gt.1.e29) go to 900 !Boundary between Rx intervals: do nothing do i=1,npts s(i)=10.0*log10(s(i)) !Convert to dB scale enddo - if(nflatten.eq.0) go to 900 - nlen=npts/nseg !Length of test segment - i0=npts/2 !Midpoint - k=0 - do n=2,nseg !Skip first segment, likely rolloff here - ib=n*nlen - ia=ib-nlen+1 - if(n.eq.nseg) ib=npts - call pctile(s(ia),ib-ia+1,npct,base) !Find lowest npct of points in segment - do i=ia,ib - if(s(i).le.base) then - if (k.lt.1000) k=k+1 !Save these "lower envelope" points - x(k)=i-i0 - y(k)=s(i) - endif + if(nflatten.gt.0) then + nterms=5 + if(nflatten.eq.2) nterms=1 + nlen=npts/nseg !Length of test segment + i0=npts/2 !Midpoint + k=0 + do n=1,nseg !Skip first segment, likely rolloff here + ib=n*nlen + ia=ib-nlen+1 + if(n.eq.nseg) ib=npts + call pctile(s(ia),ib-ia+1,npct,base) !Find lowest npct of points + do i=ia,ib + if(s(i).le.base) then + if (k.lt.1000) k=k+1 !Save these "lower envelope" points + x(k)=i-i0 + y(k)=s(i) + endif + enddo enddo - enddo - kz=k - a=0. - nterms=3 + kz=k + a=0. - call polfit(x,y,y,kz,nterms,0,a,chisqr) !Fit a low-order polynomial + call polyfit(x,y,y,kz,nterms,0,a,chisqr) !Fit a low-order polynomial - do i=1,npts - t=i-i0 - yfit=a(1)+t*(a(2)+t*(a(3)+t*(a(4)+t*(a(5))))) - s(i)=s(i)-yfit !Subtract the fitted baseline - enddo + do i=1,npts + t=i-i0 + yfit=a(1)+t*(a(2)+t*(a(3)+t*(a(4)+t*(a(5))))) + s(i)=s(i)-yfit !Subtract the fitted baseline + enddo + endif 900 return end subroutine flat4 diff --git a/lib/fmeasure.f90 b/lib/fmeasure.f90 new file mode 100644 index 00000000..40f2fa20 --- /dev/null +++ b/lib/fmeasure.f90 @@ -0,0 +1,75 @@ +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +! File Name: fmeasure.f90 +! Description: +! +! Copyright (C) 2001-2014 Joseph Taylor, K1JT +! License: GPL-3 +! +! This program 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 of the License, or (at your option) any later +! version. +! +! This program 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 +! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +! Street, Fifth Floor, Boston, MA 02110-1301, USA. +! +!------------------------------------------------------------------------------- +program fmeasure + + parameter(NZ=1000) + implicit real*8 (a-h,o-z) + character infile*50 + character line*80 + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: fmeasure ' + print*,'Example: fmeasure fmtave.out' + go to 999 + endif + call getarg(1,infile) + + open(10,file=infile,status='old',err=997) + open(11,file='fcal.out',status='old',err=998) + open(12,file='fmeasure.out',status='unknown') + + read(11,*) a,b + + write(*,1000) + write(12,1000) +1000 format(' Freq DF A+B*f Corrected Offset'/ & + ' (MHz) (Hz) (Hz) (MHz) (Hz)'/ & + '-----------------------------------------------') + i=0 + do j=1,9999 + read(10,1010,end=999) line +1010 format(a80) + i0=index(line,' 0 ') + if(i0.gt.0) then + read(line,*,err=5) f,df + dial_error=a + b*f + fcor=f + 1.d-6*df - 1.d-6*dial_error + offset_hz=1.d6*(fcor-f) + write(*,1020) f,df,dial_error,fcor,offset_hz + write(12,1020) f,df,dial_error,fcor,offset_hz +1020 format(3f8.3,f15.9,f8.2) + endif +5 continue + enddo + + go to 999 + +997 print*,'Cannot open input file: ',infile + go to 999 +998 print*,'Cannot open fcal.out' + +999 end program fmeasure diff --git a/lib/fmtave.f90 b/lib/fmtave.f90 new file mode 100644 index 00000000..e35dbe56 --- /dev/null +++ b/lib/fmtave.f90 @@ -0,0 +1,64 @@ +program fmtave + +! Average groups of frequency-calibration measurements. + + implicit real*8 (a-h,o-z) + character infile*80 + character*8 cutc,cutc1 + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: fmtave ' + print*,'Example: fmtave fmt.all' + go to 999 + endif + call getarg(1,infile) + + open(10,file=infile,status='old') + open(12,file='fmtave.out',status='unknown') + + write(*,1000) +1000 format(' Freq DF CAL N rms UTC Call'/ & + ' (kHz) (Hz) ? (Hz)'/ & + '----------------------------------------------------') + nkhz0=0 + sum=0.d0 + sumsq=0.d0 + n=0 + do i=1,99999 + read(10,*,end=10) cutc,nkHz,ncal,noffset,faudio,df,dblevel,snr + if((nkHz.ne.nkHz0) .and. i.ne.1) then + ave=sum/n + rms=0.d0 + if(n.gt.1) then + rms=sqrt(abs(sumsq - sum*sum/n)/(n-1.d0)) + endif + fMHz=0.001d0*nkHz0 + write(*,1010) fMHz,ave,ncal0,n,rms,cutc1 + write(12,1010) fMHz,ave,ncal0,n,rms,cutc1 +1010 format(f8.3,f9.3,i4,i5,f8.2,2x,a8,2x,a6) + sum=0.d0 + sumsq=0.d0 + n=0 + endif + dial_error=faudio-noffset + sum=sum + dial_error + sumsq=sumsq + dial_error**2 + n=n+1 + if(n.eq.1) then + cutc1=cutc + ncal0=ncal + endif + nkHz0=nkHz + enddo + +10 ave=sum/n + rms=0.d0 + if(n.gt.0) then + rms=sqrt((sumsq - sum*sum/n)/(n-1.d0)) + endif + fMHz=0.001d0*nkHz + write(*,1010) fMHz,ave,ncal,n,rms,cutc1 + write(12,1010) fMHz,ave,ncal,n,rms,cutc1 + +999 end program fmtave diff --git a/lib/foldspec9f.f90 b/lib/foldspec9f.f90 new file mode 100644 index 00000000..a6436eba --- /dev/null +++ b/lib/foldspec9f.f90 @@ -0,0 +1,30 @@ +subroutine foldspec9f(s1,nq,jz,ja,jb,s2) + +! Fold symbol spectra (quarter-symbol steps) from s1 into s2 + + real s1(nq,jz) + real s2(240,340) !340 = 4*85 + integer nsum(340) + + s2=0. + nsum=0 + + do j=ja,jb + k=mod(j-1,340)+1 + nsum(k)=nsum(k)+1 + do i=1,NQ + s2(i,k)=s2(i,k) + s1(i,j) + enddo + enddo + + do k=1,340 + fac=1.0 + if(nsum(k).gt.0) fac=1.0/nsum(k) + s2(1:nq,k)=fac*s2(1:nq,k) + enddo + + ave=sum(s2)/(340.0*nq) + if(ave.gt.0.0) s2=s2/ave + + return +end subroutine foldspec9f diff --git a/lib/fqso_first.f90 b/lib/fqso_first.f90 new file mode 100644 index 00000000..e553e3e4 --- /dev/null +++ b/lib/fqso_first.f90 @@ -0,0 +1,32 @@ +subroutine fqso_first(nfqso,ntol,ca,ncand) + +! If a candidate was found within +/- ntol of nfqso, move it into ca(1). + + type candidate + real freq + real dt + real sync + real flip + end type candidate + type(candidate) ca(300),cb + + dmin=1.e30 + i0=0 + do i=1,ncand + d=abs(ca(i)%freq-nfqso) + if(d.lt.dmin) then + i0=i + dmin=d + endif + enddo + + if(dmin.lt.float(ntol)) then + cb=ca(i0) + do i=i0,2,-1 + ca(i)=ca(i-1) + enddo + ca(1)=cb + endif + + return +end subroutine fqso_first diff --git a/lib/freqcal.f90 b/lib/freqcal.f90 new file mode 100644 index 00000000..540237f6 --- /dev/null +++ b/lib/freqcal.f90 @@ -0,0 +1,84 @@ +subroutine freqcal(id2,k,nkhz,noffset,ntol,line) + + parameter (NZ=30*12000,NFFT=55296,NH=NFFT/2) + integer*2 id2(0:NZ-1) + complex sp,sn + real x(0:NFFT-1) + real xi(0:NFFT-1) + real w(0:NFFT-1) !Window function + real s(0:NH) + character line*80,cflag*1 + logical first + complex cx(0:NH) + equivalence (x,cx) + data n/0/,k0/9999999/,first/.true./ + save n,k0,w,first,pi,fs,xi + + if(first) then + pi=4.0*atan(1.0) + fs=12000.0 + do i=0,NFFT-1 + ww=sin(i*pi/NFFT) + w(i)=ww*ww/NFFT + xi(i)=2.0*pi*i + enddo + first=.false. + endif + + if(k.lt.NFFT) go to 900 + if(k.lt.k0) n=0 + k0=k + + x=w*id2(k-NFFT:k-1) !Apply window + call four2a(x,NFFT,1,-1,0) !Compute spectrum, r2c + df=fs/NFFT + if (ntol.gt.noffset) then + ia=0 + ib=nint((noffset*2)/df) + else + ia=nint((noffset-ntol)/df) + ib=nint((noffset+ntol)/df) + endif + smax=0. + s=0. + do i=ia,ib + s(i)=real(cx(i))**2 + aimag(cx(i))**2 + if(s(i).gt.smax) then + smax=s(i) + ipk=i + endif + enddo + + call peakup(s(ipk-1),s(ipk),s(ipk+1),dx) + fpeak=df * (ipk+dx) + ap=(fpeak/fs+1.0/(2.0*NFFT)) + an=(fpeak/fs-1.0/(2.0*NFFT)) + sp=sum(id2((k-NFFT):k-1)*cmplx(cos(xi*ap),-sin(xi*ap))) + sn=sum(id2((k-NFFT):k-1)*cmplx(cos(xi*an),-sin(xi*an))) + fpeak=fpeak+fs*(abs(sp)-abs(sn))/(abs(sp)+abs(sn))/(2*NFFT) + xsum=0. + nsum=0 + do i=ia,ib + if(abs(i-ipk).gt.10) then + xsum=xsum+s(i) + nsum=nsum+1 + endif + enddo + ave=xsum/nsum + snr=db(smax/ave) + pave=db(ave) + 8.0 + cflag=' ' + if(snr.lt.20.0) cflag='*' + n=n+1 + nsec=mod(time(),86400) + nhr=nsec/3600 + nmin=mod(nsec/60,60) + nsec=mod(nsec,60) + ncal=1 + ferr=fpeak-noffset + write(line,1100) nhr,nmin,nsec,nkhz,ncal,noffset,fpeak,ferr,pave, & + snr,cflag,char(0) +1100 format(i2.2,':',i2.2,':',i2.2,i7,i3,i6,2f10.3,2f7.1,2x,a1,a1) + +900 return +end subroutine freqcal diff --git a/lib/fsk4hf/Makefile b/lib/fsk4hf/Makefile new file mode 100644 index 00000000..9372821b --- /dev/null +++ b/lib/fsk4hf/Makefile @@ -0,0 +1,50 @@ +# Compilers +CC = gcc +CXX = g++ +FC = gfortran + +FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion +CFLAGS = -O2 -I. + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: wsprlf + +OBJS0 = testpsk.o four2a.o bpfilter.o nonlinear.o tweak1.o spectrum.o smo.o +testpsk: $(OBJS0) + $(FC) -o testpsk $(OBJS0) -lfftw3f + +OBJS1 = gmsk8.o four2a.o gaussfilt.o +gmsk8: $(OBJS1) + $(FC) -o gmsk8 $(OBJS1) -lfftw3f + +OBJS2 = testfsk.o four2a.o smo.o +testfsk: $(OBJS2) + $(FC) -o testfsk $(OBJS2) -lfftw3f + +OBJS3 = fsk2sim.o four2a.o smo.o wavhdr.o gran.o +fsk2sim: $(OBJS3) + $(FC) -o fsk2sim $(OBJS3) -lfftw3f + +OBJS4 = fsk4sim.o four2a.o wavhdr.o gran.o tweak1.o +fsk4sim: $(OBJS4) + $(FC) -o fsk4sim $(OBJS4) -lfftw3f + +OBJS5 = wsprlf.o four2a.o +wsprlf: $(OBJS5) + $(FC) -o wsprlf $(OBJS5) -lfftw3f + +.PHONY : clean + +clean: + $(RM) *.o testpsk testfsk fsk2sim fsk4sim wsprlf diff --git a/lib/fsk4hf/Makefile.win b/lib/fsk4hf/Makefile.win new file mode 100644 index 00000000..ab383557 --- /dev/null +++ b/lib/fsk4hf/Makefile.win @@ -0,0 +1,84 @@ +# Compilers +CC = gcc +CXX = g++ +FC = gfortran + +FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion +CFLAGS = -O2 -I. + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: dbpsksim.exe + +OBJS0 = testpsk.o four2a.o bpfilter.o nonlinear.o tweak1.o spectrum.o smo.o +testpsk: $(OBJS0) + $(FC) -o testpsk $(OBJS0) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS1 = gmsk8.o four2a.o gaussfilt.o +gmsk8: $(OBJS1) + $(FC) -o gmsk8 $(OBJS1) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS2 = testfsk.o four2a.o smo.o +testfsk: $(OBJS2) + $(FC) -o testfsk $(OBJS2) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS3 = fsk2sim.o four2a.o smo.o wavhdr.o gran.o +fsk2sim: $(OBJS3) + $(FC) -o fsk2sim $(OBJS3) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS4 = fsk4sim.o four2a.o gran.o genfsk4.o smo.o getsnr.o spec4.o \ + watterson.o db.o snr2_wsprlf.o pctile.o shell.o snr_wsprlf.o +fsk4sim.exe: $(OBJS4) + $(FC) -o fsk4sim.exe $(OBJS4) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS5 = wsprlf.o four2a.o downsample.o +wsprlf.exe: $(OBJS5) + $(FC) -o wsprlf.exe $(OBJS5) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS6 = wspr_gmsk.o four2a.o gaussfilt.o +wspr_gmsk.exe: $(OBJS6) + $(FC) -o wspr_gmsk.exe $(OBJS6) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS7 = wspr_msk.o four2a.o bpfilter.o +wspr_msk.exe: $(OBJS7) + $(FC) -o wspr_msk.exe $(OBJS7) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS8 = dbpsksim.o four2a.o gran.o genbpsk.o watterson.o db.o \ + encode120.o bpdecode120.o platanh.o +dbpsksim.exe: $(OBJS8) + $(FC) -o dbpsksim.exe $(OBJS8) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS9 = fsk4a.o four2a.o gran.o genfsk4a.o spec4.o \ + watterson.o db.o +fsk4a.exe: $(OBJS9) + $(FC) -o fsk4a.exe $(OBJS9) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS10 = gmsk8.o gaussfilt.o four2a.o +gmsk8.exe: $(OBJS10) + $(FC) -o gmsk8.exe $(OBJS10) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS11 = gmsksim.o four2a.o gran.o gengmsk.o genbpsk.o watterson.o db.o \ + encode168.o bpdecode168.o platanh.o gaussfilt.o tweak1.o smo121.o +gmsksim.exe: $(OBJS11) + $(FC) -o gmsksim.exe $(OBJS11) C:\JTSDK\fftw3f\libfftw3f-3.dll + +OBJS12 = mskhfsim.o four2a.o gran.o genmskhf.o watterson.o db.o \ + encode168.o bpdecode168.o platanh.o twkfreq1.o smo121.o \ + polyfit4.o +mskhfsim.exe: $(OBJS12) + $(FC) -o mskhfsim.exe $(OBJS12) C:\JTSDK\fftw3f\libfftw3f-3.dll + +.PHONY : clean + +clean: + $(RM) *.o testpsk.exe testfsk.exe fsk2sim.exe fsk4sim.exe wsprlf.exe diff --git a/lib/fsk4hf/baseline.f90 b/lib/fsk4hf/baseline.f90 new file mode 100644 index 00000000..035f9ab4 --- /dev/null +++ b/lib/fsk4hf/baseline.f90 @@ -0,0 +1,48 @@ +subroutine baseline(s,nfa,nfb,sbase) + +! Fit baseline to spectrum (for FT8) +! Input: s(npts) Linear scale in power +! Output: sbase(npts) Baseline + + implicit real*8 (a-h,o-z) + real*4 s(1920) + real*4 sbase(1920) + real*4 base + real*8 x(1000),y(1000),a(5) + data nseg/10/,npct/10/ + + df=12000.0/3840.0 !3.125 Hz + ia=max(1,nint(nfa/df)) + ib=nint(nfb/df) + do i=ia,ib + s(i)=10.0*log10(s(i)) !Convert to dB scale + enddo + + nterms=5 + nlen=(ib-ia+1)/nseg !Length of test segment + i0=(ib-ia+1)/2 !Midpoint + k=0 + do n=1,nseg !Loop over all segments + ja=ia + (n-1)*nlen + jb=ja+nlen-1 + call pctile(s(ja),nlen,npct,base) !Find lowest npct of points + do i=ja,jb + if(s(i).le.base) then + if (k.lt.1000) k=k+1 !Save all "lower envelope" points + x(k)=i-i0 + y(k)=s(i) + endif + enddo + enddo + kz=k + a=0. + call polyfit(x,y,y,kz,nterms,0,a,chisqr) !Fit a low-order polynomial + do i=ia,ib + t=i-i0 + sbase(i)=a(1)+t*(a(2)+t*(a(3)+t*(a(4)+t*(a(5))))) + 0.65 +! write(51,3051) i*df,s(i),sbase(i) +!3051 format(3f12.3) + enddo + + return +end subroutine baseline diff --git a/lib/fsk4hf/bpdecode120.f90 b/lib/fsk4hf/bpdecode120.f90 new file mode 100644 index 00000000..c9b11ac3 --- /dev/null +++ b/lib/fsk4hf/bpdecode120.f90 @@ -0,0 +1,306 @@ +subroutine bpdecode120(llr,apmask,maxiterations,decoded,niterations,cw) + +! A log-domain belief propagation decoder for the (120,60) code. + +integer, parameter:: N=120, K=60, M=N-K +integer*1 codeword(N),cw(N),apmask(N) +integer colorder(N) +integer*1 decoded(K) +integer Nm(7,M) ! 5, 6, or 7 bits per check +integer Mn(3,N) ! 3 checks per bit +integer synd(M) +real tov(3,N) +real toc(7,M) +real tanhtoc(7,M) +real zn(N) +real llr(N) +real Tmn +integer nrw(M) + +data colorder/ & + 0,1,2,21,3,4,5,6,7,8,20,10,9,11,12,23,13,28,14,31, & + 15,16,22,26,17,30,18,29,25,32,41,34,19,33,27,36,38,43,42,24, & + 37,39,45,40,35,44,47,46,50,51,53,48,52,56,54,57,55,49,58,61, & + 60,59,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, & + 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99, & + 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119/ + +data Mn/ & + 1, 18, 48, & + 2, 4, 51, & + 3, 23, 47, & + 5, 36, 42, & + 6, 43, 49, & + 7, 24, 55, & + 8, 35, 60, & + 9, 26, 30, & + 10, 29, 45, & + 11, 13, 46, & + 12, 53, 54, & + 14, 20, 57, & + 15, 16, 58, & + 17, 39, 44, & + 19, 37, 41, & + 21, 28, 34, & + 22, 50, 59, & + 25, 31, 52, & + 27, 32, 38, & + 33, 40, 56, & + 1, 11, 47, & + 2, 10, 16, & + 3, 12, 27, & + 4, 24, 28, & + 5, 23, 60, & + 6, 29, 39, & + 7, 31, 54, & + 8, 50, 56, & + 9, 13, 14, & + 15, 22, 41, & + 17, 26, 40, & + 18, 25, 45, & + 19, 20, 55, & + 21, 30, 36, & + 32, 49, 59, & + 33, 53, 58, & + 34, 38, 46, & + 29, 35, 57, & + 37, 43, 48, & + 42, 51, 52, & + 7, 11, 44, & + 1, 42, 58, & + 2, 13, 49, & + 3, 20, 40, & + 4, 18, 56, & + 5, 45, 55, & + 6, 21, 31, & + 8, 46, 52, & + 9, 12, 48, & + 10, 37, 38, & + 14, 15, 25, & + 16, 17, 60, & + 19, 39, 53, & + 22, 44, 51, & + 23, 28, 41, & + 24, 32, 35, & + 26, 45, 59, & + 27, 33, 36, & + 30, 47, 54, & + 34, 50, 57, & + 33, 43, 55, & + 1, 41, 57, & + 2, 40, 54, & + 3, 6, 24, & + 4, 11, 59, & + 5, 13, 56, & + 7, 16, 34, & + 8, 19, 26, & + 9, 31, 58, & + 10, 21, 53, & + 12, 22, 60, & + 14, 38, 51, & + 15, 43, 46, & + 17, 48, 50, & + 18, 27, 39, & + 20, 28, 44, & + 23, 25, 49, & + 4, 29, 36, & + 30, 32, 52, & + 35, 37, 47, & + 39, 42, 59, & + 1, 21, 40, & + 2, 50, 55, & + 3, 8, 10, & + 5, 31, 37, & + 6, 14, 60, & + 7, 36, 49, & + 9, 34, 39, & + 11, 19, 25, & + 12, 52, 57, & + 13, 22, 29, & + 15, 30, 56, & + 16, 18, 20, & + 17, 24, 46, & + 23, 38, 58, & + 26, 28, 43, & + 2, 27, 41, & + 5, 32, 44, & + 33, 47, 51, & + 35, 48, 53, & + 42, 43, 54, & + 34, 45, 47, & + 1, 8, 49, & + 3, 14, 59, & + 4, 31, 46, & + 6, 20, 50, & + 7, 26, 53, & + 9, 10, 36, & + 11, 58, 60, & + 12, 21, 45, & + 13, 28, 33, & + 15, 17, 35, & + 16, 38, 52, & + 18, 41, 54, & + 19, 23, 32, & + 22, 40, 55, & + 24, 25, 42, & + 26, 27, 56, & + 29, 44, 54, & + 30, 37, 55/ + +data Nm/ & + 1, 21, 42, 62, 82, 103, 0, & + 2, 22, 43, 63, 83, 97, 0, & + 3, 23, 44, 64, 84, 104, 0, & + 2, 24, 45, 65, 78, 105, 0, & + 4, 25, 46, 66, 85, 98, 0, & + 5, 26, 47, 64, 86, 106, 0, & + 6, 27, 41, 67, 87, 107, 0, & + 7, 28, 48, 68, 84, 103, 0, & + 8, 29, 49, 69, 88, 108, 0, & + 9, 22, 50, 70, 84, 108, 0, & + 10, 21, 41, 65, 89, 109, 0, & + 11, 23, 49, 71, 90, 110, 0, & + 10, 29, 43, 66, 91, 111, 0, & + 12, 29, 51, 72, 86, 104, 0, & + 13, 30, 51, 73, 92, 112, 0, & + 13, 22, 52, 67, 93, 113, 0, & + 14, 31, 52, 74, 94, 112, 0, & + 1, 32, 45, 75, 93, 114, 0, & + 15, 33, 53, 68, 89, 115, 0, & + 12, 33, 44, 76, 93, 106, 0, & + 16, 34, 47, 70, 82, 110, 0, & + 17, 30, 54, 71, 91, 116, 0, & + 3, 25, 55, 77, 95, 115, 0, & + 6, 24, 56, 64, 94, 117, 0, & + 18, 32, 51, 77, 89, 117, 0, & + 8, 31, 57, 68, 96, 107, 118, & + 19, 23, 58, 75, 97, 118, 0, & + 16, 24, 55, 76, 96, 111, 0, & + 9, 26, 38, 78, 91, 119, 0, & + 8, 34, 59, 79, 92, 120, 0, & + 18, 27, 47, 69, 85, 105, 0, & + 19, 35, 56, 79, 98, 115, 0, & + 20, 36, 58, 61, 99, 111, 0, & + 16, 37, 60, 67, 88, 102, 0, & + 7, 38, 56, 80, 100, 112, 0, & + 4, 34, 58, 78, 87, 108, 0, & + 15, 39, 50, 80, 85, 120, 0, & + 19, 37, 50, 72, 95, 113, 0, & + 14, 26, 53, 75, 81, 88, 0, & + 20, 31, 44, 63, 82, 116, 0, & + 15, 30, 55, 62, 97, 114, 0, & + 4, 40, 42, 81, 101, 117, 0, & + 5, 39, 61, 73, 96, 101, 0, & + 14, 41, 54, 76, 98, 119, 0, & + 9, 32, 46, 57, 102, 110, 0, & + 10, 37, 48, 73, 94, 105, 0, & + 3, 21, 59, 80, 99, 102, 0, & + 1, 39, 49, 74, 100, 0, 0, & + 5, 35, 43, 77, 87, 103, 0, & + 17, 28, 60, 74, 83, 106, 0, & + 2, 40, 54, 72, 99, 0, 0, & + 18, 40, 48, 79, 90, 113, 0, & + 11, 36, 53, 70, 100, 107, 0, & + 11, 27, 59, 63, 101, 114, 119, & + 6, 33, 46, 61, 83, 116, 120, & + 20, 28, 45, 66, 92, 118, 0, & + 12, 38, 60, 62, 90, 0, 0, & + 13, 36, 42, 69, 95, 109, 0, & + 17, 35, 57, 65, 81, 104, 0, & + 7, 25, 52, 71, 86, 109, 0/ + +data nrw/ & +6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, & +6,6,6,6,6,7,6,6,6,6,6,6,6,6,6,6,6,6,6,6, & +6,6,6,6,6,6,6,5,6,6,5,6,6,7,7,6,5,6,6,6/ + +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)) + 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. 3 .and. iter .ge. 5 .and. ncheck .gt. 10) 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 ! 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:7,i)=tanh(-toc(1:7,i)/2) + enddo + + do j=1,N + do i=1,ncw + 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 bpdecode120 diff --git a/lib/fsk4hf/bpdecode168.f90 b/lib/fsk4hf/bpdecode168.f90 new file mode 100644 index 00000000..d527f71d --- /dev/null +++ b/lib/fsk4hf/bpdecode168.f90 @@ -0,0 +1,380 @@ +subroutine bpdecode168(llr,apmask,maxiterations,decoded,niterations) +! +! A log-domain belief propagation decoder for the (168,84) code. +! +integer, parameter:: N=168, K=84, M=N-K +integer*1 codeword(N),cw(N),apmask(N) +integer colorder(N) +integer*1 decoded(K) +integer Nm(7,M) ! 5, 6, or 7 bits per check +integer Mn(3,N) ! 3 checks per bit +integer synd(M) +real tov(3,N) +real toc(7,M) +real tanhtoc(7,M) +real zn(N) +real llr(N) +real Tmn +integer nrw(M) + +data colorder/0,1,2,3,28,4,5,6,7,8,9,10,11,34,12,32,13,14,15,16,17, & + 18,36,29,42,31,20,21,41,40,30,38,22,19,47,37,46,35,44,33,49,24, & + 43,51,25,26,27,50,52,57,69,54,55,45,59,58,56,61,60,53,48,23,62, & + 63,64,67,66,65,68,39,70,71,72,74,73,75,76,77,80,81,78,82,79,83, & + 84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104, & + 105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125, & + 126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146, & + 147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167/ + +data Mn/ & + 1,24,67, & + 2,5,71, & + 3,31,66, & + 4,50,58, & + 6,60,65, & + 7,32,76, & + 8,49,83, & + 9,36,41, & + 10,40,63, & + 11,14,62, & + 12,72,75, & + 13,23,78, & + 15,16,80, & + 17,54,64, & + 18,51,59, & + 19,30,48, & + 20,68,81, & + 21,29,70, & + 22,25,43, & + 26,34,73, & + 27,35,37, & + 28,39,44, & + 33,53,55, & + 38,52,84, & + 42,56,57, & + 45,74,82, & + 46,69,79, & + 47,61,77, & + 1,4,5, & + 2,48,52, & + 3,47,82, & + 6,26,76, & + 7,9,16, & + 8,10,78, & + 11,36,56, & + 12,38,65, & + 13,43,81, & + 14,33,68, & + 15,18,44, & + 17,59,77, & + 19,27,69, & + 20,21,58, & + 22,45,79, & + 23,34,54, & + 24,28,40, & + 25,80,84, & + 29,37,51, & + 30,42,83, & + 31,63,72, & + 32,50,66, & + 35,67,73, & + 39,55,74, & + 41,61,71, & + 46,60,62, & + 49,70,74, & + 53,64,75, & + 25,57,67, & + 1,46,64, & + 2,51,63, & + 3,14,80, & + 4,15,78, & + 5,27,74, & + 6,13,70, & + 7,19,20, & + 8,38,77, & + 9,75,83, & + 10,36,69, & + 11,22,29, & + 12,58,82, & + 16,35,60, & + 17,32,43, & + 18,42,45, & + 21,53,84, & + 23,39,48, & + 24,52,68, & + 26,33,61, & + 28,56,76, & + 30,65,66, & + 31,34,49, & + 37,47,81, & + 16,40,54, & + 41,44,65, & + 50,73,79, & + 55,59,60, & + 54,57,71, & + 23,62,72, & + 1,36,47, & + 2,32,70, & + 3,28,69, & + 4,7,33, & + 5,20,26, & + 6,14,63, & + 8,22,68, & + 9,13,67, & + 10,55,71, & + 11,15,19, & + 12,51,56, & + 17,27,52, & + 18,34,46, & + 21,41,42, & + 24,50,80, & + 25,39,75, & + 29,54,76, & + 30,40,84, & + 31,35,58, & + 37,79,83, & + 38,43,73, & + 44,72,81, & + 7,45,62, & + 47,48,49, & + 53,57,78, & + 20,59,66, & + 28,61,64, & + 11,75,77, & + 33,54,82, & + 1,14,44, & + 2,62,73, & + 3,9,26, & + 4,37,84, & + 5,56,80, & + 6,45,71, & + 8,67,72, & + 10,76,81, & + 12,32,78, & + 13,59,82, & + 15,17,79, & + 16,42,69, & + 18,61,70, & + 19,31,64, & + 21,39,63, & + 22,30,58, & + 23,27,66, & + 24,41,49, & + 25,36,60, & + 29,65,67, & + 34,36,53, & + 35,48,76, & + 15,38,55, & + 40,43,74, & + 46,52,57, & + 50,63,77, & + 51,68,69, & + 2,44,83, & + 1,30,55, & + 3,29,78, & + 4,34,65, & + 5,31,38, & + 6,52,58, & + 7,25,51, & + 8,16,66, & + 9,46,74, & + 10,70,75, & + 11,32,84, & + 12,48,79, & + 13,50,64, & + 14,37,57, & + 17,42,72, & + 18,43,48, & + 19,24,60, & + 20,54,83, & + 21,47,62, & + 22,28,59, & + 23,61,80, & + 8,26,39, & + 27,44,53, & + 33,49,56, & + 35,68,71, & + 12,26,40/ + +data Nm/ & + 1,29,58,87,116,144,0,& + 2,30,59,88,117,143,0,& + 3,31,60,89,118,145,0,& + 4,29,61,90,119,146,0,& + 2,29,62,91,120,147,0,& + 5,32,63,92,121,148,0,& + 6,33,64,90,109,149,0,& + 7,34,65,93,122,150,164,& + 8,33,66,94,118,151,0,& + 9,34,67,95,123,152,0,& + 10,35,68,96,114,153,0,& + 11,36,69,97,124,154,168,& + 12,37,63,94,125,155,0,& + 10,38,60,92,116,156,0,& + 13,39,61,96,126,138,0,& + 13,33,70,81,127,150,0,& + 14,40,71,98,126,157,0,& + 15,39,72,99,128,158,0,& + 16,41,64,96,129,159,0,& + 17,42,64,91,112,160,0,& + 18,42,73,100,130,161,0,& + 19,43,68,93,131,162,0,& + 12,44,74,86,132,163,0,& + 1,45,75,101,133,159,0,& + 19,46,57,102,134,149,0,& + 20,32,76,91,118,164,168,& + 21,41,62,98,132,165,0,& + 22,45,77,89,113,162,0,& + 18,47,68,103,135,145,0,& + 16,48,78,104,131,144,0,& + 3,49,79,105,129,147,0,& + 6,50,71,88,124,153,0,& + 23,38,76,90,115,166,0,& + 20,44,79,99,136,146,0,& + 21,51,70,105,137,167,0,& + 8,35,67,87,134,136,0,& + 21,47,80,106,119,156,0,& + 24,36,65,107,138,147,0,& + 22,52,74,102,130,164,0,& + 9,45,81,104,139,168,0,& + 8,53,82,100,133,0,0,& + 25,48,72,100,127,157,0,& + 19,37,71,107,139,158,0,& + 22,39,82,108,116,143,165,& + 26,43,72,109,121,0,0,& + 27,54,58,99,140,151,0,& + 28,31,80,87,110,161,0,& + 16,30,74,110,137,154,158,& + 7,55,79,110,133,166,0,& + 4,50,83,101,141,155,0,& + 15,47,59,97,142,149,0,& + 24,30,75,98,140,148,0,& + 23,56,73,111,136,165,0,& + 14,44,81,85,103,115,160,& + 23,52,84,95,138,144,0,& + 25,35,77,97,120,166,0,& + 25,57,85,111,140,156,0,& + 4,42,69,105,131,148,0,& + 15,40,84,112,125,162,0,& + 5,54,70,84,134,159,0,& + 28,53,76,113,128,163,0,& + 10,54,86,109,117,161,0,& + 9,49,59,92,130,141,0,& + 14,56,58,113,129,155,0,& + 5,36,78,82,135,146,0,& + 3,50,78,112,132,150,0,& + 1,51,57,94,122,135,0,& + 17,38,75,93,142,167,0,& + 27,41,67,89,127,142,0,& + 18,55,63,88,128,152,0,& + 2,53,85,95,121,167,0,& + 11,49,86,108,122,157,0,& + 20,51,83,107,117,0,0,& + 26,52,55,62,139,151,0,& + 11,56,66,102,114,152,0,& + 6,32,77,103,123,137,0,& + 28,40,65,114,141,0,0,& + 12,34,61,111,124,145,0,& + 27,43,83,106,126,154,0,& + 13,46,60,101,120,163,0,& + 17,37,80,108,123,0,0,& + 26,31,69,115,125,0,0,& + 7,48,66,106,143,160,0,& + 24,46,73,104,119,153,0/ + +data nrw/ & +6,6,6,6,6,6,6,7,6,6,6,7,6,6,6,6,6,6,6,6,6, & +6,6,6,6,7,6,6,6,6,6,6,6,6,6,6,6,6,6,6,5,6, & +6,7,5,6,6,7,6,6,6,6,6,7,6,6,6,6,6,6,6,6,6, & +6,6,6,6,6,6,6,6,6,5,6,6,6,5,6,6,6,5,5,6,6/ + +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)) + 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. 3 .and. iter .ge. 5 .and. ncheck .gt. 10) 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 ! 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:7,i)=tanh(-toc(1:7,i)/2) + enddo + + do j=1,N + do i=1,ncw + 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 bpdecode168 diff --git a/lib/fsk4hf/bpdecode174.f90 b/lib/fsk4hf/bpdecode174.f90 new file mode 100644 index 00000000..9442cc4a --- /dev/null +++ b/lib/fsk4hf/bpdecode174.f90 @@ -0,0 +1,401 @@ +subroutine bpdecode174(llr,apmask,maxiterations,decoded,cw,nharderror,iter) +! +! A log-domain belief propagation decoder for the (174,87) code. +! +integer, parameter:: N=174, K=87, M=N-K +integer*1 codeword(N),cw(N),apmask(N) +integer colorder(N) +integer*1 decoded(K) +integer Nm(7,M) ! 5, 6, or 7 bits per check +integer Mn(3,N) ! 3 checks per bit +integer synd(M) +real tov(3,N) +real toc(7,M) +real tanhtoc(7,M) +real zn(N) +real llr(N) +real Tmn +integer nrw(M) + +data colorder/ & + 0, 1, 2, 3, 30, 4, 5, 6, 7, 8, 9, 10, 11, 32, 12, 40, 13, 14, 15, 16,& + 17, 18, 37, 45, 29, 19, 20, 21, 41, 22, 42, 31, 33, 34, 44, 35, 47, 51, 50, 43,& + 36, 52, 63, 46, 25, 55, 27, 24, 23, 53, 39, 49, 59, 38, 48, 61, 60, 57, 28, 62,& + 56, 58, 65, 66, 26, 70, 64, 69, 68, 67, 74, 71, 54, 76, 72, 75, 78, 77, 80, 79,& + 73, 83, 84, 81, 82, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,& + 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,& + 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,& + 140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,& + 160,161,162,163,164,165,166,167,168,169,170,171,172,173/ + +data Mn/ & + 1, 25, 69, & + 2, 5, 73, & + 3, 32, 68, & + 4, 51, 61, & + 6, 63, 70, & + 7, 33, 79, & + 8, 50, 86, & + 9, 37, 43, & + 10, 41, 65, & + 11, 14, 64, & + 12, 75, 77, & + 13, 23, 81, & + 15, 16, 82, & + 17, 56, 66, & + 18, 53, 60, & + 19, 31, 52, & + 20, 67, 84, & + 21, 29, 72, & + 22, 24, 44, & + 26, 35, 76, & + 27, 36, 38, & + 28, 40, 42, & + 30, 54, 55, & + 34, 49, 87, & + 39, 57, 58, & + 45, 74, 83, & + 46, 62, 80, & + 47, 48, 85, & + 59, 71, 78, & + 1, 50, 53, & + 2, 47, 84, & + 3, 25, 79, & + 4, 6, 14, & + 5, 7, 80, & + 8, 34, 55, & + 9, 36, 69, & + 10, 43, 83, & + 11, 23, 74, & + 12, 17, 44, & + 13, 57, 76, & + 15, 27, 56, & + 16, 28, 29, & + 18, 19, 59, & + 20, 40, 63, & + 21, 35, 52, & + 22, 54, 64, & + 24, 62, 78, & + 26, 32, 77, & + 30, 72, 85, & + 31, 65, 87, & + 33, 39, 51, & + 37, 48, 75, & + 38, 70, 71, & + 41, 42, 68, & + 45, 67, 86, & + 46, 81, 82, & + 49, 66, 73, & + 58, 60, 66, & + 61, 65, 85, & + 1, 14, 21, & + 2, 13, 59, & + 3, 67, 82, & + 4, 32, 73, & + 5, 36, 54, & + 6, 43, 46, & + 7, 28, 75, & + 8, 33, 71, & + 9, 49, 76, & + 10, 58, 64, & + 11, 48, 68, & + 12, 19, 45, & + 15, 50, 61, & + 16, 22, 26, & + 17, 72, 80, & + 18, 40, 55, & + 20, 35, 51, & + 23, 25, 34, & + 24, 63, 87, & + 27, 39, 74, & + 29, 78, 83, & + 30, 70, 77, & + 31, 69, 84, & + 22, 37, 86, & + 38, 41, 81, & + 42, 44, 57, & + 47, 53, 62, & + 52, 56, 79, & + 60, 75, 81, & + 1, 39, 77, & + 2, 16, 41, & + 3, 31, 54, & + 4, 36, 78, & + 5, 45, 65, & + 6, 57, 85, & + 7, 14, 49, & + 8, 21, 46, & + 9, 15, 72, & + 10, 20, 62, & + 11, 17, 71, & + 12, 34, 47, & + 13, 68, 86, & + 18, 23, 43, & + 19, 64, 73, & + 24, 48, 79, & + 25, 70, 83, & + 26, 80, 87, & + 27, 32, 40, & + 28, 56, 69, & + 29, 63, 66, & + 30, 42, 50, & + 33, 37, 82, & + 35, 60, 74, & + 38, 55, 84, & + 44, 52, 61, & + 51, 53, 72, & + 58, 59, 67, & + 47, 56, 76, & + 1, 19, 37, & + 2, 61, 75, & + 3, 8, 66, & + 4, 60, 84, & + 5, 34, 39, & + 6, 26, 53, & + 7, 32, 57, & + 9, 52, 67, & + 10, 12, 15, & + 11, 51, 69, & + 13, 14, 65, & + 16, 31, 43, & + 17, 20, 36, & + 18, 80, 86, & + 21, 48, 59, & + 22, 40, 46, & + 23, 33, 62, & + 24, 30, 74, & + 25, 42, 64, & + 27, 49, 85, & + 28, 38, 73, & + 29, 44, 81, & + 35, 68, 70, & + 41, 63, 76, & + 45, 49, 71, & + 50, 58, 87, & + 48, 54, 83, & + 13, 55, 79, & + 77, 78, 82, & + 1, 2, 24, & + 3, 6, 75, & + 4, 56, 87, & + 5, 44, 53, & + 7, 50, 83, & + 8, 10, 28, & + 9, 55, 62, & + 11, 29, 67, & + 12, 33, 40, & + 14, 16, 20, & + 15, 35, 73, & + 17, 31, 39, & + 18, 36, 57, & + 19, 46, 76, & + 21, 42, 84, & + 22, 34, 59, & + 23, 26, 61, & + 25, 60, 65, & + 27, 64, 80, & + 30, 37, 66, & + 32, 45, 72, & + 38, 51, 86, & + 41, 77, 79, & + 43, 56, 68, & + 47, 74, 82, & + 40, 52, 78, & + 54, 61, 71, & + 46, 58, 69/ + +data Nm/ & + 1, 30, 60, 89, 118, 147, 0, & + 2, 31, 61, 90, 119, 147, 0, & + 3, 32, 62, 91, 120, 148, 0, & + 4, 33, 63, 92, 121, 149, 0, & + 2, 34, 64, 93, 122, 150, 0, & + 5, 33, 65, 94, 123, 148, 0, & + 6, 34, 66, 95, 124, 151, 0, & + 7, 35, 67, 96, 120, 152, 0, & + 8, 36, 68, 97, 125, 153, 0, & + 9, 37, 69, 98, 126, 152, 0, & + 10, 38, 70, 99, 127, 154, 0, & + 11, 39, 71, 100, 126, 155, 0, & + 12, 40, 61, 101, 128, 145, 0, & + 10, 33, 60, 95, 128, 156, 0, & + 13, 41, 72, 97, 126, 157, 0, & + 13, 42, 73, 90, 129, 156, 0, & + 14, 39, 74, 99, 130, 158, 0, & + 15, 43, 75, 102, 131, 159, 0, & + 16, 43, 71, 103, 118, 160, 0, & + 17, 44, 76, 98, 130, 156, 0, & + 18, 45, 60, 96, 132, 161, 0, & + 19, 46, 73, 83, 133, 162, 0, & + 12, 38, 77, 102, 134, 163, 0, & + 19, 47, 78, 104, 135, 147, 0, & + 1, 32, 77, 105, 136, 164, 0, & + 20, 48, 73, 106, 123, 163, 0, & + 21, 41, 79, 107, 137, 165, 0, & + 22, 42, 66, 108, 138, 152, 0, & + 18, 42, 80, 109, 139, 154, 0, & + 23, 49, 81, 110, 135, 166, 0, & + 16, 50, 82, 91, 129, 158, 0, & + 3, 48, 63, 107, 124, 167, 0, & + 6, 51, 67, 111, 134, 155, 0, & + 24, 35, 77, 100, 122, 162, 0, & + 20, 45, 76, 112, 140, 157, 0, & + 21, 36, 64, 92, 130, 159, 0, & + 8, 52, 83, 111, 118, 166, 0, & + 21, 53, 84, 113, 138, 168, 0, & + 25, 51, 79, 89, 122, 158, 0, & + 22, 44, 75, 107, 133, 155, 172, & + 9, 54, 84, 90, 141, 169, 0, & + 22, 54, 85, 110, 136, 161, 0, & + 8, 37, 65, 102, 129, 170, 0, & + 19, 39, 85, 114, 139, 150, 0, & + 26, 55, 71, 93, 142, 167, 0, & + 27, 56, 65, 96, 133, 160, 174, & + 28, 31, 86, 100, 117, 171, 0, & + 28, 52, 70, 104, 132, 144, 0, & + 24, 57, 68, 95, 137, 142, 0, & + 7, 30, 72, 110, 143, 151, 0, & + 4, 51, 76, 115, 127, 168, 0, & + 16, 45, 87, 114, 125, 172, 0, & + 15, 30, 86, 115, 123, 150, 0, & + 23, 46, 64, 91, 144, 173, 0, & + 23, 35, 75, 113, 145, 153, 0, & + 14, 41, 87, 108, 117, 149, 170, & + 25, 40, 85, 94, 124, 159, 0, & + 25, 58, 69, 116, 143, 174, 0, & + 29, 43, 61, 116, 132, 162, 0, & + 15, 58, 88, 112, 121, 164, 0, & + 4, 59, 72, 114, 119, 163, 173, & + 27, 47, 86, 98, 134, 153, 0, & + 5, 44, 78, 109, 141, 0, 0, & + 10, 46, 69, 103, 136, 165, 0, & + 9, 50, 59, 93, 128, 164, 0, & + 14, 57, 58, 109, 120, 166, 0, & + 17, 55, 62, 116, 125, 154, 0, & + 3, 54, 70, 101, 140, 170, 0, & + 1, 36, 82, 108, 127, 174, 0, & + 5, 53, 81, 105, 140, 0, 0, & + 29, 53, 67, 99, 142, 173, 0, & + 18, 49, 74, 97, 115, 167, 0, & + 2, 57, 63, 103, 138, 157, 0, & + 26, 38, 79, 112, 135, 171, 0, & + 11, 52, 66, 88, 119, 148, 0, & + 20, 40, 68, 117, 141, 160, 0, & + 11, 48, 81, 89, 146, 169, 0, & + 29, 47, 80, 92, 146, 172, 0, & + 6, 32, 87, 104, 145, 169, 0, & + 27, 34, 74, 106, 131, 165, 0, & + 12, 56, 84, 88, 139, 0, 0, & + 13, 56, 62, 111, 146, 171, 0, & + 26, 37, 80, 105, 144, 151, 0, & + 17, 31, 82, 113, 121, 161, 0, & + 28, 49, 59, 94, 137, 0, 0, & + 7, 55, 83, 101, 131, 168, 0, & + 24, 50, 78, 106, 143, 149, 0/ + +data nrw/ & + 6,6,6,6,6,6,6,6,6,6, & + 6,6,6,6,6,6,6,6,6,6, & + 6,6,6,6,6,6,6,6,6,6, & + 6,6,6,6,6,6,6,6,6,7, & + 6,6,6,6,6,7,6,6,6,6, & + 6,6,6,6,6,7,6,6,6,6, & + 7,6,5,6,6,6,6,6,6,5, & + 6,6,6,6,6,6,6,6,6,6, & + 5,6,6,6,5,6,6/ + +ncw=3 + +decoded=0 +toc=0 +tov=0 +tanhtoc=0 +! 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)) + 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 + codeword=cw(colorder+1) + decoded=codeword(M+1:N) + nerr=0 + do i=1,N + if( (2*cw(i)-1)*llr(i) .lt. 0.0 ) nerr=nerr+1 + enddo + nharderror=nerr + return + endif + + if( iter.gt.0 ) then ! this code block implements an early stopping criterion +! if( iter.gt.10000 ) 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. 10 .and. ncheck .gt. 15) then + nharderror=-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 ! 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:7,i)=tanh(-toc(1:7,i)/2) + enddo + + do j=1,N + do i=1,ncw + 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 +nharderror=-1 +return +end subroutine bpdecode174 diff --git a/lib/fsk4hf/bpdecode300.f90 b/lib/fsk4hf/bpdecode300.f90 new file mode 100644 index 00000000..22f7f885 --- /dev/null +++ b/lib/fsk4hf/bpdecode300.f90 @@ -0,0 +1,708 @@ +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) + nerr=0 + do i=1,N + if( (2*cw(i)-1)*llr(i) .lt. 0.0 ) nerr=nerr+1 + enddo + niterations=nerr + 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 diff --git a/lib/fsk4hf/chkcrc10.f90 b/lib/fsk4hf/chkcrc10.f90 new file mode 100644 index 00000000..abe7bd79 --- /dev/null +++ b/lib/fsk4hf/chkcrc10.f90 @@ -0,0 +1,27 @@ +subroutine chkcrc10(decoded,nbadcrc) + + use crc + integer*1 decoded(60) + integer*1, target:: i1Dec8BitBytes(9) + +! 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 + +! Pack 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 + nbadcrc=1 + if(crc10_check(c_loc(i1Dec8BitBytes),9)) nbadcrc=0 + + return +end subroutine chkcrc10 diff --git a/lib/fsk4hf/chkcrc12.f90 b/lib/fsk4hf/chkcrc12.f90 new file mode 100644 index 00000000..a177fa11 --- /dev/null +++ b/lib/fsk4hf/chkcrc12.f90 @@ -0,0 +1,27 @@ +subroutine chkcrc12(decoded,nbadcrc) + + use crc + integer*1 decoded(84) + integer*1, target:: i1Dec8BitBytes(11) + +! Check the CRC +! Collapse 84 decoded bits to 11 bytes. Bytes 1-9 are the message, +! byte 10 and first half of byte 11 is the crc + do ibyte=1,9 + itmp=0 + do ibit=1,8 + itmp=ishft(itmp,1)+iand(1,decoded((ibyte-1)*8+ibit)) + enddo + i1Dec8BitBytes(ibyte)=itmp + enddo + +! Pack the crc into bytes 10 and 11 for crc12_check + i1Dec8BitBytes(10)=decoded(73)*8 + decoded(74)*4 + decoded(75)*2 + decoded(76) + i1Dec8BitBytes(11)=decoded(77)*128 + decoded(78)*64 + & + decoded(79)*32 + decoded(80)*16 + decoded(81)*8 + decoded(82)*4 + & + decoded(83)*2 + decoded(84) + nbadcrc=1 + if( crc12_check(c_loc (i1Dec8BitBytes), 11) ) nbadcrc=0 + + return +end subroutine chkcrc12 diff --git a/lib/fsk4hf/chkcrc12a.f90 b/lib/fsk4hf/chkcrc12a.f90 new file mode 100644 index 00000000..fc429190 --- /dev/null +++ b/lib/fsk4hf/chkcrc12a.f90 @@ -0,0 +1,24 @@ +subroutine chkcrc12a(decoded,nbadcrc) + + use crc + integer*1 decoded(87) + integer*1, target:: i1Dec8BitBytes(11) + character*87 cbits + +! Write decoded bits into cbits: 75-bit message plus 12-bit CRC + write(cbits,1000) decoded +1000 format(87i1) + read(cbits,1001) i1Dec8BitBytes +1001 format(11b8) + read(cbits,1002) ncrc12 !Received CRC12 +1002 format(75x,b12) + + i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),128+64+32) + i1Dec8BitBytes(11)=0 + icrc12=crc12(c_loc(i1Dec8BitBytes),11) !CRC12 computed from 75 msg bits + + nbadcrc=1 + if(ncrc12.eq.icrc12) nbadcrc=0 + + return +end subroutine chkcrc12a diff --git a/lib/fsk4hf/cpolyfit.f90 b/lib/fsk4hf/cpolyfit.f90 new file mode 100644 index 00000000..fd0d5987 --- /dev/null +++ b/lib/fsk4hf/cpolyfit.f90 @@ -0,0 +1,76 @@ +subroutine cpolyfit(c,pp,id,maxn,aa,bb,zz,nhardsync) + + parameter (KK=84) !Information bits (72 + CRC12) + parameter (ND=168) !Data symbols: LDPC (168,84), r=1/2 + parameter (NS=65) !Sync symbols (2 x 26 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (236) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (3760) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + + complex c(0:NZ-1) !Complex waveform + complex zz(NS+ND) !Complex symbol values (intermediate) + complex z,z0 + real x(NS),yi(NS),yq(NS) !For complex polyfit + real pp(2*NSPS) !Shaped pulse for OQPSK + real aa(20),bb(20) !Fitted polyco's + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + + ib=NSPS-1 + ib2=N2-1 + n=0 + do j=1,117 !First-pass demodulation + ia=ib+1 + ib=ia+N2-1 + zz(j)=sum(pp*c(ia:ib))/NSPS + if(abs(id(j)).eq.2) then !Save all sync symbols + n=n+1 + x(n)=float(ia+ib)/NZ - 1.0 + yi(n)=real(zz(j))*0.5*id(j) + yq(n)=aimag(zz(j))*0.5*id(j) +! write(54,1225) n,x(n),yi(n),yq(n) +!1225 format(i5,3f12.4) + endif + if(j.le.116) then + zz(j+117)=sum(pp*c(ia+NSPS:ib+NSPS))/NSPS + endif + enddo + + aa=0. + bb=0. + nterms=0 + chisqa=0. + chisqb=0. + if(maxn.gt.0) then + npts=n + mode=0 + nterms=maxn + call polyfit4(x,yi,yi,npts,nterms,mode,aa,chisqa) + call polyfit4(x,yq,yq,npts,nterms,mode,bb,chisqb) + endif + + nhardsync=0 + do j=1,117 + if(abs(id(j)).ne.2) cycle + xx=j*2.0/117.0 - 1.0 + yii=1. + yqq=0. + if(nterms.gt.0) then + yii=aa(1) + yqq=bb(1) + do i=2,nterms + yii=yii + aa(i)*xx**(i-1) + yqq=yqq + bb(i)*xx**(i-1) + enddo + endif + z0=cmplx(yii,yqq) + z=zz(j)*conjg(z0) + p=real(z) + if(p*id(j).lt.0) nhardsync=nhardsync+1 + enddo + + return +end subroutine cpolyfit diff --git a/lib/fsk4hf/cpolyfitw.f90 b/lib/fsk4hf/cpolyfitw.f90 new file mode 100644 index 00000000..561052f8 --- /dev/null +++ b/lib/fsk4hf/cpolyfitw.f90 @@ -0,0 +1,68 @@ +subroutine cpolyfitw(c,pp,id,maxn,aa,bb,zz,nhardsync) + + include 'wsprlf_params.f90' + + complex c(0:NZ-1) !Complex waveform + complex zz(NS+ND) !Complex symbol values (intermediate) + complex z,z0 + real x(NS),yi(NS),yq(NS) !For complex polyfit + real pp(2*NSPS) !Shaped pulse for OQPSK + real aa(20),bb(20) !Fitted polyco's + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + + ib=NSPS-1 + ib2=N2-1 + n=0 + jz=(NS+ND+1)/2 + do j=1,jz !First-pass demodulation + ia=ib+1 + ib=ia+N2-1 + zz(j)=sum(pp*c(ia:ib))/NSPS + if(abs(id(j)).eq.2) then !Save all sync symbols + n=n+1 + x(n)=float(ia+ib)/NZ - 1.0 + yi(n)=real(zz(j))*0.5*id(j) + yq(n)=aimag(zz(j))*0.5*id(j) +! write(54,1225) n,x(n),yi(n),yq(n) +!1225 format(i5,3f12.4) + endif + if(j.lt.jz) then + zz(j+jz)=sum(pp*c(ia+NSPS:ib+NSPS))/NSPS + endif + enddo + + aa=0. + bb=0. + nterms=0 + chisqa=0. + chisqb=0. + if(maxn.gt.0) then + npts=n + mode=0 + nterms=maxn + call polyfit4(x,yi,yi,npts,nterms,mode,aa,chisqa) + call polyfit4(x,yq,yq,npts,nterms,mode,bb,chisqb) + endif + + nhardsync=0 + do j=1,205 + if(abs(id(j)).ne.2) cycle + xx=j*2.0/205.0 - 1.0 + yii=1. + yqq=0. + if(nterms.gt.0) then + yii=aa(1) + yqq=bb(1) + do i=2,nterms + yii=yii + aa(i)*xx**(i-1) + yqq=yqq + bb(i)*xx**(i-1) + enddo + endif + z0=cmplx(yii,yqq) + z=zz(j)*conjg(z0) + p=real(z) + if(p*id(j).lt.0) nhardsync=nhardsync+1 + enddo + + return +end subroutine cpolyfitw diff --git a/lib/fsk4hf/dbpsksim.f90 b/lib/fsk4hf/dbpsksim.f90 new file mode 100644 index 00000000..8b9ea12c --- /dev/null +++ b/lib/fsk4hf/dbpsksim.f90 @@ -0,0 +1,241 @@ +program dbpsksim + + parameter (ND=121) !Data symbols: LDPC (120,60), r=1/2 + parameter (NN=ND) !Total symbols (121) + parameter (NSPS=28800) !Samples per symbol at 12000 sps + parameter (NZ=NSPS*NN) !Samples in waveform (3484800) + parameter (NFFT1=65536,NH1=NFFT1/2) + parameter (NFFT2=128,NH2=NFFT2/2) + + character*8 arg + complex c(0:NZ-1) !Complex waveform + complex c2(0:NFFT1-1) !Short spectra + complex cr(0:NZ-1) + complex ct(0:NZ-1) + complex cz(0:NFFT2-1) + complex z0,z,zp + real s(-NH1+1:NH1) + real s2(-NH2+1:NH2) + real xnoise(0:NZ-1) !Generated random noise + real ynoise(0:NZ-1) !Generated random noise + real rxdata(120),llr(120) + integer id(NN) !Encoded NRZ data (values +/-1) + integer id1(NN) !Recovered data (1st pass) + integer id2(NN) !Recovered data (2nd pass) +! integer icw(NN) + integer*1 msgbits(60),decoded(60),codeword(120),apmask(120),cw(120) + data msgbits/0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,& + 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,0,1,0,1,1,0,1,0/ + + nnn=0 + nargs=iargc() + if(nargs.ne.6) then + print*,'Usage: dbpsksim f0(Hz) delay(ms) fspread(Hz) ndiff iters snr(dB)' + print*,'Example: dbpsksim 1500 0 0 10 -35' + print*,'Set snr=0 to cycle through a range' + go to 999 + endif + call getarg(1,arg) + read(arg,*) f0 !Low tone frequency + call getarg(2,arg) + read(arg,*) delay + call getarg(3,arg) + read(arg,*) fspread + call getarg(4,arg) + read(arg,*) ndiff + call getarg(5,arg) + read(arg,*) iters + call getarg(6,arg) + read(arg,*) snrdb + + twopi=8.d0*atan(1.d0) + fs=12000.d0 + dt=1.0/fs + ts=NSPS*dt + baud=1.d0/ts + txt=NZ*dt + bandwidth_ratio=2500.0/6000.0 + write(*,1000) baud,5*baud,txt,delay,fspread,ndiff +1000 format('Baud:',f6.3,' BW:',f4.1,' TxT:',f6.1,' Delay:',f5.2, & + ' fSpread:',f5.2,' ndiff:',i2/) + + write(*,1004) +1004 format(' SNR err ber fer fsigma'/35('-')) + + call encode120(msgbits,codeword) !Encode the test message + isna=-28 + isnb=-40 + if(snrdb.ne.0.0) then + isna=nint(snrdb) + isnb=isna + endif + do isnr=isna,isnb,-1 + snrdb=isnr + sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + nhard=0 + nhardc=0 + nfe1=0 + nfe2=0 + sqf=0. + do iter=1,iters + nnn=nnn+1 + id(1)=1 !First bit is always 1 + id(2:NN)=2*codeword-1 + call genbpsk(id,f0,ndiff,0,c) !Generate the 4-FSK waveform + if(delay.ne.0.0 .or. fspread.ne.0.0) call watterson(c,delay,fspread) + c=sig*c !Scale to requested SNR + if(snrdb.lt.90) then + do i=0,NZ-1 !Generate gaussian noise + xnoise(i)=gran() + ynoise(i)=gran() + enddo + c=c + cmplx(xnoise,ynoise) !Add noise to signal + endif + +! First attempt at finding carrier frequency fc: 64k FFTs ==> avg power spectra + nspec=NZ/NFFT1 + df1=12000.0/NFFT1 + s=0. + do k=1,nspec + ia=(k-1)*NSPS + ib=ia+NSPS-1 + c2(0:NSPS-1)=c(ia:ib) + c2(NSPS:)=0. + call four2a(c2,NFFT1,1,-1,1) + do i=0,NFFT1-1 + j=i + if(j.gt.NH1) j=j-NFFT1 + s(j)=s(j) + real(c2(i))**2 + aimag(c2(i))**2 + enddo + enddo + s=1.e-6*s + smax=0. + ipk=0 + ia=(1400.0)/df1 + ib=(1600.0)/df1 + do i=ia,ib + f=i*df1 + if(s(i).gt.smax) then + smax=s(i) + ipk=i + fc=f + endif + enddo + a=(s(ipk+1)-s(ipk-1))/2.0 + b=(s(ipk+1)+s(ipk-1)-2.0*s(ipk))/2.0 + dx=-a/(2.0*b) + fc=fc + df1*dx !Estimated carrier frequency + sqf=sqf + (fc-f0)**2 + +! The following is for testing SNR calibration: +! sp5n=(s(ipk-2)+s(ipk-1)+s(ipk)+s(ipk+1)+s(ipk+2)) !Sig + 5*noise +! base=(sum(s)-sp5n)/(NFFT1-5.0) !Noise per bin +! psig=sp5n-5*base !Sig only +! pnoise=(2500.0/df1)*base !Noise in 2500 Hz +! xsnrdb=db(psig/pnoise) + + call genbpsk(id,fc,ndiff,1,cr) !Generate reference carrier + c=c*conjg(cr) !Mix signal to baseband + + z0=1.0 + do j=1,NN !Demodulate + ia=(j-1)*NSPS + ib=ia+NSPS-1 + z=sum(c(ia:ib)) + cz(j-1)=z + zp=z*conjg(z0) + p=1.e-4*real(zp) + id1(j)=-1 + if(p.ge.0.0) id1(j)=1 + if(j.ge.2) rxdata(j-1)=p + z0=z + enddo + + rxav=sum(rxdata)/120 + rx2av=sum(rxdata*rxdata)/120 + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + ss=0.84 + llr=2.0*rxdata/(ss*ss) + apmask=0 + max_iterations=10 + call bpdecode120(llr,apmask,max_iterations,decoded,niterations,cw) + +! Count frame errors + if(niterations.lt.0 .or. count(msgbits.ne.decoded).gt.0) nfe1=nfe1+1 + +! Find carrier frequency from squared cz array. + cz(121:)=0. + cz=cz*cz + call four2a(cz,NFFT2,1,-1,1) + s2max=0. + do i=0,NFFT2-1 + j=i + if(i.gt.NH2) j=j-NFFT2 + s2(j)=real(cz(i))**2 + aimag(cz(i))**2 + if(s2(j).gt.s2max) then + s2max=s2(j) + jpk=j + endif +! write(16,1200) j*baud/NFFT2,1.e-12*s2(j) +!1200 format(2f12.3) + enddo + a=(s2(jpk+1)-s2(jpk-1))/2.0 + b=(s2(jpk+1)+s2(jpk-1)-2.0*s2(jpk))/2.0 + dx=-a/(2.0*b) + fc2=0.5*(jpk+dx)*baud/NFFT2 + + call genbpsk(id,fc2,ndiff,1,cr) !Generate new ref carrier at fc2 + c=c*conjg(cr) + z0=1.0 + do j=1,NN !Demodulate + ia=(j-1)*NSPS + ib=ia+NSPS-1 + z=sum(c(ia:ib)) + if(j.eq.1) z0=z + zp=z*conjg(z0) + p=1.e-4*real(zp) + id2(j)=-1 + if(p.ge.0.0) id2(j)=1 + if(j.ge.2) rxdata(j-1)=p + ierr=0 + if(id2(j).ne.id(j)) ierr=1 + id3=-1 + if(real(z).ge.0.0) id3=1 + if(j.ge.2 .and. id3.ne.id(j)) nhardc=nhardc+1 + if(j.ge.2 .and. ndiff.eq.0) rxdata(j-1)=real(z) + z0=z + enddo + nhard=nhard + count(id2.ne.id) !Count hard errors + + rxav=sum(rxdata)/120 + rx2av=sum(rxdata*rxdata)/120 + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + ss=0.84 + llr=2.0*rxdata/(ss*ss) !Soft symbols + apmask=0 + max_iterations=10 + decoded=0 + call bpdecode120(llr,apmask,max_iterations,decoded,niterations,cw) +! if(niterations.lt.0) then +! llr=-llr +! call bpdecode120(llr,apmask,max_iterations,decoded,niterations,cw) +! if(niterations.ge.0) nhard=NN*iters-nhard +! endif + if(niterations.ge.0) call chkcrc10(decoded,nbadcrc) + if(niterations.lt.0 .or. count(msgbits.ne.decoded).gt.0 .or. & + nbadcrc.ne.0) nfe2=nfe2+1 + enddo + + if(ndiff.eq.0) nhard=nhardc + fsigma=sqrt(sqf/iters) + ber=float(nhard)/(NN*iters) + fer=float(nfe2)/iters + write(*,1050) snrdb,nhard,ber,fer,fsigma + write(14,1050) snrdb,nhard,ber,fer,fsigma +1050 format(f6.1,i5,f8.4,f7.3,f8.2) + enddo + +999 end program dbpsksim diff --git a/lib/fsk4hf/dopspread.f90 b/lib/fsk4hf/dopspread.f90 new file mode 100644 index 00000000..cadfbecc --- /dev/null +++ b/lib/fsk4hf/dopspread.f90 @@ -0,0 +1,62 @@ +subroutine dopspread(c,fspread) + + parameter (NFFT=268800,NH=NFFT/2) + complex c(0:NFFT-1) + complex cspread(0:NFFT-1) + + df=12000.0/nfft + twopi=8*atan(1.0) + cspread(0)=1.0 + cspread(NH)=0. + b=6.0 !Lorenzian 3/28 onward + do i=1,NH + f=i*df + x=b*f/fspread + z=0. + a=0. + if(x.lt.3.0) then !Cutoff beyond x=3 + a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian + call random_number(r1) + phi1=twopi*r1 + z=a*cmplx(cos(phi1),sin(phi1)) + endif + cspread(i)=z + z=0. + if(x.lt.50.0) then + call random_number(r2) + phi2=twopi*r2 + z=a*cmplx(cos(phi2),sin(phi2)) + endif + cspread(NFFT-i)=z + enddo + + izh=fspread/df + do i=-izh,izh + f=i*df + j=i + if(j.lt.0) j=j+nfft + s=real(cspread(j))**2 + aimag(cspread(j))**2 +! write(23,3000) f,s,cspread(j) +!3000 format(f10.3,3f12.6) + enddo + + call four2a(cspread,NFFT,1,1,1) !Transform to time domain + + sum=0. + do i=0,NFFT-1 + p=real(cspread(i))**2 + aimag(cspread(i))**2 + sum=sum+p + enddo + avep=sum/NFFT + fac=sqrt(1.0/avep) + cspread=fac*cspread !Normalize to constant avg power + c=cspread*c !Apply Rayleigh fading to c() + + do i=0,NFFT-1 + p=real(cspread(i))**2 + aimag(cspread(i))**2 +! write(24,3010) i,p,cspread(i) +!3010 format(i8,3f12.6) + enddo + + return +end subroutine dopspread diff --git a/lib/fsk4hf/encode120.f90 b/lib/fsk4hf/encode120.f90 new file mode 100644 index 00000000..577bbe86 --- /dev/null +++ b/lib/fsk4hf/encode120.f90 @@ -0,0 +1,116 @@ +subroutine encode120(message,codeword) +! Encode an 60-bit message and return a 120-bit codeword. +! The generator matrix has dimensions (60,60). +! The code is a (120,60) regular ldpc code with column weight 3. +! 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(60) +integer*1 codeword(120) +integer colorder(120) +integer*1 gen(60,60) +integer*1 itmp(120) +integer*1 message(60) +integer*1 pchecks(60) +logical first +data first/.true./ +data g/ & + "65541ad98feab6e",& + "27249940a5895a3",& + "c80eac7506bf794",& + "aa50393e3e18d3f",& + "28527e87d47dced",& + "5da0dcaf8db048c",& + "d6509a43ca9b01a",& + "9a7dadd9c94f1d4",& + "bb673d3ba07cf29",& + "65e190f2fbed447",& + "bc2062a4e520969",& + "9e357f3feed059b",& + "aa6b59212036a57",& + "f78a326722d6565",& + "416754bc34c6405",& + "f77000b3f04ff67",& + "d48fbd7d48c5ab9",& + "031ffb5db3a70cb",& + "125964e358c4df5",& + "bd02c32a5a241ea",& + "4c15ecdd8561abd",& + "7f0f1b352c7413e",& + "26edb94dfd0ae79",& + "ca1ba1ee0f8fb24",& + "49878a58cb4544c",& + "3dbcd0ff821b203",& + "c1f4440160d5345",& + "b5ea9dc7a5a70ab",& + "cebcf7d94976be4",& + "0968265f5977c88",& + "c5a36937faa78c3",& + "f0d4fef11e01c10",& + "e35fc0c779bebfe",& + "cf49c3eb41a31d5",& + "3f0b19352c7013e",& + "0e15eccd8521abd",& + "dda8dcaf9d3048c",& + "fee31438fba59ed",& + "ad74a27e939189c",& + "736ac01b439106e",& + "ab5d2729b29bfa1",& + "edf11fb02e5a426",& + "5f38be1c93ecc83",& + "1e4b3b8dc516b3e",& + "84443d8bee614c6",& + "d854d9f355ceac4",& + "a476b5ece51f0ea",& + "831c2b36c4c2f68",& + "f485c97a91615ae",& + "e9376d828ade9ba",& + "cac586f089d3185",& + "b8f8c67613dafe2",& + "1a3142b401b315d",& + "87dbedc43265d2e",& + "bb64ec6e652e7da",& + "e71bfd4c95dfd38",& + "31209af07ad4f75",& + "cff1a8ccc5f4978",& + "742eded1e1dfefd",& + "1cd7154a904dac4"/ + +data colorder/ & + 0,1,2,21,3,4,5,6,7,8,20,10,9,11,12,23,13,28,14,31, & + 15,16,22,26,17,30,18,29,25,32,41,34,19,33,27,36,38,43,42,24, & + 37,39,45,40,35,44,47,46,50,51,53,48,52,56,54,57,55,49,58,61, & + 60,59,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, & + 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99, & + 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119/ + +save first,gen + +if( first ) then ! fill the generator matrix + gen=0 + do i=1,60 + 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, 60 + nsum=0 + do j=1, 60 + nsum=nsum+message(j)*gen(i,j) + enddo + pchecks(i)=mod(nsum,2) +enddo +itmp(1:60)=pchecks +itmp(61:120)=message(1:60) +codeword(colorder+1)=itmp(1:120) + +return +end subroutine encode120 diff --git a/lib/fsk4hf/encode168.f90 b/lib/fsk4hf/encode168.f90 new file mode 100644 index 00000000..bf121215 --- /dev/null +++ b/lib/fsk4hf/encode168.f90 @@ -0,0 +1,141 @@ +subroutine encode168(message,codeword) +! Encode an 84-bit message and return a 168-bit codeword. +! The generator matrix has dimensions (84,84). +! The code is a (168,84) regular ldpc code with column weight 3. +! 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*21 g(84) +integer*1 codeword(168) +integer colorder(168) +integer*1 gen(84,168) +integer*1 itmp(168) +integer*1 message(84) +integer*1 pchecks(84) +logical first +data first/.true./ +data g/ & !parity generator matrix for (168,84) code + "25c5bf31ef6710fde9a5a", & + "18038ef7899cd97a77d96", & + "270dde504dad076c02b1f", & + "ed37fe12616565bd7d500", & + "12b99aa49b5367aff3838", & + "41cc27f2fac8b228aac21", & + "2265b233a3cff0b9cee24", & + "292760cd4f7f4a526a2f1", & + "2b3db4c8bd831911680cc", & + "cef2b24ce203bdc60b266", & + "5045a24f9340915d807ab", & + "3592b7fc60ba85139502e", & + "9318023145637bd798f0e", & + "ad796023c3d58d1e6509c", & + "3da5eab57f040e75d7413", & + "27466d1d2734d0ff64830", & + "2ed50bb1ce313bbfb1ab0", & + "9a616bda01b25b7e6eeaf", & + "a84c8c1e9df103169d10d", & + "a40da29b4aca9234a8942", & + "dd258d02d79a5f209d3d0", & + "bdfdc06713511997b5621", & + "25c58f12f4096cd8ead1a", & + "b2638a478f21e10fe97de", & + "4051020f43c605d458156", & + "f651aad14322a526dae35", & + "a1c147e31bcc9d87330bf", & + "7524b53d996d48284647b", & + "a72e7d25ce31b27282e56", & + "a97f53b019022350b7519", & + "56106c6340c0810790984", & + "c63b8e03a57208635992b", & + "43a3de2aa3a2b1afb65dc", & + "9baa64847ead03b77fecc", & + "251cbd1895c8839c46b0d", & + "2858107dde2d173e13530", & + "20096f6a870f636b704e7", & + "7f833ccbceec52dd6eb79", & + "a9108dd77b8015b75242a", & + "689666a79e5579c916236", & + "aa5dff46459787f69911f", & + "794558c13138d08171089", & + "c937042857b291cee8dfd", & + "6f0bf3248bb9a231366b8", & + "1c09e756ef1656c96f2d2", & + "073b875b6774e71fba549", & + "f7d840aafc037febd2d5c", & + "dcc0e7d0da5fe17c99ad3", & + "98238ef7819cd97a77d94", & + "177c2594743477421a262", & + "7d01a833c19374fbaaa6e", & + "7bb800216660482ffd1c4", & + "39a92e2dba0d4cfda98d2", & + "44b8d88622698816456a8", & + "791db2334d6d86639229b", & + "ba6004b086bd38559ea48", & + "f94558e13138d18170089", & + "08ba145302cfbed7845ae", & + "fb8e64b6da3602168ed38", & + "1045a2cf1340915d8072b", & + "7592b6fc64ba85139582e", & + "3eb238a11bc6654452bae", & + "b69d8d23b1ea170f70214", & + "0123dfae84fb20462a614", & + "4131066ad52a339b3c0d7", & + "fd2cc26850951c43ed737", & + "a644d4eb7e56c40f0d050", & + "0c3bd9d5dab7c9ee2c8fc", & + "4a198b37af56d7ceffb56", & + "b6e946c429294cf0eed8b", & + "98384d75e758774f5ff3b", & + "5c58e5d9a4d0531d37384", & + "7a0af02719afed521fd06", & + "8cd5b2e694e7854abbc70", & + "1a2f061912d0ea19702d3", & + "6ffbce557d8fa691a50e8", & + "d43438e2e2ed5d9f14011", & + "8d502106083b809adba00", & + "67e22f9b9983aa715964d", & + "b31f3a3f3c1f406b1fd58", & + "529f60ac291f827d97331", & + "476a815424f2e2cbe641f", & + "81c82c89bcc3feec42458", & + "2c882d0e281b178e80364"/ + +data colorder/0,1,2,3,28,4,5,6,7,8,9,10,11,34,12,32,13,14,15,16,17, & + 18,36,29,42,31,20,21,41,40,30,38,22,19,47,37,46,35,44,33,49,24, & + 43,51,25,26,27,50,52,57,69,54,55,45,59,58,56,61,60,53,48,23,62, & + 63,64,67,66,65,68,39,70,71,72,74,73,75,76,77,80,81,78,82,79,83, & + 84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104, & + 105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125, & + 126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146, & + 147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167/ + +save first,gen + +if( first ) then ! fill the generator matrix + gen=0 + do i=1,84 + do j=1,21 + 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, 84 + nsum=0 + do j=1, 84 + nsum=nsum+message(j)*gen(i,j) + enddo + pchecks(i)=mod(nsum,2) +enddo +itmp(1:84)=pchecks +itmp(85:168)=message(1:84) +codeword(colorder+1)=itmp(1:168) + +return +end subroutine encode168 diff --git a/lib/fsk4hf/encode174.f90 b/lib/fsk4hf/encode174.f90 new file mode 100644 index 00000000..8ef463e8 --- /dev/null +++ b/lib/fsk4hf/encode174.f90 @@ -0,0 +1,50 @@ +subroutine encode174(message,codeword) +! Encode an 101-bit message and return a 174-bit codeword. +! The generator matrix has dimensions (73,101). +! The code is a (174,101) regular ldpc code with column weight 3. +! 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 +! + +include "ldpc_174_87_params.f90" + +integer*1 codeword(N) +integer*1 gen(M,K) +integer*1 itmp(N) +integer*1 message(K) +integer*1 pchecks(M) +logical first +data first/.true./ + +save first,gen + +if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,11 + read(g(i)( (j-1)*2+1:(j-1)*2+2 ),"(Z2)") istr + do jj=1, 8 + icol=(j-1)*8+jj + if( icol .le. 87 ) then + if( btest(istr,8-jj) ) gen(i,icol)=1 + endif + enddo + enddo + enddo +first=.false. +endif + +do i=1,M + nsum=0 + do j=1,K + nsum=nsum+message(j)*gen(i,j) + enddo + pchecks(i)=mod(nsum,2) +enddo +itmp(1:M)=pchecks +itmp(M+1:N)=message(1:K) +codeword(colorder+1)=itmp(1:N) + +return +end subroutine encode174 diff --git a/lib/fsk4hf/encode300.f90 b/lib/fsk4hf/encode300.f90 new file mode 100644 index 00000000..f1d3bbae --- /dev/null +++ b/lib/fsk4hf/encode300.f90 @@ -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 diff --git a/lib/fsk4hf/extractmessage168.f90 b/lib/fsk4hf/extractmessage168.f90 new file mode 100644 index 00000000..466d2a63 --- /dev/null +++ b/lib/fsk4hf/extractmessage168.f90 @@ -0,0 +1,48 @@ +subroutine extractmessage168(decoded,msgreceived,ncrcflag,recent_calls,nrecent) + use iso_c_binding, only: c_loc,c_size_t + use crc + use packjt + + character*22 msgreceived + character*12 call1,call2 + character*12 recent_calls(nrecent) + integer*1 decoded(84) + integer*1, target:: i1Dec8BitBytes(11) + integer*4 i4Dec6BitWords(12) + +! Collapse 84 decoded bits to 11 bytes. Bytes 1-9 are the message, byte 10 and first half of byte 11 is the crc + do ibyte=1,9 + itmp=0 + do ibit=1,8 + itmp=ishft(itmp,1)+iand(1,decoded((ibyte-1)*8+ibit)) + enddo + i1Dec8BitBytes(ibyte)=itmp + enddo +! Need to pack the crc into bytes 10 and 11 for crc12_check + i1Dec8BitBytes(10)=decoded(73)*8+decoded(74)*4+decoded(75)*2+decoded(76) + i1Dec8BitBytes(11)=decoded(77)*128+decoded(78)*64+decoded(79)*2*32+decoded(80)*16 + i1Dec8BitBytes(11)=i1Dec8BitBytes(11)+decoded(81)*8+decoded(82)*4+decoded(83)*2+decoded(84) + + if( crc12_check(c_loc (i1Dec8BitBytes), 11) ) then +! CRC12 checks out --- unpack 72-bit message + do ibyte=1,12 + itmp=0 + do ibit=1,6 + itmp=ishft(itmp,1)+iand(1,decoded((ibyte-1)*6+ibit)) + enddo + i4Dec6BitWords(ibyte)=itmp + enddo + call unpackmsg144(i4Dec6BitWords,msgreceived,call1,call2) + ncrcflag=1 + if( call1(1:2) .ne. 'CQ' .and. call1(1:2) .ne. ' ' ) then + call update_recent_calls(call1,recent_calls,nrecent) + endif + if( call2(1:2) .ne. ' ' ) then + call update_recent_calls(call2,recent_calls,nrecent) + endif + else + msgreceived=' ' + ncrcflag=-1 + endif + return + end subroutine extractmessage168 diff --git a/lib/fsk4hf/extractmessage174.f90 b/lib/fsk4hf/extractmessage174.f90 new file mode 100644 index 00000000..ec4543d4 --- /dev/null +++ b/lib/fsk4hf/extractmessage174.f90 @@ -0,0 +1,48 @@ +subroutine extractmessage174(decoded,msgreceived,ncrcflag,recent_calls,nrecent) + use iso_c_binding, only: c_loc,c_size_t + use crc + use packjt + + character*22 msgreceived + character*12 call1,call2 + character*12 recent_calls(nrecent) + character*87 cbits + integer*1 decoded(87) + integer*1, target:: i1Dec8BitBytes(11) + integer*4 i4Dec6BitWords(12) + +! Write decoded bits into cbits: 75-bit message plus 12-bit CRC + write(cbits,1000) decoded +1000 format(87i1) + read(cbits,1001) i1Dec8BitBytes +1001 format(11b8) + read(cbits,1002) ncrc12 !Received CRC12 +1002 format(75x,b12) + + i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),128+64+32) + i1Dec8BitBytes(11)=0 + icrc12=crc12(c_loc(i1Dec8BitBytes),11) !CRC12 computed from 75 msg bits + + if(ncrc12.eq.icrc12) then +! CRC12 checks out --- unpack 72-bit message + do ibyte=1,12 + itmp=0 + do ibit=1,6 + itmp=ishft(itmp,1)+iand(1,decoded((ibyte-1)*6+ibit)) + enddo + i4Dec6BitWords(ibyte)=itmp + enddo + call unpackmsg144(i4Dec6BitWords,msgreceived,call1,call2) + ncrcflag=1 + if( call1(1:2) .ne. 'CQ' .and. call1(1:2) .ne. ' ' ) then + call update_recent_calls(call1,recent_calls,nrecent) + endif + if( call2(1:2) .ne. ' ' ) then + call update_recent_calls(call2,recent_calls,nrecent) + endif + else + msgreceived=' ' + ncrcflag=-1 + endif + return + end subroutine extractmessage174 diff --git a/lib/fsk4hf/fftw3.f90 b/lib/fsk4hf/fftw3.f90 new file mode 100644 index 00000000..440ccc28 --- /dev/null +++ b/lib/fsk4hf/fftw3.f90 @@ -0,0 +1,64 @@ + INTEGER FFTW_R2HC + PARAMETER (FFTW_R2HC=0) + INTEGER FFTW_HC2R + PARAMETER (FFTW_HC2R=1) + INTEGER FFTW_DHT + PARAMETER (FFTW_DHT=2) + INTEGER FFTW_REDFT00 + PARAMETER (FFTW_REDFT00=3) + INTEGER FFTW_REDFT01 + PARAMETER (FFTW_REDFT01=4) + INTEGER FFTW_REDFT10 + PARAMETER (FFTW_REDFT10=5) + INTEGER FFTW_REDFT11 + PARAMETER (FFTW_REDFT11=6) + INTEGER FFTW_RODFT00 + PARAMETER (FFTW_RODFT00=7) + INTEGER FFTW_RODFT01 + PARAMETER (FFTW_RODFT01=8) + INTEGER FFTW_RODFT10 + PARAMETER (FFTW_RODFT10=9) + INTEGER FFTW_RODFT11 + PARAMETER (FFTW_RODFT11=10) + INTEGER FFTW_FORWARD + PARAMETER (FFTW_FORWARD=-1) + INTEGER FFTW_BACKWARD + PARAMETER (FFTW_BACKWARD=+1) + INTEGER FFTW_MEASURE + PARAMETER (FFTW_MEASURE=0) + INTEGER FFTW_DESTROY_INPUT + PARAMETER (FFTW_DESTROY_INPUT=1) + INTEGER FFTW_UNALIGNED + PARAMETER (FFTW_UNALIGNED=2) + INTEGER FFTW_CONSERVE_MEMORY + PARAMETER (FFTW_CONSERVE_MEMORY=4) + INTEGER FFTW_EXHAUSTIVE + PARAMETER (FFTW_EXHAUSTIVE=8) + INTEGER FFTW_PRESERVE_INPUT + PARAMETER (FFTW_PRESERVE_INPUT=16) + INTEGER FFTW_PATIENT + PARAMETER (FFTW_PATIENT=32) + INTEGER FFTW_ESTIMATE + PARAMETER (FFTW_ESTIMATE=64) + INTEGER FFTW_ESTIMATE_PATIENT + PARAMETER (FFTW_ESTIMATE_PATIENT=128) + INTEGER FFTW_BELIEVE_PCOST + PARAMETER (FFTW_BELIEVE_PCOST=256) + INTEGER FFTW_DFT_R2HC_ICKY + PARAMETER (FFTW_DFT_R2HC_ICKY=512) + INTEGER FFTW_NONTHREADED_ICKY + PARAMETER (FFTW_NONTHREADED_ICKY=1024) + INTEGER FFTW_NO_BUFFERING + PARAMETER (FFTW_NO_BUFFERING=2048) + INTEGER FFTW_NO_INDIRECT_OP + PARAMETER (FFTW_NO_INDIRECT_OP=4096) + INTEGER FFTW_ALLOW_LARGE_GENERIC + PARAMETER (FFTW_ALLOW_LARGE_GENERIC=8192) + INTEGER FFTW_NO_RANK_SPLITS + PARAMETER (FFTW_NO_RANK_SPLITS=16384) + INTEGER FFTW_NO_VRANK_SPLITS + PARAMETER (FFTW_NO_VRANK_SPLITS=32768) + INTEGER FFTW_NO_VRECURSE + PARAMETER (FFTW_NO_VRECURSE=65536) + INTEGER FFTW_NO_SIMD + PARAMETER (FFTW_NO_SIMD=131072) diff --git a/lib/fsk4hf/four2a.f90 b/lib/fsk4hf/four2a.f90 new file mode 100644 index 00000000..57c7239e --- /dev/null +++ b/lib/fsk4hf/four2a.f90 @@ -0,0 +1,115 @@ +subroutine four2a(a,nfft,ndim,isign,iform) + +! IFORM = 1, 0 or -1, as data is +! complex, real, or the first half of a complex array. Transform +! values are returned in array DATA. They are complex, real, or +! the first half of a complex array, as IFORM = 1, -1 or 0. + +! The transform of a real array (IFORM = 0) dimensioned N(1) by N(2) +! by ... will be returned in the same array, now considered to +! be complex of dimensions N(1)/2+1 by N(2) by .... Note that if +! IFORM = 0 or -1, N(1) must be even, and enough room must be +! reserved. The missing values may be obtained by complex conjugation. + +! The reverse transformation of a half complex array dimensioned +! N(1)/2+1 by N(2) by ..., is accomplished by setting IFORM +! to -1. In the N array, N(1) must be the true N(1), not N(1)/2+1. +! The transform will be real and returned to the input array. + +! This version of four2a makes calls to the FFTW library to do the +! actual computations. + + parameter (NPMAX=2100) !Max numberf of stored plans + parameter (NSMALL=16384) !Max size of "small" FFTs + complex a(nfft) !Array to be transformed + complex aa(NSMALL) !Local copy of "small" a() + integer nn(NPMAX),ns(NPMAX),nf(NPMAX) !Params of stored plans + integer*8 nl(NPMAX),nloc !More params of plans + integer*8 plan(NPMAX) !Pointers to stored plans + logical found_plan + data nplan/0/ !Number of stored plans + common/patience/npatience,nthreads !Patience and threads for FFTW plans + include 'fftw3.f90' !FFTW definitions + save plan,nplan,nn,ns,nf,nl + + if(nfft.lt.0) go to 999 + + nloc=loc(a) + + found_plan = .false. + !$omp critical(four2a_setup) + do i=1,nplan + if(nfft.eq.nn(i) .and. isign.eq.ns(i) .and. & + iform.eq.nf(i) .and. nloc.eq.nl(i)) then + found_plan = .true. + exit + end if + enddo + + if(i.ge.NPMAX) stop 'Too many FFTW plans requested.' + + if (.not. found_plan) then + nplan=nplan+1 + i=nplan + + nn(i)=nfft + ns(i)=isign + nf(i)=iform + nl(i)=nloc + +! Planning: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT, FFTW_MEASURE, +! FFTW_PATIENT, FFTW_EXHAUSTIVE + nflags=FFTW_ESTIMATE + if(npatience.eq.1) nflags=FFTW_ESTIMATE_PATIENT + if(npatience.eq.2) nflags=FFTW_MEASURE + if(npatience.eq.3) nflags=FFTW_PATIENT + if(npatience.eq.4) nflags=FFTW_EXHAUSTIVE + + if(nfft.le.NSMALL) then + jz=nfft + if(iform.eq.0) jz=nfft/2 + aa(1:jz)=a(1:jz) + endif + + !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls + if(isign.eq.-1 .and. iform.eq.1) then + call sfftw_plan_dft_1d(plan(i),nfft,a,a,FFTW_FORWARD,nflags) + else if(isign.eq.1 .and. iform.eq.1) then + call sfftw_plan_dft_1d(plan(i),nfft,a,a,FFTW_BACKWARD,nflags) + else if(isign.eq.-1 .and. iform.eq.0) then + call sfftw_plan_dft_r2c_1d(plan(i),nfft,a,a,nflags) + else if(isign.eq.1 .and. iform.eq.-1) then + call sfftw_plan_dft_c2r_1d(plan(i),nfft,a,a,nflags) + else + stop 'Unsupported request in four2a' + endif + !$omp end critical(fftw) + + if(nfft.le.NSMALL) then + jz=nfft + if(iform.eq.0) jz=nfft/2 + a(1:jz)=aa(1:jz) + endif + end if + !$omp end critical(four2a_setup) + + call sfftw_execute(plan(i)) + return + +999 continue + + !$omp critical(four2a) + do i=1,nplan +! The test is only to silence a compiler warning: + if(ndim.ne.-999) then + !$omp critical(fftw) ! serialize non thread-safe FFTW3 calls + call sfftw_destroy_plan(plan(i)) + !$omp end critical(fftw) + end if + enddo + + nplan=0 + !$omp end critical(four2a) + + return +end subroutine four2a diff --git a/lib/fsk4hf/fsk4hf.f90 b/lib/fsk4hf/fsk4hf.f90 new file mode 100644 index 00000000..191e05c3 --- /dev/null +++ b/lib/fsk4hf/fsk4hf.f90 @@ -0,0 +1,145 @@ +program fsk4hf + +! Simulate characteristics of a potential mode using LDPC (168,84) code, +! 4-FSK modulation, and 30 s T/R sequences. + + parameter (KK=84) !Information bits (72 + CRC12) + parameter (ND=84) !Data symbols: LDPC (168,84), r=1/2 + parameter (NS=12) !Sync symbols (3 @ 4x4 Costas arrays) + parameter (NR=2) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (98) + parameter (NSPS=2688/84) !Samples per symbol (32) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (3760) + + character*8 arg + complex c0(0:NZ-1) !Complex waveform + complex c(0:NZ-1) !Complex waveform + real xnoise(0:NZ-1) !Generated random noise + real ynoise(0:NZ-1) !Generated random noise + real rxdata(2*ND),llr(2*ND) !Soft symbols + real s(0:NSPS,NN) + real savg(0:NSPS) + real ps(0:3) + integer id(ND) !Symbol values (0-3), data only + integer id1(ND) !Recovered data values + integer*1 msgbits(KK),decoded(KK),apmask(ND),cw(ND) + data msgbits/0,0,1,0,0,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,1, & + 1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,1,1,0,1,0,1,1,1,0,1,1,0,1,1, & + 1,1,0,1,0,1,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0/ + + nargs=iargc() + if(nargs.ne.5) then + print*,'Usage: fsk4hf f0(Hz) delay(ms) fspread(Hz) iters snr(dB)' + print*,'Example: fsk4hf 20 0 0 10 -20' + print*,'Set snr=0 to cycle through a range' + go to 999 + endif + call getarg(1,arg) + read(arg,*) f0 !Generated carrier frequency + call getarg(2,arg) + read(arg,*) delay !Delta_t (ms) for Watterson model + call getarg(3,arg) + read(arg,*) fspread !Fspread (Hz) for Watterson model + call getarg(4,arg) + read(arg,*) iters !Iterations at each SNR + call getarg(5,arg) + read(arg,*) snrdb !Specified SNR_2500 + + twopi=8.0*atan(1.0) + fs=12000.0/84.0 !Sample rate = 142.857... Hz + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + baud=1.0/tt !Keying rate for "itone" symbols (baud) + txt=NZ*dt !Transmission length (s) + bandwidth_ratio=2500.0/(fs/2.0) + write(*,1000) f0,delay,fspread,iters,baud,4*baud,txt +1000 format('f0:',f5.1,' Delay:',f4.1,' fSpread:',f5.2, & + ' Iters:',i6/'Baud:',f7.3,' BW:',f5.1,' TxT:',f5.1,f5.2/) + write(*,1004) +1004 format(/' SNR sym bit ser ber fer fsigma'/50('-')) + + call genfsk4hf(msgbits,f0,id,c0) !Generate baseband waveform + isna=-10 + isnb=-30 + if(snrdb.ne.0.0) then + isna=nint(snrdb) + isnb=isna + endif + do isnr=isna,isnb,-1 !Loop over SNR range + snrdb=isnr + sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + nhard=0 + nbit=0 + nfe=0 + sqf=0. + do iter=1,iters !Loop over requested iterations + c=c0 + if(delay.ne.0.0 .or. fspread.ne.0.0) then + call watterson(c,NZ,fs,delay,fspread) + endif + c=sig*c !Scale to requested SNR + if(snrdb.lt.90) then + do i=0,NZ-1 !Generate gaussian noise + xnoise(i)=gran() + ynoise(i)=gran() + enddo + c=c + cmplx(xnoise,ynoise) !Add AWGN noise + endif + df=fs/(2*NSPS) + i0=nint(f0/df) + call spec4(c,s,savg) + do i=0,NSPS + write(12,3001) i*df,savg(i),db(savg(i)) +3001 format(3f15.3) + enddo + + do j=1,ND + nlo=0 + nhi=0 + k=j+5 + if(j.ge.43) k=j+9 + ps=s(i0:i0+6:2,k) + ps=sqrt(ps) !### + rlo=max(ps(1),ps(3))-max(ps(0),ps(2)) + rhi=max(ps(2),ps(3))-max(ps(0),ps(1)) + if(rlo.ge.0.0) nlo=1 + if(rhi.ge.0.0) nhi=1 + rxdata(2*j-1)=rhi + rxdata(2*j)=rlo + id1(j)=2*nhi+nlo + enddo +! write(*,1001) id(1:70) +! write(*,1001) id1(1:70) +!1001 format(70i1) + nhard=nhard+count(id.ne.id1) + nbit=nbit + count(iand(id,1).ne.iand(id1,1)) + & + count(iand(id,2).ne.iand(id1,2)) + + rxav=sum(rxdata)/ND + rx2av=sum(rxdata*rxdata)/ND + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + ss=0.84 + llr=2.0*rxdata/(ss*ss) + apmask=0 + max_iterations=40 + ifer=0 + call bpdecode168(llr,apmask,max_iterations,decoded,niterations,cw) + nbadcrc=0 + if(niterations.ge.0) call chkcrc12(decoded,nbadcrc) + if(niterations.lt.0 .or. count(msgbits.ne.decoded).gt.0 .or. & + nbadcrc.ne.0) ifer=1 + nfe=nfe+ifer + enddo + + fsigma=sqrt(sqf/iters) + ser=float(nhard)/(ND*iters) + ber=float(nbit)/(2*ND*iters) + fer=float(nfe)/iters + write(*,1050) snrdb,nhard,nbit,ser,ber,fer,fsigma +! write(60,1050) snrdb,nhard,ber,fer,fsigma +1050 format(f6.1,2i6,2f8.4,f7.3,f8.2) + enddo + +999 end program fsk4hf diff --git a/lib/fsk4hf/fsk4sim.f90 b/lib/fsk4hf/fsk4sim.f90 new file mode 100644 index 00000000..9800616e --- /dev/null +++ b/lib/fsk4hf/fsk4sim.f90 @@ -0,0 +1,185 @@ +program fsk4sim + + parameter (ND=60) !Data symbols: LDPC (120,60), r=1/2 + parameter (NN=ND) !Total symbols (60) + parameter (NSPS=57600) !Samples per symbol at 12000 sps + parameter (NZ=NSPS*NN) !Samples in waveform (3456000) + + character*8 arg + complex c(0:NZ-1) !Complex waveform + complex cr(0:NZ-1) + complex cs(NSPS,NN) + complex cps(0:3) + complex ct(0:2*NN-1) + complex z,w,zsum + real r(0:NZ-1) + real s(NSPS,NN) + real savg(NSPS) + real tmp(NN) !For generating random data + real xnoise(0:NZ-1) !Generated random noise + real ps(0:3) + integer id(NN) !Encoded 2-bit data (values 0-3) + integer id2(NN) !Recovered data + equivalence (r,cr) + + nnn=0 + nargs=iargc() + if(nargs.ne.6) then + print*,'Usage: fsk8sim f0 delay(ms) fspread(Hz) nts iters snr(dB)' + go to 999 + endif + call getarg(1,arg) + read(arg,*) f0 !Low tone frequency + call getarg(2,arg) + read(arg,*) delay + call getarg(3,arg) + read(arg,*) fspread + call getarg(4,arg) + read(arg,*) nts + call getarg(5,arg) + read(arg,*) iters + call getarg(6,arg) + read(arg,*) snrdb + + twopi=8.d0*atan(1.d0) + fs=12000.d0 + dt=1.0/fs + ts=NSPS*dt + baud=1.d0/ts + txt=NZ*dt + bandwidth_ratio=2500.0/6000.0 + write(*,1000) baud,5*baud,txt,delay,fspread,nts +1000 format('Baud:',f6.3,' BW:',f5.1,' TxT:',f5.1,' Delay:',f5.2, & + ' fSpread:',f5.2,' nts:',i3/) + + write(*,1004) +1004 format(' SNR Sym Bit SER BER Sym Bit SER BER'/59('-')) + + isna=-25 + isnb=-40 + if(snrdb.ne.0.0) then + isna=nint(snrdb) + isnb=isna + endif + do isnr=isna,isnb,-1 + snrdb=isnr + sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + nhard1=0 + nhard2=0 + nbit1=0 + nbit2=0 + nh2=0 + nb2=0 + do iter=1,iters + nnn=nnn+1 + id=0 + call random_number(tmp) + where(tmp.ge.0.25 .and. tmp.lt.0.50) id=1 + where(tmp.ge.0.50 .and. tmp.lt.0.75) id=2 + where(tmp.ge.0.75) id=3 + + call genfsk4(id,f0,nts,c) !Generate the 4-FSK waveform + call watterson(c,delay,fspread) + if(sig.ne.1.0) c=sig*c !Scale to requested SNR + if(snrdb.lt.90) then + do i=0,NZ-1 !Generate gaussian noise + xnoise(i)=gran() + enddo + endif + r(0:NZ-1)=real(c(0:NZ-1)) + xnoise !Add noise to signal + + call snr2_wsprlf(r,freq,snr2500,width,1) + write(*,3001) freq,snr2500,width +3001 format(40x,3f10.3) + + df=12000.0/(2*NSPS) +! i0=nint(f0/df) +! i0=nint((1500.0+freq)/df) + i0=nint((f0+freq)/df) + call spec4(r,cs,s,savg) + + do j=1,NN + nlo=0 + nhi=0 + ps=s(i0:i0+6*nts:2*nts,j) + cps=cs(i0:i0+6*nts:2*nts,j) + if(max(ps(1),ps(3)).ge.max(ps(0),ps(2))) nlo=1 + if(max(ps(2),ps(3)).ge.max(ps(0),ps(1))) nhi=1 + id2(j)=2*nhi+nlo + z=cps(id2(j)) + ct(j-1)=z + enddo + nh1=count(id.ne.id2) + nb1=count(iand(id,1).ne.iand(id2,1)) + count(iand(id,2).ne.iand(id2,2)) + + ct(NN:)=0. + call four2a(ct,2*NN,1,-1,1) + df2=baud/(2*NN) + ct=cshift(ct,NN) + ppmax=0. + dfpk=0. + do i=0,2*NN-1 + f=(i-NN)*df2 + pp=real(ct(i))**2 + aimag(ct(i))**2 + if(pp.gt.ppmax) then + ppmax=pp + dfpk=f + endif + enddo + + zsum=0. + do j=1,NN + phi=(j-1)*twopi*dfpk*ts + w=cmplx(cos(phi),sin(phi)) + cps=cs(i0:i0+6*nts:2*nts,j)*conjg(w) + z=cps(id2(j)) + ct(j)=z + zsum=zsum+z + write(12,1042) j,id(j),id2(j),20*ps,atan2(aimag(z),real(z)), & + atan2(aimag(zsum),real(zsum)),zsum +1042 format(3i2,6f8.3,2f8.1) + enddo + + phi0=atan2(aimag(zsum),real(zsum)) + zsum=0. + do j=1,NN + phi=(j-1)*twopi*dfpk*ts + phi0 + w=cmplx(cos(phi),sin(phi)) + nlo=0 + nhi=0 + cps=cs(i0:i0+6*nts:2*nts,j)*conjg(w) + ps=real(cps) + if(max(ps(1),ps(3)).ge.max(ps(0),ps(2))) nlo=1 + if(max(ps(2),ps(3)).ge.max(ps(0),ps(1))) nhi=1 + id2(j)=2*nhi+nlo + z=cps(id2(j)) + ct(j)=z + zsum=zsum+z + enddo + + nh2=count(id.ne.id2) + nb2=count(iand(id,1).ne.iand(id2,1)) + count(iand(id,2).ne.iand(id2,2)) + nhard1=nhard1+nh1 + nhard2=nhard2+nh2 + nbit1=nbit1+nb1 + nbit2=nbit2+nb2 + + fdiff=1500.0+freq - f0 + write(13,1040) snrdb,snr2500,f0,fdiff,width,nh1,nb1,nh2,nb2 +1040 format(2f7.1,f9.2,f7.2,f6.1,2(i8,i6)) +40 continue + enddo + + ser1=float(nhard1)/(NN*iters) + ser2=float(nhard2)/(NN*iters) + ber1=float(nbit1)/(2*NN*iters) + ber2=float(nbit2)/(2*NN*iters) + write(*,1050) snrdb,nhard1,nbit1,ser1,ber1,nhard2,nbit2,ser2,ber2 + write(14,1050) snrdb,nhard1,nbit1,ser1,ber1,nhard2,nbit2,ser2,ber2 +1050 format(f6.1,2(2i5,2f8.4)) + enddo + write(*,1060) NN*iters,2*NN*iters +1060 format(59('-')/'Max: ',2i5) + +999 end program fsk4sim diff --git a/lib/fsk4hf/ft8_downsample.f90 b/lib/fsk4hf/ft8_downsample.f90 new file mode 100644 index 00000000..79191416 --- /dev/null +++ b/lib/fsk4hf/ft8_downsample.f90 @@ -0,0 +1,42 @@ +subroutine ft8_downsample(dd,newdat,f0,c1) + +! Downconvert to complex data sampled at 200 Hz ==> 32 samples/symbol + + parameter (NMAX=15*12000,NSPS=1920) + parameter (NFFT1=192000,NFFT2=3200) !192000/60 = 3200 + + logical newdat + complex c1(0:NFFT2-1) + complex cx(0:NFFT1/2) + real dd(NMAX),x(NFFT1) + equivalence (x,cx) + save cx + + if(newdat) then +! Data in dd have changed, recompute the long FFT + x(1:NMAX)=dd + x(NMAX+1:NFFT1)=0. !Zero-pad the x array + call four2a(cx,NFFT1,1,-1,0) !r2c FFT to freq domain + newdat=.false. + endif + + df=12000.0/NFFT1 + baud=12000.0/NSPS + i0=nint(f0/df) + ft=f0+8.0*baud + it=min(nint(ft/df),NFFT1/2) + fb=f0-1.0*baud + ib=max(1,nint(fb/df)) + k=0 + c1=0. + do i=ib,it + c1(k)=cx(i) + k=k+1 + enddo + c1=cshift(c1,i0-ib) + call four2a(c1,NFFT2,1,1,1) !c2c FFT back to time domain + fac=1.0/sqrt(float(NFFT1)*NFFT2) + c1=fac*c1 + + return +end subroutine ft8_downsample diff --git a/lib/fsk4hf/ft8_params.f90 b/lib/fsk4hf/ft8_params.f90 new file mode 100644 index 00000000..858e61e9 --- /dev/null +++ b/lib/fsk4hf/ft8_params.f90 @@ -0,0 +1,12 @@ +! LDPC (174,87) code +parameter (KK=87) !Information bits (75 + CRC12) +parameter (ND=58) !Data symbols +parameter (NS=21) !Sync symbols (3 @ Costas 7x7) +parameter (NN=NS+ND) !Total channel symbols (79) +parameter (NSPS=1920) !Samples per symbol at 12000 S/s +parameter (NZ=NSPS*NN) !Samples in full 15 s waveform (151,680) +parameter (NMAX=15*12000) !Samples in iwave (180,000) +parameter (NFFT1=2*NSPS, NH1=NFFT1/2) !Length of FFTs for symbol spectra +parameter (NSTEP=NSPS/4) !Rough time-sync step size +parameter (NHSYM=NMAX/NSTEP-3) !Number of symbol spectra (1/4-sym steps) +parameter (NDOWN=60) !Downsample factor diff --git a/lib/fsk4hf/ft8apset.f90 b/lib/fsk4hf/ft8apset.f90 new file mode 100644 index 00000000..ca5e5a6d --- /dev/null +++ b/lib/fsk4hf/ft8apset.f90 @@ -0,0 +1,31 @@ +subroutine ft8apset(mycall12,mygrid6,hiscall12,hisgrid6,bcontest,apsym,iaptype) + parameter(NAPM=4,KK=87) + character*12 mycall12,hiscall12 + character*22 msg,msgsent + character*6 mycall,hiscall + character*6 mygrid6,hisgrid6 + character*4 hisgrid + logical bcontest + integer apsym(KK) + integer*1 msgbits(KK) + integer itone(KK) + + mycall=mycall12(1:6) + hiscall=hiscall12(1:6) + hisgrid=hisgrid6(1:4) + if(len_trim(hiscall).eq.0) then + iaptype=1 + hiscall="K9AN" + else + iaptype=2 + endif + hisgrid=hisgrid6(1:4) +! if(len_trim(hisgrid).eq.0) hisgrid="EN50" + if(index(hisgrid," ").eq.0) hisgrid="EN50" + msg=mycall//' '//hiscall//' '//hisgrid + i3bit=0 ! ### TEMPORARY ??? ### + call genft8(msg,mygrid6,bcontest,i3bit,msgsent,msgbits,itone) + apsym=2*msgbits-1 + + return +end subroutine ft8apset diff --git a/lib/fsk4hf/ft8b.f90 b/lib/fsk4hf/ft8b.f90 new file mode 100644 index 00000000..3049dfd4 --- /dev/null +++ b/lib/fsk4hf/ft8b.f90 @@ -0,0 +1,437 @@ +subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,napwid, & + lsubtract,nagain,iaptype,mygrid6,bcontest,sync0,f1,xdt,xbase,apsym, & + nharderrors,dmin,nbadcrc,ipass,iera,message,xsnr) + + use timer_module, only: timer + include 'ft8_params.f90' + parameter(NRECENT=10,NP2=2812) + character message*22,msgsent*22 + character*12 recent_calls(NRECENT) + character*6 mygrid6 + logical bcontest + real a(5) + real s1(0:7,ND),s2(0:7,NN),s1sort(8*ND) + real ps(0:7),psl(0:7) + real bmeta(3*ND),bmetb(3*ND),bmetap(3*ND) + real llr(3*ND),llra(3*ND),llr0(3*ND),llr1(3*ND),llrap(3*ND) !Soft symbols + real dd0(15*12000) + integer*1 decoded(KK),apmask(3*ND),cw(3*ND) + integer*1 msgbits(KK) + integer apsym(KK) + integer mcq(28),mde(28),mrrr(16),m73(16),mrr73(16) + integer itone(NN) + integer indxs1(8*ND) + integer icos7(0:6),ip(1) + integer nappasses(0:5) ! the number of decoding passes to use for each QSO state + integer naptypes(0:5,4) ! (nQSOProgress, decoding pass) maximum of 4 passes for now + complex cd0(3200) + complex ctwk(32) + complex csymb(32) + logical first,newdat,lsubtract,lapon,nagain + equivalence (s1,s1sort) + data icos7/2,5,6,0,4,1,3/ + data mcq/1,1,1,1,1,0,1,0,0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,1,1,0,0,1/ + data mrrr/0,1,1,1,1,1,1,0,1,1,0,0,1,1,1,1/ + data m73/0,1,1,1,1,1,1,0,1,1,0,1,0,0,0,0/ + data mde/1,1,1,1,1,1,1,1,0,1,1,0,0,1,0,0,0,0,0,1,1,1,0,1,0,0,0,1/ + data mrr73/0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,1/ + data first/.true./ + save nappasses,naptypes + + if(first) then + mcq=2*mcq-1 + mde=2*mde-1 + mrrr=2*mrrr-1 + m73=2*m73-1 + mrr73=2*mrr73-1 + nappasses(0)=2 + nappasses(1)=2 + nappasses(2)=2 + nappasses(3)=4 + nappasses(4)=4 + nappasses(5)=3 + +! iaptype +!------------------------ +! 1 CQ ??? ??? +! 2 MyCall ??? ??? +! 3 MyCall DxCall ??? +! 4 MyCall DxCall RRR +! 5 MyCall DxCall 73 +! 6 MyCall DxCall RR73 +! 7 ??? DxCall ??? + + naptypes(0,1:4)=(/1,2,0,0/) + naptypes(1,1:4)=(/2,3,0,0/) + naptypes(2,1:4)=(/2,3,0,0/) + naptypes(3,1:4)=(/3,4,5,6/) + naptypes(4,1:4)=(/3,4,5,6/) + naptypes(5,1:4)=(/3,1,2,0/) !? + first=.false. + endif + + max_iterations=30 + nharderrors=-1 + fs2=12000.0/NDOWN + dt2=1.0/fs2 + twopi=8.0*atan(1.0) + delfbest=0. + ibest=0 + + call timer('ft8_down',0) + call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal + smax=0.0 + do idt=i0-8,i0+8 !Search over +/- one quarter symbol + call sync8d(cd0,idt,ctwk,0,sync) + if(sync.gt.smax) then + smax=sync + ibest=idt + endif + enddo + xdt2=ibest*dt2 !Improved estimate for DT + +! Now peak up in frequency + i0=nint(xdt2*fs2) + smax=0.0 + do ifr=-5,5 !Search over +/- 2.5 Hz + delf=ifr*0.5 + dphi=twopi*delf*dt2 + phi=0.0 + do i=1,32 + ctwk(i)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + enddo + call sync8d(cd0,i0,ctwk,1,sync) + if( sync .gt. smax ) then + smax=sync + delfbest=delf + endif + enddo + a=0.0 + a(1)=-delfbest + call twkfreq1(cd0,NP2,fs2,a,cd0) + xdt=xdt2 + f1=f1+delfbest !Improved estimate of DF + + call sync8d(cd0,i0,ctwk,2,sync) + + j=0 + do k=1,NN + i1=ibest+(k-1)*32 + csymb=cmplx(0.0,0.0) + if( i1.ge.1 .and. i1+31 .le. NP2 ) csymb=cd0(i1:i1+31) + call four2a(csymb,32,1,-1,1) + s2(0:7,k)=abs(csymb(1:8))/1e3 + enddo + +! sync quality check + is1=0 + is2=0 + is3=0 + do k=1,7 + ip=maxloc(s2(:,k)) + if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s2(:,k+36)) + if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s2(:,k+72)) + if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 + enddo +! hard sync sum - max is 21 + nsync=is1+is2+is3 + if(nsync .le. 6) then ! bail out + nbadcrc=1 + return + endif + + j=0 + do k=1,NN + if(k.le.7) cycle + if(k.ge.37 .and. k.le.43) cycle + if(k.gt.72) cycle + j=j+1 + s1(0:7,j)=s2(0:7,k) + enddo + + call indexx(s1sort,8*ND,indxs1) + xmeds1=s1sort(indxs1(nint(0.5*8*ND))) + s1=s1/xmeds1 + + do j=1,ND + i4=3*j-2 + i2=3*j-1 + i1=3*j +! Max amplitude + ps=s1(0:7,j) + r1=max(ps(1),ps(3),ps(5),ps(7))-max(ps(0),ps(2),ps(4),ps(6)) + r2=max(ps(2),ps(3),ps(6),ps(7))-max(ps(0),ps(1),ps(4),ps(5)) + r4=max(ps(4),ps(5),ps(6),ps(7))-max(ps(0),ps(1),ps(2),ps(3)) + bmeta(i4)=r4 + bmeta(i2)=r2 + bmeta(i1)=r1 + bmetap(i4)=r4 + bmetap(i2)=r2 + bmetap(i1)=r1 +! Max log metric + psl=log(ps) + r1=max(psl(1),psl(3),psl(5),psl(7))-max(psl(0),psl(2),psl(4),psl(6)) + r2=max(psl(2),psl(3),psl(6),psl(7))-max(psl(0),psl(1),psl(4),psl(5)) + r4=max(psl(4),psl(5),psl(6),psl(7))-max(psl(0),psl(1),psl(2),psl(3)) + bmetb(i4)=r4 + bmetb(i2)=r2 + bmetb(i1)=r1 + +! Metric for Cauchy noise +! r1=log(ps(1)**3+ps(3)**3+ps(5)**3+ps(7)**3)- & +! log(ps(0)**3+ps(2)**3+ps(4)**3+ps(6)**3) +! r2=log(ps(2)**3+ps(3)**3+ps(6)**3+ps(7)**3)- & +! log(ps(0)**3+ps(1)**3+ps(4)**3+ps(5)**3) +! r4=log(ps(4)**3+ps(5)**3+ps(6)**3+ps(7)**3)- & +! log(ps(0)**3+ps(1)**3+ps(2)**3+ps(3)**3) +! Metric for AWGN, no fading +! bscale=2.5 +! b0=bessi0(bscale*ps(0)) +! b1=bessi0(bscale*ps(1)) +! b2=bessi0(bscale*ps(2)) +! b3=bessi0(bscale*ps(3)) +! b4=bessi0(bscale*ps(4)) +! b5=bessi0(bscale*ps(5)) +! b6=bessi0(bscale*ps(6)) +! b7=bessi0(bscale*ps(7)) +! r1=log(b1+b3+b5+b7)-log(b0+b2+b4+b6) +! r2=log(b2+b3+b6+b7)-log(b0+b1+b4+b5) +! r4=log(b4+b5+b6+b7)-log(b0+b1+b2+b3) + + if(nQSOProgress .eq. 0 .or. nQSOProgress .eq. 5) then +! When bits 88:115 are set as ap bits, bit 115 lives in symbol 39 along +! with no-ap bits 116 and 117. Take care of metrics for bits 116 and 117. + if(j.eq.39) then ! take care of bits that live in symbol 39 + if(apsym(28).lt.0) then + bmetap(i2)=max(ps(2),ps(3))-max(ps(0),ps(1)) + bmetap(i1)=max(ps(1),ps(3))-max(ps(0),ps(2)) + else + bmetap(i2)=max(ps(6),ps(7))-max(ps(4),ps(5)) + bmetap(i1)=max(ps(5),ps(7))-max(ps(4),ps(6)) + endif + endif + endif + +! When bits 116:143 are set as ap bits, bit 115 lives in symbol 39 along +! with ap bits 116 and 117. Take care of metric for bit 115. +! if(j.eq.39) then ! take care of bit 115 +! iii=2*(apsym(29)+1)/2 + (apsym(30)+1)/2 ! known values of bits 116 & 117 +! if(iii.eq.0) bmetap(i4)=ps(4)-ps(0) +! if(iii.eq.1) bmetap(i4)=ps(5)-ps(1) +! if(iii.eq.2) bmetap(i4)=ps(6)-ps(2) +! if(iii.eq.3) bmetap(i4)=ps(7)-ps(3) +! endif + +! bit 144 lives in symbol 48 and will be 1 if it is set as an ap bit. +! take care of metrics for bits 142 and 143 + if(j.eq.48) then ! bit 144 is always 1 + bmetap(i4)=max(ps(5),ps(7))-max(ps(1),ps(3)) + bmetap(i2)=max(ps(3),ps(7))-max(ps(1),ps(5)) + endif + +! bit 154 lives in symbol 52 and will be 0 if it is set as an ap bit +! take care of metrics for bits 155 and 156 + if(j.eq.52) then ! bit 154 will be 0 if it is set as an ap bit. + bmetap(i2)=max(ps(2),ps(3))-max(ps(0),ps(1)) + bmetap(i1)=max(ps(1),ps(3))-max(ps(0),ps(2)) + endif + + enddo + + call normalizebmet(bmeta,3*ND) + call normalizebmet(bmetb,3*ND) + call normalizebmet(bmetap,3*ND) + + scalefac=2.83 + llr0=scalefac*bmeta + llr1=scalefac*bmetb + llra=scalefac*bmetap ! llr's for use with ap + apmag=scalefac*(maxval(abs(bmetap))*1.01) + +! pass # +!------------------------------ +! 1 regular decoding +! 2 erase 24 +! 3 erase 48 +! 4 ap pass 1 +! 5 ap pass 2 +! 6 ap pass 3 +! 7 ap pass 4, etc. + + if(lapon) then + npasses=4+nappasses(nQSOProgress) + else + npasses=4 + endif + + do ipass=1,npasses + + llr=llr0 + if(ipass.eq.2) llr=llr1 + if(ipass.eq.3) llr(1:24)=0. + if(ipass.eq.4) llr(1:48)=0. + if(ipass.le.4) then + apmask=0 + llrap=llr + iaptype=0 + endif + + if(ipass .gt. 4) then + iaptype=naptypes(nQSOProgress,ipass-4) + if(iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid .and. abs(f1-nftx).gt.napwid) ) cycle + if(iaptype.eq.1 .or. iaptype.eq.2 ) then ! AP,???,??? + apmask=0 + apmask(88:115)=1 ! first 28 bits are AP + apmask(144)=1 ! not free text + llrap=llr + if(iaptype.eq.1) llrap(88:115)=apmag*mcq + if(iaptype.eq.2) llrap(88:115)=apmag*apsym(1:28) + llrap(116:117)=llra(116:117) + llrap(142:143)=llra(142:143) + llrap(144)=-apmag + endif + if(iaptype.eq.3) then ! mycall, dxcall, ??? + apmask=0 + apmask(88:115)=1 ! mycall + apmask(116:143)=1 ! hiscall + apmask(144)=1 ! not free text + llrap=llr + llrap(88:143)=apmag*apsym(1:56) + llrap(144)=-apmag + endif + if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then + apmask=0 + apmask(88:115)=1 ! mycall + apmask(116:143)=1 ! hiscall + apmask(144:159)=1 ! RRR or 73 or RR73 + llrap=llr + llrap(88:143)=apmag*apsym(1:56) + if(iaptype.eq.4) llrap(144:159)=apmag*mrrr + if(iaptype.eq.5) llrap(144:159)=apmag*m73 + if(iaptype.eq.6) llrap(144:159)=apmag*mrr73 + endif + if(iaptype.eq.7) then ! ???, dxcall, ??? + apmask=0 + apmask(116:143)=1 ! hiscall + apmask(144)=1 ! not free text + llrap=llr + llrap(115)=llra(115) + llrap(116:143)=apmag*apsym(29:56) + llrap(144)=-apmag + endif + endif + + cw=0 + call timer('bpd174 ',0) + call bpdecode174(llrap,apmask,max_iterations,decoded,cw,nharderrors, & + niterations) + call timer('bpd174 ',1) + dmin=0.0 + if(ndepth.eq.3 .and. nharderrors.lt.0) then + ndeep=3 + if(abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid) then + if((ipass.eq.3 .or. ipass.eq.4) .and. .not.nagain) then + ndeep=3 + else + ndeep=4 + endif + endif + if(nagain) ndeep=5 + call timer('osd174 ',0) + call osd174(llrap,apmask,ndeep,decoded,cw,nharderrors,dmin) + call timer('osd174 ',1) + endif + nbadcrc=1 + message=' ' + xsnr=-99.0 + if(count(cw.eq.0).eq.174) cycle !Reject the all-zero codeword +!### if(any(decoded(73:75).ne.0)) cycle !Reject if any of the 3 extra bits is nonzero + if(nharderrors.ge.0 .and. nharderrors+dmin.lt.60.0 .and. & + .not.(sync.lt.2.0 .and. nharderrors.gt.35) .and. & + .not.(ipass.gt.2 .and. nharderrors.gt.39) .and. & + .not.(ipass.eq.4 .and. nharderrors.gt.30) & + ) then + call chkcrc12a(decoded,nbadcrc) + else + nharderrors=-1 + cycle + endif +!### + i3bit=4*decoded(73) + 2*decoded(74) + decoded(75) + iFreeText=decoded(57) +! if(nbadcrc.eq.0) write(*,3001) nharderrors,nbadcrc,i3bit +!3001 format('A',3i5) +!### + if(nbadcrc.eq.0) then + call extractmessage174(decoded,message,ncrcflag,recent_calls,nrecent) + call genft8(message,mygrid6,bcontest,i3bit,msgsent,msgbits,itone) + if(i3bit.eq.1 .and. iFreeText.eq.0) message(21:21)='1' + if(i3bit.eq.2 .and. iFreeText.eq.0) message(21:21)='2' + if(lsubtract) call subtractft8(dd0,itone,f1,xdt2) + xsig=0.0 + xnoi=0.0 + do i=1,79 + xsig=xsig+s2(itone(i),i)**2 + ios=mod(itone(i)+4,7) + xnoi=xnoi+s2(ios,i)**2 + enddo + xsnr=0.001 + if(xnoi.gt.0 .and. xnoi.lt.xsig) xsnr=xsig/xnoi-1.0 + xsnr=10.0*log10(xsnr)-27.0 + xsnr2=db(xsig/xbase - 1.0) - 32.0 +! write(52,3052) f1,xdt,xsig,xnoi,xbase,xsnr,xsnr2 +!3052 format(7f10.2) + if(.not.nagain) xsnr=xsnr2 + if(xsnr .lt. -24.0) xsnr=-24.0 + return + endif + enddo + + return +end subroutine ft8b + +subroutine normalizebmet(bmet,n) + real bmet(n) + + bmetav=sum(bmet)/real(n) + bmet2av=sum(bmet*bmet)/real(n) + var=bmet2av-bmetav*bmetav + if( var .gt. 0.0 ) then + bmetsig=sqrt(var) + else + bmetsig=sqrt(bmet2av) + endif + bmet=bmet/bmetsig + return +end subroutine normalizebmet + + +function bessi0(x) +! From Numerical Recipes + real bessi0,x + double precision p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9,y + save p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9 + data p1,p2,p3,p4,p5,p6,p7/1.0d0,3.5156229d0,3.0899424d0,1.2067492d0, & + 0.2659732d0,0.360768d-1,0.45813d-2/ + data q1,q2,q3,q4,q5,q6,q7,q8,q9/0.39894228d0,0.1328592d-1, & + 0.225319d-2,-0.157565d-2,0.916281d-2,-0.2057706d-1, & + 0.2635537d-1,-0.1647633d-1,0.392377d-2/ + + if (abs(x).lt.3.75) then + y=(x/3.75)**2 + bessi0=p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7))))) + else + ax=abs(x) + y=3.75/ax + bessi0=(exp(ax)/sqrt(ax))*(q1+y*(q2+y*(q3+y*(q4 & + +y*(q5+y*(q6+y*(q7+y*(q8+y*q9)))))))) + endif + return +end function bessi0 + diff --git a/lib/fsk4hf/ft8d.f90 b/lib/fsk4hf/ft8d.f90 new file mode 100644 index 00000000..daee7b2b --- /dev/null +++ b/lib/fsk4hf/ft8d.f90 @@ -0,0 +1,63 @@ +program ft8d + +! Decode FT8 data read from *.wav files. + + include 'ft8_params.f90' + character*12 arg + character infile*80,datetime*13,message*22 + real s(NH1,NHSYM) + real candidate(3,100) + integer ihdr(11) + integer*2 iwave(NMAX) !Generated full-length waveform + real dd(NMAX) + + nargs=iargc() + if(nargs.lt.3) then + print*,'Usage: ft8d MaxIt Norder file1 [file2 ...]' + print*,'Example ft8d 40 2 *.wav' + go to 999 + endif + call getarg(1,arg) + read(arg,*) max_iterations + call getarg(2,arg) + read(arg,*) norder + nfiles=nargs-2 + + twopi=8.0*atan(1.0) + fs=12000.0 !Sample rate + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + ts=2*NSPS*dt !Duration of OQPSK symbols (s) + baud=1.0/tt !Keying rate (baud) + txt=NZ*dt !Transmission length (s) + nfa=100.0 + nfb=3000.0 + nfqso=1500.0 + + do ifile=1,nfiles + call getarg(ifile+2,infile) + open(10,file=infile,status='old',access='stream') + read(10,end=999) ihdr,iwave + close(10) + j2=index(infile,'.wav') + read(infile(j2-6:j2-1),*) nutc + datetime=infile(j2-13:j2-1) + call sync8(iwave,nfa,nfb,nfqso,s,candidate,ncand) + syncmin=2.0 + dd=iwave + do icand=1,ncand + sync=candidate(3,icand) + if( sync.lt.syncmin) cycle + f1=candidate(1,icand) + xdt=candidate(2,icand) + nsnr=min(99,nint(10.0*log10(sync)-25.5)) + call ft8b(dd,nfqso,f1,xdt,nharderrors,dmin,nbadcrc,message,xsnr) + nsnr=xsnr + xdt=xdt-0.6 + write(*,1110) datetime,0,nsnr,xdt,f1,message,nharderrors,dmin +1110 format(a13,2i4,f6.2,f7.1,' ~ ',a22,i6,f7.1) + enddo + enddo ! ifile loop + +999 end program ft8d + diff --git a/lib/fsk4hf/ft8sim.f90 b/lib/fsk4hf/ft8sim.f90 new file mode 100644 index 00000000..70d67a81 --- /dev/null +++ b/lib/fsk4hf/ft8sim.f90 @@ -0,0 +1,126 @@ +program ft8sim + +! Generate simulated data for a 15-second HF/6m mode using 8-FSK. +! Output is saved to a *.wav file. + + use wavhdr + include 'ft8_params.f90' !Set various constants + type(hdr) h !Header for .wav file + character arg*12,fname*17,sorm*1 + character msg*22,msgsent*22 + character*6 mygrid6 + logical bcontest + complex c0(0:NMAX-1) + complex c(0:NMAX-1) + integer itone(NN) + integer*1 msgbits(KK) + integer*2 iwave(NMAX) !Generated full-length waveform + data mygrid6/'EM48 '/ + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.8) then + print*,'Usage: ft8sim "message" s|m f0 DT fdop del nfiles snr' + print*,'Example: ft8sim "K1ABC W9XYZ EN37" m 1500.0 0.0 0.1 1.0 10 -18' + print*,'s|m: "s" for single signal at 1500 Hz, "m" for 25 signals' + print*,'f0 is ignored when sorm = m' + print*,'Make nfiles negative to invoke 72-bit contest mode.' + go to 999 + endif + call getarg(1,msg) !Message to be transmitted + call getarg(2,sorm) !s for single signal, m for multiple sigs + if(sorm.eq."s") then + print*,"Generating single signal at 1500 Hz." + nsig=1 + elseif( sorm.eq."m") then + print*,"Generating 25 signals per file." + nsig=25 + else + print*,"sorm parameter must be s (single) or m (multiple)." + goto 999 + endif + call getarg(3,arg) + read(arg,*) f0 !Frequency (only used for single-signal) + call getarg(4,arg) + read(arg,*) xdt !Time offset from nominal (s) + call getarg(5,arg) + read(arg,*) fspread !Watterson frequency spread (Hz) + call getarg(6,arg) + read(arg,*) delay !Watterson delay (ms) + call getarg(7,arg) + read(arg,*) nfiles !Number of files + call getarg(8,arg) + read(arg,*) snrdb !SNR_2500 + + bcontest=nfiles.lt.0 + nfiles=abs(nfiles) + twopi=8.0*atan(1.0) + fs=12000.0 !Sample rate (Hz) + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of symbols (s) + baud=1.0/tt !Keying rate (baud) + bw=8*baud !Occupied bandwidth (Hz) + txt=NZ*dt !Transmission length (s) + bandwidth_ratio=2500.0/(fs/2.0) + sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + txt=NN*NSPS/12000.0 + i3bit=0 ! ### TEMPORARY ??? ### + +! Source-encode, then get itone() + call genft8(msg,mygrid6,bcontest,i3bit,msgsent,msgbits,itone) + write(*,1000) f0,xdt,txt,snrdb,bw,msgsent +1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1, & + ' BW:',f4.1,2x,a22) + +write(*,'(28i1,1x,28i1)') msgbits(1:56) +write(*,'(16i1)') msgbits(57:72) +write(*,'(3i1)') msgbits(73:75) +write(*,'(12i1)') msgbits(76:87) + +! call sgran() + do ifile=1,nfiles + c=0. + do isig=1,nsig + c0=0. + if(nsig.eq.25) then + f0=(isig+2)*100.0 + endif + k=-1 + nint((xdt+0.5+0.01*gran())/dt) +! k=-1 + nint((xdt+0.5)/dt) + phi=0.0 + do j=1,NN !Generate complex waveform + dphi=twopi*(f0+itone(j)*baud)*dt + do i=1,NSPS + k=k+1 + phi=mod(phi+dphi,twopi) + if(k.ge.0 .and. k.lt.NMAX) c0(k)=cmplx(cos(phi),sin(phi)) + enddo + enddo + if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c0,NMAX,fs,delay,fspread) + c=c+sig*c0 + enddo + if(snrdb.lt.90) then + do i=0,NMAX-1 !Add gaussian noise at specified SNR + xnoise=gran() + ynoise=gran() + c(i)=c(i) + cmplx(xnoise,ynoise) + enddo + endif + + fac=32767.0 + rms=100.0 + if(snrdb.ge.90.0) iwave(1:NMAX)=nint(fac*real(c)) + if(snrdb.lt.90.0) iwave(1:NMAX)=nint(rms*real(c)) + + h=default_header(12000,NMAX) + write(fname,1102) ifile +1102 format('000000_',i6.6,'.wav') + open(10,file=fname,status='unknown',access='stream') + write(10) h,iwave !Save to *.wav file + close(10) + write(*,1110) ifile,xdt,f0,snrdb,fname +1110 format(i4,f7.2,f8.2,f7.1,2x,a17) + enddo + +999 end program ft8sim diff --git a/lib/fsk4hf/genbpsk.f90 b/lib/fsk4hf/genbpsk.f90 new file mode 100644 index 00000000..6c283e72 --- /dev/null +++ b/lib/fsk4hf/genbpsk.f90 @@ -0,0 +1,44 @@ +subroutine genbpsk(id,f00,ndiff,nref,c) + + parameter (ND=121) !Data symbols: LDPC (120,60), r=1/2 + parameter (NN=ND) !Total symbols (121) + parameter (NSPS=28800) !Samples per symbol at 12000 sps + parameter (NZ=NSPS*NN) !Samples in waveform (3456000) + + complex c(0:NZ-1) !Complex waveform + real*8 twopi,dt,fs,baud,f0,dphi,phi + integer id(NN) !Encoded NRZ data (values +/-1) + integer ie(NN) !Differentially encoded data + + f0=f00 + twopi=8.d0*atan(1.d0) + fs=12000.d0 + dt=1.0/fs + baud=1.d0/(NSPS*dt) + + if(ndiff.ne.0) then + ie(1)=1 !First bit is always 1 + do i=2,NN !Differentially encode + ie(i)=id(i)*ie(i-1) + enddo + endif + +! Generate the BPSK waveform + phi=0.d0 + k=-1 + do j=1,NN + dphi=twopi*f0*dt + x=id(j) + if(ndiff.ne.0) x=ie(j) !Differential + if(nref.ne.0) x=1.0 !Generate reference carrier + do i=1,NSPS + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + c(k)=x*cmplx(cos(xphi),sin(xphi)) + enddo + enddo + + return +end subroutine genbpsk diff --git a/lib/fsk4hf/genfsk4.f90 b/lib/fsk4hf/genfsk4.f90 new file mode 100644 index 00000000..d8b0394b --- /dev/null +++ b/lib/fsk4hf/genfsk4.f90 @@ -0,0 +1,36 @@ +subroutine genfsk4(id,f00,nts,c) + + parameter (ND=60) !Data symbols: LDPC (120,60), r=1/2 + parameter (NN=ND) !Total symbols (60) + parameter (NSPS=57600) !Samples per symbol at 12000 sps + parameter (NZ=NSPS*NN) !Samples in waveform (3456000) + parameter (NFFT=NZ) !Full length FFT + + complex c(0:NFFT-1) !Complex waveform + real*8 twopi,dt,fs,baud,f0,dphi,phi + integer id(NN) !Encoded 2-bit data (values 0-3) + + f0=f00 + twopi=8.d0*atan(1.d0) + fs=12000.d0 + dt=1.0/fs + baud=1.d0/(NSPS*dt) + +! Generate the 4-FSK waveform + x=0. + c=0. + phi=0.d0 + k=-1 + do j=1,NN + dphi=twopi*(f0 + nts*id(j)*baud)*dt + do i=1,NSPS + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + c(k)=cmplx(cos(xphi),sin(xphi)) + enddo + enddo + + return +end subroutine genfsk4 diff --git a/lib/fsk4hf/genfsk4hf.f90 b/lib/fsk4hf/genfsk4hf.f90 new file mode 100644 index 00000000..924e9793 --- /dev/null +++ b/lib/fsk4hf/genfsk4hf.f90 @@ -0,0 +1,51 @@ +subroutine genfsk4hf(msgbits,f0,id,c) + + parameter (KK=84) !Information bits (72 + CRC12) + parameter (ND=84) !Data symbols: LDPC (168,84), r=1/2 + parameter (NS=12) !Sync symbols (3 @ 4x4 Costas arrays) + parameter (NR=2) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (98) + parameter (NSPS=2688/84) !Samples per symbol (32) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (3136) + + complex c(0:NZ-1) !Complex waveform + integer id0(NN) !2-bit data (values 0-3), all symbols + integer id(ND) !2-bit data (values 0-3), data only + integer*1 msgbits(KK),codeword(2*ND) + integer icos4(4) !4x4 Costas array + data icos4/0,1,3,2/ + + twopi=8.0*atan(1.0) + fs=12000.0/84.0 + dt=1.0/fs + baud=1.0/(NSPS*dt) + call encode168(msgbits,codeword) !Encode the test message + id0(1)=0 !Ramp-up + id0(2:5)=icos4 !First Costas array + id0(48:51)=icos4 !Second + id0(94:97)=icos4 !Third + id0(98)=0 !Ramp down + j=5 + do i=1,84 !Data symbols + id(i)=2*codeword(2*i-1) + codeword(2*i) + j=j+1 + if(i.eq.43) j=j+4 + id0(j)=id(i) + enddo + +! Generate the 4-FSK waveform, low tone at f=0 + c=0. + phi=0.d0 + k=-1 + do j=1,NN + dphi=twopi*(f0+id0(j)*baud)*dt + do i=1,NSPS + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + c(k)=cmplx(cos(phi),sin(phi)) + enddo + enddo + + return +end subroutine genfsk4hf diff --git a/lib/fsk4hf/genft8.f90 b/lib/fsk4hf/genft8.f90 new file mode 100644 index 00000000..899dad3e --- /dev/null +++ b/lib/fsk4hf/genft8.f90 @@ -0,0 +1,56 @@ +subroutine genft8(msg,mygrid,bcontest,i3bit,msgsent,msgbits,itone) + +! Encode an FT8 message, producing array itone(). + + use crc + use packjt + include 'ft8_params.f90' + character*22 msg,msgsent + character*6 mygrid + character*87 cbits + logical bcontest + integer*4 i4Msg6BitWords(12) !72-bit message as 6-bit words + integer*1 msgbits(KK),codeword(3*ND) + integer*1, target:: i1Msg8BitBytes(11) + integer itone(NN) + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ !Costas 7x7 tone pattern + + call packmsg(msg,i4Msg6BitWords,itype,bcontest) !Pack into 12 6-bit bytes + call unpackmsg(i4Msg6BitWords,msgsent,bcontest,mygrid) !Unpack to get msgsent + + write(cbits,1000) i4Msg6BitWords,32*i3bit +1000 format(12b6.6,b8.8) + read(cbits,1001) i1Msg8BitBytes(1:10) +1001 format(10b8) + i1Msg8BitBytes(10)=iand(i1Msg8BitBytes(10),128+64+32) + i1Msg8BitBytes(11)=0 + icrc12=crc12(c_loc(i1Msg8BitBytes),11) + +! For reference, here's how to check the CRC +! i1Msg8BitBytes(10)=icrc12/256 +! i1Msg8BitBytes(11)=iand (icrc12,255) +! checksumok = crc12_check(c_loc (i1Msg8BitBytes), 11) +! if( checksumok ) write(*,*) 'Good checksum' + + write(cbits,1003) i4Msg6BitWords,i3bit,icrc12 +1003 format(12b6.6,b3.3,b12.12) + read(cbits,1004) msgbits +1004 format(87i1) + + call encode174(msgbits,codeword) !Encode the test message + +! Message structure: S7 D29 S7 D29 S7 + itone(1:7)=icos7 + itone(36+1:36+7)=icos7 + itone(NN-6:NN)=icos7 + k=7 + do j=1,ND + i=3*j -2 + k=k+1 + if(j.eq.30) k=k+7 + itone(k)=codeword(i)*4 + codeword(i+1)*2 + codeword(i+2) + enddo + + return +end subroutine genft8 diff --git a/lib/fsk4hf/genft8refsig.f90 b/lib/fsk4hf/genft8refsig.f90 new file mode 100644 index 00000000..5bf4885c --- /dev/null +++ b/lib/fsk4hf/genft8refsig.f90 @@ -0,0 +1,22 @@ +subroutine genft8refsig(itone,cref,f0) + complex cref(79*1920) + integer itone(79) + real*8 twopi,phi,dphi,dt,xnsps + data twopi/0.d0/ + save twopi + if( twopi .lt. 0.1 ) twopi=8.d0*atan(1.d0) + + xnsps=1920.d0 + dt=1.d0/12000.d0 + phi=0.d0 + k=1 + do i=1,79 + dphi=twopi*(f0*dt+itone(i)/xnsps) + do is=1,1920 + cref(k)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + k=k+1 + enddo + enddo + return +end subroutine genft8refsig diff --git a/lib/fsk4hf/genmskhf.f90 b/lib/fsk4hf/genmskhf.f90 new file mode 100644 index 00000000..7d4b0838 --- /dev/null +++ b/lib/fsk4hf/genmskhf.f90 @@ -0,0 +1,126 @@ +subroutine genmskhf(msgbits,id,icw,cbb,csync) + +!Encode an MSK-HF message, produce baseband waveform and sync vector. + + parameter (KK=84) !Information bits (72 + CRC12) + parameter (ND=168) !Data symbols: LDPC (168,84), r=1/2 + parameter (NS=65) !Sync symbols (2 x 26 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (236) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (3760) + + complex cbb(0:NZ-1) + complex csync(0:NZ-1) + real x(0:NZ-1) + real y(0:NZ-1) + real pp(N2) + logical first + integer*1 msgbits(KK),codeword(ND) + integer icw(ND) + integer id(NS+ND) + integer isync(26) !Long sync vector + integer ib13(13) !Barker 13 code + data ib13/1,1,1,1,1,-1,-1,1,1,-1,1,-1,1/ + data first/.true./ + save first,isync,twopi,pp + + if(first) then + n=z'2c1aeb1' + do i=1,26 + isync(i)=-1 + if(iand(n,1).eq.1) isync(i)=1 + n=n/2 + enddo + + twopi=8.0*atan(1.0) + do i=1,N2 !Half-sine shaped pulse + pp(i)=sin(0.5*(i-1)*twopi/N2) + enddo + first=.false. + endif + + call encode168(msgbits,codeword) !Encode the test message + icw=2*codeword - 1 + +! Message structure: R1 26*(S1+D1) S13 26*(D1+S1) R1 +! Generate QPSK without any offset; then shift the y array to get OQPSK. + +! Do the I channel first: results in array x + n=0 + k=0 + ia=0 + ib=NSPS-1 + x(ia:ib)=0. !Ramp up (half-symbol; shape TBD) + do j=1,26 !Insert group of 26*(S1+D1) + ia=ib+1 + ib=ia+N2-1 + n=n+1 + id(n)=2*isync(j) + x(ia:ib)=isync(j)*pp !Insert Sync bit + ia=ib+1 + ib=ia+N2-1 + k=k+1 + n=n+1 + id(n)=icw(k) + x(ia:ib)=id(n)*pp !Insert data bit + enddo + + do j=1,13 !Insert Barker 13 code + ia=ib+1 + ib=ia+N2-1 + n=n+1 + id(n)=2*ib13(j) + x(ia:ib)=ib13(j)*pp + enddo + + do j=1,26 !Insert group of 26*(S1+D1) + ia=ib+1 + ib=ia+N2-1 + k=k+1 + n=n+1 + id(n)=icw(k) + x(ia:ib)=id(n)*pp !Insert data bit + ia=ib+1 + ib=ia+N2-1 + n=n+1 + id(n)=2*isync(j) + x(ia:ib)=isync(j)*pp !Insert Sync bit + enddo + ia=ib+1 + ib=ia+NSPS-1 + x(ia:ib)=0. !Ramp down (half-symbol; shape TBD) + +! Now do the Q channel: results in array y + ia=0 + ib=NSPS-1 + y(ia:ib)=0. !Ramp up (half-symbol; shape TBD) + do j=1,116 + ia=ib+1 + ib=ia+N2-1 + k=k+1 + n=n+1 + id(n)=icw(k) + y(ia:ib)=id(n)*pp + enddo + ia=ib+1 + ib=ia+NSPS-1 + y(ia:ib)=0. !Ramp down (half-symbol; shape TBD) + y=cshift(y,-NSPS) !Shift Q array to get OQPSK + cbb=cmplx(x,y) !Complex baseband waveform + + ib=NSPS-1 + ib2=NSPS-1+64*N2 + do j=1,26 !Zero all data symbols in x + ia=ib+1+N2 + ib=ia+N2-1 + x(ia:ib)=0. + ia2=ib2+1+N2 + ib2=ia2+N2-1 + x(ia2:ib2)=0. + enddo + csync=x + + return +end subroutine genmskhf diff --git a/lib/fsk4hf/genwspr5.f90 b/lib/fsk4hf/genwspr5.f90 new file mode 100644 index 00000000..9385a8e1 --- /dev/null +++ b/lib/fsk4hf/genwspr5.f90 @@ -0,0 +1,107 @@ +subroutine genwspr5(msg,msgsent,itone) + +! Encode a WSPR-LF message, producing array itone(). + + use crc + include 'wsprlf_params.f90' + + character*22 msg,msgsent + character*60 cbits + integer*1,target :: idat(9) + integer*1 msgbits(KK),codeword(ND) + logical first + integer icw(ND) + integer id(NS+ND) + integer jd(NS+ND) + integer isync(48) !Long sync vector + integer ib13(13) !Barker 13 code + integer itone(NN) + integer*8 n8 + data ib13/1,1,1,1,1,-1,-1,1,1,-1,1,-1,1/ + data first/.true./ + save first,isync + + if(first) then + n8=z'cbf089223a51' + do i=1,48 + isync(i)=-1 + if(iand(n8,1).eq.1) isync(i)=1 + n8=n8/2 + enddo + first=.false. + endif + + idat=0 + call wqencode(msg,ntype0,idat) !Source encoding + id7=idat(7) + if(id7.lt.0) id7=id7+256 + id7=id7/64 + icrc=crc10(c_loc(idat),9) !Compute the 10-bit CRC + idat(8)=icrc/256 !Insert CRC into idat(8:9) + idat(9)=iand(icrc,255) + call wqdecode(idat,msgsent,itype) + + write(cbits,1004) idat(1:6),id7,icrc +1004 format(6b8.8,b2.2,b10.10) + read(cbits,1006) msgbits +1006 format(60i1) + +! call chkcrc10(msgbits,nbadcrc) +! print*,msgsent,itype,crc10_check(c_loc(idat),9),nbadcrc + + call encode300(msgbits,codeword) !Encode the test message + icw=2*codeword - 1 !NRZ codeword + +! Message structure: +! I channel: R1 48*(S1+D1) S13 48*(D1+S1) R1 +! Q channel: R1 D109 R1 +! Generate QPSK with no offset, then shift the y array to get OQPSK. + +! I channel: + n=0 + k=0 + do j=1,48 !Insert group of 48*(S1+D1) + n=n+1 + id(n)=2*isync(j) + k=k+1 + n=n+1 + id(n)=icw(k) + enddo + + do j=1,13 !Insert Barker 13 code + n=n+1 + id(n)=2*ib13(j) + enddo + + do j=1,48 !Insert group of 48*(S1+D1) + k=k+1 + n=n+1 + id(n)=icw(k) + n=n+1 + id(n)=2*isync(j) + enddo + +! Q channel + do j=1,204 + k=k+1 + n=n+1 + id(n)=icw(k) + enddo + +! Map I and Q to tones. + n=0 + jz=(NS+ND+1)/2 + do j=1,jz-1 + jd(2*j-1)=id(j)/abs(id(j)) + jd(2*j)=id(j+jz)/abs(id(j+jz)) + enddo + jd(NS+ND)=id(jz)/abs(id(jz)) + itone=0 + do j=1,jz-1 + itone(2*j+1)=(jd(2*j)*jd(2*j-1)+1)/2; + itone(2*j+2)=-(jd(2*j)*jd(2*j+1)-1)/2; + enddo + itone(NS+ND+2)=jd(NS+ND) !### Is this correct ??? ### + + return +end subroutine genwspr5 diff --git a/lib/fsk4hf/genwspr_fsk8.f90 b/lib/fsk4hf/genwspr_fsk8.f90 new file mode 100644 index 00000000..2ef6ace3 --- /dev/null +++ b/lib/fsk4hf/genwspr_fsk8.f90 @@ -0,0 +1,45 @@ +subroutine genwspr_fsk8(msg,msgsent,itone) + +! Encode a WSPR-LF 8-FSK message, producing array itone(). + + use crc + include 'wspr_fsk8_params.f90' + + character*22 msg,msgsent + character*60 cbits + integer*1,target :: idat(9) + integer*1 msgbits(KK),codeword(3*ND) + integer itone(NN) + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ !Costas 7x7 tone pattern + + idat=0 + call wqencode(msg,ntype0,idat) !Source encoding + id7=idat(7) + if(id7.lt.0) id7=id7+256 + id7=id7/64 + icrc=crc10(c_loc(idat),9) !Compute the 10-bit CRC + idat(8)=icrc/256 !Insert CRC into idat(8:9) + idat(9)=iand(icrc,255) + call wqdecode(idat,msgsent,itype) + + write(cbits,1004) idat(1:6),id7,icrc +1004 format(6b8.8,b2.2,b10.10) + read(cbits,1006) msgbits +1006 format(60i1) + +! call chkcrc10(msgbits,nbadcrc) +! print*,msgsent,itype,crc10_check(c_loc(idat),9),nbadcrc + + call encode300(msgbits,codeword) !Encode the test message + +! Message structure: S7 D100 S7 + itone(1:7)=icos7 + itone(NN-6:NN)=icos7 + do j=1,ND + i=3*j -2 + itone(j+7)=codeword(i)*4 + codeword(i+1)*2 + codeword(i+2) + enddo + + return +end subroutine genwspr_fsk8 diff --git a/lib/fsk4hf/genwsprlf.f90 b/lib/fsk4hf/genwsprlf.f90 new file mode 100644 index 00000000..4c5b31cf --- /dev/null +++ b/lib/fsk4hf/genwsprlf.f90 @@ -0,0 +1,137 @@ +subroutine genwsprlf(msgbits,id,icw,cbb,csync,itone) + +!Encode a WSPR-LF message, produce baseband waveform and sync vector. + + include 'wsprlf_params.f90' + + complex cbb(0:NZ-1) + complex csync(0:NZ-1) + real x(0:NZ-1) + real y(0:NZ-1) + real pp(N2) + logical first + integer*1 msgbits(KK),codeword(ND) + integer icw(ND) + integer id(NS+ND) + integer jd(NS+ND) + integer isync(48) !Long sync vector + integer ib13(13) !Barker 13 code + integer itone(NN) + integer*8 n8 + data ib13/1,1,1,1,1,-1,-1,1,1,-1,1,-1,1/ + data first/.true./ + save first,isync,twopi,pp + + if(first) then + n8=z'cbf089223a51' + do i=1,48 + isync(i)=-1 + if(iand(n8,1).eq.1) isync(i)=1 + n8=n8/2 + enddo + + twopi=8.0*atan(1.0) + do i=1,N2 !Half-sine shaped pulse + pp(i)=sin(0.5*(i-1)*twopi/N2) + enddo + first=.false. + endif + + call encode300(msgbits,codeword) !Encode the test message + icw=2*codeword - 1 + +! Message structure: R1 48*(S1+D1) S13 48*(D1+S1) R1 +! Generate QPSK without any offset; then shift the y array to get OQPSK. + +! Do the I channel first: results in array x + n=0 + k=0 + ia=0 + ib=NSPS-1 + x(ia:ib)=0. !Ramp up (half-symbol; shape TBD) + do j=1,48 !Insert group of 48*(S1+D1) + ia=ib+1 + ib=ia+N2-1 + n=n+1 + id(n)=2*isync(j) + x(ia:ib)=isync(j)*pp !Insert Sync bit + ia=ib+1 + ib=ia+N2-1 + k=k+1 + n=n+1 + id(n)=icw(k) + x(ia:ib)=id(n)*pp !Insert data bit + enddo + + do j=1,13 !Insert Barker 13 code + ia=ib+1 + ib=ia+N2-1 + n=n+1 + id(n)=2*ib13(j) + x(ia:ib)=ib13(j)*pp + enddo + + do j=1,48 !Insert group of 48*(S1+D1) + ia=ib+1 + ib=ia+N2-1 + k=k+1 + n=n+1 + id(n)=icw(k) + x(ia:ib)=id(n)*pp !Insert data bit + ia=ib+1 + ib=ia+N2-1 + n=n+1 + id(n)=2*isync(j) + x(ia:ib)=isync(j)*pp !Insert Sync bit + enddo + ia=ib+1 + ib=ia+NSPS-1 + x(ia:ib)=0. !Ramp down (half-symbol; shape TBD) + +! Now do the Q channel: results in array y + ia=0 + ib=NSPS-1 + y(ia:ib)=0. !Ramp up (half-symbol; shape TBD) + do j=1,204 + ia=ib+1 + ib=ia+N2-1 + k=k+1 + n=n+1 + id(n)=icw(k) + y(ia:ib)=id(n)*pp + enddo + ia=ib+1 + ib=ia+NSPS-1 + y(ia:ib)=0. !Ramp down (half-symbol; shape TBD) + y=cshift(y,-NSPS) !Shift Q array to get OQPSK + cbb=cmplx(x,y) !Complex baseband waveform + + ib=NSPS-1 + ib2=NSPS-1+64*N2 + do j=1,48 !Zero all data symbols in x + ia=ib+1+N2 + ib=ia+N2-1 + x(ia:ib)=0. + ia2=ib2+1+N2 + ib2=ia2+N2-1 + x(ia2:ib2)=0. + enddo + csync=x + +! Map I and Q to tones. + n=0 + jz=(NS+ND+1)/2 + do j=1,jz-1 + jd(2*j-1)=id(j)/abs(id(j)) + jd(2*j)=id(j+jz)/abs(id(j+jz)) + enddo + jd(NS+ND)=id(jz)/abs(id(jz)) + itone=0 + do j=1,jz-1 + itone(2*j-1)=(jd(2*j)*jd(2*j-1)+1)/2; + itone(2*j)=-(jd(2*j)*jd(2*j+1)-1)/2; + enddo + itone(NS+ND)=jd(NS+ND) !### Is this correct ??? ### + + return +end subroutine genwsprlf diff --git a/lib/fsk4hf/getfc1.f90 b/lib/fsk4hf/getfc1.f90 new file mode 100644 index 00000000..b82b0303 --- /dev/null +++ b/lib/fsk4hf/getfc1.f90 @@ -0,0 +1,58 @@ +subroutine getfc1(c,fc1) + + parameter (KK=84) !Information bits (72 + CRC12) + parameter (ND=168) !Data symbols: LDPC (168,84), r=1/2 + parameter (NS=65) !Sync symbols (2 x 26 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (236) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (3760) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + + complex c(0:NZ-1) !Complex waveform + complex c2(0:NFFT1-1) !Short spectra + real s(-NH1+1:NH1) !Coarse spectrum + + nspec=NZ/NFFT1 + fs=12000.0/72.0 + df1=fs/NFFT1 + s=0. + do k=1,nspec + ia=(k-1)*N2 + ib=ia+N2-1 + c2(0:N2-1)=c(ia:ib) + c2(N2:)=0. + call four2a(c2,NFFT1,1,-1,1) + do i=0,NFFT1-1 + j=i + if(j.gt.NH1) j=j-NFFT1 + s(j)=s(j) + real(c2(i))**2 + aimag(c2(i))**2 + enddo + enddo +! call smo121(s,NFFT1) + smax=0. + ipk=0 + fc1=0. + ia=nint(40.0/df1) + do i=-ia,ia + f=i*df1 + if(s(i).gt.smax) then + smax=s(i) + ipk=i + fc1=f + endif +! write(51,3001) f,s(i),db(s(i)) +! 3001 format(f10.3,e12.3,f10.3) + enddo + +! The following is for testing SNR calibration: +! sp3n=(s(ipk-1)+s(ipk)+s(ipk+1)) !Sig + 3*noise +! base=(sum(s)-sp3n)/(NFFT1-3.0) !Noise per bin +! psig=sp3n-3*base !Sig only +! pnoise=(2500.0/df1)*base !Noise in 2500 Hz +! xsnrdb=db(psig/pnoise) + + return +end subroutine getfc1 diff --git a/lib/fsk4hf/getfc1w.f90 b/lib/fsk4hf/getfc1w.f90 new file mode 100644 index 00000000..532b9837 --- /dev/null +++ b/lib/fsk4hf/getfc1w.f90 @@ -0,0 +1,47 @@ +subroutine getfc1w(c,fs,fa,fb,fc1,xsnr) + + include 'wsprlf_params.f90' + complex c(0:NZ-1) !Complex waveform + complex c2(0:NFFT1-1) !Short spectra + real s(-NH1+1:NH1) !Coarse spectrum + nspec=NZ/NFFT1 + df1=fs/NFFT1 + s=0. + do k=1,nspec + ia=(k-1)*N2 + ib=ia+N2-1 + c2(0:N2-1)=c(ia:ib) + c2(N2:)=0. + call four2a(c2,NFFT1,1,-1,1) + do i=0,NFFT1-1 + j=i + if(j.gt.NH1) j=j-NFFT1 + s(j)=s(j) + real(c2(i))**2 + aimag(c2(i))**2 + enddo + enddo +! call smo121(s,NFFT1) + smax=0. + ipk=0 + fc1=0. + ia=nint(fa/df1) + ib=nint(fb/df1) + do i=ia,ib + f=i*df1 + if(s(i).gt.smax) then + smax=s(i) + ipk=i + fc1=f + endif +! write(51,3001) f,s(i),db(s(i)) +! 3001 format(f10.3,e12.3,f10.3) + enddo + +! The following is for testing SNR calibration: + sp3n=(s(ipk-1)+s(ipk)+s(ipk+1)) !Sig + 3*noise + base=(sum(s)-sp3n)/(NFFT1-3.0) !Noise per bin + psig=sp3n-3*base !Sig only + pnoise=(2500.0/df1)*base !Noise in 2500 Hz + xsnr=db(psig/pnoise) + + return +end subroutine getfc1w diff --git a/lib/fsk4hf/getfc2.f90 b/lib/fsk4hf/getfc2.f90 new file mode 100644 index 00000000..9506168d --- /dev/null +++ b/lib/fsk4hf/getfc2.f90 @@ -0,0 +1,74 @@ +subroutine getfc2(c,csync,fc1,fc2,fc3) + + parameter (KK=84) !Information bits (72 + CRC12) + parameter (ND=168) !Data symbols: LDPC (168,84), r=1/2 + parameter (NS=65) !Sync symbols (2 x 26 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (236) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (3760) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + + complex c(0:NZ-1) !Complex waveform + complex cs(0:NZ-1) !For computing spectrum + complex csync(0:NZ-1) !Sync symbols only, from cbb + real a(5) + + fs=12000.0/72.0 + df=fs/NZ + baud=fs/NSPS + a(1)=-fc1 + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,cs) !Mix down by fc1 + +! Filter, square, then FFT to get refined carrier frequency fc2. + call four2a(cs,NZ,1,-1,1) !To freq domain + ia=nint(0.75*baud/df) + cs(ia:NZ-1-ia)=0. !Save only freqs around fc1 + call four2a(cs,NZ,1,1,1) !Back to time domain + cs=cs/NZ + cs=cs*cs !Square the data + call four2a(cs,NZ,1,-1,1) !Compute squared spectrum + +! Find two peaks separated by baud + pmax=0. + fc2=0. + ic=nint(baud/df) + ja=nint(0.5*baud/df) + do j=-ja,ja + f2=j*df + ia=nint((f2-0.5*baud)/df) + if(ia.lt.0) ia=ia+NZ + ib=nint((f2+0.5*baud)/df) + p=real(cs(ia))**2 + aimag(cs(ia))**2 + & + real(cs(ib))**2 + aimag(cs(ib))**2 + if(p.gt.pmax) then + pmax=p + fc2=0.5*f2 + endif +! write(52,1200) f2,p,db(p) +!1200 format(f10.3,2f15.3) + enddo + + a(1)=-fc1 + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,cs) !Mix down by fc1 + cs=cs*conjg(csync) + call four2a(cs,NZ,1,-1,1) !To freq domain + pmax=0. + do i=0,NZ-1 + f=i*df + if(i.gt.NZ/2) f=(i-NZ)*df + p=real(cs(i))**2 + aimag(cs(i))**2 +! write(51,3001) f,p,db(p) +!3001 format(f10.3,e12.3,f10.3) + if(p.gt.pmax) then + pmax=p + fc3=f + endif + enddo + + return +end subroutine getfc2 diff --git a/lib/fsk4hf/getfc2w.f90 b/lib/fsk4hf/getfc2w.f90 new file mode 100644 index 00000000..0d100ee5 --- /dev/null +++ b/lib/fsk4hf/getfc2w.f90 @@ -0,0 +1,82 @@ +subroutine getfc2w(c,csync,npeaks,fs,fc1,fpks) + + include 'wsprlf_params.f90' + + complex c(0:NZ-1) !Complex waveform + complex cs(0:NZ-1) !For computing spectrum + complex csync(0:NZ-1) !Sync symbols only, from cbb + real a(5) + real freqs(413),sp2(413),fpks(npeaks) + integer pkloc(1) + + df=fs/NZ + baud=fs/NSPS + a(1)=-fc1 + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,cs) !Mix down by fc1 + +! Filter, square, then FFT to get refined carrier frequency fc2. + call four2a(cs,NZ,1,-1,1) !To freq domain + + ia=nint(0.75*baud/df) + cs(ia:NZ-1-ia)=0. !Save only freqs around fc1 + call four2a(cs,NZ,1,1,1) !Back to time domain + cs=cs/NZ + cs=cs*cs !Square the data + call four2a(cs,NZ,1,-1,1) !Compute squared spectrum + +! Find two peaks separated by baud + pmax=0. + fc2=0. + ja=nint(0.3*baud/df) + k=1 + do j=-ja,ja + f2=j*df + ia=nint((f2-0.5*baud)/df) + if(ia.lt.0) ia=ia+NZ + ib=nint((f2+0.5*baud)/df) + p=real(cs(ia))**2 + aimag(cs(ia))**2 + & + real(cs(ib))**2 + aimag(cs(ib))**2 + if(p.gt.pmax) then + pmax=p + fc2=0.5*f2 + endif + freqs(k)=0.5*f2 + sp2(k)=p + k=k+1 +! write(52,1200) f2,p,db(p) +!1200 format(f10.3,2f15.3) + enddo + + do i=1,npeaks + pkloc=maxloc(sp2) + ipk=pkloc(1) + fpks(i)=freqs(ipk) + ipk0=max(1,ipk-1) + ipk1=min(413,ipk+1) +! ipk0=ipk +! ipk1=ipk + sp2(ipk0:ipk1)=0.0 +!write(*,*) i,fpks(i),fc2 + enddo + + a(1)=-fc1 + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,cs) !Mix down by fc1 + cs=cs*conjg(csync) + call four2a(cs,NZ,1,-1,1) !To freq domain + pmax=0. + do i=0,NZ-1 + f=i*df + if(i.gt.NZ/2) f=(i-NZ)*df + p=real(cs(i))**2 + aimag(cs(i))**2 +! write(51,3001) f,p,db(p) +!3001 format(f10.3,e12.3,f10.3) + if(p.gt.pmax) then + pmax=p + fc3=f + endif + enddo + + return +end subroutine getfc2w diff --git a/lib/fsk4hf/gran.c b/lib/fsk4hf/gran.c new file mode 100644 index 00000000..24b98650 --- /dev/null +++ b/lib/fsk4hf/gran.c @@ -0,0 +1,28 @@ +#include +#include + +/* Generate gaussian random float with mean=0 and std_dev=1 */ +float gran_() +{ + float fac,rsq,v1,v2; + static float gset; + static int iset; + + if(iset){ + /* Already got one */ + iset = 0; + return gset; + } + /* Generate two evenly distributed numbers between -1 and +1 + * that are inside the unit circle + */ + do { + v1 = 2.0 * (float)rand() / RAND_MAX - 1; + v2 = 2.0 * (float)rand() / RAND_MAX - 1; + rsq = v1*v1 + v2*v2; + } while(rsq >= 1.0 || rsq == 0.0); + fac = sqrt(-2.0*log(rsq)/rsq); + gset = v1*fac; + iset++; + return v2*fac; +} diff --git a/lib/fsk4hf/ldpc_174_87_params.f90 b/lib/fsk4hf/ldpc_174_87_params.f90 new file mode 100644 index 00000000..35af9b81 --- /dev/null +++ b/lib/fsk4hf/ldpc_174_87_params.f90 @@ -0,0 +1,102 @@ +integer, parameter:: N=174, K=87, M=N-K +character*22 g(87) +integer colorder(N) +data g/ & !parity generator matrix for (174,87) code +"23bba830e23b6b6f50982e", & +"1f8e55da218c5df3309052", & +"ca7b3217cd92bd59a5ae20", & +"56f78313537d0f4382964e", & +"29c29dba9c545e267762fe", & +"6be396b5e2e819e373340c", & +"293548a138858328af4210", & +"cb6c6afcdc28bb3f7c6e86", & +"3f2a86f5c5bd225c961150", & +"849dd2d63673481860f62c", & +"56cdaec6e7ae14b43feeee", & +"04ef5cfa3766ba778f45a4", & +"c525ae4bd4f627320a3974", & +"fe37802941d66dde02b99c", & +"41fd9520b2e4abeb2f989c", & +"40907b01280f03c0323946", & +"7fb36c24085a34d8c1dbc4", & +"40fc3e44bb7d2bb2756e44", & +"d38ab0a1d2e52a8ec3bc76", & +"3d0f929ef3949bd84d4734", & +"45d3814f504064f80549ae", & +"f14dbf263825d0bd04b05e", & +"f08a91fb2e1f78290619a8", & +"7a8dec79a51e8ac5388022", & +"ca4186dd44c3121565cf5c", & +"db714f8f64e8ac7af1a76e", & +"8d0274de71e7c1a8055eb0", & +"51f81573dd4049b082de14", & +"d037db825175d851f3af00", & +"d8f937f31822e57c562370", & +"1bf1490607c54032660ede", & +"1616d78018d0b4745ca0f2", & +"a9fa8e50bcb032c85e3304", & +"83f640f1a48a8ebc0443ea", & +"eca9afa0f6b01d92305edc", & +"3776af54ccfbae916afde6", & +"6abb212d9739dfc02580f2", & +"05209a0abb530b9e7e34b0", & +"612f63acc025b6ab476f7c", & +"0af7723161ec223080be86", & +"a8fc906976c35669e79ce0", & +"45b7ab6242b77474d9f11a", & +"b274db8abd3c6f396ea356", & +"9059dfa2bb20ef7ef73ad4", & +"3d188ea477f6fa41317a4e", & +"8d9071b7e7a6a2eed6965e", & +"a377253773ea678367c3f6", & +"ecbd7c73b9cd34c3720c8a", & +"b6537f417e61d1a7085336", & +"6c280d2a0523d9c4bc5946", & +"d36d662a69ae24b74dcbd8", & +"d747bfc5fd65ef70fbd9bc", & +"a9fa2eefa6f8796a355772", & +"cc9da55fe046d0cb3a770c", & +"f6ad4824b87c80ebfce466", & +"cc6de59755420925f90ed2", & +"164cc861bdd803c547f2ac", & +"c0fc3ec4fb7d2bb2756644", & +"0dbd816fba1543f721dc72", & +"a0c0033a52ab6299802fd2", & +"bf4f56e073271f6ab4bf80", & +"57da6d13cb96a7689b2790", & +"81cfc6f18c35b1e1f17114", & +"481a2a0df8a23583f82d6c", & +"1ac4672b549cd6dba79bcc", & +"c87af9a5d5206abca532a8", & +"97d4169cb33e7435718d90", & +"a6573f3dc8b16c9d19f746", & +"2c4142bf42b01e71076acc", & +"081c29a10d468ccdbcecb6", & +"5b0f7742bca86b8012609a", & +"012dee2198eba82b19a1da", & +"f1627701a2d692fd9449e6", & +"35ad3fb0faeb5f1b0c30dc", & +"b1ca4ea2e3d173bad4379c", & +"37d8e0af9258b9e8c5f9b2", & +"cd921fdf59e882683763f6", & +"6114e08483043fd3f38a8a", & +"2e547dd7a05f6597aac516", & +"95e45ecd0135aca9d6e6ae", & +"b33ec97be83ce413f9acc8", & +"c8b5dffc335095dcdcaf2a", & +"3dd01a59d86310743ec752", & +"14cd0f642fc0c5fe3a65ca", & +"3a0a1dfd7eee29c2e827e0", & +"8abdb889efbe39a510a118", & +"3f231f212055371cf3e2a2"/ +data colorder/ & + 0, 1, 2, 3, 30, 4, 5, 6, 7, 8, 9, 10, 11, 32, 12, 40, 13, 14, 15, 16,& + 17, 18, 37, 45, 29, 19, 20, 21, 41, 22, 42, 31, 33, 34, 44, 35, 47, 51, 50, 43,& + 36, 52, 63, 46, 25, 55, 27, 24, 23, 53, 39, 49, 59, 38, 48, 61, 60, 57, 28, 62,& + 56, 58, 65, 66, 26, 70, 64, 69, 68, 67, 74, 71, 54, 76, 72, 75, 78, 77, 80, 79,& + 73, 83, 84, 81, 82, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,& + 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,& + 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,& + 140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,& + 160,161,162,163,164,165,166,167,168,169,170,171,172,173/ + diff --git a/lib/fsk4hf/ldpc_300_60_params.f90 b/lib/fsk4hf/ldpc_300_60_params.f90 new file mode 100644 index 00000000..53ee994e --- /dev/null +++ b/lib/fsk4hf/ldpc_300_60_params.f90 @@ -0,0 +1,262 @@ +integer, parameter:: N=300, K=60, M=N-K +character*15 g(M) +integer colorder(N) +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/ + diff --git a/lib/fsk4hf/ldpcsim120.f90 b/lib/fsk4hf/ldpcsim120.f90 new file mode 100644 index 00000000..0b7d9286 --- /dev/null +++ b/lib/fsk4hf/ldpcsim120.f90 @@ -0,0 +1,238 @@ +program ldpcsim120 +! End to end test of the (120,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(120) +integer*1 cw(120) +integer*2 checksum +integer colorder(120) +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, & + 15,16,22,26,17,30,18,29,25,32,41,34,19,33,27,36,38,43,42,24, & + 37,39,45,40,35,44,47,46,50,51,53,48,52,56,54,57,55,49,58,61, & + 60,59,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, & + 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99, & + 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119/ + +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 10 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=120 +K=60 +! scale Eb/No for a (120,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 encode120(msgbits,codeword) + call init_random_seed() + call sgran() + + write(*,*) 'codeword' + write(*,'(15(8i1,1x))') codeword + +write(*,*) "Es/N0 SNR2500 ngood nundetected nbadcrc sigma" +do idb = -10, 24 + 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 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 +! 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(0.4166/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 ldpcsim120 diff --git a/lib/fsk4hf/ldpcsim168.f90 b/lib/fsk4hf/ldpcsim168.f90 new file mode 100644 index 00000000..a1aee3eb --- /dev/null +++ b/lib/fsk4hf/ldpcsim168.f90 @@ -0,0 +1,233 @@ +program ldpcsim168 +! End to end test of the (168,84)/crc12 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(11) +integer*1 msgbits(84) +integer*1 apmask(168), cw(168) +integer*2 checksum +integer*4 i4Msg6BitWords(13) +integer colorder(168) +integer nerrtot(168),nerrdec(168),nmpcbad(84) +logical checksumok,fsk,bpsk +real*8, allocatable :: rxdata(:) +real, allocatable :: llr(:) + +data colorder/0,1,2,3,28,4,5,6,7,8,9,10,11,34,12,32,13,14,15,16,17, & + 18,36,29,42,31,20,21,41,40,30,38,22,19,47,37,46,35,44,33,49,24, & + 43,51,25,26,27,50,52,57,69,54,55,45,59,58,56,61,60,53,48,23,62, & + 63,64,67,66,65,68,39,70,71,72,74,73,75,76,77,80,81,78,82,79,83, & + 84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104, & + 105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125, & + 126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146, & + 147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167/ + +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 10 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=168 +K=84 +! scale Eb/No for a (168,72) code +rate=real(72)/real(N) + +write(*,*) "rate: ",rate +write(*,*) "niter= ",max_iterations," s= ",s + +allocate ( codeword(N), decoded(K), message(K) ) +allocate ( rxdata(N), llr(N) ) + +! msg="K1JT K9AN EN50" + msg="G4WJS K9AN EN50" + call packmsg(msg,i4Msg6BitWords,itype,.false.) !Pack into 12 6-bit bytes + call unpackmsg(i4Msg6BitWords,msgsent,.false.,'') !Unpack to get msgsent + write(*,*) "message sent ",msgsent + + i4=0 + ik=0 + im=0 + do i=1,12 + nn=i4Msg6BitWords(i) + do j=1, 6 + ik=ik+1 + i4=i4+i4+iand(1,ishft(nn,j-6)) + i4=iand(i4,255) + if(ik.eq.8) then + im=im+1 +! if(i4.gt.127) i4=i4-256 + i1Msg8BitBytes(im)=i4 + ik=0 + endif + enddo + enddo + + i1Msg8BitBytes(10:11)=0 + checksum = crc12 (c_loc (i1Msg8BitBytes), 11) +! For reference, the next 3 lines show how to check the CRC + i1Msg8BitBytes(10)=checksum/256 + i1Msg8BitBytes(11)=iand (checksum,255) + checksumok = crc12_check(c_loc (i1Msg8BitBytes), 11) + if( checksumok ) write(*,*) 'Good checksum' + + mbit=0 + do i=1, 9 + i1=i1Msg8BitBytes(i) + do ibit=1,8 + mbit=mbit+1 + msgbits(mbit)=iand(1,ishft(i1,ibit-8)) + enddo + enddo + i1=i1Msg8BitBytes(10) ! First 4 bits of crc12 are LSB of this byte + do ibit=1,4 + msgbits(72+ibit)=iand(1,ishft(i1,ibit-4)) + enddo + i1=i1Msg8BitBytes(11) ! Now shift in last 8 bits of the CRC + do ibit=1,8 + msgbits(76+ibit)=iand(1,ishft(i1,ibit-8)) + enddo + + write(*,*) 'message' + write(*,'(11(8i1,1x))') msgbits + + call encode168(msgbits,codeword) + call init_random_seed() + call sgran() + + write(*,*) 'codeword' + write(*,'(21(8i1,1x))') codeword + +write(*,*) "Es/N0 SNR2500 ngood nundetected nbadcrc sigma" +do idb = 6,-6,-1 + db=idb/2.0-1.0 + sigma=1/sqrt( 2*(10**(db/10.0)) ) + 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) + nap=0 ! number of AP bits + llr(colorder(168-84+1:168-84+nap)+1)=5*(2.0*msgbits(1:nap)-1.0) + apmask=0 + apmask(colorder(168-84+1:168-84+nap)+1)=1 + +! max_iterations is max number of belief propagation iterations + call bpdecode168(llr, apmask, max_iterations, decoded, niterations) +! if( niterations .eq. -1 ) then +! norder=3 +! call osd168(llr, norder, decoded, niterations, cw) +! endif +! If the decoder finds a valid codeword, niterations will be .ge. 0. + if( niterations .ge. 0 ) then + call extractmessage168(decoded,msgreceived,ncrcflag,recent_calls,nrecent) + 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 + +write(37,*) niterations, ncrcflag, nueflag + nmpcbad(nerrmpc)=nmpcbad(nerrmpc)+1 + if( ncrcflag .eq. 1 ) then + if( nueflag .eq. 0 ) then + ngood=ngood+1 + nerrdec(nerr)=nerrdec(nerr)+1 + else if( nueflag .eq. 1 ) then + nue=nue+1; + endif + endif + endif + enddo + snr2500=db+10*log10(10.417/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,168 + 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,84 + write(25,'(i4,2x,i10)') i,nmpcbad(i) +enddo +close(25) + + + +end program ldpcsim168 diff --git a/lib/fsk4hf/ldpcsim174.f90 b/lib/fsk4hf/ldpcsim174.f90 new file mode 100644 index 00000000..b8640f6d --- /dev/null +++ b/lib/fsk4hf/ldpcsim174.f90 @@ -0,0 +1,238 @@ +program ldpcsim174 +! End to end test of the (174,75)/crc12 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(11) +integer*1 msgbits(87) +integer*1 apmask(174), cw(174) +integer*2 checksum +integer*4 i4Msg6BitWords(13) +integer colorder(174) +integer nerrtot(174),nerrdec(174),nmpcbad(87) +logical checksumok,fsk,bpsk +real*8, allocatable :: rxdata(:) +real, allocatable :: llr(:) + +data colorder/ & + 0, 1, 2, 3, 30, 4, 5, 6, 7, 8, 9, 10, 11, 32, 12, 40, 13, 14, 15, 16,& + 17, 18, 37, 45, 29, 19, 20, 21, 41, 22, 42, 31, 33, 34, 44, 35, 47, 51, 50, 43,& + 36, 52, 63, 46, 25, 55, 27, 24, 23, 53, 39, 49, 59, 38, 48, 61, 60, 57, 28, 62,& + 56, 58, 65, 66, 26, 70, 64, 69, 68, 67, 74, 71, 54, 76, 72, 75, 78, 77, 80, 79,& + 73, 83, 84, 81, 82, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,& + 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,& + 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,& + 140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,& + 160,161,162,163,164,165,166,167,168,169,170,171,172,173/ + +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.4) then + print*,'Usage: ldpcsim niter ndepth #trials s ' + print*,'eg: ldpcsim 10 2 1000 0.84' + print*,'belief propagation iterations: niter, ordered-statistics depth: ndepth' + 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,*) ndepth +call getarg(3,arg) +read(arg,*) ntrials +call getarg(4,arg) +read(arg,*) s + +fsk=.false. +bpsk=.true. + +! don't count crc bits as data bits +N=174 +K=87 +! scale Eb/No for a (174,87) code +rate=real(K)/real(N) + +write(*,*) "rate: ",rate +write(*,*) "niter= ",max_iterations," s= ",s + +allocate ( codeword(N), decoded(K), message(K) ) +allocate ( rxdata(N), llr(N) ) + + msg="K1JT K9AN EN50" +! msg="G4WJS K9AN EN50" + call packmsg(msg,i4Msg6BitWords,itype,.false.) !Pack into 12 6-bit bytes + call unpackmsg(i4Msg6BitWords,msgsent,.false.,'') !Unpack to get msgsent + write(*,*) "message sent ",msgsent + + i4=0 + ik=0 + im=0 + do i=1,12 + nn=i4Msg6BitWords(i) + do j=1, 6 + ik=ik+1 + i4=i4+i4+iand(1,ishft(nn,j-6)) + i4=iand(i4,255) + if(ik.eq.8) then + im=im+1 +! if(i4.gt.127) i4=i4-256 + i1Msg8BitBytes(im)=i4 + ik=0 + endif + enddo + enddo + + i1Msg8BitBytes(10:11)=0 + checksum = crc12 (c_loc (i1Msg8BitBytes), 11) +! For reference, the next 3 lines show how to check the CRC + i1Msg8BitBytes(10)=checksum/256 + i1Msg8BitBytes(11)=iand (checksum,255) + checksumok = crc12_check(c_loc (i1Msg8BitBytes), 11) + if( checksumok ) write(*,*) 'Good checksum' + +! K=87, For now: +! msgbits(1:72) JT message bits +! msgbits(73:75) 3 free message bits (set to 0) +! msgbits(76:87) CRC12 + mbit=0 + do i=1, 9 + i1=i1Msg8BitBytes(i) + do ibit=1,8 + mbit=mbit+1 + msgbits(mbit)=iand(1,ishft(i1,ibit-8)) + enddo + enddo + msgbits(73:75)=0 ! the three extra message bits go here + i1=i1Msg8BitBytes(10) ! First 4 bits of crc12 are LSB of this byte + do ibit=1,4 + msgbits(75+ibit)=iand(1,ishft(i1,ibit-4)) + enddo + i1=i1Msg8BitBytes(11) ! Now shift in last 8 bits of the CRC + do ibit=1,8 + msgbits(79+ibit)=iand(1,ishft(i1,ibit-8)) + enddo + + write(*,*) 'message' + write(*,'(11(8i1,1x))') msgbits + + call encode174(msgbits,codeword) + call init_random_seed() +! call sgran() + + write(*,*) 'codeword' + write(*,'(22(8i1,1x))') codeword + +write(*,*) "Es/N0 SNR2500 ngood nundetected nbadcrc sigma" +do idb = 20,-10,-1 +!do idb = -3,-3,-1 + db=idb/2.0-1.0 + sigma=1/sqrt( 2*(10**(db/10.0)) ) + 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) + nap=0 ! number of AP bits + llr(colorder(174-87+1:174-87+nap)+1)=5*(2.0*msgbits(1:nap)-1.0) + apmask=0 + apmask(colorder(174-87+1:174-87+nap)+1)=1 + +! max_iterations is max number of belief propagation iterations + call bpdecode174(llr, apmask, max_iterations, decoded, cw, nharderrors,niterations) + if( ndepth .ge. 0 .and. nharderrors .lt. 0 ) call osd174(llr, apmask, ndepth, decoded, cw, nharderrors, dmin) +! If the decoder finds a valid codeword, nharderrors will be .ge. 0. + if( nharderrors .ge. 0 ) then + call extractmessage174(decoded,msgreceived,ncrcflag,recent_calls,nrecent) + 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 + if( ncrcflag .eq. 1 ) then + if( nueflag .eq. 0 ) then + ngood=ngood+1 + nerrdec(nerr)=nerrdec(nerr)+1 + else if( nueflag .eq. 1 ) then + nue=nue+1; + endif + endif + endif + enddo + baud=12000/1920 + snr2500=db+10.0*log10((baud/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,174 + 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,87 + write(25,'(i4,2x,i10)') i,nmpcbad(i) +enddo +close(25) + +end program ldpcsim174 diff --git a/lib/fsk4hf/ldpcsim300.f90 b/lib/fsk4hf/ldpcsim300.f90 new file mode 100644 index 00000000..d8a17759 --- /dev/null +++ b/lib/fsk4hf/ldpcsim300.f90 @@ -0,0 +1,252 @@ +program ldpcsim300 + +! End-to-end test of the (300,60)/crc10 encoder and decoders. + +use crc +use packjt + +parameter(NRECENT=10) +character*12 recent_calls(NRECENT) +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 = 20,-16,-1 +!do idb = -16, -16, -1 + 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) + if( niterations .lt. 0 ) then + norder=3 + call osd300(llr, norder, decoded, niterations, cw) + endif + 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 bpdecode300(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.389/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 diff --git a/lib/fsk4hf/mskhfsim.f90 b/lib/fsk4hf/mskhfsim.f90 new file mode 100644 index 00000000..86140e1c --- /dev/null +++ b/lib/fsk4hf/mskhfsim.f90 @@ -0,0 +1,194 @@ +program msksim + +! Simulate characteristics of a potential "MSK10" mode using LDPC (168,84) +! code, OQPDK modulation, and 30 s T/R sequences. + +! Reception and Demodulation algorithm: +! 1. Compute coarse spectrum; find fc1 = approx carrier freq +! 2. Mix from fc1 to 0; LPF at +/- 0.75*R +! 3. Square, FFT; find peaks near -R/2 and +R/2 to get fc2 +! 4. Mix from fc2 to 0 +! 5. Fit cb13 (central part of csync) to c -> lag, phase +! 6. Fit complex ploynomial for channel equalization +! 7. Get soft bits from equalized data + + parameter (KK=84) !Information bits (72 + CRC12) + parameter (ND=168) !Data symbols: LDPC (168,84), r=1/2 + parameter (NS=65) !Sync symbols (2 x 26 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (236) + parameter (NSPS=1152/72) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (3776) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + + character*8 arg + complex cbb(0:NZ-1) !Complex baseband waveform + complex csync(0:NZ-1) !Sync symbols only, from cbb + complex cb13(0:N13-1) !Barker 13 waveform + complex c(0:NZ-1) !Complex waveform + complex c0(0:NZ-1) !Complex waveform + complex zz(NS+ND) !Complex symbol values (intermediate) + complex z + real xnoise(0:NZ-1) !Generated random noise + real ynoise(0:NZ-1) !Generated random noise + real rxdata(ND),llr(ND) !Soft symbols + real pp(2*NSPS) !Shaped pulse for OQPSK + real a(5) !For twkfreq1 + real aa(20),bb(20) !Fitted polyco's + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + integer ierror(NS+ND) + integer icw(NN) + integer*1 msgbits(KK),decoded(KK),apmask(ND),cw(ND) +! integer*1 codeword(ND) + data msgbits/0,0,1,0,0,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,1, & + 1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,1,1,0,1,0,1,1,1,0,1,1,0,1,1, & + 1,1,0,1,0,1,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0/ + + nargs=iargc() + if(nargs.ne.6) then + print*,'Usage: mskhfsim f0(Hz) delay(ms) fspread(Hz) maxn iters snr(dB)' + print*,'Example: mskhfsim 0 0 0 5 10 -20' + print*,'Set snr=0 to cycle through a range' + go to 999 + endif + call getarg(1,arg) + read(arg,*) f0 !Generated carrier frequency + call getarg(2,arg) + read(arg,*) delay !Delta_t (ms) for Watterson model + call getarg(3,arg) + read(arg,*) fspread !Fspread (Hz) for Watterson model + call getarg(4,arg) + read(arg,*) maxn !Max nterms for polyfit + call getarg(5,arg) + read(arg,*) iters !Iterations at each SNR + call getarg(6,arg) + read(arg,*) snrdb !Specified SNR_2500 + + twopi=8.0*atan(1.0) + fs=12000.0/72.0 !Sample rate = 166.6666667 Hz + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + ts=2*NSPS*dt !Duration of OQPSK symbols (s) + baud=1.0/tt !Keying rate for "itone" symbols (baud) + txt=NZ*dt !Transmission length (s) + bandwidth_ratio=2500.0/(fs/2.0) + write(*,1000) f0,delay,fspread,maxn,iters,baud,3*baud,txt +1000 format('f0:',f5.1,' Delay:',f4.1,' fSpread:',f5.2,' maxn:',i3, & + ' Iters:',i6/'Baud:',f7.3,' BW:',f5.1,' TxT:',f5.1,f5.2/) + write(*,1004) +1004 format(/' SNR err ber fer fsigma'/37('-')) + + do i=1,N2 !Half-sine pulse shape + pp(i)=sin(0.5*(i-1)*twopi/(2*NSPS)) + enddo + + call genmskhf(msgbits,id,icw,cbb,csync)!Generate baseband waveform and csync + cb13=csync(1680:2095) !Copy the Barker 13 waveform + a=0. + a(1)=f0 + call twkfreq1(cbb,NZ,fs,a,cbb) !Mix to specified frequency + + isna=-10 + isnb=-30 + if(snrdb.ne.0.0) then + isna=nint(snrdb) + isnb=isna + endif + do isnr=isna,isnb,-1 !Loop over SNR range + snrdb=isnr + sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + nhard=0 + nhardsync=0 + nfe=0 + sqf=0. + do iter=1,iters !Loop over requested iterations + c=cbb + if(delay.ne.0.0 .or. fspread.ne.0.0) then + call watterson(c,NZ,fs,delay,fspread) + endif + c=sig*c !Scale to requested SNR + if(snrdb.lt.90) then + do i=0,NZ-1 !Generate gaussian noise + xnoise(i)=gran() + ynoise(i)=gran() + enddo + c=c + cmplx(xnoise,ynoise) !Add AWGN noise + endif + + call getfc1(c,fc1) !First approx for freq + call getfc2(c,csync,fc1,fc2,fc3) !Refined freq + sqf=sqf + (fc1+fc2-f0)**2 + +!NB: Measured performance is about equally good using fc2 or fc3 here: + a(1)=-(fc1+fc2) + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,c) !Mix c down by fc1+fc2 + +! The following may not be necessary? +! z=sum(c(1680:2095)*cb13)/208.0 !Get phase from Barker 13 vector +! z0=z/abs(z) +! c=c*conjg(z0) + +!---------------------------------------------------------------- DT +! Not presently used: + amax=0. + jpk=0 + do j=-20*NSPS,20*NSPS !Get jpk + z=sum(c(1680+j:2095+j)*cb13)/208.0 + if(abs(z).gt.amax) then + amax=abs(z) + jpk=j + endif + enddo + xdt=jpk/fs + + nterms=maxn + c0=c + do itry=1,10 + idf=itry/2 + if(mod(itry,2).eq.0) idf=-idf + nhard0=0 + nhardsync0=0 + ifer=1 + a(1)=idf*0.01 + a(2:5)=0. + call twkfreq1(c0,NZ,fs,a,c) !Mix c0 into c + call cpolyfit(c,pp,id,maxn,aa,bb,zz,nhs) + call msksoftsym(zz,aa,bb,id,nterms,ierror,rxdata,nhard0,nhardsync0) + if(nhardsync0.gt.12) cycle + rxav=sum(rxdata)/ND + rx2av=sum(rxdata*rxdata)/ND + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + ss=0.84 + llr=2.0*rxdata/(ss*ss) + apmask=0 + max_iterations=40 + ifer=0 + call bpdecode168(llr,apmask,max_iterations,decoded,niterations,cw) + nbadcrc=0 + if(niterations.ge.0) call chkcrc12(decoded,nbadcrc) + if(niterations.lt.0 .or. count(msgbits.ne.decoded).gt.0 .or. & + nbadcrc.ne.0) ifer=1 +! if(ifer.eq.0) write(67,1301) snrdb,itry,idf,niterations, & +! nhardsync0,nhard0 +!1301 format(f6.1,5i6) + if(ifer.eq.0) exit + enddo !Freq dither loop + nhard=nhard+nhard0 + nhardsync=nharsdync+nhardsync0 + nfe=nfe+ifer + enddo + + fsigma=sqrt(sqf/iters) + ber=float(nhard)/((NS+ND)*iters) + fer=float(nfe)/iters + write(*,1050) snrdb,nhard,ber,fer,fsigma +! write(60,1050) snrdb,nhard,ber,fer,fsigma +1050 format(f6.1,i7,f8.4,f7.3,f8.2) + enddo + +999 end program msksim diff --git a/lib/fsk4hf/msksoftsym.f90 b/lib/fsk4hf/msksoftsym.f90 new file mode 100644 index 00000000..016b23e1 --- /dev/null +++ b/lib/fsk4hf/msksoftsym.f90 @@ -0,0 +1,81 @@ +subroutine msksoftsym(zz,aa,bb,id,nterms,ierror,rxdata,nhard0,nhardsync0) + + parameter (KK=84) !Information bits (72 + CRC12) + parameter (ND=168) !Data symbols: LDPC (168,84), r=1/2 + parameter (NS=65) !Sync symbols (2 x 26 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (236) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (3760) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + + complex zz(NS+ND) !Complex symbol values (intermediate) + complex z,z0 + real rxdata(ND) !Soft symbols + real aa(20),bb(20) !Fitted polyco's + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + integer ierror(NS+ND) + + n=0 + ierror=0 + do j=1,117 + xx=j*2.0/117.0 - 1.0 + yii=1. + yqq=0. + if(nterms.gt.0) then + yii=aa(1) + yqq=bb(1) + do i=2,nterms + yii=yii + aa(i)*xx**(i-1) + yqq=yqq + bb(i)*xx**(i-1) + enddo + endif + z0=cmplx(yii,yqq) + z=zz(j)*conjg(z0) + p=real(z) + if(abs(id(j)).eq.2) then + if(real(z)*id(j).lt.0) then !Sync bit + nhardsync0=nhardsync0+1 + ierror(j)=2 + endif + else + n=n+1 !Data bit + rxdata(n)=p + ierr=0 + if(id(j)*p.lt.0) then + ierr=1 + ierror(j)=1 + endif + nhard0=nhard0+ierr + endif + enddo + + do j=118,233 + xx=(j-116.5)*2.0/117.0 - 1.0 + yii=1. + yqq=0. + if(nterms.gt.0) then + yii=aa(1) + yqq=bb(1) + do i=2,nterms + yii=yii + aa(i)*xx**(i-1) + yqq=yqq + bb(i)*xx**(i-1) + enddo + endif + z0=cmplx(yii,yqq) + z=zz(j)*conjg(z0) + p=aimag(z) + n=n+1 + rxdata(n)=p + ierr=0 + if(id(j)*p.lt.0) then + ierr=1 + ierror(j)=1 + endif + nhard0=nhard0+ierr + enddo + + return +end subroutine msksoftsym diff --git a/lib/fsk4hf/msksoftsymw.f90 b/lib/fsk4hf/msksoftsymw.f90 new file mode 100644 index 00000000..c7402ec4 --- /dev/null +++ b/lib/fsk4hf/msksoftsymw.f90 @@ -0,0 +1,78 @@ +subroutine msksoftsymw(zz,aa,bb,id,nterms,ierror,rxdata,nhard0,nhardsync0) + + include 'wsprlf_params.f90' + + complex zz(NS+ND) !Complex symbol values (intermediate) + complex z,z0 + real rxdata(ND) !Soft symbols + real aa(20),bb(20) !Fitted polyco's + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + integer ierror(NS+ND) + + n=0 + ierror=0 + ierr=0 + jz=(NS+ND+1)/2 + do j=1,jz + xx=j*2.0/jz - 1.0 + yii=1. + yqq=0. + if(nterms.gt.0) then + yii=aa(1) + yqq=bb(1) + do i=2,nterms + yii=yii + aa(i)*xx**(i-1) + yqq=yqq + bb(i)*xx**(i-1) + enddo + endif + z0=cmplx(yii,yqq) + z=zz(j)*conjg(z0) + p=real(z) + if(abs(id(j)).eq.2) then + if(real(z)*id(j).lt.0) then !Sync bit + nhardsync0=nhardsync0+1 + ierror(j)=2 + endif + else + n=n+1 !Data bit + rxdata(n)=p + ierr=0 + if(id(j)*p.lt.0) then + ierr=1 + ierror(j)=1 + endif + nhard0=nhard0+ierr + endif +! write(41,3301) j,id(j),ierror(j),ierr,n,p,p*id(j) +!3301 format(5i6,2f10.3) + enddo + + do j=jz+1,NS+ND + xx=(j-jz+0.5)*2.0/jz - 1.0 + yii=1. + yqq=0. + if(nterms.gt.0) then + yii=aa(1) + yqq=bb(1) + do i=2,nterms + yii=yii + aa(i)*xx**(i-1) + yqq=yqq + bb(i)*xx**(i-1) + enddo + endif + z0=cmplx(yii,yqq) + z=zz(j)*conjg(z0) + p=aimag(z) + n=n+1 + if(n.gt.ND) exit + rxdata(n)=p + ierr=0 + if(id(j)*p.lt.0) then + ierr=1 + ierror(j)=1 + endif + nhard0=nhard0+ierr +! write(41,3301) j,id(j),ierror(j),ierr,n,p,p*id(j) + enddo + + return +end subroutine msksoftsymw diff --git a/lib/fsk4hf/osd174.f90 b/lib/fsk4hf/osd174.f90 new file mode 100644 index 00000000..f3d1403b --- /dev/null +++ b/lib/fsk4hf/osd174.f90 @@ -0,0 +1,377 @@ +subroutine osd174(llr,apmask,ndeep,decoded,cw,nhardmin,dmin) +! +! An ordered-statistics decoder for the (174,87) code. +! +include "ldpc_174_87_params.f90" + +integer*1 apmask(N),apmaskr(N) +integer*1 gen(K,N) +integer*1 genmrb(K,N),g2(N,K) +integer*1 temp(K),m0(K),me(K),mi(K),misub(K),e2sub(N-K),e2(N-K),ui(N-K) +integer*1 r2pat(N-K) +integer indices(N),nxor(N) +integer*1 cw(N),ce(N),c0(N),hdec(N) +integer*1 decoded(K) +integer indx(N) +real llr(N),rx(N),absrx(N) +logical first,reset +data first/.true./ +save first,gen + +if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,22 + read(g(i)(j:j),"(Z1)") istr + do jj=1, 4 + irow=(j-1)*4+jj + if( btest(istr,4-jj) ) gen(irow,i)=1 + enddo + enddo + enddo + do irow=1,K + gen(irow,M+irow)=1 + enddo +first=.false. +endif + +! Re-order received vector to place systematic msg bits at the end. +rx=llr(colorder+1) +apmaskr=apmask(colorder+1) + +! Hard decisions on the received word. +hdec=0 +where(rx .ge. 0) hdec=1 + +! Use magnitude of received symbols as a measure of reliability. +absrx=abs(rx) +call indexx(absrx,N,indx) + +! Re-order the columns of the generator matrix in order of decreasing reliability. +do i=1,N + genmrb(1:K,i)=gen(1:K,indx(N+1-i)) + indices(i)=indx(N+1-i) +enddo + +! Do gaussian elimination to create a generator matrix with the most reliable +! received bits in positions 1:K in order of decreasing reliability (more or less). +do id=1,K ! diagonal element indices + do icol=id,K+20 ! The 20 is ad hoc - beware + iflag=0 + if( genmrb(id,icol) .eq. 1 ) then + iflag=1 + if( icol .ne. id ) then ! reorder column + temp(1:K)=genmrb(1:K,id) + genmrb(1:K,id)=genmrb(1:K,icol) + genmrb(1:K,icol)=temp(1:K) + itmp=indices(id) + indices(id)=indices(icol) + indices(icol)=itmp + endif + do ii=1,K + if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then + genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) + endif + enddo + exit + endif + enddo +enddo + +g2=transpose(genmrb) + +! The hard decisions for the K MRB bits define the order 0 message, m0. +! Encode m0 using the modified generator matrix to find the "order 0" codeword. +! Flip various combinations of bits in m0 and re-encode to generate a list of +! codewords. Return the member of the list that has the smallest Euclidean +! distance to the received word. + +hdec=hdec(indices) ! hard decisions from received symbols +m0=hdec(1:K) ! zero'th order message +absrx=absrx(indices) +rx=rx(indices) +apmaskr=apmaskr(indices) + +call mrbencode(m0,c0,g2,N,K) +nxor=ieor(c0,hdec) +nhardmin=sum(nxor) +dmin=sum(nxor*absrx) + +cw=c0 +ntotal=0 +nrejected=0 + +if(ndeep.eq.0) goto 998 ! norder=0 +if(ndeep.gt.5) ndeep=5 +if( ndeep.eq. 1) then + nord=1 + npre1=0 + npre2=0 + nt=40 + ntheta=12 +elseif(ndeep.eq.2) then + nord=1 + npre1=1 + npre2=0 + nt=40 + ntheta=12 +elseif(ndeep.eq.3) then + nord=1 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=14 +elseif(ndeep.eq.4) then + nord=2 + npre1=1 + npre2=0 + nt=40 + ntheta=12 + ntau=19 +elseif(ndeep.eq.5) then + nord=2 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=19 +endif + +do iorder=1,nord + if( iorder.eq. 1 ) then + misub(1:K-1)=0 + misub(K)=1 + iflag=K + elseif( iorder.eq. 2 ) then + misub(1:K-2)=0 + misub(K-1:K)=1 + iflag=K-1 + endif + do while(iflag .ge.0) + if(iorder.eq.nord .and. npre1.eq.0) then + iend=iflag + else + iend=1 + endif + do n1=iflag,iend,-1 + mi=misub + mi(n1)=1 + if(any(iand(apmaskr(1:K),mi).eq.1)) cycle + ntotal=ntotal+1 + me=ieor(m0,mi) + if(n1.eq.iflag) then + call mrbencode(me,ce,g2,N,K) + e2sub=ieor(ce(K+1:N),hdec(K+1:N)) + e2=e2sub + nd1Kpt=sum(e2sub(1:nt))+1 + d1=sum(ieor(me(1:K),hdec(1:K))*absrx(1:K)) + else + e2=ieor(e2sub,g2(K+1:N,n1)) + nd1Kpt=sum(e2(1:nt))+2 + endif + if(nd1Kpt .le. ntheta) then + call mrbencode(me,ce,g2,N,K) + nxor=ieor(ce,hdec) + if(n1.eq.iflag) then + dd=d1+sum(e2sub*absrx(K+1:N)) + else + dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(K+1:N)) + endif + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + nd1Kptbest=nd1Kpt + endif + else + nrejected=nrejected+1 + endif + enddo +! Get the next test error pattern, iflag will go negative +! when the last pattern with weight iorder has been generated. + call nextpat(misub,k,iorder,iflag) + enddo +enddo + +if(npre2.eq.1) then + reset=.true. + ntotal=0 + do i1=K,1,-1 + do i2=i1-1,1,-1 + ntotal=ntotal+1 + mi(1:ntau)=ieor(g2(K+1:K+ntau,i1),g2(K+1:K+ntau,i2)) + call boxit(reset,mi(1:ntau),ntau,ntotal,i1,i2) + enddo + enddo + + ncount2=0 + ntotal2=0 + reset=.true. +! Now run through again and do the second pre-processing rule + if(nord.eq.1) then + misub(1:K-1)=0 + misub(K)=1 + iflag=K + elseif(nord.eq.2) then + misub(1:K-1)=0 + misub(K-1:K)=1 + iflag=K-1 + endif + do while(iflag .ge.0) + me=ieor(m0,misub) + call mrbencode(me,ce,g2,N,K) + e2sub=ieor(ce(K+1:N),hdec(K+1:N)) + do i2=0,ntau + ntotal2=ntotal2+1 + ui=0 + if(i2.gt.0) ui(i2)=1 + r2pat=ieor(e2sub,ui) +778 continue + call fetchit(reset,r2pat(1:ntau),ntau,in1,in2) + if(in1.gt.0.and.in2.gt.0) then + ncount2=ncount2+1 + mi=misub + mi(in1)=1 + mi(in2)=1 + if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:K),mi).eq.1)) cycle + me=ieor(m0,mi) + call mrbencode(me,ce,g2,N,K) + nxor=ieor(ce,hdec) + dd=sum(nxor*absrx) + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + endif + goto 778 + endif + enddo + call nextpat(misub,K,nord,iflag) + enddo +endif + +998 continue +! Re-order the codeword to place message bits at the end. +cw(indices)=cw +hdec(indices)=hdec +decoded=cw(K+1:N) +cw(colorder+1)=cw ! put the codeword back into received-word order +return +end subroutine osd174 + +subroutine mrbencode(me,codeword,g2,N,K) +integer*1 me(K),codeword(N),g2(N,K) +! fast encoding for low-weight test patterns + codeword=0 + do i=1,K + if( me(i) .eq. 1 ) then + codeword=ieor(codeword,g2(1:N,i)) + endif + enddo +return +end subroutine mrbencode + +subroutine nextpat(mi,k,iorder,iflag) + integer*1 mi(k),ms(k) +! generate the next test error pattern + ind=-1 + do i=1,k-1 + if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i + enddo + if( ind .lt. 0 ) then ! no more patterns of this order + iflag=ind + return + endif + ms=0 + ms(1:ind-1)=mi(1:ind-1) + ms(ind)=1 + ms(ind+1)=0 + if( ind+1 .lt. k ) then + nz=iorder-sum(ms) + ms(k-nz+1:k)=1 + endif + mi=ms + do i=1,k ! iflag will point to the lowest-index 1 in mi + if(mi(i).eq.1) then + iflag=i + exit + endif + enddo + return +end subroutine nextpat + +subroutine boxit(reset,e2,ntau,npindex,i1,i2) + integer*1 e2(1:ntau) + integer indexes(4000,2),fp(0:525000),np(4000) + logical reset + common/boxes/indexes,fp,np + + if(reset) then + patterns=-1 + fp=-1 + np=-1 + sc=-1 + indexes=-1 + reset=.false. + endif + + indexes(npindex,1)=i1 + indexes(npindex,2)=i2 + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + + ip=fp(ipat) ! see what's currently stored in fp(ipat) + if(ip.eq.-1) then + fp(ipat)=npindex + else + do while (np(ip).ne.-1) + ip=np(ip) + enddo + np(ip)=npindex + endif + return +end subroutine boxit + +subroutine fetchit(reset,e2,ntau,i1,i2) + integer indexes(4000,2),fp(0:525000),np(4000) + integer lastpat + integer*1 e2(ntau) + logical reset + common/boxes/indexes,fp,np + save lastpat,inext + + if(reset) then + lastpat=-1 + reset=.false. + endif + + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + index=fp(ipat) + + if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices + i1=indexes(index,1) + i2=indexes(index,2) + inext=np(index) + elseif(lastpat.eq.ipat .and. inext.gt.0) then + i1=indexes(inext,1) + i2=indexes(inext,2) + inext=np(inext) + else + i1=-1 + i2=-1 + inext=-1 + endif + lastpat=ipat + return +end subroutine fetchit + diff --git a/lib/fsk4hf/osd300.f90 b/lib/fsk4hf/osd300.f90 new file mode 100644 index 00000000..c4ec9a02 --- /dev/null +++ b/lib/fsk4hf/osd300.f90 @@ -0,0 +1,184 @@ +subroutine osd300(llr,norder,decoded,niterations,cw) +! +! An ordered-statistics decoder for the (300,60) code. +! +include "ldpc_300_60_params.f90" + +integer*1 gen(K,N) +integer*1 genmrb(K,N),g2(N,K) +integer*1 temp(K),m0(K),me(K),mi(K) +integer indices(N),nxor(N) +integer*1 cw(N),ce(N),c0(N),hdec(N) +integer*1 decoded(K) +integer indx(N) +real llr(N),rx(N),absrx(N) +logical first +data first/.true./ + +save first,gen + +if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,15 + read(g(i)(j:j),"(Z1)") istr + do jj=1, 4 + irow=(j-1)*4+jj + if( btest(istr,4-jj) ) gen(irow,i)=1 + enddo + enddo + enddo + do irow=1,K + gen(irow,M+irow)=1 + enddo +first=.false. +endif + +! re-order received vector to place systematic msg bits at the end +rx=llr(colorder+1) + +! hard decode the received word +hdec=0 +where(rx .ge. 0) hdec=1 + +! use magnitude of received symbols as a measure of reliability. +absrx=abs(rx) +call indexx(absrx,N,indx) + +! re-order the columns of the generator matrix in order of decreasing reliability. +do i=1,N + genmrb(1:K,i)=gen(1:K,indx(N+1-i)) + indices(i)=indx(N+1-i) +enddo + +! do gaussian elimination to create a generator matrix with the most reliable +! received bits in positions 1:K in order of decreasing reliability (more or less). +! reliability will not be strictly decreasing because column re-ordering is needed +! to put the generator matrix in systematic form. the "indices" array tracks +! column permutations caused by reliability sorting and gaussian elimination. +do id=1,K ! diagonal element indices + do icol=id,K+20 ! The 20 is ad hoc - beware + iflag=0 + if( genmrb(id,icol) .eq. 1 ) then + iflag=1 + if( icol .ne. id ) then ! reorder column + temp(1:K)=genmrb(1:K,id) + genmrb(1:K,id)=genmrb(1:K,icol) + genmrb(1:K,icol)=temp(1:K) + itmp=indices(id) + indices(id)=indices(icol) + indices(icol)=itmp + endif + do ii=1,K + if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then + genmrb(ii,1:N)=mod(genmrb(ii,1:N)+genmrb(id,1:N),2) + endif + enddo + exit + endif + enddo +enddo + +g2=transpose(genmrb) + +! The hard decisions for the K MRB bits define the order 0 message, m0. +! Encode m0 using the modified generator matrix to find the "order 0" codeword. +! Flip various combinations of bits in m0 and re-encode to generate a list of +! codewords. Test all such codewords against the received word to decide which +! codeword is most likely to be correct. + +hdec=hdec(indices) ! hard decisions from received symbols +m0=hdec(1:K) ! zero'th order message +absrx=absrx(indices) +rx=rx(indices) + +s1=sum(absrx(1:K)) +s2=sum(absrx(K+1:N)) +xlam=5.0 +rho=s1/(s1+xlam*s2) +call mrbencode(m0,c0,g2,N,K) +nxor=ieor(c0,hdec) +nhardmin=sum(nxor) +dmin=sum(nxor*absrx) +thresh=rho*dmin + +cw=c0 +nt=0 +nrejected=0 +do iorder=1,norder + mi(1:K-iorder)=0 + mi(K-iorder+1:K)=1 + iflag=0 + do while(iflag .ge. 0 ) + dpat=sum(mi*absrx(1:K)) + nt=nt+1 + if( dpat .lt. thresh ) then ! reject unlikely error patterns + me=ieor(m0,mi) + call mrbencode(me,ce,g2,N,K) + nxor=ieor(ce,hdec) + dd=sum(nxor*absrx) + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + thresh=rho*dmin + endif + else + nrejected=nrejected+1 + endif +! get the next test error pattern, iflag will go negative +! when the last pattern with weight iorder has been generated + call nextpat(mi,k,iorder,iflag) + enddo +enddo + +!write(*,*) 'nhardmin ',nhardmin +!write(*,*) 'total patterns ',nt,' number rejected ',nrejected + +! re-order the codeword to place message bits at the end +cw(indices)=cw +hdec(indices)=hdec +decoded=cw(M+1:N) +nerr=0 +do i=1,N + if( hdec(i) .ne. cw(i) ) nerr=nerr+1 +enddo +niterations=nerr +return +end subroutine osd300 + +subroutine mrbencode(me,codeword,g2,N,K) +integer*1 me(K),codeword(N),g2(N,K) +! fast encoding for low-weight test patterns + codeword=0 + do i=1,K + if( me(i) .eq. 1 ) then + codeword=ieor(codeword,g2(1:N,i)) + endif + enddo +return +end subroutine mrbencode + +subroutine nextpat(mi,k,iorder,iflag) + integer*1 mi(k),ms(k) +! generate the next test error pattern + ind=-1 + do i=1,k-1 + if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i + enddo + if( ind .lt. 0 ) then ! no more patterns of this order + iflag=ind + return + endif + ms=0 + ms(1:ind-1)=mi(1:ind-1) + ms(ind)=1 + ms(ind+1)=0 + if( ind+1 .lt. k ) then + nz=iorder-sum(ms) + ms(k-nz+1:k)=1 + endif + mi=ms + iflag=ind + return +end subroutine nextpat diff --git a/lib/fsk4hf/polyfit4.f90 b/lib/fsk4hf/polyfit4.f90 new file mode 100644 index 00000000..892cd2cd --- /dev/null +++ b/lib/fsk4hf/polyfit4.f90 @@ -0,0 +1,109 @@ +subroutine polyfit4(x,y,sigmay,npts,nterms,mode,a,chisqr) + + parameter (MAXN=20) + implicit real*8 (a-h,o-z) + real x(npts), y(npts), sigmay(npts), a(nterms),chisqr + real*8 sumx(2*MAXN-1), sumy(MAXN), array(MAXN,MAXN) + +! Accumulate weighted sums + nmax = 2*nterms-1 + sumx=0. + sumy=0. + chisq=0. + do i=1,npts + xi=x(i) + yi=y(i) + if(mode.lt.0) then + weight=1./abs(yi) + else if(mode.eq.0) then + weight=1 + else + weight=1./sigmay(i)**2 + end if + xterm=weight + do n=1,nmax + sumx(n)=sumx(n)+xterm + xterm=xterm*xi + enddo + yterm=weight*yi + do n=1,nterms + sumy(n)=sumy(n)+yterm + yterm=yterm*xi + enddo + chisq=chisq+weight*yi**2 + enddo + +! Construct matrices and calculate coefficients + do j=1,nterms + do k=1,nterms + n=j+k-1 + array(j,k)=sumx(n) + enddo + enddo + + delta=determ4(array,nterms) + if(delta.eq.0) then + chisqr=0. + a=0. + else + do l=1,nterms + do j=1,nterms + do k=1,nterms + n=j+k-1 + array(j,k)=sumx(n) + enddo + array(j,l)=sumy(j) + enddo + a(l)=determ4(array,nterms)/delta + enddo + +! Calculate chi square + + do j=1,nterms + chisq=chisq-2*a(j)*sumy(j) + do k=1,nterms + n=j+k-1 + chisq=chisq+a(j)*a(k)*sumx(n) + enddo + enddo + free=npts-nterms + chisqr=chisq/free + end if + + return +end subroutine polyfit4 + +real*8 function determ4(array,norder) + + parameter (MAXN=20) + implicit real*8 (a-h,o-z) + real*8 array(MAXN,MAXN) + + determ4=1. + do k=1,norder + if (array(k,k).ne.0) go to 41 + do j=k,norder + if(array(k,j).ne.0) go to 31 + enddo + determ4=0. + go to 60 + +31 do i=k,norder + s8=array(i,j) + array(i,j)=array(i,k) + array(i,k)=s8 + enddo + determ4=-1.*determ4 +41 determ4=determ4*array(k,k) + if(k.lt.norder) then + k1=k+1 + do i=k1,norder + do j=k1,norder + array(i,j)=array(i,j)-array(i,k)*array(k,j)/array(k,k) + enddo + enddo + end if + enddo + +60 return +end function determ4 diff --git a/lib/fsk4hf/spec4.f90 b/lib/fsk4hf/spec4.f90 new file mode 100644 index 00000000..e0588950 --- /dev/null +++ b/lib/fsk4hf/spec4.f90 @@ -0,0 +1,35 @@ +subroutine spec4(c,s,savg) + + parameter (KK=84) !Information bits (72 + CRC12) + parameter (ND=84) !Data symbols: LDPC (168,84), r=1/2 + parameter (NS=12) !Sync symbols (3 @ 4x4 Costas arrays) + parameter (NR=2) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (98) + parameter (NSPS=2688/84) !Samples per symbol (32) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (3760) + parameter (NFFT=2*NSPS,NH=NSPS) + + complex c(0:NZ-1) + complex c1(0:NFFT-1) + real s(0:NH,NN) + real savg(0:NH) + + fs=12000.0/84.0 + df=fs/NFFT + savg=0. + do j=1,NN + ia=(j-1)*NSPS + ib=ia + NSPS-1 + c1(0:NSPS-1)=c(ia:ib) + c1(NSPS:)=0. + call four2a(c1,NFFT,1,-1,1) + do k=1,NSPS + s(k,j)=real(c1(k))**2 + aimag(c1(k))**2 + enddo + savg=savg+s(0:NH,j) + enddo + s=s/NZ + savg=savg/(NN*NZ) + + return +end subroutine spec4 diff --git a/lib/fsk4hf/spec8.f90 b/lib/fsk4hf/spec8.f90 new file mode 100644 index 00000000..43fbc7ee --- /dev/null +++ b/lib/fsk4hf/spec8.f90 @@ -0,0 +1,31 @@ +subroutine spec8(c,s,savg) + + include 'wspr_fsk8_params.f90' + complex c(0:NMAXD-1) + complex c1(0:NSPS-1) + real s(0:NH2,NN) + real savg(0:NH2) + + fs=12000.0/NDOWN + df=fs/NSPS + savg=0. + do j=1,NN + ia=(j-1)*NSPS + ib=ia + NSPS-1 + c1(0:NSPS-1)=c(ia:ib) + c1(NSPS:)=0. + call four2a(c1,NSPS,1,-1,1) + do i=0,NH2 + s(i,j)=real(c1(i))**2 + aimag(c1(i))**2 + enddo + savg=savg+s(0:NH2,j) + enddo + s=s/NZ + savg=savg/(NN*NZ) +! do i=0,NH2 +! write(31,3101) i*df,savg(i) +!3101 format(f10.3,f12.3) +! enddo + + return +end subroutine spec8 diff --git a/lib/fsk4hf/subtractft8.f90 b/lib/fsk4hf/subtractft8.f90 new file mode 100644 index 00000000..1031cf2b --- /dev/null +++ b/lib/fsk4hf/subtractft8.f90 @@ -0,0 +1,61 @@ +subroutine subtractft8(dd,itone,f0,dt) + +! Subtract an ft8 signal +! +! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t)) +! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) ) +! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ] +! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt} + + use timer_module, only: timer + + parameter (NMAX=15*12000,NFRAME=1920*79) + parameter (NFFT=NMAX,NFILT=1400) + real*4 dd(NMAX), window(-NFILT/2:NFILT/2) + complex cref,camp,cfilt,cw + integer itone(79) + logical first + data first/.true./ + common/heap8/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX) + save first + + nstart=dt*12000+1 + call genft8refsig(itone,cref,f0) + camp=0. + do i=1,nframe + id=nstart-1+i + if(id.ge.1.and.id.le.NMAX) camp(i)=dd(id)*conjg(cref(i)) + enddo + + if(first) then +! Create and normalize the filter + pi=4.0*atan(1.0) + fac=1.0/float(nfft) + sum=0.0 + do j=-NFILT/2,NFILT/2 + window(j)=cos(pi*j/NFILT)**2 + sum=sum+window(j) + enddo + cw=0. + cw(1:NFILT+1)=window/sum + cw=cshift(cw,NFILT/2+1) + call four2a(cw,nfft,1,-1,1) + cw=cw*fac + first=.false. + endif + + cfilt=0.0 + cfilt(1:nframe)=camp(1:nframe) + call four2a(cfilt,nfft,1,-1,1) + cfilt(1:nfft)=cfilt(1:nfft)*cw(1:nfft) + call four2a(cfilt,nfft,1,1,1) + +! Subtract the reconstructed signal + do i=1,nframe + j=nstart+i-1 + if(j.ge.1 .and. j.le.NMAX) dd(j)=dd(j)-2*REAL(cfilt(i)*cref(i)) + enddo + + return +end subroutine subtractft8 + diff --git a/lib/fsk4hf/sync8.f90 b/lib/fsk4hf/sync8.f90 new file mode 100644 index 00000000..30f6de17 --- /dev/null +++ b/lib/fsk4hf/sync8.f90 @@ -0,0 +1,151 @@ +subroutine sync8(dd,nfa,nfb,syncmin,nfqso,s,candidate,ncand,sbase) + + include 'ft8_params.f90' +! Search over +/- 2.5s relative to 0.5s TX start time. + parameter (JZ=62) + complex cx(0:NH1) + real s(NH1,NHSYM) + real savg(NH1) + real sbase(NH1) + real x(NFFT1) + real sync2d(NH1,-JZ:JZ) + real red(NH1) + real candidate0(3,200) + real candidate(3,200) + real dd(NMAX) + integer jpeak(NH1) + integer indx(NH1) + integer ii(1) + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ !Costas 7x7 tone pattern + equivalence (x,cx) + +! Compute symbol spectra, stepping by NSTEP steps. + savg=0. + tstep=NSTEP/12000.0 + df=12000.0/NFFT1 !3.125 Hz + fac=1.0/300.0 + do j=1,NHSYM + ia=(j-1)*NSTEP + 1 + ib=ia+NSPS-1 + x(1:NSPS)=fac*dd(ia:ib) + x(NSPS+1:)=0. + call four2a(x,NFFT1,1,-1,0) !r2c FFT + do i=1,NH1 + s(i,j)=real(cx(i))**2 + aimag(cx(i))**2 + enddo + savg=savg + s(1:NH1,j) !Average spectrum + enddo + call baseline(savg,nfa,nfb,sbase) +! savg=savg/NHSYM +! do i=1,NH1 +! write(51,3051) i*df,savg(i),db(savg(i)) +!3051 format(f10.3,e12.3,f12.3) +! enddo + + ia=max(1,nint(nfa/df)) + ib=nint(nfb/df) + nssy=NSPS/NSTEP ! # steps per symbol + nfos=NFFT1/NSPS ! # frequency bin oversampling factor + jstrt=0.5/tstep + + do i=ia,ib + do j=-JZ,+JZ + ta=0. + tb=0. + tc=0. + t0a=0. + t0b=0. + t0c=0. + do n=0,6 + k=j+jstrt+nssy*n + if(k.ge.1.and.k.le.NHSYM) then + ta=ta + s(i+nfos*icos7(n),k) + t0a=t0a + sum(s(i:i+nfos*6:nfos,k)) + endif + tb=tb + s(i+nfos*icos7(n),k+nssy*36) + t0b=t0b + sum(s(i:i+nfos*6:nfos,k+nssy*36)) + if(k+nssy*72.le.NHSYM) then + tc=tc + s(i+nfos*icos7(n),k+nssy*72) + t0c=t0c + sum(s(i:i+nfos*6:nfos,k+nssy*72)) + endif + enddo + t=ta+tb+tc + t0=t0a+t0b+t0c + t0=(t0-t)/6.0 + sync_abc=t/t0 + + t=tb+tc + t0=t0b+t0c + t0=(t0-t)/6.0 + sync_bc=t/t0 + sync2d(i,j)=max(sync_abc,sync_bc) + enddo + enddo + + red=0. + do i=ia,ib + ii=maxloc(sync2d(i,-JZ:JZ)) - 1 - JZ + j0=ii(1) + jpeak(i)=j0 + red(i)=sync2d(i,j0) +! write(52,3052) i*df,red(i),db(red(i)) +!3052 format(3f12.3) + enddo + iz=ib-ia+1 + call indexx(red(ia:ib),iz,indx) + ibase=indx(nint(0.40*iz)) - 1 + ia + base=red(ibase) + red=red/base + + candidate0=0. + k=0 + do i=1,200 + n=ia + indx(iz+1-i) - 1 + if(red(n).lt.syncmin) exit + if(k.lt.200) k=k+1 + candidate0(1,k)=n*df + candidate0(2,k)=(jpeak(n)-1)*tstep + candidate0(3,k)=red(n) + enddo + ncand=k + +! Put nfqso at top of list, and save only the best of near-dupe freqs. + do i=1,ncand + if(abs(candidate0(1,i)-nfqso).lt.10.0) candidate0(1,i)=-candidate0(1,i) + if(i.ge.2) then + do j=1,i-1 + fdiff=abs(candidate0(1,i))-abs(candidate0(1,j)) + if(abs(fdiff).lt.4.0) then + if(candidate0(3,i).ge.candidate0(3,j)) candidate0(3,j)=0. + if(candidate0(3,i).lt.candidate0(3,j)) candidate0(3,i)=0. + endif + enddo +! write(*,3001) i,candidate0(1,i-1),candidate0(1,i),candidate0(3,i-1), & +! candidate0(3,i) +!3001 format(i2,4f8.1) + endif + enddo + + fac=20.0/maxval(s) + s=fac*s + +! Sort by sync +! call indexx(candidate0(3,1:ncand),ncand,indx) +! Sort by frequency + call indexx(candidate0(1,1:ncand),ncand,indx) + k=1 +! do i=ncand,1,-1 + do i=1,ncand + j=indx(i) +! if( candidate0(3,j) .ge. syncmin .and. candidate0(2,j).ge.-1.5 ) then + if( candidate0(3,j) .ge. syncmin ) then + candidate(1,k)=abs(candidate0(1,j)) + candidate(2,k)=candidate0(2,j) + candidate(3,k)=candidate0(3,j) + k=k+1 + endif + enddo + ncand=k-1 + return +end subroutine sync8 diff --git a/lib/fsk4hf/sync8d.f90 b/lib/fsk4hf/sync8d.f90 new file mode 100644 index 00000000..d0d1c63b --- /dev/null +++ b/lib/fsk4hf/sync8d.f90 @@ -0,0 +1,54 @@ +subroutine sync8d(cd0,i0,ctwk,itwk,sync) + +! Compute sync power for a complex, downsampled FT8 signal. + + parameter(NP2=2812,NDOWN=60) + complex cd0(3125) + complex csync(0:6,32) + complex csync2(32) + complex ctwk(32) + complex z1,z2,z3 + logical first + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ + data first/.true./ + save first,twopi,fs2,dt2,taus,baud,csync + + p(z1)=real(z1)**2 + aimag(z1)**2 !Statement function for power + +! Set some constants and compute the csync array. + if( first ) then + twopi=8.0*atan(1.0) + fs2=12000.0/NDOWN !Sample rate after downsampling + dt2=1/fs2 !Corresponding sample interval + taus=32*dt2 !Symbol duration + baud=1.0/taus !Keying rate + do i=0,6 + phi=0.0 + dphi=twopi*icos7(i)*baud*dt2 + do j=1,32 + csync(i,j)=cmplx(cos(phi),sin(phi)) !Waveform for 7x7 Costas array + phi=mod(phi+dphi,twopi) + enddo + enddo + first=.false. + endif + + sync=0 + do i=0,6 !Sum over 7 Costas frequencies and + i1=i0+i*32 !three Costas arrays + i2=i1+36*32 + i3=i1+72*32 + csync2=csync(i,1:32) + if(itwk.eq.1) csync2=ctwk*csync2 !Tweak the frequency + z1=0. + z2=0. + z3=0. + if(i1.ge.1 .and. i1+31.le.NP2) z1=sum(cd0(i1:i1+31)*conjg(csync2)) + if(i2.ge.1 .and. i2+31.le.NP2) z2=sum(cd0(i2:i2+31)*conjg(csync2)) + if(i3.ge.1 .and. i3+31.le.NP2) z3=sum(cd0(i3:i3+31)*conjg(csync2)) + sync = sync + p(z1) + p(z2) + p(z3) + enddo + + return +end subroutine sync8d diff --git a/lib/fsk4hf/tweak1.f90 b/lib/fsk4hf/tweak1.f90 new file mode 100644 index 00000000..c62c4087 --- /dev/null +++ b/lib/fsk4hf/tweak1.f90 @@ -0,0 +1,23 @@ +subroutine tweak1(ca,jz,f0,cb) + +! Shift frequency of analytic signal ca, with output to cb + + complex ca(jz),cb(jz) + real*8 twopi + complex*16 w,wstep + complex w4 + data twopi/0.d0/ + save twopi + + if(twopi.eq.0.d0) twopi=8.d0*atan(1.d0) + w=1.d0 + dphi=twopi*f0/12000.d0 + wstep=cmplx(cos(dphi),sin(dphi)) + do i=1,jz + w=w*wstep + w4=w + cb(i)=w4*ca(i) + enddo + + return +end subroutine tweak1 diff --git a/lib/fsk4hf/twkfreq1.f90 b/lib/fsk4hf/twkfreq1.f90 new file mode 100644 index 00000000..e6aa8f8b --- /dev/null +++ b/lib/fsk4hf/twkfreq1.f90 @@ -0,0 +1,26 @@ +subroutine twkfreq1(ca,npts,fsample,a,cb) + + complex ca(npts) + complex cb(npts) + complex w,wstep + real a(5) + data twopi/6.283185307/ + +! Mix the complex signal + w=1.0 + wstep=1.0 + x0=0.5*(npts+1) + s=2.0/npts + do i=1,npts + x=s*(i-x0) + p2=1.5*x*x - 0.5 + p3=2.5*(x**3) - 1.5*x + p4=4.375*(x**4) - 3.75*(x**2) + 0.375 + dphi=(a(1) + x*a(2) + p2*a(3) + p3*a(4) + p4*a(5)) * (twopi/fsample) + wstep=cmplx(cos(dphi),sin(dphi)) + w=w*wstep + cb(i)=w*ca(i) + enddo + + return +end subroutine twkfreq1 diff --git a/lib/fsk4hf/watterson.f90 b/lib/fsk4hf/watterson.f90 new file mode 100644 index 00000000..d047a26e --- /dev/null +++ b/lib/fsk4hf/watterson.f90 @@ -0,0 +1,62 @@ +subroutine watterson(c,npts,fs,delay,fspread) + + complex c(0:npts-1) + complex c2(0:npts-1) + complex cs1(0:npts-1) + complex cs2(0:npts-1) + + nonzero=0 + df=fs/npts + if(fspread.gt.0.0) then + do i=0,npts-1 + xx=gran() + yy=gran() + cs1(i)=0.707*cmplx(xx,yy) + xx=gran() + yy=gran() + cs2(i)=0.707*cmplx(xx,yy) + enddo + call four2a(cs1,npts,1,-1,1) !To freq domain + call four2a(cs2,npts,1,-1,1) + do i=0,npts-1 + f=i*df + if(i.gt.npts/2) f=(i-npts)*df + x=(f/(0.5*fspread))**2 + a=0. + if(x.le.50.0) then + a=exp(-x) + endif + cs1(i)=a*cs1(i) + cs2(i)=a*cs2(i) + if(abs(f).lt.10.0) then + p1=real(cs1(i))**2 + aimag(cs1(i))**2 + p2=real(cs2(i))**2 + aimag(cs2(i))**2 + if(p1.gt.0.0) nonzero=nonzero+1 +! write(62,3101) f,p1,p2,db(p1+1.e-12)-60,db(p2+1.e-12)-60 +!3101 format(f10.3,2f12.3,2f10.3) + endif + enddo + call four2a(cs1,npts,1,1,1) !Back to time domain + call four2a(cs2,npts,1,1,1) + cs1(0:npts-1)=cs1(0:npts-1)/npts + cs2(0:npts-1)=cs2(0:npts-1)/npts + endif + + nshift=nint(0.001*delay*fs) + c2(0:npts-1)=cshift(c(0:npts-1),nshift) + sq=0. + do i=0,npts-1 + if(nonzero.gt.1) then + c(i)=0.5*(cs1(i)*c(i) + cs2(i)*c2(i)) + else + c(i)=0.5*(c(i) + c2(i)) + endif + sq=sq + real(c(i))**2 + aimag(c(i))**2 +! write(61,3001) i/12000.0,c(i) +!3001 format(3f12.6) + enddo + rms=sqrt(sq/npts) + c=c/rms + + return +end subroutine watterson diff --git a/lib/fsk4hf/wavhdr.f90 b/lib/fsk4hf/wavhdr.f90 new file mode 100644 index 00000000..b54fba78 --- /dev/null +++ b/lib/fsk4hf/wavhdr.f90 @@ -0,0 +1,110 @@ +module wavhdr + type hdr + character*4 ariff + integer*4 lenfile + character*4 awave + character*4 afmt + integer*4 lenfmt + integer*2 nfmt2 + integer*2 nchan2 + integer*4 nsamrate + integer*4 nbytesec + integer*2 nbytesam2 + integer*2 nbitsam2 + character*4 adata + integer*4 ndata + end type hdr + + contains + + function default_header(nsamrate,npts) + type(hdr) default_header,h + h%ariff='RIFF' + h%awave='WAVE' + h%afmt='fmt ' + h%lenfmt=16 + h%nfmt2=1 + h%nchan2=1 + h%nsamrate=nsamrate + h%nbitsam2=16 + h%nbytesam2=h%nbitsam2 * h%nchan2 / 8 + h%adata='data' + h%nbytesec=h%nsamrate * h%nbitsam2 * h%nchan2 / 8 + h%ndata=2*npts + h%lenfile=h%ndata + 44 - 8 + default_header=h + end function default_header + + subroutine set_wsjtx_wav_params(fMHz,mode,nsubmode,ntrperiod,id2) + + parameter (NBANDS=23,NMODES=11) + character*8 mode,modes(NMODES) + integer*2 id2(4) + integer iperiod(7) + real fband(NBANDS) + data fband/0.137,0.474,1.8,3.5,5.1,7.0,10.14,14.0,18.1,21.0,24.9, & + 28.0,50.0,144.0,222.0,432.0,902.0,1296.0,2304.0,3400.0, & + 5760.0,10368.0,24048.0/ + data modes/'Echo','FSK441','ISCAT','JT4','JT65','JT6M','JT9', & + 'JT9+JT65','JTMS','JTMSK','WSPR'/ + data iperiod/5,10,15,30,60,120,900/ + + dmin=1.e30 + iband=0 + do i=1,NBANDS + if(abs(fMHz-fband(i)).lt.dmin) then + dmin=abs(fMHz-fband(i)) + iband=i + endif + enddo + + imode=0 + do i=1,NMODES + if(mode.eq.modes(i)) imode=i + enddo + + ip=0 + do i=1,7 + if(ntrperiod.eq.iperiod(i)) ip=i + enddo + + id2(1)=iband + id2(2)=imode + id2(3)=nsubmode + id2(4)=ip + + return + end subroutine set_wsjtx_wav_params + + subroutine get_wsjtx_wav_params(id2,band,mode,nsubmode,ntrperiod,ok) + + parameter (NBANDS=23,NMODES=11) + character*8 mode,modes(NMODES) + character*6 band,bands(NBANDS) + integer*2 id2(4) + integer iperiod(7) + logical ok + data modes/'Echo','FSK441','ISCAT','JT4','JT65','JT6M','JT9', & + 'JT9+JT65','JTMS','JTMSK','WSPR'/ + data iperiod/5,10,15,30,60,120,900/ + data bands/'2190m','630m','160m','80m','60m','40m','30m','20m', & + '17m','15m','12m','10m','6m','2m','1.25m','70cm','33cm', & + '23cm','13cm','9cm','6cm','3cm','1.25cm'/ + + ok=.true. + if(id2(1).lt.1 .or. id2(1).gt.NBANDS) ok=.false. + if(id2(2).lt.1 .or. id2(2).gt.NMODES) ok=.false. + if(id2(3).lt.1 .or. id2(3).gt.8) ok=.false. + if(id2(4).lt.1 .or. id2(4).gt.7) ok=.false. + + if(ok) then + band=bands(id2(1)) + mode=modes(id2(2)) + nsubmode=id2(3) + ntrperiod=iperiod(id2(4)) + endif + + return + end subroutine get_wsjtx_wav_params + +end module wavhdr diff --git a/lib/fsk4hf/wspr5_downsample.f90 b/lib/fsk4hf/wspr5_downsample.f90 new file mode 100644 index 00000000..6fdb9021 --- /dev/null +++ b/lib/fsk4hf/wspr5_downsample.f90 @@ -0,0 +1,29 @@ +subroutine wspr5_downsample(iwave,c) + +! Input: i*2 data in iwave() at sample rate 12000 Hz +! Output: Complex data in c(), sampled at 400 Hz + + include 'wsprlf_params.f90' + parameter (NMAX=300*12000,NFFT2=NMAX/30) + integer*2 iwave(NMAX) + complex c(0:NZ-1) + complex c1(0:NFFT2-1) + complex cx(0:NMAX/2) + real x(NMAX) + equivalence (x,cx) + + df=12000.0/NMAX + x=iwave + call four2a(x,NMAX,1,-1,0) !r2c FFT to freq domain + i0=nint(1500.0/df) + c1(0)=cx(i0) + do i=1,NFFT2/2 + c1(i)=cx(i0+i) + c1(NFFT2-i)=cx(i0-i) + enddo + c1=c1/NFFT2 + call four2a(c1,NFFT2,1,1,1) !c2c FFT back to time domain + c=c1(0:NZ-1) + + return +end subroutine wspr5_downsample diff --git a/lib/fsk4hf/wspr5_wav.f90 b/lib/fsk4hf/wspr5_wav.f90 new file mode 100644 index 00000000..0b09ccde --- /dev/null +++ b/lib/fsk4hf/wspr5_wav.f90 @@ -0,0 +1,48 @@ +subroutine wspr5_wav(baud,xdt,f0,itone,snrdb,iwave) + +! Generate iwave() from itone(). + + include 'wsprlf_params.f90' + parameter (NMAX=300*12000) + integer itone(NN) + integer*2 iwave(NMAX) + real*8 twopi,dt,dphi0,dphi1,dphi,phi + real dat(NMAX) + + twopi=8.d0*atan(1.d0) + dt=1.d0/12000.d0 + + dat=0. + if(snrdb.lt.90) then + do i=1,NMAX + dat(i)=gran() !Generate gaussian noise + enddo + bandwidth_ratio=2500.0/6000.0 + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb) + else + sig=1.0 + endif + + dphi0=twopi*(f0-0.25d0*baud)*dt + dphi1=twopi*(f0+0.25d0*baud)*dt + phi=0.d0 + k=nint(xdt/dt) + do j=1,NN + dphi=dphi0 + if(itone(j).eq.1) dphi=dphi1 + if(k.eq.0) phi=-dphi + do i=1,NSPS0 + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + if(k.gt.0 .and. k.le.NMAX) dat(k)=dat(k) + sig*sin(xphi) + enddo + enddo + fac=32767.0 + rms=100.0 + if(snrdb.ge.90.0) iwave=nint(fac*dat) + if(snrdb.lt.90.0) iwave=nint(rms*dat) + + return +end subroutine wspr5_wav diff --git a/lib/fsk4hf/wspr5d.f90 b/lib/fsk4hf/wspr5d.f90 new file mode 100644 index 00000000..7b50fff2 --- /dev/null +++ b/lib/fsk4hf/wspr5d.f90 @@ -0,0 +1,217 @@ +program wspr5d + +! Decode WSPR-LF data read from *.c5 or *.wav files. + +! WSPR-LF is a potential WSPR-like mode intended for use at LF and MF. +! It uses an LDPC (300,60) code, OQPSK modulation, and 5 minute T/R sequences. + +! Reception and Demodulation algorithm: +! 1. Compute coarse spectrum; find fc1 = approx carrier freq +! 2. Mix from fc1 to 0; LPF at +/- 0.75*R +! 3. Square, FFT; find peaks near -R/2 and +R/2 to get fc2 +! 4. Mix from fc2 to 0 +! 5. Fit cb13 (central part of csync) to c -> lag, phase +! 6. Fit complex ploynomial for channel equalization +! 7. Get soft bits from equalized data + +! Still to do: find and decode more than one signal in the specified passband. + + include 'wsprlf_params.f90' + parameter (NMAX=300*12000) + character arg*8,message*22,cbits*50,infile*80,fname*16,datetime*11 + character*120 data_dir + complex csync(0:NZ-1) !Sync symbols only, from cbb + complex c(0:NZ-1) !Complex waveform + complex c1(0:NZ-1) !Complex waveform + complex zz(NS+ND) !Complex symbol values (intermediate) + complex z + real*8 fMHz + real rxdata(ND),llr(ND) !Soft symbols + real pp(2*NSPS) !Shaped pulse for OQPSK + real a(5) !For twkfreq1 + real aa(20),bb(20) !Fitted polyco's + real fpks(20) + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + integer ierror(NS+ND) + integer isync(48) !Long sync vector + integer ib13(13) !Barker 13 code + integer ihdr(11) + integer*8 n8 + integer*2 iwave(NMAX) !Generated full-length waveform + integer*1 idat(7) + integer*1 decoded(KK),apmask(ND),cw(ND) + data ib13/1,1,1,1,1,-1,-1,1,1,-1,1,-1,1/ + + nargs=iargc() + if(nargs.lt.2) then + print*,'Usage: wspr5d [-a ] [-f fMHz] file1 [file2 ...]' + go to 999 + endif + iarg=1 + data_dir="." + call getarg(iarg,arg) + if(arg(1:2).eq.'-a') then + call getarg(iarg+1,data_dir) + iarg=iarg+2 + endif + call getarg(iarg,arg) + if(arg(1:2).eq.'-f') then + call getarg(iarg+1,arg) + read(arg,*) fMHz + iarg=iarg+2 + endif + + open(13,file=trim(data_dir)//'/ALL_WSPR.TXT',status='unknown', & + position='append') + maxn=8 !Default value + twopi=8.0*atan(1.0) + fs=NSPS*12000.0/NSPS0 !Sample rate + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + ts=2*NSPS*dt !Duration of OQPSK symbols (s) + baud=1.0/tt !Keying rate for "itone" symbols (baud) + txt=NZ*dt !Transmission length (s) + + do i=1,N2 !Half-sine pulse shape + pp(i)=sin(0.5*(i-1)*twopi/(2*NSPS)) + enddo + n8=z'cbf089223a51' + do i=1,48 + isync(i)=-1 + if(iand(n8,1).eq.1) isync(i)=1 + n8=n8/2 + enddo + +! Define array id() for sync symbols + id=0 + do j=1,48 !First group of 48 + id(2*j-1)=2*isync(j) + enddo + do j=1,13 !Barker 13 code + id(j+96)=2*ib13(j) + enddo + do j=1,48 !Second group of 48 + id(2*j+109)=2*isync(j) + enddo + + csync=0. + do j=1,205 + if(abs(id(j)).eq.2) then + ia=nint((j-0.5)*N2) + ib=ia+N2-1 + csync(ia:ib)=pp*id(j)/abs(id(j)) + endif + enddo + + do ifile=iarg,nargs + call getarg(ifile,infile) + open(10,file=infile,status='old',access='stream') + j1=index(infile,'.c5') + j2=index(infile,'.wav') + if(j1.gt.0) then + read(10,end=999) fname,ntrmin,fMHz,c + read(fname(8:11),*) nutc + write(datetime,'(i11)') nutc + else if(j2.gt.0) then + read(10,end=999) ihdr,iwave + read(infile(j2-4:j2-1),*) nutc + datetime=infile(j2-11:j2-1) + call wspr5_downsample(iwave,c) + else + print*,'Wrong file format?' + go to 999 + endif + close(10) + fa=100.0 + fb=150.0 + call getfc1w(c,fs,fa,fb,fc1,xsnr) !First approx for freq + npeaks=20 + call getfc2w(c,csync,npeaks,fs,fc1,fpks) !Refined freq + + a(1)=-fc1 + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,c) !Mix c down by fc1+fc2 + +! Find time offset xdt + amax=0. + jpk=0 + iaa=0 + ibb=NZ-1 + jmax=1260 + do j=-jmax,jmax,NSPS/8 + ia=j + ib=NZ-1+j + if(ia.lt.0) then + ia=0 + iaa=-j + else + iaa=0 + endif + if(ib.gt.NZ-1) then + ib=NZ-1 + ibb=NZ-1-j + endif + z=sum(c(ia:ib)*conjg(csync(iaa:ibb))) +write(51,*) j/fs,real(z),imag(z) + if(abs(z).gt.amax) then + amax=abs(z) + jpk=j + endif + enddo + xdt=jpk/fs +xdt=1.0 +jpk=fs*xdt + do i=0,NZ-1 + j=i+jpk + if(j.ge.0 .and. j.lt.NZ) c1(i)=c(j) + enddo + + nterms=maxn + do itry=1,npeaks + nhard0=0 + nhardsync0=0 + ifer=1 + a(1)=-fpks(itry) + a(2:5)=0. + call twkfreq1(c1,NZ,fs,a,c) !Mix c1 into c + call cpolyfitw(c,pp,id,maxn,aa,bb,zz,nhs) + call msksoftsymw(zz,aa,bb,id,nterms,ierror,rxdata,nhard0,nhardsync0) + if(nhardsync0.gt.35) cycle + rxav=sum(rxdata)/ND + rx2av=sum(rxdata*rxdata)/ND + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + ss=0.84 + llr=2.0*rxdata/(ss*ss) + apmask=0 + max_iterations=40 + ifer=0 + call bpdecode300(llr,apmask,max_iterations,decoded,niterations,cw) + if(niterations.lt.0) call osd300(llr,4,decoded,niterations,cw) + nbadcrc=0 + if(niterations.ge.0) call chkcrc10(decoded,nbadcrc) + if(niterations.lt.0 .or. nbadcrc.ne.0) ifer=1 + if(ifer.eq.0) exit + enddo !Freq dither loop + message=' ' + if(ifer.eq.0) then + write(cbits,1100) decoded(1:50) +1100 format(50i1) + read(cbits,1102) idat +1102 format(6b8,b2) + idat(7)=ishft(idat(7),6) + call wqdecode(idat,message,itype) + nsnr=nint(xsnr) +! freq=fMHz + 1.d-6*(fc1+fc2) + freq=fMHz + 1.d-6*(fc1+fpks(itry)) + nfdot=0 + write(13,1110) datetime,0,nsnr,xdt,freq,message,nfdot +1110 format(a11,2i4,f6.2,f12.7,2x,a22,i3) + write(*,1112) datetime(8:11),nsnr,xdt,freq,nfdot,message,itry +1112 format(a4,i4,f5.1,f11.6,i3,2x,a22,i4) + endif + enddo ! ifile loop + write(*,1120) +1120 format("") + +999 end program wspr5d diff --git a/lib/fsk4hf/wspr5d_exp.f90 b/lib/fsk4hf/wspr5d_exp.f90 new file mode 100644 index 00000000..10193fa7 --- /dev/null +++ b/lib/fsk4hf/wspr5d_exp.f90 @@ -0,0 +1,499 @@ +program wspr5d + +! Decode WSPR-LF data read from *.c5 or *.wav files. + +! WSPR-LF is a potential WSPR-like mode intended for use at LF and MF. +! It uses an LDPC (300,60) code, OQPSK modulation, and 5 minute T/R sequences. +! +! Still to do: find and decode more than one signal in the specified passband. + +! include 'wsprlf_params.f90' + + parameter (NDOWN=30) + parameter (KK=60) + parameter (ND=300) + parameter (NS=109) + parameter (NR=3) + parameter (NN=NR+NS+ND) + parameter (NSPS0=8640) + parameter (NSPS=16) + parameter (N2=2*NSPS) + parameter (NZ=NSPS*NN) + parameter (NZ400=288*NN) + parameter (NMAX=300*12000) + + character arg*8,message*22,cbits*50,infile*80,fname*16,datetime*11 + character*120 data_dir + complex csync(0:NZ-1) !Sync symbols only, from cbb + complex c400(0:NZ400-1) !Complex waveform + complex c(0:NZ-1) !Complex waveform + complex cd(0:NZ-1) !Complex waveform + complex ca(0:NZ-1) !Complex waveform + complex zz + real*8 fMHz + real rxdata(ND),llr(ND) !Soft symbols + real pp(32) !Shaped pulse for OQPSK + real sbits(412),softbits(9) + real fpks(20) + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + integer isync(48) !Long sync vector + integer ib13(13) !Barker 13 code + integer ihdr(11) + integer*8 n8 + integer*2 iwave(NMAX) !Generated full-length waveform + integer*1 idat(7) + integer*1 decoded(KK),apmask(ND),cw(ND) + integer*1 hbits(412),bits(13) + data ib13/1,1,1,1,1,-1,-1,1,1,-1,1,-1,1/ + + nargs=iargc() + if(nargs.lt.2) then + print*,'Usage: wspr5d [-a ] [-f fMHz] file1 [file2 ...]' + go to 999 + endif + iarg=1 + data_dir="." + call getarg(iarg,arg) + if(arg(1:2).eq.'-a') then + call getarg(iarg+1,data_dir) + iarg=iarg+2 + endif + call getarg(iarg,arg) + if(arg(1:2).eq.'-f') then + call getarg(iarg+1,arg) + read(arg,*) fMHz + iarg=iarg+2 + endif + + open(13,file=trim(data_dir)//'/ALL_WSPR.TXT',status='unknown', & + position='append') + maxn=8 !Default value + twopi=8.0*atan(1.0) + fs=NSPS*12000.0/NSPS0 !Sample rate + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + ts=2*NSPS*dt !Duration of OQPSK symbols (s) + baud=1.0/tt !Keying rate for "itone" symbols (baud) + txt=NZ*dt !Transmission length (s) + + do i=1,32 !Half-sine pulse shape + pp(i)=sin(0.5*(i-1)*twopi/(32)) + enddo + n8=z'cbf089223a51' + do i=1,48 + isync(i)=-1 + if(iand(n8,1).eq.1) isync(i)=1 + n8=n8/2 + enddo + +! Define array id() for sync symbols + id=0 + do j=1,48 !First group of 48 + id(2*j-1)=2*isync(j) + enddo + do j=1,13 !Barker 13 code + id(j+96)=2*ib13(j) + enddo + do j=1,48 !Second group of 48 + id(2*j+109)=2*isync(j) + enddo + + csync=0. + do j=1,205 + if(abs(id(j)).eq.2) then + ia=nint((j-0.5)*N2) + ib=ia+N2-1 + csync(ia:ib)=pp*id(j)/abs(id(j)) + endif + enddo + + do ifile=iarg,nargs + call getarg(ifile,infile) + open(10,file=infile,status='old',access='stream') + j1=index(infile,'.c5') + j2=index(infile,'.wav') + if(j1.gt.0) then + read(10,end=999) fname,ntrmin,fMHz,c400 + read(fname(8:11),*) nutc + write(datetime,'(i11)') nutc + else if(j2.gt.0) then + read(10,end=999) ihdr,iwave + read(infile(j2-4:j2-1),*) nutc + datetime=infile(j2-11:j2-1) + call wspr5_downsample(iwave,c400) + else + print*,'Wrong file format?' + go to 999 + endif + close(10) + + fa=100.0 + fb=150.0 + fs400=400.0 + call getfc1(c400,fs400,fa,fb,fc1,xsnr) !First approx for freq +!write(*,*) datetime,'initial guess ',fc1 + npeaks=5 + call getfc2(c400,npeaks,fs400,fc1,fpks) !Refined freq + + do idf=1,npeaks ! consider the top npeak peaks + fc2=fpks(idf) + call downsample(c400,fc1+fc2,cd) + s2=sum(cd*conjg(cd))/(16*412) + cd=cd/sqrt(s2) + do is=0,8 ! dt search range is narrow, to save time. + idt=is/2 + if( mod(is,2).eq. 1 ) idt=-(is+1)/2 + xdt=real(22+idt)/22.222 - 1.0 + ca=cshift(cd,22+idt) + do iseq=1,3 ! try sequence estimation lengths of 3, 6, and 9 bits. + k=1-2*iseq + nseq=iseq*3 + do i=1,408,iseq*4 + k=k+iseq*2 + j=(i+1)*16 + call mskseqdet(nseq,ca(j),pp,id(k),softbits,1,phase) + hbits(i:i+iseq*4)=bits + sbits(i:i+iseq*4)=bits + + sbits(i+1)=softbits(1) + sbits(i+2)=softbits(2) + if( id(k+1) .ne. 0 ) sbits(i+2)=id(k+1)*25 + sbits(i+3)=softbits(3) + + if( iseq .ge. 2 ) then + sbits(i+5)=softbits(4) + sbits(i+6)=softbits(5) + if( id(k+3) .ne. 0 ) sbits(i+6)=id(k+3)*25 + sbits(i+7)=softbits(6) + if( iseq .eq. 3 ) then + sbits(i+9)=softbits(7) + sbits(i+10)=softbits(8) + if( id(k+5) .ne. 0 ) sbits(i+10)=id(k+5)*25 + sbits(i+11)=softbits(9) + endif + endif + enddo + j=1 + do i=1,205 + if( abs(id(i)) .ne. 2 ) then + rxdata(j)=sbits(2*i-1) + j=j+1 + endif + enddo + do i=1,204 + rxdata(j)=sbits(2*i) + j=j+1 + enddo + rxav=sum(rxdata)/ND + rx2av=sum(rxdata*rxdata)/ND + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig +! sigma=0.84 + sigma=1.20 + llr=2*rxdata/(sigma*sigma) + apmask=0 + max_iterations=40 + ifer=0 + nbadcrc=0 + call bpdecode300(llr,apmask,max_iterations,decoded,niterations,cw) +! niterations will be equal to the Hamming distance between hard received word and the codeword + if(niterations.lt.0) call osd300(llr,3,decoded,niterations,cw) + if(niterations.ge.0) call chkcrc10(decoded,nbadcrc) + if(niterations.lt.0 .or. nbadcrc.ne.0) ifer=1 + if( ifer.eq.0 ) then + write(cbits,1200) decoded(1:50) +1200 format(50i1) + read(cbits,1202) idat +1202 format(6b8,b2) + idat(7)=ishft(idat(7),6) + call wqdecode(idat,message,itype) + nsnr=nint(xsnr) + freq=fMHz + 1.d-6*(fc1+fc2) + nfdot=0 + write(13,1210) datetime,0,nsnr,xdt,freq,message,nfdot +1210 format(a11,2i4,f6.2,f12.7,2x,a22,i3) + write(*,1212) datetime(8:11),nsnr,xdt,freq,nfdot,message,'*',idf,nseq,is,niterations +1212 format(a4,i4,f5.1,f11.6,i3,2x,a22,a1,i3,i3,i3,i4) + goto 888 + endif + enddo !iseq + enddo + enddo +888 continue + enddo + + write(*,1120) +1120 format("") + +999 end program wspr5d + +subroutine getmetric(ib,ps,xmet) + real ps(0:511) + xm1=0 + xm0=0 + do i=0,511 + if( iand(i/ib,1) .eq. 1 .and. ps(i) .gt. xm1 ) xm1=ps(i) + if( iand(i/ib,1) .eq. 0 .and. ps(i) .gt. xm0 ) xm0=ps(i) + enddo + xmet=xm1-xm0 + return +end subroutine getmetric + +subroutine mskseqdet(ns,cdat,pp,bsync,softbits,ncoh,phase) +! +! Detect sequences of 3, 6, or 9 bits (ns). +! Sync bits are assumed to be known. +! +complex cdat(16*12),cbest(16*12),cideal(16*12) +complex cdf(16*12),cfac,zz +real cm(0:511),cmbest(0:511) +real pp(32),softbits(9) +integer bit(13),bestbits(13),sgn(13) +integer bsync(7) + +twopi=8.0*atan(1.0) +dt=30.0*18.0/12000.0 +cmax=0; +fbest=0.0; +np=2**ns-1 +idfmax=40 +if( ncoh .eq. 1 ) idfmax=0 +do idf=0,idfmax + if( mod(idf,2).eq.1 ) deltaf=idf/2*0.02 + if( mod(idf,2).eq.1 ) deltaf=-(idf+1)/2*0.02 + dphi=twopi*deltaf*dt + cfac=cmplx(cos(dphi),sin(dphi)) + cdf=1.0 + do i=2,16*(ns-1) + cdf(i)=cdf(i-1)*cfac + enddo + + cm=0 + ibflag=0 + do i=0,np + bit(1)=(bsync(1)+2)/4 + bit(2)=iand(i/(2**(ns-1)),1) + bit(3)=iand(i/(2**(ns-2)),1) + if( bsync(2).ne.0 ) then ! force the barker bits + bit(3)=(bsync(2)+2)/4 + endif + bit(4)=iand(i/(2**(ns-3)),1) + bit(5)=(bsync(3)+2)/4 + + if( ns .ge. 6 ) then + bit(6)=iand(i/(2**(ns-4)),1) + bit(7)=iand(i/(2**(ns-5)),1) + if( bsync(4).ne.0 ) then ! force the barker bits + bit(7)=(bsync(4)+2)/4 + endif + bit(8)=iand(i/(2**(ns-6)),1) + bit(9)=(bsync(5)+2)/4 + if( ns .eq. 9 ) then + bit(10)=iand(i/4,1) + bit(11)=iand(i/2,1) + if( bsync(6).ne.0 ) then ! force the barker bits + bit(11)=(bsync(6)+2)/4 + endif + bit(12)=iand(i/1,1) + bit(13)=(bsync(7)+2)/4 + endif + endif + + sgn=2*bit-1 + cideal(1:16) =cmplx(sgn(1)*pp(17:32),sgn(2)*pp(1:16)) + cideal(17:32) =cmplx(sgn(3)*pp(1:16),sgn(2)*pp(17:32)) + cideal(33:48) =cmplx(sgn(3)*pp(17:32),sgn(4)*pp(1:16)) + cideal(49:64) =cmplx(sgn(5)*pp(1:16),sgn(4)*pp(17:32)) + if( ns .ge. 6 ) then + cideal(65:80) =cmplx(sgn(5)*pp(17:32),sgn(6)*pp(1:16)) + cideal(81:96) =cmplx(sgn(7)*pp(1:16),sgn(6)*pp(17:32)) + cideal(97:112) =cmplx(sgn(7)*pp(17:32),sgn(8)*pp(1:16)) + cideal(113:128)=cmplx(sgn(9)*pp(1:16),sgn(8)*pp(17:32)) + if( ns .eq. 9 ) then + cideal(129:144) =cmplx(sgn(9)*pp(17:32),sgn(10)*pp(1:16)) + cideal(145:160) =cmplx(sgn(11)*pp(1:16),sgn(10)*pp(17:32)) + cideal(161:176) =cmplx(sgn(11)*pp(17:32),sgn(12)*pp(1:16)) + cideal(177:192)=cmplx(sgn(13)*pp(1:16),sgn(12)*pp(17:32)) + endif + endif + cideal=cideal*cdf + cm(i)=abs(sum(cdat(1:64*ns/3)*conjg(cideal(1:64*ns/3))))/1.e3 + if( cm(i) .gt. cmax ) then + ibflag=1 + cmax=cm(i) + bestbits=bit + cbest=cideal + fbest=deltaf + zz=sum(cdat*conjg(cbest))/1.e3 + phase=atan2(imag(zz),real(zz)) + endif + enddo + if( ibflag .eq. 1 ) then ! new best found + cmbest=cm + endif +enddo +softbits=0.0 +call getmetric(1,cmbest,softbits(ns)) +call getmetric(2,cmbest,softbits(ns-1)) +call getmetric(4,cmbest,softbits(ns-2)) +if( ns .ge. 6 ) then + call getmetric(8,cmbest,softbits(ns-3)) + call getmetric(16,cmbest,softbits(ns-4)) + call getmetric(32,cmbest,softbits(ns-5)) + if( ns .eq. 9 ) then + call getmetric(64,cmbest,softbits(3)) + call getmetric(128,cmbest,softbits(2)) + call getmetric(256,cmbest,softbits(1)) + endif +endif +end subroutine mskseqdet + +subroutine downsample(ci,f0,co) + parameter(NI=412*288,NO=NI/18) + complex ci(0:NI-1),ct(0:NI-1) + complex co(0:NO-1) + + df=400.0/NI + ct=ci + call four2a(ct,NI,1,-1,1) !c2c FFT to freq domain + i0=nint(f0/df) + co=0.0 + co(0)=ct(i0) + b=3.0 + do i=1,NO/2 + arg=(i*df/b)**2 + filt=exp(-arg) + co(i)=ct(i0+i)*filt + co(NO-i)=ct(i0-i)*filt + enddo + co=co/NO + call four2a(co,NO,1,1,1) !c2c FFT back to time domain + return +end subroutine downsample + +subroutine getfc1(c,fs,fa,fb,fc1,xsnr) + +! include 'wsprlf_params.f90' + parameter (NZ=288*412) + parameter (NSPS=288) + parameter (N2=2*NSPS) + parameter (NFFT1=16*NSPS) + parameter (NH1=NFFT1/2) + + complex c(0:NZ-1) !Complex waveform + complex c2(0:NFFT1-1) !Short spectra + real s(-NH1+1:NH1) !Coarse spectrum + nspec=NZ/N2 + df1=fs/NFFT1 + s=0. + do k=1,nspec + ia=(k-1)*N2 + ib=ia+N2-1 + c2(0:N2-1)=c(ia:ib) + c2(N2:)=0. + call four2a(c2,NFFT1,1,-1,1) + do i=0,NFFT1-1 + j=i + if(j.gt.NH1) j=j-NFFT1 + s(j)=s(j) + real(c2(i))**2 + aimag(c2(i))**2 + enddo + enddo +! call smo121(s,NFFT1) + smax=0. + ipk=0 + fc1=0. + ia=nint(fa/df1) + ib=nint(fb/df1) + do i=ia,ib + f=i*df1 + if(s(i).gt.smax) then + smax=s(i) + ipk=i + fc1=f + endif +! write(51,3001) f,s(i),db(s(i)) +! 3001 format(f10.3,e12.3,f10.3) + enddo + +! The following is for testing SNR calibration: + sp3n=(s(ipk-1)+s(ipk)+s(ipk+1)) !Sig + 3*noise + base=(sum(s)-sp3n)/(NFFT1-3.0) !Noise per bin + psig=sp3n-3*base !Sig only + pnoise=(2500.0/df1)*base !Noise in 2500 Hz + xsnr=db(psig/pnoise) + xsnr=xsnr+5.0 + return +end subroutine getfc1 + +subroutine getfc2(c,npeaks,fs,fc1,fpks) + +! include 'wsprlf_params.f90' + parameter (NZ=288*412) + parameter (NSPS=288) + parameter (N2=2*NSPS) + parameter (NFFT1=16*NSPS) + parameter (NH1=NFFT1/2) + + complex c(0:NZ-1) !Complex waveform + complex cs(0:NZ-1) !For computing spectrum + real a(5) + real freqs(413),sp2(413),fpks(npeaks) + integer pkloc(1) + + df=fs/NZ + baud=fs/NSPS + a(1)=-fc1 + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,cs) !Mix down by fc1 + +! Filter, square, then FFT to get refined carrier frequency fc2. + call four2a(cs,NZ,1,-1,1) !To freq domain + + ia=nint(0.75*baud/df) + cs(ia:NZ-1-ia)=0. !Save only freqs around fc1 +! do i=1,NZ/2 +! filt=1/(1+((i*df)**2/(0.50*baud)**2)**8) +! cs(i)=cs(i)*filt +! cs(NZ+1-i)=cs(NZ+1-i)*filt +! enddo + call four2a(cs,NZ,1,1,1) !Back to time domain + cs=cs/NZ + cs=cs*cs !Square the data + call four2a(cs,NZ,1,-1,1) !Compute squared spectrum +! Find two peaks separated by baud + pmax=0. + fc2=0. +! ja=nint(0.3*baud/df) + ja=nint(0.5*baud/df) + k=1 + sp2=0.0 + do j=-ja,ja + f2=j*df + ia=nint((f2-0.5*baud)/df) + if(ia.lt.0) ia=ia+NZ + ib=nint((f2+0.5*baud)/df) + p=real(cs(ia))**2 + aimag(cs(ia))**2 + & + real(cs(ib))**2 + aimag(cs(ib))**2 + if(p.gt.pmax) then + pmax=p + fc2=0.5*f2 + endif + freqs(k)=0.5*f2 + sp2(k)=p + k=k+1 +! write(52,1200) f2,p,db(p) +!1200 format(f10.3,2f15.3) + enddo + + do i=1,npeaks + pkloc=maxloc(sp2) + ipk=pkloc(1) + fpks(i)=freqs(ipk) + ipk0=max(1,ipk-2) + ipk1=min(413,ipk+2) +! ipk0=ipk +! ipk1=ipk + sp2(ipk0:ipk1)=0.0 + enddo + return +end subroutine getfc2 diff --git a/lib/fsk4hf/wspr5sim.f90 b/lib/fsk4hf/wspr5sim.f90 new file mode 100644 index 00000000..5c2147b9 --- /dev/null +++ b/lib/fsk4hf/wspr5sim.f90 @@ -0,0 +1,111 @@ +program wspr5sim + +! Generate simulated data for a 5-minute "WSPR-LF" mode. Output is saved +! to a *.c5 or *.wav file. + + use wavhdr + include 'wsprlf_params.f90' !Set various constants + parameter (NMAX=300*12000) + type(hdr) h !Header for .wav file + character arg*12,fname*16 + character msg*22,msgsent*22 + complex c0(0:NZ-1) + complex c(0:NZ-1) + real*8 fMHz + integer itone(NN) + integer*2 iwave(NMAX) !Generated full-length waveform + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.8) then + print*,'Usage: wspr5sim "message" f0 DT fsp del nwav nfiles snr' + print*,'Example: wspr5sim "K1ABC FN42 30" 50 0.0 0.1 1.0 1 10 -33' + go to 999 + endif + call getarg(1,msg) !Message to be transmitted + call getarg(2,arg) + read(arg,*) f0 !Freq relative to WSPR-band center (Hz) + call getarg(3,arg) + read(arg,*) xdt !Time offset from nominal (s) + call getarg(4,arg) + read(arg,*) fspread !Watterson frequency spread (Hz) + call getarg(5,arg) + read(arg,*) delay !Watterson delay (ms) + call getarg(6,arg) + read(arg,*) nwav !1 for *.wav file, 0 for *.c5 file + call getarg(7,arg) + read(arg,*) nfiles !Number of files + call getarg(8,arg) + read(arg,*) snrdb !SNR_2500 + + twopi=8.0*atan(1.0) + fs=12000.0/NDOWN !Sample rate + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + ts=2*NSPS*dt !Duration of OQPSK symbols (s) + baud=1.0/tt !Keying rate for "itone" symbols (baud) + txt=NZ*dt !Transmission length (s) + bandwidth_ratio=2500.0/(fs/2.0) + sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + txt=NN*NSPS0/12000.0 + + call genwspr5(msg,msgsent,itone) !Encode the message, get itone + write(*,1000) f0,xdt,txt,snrdb,fspread,delay,nfiles,msgsent +1000 format('f0:',f9.3,' DT:',f6.2,' txt:',f6.1,' SNR:',f6.1, & + ' fspread:',f6.1,' delay:',f6.1,' nfiles:',i3,2x,a22) + + dphi0=twopi*(f0-0.25*baud)*dt + dphi1=twopi*(f0+0.25*baud)*dt + phi=0.0 + c0=0. + k=-1 + nint(xdt/dt) + do j=1,NN !Generate OQPSK waveform from itone + dphi=dphi0 + if(itone(j).eq.1) dphi=dphi1 + if(k.eq.0) phi=-dphi + do i=1,NSPS + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + if(k.ge.0 .and. k.lt.NZ) c0(k)=cmplx(cos(xphi),sin(xphi)) + enddo + enddo + + call sgran() + do ifile=1,nfiles + c=c0 + if(nwav.eq.0) then + if( fspread .ne. 0.0 .or. delay .ne. 0.0 ) then + call watterson(c,NZ,fs,delay,fspread) + endif + c=c*sig + if(snrdb.lt.90) then + do i=0,NZ-1 !Add gaussian noise at specified SNR + xnoise=gran() + ynoise=gran() + c(i)=c(i) + cmplx(xnoise,ynoise) + enddo + endif + write(fname,1100) ifile +1100 format('000000_',i4.4,'.c5') + open(10,file=fname,status='unknown',access='stream') + fMHz=10.1387d0 + nmin=5 + write(10) fname,nmin,fMHz,c !Save to *.c5 file + close(10) + else + call wspr5_wav(baud,xdt,f0,itone,snrdb,iwave) + h=default_header(12000,NMAX) + write(fname,1102) ifile +1102 format('000000_',i4.4,'.wav') + open(10,file=fname,status='unknown',access='stream') + write(10) h,iwave !Save to *.wav file + close(10) + endif + write(*,1110) ifile,xdt,f0,snrdb,fname +1110 format(i4,f7.2,f8.2,f7.1,2x,a16) + enddo + +999 end program wspr5sim diff --git a/lib/fsk4hf/wspr_fsk8_downsample.f90 b/lib/fsk4hf/wspr_fsk8_downsample.f90 new file mode 100644 index 00000000..9750e0cb --- /dev/null +++ b/lib/fsk4hf/wspr_fsk8_downsample.f90 @@ -0,0 +1,27 @@ +subroutine wspr_fsk8_downsample(iwave,c) + +! Input: i*2 data in iwave() at sample rate 12000 Hz +! Output: Complex data in c(), sampled at 12000/24=500 Hz + + include 'wspr_fsk8_params.f90' + integer*2 iwave(NMAX) + complex c(0:NMAXD-1) + complex c1(0:NMAXD-1) + complex cx(0:NMAX/2) + real x(NMAX) + equivalence (x,cx) + + df=12000.0/NMAX + x=iwave + call four2a(x,NMAX,1,-1,0) !r2c FFT to freq domain + i0=nint(1500.0/df) + c1(0)=cx(i0) + do i=1,NMAXD/2 + c1(i)=cx(i0+i) + c1(NMAXD-i)=cx(i0-i) + enddo + c=c1/NMAXD + call four2a(c,NMAXD,1,1,1) !c2c FFT back to time domain + + return +end subroutine wspr_fsk8_downsample diff --git a/lib/fsk4hf/wspr_fsk8_params.f90 b/lib/fsk4hf/wspr_fsk8_params.f90 new file mode 100644 index 00000000..c080f029 --- /dev/null +++ b/lib/fsk4hf/wspr_fsk8_params.f90 @@ -0,0 +1,14 @@ +! LDPC (300,60) code +parameter (NDOWN=24) !Downsample factor +parameter (KK=60) !Information bits (50 + CRC10) +parameter (ND=100) !Data symbols +parameter (NS=14) !Sync symbols (2 @ Costas 7x7) +parameter (NN=NS+ND) !Total symbols (114) +parameter (NSPS0=24576) !Samples per symbol at 12000 S/s +parameter (NSPS=NSPS0/NDOWN) !Sam/sym, downsampled (1024) +parameter (N7=7*NSPS) !Samples in Costas 7x7 array (7168) +parameter (NZ=NSPS*NN) !Samples in downsampled waveform (116,736) +parameter (NMAX=240*12000) !Samples in iwave() +parameter (NMAXD=NMAX/24) !Samples in c(), after downsampling +parameter (NFFT1=4*NSPS,NH1=NFFT1/2) +parameter (NH2=NSPS/2) diff --git a/lib/fsk4hf/wspr_fsk8_sim.f90 b/lib/fsk4hf/wspr_fsk8_sim.f90 new file mode 100644 index 00000000..40d808a0 --- /dev/null +++ b/lib/fsk4hf/wspr_fsk8_sim.f90 @@ -0,0 +1,107 @@ +program wspr_fsk8_sim + +! Generate simulated data for a 4-minute "WSPR-LF" mode using 8-FSK. +! Output is saved to a *.wav file. + + use wavhdr + include 'wspr_fsk8_params.f90' !Set various constants + type(hdr) h !Header for .wav file + character arg*12,fname*16 + character msg*22,msgsent*22 + complex c0(0:NZ-1) + complex c(0:NZ-1) + real*8 fMHz + integer itone(NN) + integer*2 iwave(NMAX) !Generated full-length waveform + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.8) then + print*,'Usage: wspr5sim "message" f0 DT fsp del nwav nfiles snr' + print*,'Example: wspr5sim "K1ABC FN42 30" 50 0.0 0.1 1.0 1 10 -33' + go to 999 + endif + call getarg(1,msg) !Message to be transmitted + call getarg(2,arg) + read(arg,*) f0 !Freq relative to WSPR-band center (Hz) + call getarg(3,arg) + read(arg,*) xdt !Time offset from nominal (s) + call getarg(4,arg) + read(arg,*) fspread !Watterson frequency spread (Hz) + call getarg(5,arg) + read(arg,*) delay !Watterson delay (ms) + call getarg(6,arg) + read(arg,*) nwav !1 for *.wav file, 0 for *.c4 file + call getarg(7,arg) + read(arg,*) nfiles !Number of files + call getarg(8,arg) + read(arg,*) snrdb !SNR_2500 + + twopi=8.0*atan(1.0) + fs=12000.0/NDOWN !Sample rate after downsampling + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of symbols (s) + baud=1.0/tt !Keying rate + bw=8*baud + txt=NZ*dt !Transmission length (s) + bandwidth_ratio=2500.0/(fs/2.0) + sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + txt=NN*NSPS0/12000.0 + + call genwspr_fsk8(msg,msgsent,itone) !Encode the message, get itone + write(*,1000) f0,xdt,txt,snrdb,bw,msgsent +1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1, & + ' BW:',f4.1,2x,a22) + + + phi=0.0 + c0=0. + k=-1 + nint(xdt/dt) + do j=1,NN !Generate OQPSK waveform from itone + dphi=twopi*(f0+itone(j)*baud)*dt + if(k.eq.0) phi=-dphi + do i=1,NSPS + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + if(k.ge.0 .and. k.lt.NZ) c0(k)=cmplx(cos(xphi),sin(xphi)) + enddo + enddo + + call sgran() + do ifile=1,nfiles + if(nwav.eq.0) then + c=c0 + if( fspread .ne. 0.0 .or. delay .ne. 0.0 ) then + call watterson(c,NZ,fs,delay,fspread) + endif + c=c*sig + if( snrdb.lt.90) then + do i=0,NZ-1 + xnoise=gran() + ynoise=gran() + c(i)=c(i)+cmplx(xnoise,ynoise) + enddo + endif + write(fname,1100) ifile +1100 format('000000_',i4.4,'.c4') + open(10,file=fname,status='unknown',access='stream') + fMHz=1.866d0 + nmin=4 + write(10) fname,nmin,fMHz,c + else + call wspr_fsk8_wav(baud,xdt,f0,itone,snrdb,iwave) + h=default_header(12000,NMAX) + write(fname,1102) ifile +1102 format('000000_',i4.4,'.wav') + open(10,file=fname,status='unknown',access='stream') + write(10) h,iwave !Save to *.wav file + close(10) + endif + write(*,1110) ifile,xdt,f0,snrdb,fname +1110 format(i4,f7.2,f8.2,f7.1,2x,a16) + enddo + +999 end program wspr_fsk8_sim diff --git a/lib/fsk4hf/wspr_fsk8_wav.f90 b/lib/fsk4hf/wspr_fsk8_wav.f90 new file mode 100644 index 00000000..3b0a0ff3 --- /dev/null +++ b/lib/fsk4hf/wspr_fsk8_wav.f90 @@ -0,0 +1,44 @@ +subroutine wspr_fsk8_wav(baud,xdt,f0,itone,snrdb,iwave) + +! Generate iwave() from itone(). + + include 'wspr_fsk8_params.f90' + integer itone(NN) + integer*2 iwave(NMAX) + real*8 twopi,dt,dphi,phi + real dat(NMAX) + + twopi=8.d0*atan(1.d0) + dt=1.d0/12000.d0 + + dat=0. + if(snrdb.lt.90) then + do i=1,NMAX + dat(i)=gran() !Generate gaussian noise, rms = 1.0 + enddo + bandwidth_ratio=2500.0/6000.0 + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb) + else + sig=1.0 + endif + + phi=0.d0 + k=nint((xdt+1.0)/dt) + do j=1,NN + dphi=twopi*(f0+ itone(j)*baud)*dt + if(k.eq.0) phi=-dphi + do i=1,NSPS0 + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + if(k.gt.0 .and. k.le.NMAX) dat(k)=dat(k) + sig*sin(xphi) + enddo + enddo + fac=32767.0 + rms=100.0 + if(snrdb.ge.90.0) iwave=nint(fac*dat) + if(snrdb.lt.90.0) iwave=nint(rms*dat) + + return +end subroutine wspr_fsk8_wav diff --git a/lib/fsk4hf/wspr_fsk8d.f90 b/lib/fsk4hf/wspr_fsk8d.f90 new file mode 100644 index 00000000..c107f848 --- /dev/null +++ b/lib/fsk4hf/wspr_fsk8d.f90 @@ -0,0 +1,196 @@ +program wspr_fsk8d + +! WSPR-LF is a potential WSPR-like mode intended for use at LF and MF. +! This version uses 4-minute T/R sequences, an LDPC (300,60) code, +! 8-FSK modulation, and noncoherent demodulation. This decoder reads +! data from *.wav files. + +! Reception and Demodulation algorithm: +! 1. Compute coarse spectrum; find fc1 = approx carrier freq +! 2. Mix from fc1 to 0; LPF at +/- 0.75*R +! 3. Find two 7x7 Costas arrays to get xdt and fc2 +! 4. Mix from fc2 to 0, compute aligned symbol spectra +! 5. Get soft bits from symbol spectra + +! Still to do: find and decode more than one signal in the specified passband. + + include 'wspr_fsk8_params.f90' + character arg*8,message*22,cbits*50,infile*80,fname*16,datetime*11 + character*120 data_dir + complex csync(0:N7-1) !Sync symbols for Costas 7x7 array + complex c1(0:2*N7-1) + complex c2(0:2*N7-1) + complex c(0:NMAXD-1) !Complex waveform + real*8 fMHz + real rxdata(3*ND),llr(3*ND) !Soft symbols + real a(5) !For twkfreq1 + real s(0:NH2,NN) + real savg(0:NH2) + real ss(0:N7) + real ss0(0:N7) + real ps(0:7) + integer ihdr(11) + integer*2 iwave(NMAX) !Generated full-length waveform + integer*1 idat(7) + integer*1 decoded(KK),apmask(3*ND),cw(3*ND) + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ !Costas 7x7 tone pattern + + nargs=iargc() + if(nargs.lt.7) then + print*,'Usage: wspr_fsk8d -d db -f fMHz -a data_dir file1 [file2 ...]' + go to 999 + endif + call getarg(1,arg) + if(arg(1:3).ne.'-d ') go to 999 + call getarg(2,arg) + read(arg,*) degrade + rxbw=3000. + + call getarg(3,arg) + if(arg(1:3).ne.'-f ') go to 999 + call getarg(4,arg) + read(arg,*) fMHz + + call getarg(5,arg) + if(arg(1:3).ne.'-a ') go to 999 + call getarg(6,data_dir) + + open(13,file=trim(data_dir)//'/ALL_WSPR.TXT',status='unknown', & + position='append') + + twopi=8.0*atan(1.0) + fs=NSPS*12000.0/NSPS0 !Sample rate after downsampling (Hz) + dt=1.0/fs !Sample interval (s) + ts=NSPS*dt !Symbol duration (s) + baud=1.0/ts !Keying rate (Hz) + txt=NZ*dt !Transmission length (s) + + phi=0. + k=-1 + do j=0,6 + dphi=twopi*baud*icos7(j)*dt + do i=1,NSPS + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + k=k+1 + csync(k)=cmplx(cos(phi),sin(phi)) + enddo + enddo + + do ifile=7,nargs + call getarg(ifile,infile) + open(10,file=infile,status='old',access='stream') + j1=index(infile,'.c4') + j2=index(infile,'.wav') + if(j1.gt.0) then + read(10,end=999) fname,ntrmin,fMHz,c(0:NZ-1) + read(fname(8:11),*) nutc + write(datetime,'(i11)') nutc + else if(j2.gt.0) then + read(10,end=999) ihdr,iwave + read(infile(j2-4:j2-1),*) nutc + datetime=infile(j2-11:j2-1) + if(degrade.gt.0.0) call degrade_snr(iwave,NMAX,degrade,rxbw) + call wspr_fsk8_downsample(iwave,c) + else + print*,'Wrong file format?' + go to 999 + endif + close(10) + pmax=0. + df1=fs/(2*N7) + ia=nint(100.0/df1) + ib=nint(150.0/df1) + ipk=0 + jpk=0 +! Get xdt and f0 from the sync arrays + do j0=0,1000,50 + j0b=j0+107*NSPS + c1(0:N7-1)=c(j0:j0+N7-1)*conjg(csync) + c1(N7:)=0. + c2(0:N7-1)=c(j0b:j0b+N7-1)*conjg(csync) + c2(N7:)=0. + call four2a(c1,2*N7,1,-1,1) + call four2a(c2,2*N7,1,-1,1) + do i=0,N7 + p=1.e-9*(real(c1(i))**2 + aimag(c1(i))**2 + & + real(c2(i))**2 + aimag(c2(i))**2) + ss(i)=p + enddo + do i=ia,ib + p=ss(i) + if(p.gt.pmax) then + pmax=p + ipk=i + jpk=j0 + endif + enddo + if(jpk.eq.j0) ss0=ss + enddo + f0=ipk*df1 + xdt=jpk*dt - 1.0 + + sp3n=(ss0(ipk-1)+ss0(ipk)+ss0(ipk+1)) !Sig + 3*noise + call pctile(ss0,N7,45,base) + psig=sp3n-3*base !Sig only + pnoise=(2500.0/df1)*base !Noise in 2500 Hz + xsnr=db(psig/pnoise) !SNR from sync tones + + if(jpk.ge.0) c(0:NMAXD-1-jpk)=c(jpk:NMAXD-1) + + a(1)=-f0 + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,c) !Mix from f0 down to 0 + call spec8(c,s,savg) !Get symbol spectra + + do j=1,ND + k=j+7 + ps=s(0:7,k) + ! ps=sqrt(ps) !### ??? ### + ps=log(ps) + r1=max(ps(1),ps(3),ps(5),ps(7))-max(ps(0),ps(2),ps(4),ps(6)) + r2=max(ps(2),ps(3),ps(6),ps(7))-max(ps(0),ps(1),ps(4),ps(5)) + r4=max(ps(4),ps(5),ps(6),ps(7))-max(ps(0),ps(1),ps(2),ps(3)) + rxdata(3*j-2)=r4 + rxdata(3*j-1)=r2 + rxdata(3*j)=r1 + enddo + + rxav=sum(rxdata)/ND + rx2av=sum(rxdata*rxdata)/ND + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + s0=0.84 + llr=2.0*rxdata/(s0*s0) + apmask=0 + max_iterations=40 + ifer=0 + call bpdecode300(llr,apmask,max_iterations,decoded,niterations,cw) + if(niterations.lt.0) call osd300(llr,4,decoded,niterations,cw) + nbadcrc=0 + if(niterations.ge.0) call chkcrc10(decoded,nbadcrc) + if(niterations.lt.0 .or. nbadcrc.ne.0) ifer=1 + nsnr=nint(xsnr) +! freq=fMHz + 1.d-6*f0 + freq=1.d-6*(f0+1500) + nfdot=0 + message=' ' + if(ifer.eq.0) then + write(cbits,1100) decoded(1:50) +1100 format(50i1) + read(cbits,1102) idat +1102 format(6b8,b2) + idat(7)=ishft(idat(7),6) + call wqdecode(idat,message,itype) + write(*,1112) datetime(8:11),nsnr,xdt,freq,nfdot,message +1112 format(a4,i4,f5.1,f11.6,i3,2x,a22) + endif + write(13,1110) datetime,0,nsnr,xdt,freq,message,nfdot +1110 format(a11,2i4,f6.2,f12.7,2x,a22,i3) + enddo ! ifile loop + write(*,1120) +1120 format("") + +999 end program wspr_fsk8d + diff --git a/lib/fsk4hf/wsprlf.f90 b/lib/fsk4hf/wsprlf.f90 new file mode 100644 index 00000000..efc3e846 --- /dev/null +++ b/lib/fsk4hf/wsprlf.f90 @@ -0,0 +1,110 @@ +program wsprlf + + parameter (NN=121) !Total symbols + parameter (NSPS=28800) !Samples per symbol @ fs=12000 Hz + parameter (NZ=NSPS*NN) !Samples in waveform + + character*8 arg + complex c(0:NZ-1) + real*8 twopi,fs,f0,dt,phi,dphi + real x(0:NZ-1) + real p(0:NZ/2) + real h0(0:NSPS/2) !Pulse shape, rising edge + real h1(0:NSPS/2) !Pulse shape, trailing edge + real tmp(NN) + integer id(NN) !Generated data + integer ie(NN) !Differentially encoded data + data fs/12000.d0/ + + nargs=iargc() + if(nargs.ne.3) then + print*,'Usage: wsprlf f0 t1 snr' + goto 999 + endif + call getarg(1,arg) + read(arg,*) f0 + call getarg(2,arg) + read(arg,*) t1 + call getarg(3,arg) + read(arg,*) snrdb + + call random_number(tmp) !Generate random bipolar data + id=1 + where(tmp.lt.0.5) id=-1 + ie(1)=1 + do i=2,NN !Differentially encode + ie(i)=id(i)*ie(i-1) + enddo + + n1=nint(t1*NSPS) + twopi=8.d0*atan(1.d0) + + do i=0,2*n1-1 !Define the shape functions + if(i.le.n1-1) then + h0(i)=0.5*(1.0-cos(0.5*i*twopi/n1)) + else + h1(i-n1)=0.5*(1.0-cos(0.5*i*twopi/n1)) + endif + enddo + if(t1.eq.0.0) h0=1 + if(t1.eq.0.0) h1=1 + +! Shape the channel pulses + x=1. + x(0:n1-1)=h0(0:n1-1) !Leading edge of 1st pulse + do j=2,NN !Leading edges + if(ie(j).ne.ie(j-1)) then + ia=(j-1)*NSPS + 1 + ib=ia+n1-1 + x(ia:ib)=h0(0:n1-1) + endif + enddo + do j=1,NN-1 !Trailing edges + if(ie(j+1).ne.ie(j)) then + ib=j*NSPS + ia=ib-n1+1 + x(ia:ib)=h1(0:n1-1) + endif + enddo + ib=NN*NSPS-1 + ia=ib-n1+1 + x(ia:ib)=h1(0:n1-1) !Trailing edge of last pulse + + dt=1.d0/fs + ts=dt*NSPS + baud=fs/NSPS + write(*,1000) baud,ts +1000 format('Baud:',f6.3,' Tsym:',f6.3) + + dphi=twopi*f0*dt + phi=0.d0 + i=-1 + do j=1,NN !Generate the baseband waveform + a=ie(j) + do k=1,NSPS + i=i+1 + x(i)=a*x(i) + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + c(i)=x(i)*cmplx(cos(xphi),sin(xphi)) + sym=i*dt/ts + if(j.le.20) write(13,1010) sym,x(i),c(i) +1010 format(4f12.6) + enddo + enddo + + call four2a(c,NZ,1,-1,1) !To freq domain + df=fs/NZ + nh=NZ/2 + do i=0,nh + f=i*df + p(i)=real(c(i))**2 + aimag(c(i))**2 + enddo + p=p/maxval(p) + do i=0,nh !Save spectrum for plotting + write(14,1020) i*df,p(i),10.0*log10(p(i)+1.e-8) +1020 format(f10.3,2e12.3) + enddo + +999 end program wsprlf diff --git a/lib/fsk4hf/wsprlf_params.f90 b/lib/fsk4hf/wsprlf_params.f90 new file mode 100644 index 00000000..d0c3f5c7 --- /dev/null +++ b/lib/fsk4hf/wsprlf_params.f90 @@ -0,0 +1,14 @@ +!parameter (NDOWN=540) !Downsample factor (default 540) +parameter (NDOWN=30) !Downsample factor (default 540) +parameter (KK=60) !Information bits (50 + CRC10) +parameter (ND=300) !Data symbols: LDPC (300,60), r=1/5 +parameter (NS=109) !Sync symbols (2 x 48 + Barker 13) +parameter (NR=3) !Ramp up/down +parameter (NN=NR+NS+ND) !Total symbols (412) +parameter (NSPS0=8640) !Samples per symbol at 12000 S/s +parameter (NSPS=NSPS0/NDOWN) !Samples per MSK symbol (16) +parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) +parameter (N13=13*N2) !Samples in central sync vector (416) +parameter (NZ=NSPS*NN) !Samples in baseband waveform (6592) +parameter (NZMAX=NSPS0*NN) +parameter (NFFT1=4*NSPS,NH1=NFFT1/2) diff --git a/lib/fsk4hf/wsprlfsim.f90 b/lib/fsk4hf/wsprlfsim.f90 new file mode 100644 index 00000000..542d4816 --- /dev/null +++ b/lib/fsk4hf/wsprlfsim.f90 @@ -0,0 +1,285 @@ +program wsprlfsim + +! Simulate characteristics of a potential "WSPR-LF" mode using LDPC (300,60) +! code, OQPSK modulation, and 5 minute T/R sequences. + +! Reception and Demodulation algorithm: +! 1. Compute coarse spectrum; find fc1 = approx carrier freq +! 2. Mix from fc1 to 0; LPF at +/- 0.75*R +! 3. Square, FFT; find peaks near -R/2 and +R/2 to get fc2 +! 4. Mix from fc2 to 0 +! 5. Fit cb13 (central part of csync) to c -> lag, phase +! 6. Fit complex ploynomial for channel equalization +! 7. Get soft bits from equalized data + + include 'wsprlf_params.f90' + +! Q: Would it be better for central Sync array to use both I and Q channels? + + character*8 arg + complex cbb(0:NZ-1) !Complex baseband waveform + complex csync(0:NZ-1) !Sync symbols only, from cbb + complex c(0:NZ-1) !Complex waveform + complex c0(0:NZ-1) !Complex waveform + complex c1(0:NZ-1) !Complex waveform + complex zz(NS+ND) !Complex symbol values (intermediate) + complex z + real xnoise(0:NZ-1) !Generated random noise + real ynoise(0:NZ-1) !Generated random noise + real rxdata(ND),llr(ND) !Soft symbols + real pp(2*NSPS) !Shaped pulse for OQPSK + real a(5) !For twkfreq1 + real aa(20),bb(20) !Fitted polyco's + real t(11) + character*12 label(11) + integer*8 count0,count1,count2,count3,clkfreq + integer nc(11) + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + integer ierror(NS+ND) + integer icw(NN) + integer itone(NN) + integer*1 msgbits(KK),decoded(KK),apmask(ND),cw(ND) +! integer*1 codeword(ND) + data msgbits/0,0,1,0,0,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,1, & + 1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,1,1,0,1,1,0,1,0,1,1,0,0,1,1/ + data label/'genwsprlf','twkfreq1 a','watterson','noise gen','getfc1w', & + 'getfc2w','twkfreq1 b','xdt loop','cpolyfitw','msksoftsym', & + 'bpdecode300'/ + + nargs=iargc() + if(nargs.ne.6) then + print*,'Usage: wsprlfsim f0(Hz) delay(ms) fspread(Hz) maxn iters snr(dB)' + print*,'Example: wsprlfsim 0 0 0 5 10 -20' + print*,'Set snr=0 to cycle through a range' + go to 999 + endif + call getarg(1,arg) + read(arg,*) f0 !Generated carrier frequency + call getarg(2,arg) + read(arg,*) delay !Delta_t (ms) for Watterson model + call getarg(3,arg) + read(arg,*) fspread !Fspread (Hz) for Watterson model + call getarg(4,arg) + read(arg,*) maxn !Max nterms for polyfit + call getarg(5,arg) + read(arg,*) iters !Iterations at each SNR + call getarg(6,arg) + read(arg,*) snrdb !Specified SNR_2500 + + nc=0 + twopi=8.0*atan(1.0) + fs=NSPS*12000.0/NSPS0 !Sample rate = 22.2222... Hz + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + ts=2*NSPS*dt !Duration of OQPSK symbols (s) + baud=1.0/tt !Keying rate for "itone" symbols (baud) + txt=NZ*dt !Transmission length (s) + bandwidth_ratio=2500.0/(fs/2.0) + write(*,1000) fs,f0,delay,fspread,maxn,baud,3*baud,txt,iters +1000 format('fs:',f10.3,' f0:',f5.1,' Delay:',f4.1,' fSpread:',f5.2, & + ' maxn:',i3,/'Baud:',f8.3,' BW:',f5.1,' TxT:',f6.1,' iters:',i4/) + write(*,1004) +1004 format(/' SNR sync data ser ber fer fsigma tsigma', & + ' tsec'/68('-')) + + do i=1,N2 !Half-sine pulse shape + pp(i)=sin(0.5*(i-1)*twopi/(2*NSPS)) + enddo + + t=0. + call system_clock(count0,clkfreq) + call genwsprlf(msgbits,id,icw,cbb,csync,itone)!Generate baseband waveform + call system_clock(count1,clkfreq) + t(1)=float(count1-count0)/float(clkfreq) + nc(1)=nc(1)+1 + do i=0,NZ-1 + write(40,4001) i,cbb(i),csync(i) +4001 format(i8,4f12.6) + enddo + + call system_clock(count0,clkfreq) + a=0. + a(1)=f0 + call twkfreq1(cbb,NZ,fs,a,c0) !Mix baseband to specified frequency + call system_clock(count1,clkfreq) + t(2)=float(count1-count0)/float(clkfreq) + nc(2)=nc(2)+1 + + isna=-20 + isnb=-40 + if(snrdb.ne.0.0) then + isna=nint(snrdb) + isnb=isna + endif + do isnr=isna,isnb,-1 !Loop over SNR range + if(isna.ne.isnb) snrdb=isnr + sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + nhard=0 + nhardsync=0 + nfe=0 + sqf=0. + sqt=0. + + call system_clock(count2,clkfreq) + do iter=1,iters !Loop over requested iterations + c=c0 + + call system_clock(count0,clkfreq) + if(delay.ne.0.0 .or. fspread.ne.0.0) then + call watterson(c,NZ,fs,delay,fspread) + endif + call system_clock(count1,clkfreq) + t(3)=t(3)+float(count1-count0)/float(clkfreq) + nc(3)=nc(3)+1 + + call system_clock(count0,clkfreq) + c=sig*c !Scale to requested SNR + if(snrdb.lt.90) then + do i=0,NZ-1 !Generate gaussian noise + xnoise(i)=gran() + ynoise(i)=gran() + enddo + c=c + cmplx(xnoise,ynoise) !Add AWGN noise + endif + call system_clock(count1,clkfreq) + t(4)=t(4)+float(count1-count0)/float(clkfreq) + nc(4)=nc(4)+1 + + call system_clock(count0,clkfreq) + call getfc1w(c,fs,fc1) !First approx for freq + call system_clock(count1,clkfreq) + t(5)=t(5)+float(count1-count0)/float(clkfreq) + nc(5)=nc(5)+1 + + call system_clock(count0,clkfreq) + call getfc2w(c,csync,fs,fc1,fc2,fc3) !Refined freq + call system_clock(count1,clkfreq) + t(6)=t(6)+float(count1-count0)/float(clkfreq) + nc(6)=nc(6)+1 + sqf=sqf + (fc1+fc2-f0)**2 + + call system_clock(count0,clkfreq) +!NB: Measured performance is about equally good using fc2 or fc3 here: + a(1)=-(fc1+fc2) + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,c) !Mix c down by fc1+fc2 + call system_clock(count1,clkfreq) + t(7)=t(7)+float(count1-count0)/float(clkfreq) + nc(7)=nc(7)+1 + +! The following may not be necessary? +! z=sum(c(3088:3503)*cb13)/208.0 !Get phase from Barker 13 vector +! z0=z/abs(z) +! c=c*conjg(z0) + + call system_clock(count0,clkfreq) +!---------------------------------------------------------------- DT +! Not presently used: + amax=0. + jpk=0 + iaa=0 + ibb=NZ-1 + do j=-20*NSPS,20*NSPS,NSPS/8 + ia=j + ib=NZ-1+j + if(ia.lt.0) then + ia=0 + iaa=-j + else + iaa=0 + endif + if(ib.gt.NZ-1) then + ib=NZ-1 + ibb=NZ-1-j + endif + z=sum(c(ia:ib)*conjg(csync(iaa:ibb))) + if(abs(z).gt.amax) then + amax=abs(z) + jpk=j + endif + enddo + xdt=jpk/fs + sqt=sqt + xdt**2 + call system_clock(count1,clkfreq) + t(8)=t(8)+float(count1-count0)/float(clkfreq) + nc(8)=nc(8)+1 + +!----------------------------------------------------------------- + + nterms=maxn + c1=c + do itry=1,20 + idf=itry/2 + if(mod(itry,2).eq.0) idf=-idf + nhard0=0 + nhardsync0=0 + ifer=1 + a(1)=idf*0.00085 + a(2:5)=0. + call system_clock(count0,clkfreq) + call twkfreq1(c1,NZ,fs,a,c) !Mix c1 into c + call cpolyfitw(c,pp,id,maxn,aa,bb,zz,nhs) + call system_clock(count1,clkfreq) + t(9)=t(9)+float(count1-count0)/float(clkfreq) + nc(9)=nc(9)+1 + + call system_clock(count0,clkfreq) + call msksoftsymw(zz,aa,bb,id,nterms,ierror,rxdata,nhard0,nhardsync0) + call system_clock(count1,clkfreq) + t(10)=t(10)+float(count1-count0)/float(clkfreq) + nc(10)=nc(10)+1 + + if(nhardsync0.gt.35) cycle + rxav=sum(rxdata)/ND + rx2av=sum(rxdata*rxdata)/ND + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + ss=0.84 + llr=2.0*rxdata/(ss*ss) + apmask=0 + max_iterations=40 + ifer=0 + call system_clock(count0,clkfreq) + call bpdecode300(llr,apmask,max_iterations,decoded,niterations,cw) + call system_clock(count1,clkfreq) + t(11)=t(11)+float(count1-count0)/float(clkfreq) + nc(11)=nc(11)+1 + nbadcrc=0 + if(niterations.ge.0) call chkcrc10(decoded,nbadcrc) + if(niterations.lt.0 .or. count(msgbits.ne.decoded).gt.0 .or. & + nbadcrc.ne.0) ifer=1 + if(ifer.eq.0) exit + enddo !Freq dither loop + nhard=nhard+nhard0 + nhardsync=nhardsync+nhardsync0 + nfe=nfe+ifer + if(nhardsync0+nhard0+niterations+ifer.gt.0) write(42,1045) snrdb, & + nhardsync0,nhard0,niterations,ifer,xdt +1045 format(f6.1,4i6,f8.2) + enddo + call system_clock(count3,clkfreq) + tsec=float(count3-count2)/float(clkfreq) + + fsigma=sqrt(sqf/iters) + tsigma=sqrt(sqt/iters) + ser=float(nhardsync)/(NS*iters) + ber=float(nhard)/(ND*iters) + fer=float(nfe)/iters + write(*,1050) snrdb,nhardsync,nhard,ser,ber,fer,fsigma,tsigma,tsec +1050 format(f6.1,2i7,2f8.4,f7.3,2f8.2f8.3) + enddo + + write(*,1060) NS*iters,ND*iters +1060 format(68('-')/6x,2i7) + + write(*,1065) +1065 format(/'Timing sec frac calls'/39('-')) + do i=1,11 + write(*,1070) label(i),t(i),t(i)/sum(t),nc(i) +1070 format(a12,2f9.3,i8) + enddo + write(*,1072) sum(t),1.0 +1072 format(39('-')/12x,2f10.3) + +999 end program wsprlfsim diff --git a/lib/ft8_decode.f90 b/lib/ft8_decode.f90 new file mode 100644 index 00000000..61984932 --- /dev/null +++ b/lib/ft8_decode.f90 @@ -0,0 +1,139 @@ +module ft8_decode + + type :: ft8_decoder + procedure(ft8_decode_callback), pointer :: callback + contains + procedure :: decode + end type ft8_decoder + + abstract interface + subroutine ft8_decode_callback (this,sync,snr,dt,freq,decoded,nap,qual) + import ft8_decoder + implicit none + class(ft8_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + real, intent(in) :: freq + character(len=22), intent(in) :: decoded + integer, intent(in) :: nap + real, intent(in) :: qual + end subroutine ft8_decode_callback + end interface + +contains + + subroutine decode(this,callback,iwave,nQSOProgress,nfqso,nftx,newdat, & + nutc,nfa,nfb,nexp_decode,ndepth,nagain,lapon,napwid,mycall12, & + mygrid6,hiscall12,hisgrid6) +! use wavhdr + use timer_module, only: timer + include 'fsk4hf/ft8_params.f90' +! type(hdr) h + + class(ft8_decoder), intent(inout) :: this + procedure(ft8_decode_callback) :: callback + real s(NH1,NHSYM) + real sbase(NH1) + real candidate(3,200) + real dd(15*12000) + logical, intent(in) :: lapon,nagain + logical newdat,lsubtract,ldupe,bcontest + character*12 mycall12, hiscall12 + character*6 mygrid6,hisgrid6 + integer*2 iwave(15*12000) + integer apsym(KK) + character datetime*13,message*22 + character*22 allmessages(100) + integer allsnrs(100) + save s,dd + + bcontest=iand(nexp_decode,128).ne.0 + this%callback => callback + write(datetime,1001) nutc !### TEMPORARY ### +1001 format("000000_",i6.6) + + call ft8apset(mycall12,mygrid6,hiscall12,hisgrid6,bcontest,apsym,iaptype) + dd=iwave + ndecodes=0 + allmessages=' ' + allsnrs=0 + ifa=nfa + ifb=nfb + if(nagain) then + ifa=nfqso-10 + ifb=nfqso+10 + endif + +! For now: +! ndepth=1: no subtraction, 1 pass, belief propagation only +! ndepth=2: subtraction, 3 passes, belief propagation only +! ndepth=3: subtraction, 3 passes, bp+osd + if(ndepth.eq.1) npass=1 + if(ndepth.ge.2) npass=3 + do ipass=1,npass + newdat=.true. ! Is this a problem? I hijacked newdat. + syncmin=1.5 + if(ipass.eq.1) then + lsubtract=.true. + if(ndepth.eq.1) lsubtract=.false. + elseif(ipass.eq.2) then + n2=ndecodes + if(ndecodes.eq.0) cycle + lsubtract=.true. + elseif(ipass.eq.3) then + if((ndecodes-n2).eq.0) cycle + lsubtract=.false. + endif + + call timer('sync8 ',0) + call sync8(dd,ifa,ifb,syncmin,nfqso,s,candidate,ncand,sbase) + call timer('sync8 ',1) + do icand=1,ncand + sync=candidate(3,icand) + f1=candidate(1,icand) + xdt=candidate(2,icand) + xbase=10.0**(0.1*(sbase(nint(f1/3.125))-40.0)) + nsnr0=min(99,nint(10.0*log10(sync) - 25.5)) !### empirical ### + call timer('ft8b ',0) + call ft8b(dd,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,napwid, & + lsubtract,nagain,iaptype,mygrid6,bcontest,sync,f1,xdt,xbase, & + apsym,nharderrors,dmin,nbadcrc,iappass,iera,message,xsnr) + nsnr=nint(xsnr) + xdt=xdt-0.5 + hd=nharderrors+dmin + call timer('ft8b ',1) + if(nbadcrc.eq.0) then +! call jtmsg(message,iflag) + if(bcontest) call fix_contest_msg(mygrid6,message) +! if(iand(iflag,31).ne.0) message(22:22)='?' + ldupe=.false. + do id=1,ndecodes + if(message.eq.allmessages(id).and.nsnr.le.allsnrs(id)) ldupe=.true. + enddo + if(.not.ldupe) then + ndecodes=ndecodes+1 + allmessages(ndecodes)=message + allsnrs(ndecodes)=nsnr + endif +! write(81,1004) nutc,ncand,icand,ipass,iaptype,iappass, & +! nharderrors,dmin,hd,min(sync,999.0),nint(xsnr), & +! xdt,nint(f1),message +!1004 format(i6.6,2i4,3i2,i3,3f6.1,i4,f6.2,i5,2x,a22) +! flush(81) + if(.not.ldupe .and. associated(this%callback)) then + qual=1.0-(nharderrors+dmin)/60.0 ! scale qual to [0.0,1.0] + call this%callback(sync,nsnr,xdt,f1,message,iaptype,qual) + endif + endif + enddo +! h=default_header(12000,NMAX) +! open(10,file='subtract.wav',status='unknown',access='stream') +! iwave=nint(dd) +! write(10) h,iwave +! close(10) + enddo + return + end subroutine decode + +end module ft8_decode diff --git a/lib/ftrsd/Makefile b/lib/ftrsd/Makefile new file mode 100644 index 00000000..61b1357e --- /dev/null +++ b/lib/ftrsd/Makefile @@ -0,0 +1,53 @@ +# Makefile for Windows in JTSDK-PY environment + +# Re-direct stdout and stderr: cmd.exe bash +# make > junk 2>&1 make &> junk + +CC = gcc +FC = gfortran + +FFLAGS = -O2 -DWIN32 -fbounds-check -fno-second-underscore -Wall \ + -Wno-conversion -Wno-character-truncation +CFLAGS = -I. -DWIN32 -DWin32 -DBIGSYM -DHAVE_STRUCT_TIMESPEC + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: libftrsd.a + +OBJS1 = extract2.o ftrsd2.o init_rs_int.o encode_rs_int.o decode_rs_int.o +libftrsd.a: $(OBJS1) + ar cr libftrsd.a $(OBJS1) + ranlib libftrsd.a + cp libftrsd.a .. + +# Build rsdtest +OBJS2 = rsdtest.o +rsdtest: $(OBJS2) ../libjt.a + $(FC) -o rsdtest $(OBJS2) libftrsd.a ../libjt.a ../libpthreadGC2.a + +ftrsd: ftrsd.o encode_rs_int.o decode_rs_int.o init_rs_int.o + gcc -g -o $@ $^ + +encode_rs_int.o: encode_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +decode_rs_int.o: decode_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +init_rs_int.o: init_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +.PHONY : clean + +clean: + rm -rf *.o libjt.a rsdtest ftrsd diff --git a/lib/ftrsd/Makefile.sfrsd b/lib/ftrsd/Makefile.sfrsd new file mode 100644 index 00000000..3f68f7ed --- /dev/null +++ b/lib/ftrsd/Makefile.sfrsd @@ -0,0 +1,30 @@ +srcdir = . +prefix = /usr/local +exec_prefix=${prefix} +CC=gcc + +CFLAGS=-I/usr/local/include -Wall -O2 + +all: encode_rs_int.o decode_rs_int.o init_rs_int.o sfrsd2.o sfrsd.o sfrsd + +encode_rs_int.o: encode_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +decode_rs_int.o: decode_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +init_rs_int.o: init_rs.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +sfrsd2.o: sfrsd2.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +sfrsd.o: sfrsd.c + gcc -DBIGSYM=1 $(CFLAGS) -c -o $@ $^ + +sfrsd: sfrsd.o encode_rs_int.o decode_rs_int.o init_rs_int.o sfrsd2.o + gcc -g -o $@ $^ + +clean: + rm -f *.o *.a sfrsd + diff --git a/lib/ftrsd/Makefile.sfrsd3 b/lib/ftrsd/Makefile.sfrsd3 new file mode 100644 index 00000000..93023f31 --- /dev/null +++ b/lib/ftrsd/Makefile.sfrsd3 @@ -0,0 +1,38 @@ +# Makefile for Windows in JTSDK-PY environment + +# Re-direct stdout and stderr: cmd.exe bash +# make > junk 2>&1 make &> junk + +CC = gcc +FC = gfortran + +FFLAGS = -O2 -DWIN32 -fbounds-check -fno-second-underscore -Wall \ + -Wno-conversion -Wno-character-truncation +CFLAGS = -I. -DWIN32 -DWin32 -DBIGSYM -DHAVE_STRUCT_TIMESPEC + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: rsdtest + +# Build rsdtest +OBJS2 = rsdtest.o extract2.o demod64b.o sfrsd3.o +rsdtest: $(OBJS2) ../libjt.a + $(FC) -o rsdtest $(OBJS2) ../libjt.a ../libpthreadGC2.a + +sfrsd: sfrsd.o encode_rs_int.o decode_rs_int.o init_rs_int.o + gcc -g -o $@ $^ + +.PHONY : clean + +clean: + rm -rf *.o libjt.a rsdtest sfrsd diff --git a/lib/ftrsd/decode_rs.c b/lib/ftrsd/decode_rs.c new file mode 100644 index 00000000..990b687a --- /dev/null +++ b/lib/ftrsd/decode_rs.c @@ -0,0 +1,268 @@ +/* Reed-Solomon decoder + * Copyright 2002 Phil Karn, KA9Q + * May be used under the terms of the GNU General Public License (GPL) + * Modified by Steve Franke, K9AN, for use in a soft-symbol RS decoder + */ + +#ifdef DEBUG +#include +#endif + +#include +#include + +#define min(a,b) ((a) < (b) ? (a) : (b)) + +#ifdef FIXED +#include "fixed.h" +#elif defined(BIGSYM) +#include "int.h" +#else +#include "char.h" +#endif + +int DECODE_RS( +#ifndef FIXED + void *p, +#endif + DTYPE *data, int *eras_pos, int no_eras, int calc_syn){ + +#ifndef FIXED + struct rs *rs = (struct rs *)p; +#endif + int deg_lambda, el, deg_omega; + int i, j, r,k; + DTYPE u,q,tmp,num1,num2,den,discr_r; + DTYPE lambda[NROOTS+1]; // Err+Eras Locator poly + static DTYPE s[51]; // and syndrome poly + DTYPE b[NROOTS+1], t[NROOTS+1], omega[NROOTS+1]; + DTYPE root[NROOTS], reg[NROOTS+1], loc[NROOTS]; + int syn_error, count; + + if( calc_syn ) { + /* form the syndromes; i.e., evaluate data(x) at roots of g(x) */ + for(i=0;i 0) { + /* Init lambda to be the erasure locator polynomial */ + lambda[1] = ALPHA_TO[MODNN(PRIM*(NN-1-eras_pos[0]))]; + for (i = 1; i < no_eras; i++) { + u = MODNN(PRIM*(NN-1-eras_pos[i])); + for (j = i+1; j > 0; j--) { + tmp = INDEX_OF[lambda[j - 1]]; + if(tmp != A0) + lambda[j] ^= ALPHA_TO[MODNN(u + tmp)]; + } + } + +#if DEBUG >= 1 + /* Test code that verifies the erasure locator polynomial just constructed + Needed only for decoder debugging. */ + + /* find roots of the erasure location polynomial */ + for(i=1;i<=no_eras;i++) + reg[i] = INDEX_OF[lambda[i]]; + + count = 0; + for (i = 1,k=IPRIM-1; i <= NN; i++,k = MODNN(k+IPRIM)) { + q = 1; + for (j = 1; j <= no_eras; j++) + if (reg[j] != A0) { + reg[j] = MODNN(reg[j] + j); + q ^= ALPHA_TO[reg[j]]; + } + if (q != 0) + continue; + /* store root and error location number indices */ + root[count] = i; + loc[count] = k; + count++; + } + if (count != no_eras) { + printf("count = %d no_eras = %d\n lambda(x) is WRONG\n",count,no_eras); + count = -1; + goto finish; + } +#if DEBUG >= 2 + printf("\n Erasure positions as determined by roots of Eras Loc Poly:\n"); + for (i = 0; i < count; i++) + printf("%d ", loc[i]); + printf("\n"); +#endif +#endif + } + for(i=0;i 0; j--){ + if (reg[j] != A0) { + reg[j] = MODNN(reg[j] + j); + q ^= ALPHA_TO[reg[j]]; + } + } + if (q != 0) + continue; /* Not a root */ + /* store root (index-form) and error location number */ +#if DEBUG>=2 + printf("count %d root %d loc %d\n",count,i,k); +#endif + root[count] = i; + loc[count] = k; + /* If we've already found max possible roots, + * abort the search to save time + */ + if(++count == deg_lambda) + break; + } + if (deg_lambda != count) { + /* + * deg(lambda) unequal to number of roots => uncorrectable + * error detected + */ + count = -1; + goto finish; + } + /* + * Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo + * x**NROOTS). in index form. Also find deg(omega). + */ + deg_omega = 0; + for (i = 0; i < NROOTS;i++){ + tmp = 0; + j = (deg_lambda < i) ? deg_lambda : i; + for(;j >= 0; j--){ + if ((s[i - j] != A0) && (lambda[j] != A0)) + tmp ^= ALPHA_TO[MODNN(s[i - j] + lambda[j])]; + } + if(tmp != 0) + deg_omega = i; + omega[i] = INDEX_OF[tmp]; + } + omega[NROOTS] = A0; + + /* + * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 = + * inv(X(l))**(FCR-1) and den = lambda_pr(inv(X(l))) all in poly-form + */ + for (j = count-1; j >=0; j--) { + num1 = 0; + for (i = deg_omega; i >= 0; i--) { + if (omega[i] != A0) + num1 ^= ALPHA_TO[MODNN(omega[i] + i * root[j])]; + } + num2 = ALPHA_TO[MODNN(root[j] * (FCR - 1) + NN)]; + den = 0; + + /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */ + for (i = min(deg_lambda,NROOTS-1) & ~1; i >= 0; i -=2) { + if(lambda[i+1] != A0) + den ^= ALPHA_TO[MODNN(lambda[i+1] + i * root[j])]; + } + if (den == 0) { +#if DEBUG >= 1 + printf("\n ERROR: denominator = 0\n"); +#endif + count = -1; + goto finish; + } + /* Apply error to data */ + if (num1 != 0) { + data[loc[j]] ^= ALPHA_TO[MODNN(INDEX_OF[num1] + INDEX_OF[num2] + NN - INDEX_OF[den])]; + } + } +finish: + if(eras_pos != NULL){ + for(i=0;i + +#ifdef FIXED +#include "fixed.h" +#elif defined(BIGSYM) +#include "int.h" +#else +#include "char.h" +#endif + +void ENCODE_RS( +#ifndef FIXED +void *p, +#endif +DTYPE *data, DTYPE *bb){ +#ifndef FIXED + struct rs *rs = (struct rs *)p; +#endif + int i, j; + DTYPE feedback; + + memset(bb,0,NROOTS*sizeof(DTYPE)); + + for(i=0;i +#include +#include +#include +#include +#include "rs2.h" + +static void *rs; +void getpp_(int workdat[], float *pp); + +void ftrsd2_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[], + int* ntrials0, int correct[], int param[], int ntry[]) +{ + int rxdat[63], rxprob[63], rxdat2[63], rxprob2[63]; + int workdat[63]; + int indexes[63]; + int era_pos[51]; + int i, j, numera, nerr, nn=63; + int ntrials = *ntrials0; + int nhard=0,nhard_min=32768,nsoft=0,nsoft_min=32768; + int ntotal=0,ntotal_min=32768,ncandidates; + int nera_best=0; + float pp,pp1,pp2; + static unsigned int nseed; + +// Power-percentage symbol metrics - composite gnnf/hf + int perr[8][8] = { + { 4, 9, 11, 13, 14, 14, 15, 15}, + { 2, 20, 20, 30, 40, 50, 50, 50}, + { 7, 24, 27, 40, 50, 50, 50, 50}, + {13, 25, 35, 46, 52, 70, 50, 50}, + {17, 30, 42, 54, 55, 64, 71, 70}, + {25, 39, 48, 57, 64, 66, 77, 77}, + {32, 45, 54, 63, 66, 75, 78, 83}, + {51, 58, 57, 66, 72, 77, 82, 86}}; + + +// Initialize the KA9Q Reed-Solomon encoder/decoder + unsigned int symsize=6, gfpoly=0x43, fcr=3, prim=1, nroots=51; + rs=init_rs_int(symsize, gfpoly, fcr, prim, nroots, 0); + +// Reverse the received symbol vectors for BM decoder + for (i=0; i<63; i++) { + rxdat[i]=mrsym[62-i]; + rxprob[i]=mrprob[62-i]; + rxdat2[i]=mr2sym[62-i]; + rxprob2[i]=mr2prob[62-i]; + } + +// Sort rxprob to find indexes of the least reliable symbols + int k, pass, tmp, nsym=63; + int probs[63]; + for (i=0; i<63; i++) { + indexes[i]=i; + probs[i]=rxprob[i]; + } + for (pass = 1; pass <= nsym-1; pass++) { + for (k = 0; k < nsym - pass; k++) { + if( probs[k] < probs[k+1] ) { + tmp = probs[k]; + probs[k] = probs[k+1]; + probs[k+1] = tmp; + tmp = indexes[k]; + indexes[k] = indexes[k+1]; + indexes[k+1] = tmp; + } + } + } + +// See if we can decode using BM HDD, and calculate the syndrome vector. + memset(era_pos,0,51*sizeof(int)); + numera=0; + memcpy(workdat,rxdat,sizeof(rxdat)); + nerr=decode_rs_int(rs,workdat,era_pos,numera,1); + if( nerr >= 0 ) { + // Hard-decision decoding succeeded. Save codeword and some parameters. + nhard=0; + for (i=0; i<63; i++) { + if( workdat[i] != rxdat[i] ) nhard=nhard+1; + } + memcpy(correct,workdat,63*sizeof(int)); + param[0]=0; + param[1]=nhard; + param[2]=0; + param[3]=0; + param[4]=0; + param[5]=0; + param[7]=1000*1000; + ntry[0]=0; + return; + } + +/* +Hard-decision decoding failed. Try the FT soft-decision method. +Generate random erasure-locator vectors and see if any of them +decode. This will generate a list of "candidate" codewords. The +soft distance between each candidate codeword and the received +word is estimated by finding the largest (pp1) and second-largest +(pp2) outputs from a synchronized filter-bank operating on the +symbol spectra, and using these to decide which candidate +codeword is "best". +*/ + + nseed=1; //Seed for random numbers + float ratio; + int thresh, nsum; + int thresh0[63]; + ncandidates=0; + nsum=0; + int ii,jj; + for (i=0; i= 0 ) { + // We have a candidate codeword. Find its hard and soft distance from + // the received word. Also find pp1 and pp2 from the full array + // s3(64,63) of synchronized symbol spectra. + ncandidates=ncandidates+1; + nhard=0; + nsoft=0; + for (i=0; i<63; i++) { + if(workdat[i] != rxdat[i]) { + nhard=nhard+1; + if(workdat[i] != rxdat2[i]) { + nsoft=nsoft+rxprob[i]; + } + } + } + nsoft=63*nsoft/nsum; + ntotal=nsoft+nhard; + + getpp_(workdat,&pp); + if(pp>pp1) { + pp2=pp1; + pp1=pp; + nsoft_min=nsoft; + nhard_min=nhard; + ntotal_min=ntotal; + memcpy(correct,workdat,63*sizeof(int)); + nera_best=numera; + ntry[0]=k; + } else { + if(pp>pp2 && pp!=pp1) pp2=pp; + } + if(nhard_min <= 41 && ntotal_min <= 71) break; + } + if(k == ntrials) ntry[0]=k; + } + + param[0]=ncandidates; + param[1]=nhard_min; + param[2]=nsoft_min; + param[3]=nera_best; + param[4]=1000.0*pp2/pp1; + param[5]=ntotal_min; + param[6]=ntry[0]; + param[7]=1000.0*pp2; + param[8]=1000.0*pp1; + if(param[0]==0) param[2]=-1; + return; +} diff --git a/lib/ftrsd/ftrsd_paper/JT65B_EME.png b/lib/ftrsd/ftrsd_paper/JT65B_EME.png new file mode 100644 index 00000000..d5c86fb0 Binary files /dev/null and b/lib/ftrsd/ftrsd_paper/JT65B_EME.png differ diff --git a/lib/ftrsd/ftrsd_paper/Makefile b/lib/ftrsd/ftrsd_paper/Makefile new file mode 100644 index 00000000..a594397a --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/Makefile @@ -0,0 +1,40 @@ +CC = gcc +FC = gfortran + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: mfsk probs.out + +OBJS1 = prob.o binomial_subs.o +prob: $(OBJS1) + $(FC) -o prob $(OBJS1) + +OBJS2 = mfsk.o binomial_subs.o +mfsk: $(OBJS2) + $(FC) -o mfsk $(OBJS2) + +OBJS3 = bodide.o binomial_subs.o +bodide: $(OBJS3) + $(FC) -o bodide $(OBJS3) + + +probs.out: prob +# x N X s + prob 35 63 40 40 > probs.out + prob 37 63 40 45 >> probs.out + prob 37 53 40 45 >> probs.out + prob 38 53 40 47 >> probs.out + +clean: + rm -rf *.o prob probs.out + diff --git a/lib/ftrsd/ftrsd_paper/binomial.c b/lib/ftrsd/ftrsd_paper/binomial.c new file mode 100644 index 00000000..fcbdafd9 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/binomial.c @@ -0,0 +1,69 @@ +#include +#include + +/* Original code copied from + http://rosettacode.org/wiki/Evaluate_binomial_coefficients +*/ + +/* We go to some effort to handle overflow situations */ + +static unsigned long gcd_ui(unsigned long x, unsigned long y) { + unsigned long t; + if (y < x) { t = x; x = y; y = t; } + while (y > 0) { + t = y; y = x % y; x = t; /* y1 <- x0 % y0 ; x1 <- y0 */ + } + return x; +} + +unsigned long binomial(unsigned long n, unsigned long k) { + unsigned long d, g, r = 1; + if (k == 0) return 1; + if (k == 1) return n; + if (k >= n) return (k == n); + if (k > n/2) k = n-k; + for (d = 1; d <= k; d++) { + if (r >= ULONG_MAX/n) { /* Possible overflow */ + unsigned long nr, dr; /* reduced numerator / denominator */ + g = gcd_ui(n, d); nr = n/g; dr = d/g; + g = gcd_ui(r, dr); r = r/g; dr = dr/g; + if (r >= ULONG_MAX/nr) return 0; /* Unavoidable overflow */ + r *= nr; + r /= dr; + n--; + } else { + r *= n--; + r /= d; + } + } + return r; +} + +int main() { + + //Get test results + printf("%lu\n", binomial(5, 3)); // 10 + printf("%lu\n", binomial(40, 19)); // 131282408400 + printf("%lu\n", binomial(67, 31)); // 11923179284862717872 + + // Compute special cases for paper on TF soft-decision RS decoder: + double a,b,c,p; + a=(double)binomial(40, 35); + b=(double)binomial(23, 5); + c=(double)binomial(63, 40); + p=a*b/c; + printf("%e %e %e %e\n",a,b,c,p); + + a=(double)binomial(40, 36); + b=(double)binomial(23, 4); + c=(double)binomial(63, 40); + p=a*b/c; + printf("%e %e %e %e\n",a,b,c,p); + + a=(double)binomial(40, 37); + b=(double)binomial(23, 8); + c=(double)binomial(63, 45); + p=a*b/c; + printf("%e %e %e %e\n",a,b,c,p); + return 0; +} diff --git a/lib/ftrsd/ftrsd_paper/binomial_subs.c b/lib/ftrsd/ftrsd_paper/binomial_subs.c new file mode 100644 index 00000000..be4a0ae5 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/binomial_subs.c @@ -0,0 +1,55 @@ +#include +#include + +/* Original code copied from + http://rosettacode.org/wiki/Evaluate_binomial_coefficients +*/ + +/* We go to some effort to handle overflow situations */ + +static unsigned long long gcd_ui(unsigned long long x, unsigned long long y) { + unsigned long long t; + if (y < x) { t = x; x = y; y = t; } + while (y > 0) { + t = y; y = x % y; x = t; /* y1 <- x0 % y0 ; x1 <- y0 */ + } + return x; +} + +unsigned long long binomial(unsigned long long n, unsigned long long k) { + unsigned long long d, g, r = 1; + if (k == 0) return 1; + if (k == 1) return n; + if (k >= n) return (k == n); + if (k > n/2) k = n-k; + for (d = 1; d <= k; d++) { + if (r >= ULLONG_MAX/n) { /* Possible overflow */ + unsigned long long nr, dr; /* reduced numerator / denominator */ + g = gcd_ui(n, d); nr = n/g; dr = d/g; + g = gcd_ui(r, dr); r = r/g; dr = dr/g; + if (r >= ULLONG_MAX/nr) return 0; /* Unavoidable overflow */ + r *= nr; + r /= dr; + n--; + } else { + r *= n--; + r /= d; + } + } + return r; +} + +unsigned long long binomial_(int *n, int *k) +{ + // printf("n=%d k=%d %lu\n",*n,*k,binomial(*n,*k)); + return binomial(*n,*k); +} + +double hypergeo_(int *x, int *NN, int *XX, int *s) +{ + double a,b,c; + a=(double)binomial(*XX, *x); + b=(double)binomial(*NN-*XX, *s-*x); + c=(double)binomial(*NN, *s); + return a*b/c; +} diff --git a/lib/ftrsd/ftrsd_paper/bmdata-rf.dat b/lib/ftrsd/ftrsd_paper/bmdata-rf.dat new file mode 100644 index 00000000..17d53312 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/bmdata-rf.dat @@ -0,0 +1,11 @@ +fspread0 0.2, BM (ntrials=0) +-22.0 0.09 +-21.5 0.20 +-21.0 0.36 +-20.5 0.55 +-20.0 0.69 +-19.5 0.83 +-19.0 0.91 +-18.5 0.960 +-18.0 0.978 +-17.5 0.987 diff --git a/lib/ftrsd/ftrsd_paper/bmdata.dat b/lib/ftrsd/ftrsd_paper/bmdata.dat new file mode 100644 index 00000000..987bbbba --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/bmdata.dat @@ -0,0 +1,8 @@ +-24.5 0.000 +-24.0 0.006 +-23.5 0.046 0.066 +-23.0 0.250 0.305 +-22.5 0.630 0.701 +-22.0 0.900 0.945 +-21.5 0.992 0.9974 +-21.0 0.99987 diff --git a/lib/ftrsd/ftrsd_paper/bmtheory25.dat b/lib/ftrsd/ftrsd_paper/bmtheory25.dat new file mode 100644 index 00000000..de854562 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/bmtheory25.dat @@ -0,0 +1,43 @@ +Es/No P(word error) +---------------------- + 0.0 0.9008E+00 0.1000E+01 + 0.5 0.8877E+00 0.1000E+01 + 1.0 0.8724E+00 0.1000E+01 + 1.5 0.8545E+00 0.1000E+01 + 2.0 0.8338E+00 0.1000E+01 + 2.5 0.8096E+00 0.1000E+01 + 3.0 0.7817E+00 0.1000E+01 + 3.5 0.7496E+00 0.1000E+01 + 4.0 0.7128E+00 0.1000E+01 + 4.5 0.6712E+00 0.1000E+01 + 5.0 0.6246E+00 0.9998E+00 + 5.5 0.5731E+00 0.9964E+00 + 6.0 0.5170E+00 0.9629E+00 + 6.5 0.4572E+00 0.7979E+00 + 7.0 0.3949E+00 0.4327E+00 + 7.5 0.3316E+00 0.1100E+00 + 8.0 0.2696E+00 0.9707E-02 + 8.5 0.2109E+00 0.2303E-03 + 9.0 0.1578E+00 0.1170E-05 + 9.5 0.1121E+00 0.1027E-08 +10.0 0.7499E-01 0.1263E-12 +10.5 0.4684E-01 0.1768E-17 +11.0 0.2703E-01 0.2282E-23 +11.5 0.1426E-01 0.2200E-30 +12.0 0.6789E-02 -.1348E-32 +12.5 0.2879E-02 -.1733E-32 +13.0 0.1072E-02 -.2119E-32 +13.5 0.3448E-03 0.3081E-32 +14.0 0.9421E-04 0.3852E-33 +14.5 0.2148E-04 -.1156E-32 +15.0 0.4006E-05 -.1733E-32 +15.5 0.5984E-06 0.2215E-32 +16.0 0.6994E-07 -.4430E-32 +16.5 0.6230E-08 -.3081E-32 +17.0 0.4105E-09 -.2889E-32 +17.5 0.1934E-10 -.1926E-33 +18.0 0.6266E-12 0.3852E-32 +18.5 0.1335E-13 -.1926E-33 +19.0 0.1777E-15 0.2119E-32 +19.5 0.1396E-17 0.1733E-32 +20.0 0.6076E-20 -.3852E-33 diff --git a/lib/ftrsd/ftrsd_paper/bmtheory40.dat b/lib/ftrsd/ftrsd_paper/bmtheory40.dat new file mode 100644 index 00000000..4903ef5c --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/bmtheory40.dat @@ -0,0 +1,43 @@ +Es/No P(word error) +---------------------- + 0.0 0.9008E+00 0.1000E+01 + 0.5 0.8877E+00 0.1000E+01 + 1.0 0.8724E+00 0.1000E+01 + 1.5 0.8545E+00 0.1000E+01 + 2.0 0.8338E+00 0.9999E+00 + 2.5 0.8096E+00 0.9991E+00 + 3.0 0.7817E+00 0.9944E+00 + 3.5 0.7496E+00 0.9713E+00 + 4.0 0.7128E+00 0.8887E+00 + 4.5 0.6712E+00 0.6883E+00 + 5.0 0.6246E+00 0.3865E+00 + 5.5 0.5731E+00 0.1310E+00 + 6.0 0.5170E+00 0.2215E-01 + 6.5 0.4572E+00 0.1536E-02 + 7.0 0.3949E+00 0.3562E-04 + 7.5 0.3316E+00 0.2223E-06 + 8.0 0.2696E+00 0.2951E-09 + 8.5 0.2109E+00 0.6449E-13 + 9.0 0.1578E+00 0.1758E-17 + 9.5 0.1121E+00 0.4426E-23 +10.0 0.7499E-01 0.7428E-30 +10.5 0.4684E-01 -.1733E-32 +11.0 0.2703E-01 0.1348E-32 +11.5 0.1426E-01 0.2985E-32 +12.0 0.6789E-02 -.1348E-32 +12.5 0.2879E-02 -.1733E-32 +13.0 0.1072E-02 -.2119E-32 +13.5 0.3448E-03 0.3081E-32 +14.0 0.9421E-04 0.3852E-33 +14.5 0.2148E-04 -.1156E-32 +15.0 0.4006E-05 -.1733E-32 +15.5 0.5984E-06 0.2215E-32 +16.0 0.6994E-07 -.4430E-32 +16.5 0.6230E-08 -.3081E-32 +17.0 0.4105E-09 -.2889E-32 +17.5 0.1934E-10 -.1926E-33 +18.0 0.6266E-12 0.3852E-32 +18.5 0.1335E-13 -.1926E-33 +19.0 0.1777E-15 0.2119E-32 +19.5 0.1396E-17 0.1733E-32 +20.0 0.6076E-20 -.3852E-33 diff --git a/lib/ftrsd/ftrsd_paper/bmtheory43.dat b/lib/ftrsd/ftrsd_paper/bmtheory43.dat new file mode 100644 index 00000000..b22ab8d8 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/bmtheory43.dat @@ -0,0 +1,43 @@ +Es/No P(word error) +---------------------- + 0.0 0.9008E+00 0.1000E+01 + 0.5 0.8877E+00 0.1000E+01 + 1.0 0.8724E+00 0.9999E+00 + 1.5 0.8545E+00 0.9996E+00 + 2.0 0.8338E+00 0.9977E+00 + 2.5 0.8096E+00 0.9889E+00 + 3.0 0.7817E+00 0.9559E+00 + 3.5 0.7496E+00 0.8599E+00 + 4.0 0.7128E+00 0.6586E+00 + 4.5 0.6712E+00 0.3780E+00 + 5.0 0.6246E+00 0.1397E+00 + 5.5 0.5731E+00 0.2826E-01 + 6.0 0.5170E+00 0.2632E-02 + 6.5 0.4572E+00 0.9396E-04 + 7.0 0.3949E+00 0.1052E-05 + 7.5 0.3316E+00 0.2965E-08 + 8.0 0.2696E+00 0.1650E-11 + 8.5 0.2109E+00 0.1388E-15 + 9.0 0.1578E+00 0.1316E-20 + 9.5 0.1121E+00 0.1021E-26 +10.0 0.7499E-01 -.9630E-33 +10.5 0.4684E-01 -.1733E-32 +11.0 0.2703E-01 0.1348E-32 +11.5 0.1426E-01 0.2985E-32 +12.0 0.6789E-02 -.1348E-32 +12.5 0.2879E-02 -.1733E-32 +13.0 0.1072E-02 -.2119E-32 +13.5 0.3448E-03 0.3081E-32 +14.0 0.9421E-04 0.3852E-33 +14.5 0.2148E-04 -.1156E-32 +15.0 0.4006E-05 -.1733E-32 +15.5 0.5984E-06 0.2215E-32 +16.0 0.6994E-07 -.4430E-32 +16.5 0.6230E-08 -.3081E-32 +17.0 0.4105E-09 -.2889E-32 +17.5 0.1934E-10 -.1926E-33 +18.0 0.6266E-12 0.3852E-32 +18.5 0.1335E-13 -.1926E-33 +19.0 0.1777E-15 0.2119E-32 +19.5 0.1396E-17 0.1733E-32 +20.0 0.6076E-20 -.3852E-33 diff --git a/lib/ftrsd/ftrsd_paper/bodide.f90 b/lib/ftrsd/ftrsd_paper/bodide.f90 new file mode 100644 index 00000000..72e0f137 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/bodide.f90 @@ -0,0 +1,54 @@ +program bodide +! Compute probability of word error for a bounded distance decoder. +! Hardwired for non-coherent 64-FSK and the JT65 RS (63,12) code on GF(64). +! +! Let ps be symbol error probability. +! The probability of getting an error pattern with e symbol errors is: +! ps^e * (1-ps)*(n-e) +! The number of error patterns with e errors is binomial(63,e) +! Overall probability of getting a word with e errors is: +! P(e)= binomial(63,e)* ps^e * (1-ps)*(n-e) +! Probability that word is correct is P(0 to 25 errors) = sum{e=0}^{25} P(e) +! Probability that word is wrong is 1-P(0 to 25 errors) +! P_word_error=1-( sum_{e=0}^{t} P(e) ) +! + implicit real*16 (a-h,o-z) + + integer*8 binomial + integer x,s,XX,NN,M + character arg*8 + + nargs=iargc() + if(nargs.ne.1) then + print*,'Probability of word error for noncoherent 64-FSK with bounded distance decoding' + print*,'Usage: bounded_distance D' + print*,'Example: bounded_distance 25' + go to 999 + endif + call getarg(1,arg) + read(arg,*) nt + M=64 + write(*,1012) +1012 format('Es/No P(word error)'/ & + '----------------------') + do isnr=0,40 + esno=10**(isnr/2.0/10.0) + hsum=0.d0 + do k=1,M-1 + h=binomial(M-1,k) + h=h*((-1)**(k+1))/(k+1) + h=h*exp(-esno*k/(k+1)) + hsum=hsum + h + enddo + ps=hsum + hsum=0.d0 + do i=0,nt + h=binomial(63,i) + h=h*ps**i + h=h*(1-ps)**(63-i) + hsum=hsum+h + enddo + pw=1-hsum + write(*,'(f4.1,4x,e10.4,4x,e10.4)') isnr/2.0, ps, pw + enddo +999 end program bodide diff --git a/lib/ftrsd/ftrsd_paper/bodide.lab b/lib/ftrsd/ftrsd_paper/bodide.lab new file mode 100644 index 00000000..6fa108e0 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/bodide.lab @@ -0,0 +1,4 @@ +7.5 0.05 BM +6.9 0.015 Theory +5.55 0.05 KV +5.3 0.005 FT diff --git a/lib/ftrsd/ftrsd_paper/fig_bodide.gnuplot b/lib/ftrsd/ftrsd_paper/fig_bodide.gnuplot new file mode 100644 index 00000000..b8bb0ada --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/fig_bodide.gnuplot @@ -0,0 +1,24 @@ +# gnuplot script for comparison to theoretical word error rate for +# bounded distance decoding + +# run: gnuplot fig_bodide.gnuplot +# then: pdflatex fig_bodide.tex + +set term epslatex standalone size 6in,2*6/3in +set output "fig_bodide.tex" +set xlabel "$E_b/N_0$ (dB)" +set ylabel "Word Error Rate" +set style func linespoints +set key off +set tics in +set mxtics 2 +set mytics 10 +set grid +set logscale y +plot [3:9] [1e-4:1] \ + "bmdata.dat" using ($1+29.1):(1-$2) with linespoints lt 2 lw 2 pt 2, \ + "ftdata-100000.dat" using ($1+29.1):(1-$3) with linespoints lt 1 lw 2 pt 7, \ + "bmtheory25.dat" using ($1-0.6):3 with linespoints lt 1 pt 5, \ + "kvasd-15.dat" using ($1+29.1):(1-$3) with linespoints lt 4 pt 6, \ + "bodide.lab" with labels + diff --git a/lib/ftrsd/ftrsd_paper/fig_ntrials_vs_nhard.gnuplot b/lib/ftrsd/ftrsd_paper/fig_ntrials_vs_nhard.gnuplot new file mode 100644 index 00000000..9a6c9b08 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/fig_ntrials_vs_nhard.gnuplot @@ -0,0 +1,14 @@ +# gnuplot script for "ntrials_vs_nhard" figure +# run: gnuplot fig_ntrials_vs_nhard.gnuplot +# then: pdflatex fig_ntrials_vs_nhard.tex +# +set term epslatex standalone size 6in,2*6/3in +set output "fig_ntrials_vs_nhard.tex" +set xlabel "Errors in received word, $X$" +set ylabel "Number of trials" +set tics in +set mxtics 5 +set mytics 10 +#set grid +set logscale y +plot "stats-100000-24db-3.dat" using 1:4 pt 12 notitle diff --git a/lib/ftrsd/ftrsd_paper/fig_psuccess.gnuplot b/lib/ftrsd/ftrsd_paper/fig_psuccess.gnuplot new file mode 100644 index 00000000..3718e29f --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/fig_psuccess.gnuplot @@ -0,0 +1,25 @@ +# gnuplot script for "Percent copy" figure +# run: gnuplot fig_psuccess.gnuplot +# then: pdflatex fig_psuccess.tex +# +set term epslatex standalone size 6in,4in +set output "fig_psuccess.tex" +set xlabel "SNR in 2500 Hz Bandwidth (dB)" +set ylabel "Percent copy" +set style func linespoints +set key off +set tics in +set mxtics 2 +set mytics 2 +set grid +plot [-30:-18] [0:105] \ + "stats_0.0" using 1:($4)/10.0 with linespoints lt 2 lw 2 pt 2, \ + "stats_0.0" using 1:($5)/10.0 with linespoints lt 1 lw 2 pt 3, \ + "stats_0.0" using 1:($6)/10.0 with linespoints lt 3 lw 2 pt 4, \ + "stats_0.2" using 1:($4)/10.0 with linespoints lt 2 pt 2, \ + "stats_0.2" using 1:($5)/10.0 with linespoints lt 1 pt 3, \ + "stats_0.2" using 1:($6)/10.0 with linespoints lt 3 pt 4, \ + "stats_1.0" using 1:($4)/10.0 with linespoints lt 2 pt 2, \ + "stats_1.0" using 1:($5)/10.0 with linespoints lt 1 pt 3, \ + "stats_1.0" using 1:($6)/10.0 with linespoints lt 3 pt 4, \ + "psuccess.lab" with labels diff --git a/lib/ftrsd/ftrsd_paper/fig_psuccess.pdf b/lib/ftrsd/ftrsd_paper/fig_psuccess.pdf new file mode 100644 index 00000000..7464629e Binary files /dev/null and b/lib/ftrsd/ftrsd_paper/fig_psuccess.pdf differ diff --git a/lib/ftrsd/ftrsd_paper/fig_subtracted.tiff b/lib/ftrsd/ftrsd_paper/fig_subtracted.tiff new file mode 100644 index 00000000..b6f0f2fa Binary files /dev/null and b/lib/ftrsd/ftrsd_paper/fig_subtracted.tiff differ diff --git a/lib/ftrsd/ftrsd_paper/fig_waterfall.png b/lib/ftrsd/ftrsd_paper/fig_waterfall.png new file mode 100644 index 00000000..b2a8dd9d Binary files /dev/null and b/lib/ftrsd/ftrsd_paper/fig_waterfall.png differ diff --git a/lib/ftrsd/ftrsd_paper/fig_waterfall.tiff b/lib/ftrsd/ftrsd_paper/fig_waterfall.tiff new file mode 100644 index 00000000..ae2cbdd6 Binary files /dev/null and b/lib/ftrsd/ftrsd_paper/fig_waterfall.tiff differ diff --git a/lib/ftrsd/ftrsd_paper/fig_wer.gnuplot b/lib/ftrsd/ftrsd_paper/fig_wer.gnuplot new file mode 100644 index 00000000..bff05333 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/fig_wer.gnuplot @@ -0,0 +1,23 @@ +# gnuplot script for "Percent copy" figure +# run: gnuplot fig_wer.gnuplot +# then: pdflatex fig_wer.tex +# +set term epslatex standalone size 6in,4in +set output "fig_wer.tex" +set xlabel "$E_b/N_0$ (dB)" +set ylabel "Word Error Rate" +set style func linespoints +set key off +set tics in +set mxtics 2 +set mytics 10 +set grid +set logscale y +plot [3:7] "ftdata-100000.dat" using ($1+29.1):(1-$2) with linespoints lt 1 pt 7 title 'FT-100K', \ + "ftdata-10000.dat" using ($1+29.1):(1-$2) with linespoints lt 1 pt 7 title 'FT-10K', \ + "ftdata-1000.dat" using ($1+29.1):(1-$2) with linespoints lt 1 pt 7 title 'FT-1K', \ + "kvasd-8.dat" using ($1+29.1):(1-$2) with linespoints lt 2 pt 8 title 'KV-8', \ + "kvasd-12.dat" using ($1+29.1):(1-$2) with linespoints lt 2 pt 8 title 'KV-12', \ + "kvasd-15.dat" using ($1+29.1):(1-$2) with linespoints lt 2 pt 8 title 'KV-15', \ + "bmdata.dat" using ($1+29.1):(1-$2) with linespoints pt 7 title 'BM', \ + "wer.lab" with labels diff --git a/lib/ftrsd/ftrsd_paper/fig_wer.pdf b/lib/ftrsd/ftrsd_paper/fig_wer.pdf new file mode 100644 index 00000000..6533f007 Binary files /dev/null and b/lib/ftrsd/ftrsd_paper/fig_wer.pdf differ diff --git a/lib/ftrsd/ftrsd_paper/fig_wer2.gnuplot b/lib/ftrsd/ftrsd_paper/fig_wer2.gnuplot new file mode 100644 index 00000000..dc8edc98 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/fig_wer2.gnuplot @@ -0,0 +1,23 @@ +# gnuplot script for "Percent copy" figure +# run: gnuplot fig_wer2.gnuplot +# then: pdflatex fig_wer2.tex +# +set term epslatex standalone size 6in,6*2/3in +set output "fig_wer2.tex" +set xlabel "SNR in 2500 Hz Bandwidth (dB)" +set ylabel "Percent Copy" +set style func linespoints +set key off +set tics in +set mxtics 2 +set mytics 5 +set grid +plot [-27:-22] [0:110] \ + "ftdata-100000.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ + "ftdata-10000.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ + "ftdata-1000.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ + "ftdata-100.dat" using 1:(100*$3) with linespoints lt 1 lw 2 pt 7, \ + "ftdata-10.dat" using 1:(100*$2) with linespoints lt 1 lw 2 pt 7, \ + "kvasd-15.dat" using 1:(100*$2) with linespoints lt 4 pt 6, \ + "bmdata.dat" using 1:(100*$2) with linespoints lt 2 lw 2 pt 2, \ + "wer2.lab" with labels diff --git a/lib/ftrsd/ftrsd_paper/fig_wer3.gnuplot b/lib/ftrsd/ftrsd_paper/fig_wer3.gnuplot new file mode 100644 index 00000000..f3c9d273 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/fig_wer3.gnuplot @@ -0,0 +1,21 @@ +# gnuplot script for "Percent copy" figure +# run: gnuplot fig_wer3.gnuplot +# then: pdflatex fig_wer3.tex +# +set term epslatex standalone size 6in,6*2/3in +set output "fig_wer3.tex" +set xlabel "SNR in 2500 Hz Bandwidth (dB)" +set ylabel "Percent Copy" +set style func linespoints +set key off +set tics in +set mxtics 2 +set mytics 10 +set grid +set label "r6315" at -25.25,30 +set label "r6330" at -26.0,30 +set label "$T=10^5$" at -22.8,15 +set label "$d=0.0$" at -22.8,10 +plot [-27:-22] [0:110] \ + "ftdata-100000.dat" using 1:(100*$3) with linespoints lt 1 pt 7 title 'FT-100K', \ + "ftdata-100000.dat" using 1:(100*$2) with linespoints lt 1 pt 7 title 'FT-100K' diff --git a/lib/ftrsd/ftrsd_paper/ftdata-10.dat b/lib/ftrsd/ftrsd_paper/ftdata-10.dat new file mode 100644 index 00000000..467be382 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/ftdata-10.dat @@ -0,0 +1,10 @@ + snr psuccess ntrials 10, r6321, r6333 +-26.0 0.0 +-25.5 0.007 +-25.0 0.039 +-24.5 0.157 0.14 +-24.0 0.362 +-23.5 0.701 0.681 +-23.0 0.914 +-22.5 0.985 0.988 +-22.0 1.0 1.0 diff --git a/lib/ftrsd/ftrsd_paper/ftdata-100.dat b/lib/ftrsd/ftrsd_paper/ftdata-100.dat new file mode 100644 index 00000000..a5d547c3 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/ftdata-100.dat @@ -0,0 +1,10 @@ + snr psuccess ntrials 100, r6321, r6333 +-26.0 0.003 0.003 +-25.5 0.033 0.037 +-25.0 0.113 0.113 +-24.5 0.315 0.330 +-24.0 0.635 0.670 +-23.5 0.908 0.903 +-23.0 0.977 0.984 +-22.5 0.9986 0.999 +-22.0 1.0 1.0 diff --git a/lib/ftrsd/ftrsd_paper/ftdata-1000.dat b/lib/ftrsd/ftrsd_paper/ftdata-1000.dat new file mode 100644 index 00000000..156a0b3b --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/ftdata-1000.dat @@ -0,0 +1,9 @@ + snr psuccess ntrials 1000, r6315, r6333 +-26.0 0.010 0.022 +-25.5 0.052 0.097 +-25.0 0.22 0.262 +-24.5 0.51 0.535 +-24.0 0.80 0.844 +-23.5 0.956 0.968 +-23.0 0.9958 0.9963 +-22.5 1.0 1.0 diff --git a/lib/ftrsd/ftrsd_paper/ftdata-10000.dat b/lib/ftrsd/ftrsd_paper/ftdata-10000.dat new file mode 100644 index 00000000..99d48597 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/ftdata-10000.dat @@ -0,0 +1,11 @@ + snr psuccess ntrials 10000 r6315, r6330 +-27.0 0.000 0.001 +-26.5 0.004 0.014 +-26.0 0.03 0.066 +-25.5 0.107 0.208 0.19 +-25.0 0.353 0.424 0.40 (2) +-24.5 0.653 0.725 +-24.0 0.913 0.913 +-23.5 0.983 0.988 +-23.0 0.998 0.999 +-22.0 1.0 1.0 diff --git a/lib/ftrsd/ftrsd_paper/ftdata-100000.dat b/lib/ftrsd/ftrsd_paper/ftdata-100000.dat new file mode 100644 index 00000000..e2db520d --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/ftdata-100000.dat @@ -0,0 +1,11 @@ +snr psuccess 100000 trials r6315, r6330, +-27.0 0.0 0.011 +-26.5 0.007 0.035 +-26.0 0.057 0.135 +-25.5 0.207 0.326 +-25.0 0.531 0.568 +-24.5 0.822 0.836 +-24.0 0.953 0.966 +-23.5 0.99423 0.996 +-23.0 0.99967 0.99974 302956/303056, 218991/219046 + diff --git a/lib/ftrsd/ftrsd_paper/ftrsd.lyx b/lib/ftrsd/ftrsd_paper/ftrsd.lyx new file mode 100644 index 00000000..4549c768 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/ftrsd.lyx @@ -0,0 +1,3289 @@ +#LyX 2.1 created this file. For more info see http://www.lyx.org/ +\lyxformat 474 +\begin_document +\begin_header +\textclass paper +\begin_preamble +\usepackage{ragged2e} +\exhyphenpenalty=10000\hyphenpenalty=10000 + +\fancyhf{} +\fancyhead[L]{Franke \& Taylor: {\it Open Source Soft-Decision Decoder \ldots}} +\fancyhead[R]{\thepage} +\makeatletter +\let\ps@plain\ps@fancy % Plain page style = fancy page style +\makeatother + +\usepackage{nomencl} +\usepackage{overcite} + +\renewcommand{\nomname}{Sidebar: Glossary of Specialized Terms} +\end_preamble +\use_default_options true +\begin_modules +boxedfloat +\end_modules +\maintain_unincluded_children false +\language english +\language_package default +\inputencoding auto +\fontencoding global +\font_roman lmodern +\font_sans lmss +\font_typewriter lmtt +\font_math auto +\font_default_family default +\use_non_tex_fonts false +\font_sc false +\font_osf false +\font_sf_scale 100 +\font_tt_scale 100 +\graphics default +\default_output_format default +\output_sync 0 +\bibtex_command default +\index_command default +\float_placement H +\paperfontsize 12 +\spacing onehalf +\use_hyperref false +\papersize default +\use_geometry true +\use_package amsmath 1 +\use_package amssymb 1 +\use_package cancel 1 +\use_package esint 1 +\use_package mathdots 1 +\use_package mathtools 1 +\use_package mhchem 1 +\use_package stackrel 1 +\use_package stmaryrd 1 +\use_package undertilde 1 +\cite_engine basic +\cite_engine_type default +\biblio_style plain +\use_bibtopic false +\use_indices false +\paperorientation portrait +\suppress_date false +\justification false +\use_refstyle 1 +\index Index +\shortcut idx +\color #008000 +\end_index +\leftmargin 1in +\topmargin 1in +\rightmargin 1in +\bottommargin 1in +\secnumdepth 3 +\tocdepth 3 +\paragraph_separation skip +\defskip bigskip +\quotes_language english +\papercolumns 1 +\papersides 1 +\paperpagestyle fancy +\tracking_changes false +\output_changes false +\html_math_output 0 +\html_css_as_file 0 +\html_be_strict false +\end_header + +\begin_body + +\begin_layout Title +Open Source Soft-Decision Decoder for the JT65 (63,12) Reed-Solomon Code +\end_layout + +\begin_layout SubTitle + +\emph on +Under-the-hood description of the JT65 decoding procedure, including a wholly + new algorithm for its powerful error-correcting code. +\end_layout + +\begin_layout Author +Steven J. + Franke, K9AN and Joseph H. + Taylor, K1JT +\end_layout + +\begin_layout Section +\begin_inset CommandInset label +LatexCommand label +name "sec:Introduction-and-Motivation" + +\end_inset + +Background and Motivation +\end_layout + +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout + + +\backslash +RaggedRight +\end_layout + +\end_inset + + The JT65 protocol has revolutionized amateur-radio weak-signal communication + by enabling operators with small or compromise antennas and relatively + low-power transmitters to communicate over propagation paths not usable + with traditional technologies. + The protocol was developed in 2003 for Earth-Moon-Earth (EME, or +\begin_inset Quotes eld +\end_inset + +moonbounce +\begin_inset Quotes erd +\end_inset + +) communication +\begin_inset CommandInset citation +LatexCommand cite +key "jt65_protocol" + +\end_inset + +, where the scattered return signals are always weak. + It was soon found that JT65 also enables worldwide communication on the + HF bands with low power, modest antennas, and efficient spectral usage. + Thousands of amateurs now use JT65 on a regular basis, making contacts + on all bands from 160 meters through microwaves. +\end_layout + +\begin_layout Standard +JT65 uses timed transmitting and receiving sequences one minute long. + Messages are short and structured so as to streamline minimal exchanges + between two amateur operators over potentially difficult radio paths. + Most messages contain two callsigns and a grid locator, signal report, + acknowledgment, or sign-off; one of the tokens CQ, QRZ, or DE may be substitute +d for the first callsign. + Alternatively, a message may contain up to 13 Latin characters of arbitrary + text. + All messages are efficiently compressed into exactly 72 bits of digital + information. + It should be obvious that the JT65 protocol is intended for the basic purpose + of completing legitimate, documented two-way contacts, but not for extended + conversations. + Full details of the message structure and encoding procedure were presented + in an earlier publication +\begin_inset CommandInset citation +LatexCommand cite +key "jt65_protocol" + +\end_inset + +. + For a concise description of the overall process of transmitting and receiving + a JT65 message, see the accompanying sidebar +\series bold +JT65 Message Processing +\series default +. +\end_layout + +\begin_layout Standard +A major reason for the success and popularity of JT65 is its use of a strong + error-correction code. + Before transmission, each 72-bit message is divided into 12 six-bit +\emph on +symbols +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Symbol: }" +description "The information carried in one signalling interval, usually an integral number of bits. JT65 uses 6-bit symbols." + +\end_inset + + +\emph default + and augmented with 51 additional symbols of error-correcting information. + These 51 +\emph on +parity symbols +\emph default + are computed according to information-theory rules that maximize the probabilit +y of correctly decoding the message, even if many symbols are received incorrect +ly. + The JT65 code is properly described as a short block-length, low-rate Reed-Solo +mon code based on a 64-symbol +\emph on +alphabet. + +\emph default + +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Alphabet: }" +description "A sequence of possible symbol values used for signaling. JT65 uses a 64-character alphabet, values in the range 0 to 63." + +\end_inset + + Characters in this alphabet are mapped onto 64 different frequencies for + transmission. + +\end_layout + +\begin_layout Standard +Reed Solomon codes are widely used to ensure reliability in data transmission + and storage. + In hardware implementations, decoding is generally accomplished with a + procedure such as the Berlekamp-Massey (BM) algorithm, based on +\emph on +hard decisions +\emph default + +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Hard decision: }" +description "Received symbols are assigned definite values by the demodulator." + +\end_inset + + for each of the symbol values received. + +\emph on +Soft decisions +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Soft decision: }" +description "Received symbols are assigned tentative values (most probable, second most probable, etc.) and quality indicators." + +\end_inset + + +\emph default + are potentially more powerful, however. + For each received JT65 symbol we can estimate not only the value most likely + to be correct, but also the second, third, etc., most likely. + Most importantly, we can also estimate the probability that each of those + possible values is the correct one. + Decoders that make use of such information are called +\emph on +soft-decision decoders. +\end_layout + +\begin_layout Standard +Until now, nearly all programs implementing JT65 have used the patented + Kötter-Vardy (KV) algebraic soft-decision decoder +\begin_inset CommandInset citation +LatexCommand cite +key "kv2001" + +\end_inset + +, licensed to and implemented by K1JT as a closed-source executable for + use only in amateur radio applications. + Since 2001 the KV decoder has been considered the best available soft-decision + decoder for Reed Solomon codes. +\end_layout + +\begin_layout Standard +We describe here a new open-source alternative called the Franke-Taylor + (FT, or K9AN-K1JT) soft-decision decoding algorithm. + It is conceptually simple, built on top of the BM hard-decision decoder, + and in this application it performs even better than the KV decoder. + The FT algorithm is implemented in the popular programs +\emph on +WSJT +\emph default +, +\emph on +MAP65 +\emph default +, and +\emph on +WSJT-X +\emph default +, widely used for amateur weak-signal communication using JT65 and other + specialized digital protocols. + These programs are open-source, freely available +\begin_inset CommandInset citation +LatexCommand cite +key "wsjt" + +\end_inset + +, and licensed under the GNU General Public License. +\end_layout + +\begin_layout Standard +The JT65 protocol specifies transmissions that start one second into a UTC + minute and last for 46.8 seconds. + Receiving software therefore has as much as ten seconds to decode a message + before the start of the next minute, when the operator will send a reply. + With today's personal computers, this relatively long time encourages experimen +tation with decoders of high computational complexity. + With time to spare, the FT algorithm lowers the decoding threshold on a + typical fading channel by many dB over the hard-decision BM decoder, and + by a meaningful amount over the KV decoder. + In addition to its excellent performance, the new algorithm has other desirable + properties, not least of which is its conceptual simplicity. + Decoding performance and computational complexity scale in a convenient + way, providing steadily increasing soft-decision decoding gain as a tunable + parameter is increased over more than five orders of magnitude. + Appreciable gain is available from our decoder even on very simple (and + relatively slow) computers. + On the other hand, because the algorithm benefits from a large number of + independent decoding trials, further performance gains should be achievable + through parallelization on high-performance computers. +\end_layout + +\begin_layout Standard +The remainder of this paper is organized as follows. + Section 2 presents a brief overview of the nature of Reed Solomon codes + and their error-correcting capabilities. + Section 3 provides statistical motivation for the FT algorithm, and Section + 4 describes the algorithm in full detail. + Material in these two sections is important because it documents our approach + and underlines its fundamental technical contributions. + These sections are heavier in formal mathematics than common in +\emph on +QEX +\emph default +; for this reason, some readers may choose to skip or skim them and proceed + more quickly to the results. + Most readers will benefit by reviewing the original paper on the JT65 protocol + +\begin_inset CommandInset citation +LatexCommand cite +key "jt65_protocol" + +\end_inset + +. + A procedure for +\emph on +hinted decoding +\emph default +--- determining which one, if any, of a list of likely messages matches + the one that was received --- is outlined in Section 5. + Finally, in Section 6 we present performance measurements of the FT and + hinted decoding algorithms and make explicit comparisons to the BM and + KV decoders familiar to users of older versions of +\emph on +WSJT +\emph default +, +\emph on +MAP65 +\emph default + and +\emph on +WSJT-X +\emph default +. + Section 7 summarizes some on-the-air experiences with the new decoder. + Refer to the sidebar +\series bold +Glossary of Specialized Terms +\series default + for brief definitions of some potentially unfamiliar language. +\end_layout + +\begin_layout Section +\begin_inset CommandInset label +LatexCommand label +name "sec:JT65-messages-and" + +\end_inset + +JT65 Messages and Reed Solomon Codes +\end_layout + +\begin_layout Standard +The JT65 message frame consists of a short, compressed 72-bit message encoded + for transmission with a Reed-Solomon code. + Reed-Solomon codes are +\emph on +block codes +\emph default + +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Block code: }" +description "An error-correcting code that treats data in blocks of fixed size." + +\end_inset + + characterized by +\begin_inset Formula $n$ +\end_inset + +, the length of their +\emph on +codewords +\emph default +; +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Codeword:}" +description "For the JT65 code, a vector of 63 symbol values each in the range 0 to 63." + +\end_inset + + +\begin_inset Formula $k$ +\end_inset + +, the number of message symbols conveyed by the codeword; and the transmission + alphabet, or number of possible values for each symbol in a codeword. + The codeword length and the number of message symbols are specified with + the notation +\begin_inset Formula $(n,k)$ +\end_inset + +. + JT65 uses a (63,12) Reed-Solomon code with an alphabet of 64 possible values + for each symbol. + Each of the 12 message symbols represents +\begin_inset Formula $\log_{2}64=6$ +\end_inset + + message bits. + The source-encoded +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Source encoding: }" +description "Compression of a message to use a minimum number or bits. JT65 source-encodes all messages to 72 bits." + +\end_inset + + message conveyed by a 63-symbol JT65 frame thus consists of 72 information + bits. + The JT65 code is +\emph on +systematic +\emph default +, which means that the 12 message symbols are embedded in the codeword without + modification and another 51 parity symbols derived from the message symbols + are added to form a codeword of 63 symbols. + +\end_layout + +\begin_layout Standard +In coding theory the concept of +\emph on +Hamming distance +\emph default + +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Hamming distance: }" +description "The Hamming distance between two codewords, or between a received word and a codeword, is equal to the number of symbol positions in which they differ." + +\end_inset + + is used as a measure of disagreement between different codewords, or between + a received word +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Received word: }" +description "A vector of symbol values, possibly accompanied by soft information on individual reliabilities." + +\end_inset + + and a codeword. + Hamming distance is the number of code symbols that differ in two words + being compared. + Reed-Solomon codes have guaranteed minimum Hamming distance +\begin_inset Formula $d$ +\end_inset + +, where +\begin_inset Formula +\begin{equation} +d=n-k+1.\label{eq:minimum_distance} +\end{equation} + +\end_inset + +With +\begin_inset Formula $n=63$ +\end_inset + + and +\begin_inset Formula $k=12$ +\end_inset + + the minimum Hamming distance of the JT65 code is +\begin_inset Formula $d=52$ +\end_inset + +. + With 72 information bits in each message, JT65 can transmit any one of + +\begin_inset Formula $2^{72}\approx4.7\times10^{21}$ +\end_inset + + possible messages. + The codeword for any message differs from every other codeword in at least + 52 of the 63 symbol positions. +\end_layout + +\begin_layout Standard +A received word containing some +\emph on +errors +\emph default + (incorrect symbols) can be decoded into the correct codeword using a determinis +tic, +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Deterministic algorithm: }" +description "A series of computational steps that for the same input always produces the same output." + +\end_inset + + algebraic algorithm provided that no more than +\begin_inset Formula $t$ +\end_inset + + symbols were received incorrectly, where +\begin_inset Formula +\begin{equation} +t=\left\lfloor \frac{n-k}{2}\right\rfloor .\label{eq:t} +\end{equation} + +\end_inset + +For the JT65 code +\begin_inset Formula $t=25$ +\end_inset + +, so it is always possible to decode a received word having 25 or fewer + symbol errors. + Any one of several well-known algebraic algorithms, such as the BM algorithm, + can carry out this hard-decision decoding. + Two steps are necessarily involved in this process. + We must (1) determine which symbols were received incorrectly, and (2) + find the correct value of the incorrect symbols. + If we somehow know that certain symbols are incorrect, that information + can be used to reduce the work involved in step 1 and allow step 2 to correct + more than +\begin_inset Formula $t$ +\end_inset + + errors. + In the unlikely event that the location of every error is known, and if + no correct symbols are accidentally labeled as errors, the BM algorithm + can correct up to +\begin_inset Formula $d-1=n-k$ +\end_inset + + errors. + +\end_layout + +\begin_layout Standard +The FT algorithm creates lists of symbols suspected of being incorrect and + sends them to the BM decoder. + Symbols flagged in this way are called +\emph on +erasures +\emph default + +\begin_inset CommandInset nomenclature +LatexCommand nomenclature +symbol "{\\bf Erasure: }" +description "A received symbol may be ``erased'' when confidence in its value is so low that it is unlikely to provide useful information. " + +\end_inset + +. + With perfect erasure information up to +\begin_inset Formula $n-k=51$ +\end_inset + + incorrect symbols can be corrected for the JT65 code. + Imperfect erasure information means that some erased symbols may be correct, + and some other symbols in error. + If +\begin_inset Formula $s$ +\end_inset + + symbols are erased and the remaining +\begin_inset Formula $n-s$ +\end_inset + + symbols contain +\begin_inset Formula $e$ +\end_inset + + errors, the BM algorithm can find the correct codeword as long as +\begin_inset Formula +\begin{equation} +s+2e\le d-1.\label{eq:erasures_and_errors} +\end{equation} + +\end_inset + +If +\begin_inset Formula $s=0$ +\end_inset + +, the decoder is said to be an +\emph on +errors-only +\emph default + decoder. + If +\begin_inset Formula $0=x|N,X,s) '/ & + '-------------------------------') + + hsum=0.d0 + do ix=x,XX + h=hypergeo(ix,NN,XX,s) + hsum=hsum + h + write(*,1020) ix,h,hsum +1020 format(i3,2d13.4) + enddo + +999 end program prob diff --git a/lib/ftrsd/ftrsd_paper/psuccess.lab b/lib/ftrsd/ftrsd_paper/psuccess.lab new file mode 100644 index 00000000..21ed9734 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/psuccess.lab @@ -0,0 +1,14 @@ +-21.5 55 BM +-24.5 50 FT +-27.0 68 DS +-25.2 25 0 +-25.7 37 0.2 +-24.6 16 1.0 +-22.6 35 0 +-20.9 29 0.2 +-19.5 35 1.0 +-28.5 25 1.0 +-28.2 56 0.2 +-28.5 72 0 + + diff --git a/lib/ftrsd/ftrsd_paper/stats-100000-24db-3.dat b/lib/ftrsd/ftrsd_paper/stats-100000-24db-3.dat new file mode 100644 index 00000000..bd2a10f4 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/stats-100000-24db-3.dat @@ -0,0 +1,930 @@ + 35 19 45 12 + 34 20 46 6 + 35 27 43 4519 + 33 21 44 11 + 32 22 39 8 + 34 21 48 333 + 30 20 42 2 + 38 25 43 12 + 38 25 49 2958 + 28 20 43 10 + 41 29 44 4070 + 32 19 44 1 + 28 19 43 2 + 38 28 43 10421 + 25 0 0 0 + 36 24 42 8 + 38 25 42 243 + 39 25 45 81 + 33 17 39 2 + 38 25 39 157 + 37 27 45 1 + 31 18 39 8 + 35 22 41 2 + 31 20 45 32 + 40 30 45 11123 + 34 25 48 516 + 37 22 49 73 + 32 19 45 2 + 39 25 43 49 + 35 25 42 12 + 43 32 45 3645 + 35 21 45 124 + 39 26 48 31 + 40 26 48 23 + 36 25 43 169 + 33 21 41 8 + 31 21 49 3 + 37 23 46 2 + 32 27 41 8 + 36 23 43 2112 + 29 19 49 4 + 34 24 41 170 + 27 15 44 1 + 34 21 43 2 + 39 25 47 28 + 30 18 43 10 + 37 22 40 8 + 42 33 48 64709 + 36 25 43 10 + 35 20 51 17 + 37 28 45 301 + 34 18 40 9 + 34 25 47 23 + 39 28 43 4856 + 36 24 45 7057 + 35 25 47 769 + 38 28 47 208 + 39 27 47 52290 + 35 22 44 85 + 34 23 48 7 + 37 21 47 82 + 42 25 39 1677 + 29 17 41 8 + 41 24 46 656 + 35 24 43 2 + 38 22 45 10400 + 36 20 42 14 + 33 22 46 2 + 25 0 0 0 + 33 20 45 12 + 30 17 45 1 + 34 20 43 40 + 32 21 42 14 + 28 15 44 1 + 37 23 42 8 + 32 21 40 8 + 39 28 44 65 + 30 17 41 2 + 32 25 44 134 + 38 24 43 12 + 38 23 47 153 + 39 26 42 8 + 37 20 47 35 + 39 27 47 1003 + 36 23 45 215 + 38 28 49 46 + 34 24 47 200 + 35 23 40 8 + 30 19 44 1 + 38 25 43 32 + 32 22 39 103 + 33 23 42 2 + 34 24 47 6 + 33 22 43 13 + 42 28 43 2127 + 34 22 41 113 + 39 30 41 517 + 30 17 42 8 + 32 20 45 1 + 34 20 51 17 + 32 15 39 9 + 37 23 47 223 + 28 15 43 1 + 38 24 42 251 + 41 26 45 2 + 39 25 49 7 + 35 26 47 237 + 32 18 43 25 + 33 23 43 8 + 41 29 43 2667 + 28 17 45 1 + 34 23 47 53 + 32 19 39 9 + 34 24 42 59 + 36 22 44 8 + 34 20 45 59 + 37 24 45 12 + 28 17 44 1 + 41 29 43 24865 + 32 19 46 6 + 33 22 47 6 + 36 20 47 143 + 36 22 47 34 + 33 19 39 9 + 38 22 44 523 + 34 24 42 737 + 36 24 39 170 + 35 22 43 2 + 32 19 48 22 + 33 20 49 76 + 42 24 49 6910 + 37 22 47 94 + 40 24 43 6 + 35 25 45 33 + 29 22 41 2 + 40 24 46 2096 + 37 20 45 135 + 36 26 43 113 + 36 21 43 13 + 37 24 47 49 + 35 24 43 54 + 37 22 43 8 + 35 23 44 2 + 30 20 43 11 + 39 30 47 2870 + 42 33 44 585 + 26 17 45 2 + 41 29 47 79 + 40 24 46 836 + 33 19 45 201 + 34 21 39 13 + 33 21 49 60 + 35 24 44 248 + 33 24 43 24 + 39 29 44 151 + 31 23 46 1 + 36 23 46 1 + 41 27 47 5565 + 42 26 47 378 + 35 27 45 4571 + 40 30 47 6422 + 32 20 42 8 + 38 28 45 449 + 38 26 47 595 + 39 24 47 1555 + 41 25 49 645 + 32 19 40 8 + 35 25 45 97 + 25 0 0 0 + 30 19 44 25 + 31 18 45 1 + 41 24 51 6915 + 34 23 46 1917 + 30 19 43 2 + 35 22 47 20 + 38 23 43 882 + 30 20 48 5 + 37 25 44 919 + 34 20 45 74 + 38 25 46 394 + 39 21 49 738 + 35 20 47 22 + 40 30 47 190 + 41 27 45 1515 + 39 27 49 55 + 35 25 41 994 + 39 27 47 7117 + 37 22 46 19 + 33 21 41 2 + 34 18 47 19 + 30 20 46 6 + 31 21 46 1 + 36 24 47 98 + 40 24 43 39 + 38 25 45 138 + 41 27 47 33 + 40 29 49 2510 + 36 26 43 2 + 34 21 45 1 + 40 26 49 1924 + 36 17 43 2 + 38 27 45 68 + 34 22 45 61 + 32 22 40 8 + 37 19 43 4784 + 32 16 43 8 + 38 27 50 46 + 35 21 43 38 + 35 22 49 4 + 38 27 49 31 + 39 28 47 4677 + 30 18 45 2 + 43 28 47 8235 + 38 28 43 830 + 32 21 47 15 + 37 24 42 10 + 37 23 45 259 + 37 25 45 35 + 40 24 45 524 + 35 19 44 1 + 36 23 45 84 + 36 24 50 17 + 31 20 46 1 + 35 24 42 74 + 42 27 47 1445 + 40 28 48 31 + 36 23 45 151 + 34 22 46 6 + 33 24 49 16 + 30 20 45 2 + 38 22 43 125 + 40 25 49 64 + 35 23 49 86 + 38 24 46 613 + 42 25 47 4232 + 34 24 43 31 + 32 18 41 2 + 37 26 43 70 + 37 27 41 14 + 37 22 39 129 + 38 27 49 3 + 32 22 47 15 + 41 27 41 472 + 38 24 43 25 + 35 28 43 309 + 41 25 47 82 + 40 23 43 8 + 40 21 43 1716 + 38 22 48 5 + 37 20 47 22 + 42 28 43 315 + 32 23 43 79 + 25 0 0 0 + 42 23 47 2245 + 35 24 45 2 + 41 25 44 12 + 36 23 43 1 + 36 19 45 151 + 41 28 45 2207 + 40 27 45 76 + 34 20 47 6 + 41 28 46 370 + 38 20 45 12 + 32 20 43 8 + 39 24 45 8 + 41 27 47 26941 + 35 23 46 3 + 34 25 41 14 + 43 27 47 26905 + 35 25 45 2 + 32 20 50 3 + 31 17 41 2 + 38 26 47 4157 + 33 24 41 2 + 41 29 43 26513 + 35 22 45 297 + 37 26 44 99 + 33 19 43 10 + 39 23 45 138 + 39 26 47 1320 + 33 22 42 2 + 42 32 45 791 + 33 23 51 3 + 38 25 43 8 + 40 27 49 1210 + 43 27 45 32969 + 37 26 49 108 + 38 18 45 1268 + 40 28 49 7810 + 36 25 44 47 + 38 27 48 20 + 34 20 44 10 + 41 27 45 429 + 33 18 43 8 + 29 17 45 1 + 40 25 42 9 + 30 21 49 4 + 37 22 45 10 + 23 0 0 0 + 36 15 45 2509 + 29 21 45 18 + 33 23 45 53 + 43 27 49 7533 + 37 28 45 2652 + 36 24 49 31 + 32 20 43 25 + 42 27 49 1500 + 41 26 45 8 + 40 25 47 152 + 37 26 45 151 + 37 27 43 139 + 34 20 47 4 + 31 21 43 44 + 37 28 45 241 + 35 25 45 422 + 33 22 45 6 + 39 26 48 23 + 38 27 49 359 + 42 26 45 1430 + 36 28 47 116 + 33 23 41 232 + 38 25 47 73 + 35 24 43 16 + 42 29 47 398 + 38 27 49 2203 + 32 20 47 3 + 32 18 48 3 + 36 23 47 44 + 37 24 48 147 + 39 22 45 31 + 31 20 44 1 + 34 21 43 8 + 39 27 47 201 + 34 23 44 12 + 34 24 43 8 + 36 17 46 2 + 41 27 47 8709 + 41 26 45 112 + 37 23 47 216 + 38 24 45 93 + 32 19 45 44 + 34 22 45 8 + 33 24 41 14 + 34 22 41 9 + 35 23 42 136 + 36 26 43 3272 + 34 18 44 40 + 38 25 43 316 + 29 23 39 9 + 35 23 45 2 + 41 29 42 136 + 37 26 43 12 + 34 21 46 43 + 39 21 47 23 + 40 29 49 14666 + 36 19 45 400 + 37 24 43 8 + 35 19 44 2 + 36 26 45 14 + 36 22 43 103 + 33 19 45 6 + 35 24 43 1 + 31 22 43 80 + 35 23 46 22 + 28 18 41 2 + 35 24 45 31 + 34 24 47 46 + 37 24 42 2 + 37 27 43 525 + 31 16 41 9 + 30 18 45 2 + 39 25 47 1416 + 37 24 46 23 + 40 28 49 5 + 39 26 46 2071 + 28 13 42 8 + 31 17 47 3 + 34 22 49 3 + 42 23 47 61 + 30 21 41 2 + 40 23 47 208 + 38 22 48 6 + 35 17 40 8 + 36 20 45 32 + 37 22 47 1116 + 41 28 47 14145 + 43 28 49 96342 + 35 19 45 102 + 31 23 43 8 + 33 20 43 1 + 30 19 46 90 + 41 27 45 19090 + 35 26 45 2942 + 40 25 47 127 + 35 23 45 12 + 37 26 46 76 + 31 19 44 32 + 42 31 49 4951 + 43 30 44 38924 + 35 19 51 17 + 41 31 44 6637 + 33 22 42 2 + 33 25 46 12 + 31 24 44 10 + 27 16 49 4 + 39 24 45 16 + 33 20 40 8 + 39 31 48 5073 + 39 21 47 72 + 35 21 47 3 + 38 27 41 1168 + 35 22 43 8 + 28 18 45 1 + 38 28 40 776 + 33 22 51 3 + 34 22 41 370 + 37 25 43 3210 + 32 24 43 8 + 35 24 46 3 + 39 20 45 41 + 35 17 43 49 + 39 29 46 20 + 31 21 44 1 + 43 24 48 4400 + 36 23 48 350 + 38 29 47 520 + 36 24 45 49 + 39 27 43 493 + 34 15 45 6 + 41 31 43 59993 + 34 24 42 27 + 31 14 41 1 + 40 30 47 13295 + 35 23 47 202 + 36 22 47 35 + 38 26 45 18576 + 34 26 43 54 + 40 30 51 173 + 43 29 47 105 + 34 24 39 9 + 33 20 43 8 + 35 27 45 65 + 31 18 42 2 + 31 21 45 6 + 40 27 45 979 + 36 21 47 3 + 29 14 43 1 + 37 24 47 432 + 39 24 50 4778 + 33 20 44 2 + 40 27 44 7398 + 36 22 47 148 + 35 21 44 11 + 35 22 45 206 + 30 18 42 8 + 40 30 43 8 + 30 22 42 9 + 29 21 39 9 + 41 26 43 1248 + 39 24 43 14 + 38 24 49 605 + 35 20 42 155 + 33 22 47 53 + 34 20 43 10 + 35 26 49 21 + 31 18 45 1 + 32 19 39 9 + 31 20 43 19 + 41 23 41 157 + 36 23 42 9 + 28 19 45 1 + 33 19 43 10 + 38 22 44 25 + 29 19 41 2 + 34 19 42 8 + 35 21 39 9 + 34 23 45 2 + 41 30 47 71025 + 40 26 48 3059 + 36 24 45 1346 + 35 19 47 34 + 36 25 45 112 + 39 27 41 7065 + 38 24 47 4 + 29 18 42 1 + 30 20 41 2 + 32 22 49 3 + 40 29 45 4589 + 38 25 42 234 + 42 28 49 3171 + 35 22 45 34 + 39 24 41 5693 + 29 20 43 2 + 29 16 44 14 + 37 25 45 19 + 36 18 44 8 + 36 27 45 1224 + 38 28 47 8906 + 29 15 51 3 + 33 20 47 46 + 33 17 41 9 + 40 22 45 1775 + 32 22 45 8 + 35 21 43 8 + 38 24 41 9 + 41 22 47 10005 + 36 27 43 12 + 33 21 47 35 + 35 21 39 9 + 34 22 44 2 + 34 17 45 67 + 31 18 45 1 + 34 21 46 32 + 35 26 44 1 + 34 23 44 8 + 31 24 47 3 + 43 23 49 9210 + 40 20 48 114 + 36 25 42 8 + 37 24 46 336 + 37 23 43 138 + 38 26 47 89 + 38 24 47 6494 + 30 18 45 1 + 43 28 47 677 + 31 23 48 3 + 32 19 43 1 + 36 23 44 19 + 43 30 47 81276 + 37 22 48 106 + 37 24 45 12 + 37 22 45 68 + 28 17 43 24 + 43 28 45 1446 + 40 30 46 2753 + 35 23 44 1 + 28 16 43 2 + 29 19 42 2 + 31 21 42 2 + 39 26 48 98 + 41 30 47 21848 + 35 22 47 5 + 40 31 45 448 + 34 23 45 94 + 29 17 42 8 + 39 30 46 1231 + 41 22 47 49 + 30 15 51 7 + 35 26 41 9 + 29 17 49 7 + 33 22 43 12 + 33 19 46 5 + 35 24 45 12 + 33 22 42 9 + 34 18 43 13 + 36 21 43 63 + 37 27 45 32 + 37 23 49 474 + 31 17 46 19 + 38 24 41 2 + 40 28 47 1621 + 39 25 47 214 + 32 21 42 19 + 34 22 47 105 + 35 26 42 2 + 35 21 44 13 + 40 25 47 556 + 39 27 49 3 + 36 25 45 32 + 39 27 41 10 + 35 20 45 1 + 28 17 45 1 + 35 23 47 6 + 33 20 50 137 + 34 22 43 177 + 30 19 41 9 + 33 23 47 579 + 33 22 39 9 + 39 20 42 74 + 42 28 47 112 + 40 29 44 197 + 36 23 43 2 + 30 17 49 3 + 37 27 45 3815 + 35 24 43 74 + 35 22 47 24 + 40 27 46 82 + 36 25 41 366 + 33 23 44 1 + 37 21 40 131 + 34 22 45 16 + 36 24 45 306 + 39 26 47 82 + 29 17 45 1 + 36 23 48 3 + 35 20 44 63 + 35 23 46 5 + 39 25 43 792 + 32 22 49 5 + 35 23 41 9 + 37 24 41 12711 + 41 32 43 36575 + 34 23 42 8 + 31 21 43 2 + 35 24 41 2 + 35 24 39 8 + 37 23 48 75 + 35 19 43 12 + 40 25 49 914 + 38 22 49 60 + 34 19 42 10 + 42 33 44 9038 + 37 27 45 1849 + 29 20 42 138 + 37 27 43 332 + 36 26 45 36 + 32 18 45 6 + 37 25 46 4676 + 29 18 45 6 + 34 22 43 8 + 41 32 45 1966 + 30 18 42 12 + 33 20 45 1 + 31 23 45 6 + 30 21 46 1 + 36 21 43 14 + 34 18 45 37 + 42 32 47 3508 + 41 32 41 13 + 37 25 45 719 + 33 20 45 111 + 38 28 42 8 + 35 23 43 14 + 39 23 47 123 + 28 13 44 1 + 34 19 41 38 + 35 21 43 8 + 33 26 47 124 + 30 18 41 9 + 43 30 46 11935 + 40 28 48 2329 + 35 19 45 286 + 30 21 43 80 + 37 21 49 474 + 41 27 49 1560 + 42 24 46 1802 + 38 28 42 6807 + 38 24 43 63 + 33 24 49 35 + 41 27 41 9795 + 29 16 41 2 + 29 17 43 2 + 34 21 45 125 + 39 28 45 1008 + 34 21 42 8 + 36 23 45 2 + 34 22 41 8 + 34 21 41 74 + 37 21 43 262 + 30 18 41 8 + 33 22 49 3 + 33 21 42 1 + 35 28 49 21 + 31 19 43 1 + 36 24 44 10 + 40 23 49 583 + 33 19 37 9 + 32 21 45 6 + 38 24 47 15 + 42 27 47 2847 + 36 28 45 106 + 39 28 43 53 + 30 16 42 2 + 28 18 49 3 + 33 21 44 1 + 36 24 45 3050 + 37 27 40 8 + 35 19 43 12 + 41 29 43 19008 + 21 0 0 0 + 38 26 41 762 + 33 21 46 12 + 41 26 47 14517 + 33 24 49 3 + 41 31 47 287 + 35 24 51 17 + 37 27 42 38 + 34 22 43 24 + 39 26 46 135 + 38 26 41 493 + 35 22 42 8 + 38 24 41 1082 + 32 23 42 1 + 33 24 40 8 + 37 25 48 640 + 28 14 39 9 + 39 20 45 212 + 37 29 45 610 + 34 26 47 57 + 29 21 41 8 + 35 16 45 53 + 35 21 44 2 + 38 26 48 188 + 34 25 41 10 + 36 23 44 8 + 35 21 45 8 + 35 26 41 8 + 37 26 40 9 + 28 12 43 1 + 34 22 51 3 + 35 25 44 13 + 32 16 44 32 + 32 19 45 143 + 29 17 43 1 + 35 22 43 93 + 38 21 43 99 + 36 26 49 242 + 34 22 45 8 + 40 24 45 136 + 40 24 48 88 + 38 21 46 49 + 40 27 49 116 + 41 26 44 3696 + 35 23 42 8 + 28 15 45 104 + 33 21 43 106 + 35 25 45 31 + 33 24 40 113 + 36 24 46 23 + 37 25 45 334 + 32 21 46 12 + 35 21 41 2 + 36 22 45 8 + 37 18 43 13 + 37 26 47 48 + 39 25 46 400 + 37 27 43 174 + 37 23 47 41 + 40 21 47 1811 + 38 26 45 79 + 26 15 43 1 + 39 27 49 19 + 31 19 44 1 + 37 22 43 8 + 32 24 38 9 + 34 23 48 3 + 37 24 51 22 + 27 18 42 2 + 31 22 47 5 + 33 17 41 2 + 40 28 45 14534 + 37 21 47 5 + 27 15 43 2 + 43 26 47 46658 + 39 22 43 8 + 36 23 41 2 + 31 19 43 12 + 36 24 43 10 + 33 20 43 149 + 30 19 47 3 + 39 27 51 1236 + 41 26 45 4744 + 39 22 47 100 + 32 18 44 6 + 32 21 43 54 + 40 30 46 777 + 35 25 43 355 + 36 24 41 138 + 40 30 47 3056 + 39 28 46 19 + 34 21 46 6 + 34 18 46 52 + 36 27 41 232 + 35 25 51 3 + 36 28 44 110 + 33 23 45 1 + 37 22 46 64301 + 39 23 49 41 + 39 30 40 25 + 36 23 48 6 + 29 17 42 2 + 36 23 44 1 + 32 17 43 40 + 32 16 49 86 + 29 19 49 5 + 38 26 41 9 + 40 28 43 56710 + 41 29 45 1711 + 36 23 49 345 + 35 25 43 8 + 35 24 46 19 + 37 23 41 648 + 30 18 45 1 + 30 21 43 1 + 34 20 45 12 + 42 25 47 431 + 40 27 41 15878 + 34 22 43 8 + 41 29 48 49 + 32 21 43 2 + 37 22 43 2 + 39 28 49 86 + 43 28 45 8032 + 41 30 49 15674 + 34 22 48 17 + 36 24 48 107 + 28 20 44 1 + 43 28 48 1986 + 40 25 47 2585 + 38 21 43 59 + 38 28 41 167 + 34 22 39 9 + 43 27 48 4196 + 32 20 44 120 + 33 25 45 99 + 26 12 42 2 + 26 15 47 4 + 37 21 42 10 + 35 25 49 3 + 42 30 49 11151 + 33 20 44 2 + 39 26 45 65238 + 31 16 40 2 + 38 26 39 8 + 36 22 45 82 + 32 22 49 7 + 33 20 45 2 + 40 24 43 12 + 32 18 50 3 + 31 21 40 2 + 34 18 44 2 + 38 28 46 194 + 36 21 43 12 + 32 20 43 8 + 30 18 42 2 + 37 21 47 31 + 36 23 47 15 + 36 21 45 113 + 34 23 44 1 + 43 29 49 3889 + 37 24 47 32 + 41 22 43 243 + 38 25 47 707 + 35 22 43 18399 + 33 22 45 123 + 37 24 42 8 + 39 25 47 1087 + 34 23 47 107 + 32 21 42 2 + 42 25 47 106 + 39 24 42 13560 + 42 29 49 52387 + 38 27 43 59 + 31 18 39 9 + 40 28 48 41 + 37 25 45 11 + 30 23 45 242 + 38 23 47 1673 + 36 23 45 751 + 29 22 41 2 + 36 19 48 3 + 36 22 45 12 + 35 18 47 20 + 40 28 49 17369 + 29 19 46 2 + 36 26 42 25 + 42 30 49 4767 + 30 20 45 6 + 35 24 44 12 + 41 24 42 1537 + 38 25 47 629 + 31 21 44 2 + 34 22 43 1 + 33 20 47 3 + 34 20 43 8 + 40 26 49 4320 + 31 16 43 9 + 34 22 45 8 + 32 22 46 124 + 32 20 43 13 + 40 28 47 1185 + 41 24 45 30643 + 39 23 43 1658 + 33 23 44 8 + 36 22 46 23 + 41 25 47 114 + 36 21 42 12 + 33 19 48 31 + 42 28 48 76 + 29 22 39 9 + 36 21 47 3 + 37 27 45 282 + 42 29 46 24995 + 36 26 39 9 + 40 25 46 123 + 39 26 41 8 + 41 30 45 3143 + 34 20 41 27 + 38 31 42 17297 + 40 24 51 3052 + 36 28 45 190 + 31 23 42 8 + 42 26 42 68 + 39 31 45 37327 + 37 27 41 8 + 36 20 45 76 + 38 26 42 10 + 36 21 45 63 + 40 31 43 140 + 40 27 49 21 + 31 22 36 9 + 34 22 39 9 + 29 17 43 2 + 36 26 45 61 + 38 23 45 15 + 31 21 43 54 + 36 22 41 93 + 31 18 43 2 + 35 25 49 108 + 41 29 45 18292 + 37 25 45 104 + 28 20 41 2 + 35 26 46 35 + 34 20 46 19 + 38 22 51 183 + 34 14 43 8 + 32 23 43 16 + 27 17 44 1 + 29 15 42 2 + 37 26 41 129 diff --git a/lib/ftrsd/ftrsd_paper/stats_0.0 b/lib/ftrsd/ftrsd_paper/stats_0.0 new file mode 100644 index 00000000..75c97780 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/stats_0.0 @@ -0,0 +1,27 @@ + SNR Files Sync BM FT Hint Total False BadSync +-------------------------------------------------------- +-18.0 1000 1000 1000 1000 1000 1000 0 0 +-18.5 1000 1000 1000 1000 1000 1000 0 0 +-19.0 1000 1000 1000 1000 1000 1000 0 0 +-19.5 1000 1000 1000 1000 1000 1000 0 0 +-20.0 1000 1000 1000 1000 1000 1000 0 0 +-20.5 1000 1000 1000 1000 1000 1000 0 0 +-21.0 1000 1000 1000 1000 1000 1000 0 0 +-21.5 1000 1000 991 1000 1000 1000 0 0 +-22.0 1000 1000 918 1000 1000 1000 0 0 +-22.5 1000 1000 631 1000 1000 1000 0 0 +-23.0 1000 1000 261 1000 1000 1000 0 0 +-23.5 1000 1000 57 990 1000 1000 0 0 +-24.0 1000 1000 0 925 1000 1000 0 0 +-24.5 1000 1000 0 737 1000 1000 0 0 +-25.0 1000 999 0 445 999 999 1 ? +-25.5 1000 996 0 191 996 996 2 ? +-26.0 1000 980 0 68 985 985 3 ? +-26.5 1000 953 0 18 975 975 3 ? +-27.0 1000 904 0 3 926 926 4 ? +-27.5 1000 816 0 2 874 874 3 ? +-28.0 1000 722 0 0 786 786 7 ? +-28.5 1000 590 0 0 616 616 12 ? +-29.0 1000 451 0 0 479 479 15 ? +-29.5 1000 355 0 0 303 303 27 ? +-30.0 1000 277 0 0 173 173 28 ? diff --git a/lib/ftrsd/ftrsd_paper/stats_0.2 b/lib/ftrsd/ftrsd_paper/stats_0.2 new file mode 100644 index 00000000..1e0cb00c --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/stats_0.2 @@ -0,0 +1,27 @@ + SNR Files Sync BM FT Hint Total False BadSync +-------------------------------------------------------- +-18.0 1000 998 973 998 998 998 0 2 +-18.5 1000 1000 960 1000 1000 1000 0 0 +-19.0 1000 1000 917 1000 1000 1000 0 0 +-19.5 1000 1000 849 1000 1000 1000 0 0 +-20.0 1000 1000 725 1000 1000 1000 0 0 +-20.5 1000 1000 549 1000 1000 1000 0 0 +-21.0 1000 1000 373 1000 1000 1000 0 0 +-21.5 1000 1000 216 1000 1000 1000 0 0 +-22.0 1000 1000 100 998 1000 1000 0 0 +-22.5 1000 1000 32 998 1000 1000 0 0 +-23.0 1000 1000 12 991 1000 1000 0 0 +-23.5 1000 998 2 958 1000 1000 0 2 +-24.0 1000 992 0 878 998 998 1 8 +-24.5 1000 986 0 739 995 995 0 14 +-25.0 1000 977 0 533 991 991 0 23 +-25.5 1000 959 0 324 975 975 3 41 +-26.0 1000 930 0 153 953 953 1 70 +-26.5 1000 874 0 51 924 924 8 126 +-27.0 1000 808 0 14 866 866 6 192 +-27.5 1000 716 0 3 799 799 10 284 +-28.0 1000 610 0 1 689 689 14 390 +-28.5 1000 497 0 0 596 596 19 503 +-29.0 1000 399 0 0 451 451 21 601 +-29.5 1000 300 0 0 270 270 27 700 +-30.0 1000 243 0 0 172 172 26 757 diff --git a/lib/ftrsd/ftrsd_paper/stats_1.0 b/lib/ftrsd/ftrsd_paper/stats_1.0 new file mode 100644 index 00000000..34f94c62 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/stats_1.0 @@ -0,0 +1,27 @@ + SNR Files Sync BM FT Hint Total False BadSync +-------------------------------------------------------- +-18.0 1000 998 917 998 998 998 1 2 +-18.5 1000 998 824 998 998 998 0 2 +-19.0 1000 999 695 999 999 999 0 1 +-19.5 1000 999 504 999 999 999 0 1 +-20.0 1000 1000 300 1000 1000 1000 0 0 +-20.5 1000 1000 148 1000 1000 1000 0 0 +-21.0 1000 1000 56 1000 1000 1000 0 0 +-21.5 1000 1000 10 1000 1000 1000 0 0 +-22.0 1000 999 3 995 1000 1000 0 1 +-22.5 1000 998 0 972 1000 1000 0 2 +-23.0 1000 997 0 899 999 999 0 3 +-23.5 1000 996 0 758 999 999 0 4 +-24.0 1000 990 0 545 999 999 0 10 +-24.5 1000 981 0 305 988 988 2 19 +-25.0 1000 964 0 128 987 987 0 36 +-25.5 1000 930 0 43 956 956 4 70 +-26.0 1000 870 0 15 932 932 4 130 +-26.5 1000 810 0 4 889 889 8 190 +-27.0 1000 737 0 0 798 798 9 263 +-27.5 1000 632 0 0 650 650 10 368 +-28.0 1000 522 0 0 526 526 15 478 +-28.5 1000 426 0 0 383 383 19 574 +-29.0 1000 332 0 0 226 226 34 668 +-29.5 1000 260 0 0 136 136 32 740 +-30.0 1000 209 0 0 64 64 47 791 diff --git a/lib/ftrsd/ftrsd_paper/wer.lab b/lib/ftrsd/ftrsd_paper/wer.lab new file mode 100644 index 00000000..e69de29b diff --git a/lib/ftrsd/ftrsd_paper/wer2.lab b/lib/ftrsd/ftrsd_paper/wer2.lab new file mode 100644 index 00000000..b3440f83 --- /dev/null +++ b/lib/ftrsd/ftrsd_paper/wer2.lab @@ -0,0 +1,7 @@ +-25.7 30 $10^5$ +-25.25 36 $10^4$ +-24.5 44 $10^3$ +-24.15 48 $10^2$ +-23.7 44 10 +-22.5 48 BM +-25.2 24 KV \ No newline at end of file diff --git a/lib/ftrsd/init_rs.c b/lib/ftrsd/init_rs.c new file mode 100644 index 00000000..4b1d1edb --- /dev/null +++ b/lib/ftrsd/init_rs.c @@ -0,0 +1,119 @@ +/* Initialize a RS codec + * + * Copyright 2002 Phil Karn, KA9Q + * May be used under the terms of the GNU General Public License (GPL) + */ +#include + +#ifdef CCSDS +#include "ccsds.h" +#elif defined(BIGSYM) +#include "int.h" +#else +#include "char.h" +#endif + +void FREE_RS(void *p){ + struct rs *rs = (struct rs *)p; + + free(rs->alpha_to); + free(rs->index_of); + free(rs->genpoly); + free(rs); +} + +/* Initialize a Reed-Solomon codec + * symsize = symbol size, bits (1-8) + * gfpoly = Field generator polynomial coefficients + * fcr = first root of RS code generator polynomial, index form + * prim = primitive element to generate polynomial roots + * nroots = RS code generator polynomial degree (number of roots) + */ +void *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned fcr,unsigned prim, + unsigned int nroots){ + struct rs *rs; + int i, j, sr,root,iprim; + + if(symsize > 8*sizeof(DTYPE)) + return NULL; /* Need version with ints rather than chars */ + + if(fcr >= (1<= (1<= (1<mm = symsize; + rs->nn = (1<alpha_to = (DTYPE *)malloc(sizeof(DTYPE)*(rs->nn+1)); + if(rs->alpha_to == NULL){ + free(rs); + return NULL; + } + rs->index_of = (DTYPE *)malloc(sizeof(DTYPE)*(rs->nn+1)); + if(rs->index_of == NULL){ + free(rs->alpha_to); + free(rs); + return NULL; + } + + /* Generate Galois field lookup tables */ + rs->index_of[0] = A0; /* log(zero) = -inf */ + rs->alpha_to[A0] = 0; /* alpha**-inf = 0 */ + sr = 1; + for(i=0;inn;i++){ + rs->index_of[sr] = i; + rs->alpha_to[i] = sr; + sr <<= 1; + if(sr & (1<nn; + } + if(sr != 1){ + /* field generator polynomial is not primitive! */ + free(rs->alpha_to); + free(rs->index_of); + free(rs); + return NULL; + } + + /* Form RS code generator polynomial from its roots */ + rs->genpoly = (DTYPE *)malloc(sizeof(DTYPE)*(nroots+1)); + if(rs->genpoly == NULL){ + free(rs->alpha_to); + free(rs->index_of); + free(rs); + return NULL; + } + rs->fcr = fcr; + rs->prim = prim; + rs->nroots = nroots; + + /* Find prim-th root of 1, used in decoding */ + for(iprim=1;(iprim % prim) != 0;iprim += rs->nn) + ; + rs->iprim = iprim / prim; + + rs->genpoly[0] = 1; + for (i = 0,root=fcr*prim; i < nroots; i++,root += prim) { + rs->genpoly[i+1] = 1; + + /* Multiply rs->genpoly[] by @**(root + x) */ + for (j = i; j > 0; j--){ + if (rs->genpoly[j] != 0) + rs->genpoly[j] = rs->genpoly[j-1] ^ rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[j]] + root)]; + else + rs->genpoly[j] = rs->genpoly[j-1]; + } + /* rs->genpoly[0] can never be zero */ + rs->genpoly[0] = rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[0]] + root)]; + } + /* convert rs->genpoly[] to index form for quicker encoding */ + for (i = 0; i <= nroots; i++) + rs->genpoly[i] = rs->index_of[rs->genpoly[i]]; + + return rs; +} diff --git a/lib/ftrsd/int.h b/lib/ftrsd/int.h new file mode 100644 index 00000000..ada5bfd4 --- /dev/null +++ b/lib/ftrsd/int.h @@ -0,0 +1,54 @@ +/* Include file to configure the RS codec for integer symbols + * + * Copyright 2002, Phil Karn, KA9Q + * May be used under the terms of the GNU General Public License (GPL) + */ +#define DTYPE int + +/* Reed-Solomon codec control block */ +struct rs { + unsigned int mm; /* Bits per symbol */ + unsigned int nn; /* Symbols per block (= (1<= rs->nn) { + x -= rs->nn; + x = (x >> rs->mm) + (x & rs->nn); + } + return x; +} +#define MODNN(x) modnn(rs,x) + +#define MM (rs->mm) +#define NN (rs->nn) +#define ALPHA_TO (rs->alpha_to) +#define INDEX_OF (rs->index_of) +#define GENPOLY (rs->genpoly) +#define NROOTS (rs->nroots) +#define FCR (rs->fcr) +#define PRIM (rs->prim) +#define IPRIM (rs->iprim) +#define A0 (NN) + +#define ENCODE_RS encode_rs_int +#define DECODE_RS decode_rs_int +#define INIT_RS init_rs_int +#define FREE_RS free_rs_int + +void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity); +int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras, int calc_syn); +void *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned int fcr, + unsigned int prim,unsigned int nroots); +void FREE_RS(void *p); + + + + diff --git a/lib/ftrsd/rs2.h b/lib/ftrsd/rs2.h new file mode 100644 index 00000000..c2b807d1 --- /dev/null +++ b/lib/ftrsd/rs2.h @@ -0,0 +1,16 @@ +/* User include file for the Reed-Solomon codec + * Copyright 2002, Phil Karn KA9Q + * May be used under the terms of the GNU General Public License (GPL) + */ + +/* General purpose RS codec, integer symbols */ +void encode_rs_int(void *rs,int *data,int *parity); +int decode_rs_int(void *rs,int *data,int *eras_pos,int no_eras, int calc_syn); +void *init_rs_int(int symsize,int gfpoly,int fcr, + int prim,int nroots,int pad); +void free_rs_int(void *rs); + +/* Tables to map from conventional->dual (Taltab) and + * dual->conventional (Tal1tab) bases + */ +extern unsigned char Taltab[],Tal1tab[]; diff --git a/lib/ftrsd/rsdtest.f90 b/lib/ftrsd/rsdtest.f90 new file mode 100644 index 00000000..2c862e5a --- /dev/null +++ b/lib/ftrsd/rsdtest.f90 @@ -0,0 +1,34 @@ +program rsdtest + + real s3(64,63) + character msg*22,arg*12 + integer param(0:7) + + nargs=iargc() + if(nargs.ne.2) then + print*,'Usage: rsdtest ntrials nfiles' + go to 999 + endif + call getarg(1,arg) + read(arg,*) ntrials + call getarg(2,arg) + read(arg,*) nfiles + + open(10,file='s3_1000.bin',access='stream', status='old') + open(22,file='kvasd.dat',access='direct',recl=1024,status='unknown') + + nadd=1 + ifile0=0 + if(nfiles.lt.0) then + ifile0=-nfiles + nfiles=99999 + endif + + do ifile=1,nfiles + read(10,end=999) s3 + if(ifile.lt.ifile0) cycle + call extract2(s3,nadd,ntrials,param,msg) + if(ifile.eq.ifile0) exit + enddo + +999 end program rsdtest diff --git a/lib/ftrsd/sfrsd.c b/lib/ftrsd/sfrsd.c new file mode 100644 index 00000000..e64dfc96 --- /dev/null +++ b/lib/ftrsd/sfrsd.c @@ -0,0 +1,137 @@ +/* + sfrsd.c + + A soft-decision decoder for the JT65 (63,12) Reed-Solomon code. + + This decoding scheme is built around Phil Karn's Berlekamp-Massey + errors and erasures decoder. The approach is inspired by a number of + publications, including the stochastic Chase decoder described + in "Stochastic Chase Decoding of Reed-Solomon Codes", by Leroux et al., + IEEE Communications Letters, Vol. 14, No. 9, September 2010 and + "Soft-Decision Decoding of Reed-Solomon Codes Using Successive Error- + and-Erasure Decoding," by Soo-Woong Lee and B. V. K. Vijaya Kumar. + + Steve Franke K9AN, Urbana IL, September 2015 + */ + +#include +#include +#include +#include +#include +#include "sfrsd2.h" + +//*************************************************************************** +void usage(void) +{ + printf("Usage: sfrsd [options...] \n"); + printf(" input file should be in kvasd format\n"); + printf("\n"); + printf("Options:\n"); + printf(" -n number of random erasure vectors to try\n"); + printf(" -v verbose\n"); +} + +int main(int argc, char *argv[]){ + + extern char *optarg; + extern int optind; + + int correct[63], indx[63], param[8]; + int c,i; + char *infile; + + FILE *datfile, *logfile; + int nsec, maxe, nads; + float xlambda; + int mrsym[63],mrprob[63],mr2sym[63],mr2prob[63]; + int nsec2,ncount,dat4[12]; + int ntrials, nverbose, ntry; + int nhard; + double tt; + + ntrials=10000; + nverbose=1; + + while ( (c = getopt(argc, argv, "n:qv")) !=-1 ) { + switch (c) { + case 'n': + ntrials=(int)strtof(optarg,NULL); + printf("ntrials set to %d\n",ntrials); + break; + case 'v': + nverbose=1; + break; + case 'q': //accept (and ignore) -q option for WSJT10 compatibility + break; + case '?': + usage(); + exit(1); + } + } + + if( optind+1 > argc) { + // usage(); + // exit(1); + infile="kvasd.dat"; + } else { + infile=argv[optind]; + } + + logfile=fopen("/tmp/sfrsd.log","a"); + if( !logfile ) { + printf("Unable to open sfrsd.log\n"); + exit(1); + } + + datfile=fopen(infile,"rb"); + if( !datfile ) { + printf("Unable to open kvasd.dat\n"); + exit(1); + } else { + fread(&nsec,sizeof(int),1,datfile); + fread(&xlambda,sizeof(float),1,datfile); + fread(&maxe,sizeof(int),1,datfile); + fread(&nads,sizeof(int),1,datfile); + fread(&mrsym,sizeof(int),63,datfile); + fread(&mrprob,sizeof(int),63,datfile); + fread(&mr2sym,sizeof(int),63,datfile); + fread(&mr2prob,sizeof(int),63,datfile); + fread(&nsec2,sizeof(int),1,datfile); + fread(&ncount,sizeof(int),1,datfile); + fread(&dat4,sizeof(int),12,datfile); + fclose(datfile); + } + + sfrsd2_(mrsym,mrprob,mr2sym,mr2prob,&ntrials,&nverbose,correct,param,indx,&tt,&ntry); + nhard=param[1]; + if( nhard>=0 ) { + for (i=0; i<12; i++) { + dat4[i]=correct[11-i]; + } + } else { + nhard=-1; + memset(dat4,0,12*sizeof(int)); + } + datfile=fopen(infile,"wb"); + if( !datfile ) { + printf("Unable to open kvasd.dat\n"); + return 1; + } else { + fwrite(&nsec,sizeof(int),1,datfile); + fwrite(&xlambda,sizeof(float),1,datfile); + fwrite(&maxe,sizeof(int),1,datfile); + fwrite(&nads,sizeof(int),1,datfile); + fwrite(&mrsym,sizeof(int),63,datfile); + fwrite(&mrprob,sizeof(int),63,datfile); + fwrite(&mr2sym,sizeof(int),63,datfile); + fwrite(&mr2prob,sizeof(int),63,datfile); + fwrite(&nsec2,sizeof(int),1,datfile); + fwrite(&nhard,sizeof(int),1,datfile); + fwrite(&dat4,sizeof(int),12,datfile); + fclose(datfile); + } + exit(0); +} + + diff --git a/lib/ftrsd/sfrsd2.h b/lib/ftrsd/sfrsd2.h new file mode 100644 index 00000000..4ef7ab47 --- /dev/null +++ b/lib/ftrsd/sfrsd2.h @@ -0,0 +1,3 @@ +void ftrsd2_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[], + int* ntrials0, int* verbose0, int correct[], int param[], + int indexes[], double tt[], int ntry[]); diff --git a/lib/ftrsd/sfrsd3.c b/lib/ftrsd/sfrsd3.c new file mode 100644 index 00000000..f117dcca --- /dev/null +++ b/lib/ftrsd/sfrsd3.c @@ -0,0 +1,243 @@ +/* + sfrsd2.c + + A soft-decision decoder for the JT65 (63,12) Reed-Solomon code. + + This decoding scheme is built around Phil Karn's Berlekamp-Massey + errors and erasures decoder. The approach is inspired by a number of + publications, including the stochastic Chase decoder described + in "Stochastic Chase Decoding of Reed-Solomon Codes", by Leroux et al., + IEEE Communications Letters, Vol. 14, No. 9, September 2010 and + "Soft-Decision Decoding of Reed-Solomon Codes Using Successive Error- + and-Erasure Decoding," by Soo-Woong Lee and B. V. K. Vijaya Kumar. + + Steve Franke K9AN and Joe Taylor K1JT + */ + +#include +#include +#include +#include +#include +#include "rs2.h" + +static void *rs; + +void sfrsd2_(int mrsym[], int mrprob[], int mr2sym[], int mr2prob[], + int* ntrials0, int* verbose0, int correct[], int param[], + int indexes[], double tt[], int ntry[]) +{ + int rxdat[63], rxprob[63], rxdat2[63], rxprob2[63]; + int workdat[63],workdat2[63]; + int era_pos[51]; + int c, i, j, numera, nmr2, nerr, nn=63, kk=12; + FILE *datfile, *logfile; + int ntrials = *ntrials0; + int verbose = *verbose0; + int nhard=0,nhard_min=32768,nsoft=0,nsoft_min=32768, ncandidates; + int ngmd,nera_best; + clock_t t0=0,t1=0; + int perr[8][8] = { + 12, 31, 44, 52, 60, 57, 50, 50, + 28, 38, 49, 58, 65, 69, 64, 80, + 40, 41, 53, 62, 66, 73, 76, 81, + 50, 53, 53, 64, 70, 76, 77, 81, + 50, 50, 52, 60, 71, 72, 77, 84, + 50, 50, 56, 62, 67, 73, 81, 85, + 50, 50, 71, 62, 70, 77, 80, 85, + 50, 50, 62, 64, 71, 75, 82, 87}; + + int pmr2[8][8] = { + 4, 8, 9, 7, 6, 0, 0, 0, + 13, 18, 15, 11, 9, 7, 5, 0, + 0, 23, 21, 15, 12, 10, 7, 4, + 0, 34, 28, 20, 16, 14, 11, 7, + 0, 20, 26, 25, 19, 14, 12, 9, + 0, 0, 28, 27, 22, 19, 14, 11, + 0, 0, 40, 29, 29, 23, 18, 12, + 0, 0, 40, 35, 31, 21, 20, 13}; + + if(verbose) { + logfile=fopen("sfrsd.log","a"); + if( !logfile ) { + printf("Unable to open sfrsd.log\n"); + exit(1); + } + } + +// Initialize the KA9Q Reed-Solomon encoder/decoder + unsigned int symsize=6, gfpoly=0x43, fcr=3, prim=1, nroots=51; + rs=init_rs_int(symsize, gfpoly, fcr, prim, nroots, 0); + +// Reverse the received symbol vector for BM decoder + for (i=0; i<63; i++) { + rxdat[i]=mrsym[62-i]; + rxprob[i]=mrprob[62-i]; + rxdat2[i]=mr2sym[62-i]; + rxprob2[i]=mr2prob[62-i]; + } + +// Sort the mrsym probabilities to find the least reliable symbols + int k, pass, tmp, nsym=63; + int probs[63]; + for (i=0; i<63; i++) { + indexes[i]=i; + probs[i]=rxprob[i]; + } + for (pass = 1; pass <= nsym-1; pass++) { + for (k = 0; k < nsym - pass; k++) { + if( probs[k] < probs[k+1] ) { + tmp = probs[k]; + probs[k] = probs[k+1]; + probs[k+1] = tmp; + tmp = indexes[k]; + indexes[k] = indexes[k+1]; + indexes[k+1] = tmp; + } + } + } + +// See if we can decode using BM HDD, and calculate the syndrome vector. + memset(era_pos,0,51*sizeof(int)); + numera=0; + memcpy(workdat,rxdat,sizeof(rxdat)); + nerr=decode_rs_int(rs,workdat,era_pos,numera,1); + if( nerr >= 0 ) { + if(verbose) fprintf(logfile," BM decode nerrors= %3d : ",nerr); + memcpy(correct,workdat,63*sizeof(int)); + ngmd=-1; + param[0]=0; + param[1]=0; + param[2]=0; + param[3]=0; + param[4]=0; + return; + } + +/* +Generate random erasure-locator vectors and see if any of them +decode. This will generate a list of potential codewords. The +"soft" distance between each codeword and the received word is +used to decide which codeword is "best". +*/ + +#ifdef WIN32 + srand(0xdeadbeef); +#else + srandom(0xdeadbeef); +#endif + + float ratio, ratio0[63]; + int threshe, thresh2, nsum; + int thresh0[63],thresh1[63], mr2flag; + ncandidates=0; + nsum=0; + int ii,jj; + for (i=0; i= 0 ) { + ncandidates=ncandidates+1; + nhard=0; + nsoft=0; + for (i=0; i<63; i++) { + if(workdat[i] != rxdat[i]) { + nhard=nhard+1; + if(workdat[i] != rxdat2[i]) { + nsoft=nsoft+rxprob[i]; + } + } + } + nsoft=63*nsoft/nsum; + if((nsoft < 33) && (nhard < 43) && (nhard+nsoft) < 74) { //??? + if( (nsoft < nsoft_min) ) { + nsoft_min=nsoft; + nhard_min=nhard; + memcpy(correct,workdat,63*sizeof(int)); + ngmd=0; + nera_best=numera; + ntry[0]=k; + } + } + if(nsoft_min < 27) break; + if((nsoft_min < 32) && (nhard_min < 43) && + (nhard_min+nsoft_min) < 74) break; + } + if(k == ntrials-1) ntry[0]=k+1; + } + + if(verbose) fprintf(logfile, + "%d trials and %d candidates after stochastic loop\n",k,ncandidates); + + if( (ncandidates >= 0) && (nsoft_min < 36) && (nhard_min < 44) ) { + if(verbose) { + for (i=0; i<63; i++) { + fprintf(logfile,"%3d %3d %3d %3d %3d %3d\n",i,correct[i], + rxdat[i],rxprob[i],rxdat2[i],rxprob2[i]); + } + fprintf(logfile,"**** ncandidates %d nhard %d nsoft %d nsum %d\n", + ncandidates,nhard_min,nsoft_min,nsum); + } + } else { + nhard_min=-1; + } + + if(verbose) { + fprintf(logfile,"exiting sfrsd\n"); + fclose(logfile); + } + param[0]=ncandidates; + param[1]=nhard_min; + param[2]=nsoft_min; + param[3]=nera_best; + param[4]=ngmd; + if(param[0]==0) param[2]=-1; + return; +} diff --git a/lib/gen4.f90 b/lib/gen4.f90 new file mode 100644 index 00000000..7b06be8c --- /dev/null +++ b/lib/gen4.f90 @@ -0,0 +1,43 @@ +subroutine gen4(msg0,ichk,msgsent,itone,itype) + +! Encode a JT4 message. Returns msgsent, the message as it will be +! decoded, an integer array itone(206) of 4-FSK tons values in the +! range 0-3; and itype, the JT message type. + + use jt4 + use packjt + character*22 msg0 + character*22 message !Message to be generated + character*22 msgsent !Message as it will be received + character*1 c + integer itone(206) + integer*4 i4Msg6BitWords(13) !72-bit message as 6-bit words + integer mettab(-128:127,0:1) + save + + if(msg0(1:1).eq.'@') then + read(msg0(2:5),*,end=1,err=1) nfreq + go to 2 +1 nfreq=1000 +2 itone(1)=nfreq + msgsent=msg0 + else + call getmet4(mettab,ndelta) + + message=msg0 + call fmtmsg(message,iz) + call packmsg(message,i4Msg6BitWords,itype,.false.) !Pack into 12 6-bit bytes + call unpackmsg(i4Msg6BitWords,msgsent,.false.,' ') !Unpack to get msgsent + if(ichk.ne.0) go to 999 + call encode4(message,itone) !Encode the information bits + i1=index(message,'-') + c=message(i1+1:i1+1) + if(i1.ge.9 .and. c.ge.'0' .and. c.le.'3') then + itone=2*itone + (1-npr(2:)) !Inverted '#' sync + else + itone=2*itone + npr(2:) !Data = MSB, sync = LSB + endif + endif + +999 return +end subroutine gen4 diff --git a/lib/gen65.f90 b/lib/gen65.f90 index 69388c36..ab61fd33 100644 --- a/lib/gen65.f90 +++ b/lib/gen65.f90 @@ -3,11 +3,12 @@ subroutine gen65(msg0,ichk,msgsent,itone,itype) ! Encodes a JT65 message to yieild itone(1:126) ! Temporarily, does not implement EME shorthands + use packjt character*22 msg0 character*22 message !Message to be generated character*22 msgsent !Message as it will be received integer itone(126) -! character*3 cok !' ' or 'OOO' + character*3 cok !' ' or 'OOO' integer dgen(13) integer sent(63) integer nprc(126) @@ -20,43 +21,63 @@ subroutine gen65(msg0,ichk,msgsent,itone,itype) 1,1,1,1,1,1/ save - message=msg0 - do i=1,22 - if(ichar(message(i:i)).eq.0) then - message(i:)=' ' - exit - endif - enddo - - do i=1,22 !Strip leading blanks - if(message(1:1).ne.' ') exit - message=message(i+1:) - enddo + if(msg0(1:1).eq.'@') then + read(msg0(2:5),*,end=1,err=1) nfreq + go to 2 +1 nfreq=1000 +2 itone(1)=nfreq + else + message=msg0 + do i=1,22 + if(ichar(message(i:i)).eq.0) then + message(i:)=' ' + exit + endif + enddo - nspecial=0 -! call chkmsg(message,cok,nspecial,flip) - if(nspecial.eq.0) then - call packmsg(message,dgen,itype) !Pack message into 72 bits - call unpackmsg(dgen,msgsent) !Unpack to get message sent - if(ichk.ne.0) go to 999 !Return if checking only + do i=1,22 !Strip leading blanks + if(message(1:1).ne.' ') exit + message=message(i+1:) + enddo - call rs_encode(dgen,sent) !Apply Reed-Solomon code - call interleave63(sent,1) !Apply interleaving - call graycode65(sent,63,1) !Apply Gray code - nsym=126 !Symbols per transmission - else - nsym=32 - endif + call chkmsg(message,cok,nspecial,flip) + ntest=0 + if(flip.lt.0.0) ntest=1 + if(nspecial.eq.0) then + call packmsg(message,dgen,itype,.false.) !Pack message into 72 bits + call unpackmsg(dgen,msgsent,.false.,' ') !Unpack to get message sent + msgsent(20:22)=cok + call fmtmsg(msgsent,iz) + if(ichk.ne.0) go to 999 !Return if checking only - k=0 - do j=1,nsym - if(nprc(j).eq.0) then - k=k+1 - itone(j)=sent(k)+2 + call rs_encode(dgen,sent) !Apply Reed-Solomon code + call interleave63(sent,1) !Apply interleaving + call graycode65(sent,63,1) !Apply Gray code + nsym=126 !Symbols per transmission + k=0 + do j=1,nsym + if(nprc(j).eq.ntest) then + k=k+1 + itone(j)=sent(k)+2 + else + itone(j)=0 + endif + enddo else - itone(j)=0 + nsym=32 + k=0 + do j=1,nsym + do n=1,4 + k=k+1 + if(iand(j,1).eq.1) itone(k)=0 + if(iand(j,1).eq.0) itone(k)=10*nspecial + if(k.eq.126) go to 10 + enddo + enddo +10 msgsent=message + itype=7 endif - enddo + endif 999 return end subroutine gen65 diff --git a/lib/gen9.f90 b/lib/gen9.f90 new file mode 100644 index 00000000..503ef6d3 --- /dev/null +++ b/lib/gen9.f90 @@ -0,0 +1,65 @@ +subroutine gen9(msg0,ichk,msgsent,i4tone,itype) + +! Encodes a JT9 message and returns msgsent, the message as it will +! be decoded, and an integer array i4tone(85) of 9-FSK tone values +! in the range 0-8. + + use packjt + character*22 msg0 + character*22 message !Message to be generated + character*22 msgsent !Message as it will be received + integer*4 i4Msg6BitWords(13) !72-bit message as 6-bit words + integer*1 i1Msg8BitBytes(13) !72 bits and zero tail as 8-bit bytes + integer*1 i1EncodedBits(207) !Encoded information-carrying bits + integer*1 i1ScrambledBits(207) !Encoded bits after interleaving + integer*4 i4DataSymbols(69) !Data symbols (values 0-7) + integer*4 i4GrayCodedSymbols(69) !Gray-coded symbols (values 0-7) + integer*4 i4tone(85) !Tone #s, data and sync (values 0-8) + include 'jt9sync.f90' + save + + if(msg0(1:1).eq.'@') then + read(msg0(2:5),*,end=1,err=1) nfreq + go to 2 +1 nfreq=1000 +2 i4tone(1)=nfreq + else + message=msg0 + do i=1,22 + if(ichar(message(i:i)).eq.0) then + message(i:)=' ' + exit + endif + enddo + + do i=1,22 !Strip leading blanks + if(message(1:1).ne.' ') exit + message=message(i+1:) + enddo + + call packmsg(message,i4Msg6BitWords,itype,.false.) !Pack into 12 6-bit bytes + call unpackmsg(i4Msg6BitWords,msgsent,.false.,' ') !Unpack to get msgsent + if(ichk.ne.0) go to 999 + call entail(i4Msg6BitWords,i1Msg8BitBytes) !Add tail, make 8-bit bytes + nsym2=206 + call encode232(i1Msg8BitBytes,nsym2,i1EncodedBits) !Encode K=32, r=1/2 + i1EncodedBits(207)=0 + call interleave9(i1EncodedBits,1,i1ScrambledBits) !Interleave bits + i1ScrambledBits(207)=0 + call packbits(i1ScrambledBits,69,3,i4DataSymbols) !Pk 3-bits into words + call graycode(i4DataSymbols,69,1,i4GrayCodedSymbols) !Apply Gray code + +! Insert sync symbols at ntone=0 and add 1 to the data-tone numbers. + j=0 + do i=1,85 + if(isync(i).eq.1) then + i4tone(i)=0 + else + j=j+1 + i4tone(i)=i4GrayCodedSymbols(j)+1 + endif + enddo + endif + +999 return +end subroutine gen9 diff --git a/lib/geniscat.f90 b/lib/geniscat.f90 new file mode 100644 index 00000000..6df6ed98 --- /dev/null +++ b/lib/geniscat.f90 @@ -0,0 +1,55 @@ +subroutine geniscat(msg,msgsent,itone) + +! Generate an ISCAT waveform. + + parameter (NSZ=1291) + character msg*28,msgsent*28 !Message to be transmitted + integer imsg(30) + integer itone(NSZ) + real*8 sps + character c*42 + integer icos(4) !Costas array + data icos/0,1,3,2/ + data nsync/4/,nlen/2/,ndat/18/ + data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ /.?@-'/ + + sps=256.d0*12000.d0/11025.d0 + nsym=int(30*12000.d0/sps) + nblk=nsync+nlen+ndat + + do i=22,1,-1 + if(msg(i:i).ne.' ' .and. msg(i:i).ne.char(0)) exit + enddo + nmsg=i + msglen=nmsg+1 + k=0 + kk=1 + imsg(1)=40 !Always start with BOM char: '@' + do i=1,nmsg !Define the tone sequence + imsg(i+1)=36 !Illegal char set to blank + do j=1,42 + if(msg(i:i).eq.c(j:j)) imsg(i+1)=j-1 + enddo + enddo + + do i=1,nsym !Total symbols in 30 s + j=mod(i-1,nblk)+1 + if(j.le.nsync) then + itone(i)=icos(j) !Insert 4x4 Costas array + else if(j.gt.nsync .and. j.le.nsync+nlen) then + itone(i)=msglen !Insert message-length indicator + if(j.ge.nsync+2) then + n=msglen + 5*(j-nsync-1) + if(n.gt.41) n=n-42 + itone(i)=n + endif + else + k=k+1 + kk=mod(k-1,msglen)+1 + itone(i)=imsg(kk) + endif + enddo + msgsent=msg + + return +end subroutine geniscat diff --git a/lib/genjt9.f90 b/lib/genjt9.f90 deleted file mode 100644 index 5dd8c0c8..00000000 --- a/lib/genjt9.f90 +++ /dev/null @@ -1,55 +0,0 @@ -subroutine genjt9(msg0,ichk,msgsent,i4tone,itype) - -! Encodes a JT9 message and returns msgsent, the message as it will -! be decoded, and an integer array i4tone(85) of 9-FSK tone values -! in the range 0-8. - - character*22 msg0 - character*22 message !Message to be generated - character*22 msgsent !Message as it will be received - integer*4 i4Msg6BitWords(13) !72-bit message as 6-bit words - integer*1 i1Msg8BitBytes(13) !72 bits and zero tail as 8-bit bytes - integer*1 i1EncodedBits(207) !Encoded information-carrying bits - integer*1 i1ScrambledBits(207) !Encoded bits after interleaving - integer*4 i4DataSymbols(69) !Data symbols (values 0-7) - integer*4 i4GrayCodedSymbols(69) !Gray-coded symbols (values 0-7) - integer*4 i4tone(85) !Tone #s, data and sync (values 0-8) - include 'jt9sync.f90' - save - - message=msg0 - do i=1,22 - if(ichar(message(i:i)).eq.0) then - message(i:)=' ' - exit - endif - enddo - - do i=1,22 !Strip leading blanks - if(message(1:1).ne.' ') exit - message=message(i+1:) - enddo - - call packmsg(message,i4Msg6BitWords,itype) !Pack into 12 6-bit bytes - call unpackmsg(i4Msg6BitWords,msgsent) !Unpack to get msgsent - if(ichk.ne.0) go to 999 - call entail(i4Msg6BitWords,i1Msg8BitBytes) !Add tail, convert to 8-bit bytes - nsym2=206 - call encode232(i1Msg8BitBytes,nsym2,i1EncodedBits) !Encode K=32, r=1/2 - call interleave9(i1EncodedBits,1,i1ScrambledBits) !Interleave the bits - call packbits(i1ScrambledBits,nsym2,3,i4DataSymbols) !Pack 3-bits into words - call graycode(i4DataSymbols,69,1,i4GrayCodedSymbols) !Apply Gray code - -! Insert sync symbols at ntone=0 and add 1 to the data-tone numbers. - j=0 - do i=1,85 - if(isync(i).eq.1) then - i4tone(i)=0 - else - j=j+1 - i4tone(i)=i4GrayCodedSymbols(j)+1 - endif - enddo - -999 return -end subroutine genjt9 diff --git a/lib/genmet.f90 b/lib/genmet.f90 index 0682bf80..81f2e56d 100644 --- a/lib/genmet.f90 +++ b/lib/genmet.f90 @@ -33,6 +33,8 @@ program genmet hist=0 nerr=0 + call sgran() + do iter=1,iters do i=0,ntones-1 r(i)=0. diff --git a/lib/genmsk144.f90 b/lib/genmsk144.f90 new file mode 100644 index 00000000..62fc00a1 --- /dev/null +++ b/lib/genmsk144.f90 @@ -0,0 +1,147 @@ +subroutine genmsk144(msg0,mygrid,ichk,bcontest,msgsent,i4tone,itype) +! s8 + 48bits + s8 + 80 bits = 144 bits (72ms message duration) +! +! Encode an MSK144 message +! Input: +! - msg0 requested message to be transmitted +! - ichk if ichk=1, return only msgsent +! if ichk.ge.10000, set imsg=ichk-10000 for short msg +! - msgsent message as it will be decoded +! - i4tone array of audio tone values, 0 or 1 +! - itype message type +! 1 = standard message "Call_1 Call_2 Grid/Rpt" +! 2 = type 1 prefix +! 3 = type 1 suffix +! 4 = type 2 prefix +! 5 = type 2 suffix +! 6 = free text (up to 13 characters) +! 7 = short message " Rpt" + + use iso_c_binding, only: c_loc,c_size_t + use packjt + use hashing + character*22 msg0 + character*22 message !Message to be generated + character*22 msgsent !Message as it will be received + character*6 mygrid + integer*4 i4Msg6BitWords(13) !72-bit message as 6-bit words + integer*4 i4tone(144) ! + integer*1, target:: i1Msg8BitBytes(10) !80 bits represented in 10 bytes + integer*1 codeword(128) !Encoded bits before re-ordering + integer*1 msgbits(80) !72-bit message + 8-bit hash + integer*1 bitseq(144) !Tone #s, data and sync (values 0-1) + integer*1 i1hash(4) + integer*1 s8(8) + logical bcontest + real*8 pp(12) + real*8 xi(864),xq(864),pi,twopi + data s8/0,1,1,1,0,0,1,0/ + equivalence (ihash,i1hash) + logical first + data first/.true./ + save + + if(first) then + first=.false. + nsym=128 + pi=4.0*atan(1.0) + twopi=8.*atan(1.0) + do i=1,12 + pp(i)=sin((i-1)*pi/12) + enddo + endif + + if(msg0(1:1).eq.'@') then !Generate a fixed tone + read(msg0(2:5),*,end=1,err=1) nfreq !at specified frequency + go to 2 +1 nfreq=1000 +2 i4tone(1)=nfreq + else + message=msg0 + do i=1,22 + if(ichar(message(i:i)).eq.0) then + message(i:)=' ' + exit + endif + enddo + + do i=1,22 !Strip leading blanks + if(message(1:1).ne.' ') exit + message=message(i+1:) + enddo + + if(message(1:1).eq.'<') then + call genmsk40(message,msgsent,ichk,i4tone,itype) + if(itype.lt.0) go to 999 + i4tone(41)=-40 + go to 999 + endif + + call packmsg(message,i4Msg6BitWords,itype,bcontest) !Pack into 12 6-bit bytes + call unpackmsg(i4Msg6BitWords,msgsent,bcontest,mygrid) !Unpack to get msgsent + + if(ichk.eq.1) go to 999 + i4=0 + ik=0 + im=0 + do i=1,12 + nn=i4Msg6BitWords(i) + do j=1, 6 + ik=ik+1 + i4=i4+i4+iand(1,ishft(nn,j-6)) + i4=iand(i4,255) + if(ik.eq.8) then + im=im+1 + i1Msg8BitBytes(im)=i4 + ik=0 + endif + enddo + enddo + + ihash=nhash(c_loc(i1Msg8BitBytes),int(9,c_size_t),146) + ihash=2*iand(ihash,32767) !Generate the 8-bit hash + i1Msg8BitBytes(10)=i1hash(1) !CRC to byte 10 + + mbit=0 + do i=1, 10 + i1=i1Msg8BitBytes(i) + do ibit=1,8 + mbit=mbit+1 + msgbits(mbit)=iand(1,ishft(i1,ibit-8)) + enddo + enddo + + call encode_msk144(msgbits,codeword) + +!Create 144-bit channel vector: +!8-bit sync word + 48 bits + 8-bit sync word + 80 bits + bitseq=0 + bitseq(1:8)=s8 + bitseq(9:56)=codeword(1:48) + bitseq(57:64)=s8 + bitseq(65:144)=codeword(49:128) + bitseq=2*bitseq-1 + + xq(1:6)=bitseq(1)*pp(7:12) !first bit is mapped to 1st half-symbol on q + do i=1,71 + is=(i-1)*12+7 + xq(is:is+11)=bitseq(2*i+1)*pp + enddo + xq(864-5:864)=bitseq(1)*pp(1:6) !last half symbol + do i=1,72 + is=(i-1)*12+1 + xi(is:is+11)=bitseq(2*i)*pp + enddo +! Map I and Q to tones. + i4tone=0 + do i=1,72 + i4tone(2*i-1)=(bitseq(2*i)*bitseq(2*i-1)+1)/2; + i4tone(2*i)=-(bitseq(2*i)*bitseq(mod(2*i,144)+1)-1)/2; + enddo + endif + +! Flip polarity + i4tone=-i4tone+1 + +999 return +end subroutine genmsk144 diff --git a/lib/genmsk40.f90 b/lib/genmsk40.f90 new file mode 100644 index 00000000..3310b106 --- /dev/null +++ b/lib/genmsk40.f90 @@ -0,0 +1,66 @@ +subroutine genmsk40(msg,msgsent,ichk,itone,itype) + + use hashing + character*22 msg,msgsent,hashmsg + character*4 crpt,rpt(0:15) + logical first + integer*4 itone(144) + integer*1 message(16),codeword(32),bitseq(40) + integer*1 s8r(8) + data s8r/1,0,1,1,0,0,0,1/ ! Sync word is reversed wrt msk144 sync word. + data first/.true./ + data rpt/"-03 ","+00 ","+03 ","+06 ","+10 ","+13 ","+16 ", & + "R-03","R+00","R+03","R+06","R+10","R+13","R+16", & + "RRR ","73 "/ + save first,rpt + + itype=-1 + msgsent='*** bad message ***' + itone=0 + i1=index(msg,'>') + if(i1.lt.9) go to 900 + call fmtmsg(msg,iz) + crpt=msg(i1+2:i1+5) + do i=0,15 + if(crpt.eq.rpt(i)) go to 10 + enddo + go to 900 + +10 irpt=i !Report index, 0-15 + if(ichk.lt.10000) then + hashmsg=msg(2:i1-1) + call hash(hashmsg,22,ihash) + ihash=iand(ihash,4095) !12-bit hash + ig=16*ihash + irpt !4-bit report + else + ig=ichk-10000 + endif + + do i=1,16 + message(i)=iand(1,ishft(ig,1-i)) + enddo + + call encode_msk40(message,codeword) +! write(*,'(a6,i6,2x,a6,i6,2x,a6,i6)') ' msg: ',ig,'rprt: ',irpt,'hash: ',ihash +! write(*,'(a6,32i1)') ' cw: ',codeword + + bitseq(1:8)=s8r + bitseq(9:40)=codeword + bitseq=2*bitseq-1 + +! Map I and Q to tones. + itone=0 + do i=1, 20 + itone(2*i-1)=(bitseq(2*i)*bitseq(2*i-1)+1)/2; + itone(2*i)=-(bitseq(2*i)*bitseq(mod(2*i,40)+1)-1)/2; + enddo + +! Flip polarity + itone=-itone+1 + + msgsent=msg + itype=7 + +900 return +end subroutine genmsk40 + diff --git a/lib/genmsk_short.f90 b/lib/genmsk_short.f90 new file mode 100644 index 00000000..f1b555f3 --- /dev/null +++ b/lib/genmsk_short.f90 @@ -0,0 +1,66 @@ +subroutine genmsk_short(msg,msgsent,ichk,itone,itype) + + use hashing + character*22 msg,msgsent + character*3 crpt,rpt(0:7) + logical first + integer itone(35) + integer ig24(0:4096-1) !Codewords for Golay (24,12) code + integer b11(11) + data b11/1,1,1,0,0,0,1,0,0,1,0/ !Barker 11 code + data rpt /'26 ','27 ','28 ','R26','R27','R28','RRR','73 '/ + data first/.true./ + save first,ig24 + + if(first) then + call golay24_table(ig24) !Define the Golay(24,12) codewords + first=.false. + endif + + itype=-1 + msgsent='*** bad message ***' + itone=0 + i1=index(msg,'>') + if(i1.lt.9) go to 900 + call fmtmsg(msg,iz) + crpt=msg(i1+2:i1+5) + do i=0,7 + if(crpt.eq.rpt(i)) go to 10 + enddo + go to 900 + +10 irpt=i !Report index, 0-7 + if(ichk.lt.10000) then + call hash(msg(2:i1-1),i1-2,ihash) + ihash=iand(ihash,511) !9-bit hash for the two callsigns + ig=8*ihash + irpt !12-bit message information + else + ig=ichk-10000 + endif + ncodeword=ig24(ig) + itone(1:11)=b11 !Insert the Barker-11 code + n=2**24 + do i=12,35 !Insert codeword into itone array + n=n/2 + itone(i)=0 + if(iand(ncodeword,n).ne.0) itone(i)=1 + enddo + msgsent=msg + itype=7 + + n=count(itone(1:35).eq.0) + if(mod(n,2).ne.0) stop 'Parity error in genmsk_short.' + +900 return +end subroutine genmsk_short + +subroutine hash_calls(calls,ih9) + + use hashing + character*(*) calls + i1=index(calls,'>') + call hash(calls(2:i1-1),i1-2,ih9) + ih9=iand(ih9,511) !9-bit hash for the two callsigns + + return +end subroutine hash_calls diff --git a/lib/genqra64.f90 b/lib/genqra64.f90 new file mode 100644 index 00000000..819f13cc --- /dev/null +++ b/lib/genqra64.f90 @@ -0,0 +1,57 @@ +subroutine genqra64(msg0,ichk,msgsent,itone,itype) + +! Encodes a QRA64 message to yield itone(1:84) + + use packjt + character*22 msg0 + character*22 message !Message to be generated + character*22 msgsent !Message as it will be received + integer itone(84) + character*3 cok !' ' or 'OOO' + logical old_qra_sync + integer dgen(13) + integer sent(63) + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ !Defines a 7x7 Costas array + save + + if(msg0(1:1).eq.'@') then + read(msg0(2:5),*,end=1,err=1) nfreq + go to 2 +1 nfreq=1000 +2 itone(1)=nfreq + write(msgsent,1000) nfreq +1000 format(i5,' Hz') + else + message=msg0 + do i=1,22 + if(ichar(message(i:i)).eq.0) then + message(i:)=' ' + exit + endif + enddo + + do i=1,22 !Strip leading blanks + if(message(1:1).ne.' ') exit + message=message(i+1:) + enddo + + call chkmsg(message,cok,nspecial,flip) + call packmsg(message,dgen,itype,.false.) !Pack message into 72 bits + call unpackmsg(dgen,msgsent,.false.,' ') !Unpack to get message sent + if(ichk.ne.0) go to 999 !Return if checking only + call qra64_enc(dgen,sent) !Encode using QRA64 + + nsync=10 + inquire(file='old_qra_sync',exist=old_qra_sync) + if(old_qra_sync) nsync=1 + + itone(1:7)=nsync*icos7 !Insert 7x7 Costas array in 3 places + itone(8:39)=sent(1:32) + itone(40:46)=nsync*icos7 + itone(47:77)=sent(33:63) + itone(78:84)=nsync*icos7 + endif + +999 return +end subroutine genqra64 diff --git a/lib/genwspr.f90 b/lib/genwspr.f90 new file mode 100644 index 00000000..d1d5183b --- /dev/null +++ b/lib/genwspr.f90 @@ -0,0 +1,30 @@ +subroutine genwspr(message,msgsent,itone) +! Encode a WSPR message and generate the array of channel symbols. + + character*22 message,msgsent + parameter (MAXSYM=176) + integer*1 symbol(MAXSYM) + integer*1 data0(11) + integer*4 itone(162) + integer npr3(162) + data npr3/ & + 1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, & + 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, & + 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, & + 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, & + 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, & + 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, & + 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, & + 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, & + 0,0/ + + call wqencode(message,ntype,data0) !Source encoding + call encode232(data0,162,symbol) !Convolutional encoding + call inter_wspr(symbol,1) !Interleaving + do i=1,162 + itone(i)=npr3(i) + 2*symbol(i) + enddo + msgsent=message !### To be fixed... ?? ### + + return +end subroutine genwspr diff --git a/lib/geocentric.f90 b/lib/geocentric.f90 deleted file mode 100644 index 11ea7cb6..00000000 --- a/lib/geocentric.f90 +++ /dev/null @@ -1,17 +0,0 @@ -subroutine geocentric(alat,elev,hlt,erad) - - implicit real*8 (a-h,o-z) - -! IAU 1976 flattening f, equatorial radius a - f = 1.d0/298.257d0 - a = 6378140.d0 - c = 1.d0/sqrt(1.d0 + (-2.d0 + f)*f*sin(alat)*sin(alat)) - arcf = (a*c + elev)*cos(alat) - arsf = (a*(1.d0 - f)*(1.d0 - f)*c + elev)*sin(alat) - hlt = datan2(arsf,arcf) - erad = sqrt(arcf*arcf + arsf*arsf) - erad = 0.001d0*erad - - return -end subroutine geocentric - diff --git a/lib/geodist.f90 b/lib/geodist.f90 index 2ca75535..f93bde92 100644 --- a/lib/geodist.f90 +++ b/lib/geodist.f90 @@ -29,6 +29,13 @@ subroutine geodist(Eplat,Eplon,Stlat,Stlon,Az,Baz,Dist) data D2R/0.01745329251994/ ! degrees to radians conversion factor data Pi2/6.28318530718/ + if(abs(Eplat-Stlat).lt.0.02 .and. abs(Eplon-Stlon).lt.0.02) then + Az=0. + Baz=180.0 + Dist=0 + go to 999 + endif + BOA = BL/AL F = 1.0 - BOA ! Convert st/end pts to radians @@ -93,4 +100,6 @@ subroutine geodist(Eplat,Eplon,Stlat,Stlon,Az,Baz,Dist) az = 360.0 - az baz = 360.0 - baz + +999 return end subroutine geodist diff --git a/lib/getmet24.f90 b/lib/getmet24.f90 deleted file mode 100644 index f35a90ae..00000000 --- a/lib/getmet24.f90 +++ /dev/null @@ -1,52 +0,0 @@ -subroutine getmet24(mode,mettab) - -! Return appropriate metric table for soft-decision convolutional decoder. - -! Metric table (RxSymbol,TxSymbol) - integer mettab(0:255,0:1) - real*4 xx0(0:255) - data xx0/ & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & - 0.988, 1.000, 0.991, 0.993, 1.000, 0.995, 1.000, 0.991, & - 1.000, 0.991, 0.992, 0.991, 0.990, 0.990, 0.992, 0.996, & - 0.990, 0.994, 0.993, 0.991, 0.992, 0.989, 0.991, 0.987, & - 0.985, 0.989, 0.984, 0.983, 0.979, 0.977, 0.971, 0.975, & - 0.974, 0.970, 0.970, 0.970, 0.967, 0.962, 0.960, 0.957, & - 0.956, 0.953, 0.942, 0.946, 0.937, 0.933, 0.929, 0.920, & - 0.917, 0.911, 0.903, 0.895, 0.884, 0.877, 0.869, 0.858, & - 0.846, 0.834, 0.821, 0.806, 0.790, 0.775, 0.755, 0.737, & - 0.713, 0.691, 0.667, 0.640, 0.612, 0.581, 0.548, 0.510, & - 0.472, 0.425, 0.378, 0.328, 0.274, 0.212, 0.146, 0.075, & - 0.000,-0.079,-0.163,-0.249,-0.338,-0.425,-0.514,-0.606, & - -0.706,-0.796,-0.895,-0.987,-1.084,-1.181,-1.280,-1.376, & - -1.473,-1.587,-1.678,-1.790,-1.882,-1.992,-2.096,-2.201, & - -2.301,-2.411,-2.531,-2.608,-2.690,-2.829,-2.939,-3.058, & - -3.164,-3.212,-3.377,-3.463,-3.550,-3.768,-3.677,-3.975, & - -4.062,-4.098,-4.186,-4.261,-4.472,-4.621,-4.623,-4.608, & - -4.822,-4.870,-4.652,-4.954,-5.108,-5.377,-5.544,-5.995, & - -5.632,-5.826,-6.304,-6.002,-6.559,-6.369,-6.658,-7.016, & - -6.184,-7.332,-6.534,-6.152,-6.113,-6.288,-6.426,-6.313, & - -9.966,-6.371,-9.966,-7.055,-9.966,-6.629,-6.313,-9.966, & - -5.858,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966/ - save - - bias=0.5 - scale=10.0 - do i=0,255 - mettab(i,0)=nint(scale*(xx0(i)-bias)) - if(i.ge.1) mettab(256-i,1)=mettab(i,0) - enddo - - return -end subroutine getmet24 - diff --git a/lib/getmet4.f90 b/lib/getmet4.f90 new file mode 100644 index 00000000..73789357 --- /dev/null +++ b/lib/getmet4.f90 @@ -0,0 +1,56 @@ +subroutine getmet4(mettab,ndelta) + +! Return appropriate metric table for soft-decision convolutional decoder. + +! Metric table (RxSymbol,TxSymbol) +! integer mettab(0:255,0:1) + integer mettab(-128:127,0:1) + real*4 xx0(0:255) + data xx0/ & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, & + 0.988, 1.000, 0.991, 0.993, 1.000, 0.995, 1.000, 0.991, & + 1.000, 0.991, 0.992, 0.991, 0.990, 0.990, 0.992, 0.996, & + 0.990, 0.994, 0.993, 0.991, 0.992, 0.989, 0.991, 0.987, & + 0.985, 0.989, 0.984, 0.983, 0.979, 0.977, 0.971, 0.975, & + 0.974, 0.970, 0.970, 0.970, 0.967, 0.962, 0.960, 0.957, & + 0.956, 0.953, 0.942, 0.946, 0.937, 0.933, 0.929, 0.920, & + 0.917, 0.911, 0.903, 0.895, 0.884, 0.877, 0.869, 0.858, & + 0.846, 0.834, 0.821, 0.806, 0.790, 0.775, 0.755, 0.737, & + 0.713, 0.691, 0.667, 0.640, 0.612, 0.581, 0.548, 0.510, & + 0.472, 0.425, 0.378, 0.328, 0.274, 0.212, 0.146, 0.075, & + 0.000,-0.079,-0.163,-0.249,-0.338,-0.425,-0.514,-0.606, & + -0.706,-0.796,-0.895,-0.987,-1.084,-1.181,-1.280,-1.376, & + -1.473,-1.587,-1.678,-1.790,-1.882,-1.992,-2.096,-2.201, & + -2.301,-2.411,-2.531,-2.608,-2.690,-2.829,-2.939,-3.058, & + -3.164,-3.212,-3.377,-3.463,-3.550,-3.768,-3.677,-3.975, & + -4.062,-4.098,-4.186,-4.261,-4.472,-4.621,-4.623,-4.608, & + -4.822,-4.870,-4.652,-4.954,-5.108,-5.377,-5.544,-5.995, & + -5.632,-5.826,-6.304,-6.002,-6.559,-6.369,-6.658,-7.016, & + -6.184,-7.332,-6.534,-6.152,-6.113,-6.288,-6.426,-6.313, & + -9.966,-6.371,-9.966,-7.055,-9.966,-6.629,-6.313,-9.966, & + -5.858,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966/ + save + + bias=0.5 + scale=50 + ndelta=nint(3.4*scale) + do i=0,255 + xx=xx0(i) + if(i.ge.160) xx=xx0(160) - (i-160)*6.822/65.3 + mettab(i-128,0)=nint(scale*(xx-bias)) + if(i.ge.1) mettab(128-i,1)=mettab(i-128,0) + enddo + mettab(-128,1)=mettab(-127,1) + + return +end subroutine getmet4 diff --git a/lib/getpfx1.f90 b/lib/getpfx1.f90 deleted file mode 100644 index 332278eb..00000000 --- a/lib/getpfx1.f90 +++ /dev/null @@ -1,100 +0,0 @@ -subroutine getpfx1(callsign,k,nv2) - - character*12 callsign0,callsign,lof,rof - character*8 c - character addpfx*8,tpfx*4,tsfx*3 - logical ispfx,issfx,invalid - common/pfxcom/addpfx - include 'pfx.f90' - - callsign0=callsign - nv2=1 - iz=index(callsign,' ') - 1 - if(iz.lt.0) iz=12 - islash=index(callsign(1:iz),'/') - k=0 -! if(k.eq.0) go to 10 !Tnx to DL9RDZ for reminder:this was for tests only! - c=' ' - if(islash.gt.0 .and. islash.le.(iz-4)) then -! Add-on prefix - c=callsign(1:islash-1) - callsign=callsign(islash+1:iz) - do i=1,NZ - if(pfx(i)(1:4).eq.c) then - k=i - nv2=2 - go to 10 - endif - enddo - if(addpfx.eq.c) then - k=449 - nv2=2 - go to 10 - endif - - else if(islash.eq.(iz-1)) then -! Add-on suffix - c=callsign(islash+1:iz) - callsign=callsign(1:islash-1) - do i=1,NZ2 - if(sfx(i).eq.c(1:1)) then - k=400+i - nv2=3 - go to 10 - endif - enddo - endif - -10 if(islash.ne.0 .and.k.eq.0) then -! Original JT65 would force this compound callsign to be treated as -! plain text. In JT65v2, we will encode the prefix or suffix into nc1. -! The task here is to compute the proper value of k. - lof=callsign0(:islash-1) - rof=callsign0(islash+1:) - llof=len_trim(lof) - lrof=len_trim(rof) - ispfx=(llof.gt.0 .and. llof.le.4) - issfx=(lrof.gt.0 .and. lrof.le.3) - invalid=.not.(ispfx.or.issfx) - if(ispfx.and.issfx) then - if(llof.lt.3) issfx=.false. - if(lrof.lt.3) ispfx=.false. - if(ispfx.and.issfx) then - i=ichar(callsign0(islash-1:islash-1)) - if(i.ge.ichar('0') .and. i.le.ichar('9')) then - issfx=.false. - else - ispfx=.false. - endif - endif - endif - - if(invalid) then - k=-1 - else - if(ispfx) then - tpfx=lof(1:4) - k=nchar(tpfx(1:1)) - k=37*k + nchar(tpfx(2:2)) - k=37*k + nchar(tpfx(3:3)) - k=37*k + nchar(tpfx(4:4)) - nv2=4 - i=index(callsign0,'/') - callsign=callsign0(:i-1) - callsign=callsign0(i+1:) - endif - if(issfx) then - tsfx=rof(1:3) - k=nchar(tsfx(1:1)) - k=37*k + nchar(tsfx(2:2)) - k=37*k + nchar(tsfx(3:3)) - nv2=5 - i=index(callsign0,'/') - callsign=callsign0(:i-1) - endif - endif - endif - - return -end subroutine getpfx1 - diff --git a/lib/getpfx2.f90 b/lib/getpfx2.f90 deleted file mode 100644 index d747e7f2..00000000 --- a/lib/getpfx2.f90 +++ /dev/null @@ -1,24 +0,0 @@ -subroutine getpfx2(k0,callsign) - - character callsign*12 - include 'pfx.f90' - character addpfx*8 - common/pfxcom/addpfx - - k=k0 - if(k.gt.450) k=k-450 - if(k.ge.1 .and. k.le.NZ) then - iz=index(pfx(k),' ') - 1 - callsign=pfx(k)(1:iz)//'/'//callsign - else if(k.ge.401 .and. k.le.400+NZ2) then - iz=index(callsign,' ') - 1 - callsign=callsign(1:iz)//'/'//sfx(k-400) - else if(k.eq.449) then - iz=index(addpfx,' ') - 1 - if(iz.lt.1) iz=8 - callsign=addpfx(1:iz)//'/'//callsign - endif - - return -end subroutine getpfx2 - diff --git a/lib/go_chkfft.cmd b/lib/go_chkfft.cmd new file mode 100644 index 00000000..375a194e --- /dev/null +++ b/lib/go_chkfft.cmd @@ -0,0 +1 @@ +gfortran -o chkfft chkfft3.f90 four2a.f90 gran.c /jtsdk/fftw3f/libfftw3f-3.dll diff --git a/lib/golay24_table.c b/lib/golay24_table.c new file mode 100644 index 00000000..f7bd8750 --- /dev/null +++ b/lib/golay24_table.c @@ -0,0 +1,28 @@ +void golay24_table_(int cw[]) +{ + // Compute arnd return the table of 4096 codewords for the Golay (24,12) code. + + // Array y contains the twelve rows (columns) of the parity-check matrix + int y[12] = { 0x7ff, 0xee2, 0xdc5, 0xb8b, 0xf16, 0xe2d, + 0xc5b, 0x8b7, 0x96e, 0xadc, 0xdb8, 0xb71 }; + + int c[2]; /* Codeword composed of 12-bit info and 12-bit parity */ + + + int i,j,k; + int aux; + int weight(int vector); + + for(k=0; k<4096; k++) { + c[0] = k; + c[1] = 0; + for (i=0; i<12; i++) { + aux = 0; + for (j=0; j<12; j++) { + aux = aux ^ ((c[0] & y[i]) >> j & 1); + } + c[1] = (c[1] << 1) ^ aux; + } + cw[k]=4096*c[0] + c[1]; + } +} diff --git a/lib/grayline.f90 b/lib/grayline.f90 new file mode 100644 index 00000000..cc1aeeea --- /dev/null +++ b/lib/grayline.f90 @@ -0,0 +1,32 @@ +subroutine grayline(nyear,month,nday,uth,mygrid,nduration,isun) + + character*6 mygrid + real LST + real lat,lon + + call grid2deg(MyGrid,elon,lat) + lon=-elon + + uth0=uth-0.5*nduration/60.0 + uth1=uth+0.5*nduration/60.0 + + call sun(nyear,month,nday,uth0,lon,lat,RASun,DecSun,LST, & + AzSun,ElSun0,mjd,day) + call sun(nyear,month,nday,uth1,lon,lat,RASun,DecSun,LST, & + AzSun,ElSun1,mjd,day) + + elchk=-0.8333 + isun=-1 + if(elsun0.lt.elchk .and. elsun1.ge.elchk) then + isun=0 + else if(elsun0.gt.elchk .and. elsun1.le.elchk) then + isun=2 + else if(elsun1.gt.elchk) then + isun=1 + else + isun=3 + endif + + return +end subroutine grayline + diff --git a/lib/grid2k.f90 b/lib/grid2k.f90 deleted file mode 100644 index f68b1409..00000000 --- a/lib/grid2k.f90 +++ /dev/null @@ -1,12 +0,0 @@ -subroutine grid2k(grid,k) - - character*6 grid - - call grid2deg(grid,xlong,xlat) - nlong=nint(xlong) - nlat=nint(xlat) - k=0 - if(nlat.ge.85) k=5*(nlong+179)/2 + nlat-84 - - return -end subroutine grid2k diff --git a/lib/grid2n.f90 b/lib/grid2n.f90 deleted file mode 100644 index d02d786d..00000000 --- a/lib/grid2n.f90 +++ /dev/null @@ -1,10 +0,0 @@ -subroutine grid2n(grid,n) - character*4 grid - - i1=ichar(grid(1:1))-ichar('A') - i2=ichar(grid(3:3))-ichar('0') - i=10*i1 + i2 - n=-i - 31 - - return -end subroutine grid2n diff --git a/lib/hash.f90 b/lib/hash.f90 new file mode 100644 index 00000000..37598390 --- /dev/null +++ b/lib/hash.f90 @@ -0,0 +1,10 @@ +subroutine hash(string,len,ihash) + use iso_c_binding, only: c_loc,c_size_t + use hashing + parameter (MASK15=32767) +! character*(*), target :: string + character*1, target :: string + i=nhash(c_loc(string),int(len,c_size_t),146) + ihash=iand(i,MASK15) + return +end subroutine hash diff --git a/lib/hashing.f90 b/lib/hashing.f90 new file mode 100644 index 00000000..5534fa92 --- /dev/null +++ b/lib/hashing.f90 @@ -0,0 +1,10 @@ +module hashing + interface + integer(c_int32_t) function nhash (key, length, initval) bind(C, name="nhash") + use iso_c_binding, only: c_ptr, c_size_t, c_int32_t + type(c_ptr), intent(in), value :: key + integer(c_size_t), intent(in), value :: length + integer(c_int32_t), intent(in), value :: initval + end function nhash + end interface +end module hashing diff --git a/lib/hint65.f90 b/lib/hint65.f90 new file mode 100644 index 00000000..3d185330 --- /dev/null +++ b/lib/hint65.f90 @@ -0,0 +1,166 @@ +subroutine hint65(s3,mrs,mrs2,nadd,nflip,mycall,hiscall,hisgrid,qual,decoded) + + use packjt + use prog_args + parameter (MAXCALLS=10000,MAXRPT=63) + parameter (MAXMSG=2*MAXCALLS + 2 + MAXRPT) + real s3(64,63) + integer*1 sym1(0:62,MAXMSG) + integer*1 sym2(0:62,MAXMSG) + integer mrs(63),mrs2(63) + integer dgen(12),sym(0:62),sym_rev(0:62) + character*6 mycall,hiscall,hisgrid,call2(MAXCALLS) + character*4 grid2(MAXCALLS),rpt(MAXRPT) + character callsign*12,grid*4 + character*180 line + character ceme*3,msg*22,msg00*22 + character*22 msg0(MAXMSG),decoded + logical*1 eme(MAXCALLS) + logical first + data first/.true./ + data rpt/'-01','-02','-03','-04','-05', & + '-06','-07','-08','-09','-10', & + '-11','-12','-13','-14','-15', & + '-16','-17','-18','-19','-20', & + '-21','-22','-23','-24','-25', & + '-26','-27','-28','-29','-30', & + 'R-01','R-02','R-03','R-04','R-05', & + 'R-06','R-07','R-08','R-09','R-10', & + 'R-11','R-12','R-13','R-14','R-15', & + 'R-16','R-17','R-18','R-19','R-20', & + 'R-21','R-22','R-23','R-24','R-25', & + 'R-26','R-27','R-28','R-29','R-30', & + 'RO','RRR','73'/ + save first,sym1,nused,msg0,sym2 + + first=.true. !### For now, at least: always recompute hypothetical messages + if(first) then + neme=0 + open(23,file=trim(data_dir)//'/CALL3.TXT',status='unknown') + icall=0 + j=0 + do i=1,MAXCALLS + read(23,1002,end=10) line +1002 format(a80) + if(line(1:4).eq.'ZZZZ') cycle + if(line(1:2).eq.'//') cycle + i1=index(line,',') + if(i1.lt.4) cycle + i2=index(line(i1+1:),',') + if(i2.lt.5) cycle + i2=i2+i1 + i3=index(line(i2+1:),',') + if(i3.lt.1) i3=index(line(i2+1:),' ') + i3=i2+i3 + callsign=line(1:i1-1) + grid=line(i1+1:i1+4) + ceme=line(i2+1:i3-1) + eme(i)=ceme.eq.'EME' + if(neme.eq.1 .and. (.not.eme(i))) cycle + j=j+1 + call2(j)=callsign(1:6) !### Fix for compound callsigns! + grid2(j)=grid + enddo +10 ncalls=j + if(ncalls.lt.10) then + write(*,1010) ncalls +1010 format('CALL3.TXT very short (N =',i2,') or missing?') + endif + close(23) + +! NB: generation of test messages is not yet complete! + j=0 + do i=-1,ncalls + if(i.eq.0 .and. hiscall.eq.' ' .and. hisgrid(1:4).eq.' ') cycle + mz=2 + if(i.eq.-1) mz=1 + if(i.eq.0) mz=65 + do m=1,mz + j=j+1 + if(i.eq.-1) then + msg='0123456789ABC' + else if(i.eq.0) then + if(m.eq.1) msg=mycall//' '//hiscall//' '//hisgrid(1:4) + if(m.eq.2) msg='CQ '//hiscall//' '//hisgrid(1:4) + if(m.ge.3) msg=mycall//' '//hiscall//' '//rpt(m-2) + else + if(m.eq.1) msg=mycall//' '//call2(i)//' '//grid2(i) + if(m.eq.2) msg='CQ '//call2(i)//' '//grid2(i) + endif + call fmtmsg(msg,iz) + call packmsg(msg,dgen,itype,.false.) !Pack message into 72 bits + call rs_encode(dgen,sym_rev) !RS encode + sym(0:62)=sym_rev(62:0:-1) + sym1(0:62,j)=sym + + call interleave63(sym_rev,1) !Interleave channel symbols + call graycode(sym_rev,63,1,sym_rev) !Apply Gray code + sym2(0:62,j)=sym_rev(0:62) + msg0(j)=msg + enddo + enddo + nused=j + first=.false. + endif + + ref0=0. + do j=1,63 + ref0=ref0 + s3(mrs(j)+1,j) + enddo + + u1=0. + u1=-99.0 + u2=u1 + +! Find u1 and u2 (best and second-best) codeword from a list, using +! a bank of matched filters on the symbol spectra s3(i,j). + ipk=1 + ipk2=0 + msg00=' ' + do k=1,nused + if(k.ge.2 .and. k.le.64 .and. nflip.lt.0) cycle +! Test all messages if nflip=+1; skip the CQ messages if nflip=-1. + if(nflip.gt.0 .or. msg0(k)(1:3).ne.'CQ ') then + psum=0. + ref=ref0 + do j=1,63 + i=sym2(j-1,k)+1 + psum=psum + s3(i,j) + if(i.eq.mrs(j)+1) ref=ref - s3(i,j) + s3(mrs2(j)+1,j) + enddo + p=psum/ref + + if(p.gt.u1) then + if(msg0(k).ne.msg00) then + ipk2=ipk + u2=u1 + endif + u1=p + ipk=k + msg00=msg0(k) + endif + if(msg0(k).ne.msg00 .and. p.gt.u2) then + u2=p + ipk2=k + endif + endif + enddo + +!### Just in case ??? +! rewind 77 +! write(77,*) u1,u2,ipk,ipk2 +! call flush(77) +!### + + decoded=' ' + bias=max(1.12*u2,0.35) + if(nadd.ge.4) bias=max(1.08*u2,0.45) + if(nadd.ge.8) bias=max(1.04*u2,0.60) + qual=100.0*(u1-bias) +! write(*,3301) u1,u2,u1/u2,bias,qual,nadd,ipk,ipk2 +!3301 format(5f6.2,i3,2i6) + qmin=1.0 + if(qual.ge.qmin) decoded=msg0(ipk) + + return +end subroutine hint65 diff --git a/lib/hspec.f90 b/lib/hspec.f90 new file mode 100644 index 00000000..4ede5060 --- /dev/null +++ b/lib/hspec.f90 @@ -0,0 +1,106 @@ +subroutine hspec(id2,k,nutc0,ntrpdepth,nrxfreq,ntol,bmsk144,bcontest, & + btrain,pcoeffs,ingain,mycall,hiscall,bshmsg,bswl,datadir,green,s, & + jh,pxmax,dbNoGain,line1,mygrid) + +! Input: +! k pointer to the most recent new data +! nutc0 UTC for display of decode(s) +! ntrpdepth TR period and 1000*ndepth +! nrxfreq Rx audio center frequency +! ntol Decoding range is +/- ntol +! bmsk144 Boolean, true if in MSK144 mode +! btrain Boolean, turns on training in MSK144 mode +! ingain Relative gain for spectra + +! Output: +! green() power +! s() spectrum for horizontal spectrogram +! jh index of most recent data in green(), s() + + parameter (JZ=703) + character*80 line1 + character*512 datadir + character*12 mycall,hiscall + character*6 mygrid + integer*2 id2(0:120*12000-1) + logical*1 bmsk144,bcontest,bshmsg,btrain,bswl + real green(0:JZ-1) + real s(0:63,0:JZ-1) + real x(512) + real*8 pcoeffs(5) + complex cx(0:256) + data rms/999.0/,k0/99999999/ + equivalence (x,cx) + save ja,rms0 + + ndepth=ntrpdepth/1000 + ntrperiod=ntrpdepth - 1000*ndepth + gain=10.0**(0.1*ingain) + nfft=512 + nstep=nfft + nblks=7 + if(ntrperiod.lt.30) then + nstep=256 + nblks=14 + endif + + if(k.gt.30*12000) go to 900 + if(k.lt.nfft) then + jh=0 + go to 900 !Wait for enough samples to start + endif + + if(k.lt.k0) then !Start a new data block + ja=-nstep + jh=-1 + rms0=0.0 + endif + + pxmax = 0; + do iblk=1,nblks + if(jh.lt.JZ-1) jh=jh+1 + ja=ja+nstep + jb=ja+nfft-1 + x=id2(ja:jb) + sq=dot_product(x,x) + xmax = maxval(x); + xmin = abs(minval(x)); + if (xmin > xmax) xmax = xmin; + if (xmax.gt.0.0) pxmax=20.0*log10(xmax); + rms=sqrt(gain*sq/nfft) + rms2=sqrt(sq/nfft); + green(jh)=0. + if(rms.gt.0.0) then + green(jh)=20.0*log10(rms) + dbNoGain=20.0*log10(rms2); + endif + call four2a(x,nfft,1,-1,0) !Real-to-complex FFT + df=12000.0/nfft + fac=(1.0/nfft)**2 + do i=1,64 + j=2*i + sx=real(cx(j))**2 + aimag(cx(j))**2 + real(cx(j-1))**2 + & + aimag(cx(j-1))**2 + s(i-1,jh)=fac*gain*sx + enddo + if(ja+2*nfft.gt.k) exit + enddo + k0=k + + if(bmsk144) then + if(k.ge.7168) then + tsec=(k-7168)/12000.0 + k0=k-7168 + tt1=sum(float(abs(id2(k0:k0+3583)))) + k0=k-3584 + tt2=sum(float(abs(id2(k0:k0+3583)))) + if(tt1.ne.0.0 .and. tt2.ne.0) then + call mskrtd(id2(k-7168+1:k),nutc0,tsec,ntol,nrxfreq,ndepth, & + mycall,mygrid,hiscall,bshmsg,bcontest,btrain,pcoeffs,bswl,& + datadir,line1) + endif + endif + endif + +900 return +end subroutine hspec diff --git a/lib/image.f90 b/lib/image.f90 new file mode 100644 index 00000000..db1d7e13 --- /dev/null +++ b/lib/image.f90 @@ -0,0 +1,336 @@ +subroutine imopen(plotfile) + character*(*) plotfile + common/imcom/ lu,npage + + lu=80 + open(lu,file=plotfile,status='unknown') + write(lu,1000) +1000 format('%!PS-Adobe-2.0'/ & + '/rightshow { dup stringwidth pop neg 0 rmoveto show } def'/ & + '/centershow { dup stringwidth pop neg 2 div ', & + '0 rmoveto show } def'/ & + '/lt { lineto } def'/'%%Page: 1 1') + npage=1 + + return +end subroutine imopen + +subroutine impalette(palette) + character*(*) palette + integer r(0:8),g(0:8),b(0:8) + integer rr,gg,bb + common/imcom/ lu,npage + common/imcom2/rr(0:255),gg(0:255),bb(0:255) + + if(palette.eq.'afmhot') then + do i=0,255 + j=255-i + rr(i)=min(255,2*j) + gg(i)=max(0,min(255,2*j-128)) + bb(i)=max(0,min(255,2*j-256)) + enddo + else if(palette.eq.'hot') then + do i=0,255 + j=255-i + rr(i)=min(255,3*j) + gg(i)=max(0,min(255,3*j-256)) + bb(i)=max(0,min(255,3*j-512)) + enddo + else + open(11,file="Palettes/"//palette,status="old") + do j=0,8 + read(11,*) r(j),g(j),b(j) + enddo + close(11) + do i=0,255 + j0=i/32 + j1=j0+1 + k=i-32*j0 + rr(i)=r(j0) + int((k*(r(j1)-r(j0)))/31 + 0.5) + gg(i)=g(j0) + int((k*(g(j1)-g(j0)))/31 + 0.5) + bb(i)=b(j0) + int((k*(b(j1)-b(j0)))/31 + 0.5) + enddo + + endif + + return +end subroutine impalette + +subroutine imclose + common/imcom/ lu,npage + write(lu,1000) +1000 format('showpage'/'%%Trailer') + close(lu) + return +end subroutine imclose + +subroutine imnewpage + common/imcom/ lu,npage + npage=npage+1 + write(lu,1000) npage,npage +1000 format('showpage'/'%%Page:',2i4) + return +end subroutine imnewpage + +subroutine imxline(x,y,dx) +! Draw a line from (x,y) to (x+dx,y) integer r,g,b + common/imcom/ lu,npage + write(lu,1000) 72.0*x,72.0*y,72.0*dx +1000 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto stroke') + return +end subroutine imxline + +subroutine imyline(x,y,dy) +! Draw a line from (x,y) to (x,y+dy) + common/imcom/ lu,npage + write(lu,1000) 72.0*x,72.0*y,72.0*dy +1000 format('newpath',2f7.1,' moveto 0',f7.1,' rlineto stroke') + return +end subroutine imyline + +subroutine imwidth(width) + common/imcom/ lu,npage + write(lu,1000) width +1000 format(f7.1,' setlinewidth') + return +end subroutine imwidth + +subroutine imfont(fontname,npoints) + character*(*) fontname + common/imcom/ lu,npage + write(lu,1000) fontname,npoints +1000 format('/',a,' findfont',i4,' scalefont setfont') + return +end subroutine imfont + +subroutine imstring(string,x,y,just,ndeg) + character*(*) string + common/imcom/ lu,npage + write(lu,1000) 72.0*x,72.0*y,ndeg,string +1000 format(2f7.1,' moveto',i4,' rotate'/'(',a,')') + if(just.eq.1) write(lu,*) 'rightshow' + if(just.eq.2) write(lu,*) 'centershow' + if(just.eq.3) write(lu,*) 'show' + write(lu,1010) -ndeg +1010 format(i4,' rotate'/) + return +end subroutine imstring + +subroutine imr4mat(z,IP,JP,imax,jmax,zz1,zz2,x,y,dx,dy,nbox) + real z(IP,JP) + integer idat(2048) + common/imcom/ lu,npage + + z1=zz1 + z2=zz2 + if(z1.eq.0.0 .and. z2.eq.0.0) then + z1=z(1,1) + z2=z1 + do i=1,imax + do j=1,jmax + z1=min(z(i,j),z1) + z2=max(z(i,j),z2) + enddo + enddo + endif + scale=255.99/(z2-z1) + + write(lu,1002) 72.0*x,72.0*y,72.0*dx,72.0*dy +1002 format(2f7.1,' translate',2f7.1,' scale') + write(lu,*) imax,jmax,8,' [',imax,0,0,jmax,0,0,']' + write(lu,*) '{<' + + do j=1,jmax + do i=1,imax + idat(i)=scale*(z(i,j)-z1) + idat(i)=max(idat(i),0) + idat(i)=min(idat(i),255) + idat(i)=255-idat(i) + enddo + write(lu,1004) (idat(i),i=1,imax) +1004 format(30z2.2) + enddo + write(lu,*) '>} image' + write(lu,1006) 1.0/(72.0*dx),1.0/(72.0*dy),-72.0*x,-72.0*y +1006 format(2f9.6,' scale',2f7.1,' translate') + + if(nbox.ne.0) then + write(lu,1010) 72.0*x,72.0*y,72.0*dx,72.0*dy,-72*dx +1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & + f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') + endif + + return +end subroutine imr4mat + +subroutine imr4mat_color(z,IP,JP,imax,jmax,zz1,zz2,x,y,dx,dy,nbox) + real z(IP,JP) + integer idat(2048,3) + integer rr,gg,bb + common/imcom/ lu,npage + common/imcom2/rr(0:255),gg(0:255),bb(0:255) + + z1=zz1 + z2=zz2 + if(z1.eq.0.0 .and. z2.eq.0.0) then + z1=z(1,1) + z2=z1 + do i=1,imax + do j=1,jmax + z1=min(z(i,j),z1) + z2=max(z(i,j),z2) + enddo + enddo + endif + scale=255.99/(z2-z1) + + write(lu,1002) 72.0*x,72.0*y,72.0*dx,72.0*dy +1002 format(2f7.1,' translate',2f7.1,' scale') + write(lu,1003) imax,jmax,8,imax,0,0,jmax,0,0 +1003 format(3i5,' [',6i4,']') + write(lu,1004) imax +1004 format('{currentfile 3',i4,' mul string readhexstring pop} bind'/ & + 'false 3 colorimage') + + do j=1,jmax + do i=1,imax + n=scale*(z(i,j)-z1) + n=max(n,0) + n=min(n,255) + idat(i,1)=rr(n) + idat(i,2)=gg(n) + idat(i,3)=bb(n) + enddo + write(lu,1005) (idat(i,1),idat(i,2),idat(i,3),i=1,imax) +1005 format(30z2.2) + enddo + + write(lu,1006) 1.0/(72.0*dx),1.0/(72.0*dy),-72.0*x,-72.0*y +1006 format(2f9.6,' scale',2f7.1,' translate') + + if(nbox.ne.0) then + write(lu,1010) 72.0*x,72.0*y,72.0*dx,72.0*dy,-72*dx +1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & + f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') + endif + + return +end subroutine imr4mat_color + +subroutine imr4pro(p,imax,yy1,yy2,x,y,dx,dy,nbox) + real p(imax) + common/imcom/ lu,npage + + y1=yy1 + y2=yy2 + if(y1.eq.0.0 .and. y2.eq.0.0) then + y1=p(1) + y2=y1 + do i=1,imax + y1=min(p(i),y1) + y2=max(p(i),y2) + enddo + endif + + xscale=72.0*dx/imax + xoff=72.0*x + yscale=72.0*dy + if(y1.ne.y2) yscale=yscale/(y2-y1) + yoff=72.0*y + + write(lu,*) '1.416 setmiterlimit' + write(lu,1002) xoff+0.5*xscale,yoff+yscale*(p(1)-y1) +1002 format('newpath',2f7.1,' moveto') + + do i=2,imax + write(lu,1004) xoff+(i-0.5)*xscale,yoff+yscale*(p(i)-y1) +1004 format(2f6.1,' lt') + enddo + write(lu,*) 'stroke' + + if(nbox.ne.0) then + write(lu,1010) xoff,yoff,72.0*dx,72.0*dy,-72*dx +1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & + f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') + endif + + return +end subroutine imr4pro + +subroutine imline(x1,y1,x2,y2) + common/imcom/ lu,npage + write(lu,1000) 72*x1,72*y1,72*x2,72*y2 +1000 format('newpath',2f7.1,' moveto',2f7.1,' lineto stroke') + return +end subroutine imline + +subroutine imcircle(x,y,radius,shade) + common/imcom/ lu,npage + write(lu,1000) shade +1000 format(f7.1,' setgray') + write(lu,1002) 72*x,72*y,72*radius +1002 format('newpath',3f7.1,' 0 360 arc fill') + write(lu,1000) 0.0 + write(lu,1004) 72*x,72*y,72*radius +1004 format('newpath',3f7.1,' 0 360 arc stroke') + return +end subroutine imcircle + +subroutine imtriangle(x,y,rr,shade) + common/imcom/ lu,npage + write(lu,1000) shade +1000 format(f7.1,' setgray') + write(lu,1002) 72*x,72*(y+rr) +1002 format('newpath',2f7.1,' moveto ') + write(lu,1004) 72*(x-rr),72*(y-rr) +1004 format(2f7.1,' lineto ') + write(lu,1004) 72*(x+rr),72*(y-rr) + write(lu,*) 'closepath fill 0 setgray' + write(lu,1002) 72*x,72*(y+rr) + write(lu,1004) 72*(x-rr),72*(y-rr) + write(lu,1004) 72*(x+rr),72*(y-rr) + write(lu,*) 'closepath stroke' + + return +end subroutine imtriangle + +subroutine imr4prov(p,jmax,xx1,xx2,x,y,dx,dy,nbox) + real p(jmax) + common/imcom/ lu,npage + + x1=xx1 + x2=xx2 + if(x1.eq.0.0 .and. x2.eq.0.0) then + x1=p(1) + x2=x1 + do j=1,jmax + x1=min(p(j),x1) + x2=max(p(j),x2) + enddo + endif + + xscale=72.0*dx + xoff=72.0*x + if(x1.ne.x2) xscale=xscale/(x2-x1) + + yscale=72.0*dy/jmax + yoff=72.0*y + + write(lu,*) '1.416 setmiterlimit' + write(lu,1002) xoff+xscale*(x2-p(1)),yoff+0.5*yscale +1002 format('newpath',2f7.1,' moveto') + + do j=2,jmax + write(lu,1004) xoff+xscale*(x2-p(j)),yoff+(j-0.5)*yscale +1004 format(2f6.1,' lt') + enddo + write(lu,*) 'stroke' + + if(nbox.ne.0) then + write(lu,1010) xoff,yoff,72.0*dx,72.0*dy,-72*dx +1010 format('newpath',2f7.1,' moveto',f7.1,' 0 rlineto 0', & + f7.1,' rlineto',f7.1,' 0 rlineto closepath stroke') + endif + + return +end subroutine imr4prov diff --git a/lib/indexx.f90 b/lib/indexx.f90 index 57c1ec07..7a35f53b 100644 --- a/lib/indexx.f90 +++ b/lib/indexx.f90 @@ -1,19 +1,91 @@ -subroutine indexx(n,arr,indx) +subroutine indexx(arr,n,indx) - parameter (NMAX=3000) - integer indx(n) + parameter (M=7,NSTACK=50) + integer n,indx(n) real arr(n) - real brr(NMAX) - if(n.gt.NMAX) then - print*,'n=',n,' too big in indexx.' - stop - endif - do i=1,n - brr(i)=arr(i) - indx(i)=i + integer i,indxt,ir,itemp,j,jstack,k,l,istack(NSTACK) + real a + + do j=1,n + indx(j)=j enddo - call ssort(brr,indx,n,2) - return + jstack=0 + l=1 + ir=n +1 if(ir-l.lt.M) then + do j=l+1,ir + indxt=indx(j) + a=arr(indxt) + do i=j-1,1,-1 + if(arr(indx(i)).le.a) goto 2 + indx(i+1)=indx(i) + enddo + i=0 +2 indx(i+1)=indxt + enddo + if(jstack.eq.0) return + + ir=istack(jstack) + l=istack(jstack-1) + jstack=jstack-2 + + else + k=(l+ir)/2 + itemp=indx(k) + indx(k)=indx(l+1) + indx(l+1)=itemp + + if(arr(indx(l+1)).gt.arr(indx(ir))) then + itemp=indx(l+1) + indx(l+1)=indx(ir) + indx(ir)=itemp + endif + + if(arr(indx(l)).gt.arr(indx(ir))) then + itemp=indx(l) + indx(l)=indx(ir) + indx(ir)=itemp + endif + + if(arr(indx(l+1)).gt.arr(indx(l))) then + itemp=indx(l+1) + indx(l+1)=indx(l) + indx(l)=itemp + endif + + i=l+1 + j=ir + indxt=indx(l) + a=arr(indxt) +3 continue + i=i+1 + if(arr(indx(i)).lt.a) goto 3 + +4 continue + j=j-1 + if(arr(indx(j)).gt.a) goto 4 + if(j.lt.i) goto 5 + itemp=indx(i) + indx(i)=indx(j) + indx(j)=itemp + goto 3 + +5 indx(l)=indx(j) + indx(j)=indxt + jstack=jstack+2 + if(jstack.gt.NSTACK) stop 'NSTACK too small in indexx' + if(ir-i+1.ge.j-l)then + istack(jstack)=ir + istack(jstack-1)=i + ir=j-1 + else + istack(jstack)=j-1 + istack(jstack-1)=l + l=i + endif + endif + goto 1 + end subroutine indexx diff --git a/lib/init_random_seed.c b/lib/init_random_seed.c new file mode 100644 index 00000000..7e6ed889 --- /dev/null +++ b/lib/init_random_seed.c @@ -0,0 +1,82 @@ +#include "init_random_seed.h" + +#include +#include +#include +#include +#include +#include + +/* basic PRNG to use for improving the basic seed selection */ +static unsigned lcg (uint64_t seed) +{ + if (0 ==seed) + { + seed = UINT64_C(104729); + } + else + { + seed %= UINT64_C(4294967296); + } + seed = (seed * UINT64_C(279470273)) % UINT64_C(4294967291); + return seed % UINT64_MAX; +} + +/* Generate a good PRNG seed value */ +void init_random_seed(void) +{ + unsigned seed = 0u; + int have_seed = 0; + + // try /dev/urandom for an initial seed + int random_source; + if ((random_source = open ("/dev/urandom", O_RDONLY)) >= 0) + { + size_t random_data_length = 0; + have_seed = -1; + while (random_data_length < sizeof seed) + { + ssize_t result = read (random_source, &seed + random_data_length, (sizeof seed) - random_data_length); + if (result < 0) + { + // error, unable to read /dev/random + have_seed = 0; + } + random_data_length += result; + } + close (random_source); + } + if (!have_seed) + { + // fallback to combining the time and PID in a fairly random way + pid_t pid = getpid (); + struct timeval tv; + gettimeofday (&tv, NULL); + seed = (unsigned)(((unsigned)pid << 16) + ^ (unsigned)pid + ^ (unsigned)tv.tv_sec + ^ (unsigned)tv.tv_usec); + seed = lcg (seed); + } + srand (seed); +} + +#ifdef TEST +#include + +int main (int argc, char * argv[]) +{ + init_random_seed (); + int i, j; + int r[10][4]; + for (i = 0; i < 10; ++i) + { + for (j = 0; j < 4; ++j) + { + printf ("%10d ", rand ()); + } + printf ("\n"); + } + return 0; +} +#endif diff --git a/lib/init_random_seed.f90 b/lib/init_random_seed.f90 new file mode 100644 index 00000000..7d85f9dd --- /dev/null +++ b/lib/init_random_seed.f90 @@ -0,0 +1,55 @@ +! +! Generate a seed for the RANDOM_NUMBER PRNG that is guaranteed to be +! unique even if many processes are started simultaneously +! +subroutine init_random_seed() + use iso_fortran_env, only: int64 + implicit none + integer, allocatable :: seed(:) + integer :: i, n, un, istat, dt(8), pid + integer(int64) :: t + + call random_seed(size = n) + allocate(seed(n)) + ! First try if the OS provides a random number generator + open(newunit=un, file="/dev/urandom", access="stream", & + form="unformatted", action="read", status="old", iostat=istat) + if (istat == 0) then + read(un) seed + close(un) + else + ! Fallback to XOR:ing the current time and pid. The PID is + ! useful in case one launches multiple instances of the same + ! program in parallel. + call system_clock(t) + if (t == 0) then + call date_and_time(values=dt) + t = (dt(1) - 1970) * 365_int64 * 24 * 60 * 60 * 1000 & + + dt(2) * 31_int64 * 24 * 60 * 60 * 1000 & + + dt(3) * 24_int64 * 60 * 60 * 1000 & + + dt(5) * 60 * 60 * 1000 & + + dt(6) * 60 * 1000 + dt(7) * 1000 & + + dt(8) + end if + pid = getpid() + t = ieor(t, int(pid, kind(t))) + do i = 1, n + seed(i) = lcg(t) + end do + end if + call random_seed(put=seed) +contains + ! This simple PRNG might not be good enough for real work, but is + ! sufficient for seeding a better PRNG. + function lcg(s) + integer :: lcg + integer(int64) :: s + if (s == 0) then + s = 104729 + else + s = mod(s, 4294967296_int64) + end if + s = mod(s * 279470273_int64, 4294967291_int64) + lcg = int(mod(s, int(huge(0), int64)), kind(0)) + end function lcg +end subroutine init_random_seed diff --git a/lib/init_random_seed.h b/lib/init_random_seed.h new file mode 100644 index 00000000..01480338 --- /dev/null +++ b/lib/init_random_seed.h @@ -0,0 +1,20 @@ +#ifndef INIT_RANDOM_SEED_H__ +#define INIT_RANDOM_SEED_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * Generate a seed for the RANDOM_NUMBER PRNG that is guaranteed to + * be unique even if many processes are started simultaneously + * + * Not suitable for multi-threaded requirements + */ + void init_random_seed (void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/init_rs.c b/lib/init_rs.c index b836c1c5..a8052365 100644 --- a/lib/init_rs.c +++ b/lib/init_rs.c @@ -13,8 +13,6 @@ #include "char.h" #endif -//#define NULL ((void *)0) - void FREE_RS(void *p){ struct rs *rs = (struct rs *)p; diff --git a/lib/inter_wspr.f90 b/lib/inter_wspr.f90 new file mode 100644 index 00000000..9f980454 --- /dev/null +++ b/lib/inter_wspr.f90 @@ -0,0 +1,45 @@ +subroutine inter_wspr(id,ndir) + +! Interleave (ndir=1) or de-interleave (ndir=-1) the array id. + + integer*1 id(0:161),itmp(0:161) + integer j0(0:161) + logical first + data first/.true./ + save + + if(first) then +! Compute the interleave table using bit reversal. + k=-1 + do i=0,255 + n=0 + ii=i + do j=0,7 + n=n+n + if(iand(ii,1).ne.0) n=n+1 + ii=ii/2 + enddo + if(n.le.161) then + k=k+1 + j0(k)=n + endif + enddo + first=.false. + endif + + if(ndir.eq.1) then + do i=0,161 + itmp(j0(i))=id(i) + enddo + else + do i=0,161 + itmp(i)=id(j0(i)) + enddo + endif + + do i=0,161 + id(i)=itmp(i) + enddo + + return +end subroutine inter_wspr diff --git a/lib/interleave24.f90 b/lib/interleave24.f90 deleted file mode 100644 index 3cdd9c52..00000000 --- a/lib/interleave24.f90 +++ /dev/null @@ -1,43 +0,0 @@ -subroutine interleave24(id,ndir) - integer*1 id(0:205),itmp(0:205) - integer j0(0:205) - logical first - data first/.true./ - save first,j0 - - if(first) then - k=-1 - do i=0,255 - m=i - n=iand(m,1) - n=2*n + iand(m/2,1) - n=2*n + iand(m/4,1) - n=2*n + iand(m/8,1) - n=2*n + iand(m/16,1) - n=2*n + iand(m/32,1) - n=2*n + iand(m/64,1) - n=2*n + iand(m/128,1) - if(n.le.205) then - k=k+1 - j0(k)=n - endif - enddo - first=.false. - endif - - if(ndir.eq.1) then - do i=0,205 - itmp(j0(i))=id(i) - enddo - else - do i=0,205 - itmp(i)=id(j0(i)) - enddo - endif - - do i=0,205 - id(i)=itmp(i) - enddo - - return -end subroutine interleave24 diff --git a/lib/interleave4.f90 b/lib/interleave4.f90 new file mode 100644 index 00000000..db57ec32 --- /dev/null +++ b/lib/interleave4.f90 @@ -0,0 +1,43 @@ +subroutine interleave4(id,ndir) + integer*1 id(0:205),itmp(0:205) + integer j0(0:205) + logical first + data first/.true./ + save first,j0 + + if(first) then + k=-1 + do i=0,255 + m=i + n=iand(m,1) + n=2*n + iand(m/2,1) + n=2*n + iand(m/4,1) + n=2*n + iand(m/8,1) + n=2*n + iand(m/16,1) + n=2*n + iand(m/32,1) + n=2*n + iand(m/64,1) + n=2*n + iand(m/128,1) + if(n.le.205) then + k=k+1 + j0(k)=n + endif + enddo + first=.false. + endif + + if(ndir.eq.1) then + do i=0,205 + itmp(j0(i))=id(i) + enddo + else + do i=0,205 + itmp(i)=id(j0(i)) + enddo + endif + + do i=0,205 + id(i)=itmp(i) + enddo + + return +end subroutine interleave4 diff --git a/lib/ipcomm.cpp b/lib/ipcomm.cpp index d845a604..6f65dcae 100644 --- a/lib/ipcomm.cpp +++ b/lib/ipcomm.cpp @@ -3,6 +3,8 @@ #include #include +#include "../commons.h" + // Multiple instances: KK1D, 17 Jul 2013 QSharedMemory mem_jt9; @@ -16,17 +18,13 @@ extern "C" { bool detach_jt9_(); bool lock_jt9_(); bool unlock_jt9_(); - char* address_jt9_(); + struct jt9com * address_jt9_(); int size_jt9_(); // Multiple instances: wrapper for QSharedMemory::setKey() bool setkey_jt9_(char* mykey, int mykey_len); bool acquire_jt9_(); bool release_jt9_(); - - extern struct { - char c[10]; - } jt9com_; } bool attach_jt9_() {return mem_jt9.attach();} @@ -34,7 +32,7 @@ bool create_jt9_(int nsize) {return mem_jt9.create(nsize);} bool detach_jt9_() {return mem_jt9.detach();} bool lock_jt9_() {return mem_jt9.lock();} bool unlock_jt9_() {return mem_jt9.unlock();} -char* address_jt9_() {return (char*)mem_jt9.constData();} +struct jt9com * address_jt9_() {return reinterpret_cast(mem_jt9.data());} int size_jt9_() {return (int)mem_jt9.size();} // Multiple instances: diff --git a/lib/iscat.f90 b/lib/iscat.f90 new file mode 100644 index 00000000..c02a0fbe --- /dev/null +++ b/lib/iscat.f90 @@ -0,0 +1,206 @@ +subroutine iscat(cdat0,npts0,nh,npct,t2,pick,cfile6,minsync,ntol, & + NFreeze,MouseDF,mousebutton,mode4,nafc,nmore,psavg,maxlines,nlines,line) + +! Decode an ISCAT signal + + parameter (NMAX=30*3101) + parameter (NSZ=4*1400) + character cfile6*6 !File time + character c42*42 + character msg*29,msg1*29,msgbig*29 + character*80 line(100) + character csync*1 + complex cdat0(NMAX) + complex cdat(NMAX) + real s0(288,NSZ) + real fs1(0:41,30) + real psavg(72) !Average spectrum of whole file + integer nsum(30) + integer ntol + integer icos(4) + logical pick,last + data icos/0,1,3,2/ + data nsync/4/,nlen/2/,ndat/18/ + data c42/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ /.?@-'/ + save cdat,s0 + + nlines = 0 + fsample=3100.78125 !Sample rate after 9/32 downsampling + nsps=144/mode4 + + bigworst=-1.e30 !Silence compiler warnings ... + bigxsync=0. + bigsig=-1.e30 + msglenbig=0 + ndf0big=0 + nfdotbig=0 + bigt2=0. + bigavg=0. + bigtana=0. + if(nmore.eq.-999) bigsig=-1 !... to here + + last=.false. + do inf=1,6 !Loop over data-segment sizes + nframes=2**inf + if(nframes*24*nsps.gt.npts0) then + nframes=npts0/(24*nsps) + last=.true. + endif + npts=nframes*24*nsps + + do ia=1,npts0-npts,nsps*24 !Loop over start times stepped by 1 frame + ib=ia+npts-1 + cdat(1:npts)=cdat0(ia:ib) + t3=(ia + 0.5*npts)/fsample + 0.9 + if(pick) t3=t2+t3 + +! Compute symbol spectra and establish sync: + call synciscat(cdat,npts,nh,npct,s0,jsym,df,ntol,NFreeze, & + MouseDF,mousebutton,mode4,nafc,psavg,xsync,sig,ndf0,msglen, & + ipk,jpk,idf,df1) + nfdot=nint(idf*df1) + + isync=xsync + if(msglen.eq.0 .or. isync.lt.max(minsync,0)) then + msglen=0 + worst=1. + avg=1. + ndf0=0 + cycle + endif + + ipk3=0 !Silence compiler warning + nblk=nsync+nlen+ndat + fs1=0. + nsum=0 + nfold=jsym/96 + jb=96*nfold + k=0 + n=0 + do j=jpk,jsym,4 !Fold information symbols into fs1 + k=k+1 + km=mod(k-1,nblk)+1 + if(km.gt.6) then + n=n+1 + m=mod(n-1,msglen)+1 + ii=nint(idf*float(j-jb/2)/float(jb)) + do i=0,41 + iii=ii+ipk+2*i + if(iii.ge.1 .and. iii.le.288) fs1(i,m)=fs1(i,m) + s0(iii,j) + enddo + nsum(m)=nsum(m)+1 + endif + enddo + + do m=1,msglen + fs1(0:41,m)=fs1(0:41,m)/nsum(m) + enddo + +! Read out the message contents: + msg= ' ' + msg1=' ' + mpk=0 + worst=9999. + sum=0. + do m=1,msglen + smax=0. + smax2=0. + do i=0,41 + if(fs1(i,m).gt.smax) then + smax=fs1(i,m) + ipk3=i + endif + enddo + do i=0,41 + if(fs1(i,m).gt.smax2 .and. i.ne.ipk3) smax2=fs1(i,m) + enddo + rr=0. + if(smax2.gt.0.0) rr=smax/smax2 + sum=sum + rr + if(rr.lt.worst) worst=rr + if(ipk3.eq.40) mpk=m + msg1(m:m)=c42(ipk3+1:ipk3+1) + enddo + + avg=sum/msglen + if(mpk.eq.1) then + msg=msg1(2:) + else if(mpk.lt.msglen) then + msg=msg1(mpk+1:msglen)//msg1(1:mpk-1) + else + msg=msg1(1:msglen-1) + endif + + ttot=npts/3100.78125 + + if(worst.gt.bigworst) then + bigworst=worst + bigavg=avg + bigxsync=xsync + bigsig=sig + ndf0big=ndf0 + nfdotbig=nfdot + msgbig=msg + msglenbig=msglen + bigt2=t3 + bigtana=nframes*24*nsps/fsample + endif + + isync = xsync + if(avg.gt.2.5 .and. xsync.ge.max(float(minsync),1.5) .and. & + maxlines.ge.2) then + nsig=nint(sig) + nworst=10.0*(worst-1.0) + navg=10.0*(avg-1.0) + if(nworst.gt.10) nworst=10 + if(navg.gt.10) navg=10 + tana=nframes*24*nsps/fsample + csync=' ' + if(isync.ge.1) csync='*' + if(nlines.le.maxlines-1) nlines = nlines + 1 + write(line(nlines),1020) cfile6,isync,nsig,t2,ndf0,nfdot,csync, & + msg(1:28),msglen,navg,nworst,tana,char(0) + endif + enddo + if(last) exit + enddo + + worst=bigworst + avg=bigavg + xsync=bigxsync + sig=bigsig + ndf0=ndf0big + nfdot=nfdotbig + msg=msgbig + msglen=msglenbig + t2=bigt2 + tana=bigtana + + isync=xsync + nworst=10.0*(worst-1.0) + navg=10.0*(avg-1.0) + if(nworst.gt.10) nworst=10 + if(navg.gt.10) navg=10 + + if(navg.le.0 .or. isync.lt.max(minsync,0)) then + msg=' ' + nworst=0 + navg=0 + ndf0=0 + nfdot=0 + sig=-20 + msglen=0 + tana=0. + t2=0. + endif + csync=' ' + if(isync.ge.1) csync='*' + nsig=nint(sig) + + if(nlines.le.maxlines-1) nlines = nlines + 1 + write(line(nlines),1020) cfile6,isync,nsig,t2,ndf0,nfdot,csync,msg(1:28), & + msglen,navg,nworst,tana,char(0) +1020 format(a6,2i4,f5.1,i5,i4,1x,a1,2x,a28,i4,i3,2x,i1,f5.1,a1) + + return +end subroutine iscat diff --git a/lib/iso_c_utilities.f90 b/lib/iso_c_utilities.f90 new file mode 100644 index 00000000..cdcc1a74 --- /dev/null +++ b/lib/iso_c_utilities.f90 @@ -0,0 +1,87 @@ +module iso_c_utilities + + use, intrinsic :: iso_c_binding, only: c_ptr, c_char, c_f_pointer, c_associated + implicit none + + public :: c_to_f_string, c_f_dyn_string + + private + + character(c_char), dimension(1), save, target :: dummy_string = "?" + + interface ! strlen is a standard C function from + ! int strlen(char *string) + function strlen (string) result (len) bind (c, name="strlen") + use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t + implicit none + type(c_ptr), value :: string + integer(kind=c_size_t) :: len + end function strlen + + ! void free(void * p) + subroutine c_free (p) bind (c, name="free") + use, intrinsic :: iso_c_binding, only: c_ptr + implicit none + type(c_ptr), value :: p + end subroutine c_free + end interface + +contains + + ! + ! Cast C string pointer to Fortran string pointer + ! + ! Warning! - C data must outlive result scope + ! + function c_to_f_string (c_str) result (f_str) + use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer, c_char + implicit none + type(c_ptr), intent(in) :: c_str + character(kind=c_char, len=:), pointer :: f_str + character(kind=c_char), pointer :: arr(:) + interface ! strlen is a standard C function from + ! int strlen(char *string) + function strlen (string) result (len) bind (c, name="strlen") + use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t + implicit none + type(c_ptr), value :: string + integer(kind=c_size_t) :: len + end function strlen + end interface + call c_f_pointer (c_str, arr, [strlen (c_str)]) + call get_scalar_pointer (size (arr), arr, f_str) + end function c_to_f_string + + subroutine get_scalar_pointer (scalar_len, scalar, fptr) + ! Convert a null-terminated C string into a Fortran character pointer + use, intrinsic :: iso_c_binding, only: c_char + integer, intent(in) :: scalar_len + character(kind=c_char, len=scalar_len), intent(in), target :: scalar(1) + character(kind=c_char, len=:), pointer :: fptr + fptr => scalar(1) + end subroutine get_scalar_pointer + + function c_f_dyn_string (cptr) result (fstr) + ! Convert a null-terminated malloc'ed C string into a Fortran character array + type(c_ptr), intent(in) :: cptr ! The C address + character(kind=c_char), allocatable :: fstr(:) + character(kind=c_char), pointer :: fptr(:) + interface ! strlen is a standard C function from + ! void free(void * p) + subroutine c_free (p) bind (c, name="free") + use, intrinsic :: iso_c_binding, only: c_ptr + implicit none + type(c_ptr), value :: p + end subroutine c_free + end interface + if (c_associated (cptr)) then + call c_f_pointer (fptr=fptr, cptr=cptr, shape=[strlen(cptr)]) + else + ! To avoid segfaults, associate FPTR with a dummy target: + fptr => dummy_string + end if + fstr = fptr + call c_free (cptr) + end function c_f_dyn_string + +end module diff --git a/lib/jplsubs.f b/lib/jplsubs.f new file mode 100644 index 00000000..6dcd1c9b --- /dev/null +++ b/lib/jplsubs.f @@ -0,0 +1,899 @@ +C++++++++++++++++++++++++ +C + SUBROUTINE FSIZER1(NRECL,KSIZE,NRFILE,NAMFIL) +C +C++++++++++++++++++++++++ +C +C Version 1.0 uses the INQUIRE statement to find out the the record length +C of the direct access file before opening it. This procedure is non-standard, +C but seems to work for VAX machines. +C +C THE SUBROUTINE ALSO SETS THE VALUES OF NRECL, NRFILE, AND NAMFIL. + +C ***************************************************************** +C ***************************************************************** +C +C THE PARAMETERS NAMFIL, NRECL, AND NRFILE ARE TO BE SET BY THE USER +C +C ***************************************************************** + +C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE + + CHARACTER*256 NAMFIL + +c NAMFIL='JPLEPH' + +C ***************************************************************** + +C NRECL=1 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN S.P. WORDS +C NRECL=4 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN BYTES +C (for a VAX, it is probably 1) +C + NRECL=4 + +C ***************************************************************** + +C NRFILE IS THE INTERNAL UNIT NUMBER USED FOR THE EPHEMERIS FILE + +c NRFILE=12 + +C ***************************************************************** + +C FIND THE RECORD SIZE USING THE INQUIRE STATEMENT + + +c IRECSZ=0 + + INQUIRE(FILE=NAMFIL,RECL=IRECSZ) + +C IF 'INQUIRE' DOES NOT WORK, USUALLY IRECSZ WILL BE LEFT AT 0 + + IF(IRECSZ .LE. 0) write(*,*) + . ' INQUIRE STATEMENT PROBABLY DID NOT WORK' + + KSIZE=IRECSZ/NRECL + if(nrfile.eq.-99) stop !silence compiler warning + + RETURN + + END +C++++++++++++++++++++++++ +C + SUBROUTINE FSIZER2(NRECL,KSIZE,NRFILE,NAMFIL) +C +C++++++++++++++++++++++++ +C THIS SUBROUTINE OPENS THE FILE, 'NAMFIL', WITH A PHONY RECORD LENGTH, READS +C THE FIRST RECORD, AND USES THE INFO TO COMPUTE KSIZE, THE NUMBER OF SINGLE +C PRECISION WORDS IN A RECORD. +C +C THE SUBROUTINE ALSO SETS THE VALUES OF NRECL, NRFILE, AND NAMFIL. + + IMPLICIT DOUBLE PRECISION(A-H,O-Z) + + SAVE + + INTEGER OLDMAX + PARAMETER (OLDMAX = 400) + INTEGER NMAX + PARAMETER (NMAX = 1000) + CHARACTER*6 TTL(14,3),CNAM(NMAX) + CHARACTER*256 NAMFIL,jpleph_file_name + DIMENSION SS(3) + INTEGER IPT(3,13) + common/jplcom/jpleph_file_name + +C ***************************************************************** +C ***************************************************************** +C +C THE PARAMETERS NRECL, NRFILE, AND NAMFIL ARE TO BE SET BY THE USER +C +C ***************************************************************** + +C NRECL=1 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN S.P. WORDS +C NRECL=4 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN BYTES +C (for UNIX, it is probably 4) +C + NRECL=4 + +C NRFILE IS THE INTERNAL UNIT NUMBER USED FOR THE EPHEMERIS FILE + + NRFILE=12 + +C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE + +! NAMFIL='JPLEPH' + NAMFIL=jpleph_file_name + +C ***************************************************************** +C ***************************************************************** + +C ** OPEN THE DIRECT-ACCESS FILE AND GET THE POINTERS IN ORDER TO +C ** DETERMINE THE SIZE OF THE EPHEMERIS RECORD + + MRECL=NRECL*1000 + + OPEN(NRFILE, + * FILE=NAMFIL, + * ACCESS='DIRECT', + * FORM='UNFORMATTED', + * RECL=MRECL, + * STATUS='OLD') + + READ(NRFILE,REC=1)TTL,(CNAM(K),K=1,OLDMAX),SS,NCON,AU,EMRAT, + & ((IPT(I,J),I=1,3),J=1,12),NUMDE,(IPT(I,13),I=1,3) + + CLOSE(NRFILE) + +C FIND THE NUMBER OF EPHEMERIS COEFFICIENTS FROM THE POINTERS + + KMX = 0 + KHI = 0 + + DO I = 1,13 + IF (IPT(1,I) .GT. KMX) THEN + KMX = IPT(1,I) + KHI = I + ENDIF + ENDDO + + ND = 3 + IF (KHI .EQ. 12) ND=2 + + KSIZE = 2*(IPT(1,KHI)+ND*IPT(2,KHI)*IPT(3,KHI)-1) + + RETURN + + END +C++++++++++++++++++++++++ +C + SUBROUTINE FSIZER3(NRECL,KSIZE,NRFILE,NAMFIL) +C +C++++++++++++++++++++++++ +C +C THE SUBROUTINE SETS THE VALUES OF NRECL, KSIZE, NRFILE, AND NAMFIL. + + SAVE + CHARACTER*256 NAMFIL,jpleph_file_name + common/jplcom/jpleph_file_name + +C ***************************************************************** +C ***************************************************************** +C +C THE PARAMETERS NRECL, NRFILE, AND NAMFIL ARE TO BE SET BY THE USER + +C ***************************************************************** + +C NRECL=1 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN S.P. WORDS +C NRECL=4 IF "RECL" IN THE OPEN STATEMENT IS THE RECORD LENGTH IN BYTES + + NRECL=4 + +C ***************************************************************** + +C NRFILE IS THE INTERNAL UNIT NUMBER USED FOR THE EPHEMERIS FILE (DEFAULT: 12) + + NRFILE=12 + +C ***************************************************************** + +C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE + +! NAMFIL='JPLEPH' + NAMFIL=jpleph_file_name + +C ***************************************************************** + +C KSIZE must be set by the user according to the ephemeris to be read + +C For de200, set KSIZE to 1652 +C For de405, set KSIZE to 2036 +C For de406, set KSIZE to 1456 +C For de414, set KSIZE to 2036 +C For de418, set KSIZE to 2036 +C For de421, set KSIZE to 2036 +C For de422, set KSIZE to 2036 +C For de423, set KSIZE to 2036 +C For de424, set KSIZE to 2036 +C For de430, set KSIZE to 2036 + + KSIZE = 2036 + +C ******************************************************************* + + RETURN + + END +C++++++++++++++++++++++++++ +C + SUBROUTINE PLEPH ( ET, NTARG, NCENT, RRD ) +C +C++++++++++++++++++++++++++ +C NOTE : Over the years, different versions of PLEPH have had a fifth argument: +C sometimes, an error return statement number; sometimes, a logical denoting +C whether or not the requested date is covered by the ephemeris. We apologize +C for this inconsistency; in this present version, we use only the four necessary +C arguments and do the testing outside of the subroutine. +C +C THIS SUBROUTINE READS THE JPL PLANETARY EPHEMERIS +C AND GIVES THE POSITION AND VELOCITY OF THE POINT 'NTARG' +C WITH RESPECT TO 'NCENT'. +C +C CALLING SEQUENCE PARAMETERS: +C +C ET = D.P. JULIAN EPHEMERIS DATE AT WHICH INTERPOLATION +C IS WANTED. +C +C ** NOTE THE ENTRY DPLEPH FOR A DOUBLY-DIMENSIONED TIME ** +C THE REASON FOR THIS OPTION IS DISCUSSED IN THE +C SUBROUTINE STATE +C +C NTARG = INTEGER NUMBER OF 'TARGET' POINT. +C +C NCENT = INTEGER NUMBER OF CENTER POINT. +C +C THE NUMBERING CONVENTION FOR 'NTARG' AND 'NCENT' IS: +C +C 1 = MERCURY 8 = NEPTUNE +C 2 = VENUS 9 = PLUTO +C 3 = EARTH 10 = MOON +C 4 = MARS 11 = SUN +C 5 = JUPITER 12 = SOLAR-SYSTEM BARYCENTER +C 6 = SATURN 13 = EARTH-MOON BARYCENTER +C 7 = URANUS 14 = NUTATIONS (LONGITUDE AND OBLIQ) +C 15 = LIBRATIONS, IF ON EPH FILE +C +C (IF NUTATIONS ARE WANTED, SET NTARG = 14. FOR LIBRATIONS, +C SET NTARG = 15. SET NCENT=0.) +C +C RRD = OUTPUT 6-WORD D.P. ARRAY CONTAINING POSITION AND VELOCITY +C OF POINT 'NTARG' RELATIVE TO 'NCENT'. THE UNITS ARE AU AND +C AU/DAY. FOR LIBRATIONS THE UNITS ARE RADIANS AND RADIANS +C PER DAY. IN THE CASE OF NUTATIONS THE FIRST FOUR WORDS OF +C RRD WILL BE SET TO NUTATIONS AND RATES, HAVING UNITS OF +C RADIANS AND RADIANS/DAY. +C +C The option is available to have the units in km and km/sec. +C For this, set km=.true. in the STCOMX common block. +C + + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + + INTEGER NMAX + PARAMETER (NMAX = 1000) + + DIMENSION RRD(6),ET2Z(2),ET2(2),PV(6,13) + DIMENSION PVST(6,11),PNUT(4) + DIMENSION SS(3),CVAL(NMAX),PVSUN(6),ZIPS(2) + DATA ZIPS/2*0.d0/ + + LOGICAL BSAVE,KM,BARY + LOGICAL FIRST + DATA FIRST/.TRUE./ + + INTEGER LIST(12),IPT(39),DENUM + COMMON/EPHHDR/CVAL,SS,AU,EMRAT,DENUM,NCON,IPT + COMMON/STCOMX/KM,BARY,PVSUN + +C INITIALIZE ET2 FOR 'STATE' AND SET UP COMPONENT COUNT +C + ET2(1)=ET + ET2(2)=0.D0 + GO TO 11 + +C ENTRY POINT 'DPLEPH' FOR DOUBLY-DIMENSIONED TIME ARGUMENT +C (SEE THE DISCUSSION IN THE SUBROUTINE STATE) + + ENTRY DPLEPH(ET2Z,NTARG,NCENT,RRD) + + ET2(1)=ET2Z(1) + ET2(2)=ET2Z(2) + + 11 IF(FIRST) CALL STATE(ZIPS,LIST,PVST,PNUT) + FIRST=.FALSE. + + IF(NTARG .EQ. NCENT) RETURN + + DO I=1,12 + LIST(I)=0 + ENDDO + +C CHECK FOR NUTATION CALL + + IF(NTARG.NE.14) GO TO 97 + IF(IPT(35).GT.0) THEN + LIST(11)=2 + CALL STATE(ET2,LIST,PVST,PNUT) + DO I=1,4 + RRD(I)=PNUT(I) + ENDDO + RRD(5) = 0.d0 + RRD(6) = 0.d0 + RETURN + ELSE + DO I=1,4 + RRD(I)=0.d0 + ENDDO + WRITE(6,297) + 297 FORMAT(' ***** NO NUTATIONS ON THE EPHEMERIS FILE *****') + STOP + ENDIF + +C CHECK FOR LIBRATIONS + + 97 CONTINUE + DO I=1,6 + RRD(I)=0.d0 + ENDDO + + IF(NTARG.NE.15) GO TO 98 + IF(IPT(38).GT.0) THEN + LIST(12)=2 + CALL STATE(ET2,LIST,PVST,PNUT) + DO I=1,6 + RRD(I)=PVST(I,11) + ENDDO + RETURN + ELSE + WRITE(6,298) + 298 FORMAT(' ***** NO LIBRATIONS ON THE EPHEMERIS FILE *****') + STOP + ENDIF + +C FORCE BARYCENTRIC OUTPUT BY 'STATE' + + 98 BSAVE=BARY + BARY=.TRUE. + +C SET UP PROPER ENTRIES IN 'LIST' ARRAY FOR STATE CALL + + DO I=1,2 + K=NTARG + IF(I .EQ. 2) K=NCENT + IF(K .LE. 10) LIST(K)=2 + IF(K .EQ. 10) LIST(3)=2 + IF(K .EQ. 3) LIST(10)=2 + IF(K .EQ. 13) LIST(3)=2 + ENDDO + +C MAKE CALL TO STATE + + CALL STATE(ET2,LIST,PVST,PNUT) + + DO I=1,10 + DO J = 1,6 + PV(J,I) = PVST(J,I) + ENDDO + ENDDO + + IF(NTARG .EQ. 11 .OR. NCENT .EQ. 11) THEN + DO I=1,6 + PV(I,11)=PVSUN(I) + ENDDO + ENDIF + + IF(NTARG .EQ. 12 .OR. NCENT .EQ. 12) THEN + DO I=1,6 + PV(I,12)=0.D0 + ENDDO + ENDIF + + IF(NTARG .EQ. 13 .OR. NCENT .EQ. 13) THEN + DO I=1,6 + PV(I,13) = PVST(I,3) + ENDDO + ENDIF + + IF(NTARG*NCENT .EQ. 30 .AND. NTARG+NCENT .EQ. 13) THEN + DO I=1,6 + PV(I,3)=0.D0 + ENDDO + GO TO 99 + ENDIF + + IF(LIST(3) .EQ. 2) THEN + DO I=1,6 + PV(I,3)=PVST(I,3)-PVST(I,10)/(1.D0+EMRAT) + ENDDO + ENDIF + + IF(LIST(10) .EQ. 2) THEN + DO I=1,6 + PV(I,10) = PV(I,3)+PVST(I,10) + ENDDO + ENDIF + + 99 DO I=1,6 + RRD(I)=PV(I,NTARG)-PV(I,NCENT) + ENDDO + + BARY=BSAVE + + RETURN + END +C+++++++++++++++++++++++++++++++++ +C + SUBROUTINE INTERP(BUF,T,NCF,NCM,NA,IFL,PV) +C +C+++++++++++++++++++++++++++++++++ +C +C THIS SUBROUTINE DIFFERENTIATES AND INTERPOLATES A +C SET OF CHEBYSHEV COEFFICIENTS TO GIVE POSITION AND VELOCITY +C +C CALLING SEQUENCE PARAMETERS: +C +C INPUT: +C +C BUF 1ST LOCATION OF ARRAY OF D.P. CHEBYSHEV COEFFICIENTS OF POSITION +C +C T T(1) IS DP FRACTIONAL TIME IN INTERVAL COVERED BY +C COEFFICIENTS AT WHICH INTERPOLATION IS WANTED +C (0 .LE. T(1) .LE. 1). T(2) IS DP LENGTH OF WHOLE +C INTERVAL IN INPUT TIME UNITS. +C +C NCF # OF COEFFICIENTS PER COMPONENT +C +C NCM # OF COMPONENTS PER SET OF COEFFICIENTS +C +C NA # OF SETS OF COEFFICIENTS IN FULL ARRAY +C (I.E., # OF SUB-INTERVALS IN FULL INTERVAL) +C +C IFL INTEGER FLAG: =1 FOR POSITIONS ONLY +C =2 FOR POS AND VEL +C +C +C OUTPUT: +C +C PV INTERPOLATED QUANTITIES REQUESTED. DIMENSION +C EXPECTED IS PV(NCM,IFL), DP. +C +C + IMPLICIT DOUBLE PRECISION (A-H,O-Z) +C + SAVE +C + DOUBLE PRECISION BUF(NCF,NCM,*),T(2),PV(NCM,*),PC(18),VC(18) + +C + DATA NP/2/ + DATA NV/3/ + DATA TWOT/0.D0/ + DATA PC(1),PC(2)/1.D0,0.D0/ + DATA VC(2)/1.D0/ +C +C ENTRY POINT. GET CORRECT SUB-INTERVAL NUMBER FOR THIS SET +C OF COEFFICIENTS AND THEN GET NORMALIZED CHEBYSHEV TIME +C WITHIN THAT SUBINTERVAL. +C + DNA=DBLE(NA) + DT1=DINT(T(1)) + TEMP=DNA*T(1) + L=IDINT(TEMP-DT1)+1 + +C TC IS THE NORMALIZED CHEBYSHEV TIME (-1 .LE. TC .LE. 1) + + TC=2.D0*(DMOD(TEMP,1.D0)+DT1)-1.D0 + +C CHECK TO SEE WHETHER CHEBYSHEV TIME HAS CHANGED, +C AND COMPUTE NEW POLYNOMIAL VALUES IF IT HAS. +C (THE ELEMENT PC(2) IS THE VALUE OF T1(TC) AND HENCE +C CONTAINS THE VALUE OF TC ON THE PREVIOUS CALL.) + + IF(TC.NE.PC(2)) THEN + NP=2 + NV=3 + PC(2)=TC + TWOT=TC+TC + ENDIF +C +C BE SURE THAT AT LEAST 'NCF' POLYNOMIALS HAVE BEEN EVALUATED +C AND ARE STORED IN THE ARRAY 'PC'. +C + IF(NP.LT.NCF) THEN + DO 1 I=NP+1,NCF + PC(I)=TWOT*PC(I-1)-PC(I-2) + 1 CONTINUE + NP=NCF + ENDIF +C +C INTERPOLATE TO GET POSITION FOR EACH COMPONENT +C + DO 2 I=1,NCM + PV(I,1)=0.D0 + DO 3 J=NCF,1,-1 + PV(I,1)=PV(I,1)+PC(J)*BUF(J,I,L) + 3 CONTINUE + 2 CONTINUE + IF(IFL.LE.1) RETURN +C +C IF VELOCITY INTERPOLATION IS WANTED, BE SURE ENOUGH +C DERIVATIVE POLYNOMIALS HAVE BEEN GENERATED AND STORED. +C + VFAC=(DNA+DNA)/T(2) + VC(3)=TWOT+TWOT + IF(NV.LT.NCF) THEN + DO 4 I=NV+1,NCF + VC(I)=TWOT*VC(I-1)+PC(I-1)+PC(I-1)-VC(I-2) + 4 CONTINUE + NV=NCF + ENDIF +C +C INTERPOLATE TO GET VELOCITY FOR EACH COMPONENT +C + DO 5 I=1,NCM + PV(I,2)=0.D0 + DO 6 J=NCF,2,-1 + PV(I,2)=PV(I,2)+VC(J)*BUF(J,I,L) + 6 CONTINUE + PV(I,2)=PV(I,2)*VFAC + 5 CONTINUE +C + RETURN +C + END + +C+++++++++++++++++++++++++ +C + SUBROUTINE SPLIT(TT,FR) +C +C+++++++++++++++++++++++++ +C +C THIS SUBROUTINE BREAKS A D.P. NUMBER INTO A D.P. INTEGER +C AND A D.P. FRACTIONAL PART. +C +C CALLING SEQUENCE PARAMETERS: +C +C TT = D.P. INPUT NUMBER +C +C FR = D.P. 2-WORD OUTPUT ARRAY. +C FR(1) CONTAINS INTEGER PART +C FR(2) CONTAINS FRACTIONAL PART +C +C FOR NEGATIVE INPUT NUMBERS, FR(1) CONTAINS THE NEXT +C MORE NEGATIVE INTEGER; FR(2) CONTAINS A POSITIVE FRACTION. +C +C CALLING SEQUENCE DECLARATIONS +C + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + + DIMENSION FR(2) + +C MAIN ENTRY -- GET INTEGER AND FRACTIONAL PARTS + + FR(1)=DINT(TT) + FR(2)=TT-FR(1) + + IF(TT.GE.0.D0 .OR. FR(2).EQ.0.D0) RETURN + +C MAKE ADJUSTMENTS FOR NEGATIVE INPUT NUMBER + + FR(1)=FR(1)-1.D0 + FR(2)=FR(2)+1.D0 + + RETURN + + END + + +C++++++++++++++++++++++++++++++++ +C + SUBROUTINE STATE(ET2,LIST,PV,PNUT) +C +C++++++++++++++++++++++++++++++++ +C +C THIS SUBROUTINE READS AND INTERPOLATES THE JPL PLANETARY EPHEMERIS FILE +C +C CALLING SEQUENCE PARAMETERS: +C +C INPUT: +C +C ET2 DP 2-WORD JULIAN EPHEMERIS EPOCH AT WHICH INTERPOLATION +C IS WANTED. ANY COMBINATION OF ET2(1)+ET2(2) WHICH FALLS +C WITHIN THE TIME SPAN ON THE FILE IS A PERMISSIBLE EPOCH. +C +C A. FOR EASE IN PROGRAMMING, THE USER MAY PUT THE +C ENTIRE EPOCH IN ET2(1) AND SET ET2(2)=0. +C +C B. FOR MAXIMUM INTERPOLATION ACCURACY, SET ET2(1) = +C THE MOST RECENT MIDNIGHT AT OR BEFORE INTERPOLATION +C EPOCH AND SET ET2(2) = FRACTIONAL PART OF A DAY +C ELAPSED BETWEEN ET2(1) AND EPOCH. +C +C C. AS AN ALTERNATIVE, IT MAY PROVE CONVENIENT TO SET +C ET2(1) = SOME FIXED EPOCH, SUCH AS START OF INTEGRATION, +C AND ET2(2) = ELAPSED INTERVAL BETWEEN THEN AND EPOCH. +C +C LIST 12-WORD INTEGER ARRAY SPECIFYING WHAT INTERPOLATION +C IS WANTED FOR EACH OF THE BODIES ON THE FILE. +C +C LIST(I)=0, NO INTERPOLATION FOR BODY I +C =1, POSITION ONLY +C =2, POSITION AND VELOCITY +C +C THE DESIGNATION OF THE ASTRONOMICAL BODIES BY I IS: +C +C I = 1: MERCURY +C = 2: VENUS +C = 3: EARTH-MOON BARYCENTER +C = 4: MARS +C = 5: JUPITER +C = 6: SATURN +C = 7: URANUS +C = 8: NEPTUNE +C = 9: PLUTO +C =10: GEOCENTRIC MOON +C =11: NUTATIONS IN LONGITUDE AND OBLIQUITY +C =12: LUNAR LIBRATIONS (IF ON FILE) +C +C OUTPUT: +C +C PV DP 6 X 11 ARRAY THAT WILL CONTAIN REQUESTED INTERPOLATED +C QUANTITIES (OTHER THAN NUTATION, STOERD IN PNUT). +C THE BODY SPECIFIED BY LIST(I) WILL HAVE ITS +C STATE IN THE ARRAY STARTING AT PV(1,I). +C (ON ANY GIVEN CALL, ONLY THOSE WORDS IN 'PV' WHICH ARE +C AFFECTED BY THE FIRST 10 'LIST' ENTRIES, AND BY LIST(12) +C IF LIBRATIONS ARE ON THE FILE, ARE SET. +C THE REST OF THE 'PV' ARRAYIS UNTOUCHED.) +C THE ORDER OF COMPONENTS STARTING IN PV(1,I) IS: X,Y,Z,DX,DY,DZ. +C +C ALL OUTPUT VECTORS ARE REFERENCED TO THE EARTH MEAN +C EQUATOR AND EQUINOX OF J2000 IF THE DE NUMBER IS 200 OR +C GREATER; OF B1950 IF THE DE NUMBER IS LESS THAN 200. +C +C THE MOON STATE IS ALWAYS GEOCENTRIC; THE OTHER NINE STATES +C ARE EITHER HELIOCENTRIC OR SOLAR-SYSTEM BARYCENTRIC, +C DEPENDING ON THE SETTING OF COMMON FLAGS (SEE BELOW). +C +C LUNAR LIBRATIONS, IF ON FILE, ARE PUT INTO PV(K,11) IF +C LIST(12) IS 1 OR 2. +C +C NUT DP 4-WORD ARRAY THAT WILL CONTAIN NUTATIONS AND RATES, +C DEPENDING ON THE SETTING OF LIST(11). THE ORDER OF +C QUANTITIES IN NUT IS: +C +C D PSI (NUTATION IN LONGITUDE) +C D EPSILON (NUTATION IN OBLIQUITY) +C D PSI DOT +C D EPSILON DOT +C +C * STATEMENT # FOR ERROR RETURN, IN CASE OF EPOCH OUT OF +C RANGE OR I/O ERRORS. +C +C COMMON AREA STCOMX: +C +C KM LOGICAL FLAG DEFINING PHYSICAL UNITS OF THE OUTPUT +C STATES. KM = .TRUE., KM AND KM/SEC +C = .FALSE., AU AND AU/DAY +C DEFAULT VALUE = .FALSE. (KM DETERMINES TIME UNIT +C FOR NUTATIONS AND LIBRATIONS. ANGLE UNIT IS ALWAYS RADIANS.) +C +C BARY LOGICAL FLAG DEFINING OUTPUT CENTER. +C ONLY THE 9 PLANETS ARE AFFECTED. +C BARY = .TRUE. =\ CENTER IS SOLAR-SYSTEM BARYCENTER +C = .FALSE. =\ CENTER IS SUN +C DEFAULT VALUE = .FALSE. +C +C PVSUN DP 6-WORD ARRAY CONTAINING THE BARYCENTRIC POSITION AND +C VELOCITY OF THE SUN. +C +C + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + + SAVE + + INTEGER OLDMAX + PARAMETER ( OLDMAX = 400) + INTEGER NMAX + PARAMETER ( NMAX = 1000) + + DIMENSION ET2(2),PV(6,11),PNUT(4),T(2),PJD(4),BUF(1500), + . SS(3),CVAL(NMAX),PVSUN(6) + + INTEGER LIST(12),IPT(3,13) + + LOGICAL FIRST + DATA FIRST/.TRUE./ + + CHARACTER*6 TTL(14,3),CNAM(NMAX) + CHARACTER*256 NAMFIL + + LOGICAL KM,BARY + + COMMON/EPHHDR/CVAL,SS,AU,EMRAT,NUMDE,NCON,IPT + COMMON/CHRHDR/CNAM,TTL + COMMON/STCOMX/KM,BARY,PVSUN + +C +C ENTRY POINT - 1ST TIME IN, GET POINTER DATA, ETC., FROM EPH FILE +C + IF(FIRST) THEN + FIRST=.FALSE. + +C ************************************************************************ +C ************************************************************************ + +C THE USER MUST SELECT ONE OF THE FOLLOWING BY DELETING THE 'C' IN COLUMN 1 + +C ************************************************************************ + +C CALL FSIZER1(NRECL,KSIZE,NRFILE,NAMFIL) +C CALL FSIZER2(NRECL,KSIZE,NRFILE,NAMFIL) + CALL FSIZER3(NRECL,KSIZE,NRFILE,NAMFIL) + + IF(NRECL .EQ. 0) WRITE(*,*)' ***** FSIZER IS NOT WORKING *****' + +C ************************************************************************ +C ************************************************************************ + + IRECSZ=NRECL*KSIZE + NCOEFFS=KSIZE/2 + + OPEN(NRFILE, + * FILE=NAMFIL, + * ACCESS='DIRECT', + * FORM='UNFORMATTED', + * RECL=IRECSZ, + * STATUS='OLD') + + READ(NRFILE,REC=1)TTL,(CNAM(K),K=1,OLDMAX),SS,NCON,AU,EMRAT, + & ((IPT(I,J),I=1,3),J=1,12),NUMDE,(IPT(I,13),I=1,3) + & ,(CNAM(L),L=OLDMAX+1,NCON) + + IF(NCON .LE. OLDMAX)THEN + READ(NRFILE,REC=2)(CVAL(I),I=1,OLDMAX) + ELSE + READ(NRFILE,REC=2)(CVAL(I),I=1,NCON) + ENDIF + + NRL=0 + + ENDIF + +C ********** MAIN ENTRY POINT ********** + + IF(ET2(1) .EQ. 0.D0) RETURN + + S=ET2(1)-.5D0 + CALL SPLIT(S,PJD(1)) + CALL SPLIT(ET2(2),PJD(3)) + PJD(1)=PJD(1)+PJD(3)+.5D0 + PJD(2)=PJD(2)+PJD(4) + CALL SPLIT(PJD(2),PJD(3)) + PJD(1)=PJD(1)+PJD(3) + +C ERROR RETURN FOR EPOCH OUT OF RANGE + + IF(PJD(1)+PJD(4).LT.SS(1) .OR. PJD(1)+PJD(4).GT.SS(2)) GO TO 98 + +C CALCULATE RECORD # AND RELATIVE TIME IN INTERVAL + + NR=IDINT((PJD(1)-SS(1))/SS(3))+3 + IF(PJD(1).EQ.SS(2)) NR=NR-1 + + tmp1 = DBLE(NR-3)*SS(3) + SS(1) + tmp2 = PJD(1) - tmp1 + T(1) = (tmp2 + PJD(4))/SS(3) + +C READ CORRECT RECORD IF NOT IN CORE + + IF(NR.NE.NRL) THEN + NRL=NR + READ(NRFILE,REC=NR,ERR=99)(BUF(K),K=1,NCOEFFS) + ENDIF + + IF(KM) THEN + T(2)=SS(3)*86400.D0 + AUFAC=1.D0 + ELSE + T(2)=SS(3) + AUFAC=1.D0/AU + ENDIF + +C INTERPOLATE SSBARY SUN + + CALL INTERP(BUF(IPT(1,11)),T,IPT(2,11),3,IPT(3,11),2,PVSUN) + + DO I=1,6 + PVSUN(I)=PVSUN(I)*AUFAC + ENDDO + +C CHECK AND INTERPOLATE WHICHEVER BODIES ARE REQUESTED + + DO 4 I=1,10 + IF(LIST(I).EQ.0) GO TO 4 + + CALL INTERP(BUF(IPT(1,I)),T,IPT(2,I),3,IPT(3,I), + & LIST(I),PV(1,I)) + + DO J=1,6 + IF(I.LE.9 .AND. .NOT.BARY) THEN + PV(J,I)=PV(J,I)*AUFAC-PVSUN(J) + ELSE + PV(J,I)=PV(J,I)*AUFAC + ENDIF + ENDDO + + 4 CONTINUE + +C DO NUTATIONS IF REQUESTED (AND IF ON FILE) + + IF(LIST(11).GT.0 .AND. IPT(2,12).GT.0) + * CALL INTERP(BUF(IPT(1,12)),T,IPT(2,12),2,IPT(3,12), + * LIST(11),PNUT) + +C GET LIBRATIONS IF REQUESTED (AND IF ON FILE) + + IF(LIST(12).GT.0 .AND. IPT(2,13).GT.0) + * CALL INTERP(BUF(IPT(1,13)),T,IPT(2,13),3,IPT(3,13), + * LIST(12),PV(1,11)) + + RETURN + + 98 WRITE(*,198)ET2(1)+ET2(2),SS(1),SS(2) + 198 FORMAT(' *** Requested JED,',f12.2, + * ' not within ephemeris limits,',2f12.2,' ***') + + STOP + + 99 WRITE(*,'(2F12.2,A80)')ET2,'ERROR RETURN IN STATE' + + STOP + + END +C+++++++++++++++++++++++++++++ +C + SUBROUTINE CONST(NAM,VAL,SSS,N) +C +C+++++++++++++++++++++++++++++ +C +C THIS ENTRY OBTAINS THE CONSTANTS FROM THE EPHEMERIS FILE +C +C CALLING SEQEUNCE PARAMETERS (ALL OUTPUT): +C +C NAM = CHARACTER*6 ARRAY OF CONSTANT NAMES +C +C VAL = D.P. ARRAY OF VALUES OF CONSTANTS +C +C SSS = D.P. JD START, JD STOP, STEP OF EPHEMERIS +C +C N = INTEGER NUMBER OF ENTRIES IN 'NAM' AND 'VAL' ARRAYS +C + IMPLICIT DOUBLE PRECISION (A-H,O-Z) + + SAVE + + INTEGER NMAX + PARAMETER (NMAX = 1000) + + CHARACTER*6 NAM(*),TTL(14,3),CNAM(NMAX) + + DOUBLE PRECISION VAL(*),SSS(3),SS(3),CVAL(NMAX),ZIPS(2) + DOUBLE PRECISION PVST(6,11),PNUT(4) + DATA ZIPS/2*0.d0/ + + INTEGER IPT(3,13),DENUM,LIST(12) + logical first + data first/.true./ + + COMMON/EPHHDR/CVAL,SS,AU,EMRAT,DENUM,NCON,IPT + COMMON/CHRHDR/CNAM,TTL + +C CALL STATE TO INITIALIZE THE EPHEMERIS AND READ IN THE CONSTANTS + + IF(FIRST) CALL STATE(ZIPS,LIST,PVST,PNUT) + first=.false. + + N=NCON + + DO I=1,3 + SSS(I)=SS(I) + ENDDO + + DO I=1,N + NAM(I)=CNAM(I) + VAL(I)=CVAL(I) + ENDDO + + RETURN + + END diff --git a/lib/jt4.f90 b/lib/jt4.f90 new file mode 100644 index 00000000..21407255 --- /dev/null +++ b/lib/jt4.f90 @@ -0,0 +1,26 @@ +module jt4 + parameter (MAXAVE=64) + integer iutc(MAXAVE) + integer nfsave(MAXAVE) + integer listutc(10) + real ppsave(207,7,MAXAVE) !Accumulated data for message averaging + real rsymbol(207,7) + real dtsave(MAXAVE) + real syncsave(MAXAVE) + real flipsave(MAXAVE) + real zz(1260,65,7) + + integer nsave,nlist,ich1,ich2 + integer nch(7) + integer npr(207) + data rsymbol/1449*0.0/ + data nch/1,2,4,9,18,36,72/ + data npr/ & + 0,0,0,0,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0, & + 0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,0,0, & + 1,0,0,1,0,0,1,1,1,1,1,0,0,0,1,0,1,0,0,0,1,1,1,1,0,1,1,0,0,1, & + 0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1,0,1,0,1, & + 0,1,1,1,0,0,1,0,1,1,0,1,1,1,1,0,0,0,0,1,1,0,1,1,0,0,0,1,1,1, & + 0,1,1,1,0,1,1,1,0,0,1,0,0,0,1,1,0,1,1,0,0,1,0,0,0,1,1,1,1,1, & + 1,0,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,1,0,1,1,1,1,0,1,0,1/ +end module jt4 diff --git a/lib/jt4_decode.f90 b/lib/jt4_decode.f90 new file mode 100644 index 00000000..3540b0c1 --- /dev/null +++ b/lib/jt4_decode.f90 @@ -0,0 +1,420 @@ +module jt4_decode + type :: jt4_decoder + procedure(jt4_decode_callback), pointer :: decode_callback => null () + procedure(jt4_average_callback), pointer :: average_callback => null () + contains + procedure :: decode + procedure, private :: wsjt4, avg4 + end type jt4_decoder + +! Callback function to be called with each decode + abstract interface + subroutine jt4_decode_callback (this, snr, dt, freq, have_sync, & + sync, is_deep, decoded, qual, ich, is_average, ave) + import jt4_decoder + implicit none + class(jt4_decoder), intent(inout) :: this + integer, intent(in) :: snr + real, intent(in) :: dt + integer, intent(in) :: freq + logical, intent(in) :: have_sync + logical, intent(in) :: is_deep + character(len=1), intent(in) :: sync + character(len=22), intent(in) :: decoded + real, intent(in) :: qual + integer, intent(in) :: ich + logical, intent(in) :: is_average + integer, intent(in) :: ave + end subroutine jt4_decode_callback + end interface + +! Callback function to be called with each average result + abstract interface + subroutine jt4_average_callback (this, used, utc, sync, dt, freq, flip) + import jt4_decoder + implicit none + class(jt4_decoder), intent(inout) :: this + logical, intent(in) :: used + integer, intent(in) :: utc + real, intent(in) :: sync + real, intent(in) :: dt + integer, intent(in) :: freq + logical, intent(in) :: flip + end subroutine jt4_average_callback + end interface + +contains + + subroutine decode(this,decode_callback,dd,jz,nutc,nfqso,ntol0,emedelay, & + dttol,nagain,ndepth,nclearave,minsync,minw,nsubmode,mycall,hiscall, & + hisgrid,nlist0,listutc0,average_callback) + + use jt4 + use timer_module, only: timer + + class(jt4_decoder), intent(inout) :: this + procedure(jt4_decode_callback) :: decode_callback + integer, intent(in) :: jz,nutc,nfqso,ntol0,ndepth,minsync,minw,nsubmode, & + nlist0,listutc0(10) + real, intent(in) :: dd(jz),emedelay,dttol + logical, intent(in) :: nagain, nclearave + character(len=12), intent(in) :: mycall,hiscall + character(len=6), intent(in) :: hisgrid + procedure(jt4_average_callback), optional :: average_callback + + real*4 dat(30*11025) + character*6 cfile6 + + this%decode_callback => decode_callback + if (present (average_callback)) then + this%average_callback => average_callback + end if + mode4=nch(nsubmode+1) + ntol=ntol0 + neme=0 + lumsg=6 !### temp ? ### + ndiag=1 + nlist=nlist0 + listutc=listutc0 + + ! Lowpass filter and decimate by 2 + call timer('lpf1 ',0) + call lpf1(dd,jz,dat,jz2) + call timer('lpf1 ',1) + + write(cfile6(1:4),1000) nutc +1000 format(i4.4) + cfile6(5:6)=' ' + + call timer('wsjt4 ',0) + call this%wsjt4(dat,jz2,nutc,NClearAve,minsync,ntol,emedelay,dttol,mode4, & + minw,mycall,hiscall,hisgrid,nfqso,NAgain,ndepth,neme) + call timer('wsjt4 ',1) + + return + end subroutine decode + + subroutine wsjt4(this,dat,npts,nutc,NClearAve,minsync,ntol,emedelay,dttol, & + mode4,minw,mycall,hiscall,hisgrid,nfqso,NAgain,ndepth,neme) + +! Orchestrates the process of decoding JT4 messages. Note that JT4 +! always operates as if in "Single Decode" mode; it looks for only one +! decodable signal in the FTol range. + + use jt4 + use timer_module, only: timer + + class(jt4_decoder), intent(inout) :: this + integer, intent(in) :: npts,nutc,minsync,ntol,mode4,minw, & + nfqso,ndepth,neme + logical, intent(in) :: NAgain,NClearAve + character(len=12), intent(in) :: mycall,hiscall + character(len=6), intent(in) :: hisgrid + real, intent(in) :: dat(npts) !Raw data + + real ccfblue(-5:540) !CCF in time + real ccfred(-224:224) !CCF in frequency + real ps0(450) + +! real z(458,65) + logical first,prtavg + character decoded*22,special*5 + character*22 avemsg,deepmsg,deepave,blank,deepmsg0,deepave1 + character csync*1 + data first/.true./,nutc0/-999/,nfreq0/-999999/ + save + + if(first) then + nsave=0 + first=.false. + blank=' ' + ccfblue=0. + ccfred=0. +! Silence compiler warnings + if(dttol.eq.-99.0 .and. emedelay.eq.-99.0 .and. nagain) stop + endif + + zz=0. +! syncmin=3.0 + minsync + syncmin=1.0+minsync + naggressive=0 + if(ndepth.ge.2) naggressive=1 + nq1=3 + nq2=6 + if(naggressive.eq.1) nq1=1 + if(NClearAve) then + nsave=0 + iutc=-1 + nfsave=0. + listutc=0 + ppsave=0. + rsymbol=0. + dtsave=0. + syncsave=0. + nfanoave=0 + ndeepave=0 + endif + +! Attempt to synchronize: look for sync pattern, get DF and DT. + call timer('sync4 ',0) + mousedf=nint(nfqso + 1.5*4.375*mode4 - 1270.46) + call sync4(dat,npts,ntol,1,MouseDF,4,mode4,minw+1,dtx,dfx, & + snrx,snrsync,ccfblue,ccfred,flip,width,ps0) + sync=snrsync + dtxz=dtx-0.8 + nfreqz=dfx + 1270.46 - 1.5*4.375*mode4 + call timer('sync4 ',1) + + snrx=db(sync) - 26. + nsnr=nint(snrx) + if(sync.lt.syncmin) then + if (associated (this%decode_callback)) then + call this%decode_callback(nsnr,dtxz,nfreqz,.false.,csync, & + .false.,decoded,0.,ich,.false.,0) + end if + go to 990 + endif + +! We have achieved sync + decoded=blank + deepmsg=blank + special=' ' + nsync=sync + nsnrlim=-33 + csync='*' + if(flip.lt.0.0) csync='#' + qbest=0. + qabest=0. + prtavg=.false. + + do idt=-2,2 + dtx=dtxz + 0.03*idt + nfreq=nfreqz + 2*idf + +! Attempt a single-sequence decode, including deep4 if Fano fails. + call timer('decode4 ',0) + call decode4(dat,npts,dtx,nfreq,flip,mode4,ndepth,neme,minw, & + mycall,hiscall,hisgrid,decoded,nfano,deepmsg,qual,ich) + call timer('decode4 ',1) + + if(nfano.gt.0) then +! Fano succeeded: report the message and return !Fano OK + if (associated (this%decode_callback)) then + call this%decode_callback(nsnr,dtx,nfreq,.true.,csync, & + .false.,decoded,99.,ich,.false.,0) + end if + nsave=0 + go to 990 + + else !Fano failed + if(qual.gt.qbest) then + dtx0=dtx + nfreq0=nfreq + deepmsg0=deepmsg + ich0=ich + qbest=qual + endif + endif + + if(idt.ne.0) cycle +! Single-sequence Fano decode failed, so try for an average Fano decode: + qave=0. +! If we're doing averaging, call avg4 + if(iand(ndepth,16).eq.16 .and. (.not.prtavg)) then + if(nutc.ne.nutc0 .or. abs(nfreq-nfreq0).gt.ntol) then +! This is a new minute or a new frequency, so call avg4. + nutc0=nutc !Try decoding average + nfreq0=nfreq + nsave=nsave+1 + nsave=mod(nsave-1,64)+1 + call timer('avg4 ',0) + call this%avg4(nutc,sync,dtx,flip,nfreq,mode4,ntol,ndepth,neme, & + mycall,hiscall,hisgrid,nfanoave,avemsg,qave,deepave,ich, & + ndeepave) + call timer('avg4 ',1) + endif + + if(nfanoave.gt.0) then +! Fano succeeded: report the message AVG FANO OK + if (associated (this%decode_callback)) then + call this%decode_callback(nsnr,dtx,nfreq,.true.,csync, & + .false.,avemsg,99.,ich,.true.,nfanoave) + end if + prtavg=.true. + cycle + else + if(qave.gt.qabest) then + dtx1=dtx + nfreq1=nfreq + deepave1=deepave + ich1=ich + qabest=qave + endif + endif + endif + enddo + + dtx=dtx0 + nfreq=nfreq0 + deepmsg=deepmsg0 + ich=ich0 + qual=qbest + + if (associated (this%decode_callback)) then + if(int(qual).ge.nq1) then + call this%decode_callback(nsnr,dtx,nfreqz,.true.,csync,.true., & + deepmsg,qual,ich,.false.,0) + else + call this%decode_callback(nsnr,dtxz,nfreqz,.true.,csync, & + .false.,blank,0.,ich,.false.,0) + endif + end if + + dtx=dtx1 + nfreq=nfreq1 + deepave=deepave1 + ich=ich1 + qave=qabest + + if (associated (this%decode_callback) .and. ndeepave.ge.2) then + if(int(qave).ge.nq1) then + call this%decode_callback(nsnr,dtx,nfreq,.true.,csync,.true., & + deepave,qave,ich,.true.,ndeepave) + endif + end if + +990 return + end subroutine wsjt4 + + subroutine avg4(this,nutc,snrsync,dtxx,flip,nfreq,mode4,ntol,ndepth,neme, & + mycall,hiscall,hisgrid,nfanoave,avemsg,qave,deepave,ichbest,ndeepave) + +! Decodes averaged JT4 data + + use jt4 + class(jt4_decoder), intent(inout) :: this + + character*22 avemsg,deepave,deepbest + character mycall*12,hiscall*12,hisgrid*6 + character*1 csync,cused(64) + real sym(207,7) + integer iused(64) + logical first + data first/.true./ + save + + if(first) then + iutc=-1 + nfsave=0 + dtdiff=0.2 + first=.false. + endif + + do i=1,64 + if(nutc.eq.iutc(i) .and. abs(nfreq-nfsave(i)).le.ntol) go to 10 + enddo + +! Save data for message averaging + iutc(nsave)=nutc + syncsave(nsave)=snrsync + dtsave(nsave)=dtxx + nfsave(nsave)=nfreq + flipsave(nsave)=flip + ppsave(1:207,1:7,nsave)=rsymbol(1:207,1:7) + +10 sym=0. + syncsum=0. + dtsum=0. + nfsum=0 + nsum=0 + + do i=1,64 + cused(i)='.' + if(iutc(i).lt.0) cycle + if(mod(iutc(i),2).ne.mod(nutc,2)) cycle !Use only same sequence + if(abs(dtxx-dtsave(i)).gt.dtdiff) cycle !DT must match + if(abs(nfreq-nfsave(i)).gt.ntol) cycle !Freq must match + if(flip.ne.flipsave(i)) cycle !Sync (*/#) must match + sym(1:207,1:7)=sym(1:207,1:7) + ppsave(1:207,1:7,i) + syncsum=syncsum + syncsave(i) + dtsum=dtsum + dtsave(i) + nfsum=nfsum + nfsave(i) + cused(i)='$' + nsum=nsum+1 + iused(nsum)=i + enddo + if(nsum.lt.64) iused(nsum+1)=0 + + syncave=0. + dtave=0. + fave=0. + if(nsum.gt.0) then + sym=sym/nsum + syncave=syncsum/nsum + dtave=dtsum/nsum + fave=float(nfsum)/nsum + endif + + do i=1,nsave + csync='*' + if(flipsave(i).lt.0.0) csync='#' + if (associated (this%average_callback)) then + call this%average_callback(cused(i) .eq. '$',iutc(i), & + syncsave(i),dtsave(i),nfsave(i),flipsave(i).lt.0.) + end if + enddo + + sqt=0. + sqf=0. + do j=1,64 + i=iused(j) + if(i.eq.0) exit + csync='*' + if(flipsave(i).lt.0.0) csync='#' + sqt=sqt + (dtsave(i)-dtave)**2 + sqf=sqf + (nfsave(i)-fave)**2 + enddo + rmst=0. + rmsf=0. + if(nsum.ge.2) then + rmst=sqrt(sqt/(nsum-1)) + rmsf=sqrt(sqf/(nsum-1)) + endif + kbest=ich1 + do k=ich1,ich2 + call extract4(sym(1,k),ncount,avemsg) !Do the Fano decode + nfanoave=0 + if(ncount.ge.0) then + ichbest=k + nfanoave=nsum + go to 900 + endif + if(nch(k).ge.mode4) exit + enddo + + deepave=' ' + qave=0. + +! Possibly should pass nadd=nused, also ? + if(iand(ndepth,32).eq.32) then + flipx=1.0 !Normal flip not relevant for ave msg + qbest=0. + do k=ich1,ich2 + call deep4(sym(2,k),neme,flipx,mycall,hiscall,hisgrid,deepave,qave) + if(qave.gt.qbest) then + qbest=qave + deepbest=deepave + kbest=k + ndeepave=nsum + endif + if(nch(k).ge.mode4) exit + enddo + + deepave=deepbest + qave=qbest + ichbest=kbest + endif + +900 return + end subroutine avg4 +end module jt4_decode diff --git a/lib/jt4a.f90 b/lib/jt4a.f90 new file mode 100644 index 00000000..fc37ec05 --- /dev/null +++ b/lib/jt4a.f90 @@ -0,0 +1,2 @@ + ! The contents of this file have been migrated to lib/jt4_decode.f90 + diff --git a/lib/jt4code.f90 b/lib/jt4code.f90 new file mode 100644 index 00000000..e11f6144 --- /dev/null +++ b/lib/jt4code.f90 @@ -0,0 +1,50 @@ +program jt4code + +! Provides examples of message packing, bit and symbol ordering, +! convolutional encoding, and other necessary details of the JT4 +! protocol. + + use jt4 + use packjt + character*22 msg,decoded,bad*1,msgtype*13 + integer i4tone(206) + include 'testmsg.f90' + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: jt4code "message"' + print*,' jt4code -t' + go to 999 + endif + + call getarg(1,msg) + nmsg=1 + if(msg(1:2).eq."-t") nmsg=NTEST + + write(*,1010) +1010 format(" Message Decoded Err? Type"/ & + 74("-")) + do imsg=1,nmsg + if(nmsg.gt.1) msg=testmsg(imsg) + call fmtmsg(msg,iz) !To upper case, collapse multiple blanks + ichk=0 + call gen4(msg,ichk,decoded,i4tone,itype) + + msgtype="" + if(itype.eq.1) msgtype="Std Msg" + if(itype.eq.2) msgtype="Type 1 prefix" + if(itype.eq.3) msgtype="Type 1 suffix" + if(itype.eq.4) msgtype="Type 2 prefix" + if(itype.eq.5) msgtype="Type 2 suffix" + if(itype.eq.6) msgtype="Free text" + + bad=" " + if(decoded.ne.msg) bad="*" + write(*,1020) imsg,msg,decoded,bad,itype,msgtype +1020 format(i2,'.',2x,a22,2x,a22,3x,a1,i3,": ",a13) + enddo + + if(nmsg.eq.1) write(*,1030) i4tone +1030 format(/'Channel symbols'/(30i2)) + +999 end program jt4code diff --git a/lib/jt4sim.f90 b/lib/jt4sim.f90 new file mode 100644 index 00000000..73edabf7 --- /dev/null +++ b/lib/jt4sim.f90 @@ -0,0 +1,181 @@ +program jt4sim + +! Generate simulated jt4 data for testing the decoder using new fading models +! Based on qra64sim with appropriate changes for JT4 +! Includes option to generate 1000Hz single tone with "ST" as the message + + use wavhdr + use packjt + use jt4 + parameter (NMAX=60*12000) ! = 648,000 + parameter (NFFT=10*65536,NH=NFFT/2) + type(hdr) h !Header for .wav file + integer*2 iwave(NMAX) !Generated waveform + integer*4 itone(206) !Channel symbols (values 0-8) + real*4 xnoise(NMAX) !Generated random noise + real*4 dat(NMAX) !Generated real data + complex cdat(NMAX) !Generated complex waveform + complex cspread(0:NFFT-1) !Complex amplitude for Rayleigh fading + complex z + real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq + character message*22,fname*11,csubmode*1,arg*12 + character msgsent*22 + + nargs=iargc() + if(nargs.ne. 7) then + print *, 'Usage: jt4sim "msg" A-E Nsigs fDop DT Nfiles SNR' + print *, 'Example jt4sim "K1ABC W9XYZ EN37" A 10 0.2 0.0 1 0' + print *, 'Example jt4sim "ST" A 10 0.2 0.0 1 0' + go to 999 + endif + call getarg(1,message) + call fmtmsg(message, iz) + call getarg(2,csubmode) + mode4=ichar(csubmode) - ichar('A') + 1 + call getarg(3,arg) + read(arg,*) nsigs + call getarg(4,arg) + read(arg,*) fspread + call getarg(5,arg) + read(arg,*) xdt + call getarg(6,arg) + read(arg,*) nfiles + call getarg(7,arg) + read(arg,*) snrdb + + if(mode4.ge.8) nsigs=1 ! temporary - will need sorting out + rms=100. + fsample=12000.d0 !Sample rate (Hz) + dt=1.d0/fsample !Sample interval (s) + twopi=8.d0*atan(1.d0) + npts=60*12000 !Total samples in .wav file + nsps=12000.d0/4.375d0 + baud=12000.d0/nsps !Keying rate = 1.7361111111 + nsym=206 !Number of channel symbols + h=default_header(12000,npts) + dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz) + ichk=0 + + write(*,1000) +1000 format('File Sig Freq A-E S/N DT Dop Message'/60('-')) + + do ifile=1,nfiles !Loop over requested number of files + write(fname,1002) ifile !Output filename +1002 format('000000_',i4.4) + open(10,file=fname//'.wav',access='stream',status='unknown') + xnoise=0. + cdat=0. + if(snrdb.lt.90) then + do i=1,npts + xnoise(i)=gran() !Generate gaussian noise + enddo + endif + + do isig=1,nsigs !Generate requested number of sigs + if(mod(nsigs,2).eq.0) f0=1500.0 + dfsig*(isig-0.5-nsigs/2) + if(mod(nsigs,2).eq.1) f0=1500.0 + dfsig*(isig-(nsigs+1)/2) + if(nsigs.eq.1) f0=1000.0 + xsnr=snrdb + if(snrdb.eq.0.0) xsnr=-20 - isig + + call gen4(message,ichk,msgsent,itone,itype) + + bandwidth_ratio=2500.0/6000.0 + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*xsnr) + if(xsnr.gt.90.0) sig=1.0 + write(*,1020) ifile,isig,f0,csubmode,xsnr,xdt,fspread,message +1020 format(i4,i4,f10.3,2x,a1,2x,f5.1,f6.2,f6.1,1x,a22) + + phi=0.d0 + dphi=0.d0 + k=(xdt+1.0)*12000 !Start audio at t = xdt + 1.0 s + isym0=-99 + + do i=1,npts !Add this signal into cdat() + isym=i/nsps + 1 + if(isym.gt.nsym) exit + if(isym.ne.isym0) then + if(message(1:2).eq.'ST') then !Finds ST in message string for single tone + freq=1000 !1000Hz for single tone + else + freq=f0 + itone(isym)*baud*nch(mode4) + endif + dphi=twopi*freq*dt + isym0=isym + + endif + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + z=cmplx(cos(xphi),sin(xphi)) + k=k+1 + if(k.ge.1) cdat(k)=cdat(k) + sig*z + enddo + enddo + + if(fspread.ne.0) then !Apply specified Doppler spread + df=12000.0/nfft + twopi=8*atan(1.0) + cspread(0)=1.0 + cspread(NH)=0. + b=6.0 !Lorenzian 3/28 onward + do i=1,NH + f=i*df + x=b*f/fspread + z=0. + a=0. + if(x.lt.3.0) then !Cutoff beyond x=3 + a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian + call random_number(r1) + phi1=twopi*r1 + z=a*cmplx(cos(phi1),sin(phi1)) + endif + cspread(i)=z + z=0. + if(x.lt.50.0) then + call random_number(r2) + phi2=twopi*r2 + z=a*cmplx(cos(phi2),sin(phi2)) + endif + cspread(NFFT-i)=z + enddo + + do i=0,NFFT-1 + f=i*df + if(i.gt.NH) f=(i-nfft)*df + s=real(cspread(i))**2 + aimag(cspread(i))**2 +! write(13,3000) i,f,s,cspread(i) +!3000 format(i5,f10.3,3f12.6) + enddo +! s=real(cspread(0))**2 + aimag(cspread(0))**2 +! write(13,3000) 1024,0.0,s,cspread(0) + + call four2a(cspread,NFFT,1,1,1) !Transform to time domain + + sum=0. + do i=0,NFFT-1 + p=real(cspread(i))**2 + aimag(cspread(i))**2 + sum=sum+p + enddo + avep=sum/NFFT + fac=sqrt(1.0/avep) + cspread=fac*cspread !Normalize to constant avg power + cdat(1:NFFT)=cspread*cdat(1:NFFT) !Apply Rayleigh fading + +! do i=0,NFFT-1 +! p=real(cspread(i))**2 + aimag(cspread(i))**2 +! write(14,3010) i,p,cspread(i) +!3010 format(i8,3f12.6) +! enddo + + endif + + dat=aimag(cdat) + xnoise !Add the generated noise + fac=32767.0/nsigs + if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts)) + if(snrdb.lt.90.0) iwave(1:npts)=nint(rms*dat(1:npts)) + write(10) h,iwave(1:npts) !Save the .wav file + close(10) + enddo + +999 end program jt4sim diff --git a/lib/jt65.f90 b/lib/jt65.f90 index 10f7525a..9b99730f 100644 --- a/lib/jt65.f90 +++ b/lib/jt65.f90 @@ -1,68 +1,142 @@ -program jt65 - -! Test the JT65 decoder for WSJT-X - - parameter (NZMAX=60*12000) - integer*4 ihdr(11) - integer*2 id2(NZMAX) - real*4 dd(NZMAX) - character*80 infile - integer*2 nfmt2,nchan2,nbitsam2,nbytesam2 - character*4 ariff,awave,afmt,adata - common/hdr/ariff,lenfile,awave,afmt,lenfmt,nfmt2,nchan2, & - nsamrate,nbytesec,nbytesam2,nbitsam2,adata,ndata - common/tracer/limtrace,lu - equivalence (lenfile,ihdr(2)) - - nargs=iargc() - if(nargs.lt.1) then - print*,'Usage: jt65 file1 [file2 ...]' - go to 999 - endif - limtrace=0 - lu=12 - - newdat=1 - ntol=50 - nfa=2700 -! nfb=4000 - nfqso=933 - nagain=0 - - open(12,file='timer.out',status='unknown') - open(22,file='kvasd.dat',access='direct',recl=1024,status='unknown') - - call timer('jt65 ',0) - - do ifile=1,nargs - call getarg(ifile,infile) - open(10,file=infile,access='stream',status='old',err=998) - - call timer('read ',0) - read(10) ihdr - nutc=ihdr(1) !Silence compiler warning - i1=index(infile,'.wav') - read(infile(i1-4:i1-1),*,err=10) nutc - go to 20 -10 nutc=0 -20 npts=52*12000 - read(10) id2(1:npts) - call timer('read ',1) - dd(1:npts)=id2(1:npts) - dd(npts+1:)=0. - - call timer('jt65a ',0) - call jt65a(dd,npts,newdat,nutc,ntol,nfa,nfqso,nagain,ndecoded) - call timer('jt65a ',1) - enddo - - call timer('jt65 ',1) - call timer('jt65 ',101) - call four2a(a,-1,1,1,1) !Free the memory used for plans - call filbig(a,-1,1,0.0,0,0,0,0,0) ! (ditto) - go to 999 - -998 print*,'Cannot open file:' - print*,infile - -999 end program jt65 +program jt65 + + ! Test the JT65 decoder for WSJT-X + + use options + use timer_module, only: timer + use timer_impl, only: init_timer + use jt65_test + use readwav + + character c,mode + logical :: display_help=.false.,nrobust=.false.,single_decode=.false. + type(wav_header) :: wav + integer*2 id2(NZMAX) + real*4 dd(NZMAX) + character*80 infile + character(len=500) optarg + character*12 mycall,hiscall + character*6 hisgrid + + type (option) :: long_options(12) = [ & + option ('aggressive',.true.,'a','aggressiveness [0-10], default AGGR=0','AGGR'), & + option ('depth',.true.,'d','depth=5 hinted decoding, default DEPTH=0','DEPTH'), & + option ('freq',.true.,'f','signal frequency, default FREQ=1270','FREQ'), & + option ('help',.false.,'h','Display this help message',''), & + option ('mode',.true.,'m','Mode A, B, C. Default is A.','MODE'), & + option ('ntrials',.true.,'n','number of trials, default TRIALS=10000','TRIALS'), & + option ('robust-sync',.false.,'r','robust sync',''), & + option ('my-call',.true.,'c','my callsign',''), & + option ('his-call',.true.,'x','his callsign',''), & + option ('his-grid',.true.,'g','his grid locator',''), & + option ('experience-decoding',.true.,'X' & + ,'experience decoding options (1..n), default FLAGS=0','FLAGS'), & + option ('single-signal-mode',.false.,'s','decode at signal frequency only','') ] + + naggressive=0 + nfqso=1500 + ntrials=10000 + nexp_decode=0 + ntol=1000 + nsubmode=0 + nlow=200 + nhigh=4000 + n2pass=2 + ndepth=3 + + do + call getopt('a:d:f:hm:n:rc:x:g:X:s',long_options,c,optarg,narglen,nstat,noffset,nremain,.true.) + if( nstat .ne. 0 ) then + exit + end if + select case (c) + case ('a') + read (optarg(:narglen), *) naggressive + case ('d') + read (optarg(:narglen), *) ndepth + case ('f') + read (optarg(:narglen), *) nfqso + case ('h') + display_help = .true. + case ('m') + read (optarg(:narglen), *) mode + if( mode .eq. 'b' .or. mode .eq. 'B' ) then + nsubmode=1 + endif + if( mode .eq. 'c' .or. mode .eq. 'C' ) then + nsubmode=2 + endif + case ('n') + read (optarg(:narglen), *) ntrials + case ('r') + nrobust=.true. + case ('c') + read (optarg(:narglen), *) mycall + case ('x') + read (optarg(:narglen), *) hiscall + case ('g') + read (optarg(:narglen), *) hisgrid + case ('X') + read (optarg(:narglen), *) nexp_decode + case ('s') + single_decode=.true. + ntol=100 + nlow=nfqso-ntol + nhigh=nfqso+ntol + n2pass=1 + end select + end do + + if(single_decode) nexp_decode=ior(nexp_decode,32) + if(display_help .or. nstat.lt.0 .or. nremain.lt.1) then + print *, '' + print *, 'Usage: jt65 [OPTIONS] file1 [file2 ...]' + print *, '' + print *, ' JT65 decode pre-recorded .WAV file(s)' + print *, '' + print *, 'OPTIONS:' + print *, '' + do i = 1, size (long_options) + call long_options(i) % print (6) + end do + go to 999 + endif + + call init_timer ('timer.out') + call timer('jt65 ',0) + + ndecoded=0 + do ifile=noffset+1,noffset+nremain + nfa=nlow + nfb=nhigh + minsync=0 + call get_command_argument(ifile,optarg,narglen) + infile=optarg(:narglen) + call timer('read ',0) + call wav%read (infile) + i1=index(infile,'.wav') + if( i1 .eq. 0 ) i1=index(infile,'.WAV') + read(infile(i1-4:i1-1),*,err=998) nutc + npts=52*12000 + read(unit=wav%lun) id2(1:npts) + close(unit=wav%lun) + call timer('read ',1) + dd(1:npts)=id2(1:npts) + dd(npts+1:)=0. + call test(dd,nutc,nfa,nfb,nfqso,ntol,nsubmode, & + n2pass,nrobust,ntrials,naggressive,ndepth, & + mycall,hiscall,hisgrid,nexp_decode) + if(nft.gt.0) exit + enddo + + call timer('jt65 ',1) + call timer('jt65 ',101) + ! call four2a(a,-1,1,1,1) !Free the memory used for plans + ! call filbig(a,-1,1,0.0,0,0,0,0,0) ! (ditto) + go to 999 + +998 print*,'Cannot read from file:' + print*,infile + +999 continue +end program jt65 diff --git a/lib/jt65_decode.f90 b/lib/jt65_decode.f90 new file mode 100644 index 00000000..fe0a1ede --- /dev/null +++ b/lib/jt65_decode.f90 @@ -0,0 +1,494 @@ +module jt65_decode + + integer, parameter :: NSZ=3413, NZMAX=60*12000 + + type :: jt65_decoder + procedure(jt65_decode_callback), pointer :: callback => null() + contains + procedure :: decode + end type jt65_decoder + +! Callback function to be called with each decode + abstract interface + subroutine jt65_decode_callback(this,sync,snr,dt,freq,drift, & + nflip,width,decoded,ft,qual,nsmo,nsum,minsync) + + import jt65_decoder + implicit none + class(jt65_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + integer, intent(in) :: freq + integer, intent(in) :: drift + integer, intent(in) :: nflip + real, intent(in) :: width + character(len=22), intent(in) :: decoded + integer, intent(in) :: ft + integer, intent(in) :: qual + integer, intent(in) :: nsmo + integer, intent(in) :: nsum + integer, intent(in) :: minsync + + end subroutine jt65_decode_callback + end interface + +contains + + subroutine decode(this,callback,dd0,npts,newdat,nutc,nf1,nf2,nfqso, & + ntol,nsubmode,minsync,nagain,n2pass,nrobust,ntrials,naggressive, & + ndepth,emedelay,clearave,mycall,hiscall,hisgrid,nexp_decode) + +! Process dd0() data to find and decode JT65 signals. + + use jt65_mod + use timer_module, only: timer + + include 'constants.f90' + + class(jt65_decoder), intent(inout) :: this + procedure(jt65_decode_callback) :: callback + real, intent(in) :: dd0(NZMAX),emedelay + integer, intent(in) :: npts, nutc, nf1, nf2, nfqso, ntol & + , nsubmode, minsync, n2pass, ntrials, naggressive, ndepth & + , nexp_decode + logical, intent(in) :: newdat, nagain, nrobust, clearave + character(len=12), intent(in) :: mycall, hiscall + character(len=6), intent(in) :: hisgrid + + real dd(NZMAX) + real ss(322,NSZ) + real savg(NSZ) + real a(5) + character*22 decoded,decoded0,avemsg,deepave + type candidate + real freq + real dt + real sync + real flip + end type candidate + type(candidate) ca(300) + type accepted_decode + real freq + real dt + real sync + character*22 decoded + end type accepted_decode + type(accepted_decode) dec(50) + logical :: first_time,prtavg,single_decode,bVHF + + integer h0(0:11),d0(0:11) + real r0(0:11) + common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano + common/steve/thresh0 + +! 0 1 2 3 4 5 6 7 8 9 10 11 + data h0/41,42,43,43,44,45,46,47,48,48,49,49/ + data d0/71,72,73,74,76,77,78,80,81,82,83,83/ + +! 0 1 2 3 4 5 6 7 8 9 10 11 + data r0/0.70,0.72,0.74,0.76,0.78,0.80,0.82,0.84,0.86,0.88,0.90,0.90/ + data nutc0/-999/,nfreq0/-999/,nsave/0/ + save + + this%callback => callback + first_time=newdat + dd=dd0 + ndecoded=0 + + if(nsubmode.ge.100) then +! This is QRA64 mode + mode64=2**(nsubmode-100) +!### +! open(60,file='qra64_data.bin',access='stream',position='append') +! write(60) dd,npts,nutc,nf1,nf2,nfqso,ntol,mode64,minsync,ndepth, & +! mycall,hiscall,hisgrid +! close(60) +!### + call qra64a(dd,npts,nutc,nf1,nf2,nfqso,ntol,mode64,minsync,ndepth, & + emedelay,mycall,hiscall,hisgrid,sync,nsnr,dtx,nfreq,decoded,nft) + if (associated(this%callback)) then + ndrift=0 + nflip=1 + width=1.0 + nsmo=0 + nqual=0 + call this%callback(sync,nsnr,dtx,nfreq,ndrift, & + nflip,width,decoded,nft,nqual,nsmo,1,minsync) + end if + go to 900 + endif + + do ipass=1,n2pass !Two-pass decoding loop + first_time=.true. + if(ipass.eq.1) then !First-pass parameters + thresh0=2.5 + nsubtract=1 + elseif( ipass.eq.2 ) then !Second-pass parameters + thresh0=2.5 + nsubtract=0 + endif + if(n2pass.lt.2) nsubtract=0 + + ! if(newdat) then + call timer('symsp65 ',0) + ss=0. + call symspec65(dd,npts,ss,nhsym,savg) !Get normalized symbol spectra + call timer('symsp65 ',1) + ! endif + nfa=nf1 + nfb=nf2 + single_decode=iand(nexp_decode,32).ne.0 .or. nagain + bVHF=iand(nexp_decode,64).ne.0 + +!### Q: should either of the next two uses of "single_decode" be "bVHF" instead? + if(single_decode .or. (bVHF .and. ntol.lt.1000)) then + nfa=max(200,nfqso-ntol) + nfb=min(4000,nfqso+ntol) + thresh0=1.0 + endif + df=12000.0/8192.0 !df = 1.465 Hz + if(bVHF) then + ia=max(1,nint(nfa/df)-ntol) + ib=min(NSZ,nint(nfb/df)+ntol) + nz=ib-ia+1 + call lorentzian(savg(ia),nz,a) + baseline=a(1) + amp=a(2) + f0=(a(3)+ia-1)*df + width=a(4)*df + endif + + ncand=0 + call timer('sync65 ',0) + call sync65(ss,nfa,nfb,naggressive,ntol,nhsym,ca,ncand,0,bVHF) + call timer('sync65 ',1) + +! If a candidate was found within +/- ntol of nfqso, move it into ca(1). + call fqso_first(nfqso,ntol,ca,ncand) + if(single_decode) then + if(ncand.eq.0) ncand=1 + if(abs(ca(1)%freq - f0).gt.width) width=2*df !### ??? ### + endif + nvec=ntrials + if(ncand.gt.75) then + nvec=100 + endif + + mode65=2**nsubmode + nflip=1 + nqd=0 + decoded=' ' + decoded0="" + freq0=0. + prtavg=.false. + if(.not.nagain) nsum=0 + if(clearave) then + nsum=0 + nsave=0 + endif + + if(bVHF) then +! Be sure to search for shorthand message at nfqso +/- ntol + if(ncand.lt.300) ncand=ncand+1 + ca(ncand)%sync=5.0 + ca(ncand)%dt=2.5 + ca(ncand)%freq=nfqso + endif + + do icand=1,ncand + sync1=ca(icand)%sync + dtx=ca(icand)%dt + freq=ca(icand)%freq + if(bVHF) then + flip=ca(icand)%flip + nflip=flip + endif + if(sync1.lt.float(minsync)) nflip=0 + if(ipass.eq.1) ntry65a=ntry65a + 1 + if(ipass.eq.2) ntry65b=ntry65b + 1 + call timer('decod65a',0) + nft=0 + nspecial=0 + call decode65a(dd,npts,first_time,nqd,freq,nflip,mode65,nvec, & + naggressive,ndepth,ntol,mycall,hiscall,hisgrid, & + nexp_decode,bVHF,sync2,a,dtx,nft,nspecial,qual, & + nhist,nsmo,decoded) + if(nspecial.eq.2) decoded='RO' + if(nspecial.eq.3) decoded='RRR' + if(nspecial.eq.4) decoded='73' + call timer('decod65a',1) + if(sync1.lt.float(minsync) .and. & + decoded.eq.' ') nflip=0 + if(nft.ne.0) nsum=1 + + nhard_min=param(1) + nrtt1000=param(4) + ntotal_min=param(5) + nsmo=param(9) + + nfreq=nint(freq+a(1)) + ndrift=nint(2.0*a(2)) + if(bVHF) then + s2db=sync1 - 30.0 + db(width/3.3) !### VHF/UHF/microwave + if(nspecial.gt.0) s2db=sync2 + else + s2db=10.0*log10(sync2) - 35 !### Empirical (HF) + endif + nsnr=nint(s2db) + if(nsnr.lt.-30) nsnr=-30 + if(nsnr.gt.-1) nsnr=-1 + nftt=0 + + if(nft.ne.1 .and. iand(ndepth,16).eq.16 .and. (.not.prtavg)) then +! Single-sequence FT decode failed, so try for an average FT decode. + if(nutc.ne.nutc0 .or. abs(nfreq-nfreq0).gt.ntol) then +! This is a new minute or a new frequency, so call avg65. + nutc0=nutc + nfreq0=nfreq + nsave=nsave+1 + nsave=mod(nsave-1,64)+1 + call avg65(nutc,nsave,sync1,dtx,nflip,nfreq,mode65,ntol, & + ndepth,nagain,ntrials,naggressive,clearave,neme,mycall, & + hiscall,hisgrid,nftt,avemsg,qave,deepave,nsum,ndeepave) + nsmo=param(9) + nqave=qave + + if (associated(this%callback) .and. nsum.ge.2) then + call this%callback(sync1,nsnr,dtx-1.0,nfreq,ndrift, & + nflip,width,avemsg,nftt,nqave,nsmo,nsum,minsync) + prtavg=.true. + end if + + endif + endif + + if(nftt.eq.1) then +! nft=1 + decoded=avemsg + go to 5 + endif + n=naggressive + rtt=0.001*nrtt1000 + if(nft.lt.2 .and. minsync.ge.0 .and. nspecial.eq.0) then + if(nhard_min.gt.50) cycle + if(nhard_min.gt.h0(n)) cycle + if(ntotal_min.gt.d0(n)) cycle + if(rtt.gt.r0(n)) cycle + endif + +5 continue + if(decoded.eq.decoded0 .and. abs(freq-freq0).lt. 3.0 .and. & + minsync.ge.0) cycle !Don't display dupes + if(decoded.ne.' ' .or. minsync.lt.0) then + if(nsubtract.eq.1) then + call timer('subtr65 ',0) + call subtract65(dd,npts,freq,dtx) + call timer('subtr65 ',1) + endif + + ndupe=0 ! de-dedupe + do i=1, ndecoded + if(decoded==dec(i)%decoded) then + ndupe=1 + exit + endif + enddo + if(ndupe.ne.1 .and. sync1.ge.float(minsync)) then + if(ipass.eq.1) n65a=n65a + 1 + if(ipass.eq.2) n65b=n65b + 1 + if(ndecoded.lt.50) ndecoded=ndecoded+1 + dec(ndecoded)%freq=freq+a(1) + dec(ndecoded)%dt=dtx + dec(ndecoded)%sync=sync2 + dec(ndecoded)%decoded=decoded + nqual=min(qual,9999.0) + + if (associated(this%callback)) then + call this%callback(sync1,nsnr,dtx-1.0,nfreq,ndrift, & + nflip,width,decoded,nft,nqual,nsmo,1,minsync) + end if + endif + decoded0=decoded + freq0=freq + if(decoded0.eq.' ') decoded0='*' + endif + enddo !Candidate loop + if(ndecoded.lt.1) exit + enddo !Two-pass loop + +900 return + end subroutine decode + + subroutine avg65(nutc,nsave,snrsync,dtxx,nflip,nfreq,mode65,ntol,ndepth, & + nagain, ntrials,naggressive,clearave,neme,mycall,hiscall,hisgrid,nftt, & + avemsg,qave,deepave,nsum,ndeepave) + +! Decodes averaged JT65 data + + use jt65_mod + parameter (MAXAVE=64) + character*22 avemsg,deepave,deepbest + character mycall*12,hiscall*12,hisgrid*6 + character*1 csync,cused(64) + logical nagain + integer iused(64) +! Accumulated data for message averaging + integer iutc(MAXAVE) + integer nfsave(MAXAVE) + integer nflipsave(MAXAVE) + real s1b(-255:256,126) + real s1save(-255:256,126,MAXAVE) + real s2(66,126) + real s3save(64,63,MAXAVE) + real s3b(64,63) + real s3c(64,63) + real dtsave(MAXAVE) + real syncsave(MAXAVE) + logical first,clearave + data first/.true./ + save + + if(first .or. clearave) then + iutc=-1 + nfsave=0 + dtdiff=0.2 + first=.false. + s3save=0. + s1save=0. + nsave=1 !### ??? +! Silence compiler warnings + if(nagain .and. ndeepave.eq.-99 .and. neme.eq.-99) stop + endif + + do i=1,64 + if(iutc(i).lt.0) exit + if(nutc.eq.iutc(i) .and. abs(nfreq-nfsave(i)).le.ntol) go to 10 + enddo + +! Save data for message averaging + iutc(nsave)=nutc + syncsave(nsave)=snrsync + dtsave(nsave)=dtxx + nfsave(nsave)=nfreq + nflipsave(nsave)=nflip + s1save(-255:256,1:126,nsave)=s1 + s3save(1:64,1:63,nsave)=s3a + +10 syncsum=0. + dtsum=0. + nfsum=0 + nsum=0 + s1b=0. + s3b=0. + s3c=0. + + do i=1,MAXAVE !Consider all saved spectra + cused(i)='.' + if(iutc(i).lt.0) cycle + if(mod(iutc(i),2).ne.mod(nutc,2)) cycle !Use only same (odd/even) seq + if(abs(dtxx-dtsave(i)).gt.dtdiff) cycle !DT must match + if(abs(nfreq-nfsave(i)).gt.ntol) cycle !Freq must match + if(nflip.ne.nflipsave(i)) cycle !Sync type (*/#) must match + s3b=s3b + s3save(1:64,1:63,i) + s1b=s1b + s1save(-255:256,1:126,i) + syncsum=syncsum + syncsave(i) + dtsum=dtsum + dtsave(i) + nfsum=nfsum + nfsave(i) + cused(i)='$' + nsum=nsum+1 + iused(nsum)=i + enddo + if(nsum.lt.64) iused(nsum+1)=0 + + syncave=0. + dtave=0. + fave=0. + if(nsum.gt.0) then + syncave=syncsum/nsum + dtave=dtsum/nsum + fave=float(nfsum)/nsum + endif + + do i=1,nsave + csync='*' + if(nflipsave(i).lt.0.0) csync='#' + write(14,1000) cused(i),iutc(i),syncsave(i),dtsave(i)-1.0,nfsave(i),csync +1000 format(a1,i5.4,f6.1,f6.2,i6,1x,a1) + enddo + if(nsum.lt.2) go to 900 + + nftt=0 + df=1378.125/512.0 + +! Do the smoothing loop + qualbest=0. + minsmo=0 + maxsmo=0 + if(mode65.ge.2) then + minsmo=nint(width/df) + maxsmo=2*minsmo + endif + nn=0 + do ismo=minsmo,maxsmo + if(ismo.gt.0) then + do j=1,126 + call smo121(s1b(-255,j),512) + if(j.eq.1) nn=nn+1 + if(nn.ge.4) then + call smo121(s1b(-255,j),512) + if(j.eq.1) nn=nn+1 + endif + enddo + endif + + do i=1,66 + jj=i + if(mode65.eq.2) jj=2*i-1 + if(mode65.eq.4) then + ff=4*(i-1)*df - 355.297852 + jj=nint(ff/df)+1 + endif + s2(i,1:126)=s1b(jj,1:126) + enddo + + do j=1,63 + k=mdat(j) !Points to data symbol + if(nflip.lt.0) k=mdat2(j) + do i=1,64 + s3c(i,j)=4.e-5*s2(i+2,k) + enddo + enddo + + nadd=nsum*ismo + call extract(s3c,nadd,mode65,ntrials,naggressive,ndepth,nflip,mycall, & + hiscall,hisgrid,nexp_decode,ncount,nhist,avemsg,ltext,nftt,qual) + if(nftt.eq.1) then + nsmo=ismo + param(9)=nsmo + go to 900 + else if(nftt.eq.2) then + if(qual.gt.qualbest) then + deepbest=avemsg + qualbest=qual + nnbest=nn + nsmobest=ismo + nfttbest=nftt + endif + endif + enddo + + if(nfttbest.eq.2) then + avemsg=deepbest !### ??? + deepave=deepbest + qave=qualbest + nsmo=nsmobest + param(9)=nsmo + nftt=nfttbest + endif +900 continue + + return + end subroutine avg65 + +end module jt65_decode diff --git a/lib/jt65_mod.f90 b/lib/jt65_mod.f90 new file mode 100644 index 00000000..9bf9e261 --- /dev/null +++ b/lib/jt65_mod.f90 @@ -0,0 +1,13 @@ +module jt65_mod + + integer param(0:9) + integer mrs(63) + integer mrs2(63) + integer mdat(126),mref(126,2),mdat2(126),mref2(126,2) !From prcom + + real s1(-255:256,126) + real s3a(64,63) + real pr(126) + real width + +end module jt65_mod diff --git a/lib/jt65_test.f90 b/lib/jt65_test.f90 new file mode 100644 index 00000000..e1eac4de --- /dev/null +++ b/lib/jt65_test.f90 @@ -0,0 +1,81 @@ +module jt65_test + + ! Test the JT65 decoder for WSJT-X + + implicit none + + public :: test + integer, parameter, public :: NZMAX=60*12000 + integer, public :: nft + +contains + + subroutine test (dd,nutc,nflow,nfhigh,nfqso,ntol,nsubmode,n2pass,nrobust & + ,ntrials,naggressive,ndepth,mycall,hiscall,hisgrid,nexp_decode) + use timer_module, only: timer + use jt65_decode + implicit none + + include 'constants.f90' + real, intent(in) :: dd(NZMAX) + integer, intent(in) :: nutc, nflow, nfhigh, nfqso, ntol, nsubmode, n2pass & + , ntrials, naggressive, ndepth, nexp_decode + logical, intent(in) :: nrobust + character(len=12), intent(in) :: mycall, hiscall + character(len=6), intent(in) :: hisgrid + type(jt65_decoder) :: my_decoder + logical nclearave !### Should be a dummy arg? + nclearave=.false. + + call timer('jt65a ',0) + call my_decoder%decode(my_callback,dd,npts=52*12000,newdat=.true., & + nutc=nutc,nf1=nflow,nf2=nfhigh,nfqso=nfqso,ntol=ntol, & + nsubmode=nsubmode, minsync=-1,nagain=.false.,n2pass=n2pass, & + nrobust=nrobust,ntrials=ntrials,naggressive=naggressive, & + ndepth=ndepth,emedelay=0.0,clearave=nclearave,mycall=mycall, & + hiscall=hiscall,hisgrid=hisgrid,nexp_decode=nexp_decode) + call timer('jt65a ',1) + end subroutine test + + subroutine my_callback (this,sync,snr,dt,freq,drift,nflip,width, & + decoded,ft,qual,smo,sum,minsync) + use jt65_decode + implicit none + + class(jt65_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + integer, intent(in) :: freq + integer, intent(in) :: drift + integer, intent(in) :: nflip + real, intent(in) :: width + character(len=22), intent(in) :: decoded + integer, intent(in) :: ft + integer, intent(in) :: qual + integer, intent(in) :: smo + integer, intent(in) :: sum + integer, intent(in) :: minsync + + integer nwidth + real t + + if(minsync+nflip+qual.eq.-9999) stop !Silence compiler warning + t=max(0.0,width*width-7.2) + nwidth=max(nint(sqrt(t)),2) +!### deal with nflip here! ### +!### also single_decode, csync, etc... ### + write(*,1010) snr,dt,freq,decoded +1010 format(i4,f5.1,i5,1x,'#',1x,a22) + write(13,1012) nint(sync),snr,dt,freq,drift,nwidth, & + decoded,ft,sum,smo +1012 format(i4,i5,f6.2,i5,i4,i3,1x,a22,' JT65',3i3) + nft=ft + call flush(6) +! write(79,3001) sync,snr,dt,freq,candidates, & +! hard_min,total_min,rtt,tries,ft,qual,decoded +!3001 format(f5.1,i4,f5.1,i5,i6,i3,i4,f6.3,i8,i2,i3,1x,a22) + + end subroutine my_callback + +end module jt65_test diff --git a/lib/jt65a.f90 b/lib/jt65a.f90 deleted file mode 100644 index a1578fa9..00000000 --- a/lib/jt65a.f90 +++ /dev/null @@ -1,105 +0,0 @@ -subroutine jt65a(dd0,npts,newdat,nutc,nf1,nf2,nfqso,ntol,nagain,ndecoded) - -! Process dd() data to find and decode JT65 signals. - - parameter (NSZ=3413) - parameter (NZMAX=60*12000) - parameter (NFFT=8192) - real dd0(NZMAX) - real dd(NZMAX) - real*4 ss(322,NSZ) - real*4 savg(NSZ) - logical done(NSZ) - real a(5) - character decoded*22 - common/decstats/num65,numbm,numkv,num9,numfano - save - - dd=0. - tskip=2.0 - nskip=12000*tskip - dd(1+nskip:npts+nskip)=dd0(1:npts) - npts=npts+nskip - - if(newdat.ne.0) then - call timer('symsp65 ',0) - call symspec65(dd,npts,ss,nhsym,savg) !Get normalized symbol spectra - call timer('symsp65 ',1) - endif - - df=12000.0/NFFT !df = 12000.0/16384 = 0.732 Hz - ftol=16.0 !Frequency tolerance (Hz) - mode65=1 !Decoding JT65A only, for now. - done=.false. - freq0=-999. - - do nqd=1,0,-1 - if(nqd.eq.1) then !Quick decode, at fQSO - fa=nfqso - ntol - fb=nfqso + ntol - else !Wideband decode at all freqs - fa=nf1 - fb=nf2 - endif - ia=max(51,nint(fa/df)) - ib=min(NSZ-51,nint(fb/df)) - - thresh0=1.5 - - do i=ia,ib !Search over freq range - freq=i*df - if(savg(i).lt.thresh0 .or. done(i)) cycle - - call timer('ccf65 ',0) - call ccf65(ss(1,i),nhsym,savg(i),sync1,dt,flipk,syncshort,snr2,dt2) - call timer('ccf65 ',1) - - ftest=abs(freq-freq0) - thresh1=1.0 - if(nqd.eq.1 .and. ntol.le.100) thresh1=0. - if(sync1.lt.thresh1 .or. ftest.lt.ftol) cycle - - nflip=nint(flipk) - call timer('decod65a',0) - call decode65a(dd,npts,newdat,nqd,freq,nflip,mode65,sync2,a,dt, & - nbmkv,nhist,decoded) - call timer('decod65a',1) - - ftest=abs(freq+a(1)-freq0) - if(ftest.lt.ftol) cycle - - if(decoded.ne.' ') then - ndecoded=1 - nfreq=nint(freq+a(1)) - ndrift=nint(2.0*a(2)) - s2db=10.0*log10(sync2) - 32 !### empirical (was 40) ### - nsnr=nint(s2db) - if(nsnr.lt.-30) nsnr=-30 - if(nsnr.gt.-1) nsnr=-1 - dt=dt-tskip - if(nbmkv.eq.1) numbm=numbm+1 - if(nbmkv.eq.2) numkv=numkv+1 - -! Serialize writes - see also decjt9.f90 - - !$omp critical(decode_results) - - write(*,1010) nutc,nsnr,dt,nfreq,decoded -1010 format(i4.4,i4,f5.1,i5,1x,'#',1x,a22) - write(13,1012) nutc,nint(sync1),nsnr,dt,float(nfreq),ndrift, & - decoded,nbmkv -1012 format(i4.4,i4,i5,f6.1,f8.0,i4,3x,a22,' JT65',i4) - call flush(6) - call flush(13) - !$omp end critical(decode_results) - - freq0=freq+a(1) - i2=min(NSZ,i+15) !### ??? ### - done(i:i2)=.true. - endif - enddo - if(nagain.eq.1) exit - enddo - - return -end subroutine jt65a diff --git a/lib/jt65code.f90 b/lib/jt65code.f90 index 9d528907..4f2a4e03 100644 --- a/lib/jt65code.f90 +++ b/lib/jt65code.f90 @@ -1,104 +1,101 @@ -program JT65code - -! Provides examples of message packing, bit and symbol ordering, -! Reed Solomon encoding, and other necessary details of the JT65 -! protocol. - - character*22 testmsg(26) - character*22 msg,msg0,msg1,decoded,cok*3,bad*1,msgtype*10 - integer dgen(12),sent(63),recd(12),era(51) - - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: jt65code "message"' - print*,' jt65code -t' - go to 999 - endif - - call getarg(1,msg) !Get message from command line - nmsg=1 - if(msg(1:2).eq."-t") then - testmsg(1)="KA1ABC WB9XYZ EN34" - testmsg(2)="KA1ABC WB9XYZ EN34 OOO" - testmsg(3)="KA1ABC WB9XYZ RO" - testmsg(4)="KA1ABC WB9XYZ -21" - testmsg(5)="KA1ABC WB9XYZ R-19" - testmsg(6)="KA1ABC WB9XYZ RRR" - testmsg(7)="KA1ABC WB9XYZ 73" - testmsg(8)="KA1ABC WB9XYZ" - testmsg(9)="KA1ABC WB9XYZ OOO" - testmsg(10)="KA1ABC WB9XYZ RO" - testmsg(11)="ZL/KA1ABC WB9XYZ" - testmsg(12)="KA1ABC ZL/WB9XYZ" - testmsg(13)="KA1ABC/4 WB9XYZ" - testmsg(14)="KA1ABC WB9XYZ/4" - testmsg(15)="CQ ZL4/KA1ABC" - testmsg(16)="DE ZL4/KA1ABC" - testmsg(17)="QRZ ZL4/KA1ABC" - testmsg(18)="CQ WB9XYZ/VE4" - testmsg(19)="HELLO WORLD" - testmsg(20)="ZL4/KA1ABC 73" - testmsg(21)="RO" - testmsg(22)="RRR" - testmsg(23)="73" - testmsg(24)="KA1ABC XL/WB9XYZ" - testmsg(25)="KA1ABC WB9XYZ/W4" - testmsg(26)="123456789ABCDEFGH" - nmsg=26 - endif - - write(*,1010) -1010 format("Message Decoded Err?"/ & - "-----------------------------------------------------------------") - - do imsg=1,nmsg - if(nmsg.gt.1) msg=testmsg(imsg) - - call fmtmsg(msg,iz) !To upper, collapse mult blanks - msg0=msg !Input message - call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report - msg1=msg !Message without "OOO" - - if(nspecial.gt.0) then !or is a shorthand message - if(nspecial.eq.2) decoded="RO" - if(nspecial.eq.3) decoded="RRR" - if(nspecial.eq.4) decoded="73" - itype=-1 - msgtype="Shorthand" - go to 10 - endif - - call packmsg(msg1,dgen,itype) !Pack message into 12 six-bit bytes - msgtype="" - if(itype.eq.1) msgtype="Std Msg" - if(itype.eq.2) msgtype="Type 1 pfx" - if(itype.eq.3) msgtype="Type 1 sfx" - if(itype.eq.4) msgtype="Type 2 pfx" - if(itype.eq.5) msgtype="Type 2 sfx" - if(itype.eq.6) msgtype="Free text" - - call rs_encode(dgen,sent) !RS encode - call interleave63(sent,1) !Interleave channel symbols - call graycode(sent,63,1,sent) !Apply Gray code - call graycode(sent,63,-1,sent) - call interleave63(sent,-1) - call rs_decode(sent,era,0,recd,nerr) - call unpackmsg(recd,decoded) !Unpack the user message - if(cok.eq."OOO") decoded(20:22)=cok - call fmtmsg(decoded,iz) - -10 bad=" " - if(decoded.ne.msg0) bad="*" - write(*,1020) msg0,decoded,bad,itype,msgtype -1020 format(a22,2x,a22,3x,a1,i3,": ",a10) - enddo - - if(nmsg.eq.1 .and. nspecial.eq.0) then - write(*,1030) dgen -1030 format(/'Packed message, 6-bit symbols ',12i3) !Display packed symbols - - write(*,1040) sent -1040 format(/'Information-carrying channel symbols'/(i5,20i3)) - endif - -999 end program JT65code +program JT65code + +! Provides examples of message packing, bit and symbol ordering, +! Reed Solomon encoding, and other necessary details of the JT65 +! protocol. + + use packjt + character*22 msg,msgchk,msg0,msg1,decoded,cok*3,bad*1,msgtype*10,expected + integer dgen(12),sent(63),tmp(63),recd(12),era(51) + include 'testmsg.f90' + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: jt65code "message"' + print*,' jt65code -t' + go to 999 + endif + + call getarg(1,msg) !Get message from command line + msgchk=msg + call fmtmsg(msgchk,iz) + nmsg=1 + if(msg(1:2).eq."-t") then + if (NTEST+5 > MAXTEST) then + write(*,*) "NTEST exceed MAXTEST" + endif + testmsg(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" + testmsg(NTEST+2)="KA1ABC WB9XYZ OOO" + testmsg(NTEST+3)="RO" + testmsg(NTEST+4)="RRR" + testmsg(NTEST+5)="73" + testmsgchk(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" + testmsgchk(NTEST+2)="KA1ABC WB9XYZ OOO" + testmsgchk(NTEST+3)="RO" + testmsgchk(NTEST+4)="RRR" + testmsgchk(NTEST+5)="73" + nmsg=NTEST+5 + endif + + write(*,1010) +1010 format(" Message Decoded Err? Type Expected"/ & + 76("-")) + + do imsg=1,nmsg + if(nmsg.gt.1) then + msg=testmsg(imsg) + msgchk=testmsgchk(imsg) + endif + + call fmtmsg(msg,iz) !To upper, collapse mult blanks + msg0=msg !Input message + call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report + msg1=msg !Message without "OOO" + + if(nspecial.gt.0) then !or is a shorthand message + if(nspecial.eq.2) decoded="RO" + if(nspecial.eq.3) decoded="RRR" + if(nspecial.eq.4) decoded="73" + itype=-1 + msgtype="Shorthand" + go to 10 + endif + + call packmsg(msg1,dgen,itype,.false.) !Pack message into 12 six-bit bytes + msgtype="" + if(itype.eq.1) msgtype="Std Msg" + if(itype.eq.2) msgtype="Type 1 pfx" + if(itype.eq.3) msgtype="Type 1 sfx" + if(itype.eq.4) msgtype="Type 2 pfx" + if(itype.eq.5) msgtype="Type 2 sfx" + if(itype.eq.6) msgtype="Free text" + + call rs_encode(dgen,sent) !RS encode + call interleave63(sent,1) !Interleave channel symbols + call graycode(sent,63,1,sent) !Apply Gray code + + call graycode(sent,63,-1,tmp) !Remove Gray code + call interleave63(tmp,-1) !Remove interleaving + call rs_decode(tmp,era,0,recd,nerr) !Decode the message + call unpackmsg(recd,decoded,.false.,' ') !Unpack the user message + if(cok.eq."OOO") decoded(20:22)=cok + call fmtmsg(decoded,iz) + +10 bad=" " + if(decoded.ne.msgchk) bad="*" + expected = 'EXACT' + if (msg0.ne.msgchk) expected = 'TRUNCATED' + if (nmsg.eq.1) expected = 'UNKNOWN' + write(*,1020) imsg,msg0,decoded,bad,itype,msgtype,expected +1020 format(i2,'.',1x,a22,1x,a22,1x,a1,i3,":",a10,2x,a22) + enddo + + if(nmsg.eq.1 .and. nspecial.eq.0) then + write(*,1030) dgen +1030 format(/'Packed message, 6-bit symbols ',12i3) !Display packed symbols + + write(*,1040) sent +1040 format(/'Information-carrying channel symbols'/(i5,20i3)) + endif + +999 end program JT65code diff --git a/lib/jt65sim.f90 b/lib/jt65sim.f90 new file mode 100644 index 00000000..5f0a384f --- /dev/null +++ b/lib/jt65sim.f90 @@ -0,0 +1,271 @@ +program jt65sim + +! Generate simulated JT65 data for testing WSJT-X + + use wavhdr + use packjt + use options + parameter (NMAX=54*12000) ! = 648,000 + parameter (NFFT=10*65536,NH=NFFT/2) + type(hdr) h !Header for .wav file + integer*2 iwave(NMAX) !Generated waveform + integer*4 itone(126) !Channel symbols (values 0-65) + integer dgen(12) !Twelve 6-bit data symbols + integer sent(63) !RS(63,12) codeword + real*4 xnoise(NMAX) !Generated random noise + real*4 dat(NMAX) !Generated real data + complex cdat(NMAX) !Generated complex waveform + complex cspread(0:NFFT-1) !Complex amplitude for Rayleigh fading + complex z + real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq,sps + character msg*22,fname*11,csubmode*1,c,optarg*500,numbuf*32 +! character call1*5,call2*5 + logical :: display_help=.false.,seed_prngs=.true. + type (option) :: long_options(8) = [ & + option ('help',.false.,'h','Display this help message',''), & + option ('sub-mode',.true.,'m','sub mode, default MODE=A','MODE'), & + option ('num-sigs',.true.,'n','number of signals per file, default SIGNALS=10','SIGNALS'), & + option ('doppler-spread',.true.,'d','Doppler spread, default SPREAD=0.0','SPREAD'), & + option ('time-offset',.true.,'t','Time delta, default SECONDS=0.0','SECONDS'), & + option ('num-files',.true.,'f','Number of files to generate, default FILES=1','FILES'), & + option ('no-prng-seed',.false.,'p','Do not seed PRNGs (use for reproducible tests)',''), & + option ('strength',.true.,'s','S/N in dB (2500Hz reference b/w), default SNR=0','SNR') ] + integer nprc(126) !Sync pattern + data nprc/1,0,0,1,1,0,0,0,1,1,1,1,1,1,0,1,0,1,0,0, & + 0,1,0,1,1,0,0,1,0,0,0,1,1,1,0,0,1,1,1,1, & + 0,1,1,0,1,1,1,1,0,0,0,1,1,0,1,0,1,0,1,1, & + 0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,0,0,0,0,1, & + 1,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,1,1,0,1, & + 0,1,0,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,1, & + 1,1,1,1,1,1/ + +! Default parameters: + csubmode='A' + mode65=1 + nsigs=10 + fspread=0. + xdt=0. + snrdb=0. + nfiles=1 + + do + call getopt('hm:n:d:t:f:ps:',long_options,c,optarg,narglen,nstat,noffset,nremain,.true.) + if( nstat .ne. 0 ) then + exit + end if + select case (c) + case ('h') + display_help = .true. + case ('m') + read (optarg(:narglen), *) csubmode + if(csubmode.eq.'A') mode65=1 + if(csubmode.eq.'B') mode65=2 + if(csubmode.eq.'C') mode65=4 + case ('n') + read (optarg(:narglen), *,err=10) nsigs + case ('d') + read (optarg(:narglen), *,err=10) fspread + case ('t') + read (optarg(:narglen), *) numbuf + if (numbuf(1:1) == '\') then + read (numbuf(2:), *,err=10) xdt + else + read (numbuf, *,err=10) xdt + end if + case ('f') + read (optarg(:narglen), *,err=10) nfiles + case ('p') + seed_prngs=.false. + case ('s') + read (optarg(:narglen), *) numbuf + if (numbuf(1:1) == '\') then + read (numbuf(2:), *,err=10) snrdb + else + read (numbuf, *,err=10) snrdb + end if + end select + cycle +10 display_help=.true. + print *, 'Optional argument format error for option -', c + end do + + if(display_help .or. nstat.lt.0 .or. nremain.ge.1) then + print *, '' + print *, 'Usage: jt65sim [OPTIONS]' + print *, '' + print *, ' Generate one or more simulated JT65 signals in .WAV file(s)' + print *, '' + print *, 'Example: jt65sim -m B -n 10 -d 0.2 -s \\-24.5 -t 0.0 -f 4' + print *, '' + print *, 'OPTIONS: NB Use \ (\\ on *nix shells) to escape -ve arguments' + print *, '' + do i = 1, size (long_options) + call long_options(i) % print (6) + end do + go to 999 + endif + + if (seed_prngs) then + call init_random_seed() ! seed Fortran RANDOM_NUMBER generator + call sgran() ! see C rand generator (used in gran) + end if + + rms=100. + fsample=12000.d0 !Sample rate (Hz) + dt=1.d0/fsample !Sample interval (s) + twopi=8.d0*atan(1.d0) + npts=54*12000 !Total samples in .wav file + baud=11025.d0/4096.d0 !Keying rate + sps=12000.d0/baud !Samples per symbol, at fsample=12000 Hz + nsym=126 !Number of channel symbols + h=default_header(12000,npts) + dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz) + + do ifile=1,nfiles !Loop over requested number of files + write(fname,1002) ifile !Output filename +1002 format('000000_',i4.4) + open(10,file=fname//'.wav',access='stream',status='unknown') + + xnoise=0. + cdat=0. + if(snrdb.lt.90) then + do i=1,npts + xnoise(i)=gran() !Generate gaussian noise + enddo + endif + + do isig=1,nsigs !Generate requested number of sigs + if(mod(nsigs,2).eq.0) f0=1500.0 + dfsig*(isig-0.5-nsigs/2) + if(mod(nsigs,2).eq.1) f0=1500.0 + dfsig*(isig-(nsigs+1)/2) + xsnr=snrdb + if(snrdb.eq.0.0) xsnr=-19 - isig + if(csubmode.eq.'B' .and. snrdb.eq.0.0) xsnr=-21 - isig + if(csubmode.eq.'C' .and. snrdb.eq.0.0) xsnr=-21 - isig + +!### +! call1="K1ABC" +! ic3=65+mod(isig-1,26) +! ic2=65+mod((isig-1)/26,26) +! ic1=65 +! call2="W9"//char(ic1)//char(ic2)//char(ic3) +! write(msg,1010) call1,call2,nint(xsnr) +!1010 format(a5,1x,a5,1x,i3.2) + msg="K1ABC W9XYZ EN37" +!### + + call packmsg(msg,dgen,itype,.false.) !Pack message into 12 six-bit bytes + call rs_encode(dgen,sent) !Encode using RS(63,12) + call interleave63(sent,1) !Interleave channel symbols + call graycode65(sent,63,1) !Apply Gray code + + k=0 + do j=1,nsym !Insert sync and data into itone() + if(nprc(j).eq.0) then + k=k+1 + itone(j)=sent(k)+2 + else + itone(j)=0 + endif + enddo + + bandwidth_ratio=2500.0/6000.0 + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*xsnr) + if(xsnr.gt.90.0) sig=1.0 + write(*,1020) ifile,isig,f0,csubmode,xsnr,xdt,fspread,msg +1020 format(i4,i4,f10.3,2x,a1,2x,f5.1,f6.2,f5.1,1x,a22) + + phi=0.d0 + dphi=0.d0 + k=12000 + xdt*12000 !Start audio at t = xdt + 1.0 s + isym0=-99 + do i=1,npts !Add this signal into cdat() + isym=floor(i/sps)+1 + if(isym.gt.nsym) exit + if(isym.ne.isym0) then + freq=f0 + itone(isym)*baud*mode65 + dphi=twopi*freq*dt + isym0=isym + endif + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + z=cmplx(cos(xphi),sin(xphi)) + k=k+1 + if(k.ge.1) cdat(k)=cdat(k) + sig*z + enddo + enddo + + if(fspread.ne.0) then !Apply specified Doppler spread + df=12000.0/nfft + twopi=8*atan(1.0) + cspread(0)=1.0 + cspread(NH)=0. + +! The following options were added 3/15/2016 to make the half-power tone +! widths equal to the requested Doppler spread. (Previously we effectively +! used b=1.0 and Gaussian shape, which made the tones 1.665 times wider.) +! b=2.0*sqrt(log(2.0)) !Gaussian (before 3/15/2016) +! b=2.0 !Lorenzian 3/15 - 3/27 + b=6.0 !Lorenzian 3/28 onward + + do i=1,NH + f=i*df + x=b*f/fspread + z=0. + a=0. + if(x.lt.3.0) then !Cutoff beyond x=3 +! a=sqrt(exp(-x*x)) !Gaussian + a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian + call random_number(r1) + phi1=twopi*r1 + z=a*cmplx(cos(phi1),sin(phi1)) + endif + cspread(i)=z + z=0. + if(x.lt.50.0) then + call random_number(r2) + phi2=twopi*r2 + z=a*cmplx(cos(phi2),sin(phi2)) + endif + cspread(NFFT-i)=z + enddo + + do i=0,NFFT-1 + f=i*df + if(i.gt.NH) f=(i-nfft)*df + s=real(cspread(i))**2 + aimag(cspread(i))**2 +! write(13,3000) i,f,s,cspread(i) +!3000 format(i5,f10.3,3f12.6) + enddo +! s=real(cspread(0))**2 + aimag(cspread(0))**2 +! write(13,3000) 1024,0.0,s,cspread(0) + + call four2a(cspread,NFFT,1,1,1) !Transform to time domain + + sum=0. + do i=0,NFFT-1 + p=real(cspread(i))**2 + aimag(cspread(i))**2 + sum=sum+p + enddo + avep=sum/NFFT + fac=sqrt(1.0/avep) + cspread=fac*cspread !Normalize to constant avg power + cdat=cspread(1:npts)*cdat !Apply Rayleigh fading + +! do i=0,NFFT-1 +! p=real(cspread(i))**2 + aimag(cspread(i))**2 +! write(14,3010) i,p,cspread(i) +!3010 format(i8,3f12.6) +! enddo + + endif + + dat=aimag(cdat) + xnoise !Add the generated noise + fac=32767.0/nsigs + if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts)) + if(snrdb.lt.90.0) iwave(1:npts)=nint(rms*dat(1:npts)) + write(10) h,iwave(1:npts) !Save the .wav file + close(10) + enddo + +999 end program jt65sim diff --git a/lib/jt9.f90 b/lib/jt9.f90 index 5a0b77c6..10461209 100644 --- a/lib/jt9.f90 +++ b/lib/jt9.f90 @@ -7,172 +7,206 @@ program jt9 use prog_args use, intrinsic :: iso_c_binding use FFTW3 + use timer_module, only: timer + use timer_impl, only: init_timer, fini_timer + use readwav + + include 'jt9com.f90' - include 'constants.f90' integer(C_INT) iret - integer*4 ihdr(11) + type(wav_header) wav real*4 s(NSMAX) - integer*2 id2 character c character(len=500) optarg, infile character wisfile*80 - integer :: arglen,stat,offset,remain,mode=0,flow=200,fsplit=2700,fhigh=4007,nrxfreq=1500,ntrperiod=1,ndepth=1 - logical :: shmem = .false., read_files = .false., have_args = .false., tx9 = .false., display_help = .false. - type (option) :: long_options(16) = [ & - option ('help', .false., 'h', 'Display this help message', ''), & - option ('shmem', .true., 's', 'Use shared memory for sample data', ''), & - option ('tr-period', .true., 'p', 'Tx/Rx period, default=1', ''), & - option ('executable-path', .true., 'e', 'Location of subordinate executables (KVASD) default="."', ''), & - option ('data-path', .true., 'a', 'Location of writeable data files, detfault="."', ''), & - option ('temp-path', .true., 't', 'Temporary files path, default="."', ''), & - option ('lowest', .true., 'L', 'Lowest frequency decoded (JT65), default=200Hz', ''), & - option ('highest', .true., 'H', 'Highest frequency decoded, default=4007Hz', ''), & - option ('split', .true., 'S', 'Lowest JT9 frequency decoded, default=2700Hz', ''), & - option ('rx-frequency', .true., 'f', 'Receive frequency offset, default=1500', ''), & - option ('patience', .true., 'w', 'FFTW3 planing patience (0-4), default=1', ''), & - option ('fft-threads', .true., 'm', 'Number of threads to process large FFTs, default=1', ''), & - option ('jt65', .false., '6', 'JT65 mode', ''), & - option ('jt9', .false., '9', 'JT9 mode', ''), & - option ('depth', .true., 'd', 'JT9 decoding depth (1-3), default=1', ''), & - option ('tx-jt9', .false., 'T', 'Tx mode is JT9, default=JT65', '') ] - common/jt9com/ss(184,NSMAX),savg(NSMAX),id2(NMAX),nutc,ndiskdat,ntr, & - mousefqso,newdat,nfa,nfsplit,nfb,ntol,kin,nzhsym,nsynced,ndecoded - common/tracer/limtrace,lu +!### ndepth was defined as 60001. Why??? + integer :: arglen,stat,offset,remain,mode=0,flow=200,fsplit=2700, & + fhigh=4000,nrxfreq=1500,ntrperiod=1,ndepth=1,nexp_decode=0 + logical :: read_files = .true., tx9 = .false., display_help = .false. + type (option) :: long_options(25) = [ & + option ('help', .false., 'h', 'Display this help message', ''), & + option ('shmem',.true.,'s','Use shared memory for sample data','KEY'), & + option ('tr-period', .true., 'p', 'Tx/Rx period, default MINUTES=1', & + 'MINUTES'), & + option ('executable-path', .true., 'e', & + 'Location of subordinate executables (KVASD) default PATH="."', & + 'PATH'), & + option ('data-path', .true., 'a', & + 'Location of writeable data files, default PATH="."', 'PATH'), & + option ('temp-path', .true., 't', & + 'Temporary files path, default PATH="."', 'PATH'), & + option ('lowest', .true., 'L', & + 'Lowest frequency decoded (JT65), default HERTZ=200', 'HERTZ'), & + option ('highest', .true., 'H', & + 'Highest frequency decoded, default HERTZ=4007', 'HERTZ'), & + option ('split', .true., 'S', & + 'Lowest JT9 frequency decoded, default HERTZ=2700', 'HERTZ'), & + option ('rx-frequency', .true., 'f', & + 'Receive frequency offset, default HERTZ=1500', 'HERTZ'), & + option ('patience', .true., 'w', & + 'FFTW3 planing patience (0-4), default PATIENCE=1', 'PATIENCE'), & + option ('fft-threads', .true., 'm', & + 'Number of threads to process large FFTs, default THREADS=1', & + 'THREADS'), & + option ('jt65', .false., '6', 'JT65 mode', ''), & + option ('jt9', .false., '9', 'JT9 mode', ''), & + option ('ft8', .false., '8', 'FT8 mode', ''), & + option ('jt4', .false., '4', 'JT4 mode', ''), & + option ('qra64', .false., 'q', 'QRA64 mode', ''), & + option ('sub-mode', .true., 'b', 'Sub mode, default SUBMODE=A', 'A'), & + option ('depth', .true., 'd', & + 'JT9 decoding depth (1-3), default DEPTH=1', 'DEPTH'), & + option ('tx-jt9', .false., 'T', 'Tx mode is JT9', ''), & + option ('my-call', .true., 'c', 'my callsign', 'CALL'), & + option ('my-grid', .true., 'G', 'my grid locator', 'GRID'), & + option ('his-call', .true., 'x', 'his callsign', 'CALL'), & + option ('his-grid', .true., 'g', 'his grid locator', 'GRID'), & + option ('experience-decode', .true., 'X', & + 'experience based decoding flags (1..n), default FLAGS=0', & + 'FLAGS') ] + + type(dec_data), allocatable :: shared_data + character(len=12) :: mycall, hiscall + character(len=6) :: mygrid, hisgrid common/patience/npatience,nthreads - common/decstats/num65,numbm,numkv,num9,numfano,infile + common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano data npatience/1/,nthreads/1/ + nsubmode = 0 + do - call getopt('hs:e:a:r:m:p:d:f:w:t:96TL:S:H:',long_options,c,optarg,arglen,stat, & - offset,remain) + call getopt('hs:e:a:b:r:m:p:d:f:w:t:9864qTL:S:H:c:G:x:g:X:', & + long_options,c,optarg,arglen,stat,offset,remain,.true.) if (stat .ne. 0) then exit end if - have_args = .true. select case (c) case ('h') display_help = .true. - case ('s') - shmem = .true. + read_files = .false. shm_key = optarg(:arglen) - case ('e') exe_dir = optarg(:arglen) - case ('a') data_dir = optarg(:arglen) - + case ('b') + nsubmode = ichar (optarg(:1)) - ichar ('A') case ('t') temp_dir = optarg(:arglen) - case ('m') read (optarg(:arglen), *) nthreads - case ('p') - read_files = .true. read (optarg(:arglen), *) ntrperiod - case ('d') - read_files = .true. read (optarg(:arglen), *) ndepth - case ('f') - read_files = .true. read (optarg(:arglen), *) nrxfreq - case ('L') - read_files = .true. read (optarg(:arglen), *) flow - case ('S') - read_files = .true. read (optarg(:arglen), *) fsplit - case ('H') - read_files = .true. read (optarg(:arglen), *) fhigh - + case ('q') + mode = 164 + case ('4') + mode = 4 case ('6') - read_files = .true. if (mode.lt.65) mode = mode + 65 - case ('9') - read_files = .true. if (mode.lt.9.or.mode.eq.65) mode = mode + 9 - + case ('8') + mode = 8 case ('T') - read_files = .true. tx9 = .true. - case ('w') read (optarg(:arglen), *) npatience - + case ('c') + read (optarg(:arglen), *) mycall + case ('G') + read (optarg(:arglen), *) mygrid + case ('x') + read (optarg(:arglen), *) hiscall + case ('g') + read (optarg(:arglen), *) hisgrid + case ('X') + read (optarg(:arglen), *) nexp_decode end select end do - if (display_help .or. .not. have_args .or. (stat .lt. 0 .or. (shmem .and. remain .gt. 0) & - .or. (read_files .and. remain .eq. 0) .or. & - (shmem .and. read_files))) then - print*,'Usage: jt9 -p OPTIONS file1 [file2 ...]' - print*,' Reads data from *.wav files.' - print*,'' - print*,' jt9 -s [-w n] [-m n] [-e path] [-a path] [-t path]' - print*,' Gets data from shared memory region with key==' + if (display_help .or. stat .lt. 0 & + .or. (.not. read_files .and. remain .gt. 0) & + .or. (read_files .and. remain .lt. 1)) then + + print *, 'Usage: jt9 [OPTIONS] file1 [file2 ...]' + print *, ' Reads data from *.wav files.' + print *, '' + print *, ' jt9 -s [-w patience] [-m threads] [-e path] [-a path] [-t path]' + print *, ' Gets data from shared memory region with key==' + print *, '' + print *, 'OPTIONS:' + print *, '' do i = 1, size (long_options) - print*,'' call long_options(i) % print (6) end do go to 999 endif + + iret=fftwf_init_threads() !Initialize FFTW threading + +! Default to 1 thread, but use nthreads for the big ones + call fftwf_plan_with_nthreads(1) - iret=fftwf_init_threads() !Initialize FFTW threading - call fftwf_plan_with_nthreads(1) !Default to 1 thread but use nthreads for the big ones ! Import FFTW wisdom, if available wisfile=trim(data_dir)//'/jt9_wisdom.dat'// C_NULL_CHAR iret=fftwf_import_wisdom_from_filename(wisfile) - num65=0 - numbm=0 - numkv=0 + ntry65a=0 + ntry65b=0 + n65a=0 + n65b=0 num9=0 numfano=0 - if (shmem) then - call jt9a() + if (.not. read_files) then + call jt9a() !We're running under control of WSJT-X go to 999 endif - limtrace=0 - lu=12 + allocate(shared_data) nflatten=0 do iarg = offset + 1, offset + remain call get_command_argument (iarg, optarg, arglen) infile = optarg(:arglen) - open(10,file=infile,access='stream',status='old',err=998) - read(10) ihdr - nutc0=ihdr(1) !Silence compiler warning + call wav%read (infile) + nfsample=wav%audio_format%sample_rate i1=index(infile,'.wav') - read(infile(i1-4:i1-1),*,err=1) nutc0 + if(i1.lt.1) i1=index(infile,'.WAV') + if(infile(i1-5:i1-5).eq.'_') then + read(infile(i1-4:i1-1),*,err=1) nutc + else + read(infile(i1-6:i1-1),*,err=1) nutc + endif go to 2 -1 nutc0=0 +1 nutc=0 2 nsps=0 if(ntrperiod.eq.1) then nsps=6912 - nzhsym=173 + shared_data%params%nzhsym=181 else if(ntrperiod.eq.2) then nsps=15360 - nzhsym=178 + shared_data%params%nzhsym=178 else if(ntrperiod.eq.5) then nsps=40960 - nzhsym=172 + shared_data%params%nzhsym=172 else if(ntrperiod.eq.10) then nsps=82944 - nzhsym=171 + shared_data%params%nzhsym=171 else if(ntrperiod.eq.30) then nsps=252000 - nzhsym=167 + shared_data%params%nzhsym=167 endif if(nsps.eq.0) stop 'Error: bad TRperiod' @@ -181,47 +215,101 @@ program jt9 nhsym0=-999 npts=(60*ntrperiod-6)*12000 if(iarg .eq. offset + 1) then - open(12,file=trim(data_dir)//'/timer.out',status='unknown') + call init_timer (trim(data_dir)//'/timer.out') call timer('jt9 ',0) endif - id2=0 !??? Why is this necessary ??? + shared_data%id2=0 !??? Why is this necessary ??? do iblk=1,npts/kstep k=iblk*kstep + if(mode.eq.8 .and. k.gt.179712) exit call timer('read_wav',0) - read(10,end=10) id2(k-kstep+1:k) - call timer('read_wav',1) - + read(unit=wav%lun,end=3) shared_data%id2(k-kstep+1:k) + go to 4 +3 call timer('read_wav',1) + print*,'EOF on input file ',infile + exit +4 call timer('read_wav',1) nhsym=(k-2048)/kstep if(nhsym.ge.1 .and. nhsym.ne.nhsym0) then -! Emit signal readyForFFT - ingain=0 - call timer('symspec ',0) - call symspec(k,ntrperiod,nsps,ingain,nflatten,pxdb,s,df3,ihsym,npts8) - call timer('symspec ',1) + if(mode.eq.9 .or. mode.eq.74) then +! Compute rough symbol spectra for the JT9 decoder + ingain=0 + call timer('symspec ',0) + nminw=1 + call symspec(shared_data,k,ntrperiod,nsps,ingain,nminw,pxdb, & + s,df3,ihsym,npts8,pxdbmax) + call timer('symspec ',1) + endif nhsym0=nhsym - if(ihsym.ge.173) go to 10 + if(nhsym.ge.181) exit endif enddo - -10 close(10) - call fillcom(nutc0,ndepth,nrxfreq,mode,tx9,flow,fsplit,fhigh) - call decoder(ss,id2) + close(unit=wav%lun) + shared_data%params%nutc=nutc + shared_data%params%ndiskdat=.true. + shared_data%params%ntr=60 + shared_data%params%nfqso=nrxfreq + shared_data%params%newdat=.true. + shared_data%params%npts8=74736 + shared_data%params%nfa=flow + shared_data%params%nfsplit=fsplit + shared_data%params%nfb=fhigh + shared_data%params%ntol=20 + shared_data%params%kin=64800 + shared_data%params%nzhsym=181 + shared_data%params%ndepth=ndepth + shared_data%params%lapon=.true. + shared_data%params%napwid=75 + shared_data%params%dttol=3. + +! shared_data%params%minsync=0 !### TEST ONLY +! shared_data%params%nfqso=1500 !### TEST ONLY +! mycall="G3WDG " !### TEST ONLY +! hiscall="VK7MO " !### TEST ONLY +! hisgrid="QE37 " !### TEST ONLY + if(mode.eq.164 .and. nsubmode.lt.100) nsubmode=nsubmode+100 + + shared_data%params%naggressive=0 + shared_data%params%n2pass=2 +! shared_data%params%nranera=8 !### ntrials=10000 + shared_data%params%nranera=6 !### ntrials=3000 + shared_data%params%nrobust=.false. + shared_data%params%nexp_decode=nexp_decode + shared_data%params%mycall=mycall + shared_data%params%mygrid=mygrid + shared_data%params%hiscall=hiscall + shared_data%params%hisgrid=hisgrid + if (shared_data%params%mycall == '') shared_data%params%mycall='K1ABC' + if (shared_data%params%hiscall == '') shared_data%params%hiscall='W9XYZ' + if (shared_data%params%hisgrid == '') shared_data%params%hiscall='EN37' + if (tx9) then + shared_data%params%ntxmode=9 + else + shared_data%params%ntxmode=65 + end if + if (mode.eq.0) then + shared_data%params%nmode=65+9 + else + shared_data%params%nmode=mode + end if + shared_data%params%nsubmode=nsubmode + shared_data%params%datetime="2013-Apr-16 15:13" !### Temp + if(mode.eq.9 .and. fsplit.ne.2700) shared_data%params%nfa=fsplit + call multimode_decoder(shared_data%ss,shared_data%id2,shared_data%params,nfsample) enddo call timer('jt9 ',1) call timer('jt9 ',101) - go to 999 - -998 print*,'Cannot open file:' - print*,infile 999 continue ! Output decoder statistics - write(12,1100) numbm,numkv,numbm+numkv,num65,numfano,num9 -1100 format(58('-')/' BM KV JT65 Tries JT9 Tries'/ & - 58('-')/6i8) + call fini_timer () +! open (unit=12, file=trim(data_dir)//'/timer.out', status='unknown', position='append') +! write(12,1100) n65a,ntry65a,n65b,ntry65b,numfano,num9 +!1100 format(58('-')/' JT65_1 Tries_1 JT65_2 Tries_2 JT9 Tries'/ & +! 58('-')/6i8) ! Save wisdom and free memory iret=fftwf_export_wisdom_to_filename(wisfile) @@ -229,5 +317,4 @@ program jt9 call filbig(a,-1,1,0.0,0,0,0,0,0) !used for FFT plans call fftwf_cleanup_threads() call fftwf_cleanup() - end program jt9 diff --git a/lib/jt9_decode.f90 b/lib/jt9_decode.f90 new file mode 100644 index 00000000..d862504a --- /dev/null +++ b/lib/jt9_decode.f90 @@ -0,0 +1,172 @@ +module jt9_decode + + type :: jt9_decoder + procedure(jt9_decode_callback), pointer :: callback + contains + procedure :: decode + end type jt9_decoder + + abstract interface + subroutine jt9_decode_callback (this, sync, snr, dt, freq, drift, & + decoded) + import jt9_decoder + implicit none + class(jt9_decoder), intent(inout) :: this + real, intent(in) :: sync + integer, intent(in) :: snr + real, intent(in) :: dt + real, intent(in) :: freq + integer, intent(in) :: drift + character(len=22), intent(in) :: decoded + end subroutine jt9_decode_callback + end interface + +contains + + subroutine decode(this,callback,ss,id2,nfqso,newdat,npts8,nfa, & + nfsplit,nfb,ntol,nzhsym,nagain,ndepth,nmode,nsubmode,nexp_decode) + use timer_module, only: timer + + include 'constants.f90' + class(jt9_decoder), intent(inout) :: this + procedure(jt9_decode_callback) :: callback + real ss(184,NSMAX) + logical, intent(in) :: newdat, nagain + character*22 msg + real*4 ccfred(NSMAX) + real*4 red2(NSMAX) + logical ccfok(NSMAX) + logical done(NSMAX) + integer*2 id2(NTMAX*12000) + integer*1 i1SoftSymbols(207) + common/decstats/ntry65a,ntry65b,n65a,n65b,num9,numfano + save ccfred,red2 + + if(nexp_decode.eq.-99) stop !Silence compiler warning + this%callback => callback + if(nmode.eq.9 .and. nsubmode.ge.1) then + call decode9w(nfqso,ntol,nsubmode,ss,id2,sync,nsnr,xdt,freq,msg) + if (associated(this%callback)) then + ndrift=0 + call this%callback(sync,nsnr,xdt,freq,ndrift,msg) + end if + go to 999 + endif + + nsynced=0 + ndecoded=0 + nsps=6912 !Params for JT9-1 + df3=1500.0/2048.0 + + tstep=0.5*nsps/12000.0 !Half-symbol step (seconds) + done=.false. + + nf0=0 + nf1=nfa + if(nmode.eq.65+9) nf1=nfsplit + ia=max(1,nint((nf1-nf0)/df3)) + ib=min(NSMAX,nint((nfb-nf0)/df3)) + lag1=-int(2.5/tstep + 0.9999) + lag2=int(5.0/tstep + 0.9999) + if(newdat) then + call timer('sync9 ',0) + call sync9(ss,nzhsym,lag1,lag2,ia,ib,ccfred,red2,ipk) + call timer('sync9 ',1) + endif + + nsps8=nsps/8 + df8=1500.0/nsps8 + dblim=db(864.0/nsps8) - 26.2 + + ia1=1 !quel compiler gripe + ib1=1 !quel compiler gripe + do nqd=1,0,-1 + limit=5000 + ccflim=3.0 + red2lim=1.6 + schklim=2.2 + if(iand(ndepth,7).eq.2) then + limit=10000 + ccflim=2.7 + endif + if(iand(ndepth,7).eq.3 .or. nqd.eq.1) then + limit=30000 + ccflim=2.5 + schklim=2.0 + endif + if(nagain) then + limit=100000 + ccflim=2.4 + schklim=1.8 + endif + ccfok=.false. + + if(nqd.eq.1) then + nfa1=nfqso-ntol + nfb1=nfqso+ntol + ia=max(1,nint((nfa1-nf0)/df3)) + ib=min(NSMAX,nint((nfb1-nf0)/df3)) + ccfok(ia:ib)=(ccfred(ia:ib).gt.(ccflim-2.0)) .and. & + (red2(ia:ib).gt.(red2lim-1.0)) + ia1=ia + ib1=ib + else + nfa1=nf1 + nfb1=nfb + ia=max(1,nint((nfa1-nf0)/df3)) + ib=min(NSMAX,nint((nfb1-nf0)/df3)) + do i=ia,ib + ccfok(i)=ccfred(i).gt.ccflim .and. red2(i).gt.red2lim + enddo + ccfok(ia1:ib1)=.false. + endif + + fgood=0. + do i=ia,ib + if(done(i) .or. (.not.ccfok(i))) cycle + f=(i-1)*df3 + if(nqd.eq.1 .or. & + (ccfred(i).ge.ccflim .and. abs(f-fgood).gt.10.0*df8)) then + + call timer('softsym ',0) + fpk=nf0 + df3*(i-1) + call softsym(id2,npts8,nsps8,newdat,fpk,syncpk,snrdb,xdt, & + freq,drift,a3,schk,i1SoftSymbols) + call timer('softsym ',1) + + sync=(syncpk+1)/4.0 + if(nqd.eq.1 .and. ((sync.lt.0.5) .or. (schk.lt.1.0))) cycle + if(nqd.ne.1 .and. ((sync.lt.1.0) .or. (schk.lt.1.5))) cycle + + call timer('jt9fano ',0) + call jt9fano(i1SoftSymbols,limit,nlim,msg) + call timer('jt9fano ',1) + + if(sync.lt.0.0 .or. snrdb.lt.dblim-2.0) sync=0.0 + nsync=int(sync) + if(nsync.gt.10) nsync=10 + nsnr=nint(snrdb) + ndrift=nint(drift/df3) + num9=num9+1 + + if(msg.ne.' ') then + numfano=numfano+1 + if (associated(this%callback)) then + call this%callback(sync,nsnr,xdt,freq,ndrift,msg) + end if + iaa=max(1,i-1) + ibb=min(NSMAX,i+22) + fgood=f + nsynced=1 + ndecoded=1 + ccfok(iaa:ibb)=.false. + done(iaa:ibb)=.true. + endif + endif + enddo + if(nagain) exit + enddo + +999 return + end subroutine decode +end module jt9_decode diff --git a/lib/jt9a.f90 b/lib/jt9a.f90 index ae34c82d..9729e080 100644 --- a/lib/jt9a.f90 +++ b/lib/jt9a.f90 @@ -1,44 +1,46 @@ subroutine jt9a() - + use, intrinsic :: iso_c_binding, only: c_f_pointer use prog_args + use timer_module, only: timer + use timer_impl, only: init_timer !, limtrace + + include 'jt9com.f90' ! These routines connect the shared memory region to the decoder. interface function address_jt9() - integer*1, pointer :: address_jt9 + use, intrinsic :: iso_c_binding, only: c_ptr + type(c_ptr) :: address_jt9 end function address_jt9 end interface integer*1 attach_jt9 ! integer*1 lock_jt9,unlock_jt9 integer size_jt9 - integer*1, pointer :: p_jt9 - character*80 cwd ! Multiple instances: character*80 mykey + type(dec_data), pointer :: shared_data + type(params_block) :: local_params logical fileExists - common/tracer/limtrace,lu ! Multiple instances: i0 = len(trim(shm_key)) - call getcwd(cwd) - open(12,file=trim(data_dir)//'/timer.out',status='unknown') + call init_timer (trim(data_dir)//'/timer.out') +! open(23,file=trim(data_dir)//'/CALL3.TXT',status='unknown') - limtrace=0 ! limtrace=-1 !Disable all calls to timer() - lu=12 ! Multiple instances: set the shared memory key before attaching mykey=trim(repeat(shm_key,1)) i0 = len(mykey) i0=setkey_jt9(trim(mykey)) - i1=attach_jt9() + msdelay=10 10 inquire(file=trim(temp_dir)//'/.lock',exist=fileExists) if(fileExists) then - call sleep_msec(100) + call sleep_msec(msdelay) go to 10 endif @@ -55,17 +57,19 @@ subroutine jt9a() print*,"Must start 'jt9 -s ' from within WSJT-X." go to 999 endif - p_jt9=>address_jt9() - call timer('jt9b ',0) - call jt9b(p_jt9,nbytes) - call timer('jt9b ',1) + call c_f_pointer(address_jt9(),shared_data) + local_params=shared_data%params !save a copy because wsjtx carries on accessing + call flush(6) + call timer('decoder ',0) + call multimode_decoder(shared_data%ss,shared_data%id2,local_params,12000) + call timer('decoder ',1) 100 inquire(file=trim(temp_dir)//'/.lock',exist=fileExists) if(fileExists) go to 10 - call sleep_msec(100) + call sleep_msec(msdelay) go to 100 -999 call timer('jt9b ',101) +999 call timer('decoder ',101) return end subroutine jt9a diff --git a/lib/jt9b.f90 b/lib/jt9b.f90 deleted file mode 100644 index 63de536b..00000000 --- a/lib/jt9b.f90 +++ /dev/null @@ -1,12 +0,0 @@ -subroutine jt9b(jt9com,nbytes) - - include 'constants.f90' - integer*1 jt9com(0:nbytes-1) - kss=0 - ksavg=kss + 4*184*NSMAX - kid2=ksavg + 4*NSMAX - knutc=kid2 + 2*NTMAX*12000 - call jt9c(jt9com(kss),jt9com(ksavg),jt9com(kid2),jt9com(knutc)) - - return -end subroutine jt9b diff --git a/lib/jt9c.f90 b/lib/jt9c.f90 deleted file mode 100644 index 9f06274a..00000000 --- a/lib/jt9c.f90 +++ /dev/null @@ -1,23 +0,0 @@ -subroutine jt9c(ss,savg,id2,nparams0) - - include 'constants.f90' - real*4 ss(184*NSMAX),savg(NSMAX) - integer*2 id2(NTMAX*12000) - - integer nparams0(22),nparams(22) - character*20 datetime - common/npar/nutc,ndiskdat,ntrperiod,nfqso,newdat,npts8,nfa,nfsplit,nfb, & - ntol,kin,nzhsym,nsave,nagain,ndepth,ntxmode,nmode,datetime - common/patience/npatience,nthreads - equivalence (nparams,nutc) - - nutc=id2(1)+int(savg(1)) !Silence compiler warning - nparams=nparams0 !Copy parameters into common/npar/ - if(ndiskdat.ne.0) npatience=2 - - call flush(6) -! if(sum(nparams).ne.0) call decoder(ss,id2,ldir) - call decoder(ss,id2) - - return -end subroutine jt9c diff --git a/lib/jt9code.f90 b/lib/jt9code.f90 index 12c385aa..5a4b4fc8 100644 --- a/lib/jt9code.f90 +++ b/lib/jt9code.f90 @@ -1,71 +1,84 @@ -program jt9code - -! Generate simulated data for testing of WSJT-X - - character*22 testmsg(20) - character msg*22,msg0*22,decoded*22,bad*1,msgtype*10 - integer*4 i4tone(85) !Channel symbols (values 0-8) - include 'jt9sync.f90' - - nargs=iargc() - if(nargs.ne.1) then - print*,'Usage: jt9code "message"' - print*,' jt9code -t' - go to 999 - endif - - call getarg(1,msg) - nmsg=1 - if(msg(1:2).eq."-t") then - testmsg(1)="KA1ABC WB9XYZ EN34" - testmsg(2)="KA1ABC WB9XYZ RO" - testmsg(3)="KA1ABC WB9XYZ -21" - testmsg(4)="KA1ABC WB9XYZ R-19" - testmsg(5)="KA1ABC WB9XYZ RRR" - testmsg(6)="KA1ABC WB9XYZ 73" - testmsg(7)="KA1ABC WB9XYZ" - testmsg(8)="ZL/KA1ABC WB9XYZ" - testmsg(9)="KA1ABC ZL/WB9XYZ" - testmsg(10)="KA1ABC/4 WB9XYZ" - testmsg(11)="KA1ABC WB9XYZ/4" - testmsg(12)="CQ ZL4/KA1ABC" - testmsg(13)="DE ZL4/KA1ABC" - testmsg(14)="QRZ ZL4/KA1ABC" - testmsg(15)="CQ WB9XYZ/VE4" - testmsg(16)="HELLO WORLD" - testmsg(17)="ZL4/KA1ABC 73" - testmsg(18)="KA1ABC XL/WB9XYZ" - testmsg(19)="KA1ABC WB9XYZ/W4" - testmsg(20)="123456789ABCDEFGH" - nmsg=20 - endif - - write(*,1010) -1010 format("Message Decoded Err?"/ & - "-----------------------------------------------------------------") - do imsg=1,nmsg - if(nmsg.gt.1) msg=testmsg(imsg) - call fmtmsg(msg,iz) !To upper, collapse mult blanks - msg0=msg !Input message - - ichk=0 - call genjt9(msg,ichk,decoded,i4tone,itype) !Encode message into tone #s - - msgtype="" - if(itype.eq.1) msgtype="Std Msg" - if(itype.eq.2) msgtype="Type 1 pfx" - if(itype.eq.3) msgtype="Type 1 sfx" - if(itype.eq.4) msgtype="Type 2 pfx" - if(itype.eq.5) msgtype="Type 2 sfx" - if(itype.eq.6) msgtype="Free text" - - bad=" " - if(decoded.ne.msg0) bad="*" - write(*,1020) msg0,decoded,bad,itype,msgtype -1020 format(a22,2x,a22,3x,a1,i3,": ",a10) - enddo - - if(nmsg.eq.1) write(*,1030) i4tone -1030 format(/'Channel symbols'/(30i2)) - -999 end program jt9code +program jt9code + +! Generate simulated data for testing of WSJT-X + + character*22 msg,msgchk,msg0,msg1,decoded,cok*3,bad*1,msgtype*10,expected + integer*4 i4tone(85) !Channel symbols (values 0-8) + include 'testmsg.f90' + include 'jt9sync.f90' + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: jt9code "message"' + print*,' jt9code -t' + go to 999 + endif + + call getarg(1,msg) + nmsg=1 + if(msg(1:2).eq."-t") then + if (NTEST+5 > MAXTEST) then + write(*,*) "NTEST exceed MAXTEST" + endif + testmsg(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" + testmsg(NTEST+2)="KA1ABC WB9XYZ OOO" + testmsg(NTEST+3)="RO" + testmsg(NTEST+4)="RRR" + testmsg(NTEST+5)="73" + testmsgchk(NTEST+1)="KA1ABC WB9XYZ EN34 OOO" + testmsgchk(NTEST+2)="KA1ABC WB9XYZ OOO" + testmsgchk(NTEST+3)="RO" + testmsgchk(NTEST+4)="RRR" + testmsgchk(NTEST+5)="73" + nmsg=NTEST+5 + endif + + write(*,1010) +1010 format(" Message Decoded Err? Type Expected"/ & + 76("-")) + do imsg=1,nmsg + if(nmsg.gt.1) then + msg=testmsg(imsg) + msgchk=testmsgchk(imsg) + endif + call fmtmsg(msg,iz) !To upper case, collapse multiple blanks + msg0=msg + ichk=0 + call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report + msg1=msg !Message without "OOO" + + if(nspecial.gt.0) then !or is a shorthand message + if(nspecial.eq.2) decoded="RO" + if(nspecial.eq.3) decoded="RRR" + if(nspecial.eq.4) decoded="73" + itype=-1 + msgtype="Shorthand" + go to 10 + endif + + call gen9(msg,ichk,decoded,i4tone,itype) !Encode message into tone #s + + msgtype="" + if(itype.eq.1) msgtype="Std Msg" + if(itype.eq.2) msgtype="Type 1 pfx" + if(itype.eq.3) msgtype="Type 1 sfx" + if(itype.eq.4) msgtype="Type 2 pfx" + if(itype.eq.5) msgtype="Type 2 sfx" + if(itype.eq.6) msgtype="Free text" + + if(cok.eq."OOO") decoded(20:22)=cok + call fmtmsg(decoded,iz) + +10 bad=" " + expected = 'EXACT' + if (msg0.ne.msgchk) expected = 'TRUNCATED' + if (nmsg.eq.1) expected = 'UNKNOWN' + if(decoded.ne.msgchk) bad="*" + write(*,1020) imsg,msg0,decoded,bad,itype,msgtype,expected +1020 format(i2,'.',1x,a22,1x,a22,1x,a1,i3,":",a10,2x,a22) + enddo + + if(nmsg.eq.1) write(*,1030) i4tone +1030 format(/'Channel symbols'/(30i2)) + +999 end program jt9code diff --git a/lib/jt9com.f90 b/lib/jt9com.f90 new file mode 100644 index 00000000..f42e55d1 --- /dev/null +++ b/lib/jt9com.f90 @@ -0,0 +1,55 @@ + use, intrinsic :: iso_c_binding, only: c_int, c_short, c_float, c_char, c_bool + + include 'constants.f90' + + ! + ! these structures must be kept in sync with ../commons.h + ! + type, bind(C) :: params_block + integer(c_int) :: nutc + logical(c_bool) :: ndiskdat + integer(c_int) :: ntr + integer(c_int) :: nQSOProgress ! See MainWindow::m_QSOProgress for values + integer(c_int) :: nfqso + integer(c_int) :: nftx + logical(c_bool) :: newdat + integer(c_int) :: npts8 + integer(c_int) :: nfa + integer(c_int) :: nfsplit + integer(c_int) :: nfb + integer(c_int) :: ntol + integer(c_int) :: kin + integer(c_int) :: nzhsym + integer(c_int) :: nsubmode + logical(c_bool) :: nagain + integer(c_int) :: ndepth + logical(c_bool) :: lapon + integer(c_int) :: napwid + integer(c_int) :: ntxmode + integer(c_int) :: nmode + integer(c_int) :: minw + logical(c_bool) :: nclearave + integer(c_int) :: minsync + real(c_float) :: emedelay + real(c_float) :: dttol + integer(c_int) :: nlist + integer(c_int) :: listutc(10) + integer(c_int) :: n2pass + integer(c_int) :: nranera + integer(c_int) :: naggressive + logical(c_bool) :: nrobust + integer(c_int) :: nexp_decode + character(kind=c_char, len=20) :: datetime + character(kind=c_char, len=12) :: mycall + character(kind=c_char, len=6) :: mygrid + character(kind=c_char, len=12) :: hiscall + character(kind=c_char, len=6) :: hisgrid + end type params_block + + type, bind(C) :: dec_data + real(c_float) :: ss(184,NSMAX) + real(c_float) :: savg(NSMAX) + real(c_float) :: sred(5760) + integer(c_short) :: id2(NMAX) + type(params_block) :: params + end type dec_data diff --git a/lib/jt9fano.f90 b/lib/jt9fano.f90 index 0cd6b7a9..275e0e07 100644 --- a/lib/jt9fano.f90 +++ b/lib/jt9fano.f90 @@ -4,6 +4,7 @@ subroutine jt9fano(i1SoftSymbols,limit,nlim,msg) ! Input: i1SoftSymbols(207) - Single-bit soft symbols ! Output: msg - decoded message (blank if erasure) + use packjt character*22 msg integer*4 i4DecodedBytes(9) integer*4 i4Decoded6BitWords(12) @@ -11,7 +12,7 @@ subroutine jt9fano(i1SoftSymbols,limit,nlim,msg) integer*1 i1SoftSymbols(207) integer*1 i1DecodedBits(72) - real*4 xx0(0:255) + real*4 xx0(0:262) logical first integer*4 mettab(-128:127,0:1) @@ -48,7 +49,9 @@ subroutine jt9fano(i1SoftSymbols,limit,nlim,msg) -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & - -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966/ + -9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966,-9.966, & + 1.43370769e-019,2.64031087e-006,6.25548654e+028, & + 2.44565251e+020,4.74227538e+030,10497312.,7.74079654e-039/ save if(first) then @@ -81,7 +84,7 @@ subroutine jt9fano(i1SoftSymbols,limit,nlim,msg) enddo call unpackbits(i4DecodedBytes,nbytes,8,i1DecodedBits) call packbits(i1DecodedBits,12,6,i4Decoded6BitWords) - call unpackmsg(i4Decoded6BitWords,msg) !Unpack decoded msg + call unpackmsg(i4Decoded6BitWords,msg,.false.,' ') !Unpack decoded msg if(index(msg,'000AAA ').gt.0) msg=' ' endif diff --git a/lib/jt9sim.f90 b/lib/jt9sim.f90 index 21ed22a7..480d4930 100644 --- a/lib/jt9sim.f90 +++ b/lib/jt9sim.f90 @@ -3,6 +3,7 @@ program jt9sim ! Generate simulated data for testing of WSJT-X use wavhdr + use packjt parameter (NTMAX=120) parameter (NMAX=NTMAX*12000) type(hdr) h @@ -58,7 +59,6 @@ program jt9sim if(nsps.eq.0) stop 'Bad value for minutes.' f0=1400.d0 !Center frequency (Hz) - if(snrdb.gt.90.0) f0=fspan ! f0=3000.d0 !Center frequency (Hz) ! f0=1500.0 @@ -67,6 +67,9 @@ program jt9sim ! if(minutes.eq.30) f0=1025. + call init_random_seed() ! seed Fortran RANDOM_NUMBER generator + call sgran() ! see C rand generator (used in gran) + h=default_header(12000,npts) k=0 !Silence compiler warning @@ -95,7 +98,7 @@ program jt9sim endif if(msg0.ne.' ') then - call genjt9(message,0,msgsent,i4tone,itype) !Encode message into tone #s + call gen9(message,0,msgsent,i4tone,itype) !Encode message into tone #s endif rewind 12 @@ -104,7 +107,7 @@ program jt9sim if(msg0.eq.' ') then read(12,1004) message !Use pre-generated message texts 1004 format(a22) - call genjt9(message,0,msgsent,i4tone,itype) + call gen9(message,0,msgsent,i4tone,itype) endif f=f0 diff --git a/lib/jt9w.f90 b/lib/jt9w.f90 new file mode 100644 index 00000000..47623e7b --- /dev/null +++ b/lib/jt9w.f90 @@ -0,0 +1,28 @@ +program jt9w + + parameter (NSMAX=6827,NZMAX=60*12000) + real ss(184,NSMAX) + real ref(NSMAX) + integer*2 id2(NZMAX) + character*12 arg + character*22 decoded + + call getarg(1,arg) + read(arg,*) iutc + + open(20,file='refspec.dat',status='old') + do i=1,NSMAX + read(20,*) j,freq,ref(i) + enddo + + do ifile=1,999 + read(60,end=999) nutc,nfqso,ntol,ndepth,nmode,nsubmode,ss,id2 + if(nutc.ne.iutc) cycle + ntol=100 + call decode9w(nutc,nfqso,ntol,nsubmode,ss,id2,sync,nsnr,xdt,freq,decoded) + write(*,1100) nutc,nsnr,xdt1-1.0,nint(freq),decoded +1100 format(i4.4,i4,f5.1,i5,1x,'@',1x,a22) + exit + enddo + +999 end program jt9w diff --git a/lib/jtmsg.f90 b/lib/jtmsg.f90 new file mode 100644 index 00000000..ff7483ad --- /dev/null +++ b/lib/jtmsg.f90 @@ -0,0 +1,131 @@ +subroutine jtmsg(msg,iflag) + +! Attempts to identify false decodes in JT-style messages. + +! Returns iflag with sum of bits as follows: +! ------------------------------------------ +! 1 Grid/Report invalid +! 2 Second callsign invalid +! 4 First callsign invalid +! 8 Very unlikely free text +! 16 Questionable free text +! 0 Message is probably OK +! ------------------------------------------ + + character*22 msg,t + character*13 w1,w2,w3,w + character*6 bc1,bc2,bc3 + character*1 c + logical c1ok,c2ok,c3ok,isdigit,isletter,isgrid4 + +! Statement functions + isdigit(c)=(ichar(c).ge.ichar('0')) .and. (ichar(c).le.ichar('9')) + isletter(c)=(ichar(c).ge.ichar('A')) .and. (ichar(c).le.ichar('Z')) + isgrid4(w)=(len_trim(w).eq.4 .and. & + ichar(w(1:1)).ge.ichar('A') .and. ichar(w(1:1)).le.ichar('R') .and. & + ichar(w(2:2)).ge.ichar('A') .and. ichar(w(2:2)).le.ichar('R') .and. & + ichar(w(3:3)).ge.ichar('0') .and. ichar(w(3:3)).le.ichar('9') .and. & + ichar(w(4:4)).ge.ichar('0') .and. ichar(w(4:4)).le.ichar('9')) + + t=trim(msg) !Temporary copy of msg + nt=len_trim(t) + +! Check for standard messages +! Insert underscore in "CQ AA " to "CQ ZZ ", "CQ nnn " to make them one word. + if(t(1:3).eq.'CQ ' .and. isletter(t(4:4)) .and. & + isletter(t(5:5)) .and. t(6:6).eq.' ') t(3:3)='_' + if(t(1:3).eq.'CQ ' .and. isdigit(t(4:4)) .and. & + isdigit(t(5:5)) .and. isdigit(t(6:6)) .and. t(7:7).eq.' ') t(3:3)='_' + +! Parse first three words + w1=' ' + w2=' ' + w3=' ' + i1=index(t,' ') + if(i1.gt.0) w1(1:i1-1)=t(1:i1-1) + t=t(i1+1:) + i2=index(t,' ') + if(i2.gt.0) w2(1:i2-1)=t(1:i2-1) + t=t(i2+1:) + i3=index(t,' ') + if(i3.gt.0) w3(1:i3-1)=t(1:i3-1) + + if(w1(1:3).eq.'CQ ' .or. w1(1:3).eq.'CQ_' .or. w1(1:3).eq.'DE ' .or. & + w1(1:4).eq.'QRZ ') then +! CQ/DE/QRZ: Should have one good callsign in w2 and maybe a grid/rpt in w3 + call chkcall(w2,bc2,c2ok) + iflag=0 + if(.not.c2ok) iflag=iflag+2 + if(len_trim(w3).ne.0 .and. (.not.isgrid4(w3))) iflag=iflag+1 + if(w1(1:3).eq.'DE ' .and. c2ok) iflag=0 + if(iflag.eq.0) return + endif + +! Check for two calls and maybe a grid, rpt, R+rpr, RRR, or 73 + iflag=0 + call chkcall(w1,bc1,c1ok) + call chkcall(w2,bc2,c2ok) + if(.not.c1ok) iflag=iflag+4 + if(.not.c2ok) iflag=iflag+2 + if(len_trim(w3).ne.0 .and. (.not.isgrid4(w3)) .and. & + w3(1:1).ne.'+' .and. w3(1:1).ne.'-' .and. & + w3(1:2).ne.'R+' .and. w3(1:2).ne.'R-' .and. & + w3(1:3).ne.'73 ' .and. w3(1:4).ne.'RRR ') iflag=iflag+1 + call chkcall(w3,bc3,c3ok) +! Allow(?) non-standard messages of the form CQ AS OC K1JT + if(w1(1:3).eq.'CQ_'.and.isletter(w2(1:1)).and.isletter(w2(2:2)).and. & + w2(3:3).eq.' '.and.c3ok) iflag=0 + if(iflag.eq.0 .or. nt.gt.13) return + +! Check for plausible free text + + nc=0 + np=0 + do i=1,13 + c=msg(i:i) + if(c.ne.' ') nc=nc+1 !Number of non-blank characters + if(c.eq.'+') np=np+1 !Number of punctuation characters + if(c.eq.'-') np=np+1 + if(c.eq.'.') np=np+1 + if(c.eq.'/') np=np+1 + if(c.eq.'?') np=np+1 + enddo + nb=13-nc !Number of blanks + iflag=16 !Mark as potentially questionable + if(nc.ge.12 .or. (nc.ge.11 .and. np.gt.0)) then + iflag=8 !Unlikely free text, flag it + endif + +! Save messages containing some common words + if(msg(1:3).eq.'CQ ') iflag=0 + if(index(msg,'DE ').gt.0) iflag=0 + if(index(msg,'TU ').gt.0) iflag=0 + if(index(msg,' TU').gt.0) iflag=0 + if(index(msg,'73 ').gt.0) iflag=0 + if(index(msg,' 73').gt.0) iflag=0 + if(index(msg,'TNX').gt.0) iflag=0 + if(index(msg,'THX').gt.0) iflag=0 + if(index(msg,'EQSL').gt.0) iflag=0 + if(index(msg,'LOTW').gt.0) iflag=0 + if(index(msg,'DECOD').gt.0) iflag=0 + if(index(msg,'CHK').gt.0) iflag=0 + if(index(msg,'CLK').gt.0) iflag=0 + if(index(msg,'CLOCK').gt.0) iflag=0 + if(index(msg,'LOG').gt.0) iflag=0 + if(index(msg,'QRM').gt.0) iflag=0 + if(index(msg,'QSY').gt.0) iflag=0 + if(index(msg,'TEST').gt.0) iflag=0 + if(index(msg,'CQDX').gt.0) iflag=0 + if(index(msg,'CALL').gt.0) iflag=0 + if(index(msg,'QRZ').gt.0) iflag=0 + if(index(msg,'AUTO').gt.0) iflag=0 + if(index(msg,'PHOTO').gt.0) iflag=0 + if(index(msg,'HYBRID').gt.0) iflag=0 + + if(c1ok .and. w1(1:6).eq.bc1) iflag=0 + if(c2ok .and. w2(1:6).eq.bc2) iflag=0 + + if(nb.ge.4) iflag=0 + + return +end subroutine jtmsg diff --git a/lib/k2grid.f90 b/lib/k2grid.f90 deleted file mode 100644 index aa763157..00000000 --- a/lib/k2grid.f90 +++ /dev/null @@ -1,12 +0,0 @@ -subroutine k2grid(k,grid) - character grid*6 - - nlong=2*mod((k-1)/5,90)-179 - if(k.gt.450) nlong=nlong+180 - nlat=mod(k-1,5)+ 85 - dlat=nlat - dlong=nlong - call deg2grid(dlong,dlat,grid) - - return -end subroutine k2grid diff --git a/lib/ldpc/COPYRIGHT b/lib/ldpc/COPYRIGHT new file mode 100755 index 00000000..9cd0d7f6 --- /dev/null +++ b/lib/ldpc/COPYRIGHT @@ -0,0 +1,15 @@ +Except as otherwise specified, all program code and documentation in this +directory is copyright (c) 1995-2012 by Radford M. Neal. + +Permission is granted for anyone to copy, use, modify, and distribute +these programs and accompanying documents for any purpose, provided +this copyright notice is retained and prominently displayed, and note +is made of any changes made to these programs. These programs and +documents are distributed without any warranty, express or implied. +As the programs were written for research purposes only, they have not +been tested to the degree that would be advisable in any important +application. All use of these programs is entirely at the user's own +risk. + +Some routines in the module rand.c are taken from the GNU C Library, +and are copyrighted as described there and in the file LGPL. diff --git a/lib/ldpc/LDPC-install b/lib/ldpc/LDPC-install new file mode 100755 index 00000000..0ca12ace --- /dev/null +++ b/lib/ldpc/LDPC-install @@ -0,0 +1,28 @@ +#!/bin/sh + +# Copy the LPDC programs to the directory specified. The program file +# might be the name of the program, or (eg, on Cygwin) the name of the +# program with .exe appended. + +if [ x$1 == x -o x$2 != x ]; then + echo Usage: LDPC-install bin-directory + exit 1 +fi + +echo Installing LPDC programs in $1 + +mkdir -p $1 + +for prog in make-pchk alist-to-pchk pchk-to-alist \ + make-ldpc print-pchk make-gen print-gen \ + rand-src encode transmit decode extract verify; do + if [ -f $prog ]; then + cp $prog $1 + elif [ -f $prog.exe ]; then + cp $prog.exe $1 + else + echo No program $prog to install + fi +done + +echo Done diff --git a/lib/ldpc/LGPL b/lib/ldpc/LGPL new file mode 100755 index 00000000..7106bb0a --- /dev/null +++ b/lib/ldpc/LGPL @@ -0,0 +1,463 @@ +The following is the license under which the portions of the GNU C +library used in the rand.c module is distributed. Note that this +license does not apply to the rest of this software. + + +GNU LESSER GENERAL PUBLIC LICENSE +Version 2.1, February 1999 + +Copyright (C) 1991, 1999 Free Software Foundation, Inc. +59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts +as the successor of the GNU Library Public License, version 2, hence +the version number 2.1.] + +Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + +This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + +When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + +To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + +For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + +Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + +Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + +When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + +We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + +For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + +Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + +The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + +GNU LESSER GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of e Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + +You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + +2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) The modified work must itself be a software library. + +b) You must cause the files modified to carry prominent notices +stating that you changed the files and the date of any change. + +c) You must cause the whole of the work to be licensed at no +charge to all third parties under the terms of this License. + +d) If a facility in the modified Library refers to a function or a +table of data to be supplied by an application program that uses +the facility, other than as an argument passed when the facility +is invoked, then you must make a good faith effort to ensure that, +in the event an application does not supply such function or +table, the facility still operates, and performs whatever part of +its purpose remains meaningful. + +(For example, a function in a library to compute square roots has +a purpose that is entirely well-defined independent of the +application. Therefore, Subsection 2d requires that any +application-supplied function or table used by this function must +be optional: if the application does not supply it, the square +root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + +Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + +However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + +When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + +If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + +6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + +a) Accompany the work with the complete corresponding +machine-readable source code for the Library including whatever +changes were used in the work (which must be distributed under +Sections 1 and 2 above); and, if the work is an executable linked +with the Library, with the complete machine-readable "work that +uses the Library", as object code and/or source code, so that the +user can modify the Library and then relink to produce a modified +executable containing the modified Library. (It is understood +that the user who changes the contents of definitions files in the +Library will not necessarily be able to recompile the application +to use the modified definitions.) + +b) Use a suitable shared library mechanism for linking with the +Library. A suitable mechanism is one that (1) uses at run time a +copy of the library already present on the user's computer system, +rather than copying library functions into the executable, and (2) +will operate properly with a modified version of the library, if +the user installs one, as long as the modified version is +interface-compatible with the version that the work was made with. + +c) Accompany the work with a written offer, valid for at +least three years, to give the same user the materials +specified in Subsection 6a, above, for a charge no more +than the cost of performing this distribution. + +d) If distribution of the work is made by offering access to copy +from a designated place, offer equivalent access to copy the above +specified materials from the same place. + +e) Verify that the user has already received a copy of these +materials or that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + +It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + +7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + +a) Accompany the combined library with a copy of the same work +based on the Library, uncombined with any other library +facilities. This must be distributed under the terms of the +Sections above. + +b) Give prominent notice with the combined library of the fact +that part of it is a work based on the Library, and explaining +where to find the accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + +11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + +NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + +END OF TERMS AND CONDITIONS diff --git a/lib/ldpc/Makefile b/lib/ldpc/Makefile new file mode 100755 index 00000000..5f539ee8 --- /dev/null +++ b/lib/ldpc/Makefile @@ -0,0 +1,115 @@ +# MAKEFILE FOR LDPC PROGRAMS & ASSOCIATED UTILITIES. + +# Copyright (c) 1995-2012 by Radford M. Neal. +# +# Permission is granted for anyone to copy, use, modify, and distribute +# these programs and accompanying documents for any purpose, provided +# this copyright notice is retained and prominently displayed, and note +# is made of any changes made to these programs. These programs and +# documents are distributed without any warranty, express or implied. +# As the programs were written for research purposes only, they have not +# been tested to the degree that would be advisable in any important +# application. All use of these programs is entirely at the user's own +# risk. + + +# NOTE: The natural random numbers in "randfile" are accessed by the +# 'rand' module via a path to this directory. Change the definition of +# RAND_FILE in the compilation command for rand.c below if this is not +# appropriate. + +# NOTE: This makefile is trivial, simply recompiling everything from +# scratch every time. Since this takes only about 5 seconds on a modern +# PC, there's no point in putting in dependency-based rules, which just +# make things more complex and error-prone. + + +COMPILE = cc -c -O # Command to compile a module from .c to .o +LINK = cc # Command to link a program + + +# MAKE ALL THE MAIN PROGRAMS. First makes the modules used. + +progs: modules + $(COMPILE) make-pchk.c + $(LINK) make-pchk.o mod2sparse.o mod2dense.o mod2convert.o \ + rcode.o alloc.o intio.o open.o -lm -o make-pchk + $(COMPILE) alist-to-pchk.c + $(LINK) alist-to-pchk.o mod2sparse.o mod2dense.o mod2convert.o \ + rcode.o alloc.o intio.o open.o -lm -o alist-to-pchk + $(COMPILE) pchk-to-alist.c + $(LINK) pchk-to-alist.o mod2sparse.o mod2dense.o mod2convert.o \ + rcode.o alloc.o intio.o open.o -lm -o pchk-to-alist + $(COMPILE) make-ldpc.c + $(LINK) make-ldpc.o mod2sparse.o mod2dense.o mod2convert.o \ + rcode.o rand.o alloc.o intio.o open.o distrib.o -lm -o make-ldpc + $(COMPILE) print-pchk.c + $(LINK) print-pchk.o mod2sparse.o mod2dense.o mod2convert.o \ + rcode.o rand.o alloc.o intio.o open.o -lm -o print-pchk + $(COMPILE) make-gen.c + $(LINK) make-gen.o mod2sparse.o mod2dense.o mod2convert.o \ + rcode.o alloc.o intio.o open.o -lm -o make-gen + $(COMPILE) print-gen.c + $(LINK) print-gen.o mod2sparse.o mod2dense.o mod2convert.o \ + rcode.o rand.o alloc.o intio.o open.o -lm -o print-gen + $(COMPILE) rand-src.c + $(LINK) rand-src.o rand.o open.o -lm -o rand-src + $(COMPILE) encode.c + $(LINK) encode.o mod2sparse.o mod2dense.o mod2convert.o \ + enc.o rcode.o rand.o alloc.o intio.o blockio.o open.o -lm -o encode + $(COMPILE) transmit.c + $(LINK) transmit.o channel.o rand.o open.o -lm -o transmit + $(COMPILE) decode.c + $(LINK) decode.o channel.o mod2sparse.o mod2dense.o mod2convert.o \ + enc.o check.o \ + rcode.o rand.o alloc.o intio.o blockio.o dec.o open.o -lm -o decode + $(COMPILE) extract.c + $(LINK) extract.o mod2sparse.o mod2dense.o mod2convert.o \ + rcode.o alloc.o intio.o blockio.o open.o -lm -o extract + $(COMPILE) verify.c + $(LINK) verify.o mod2sparse.o mod2dense.o mod2convert.o check.o \ + rcode.o alloc.o intio.o blockio.o open.o -lm -o verify + +# MAKE THE TEST PROGRAMS. First makes the modules used. + +tests: modules + $(COMPILE) mod2dense-test.c + $(LINK) mod2dense-test.o mod2dense.o alloc.o intio.o \ + -lm -o mod2dense-test + $(COMPILE) mod2sparse-test.c + $(LINK) mod2sparse-test.o mod2sparse.o alloc.o intio.o \ + -lm -o mod2sparse-test + $(COMPILE) mod2convert-test.c + $(LINK) mod2convert-test.o mod2convert.o mod2dense.o mod2sparse.o \ + alloc.o intio.o rand.o open.o -lm -o mod2convert-test + $(COMPILE) rand-test.c + $(LINK) rand-test.o rand.o -lm -o rand-test + + +# MAKE THE MODULES USED BY THE PROGRAMS. + +modules: + $(COMPILE) rcode.c + $(COMPILE) channel.c + $(COMPILE) dec.c + $(COMPILE) enc.c + $(COMPILE) alloc.c + $(COMPILE) intio.c + $(COMPILE) blockio.c + $(COMPILE) check.c + $(COMPILE) open.c + $(COMPILE) mod2dense.c + $(COMPILE) mod2sparse.c + $(COMPILE) mod2convert.c + $(COMPILE) distrib.c + $(COMPILE) -DRAND_FILE=\"`pwd`/randfile\" rand.c + + +# CLEAN UP ALL PROGRAMS AND REMOVE ALL FILES PRODUCED BY TESTS AND EXAMPLES. + +clean: + rm -f core *.o *.exe ex-*.* test-file \ + make-pchk alist-to-pchk pchk-to-alist \ + make-ldpc print-pchk make-gen print-gen \ + rand-src encode transmit decode extract verify \ + mod2dense-test mod2sparse-test mod2convert-test rand-test diff --git a/lib/ldpc/Makefile.msk_osx b/lib/ldpc/Makefile.msk_osx new file mode 100644 index 00000000..45aa36a4 --- /dev/null +++ b/lib/ldpc/Makefile.msk_osx @@ -0,0 +1,39 @@ +# Compilers +CC = gcc +CXX = g++ +FC = gfortran +AR = ar cr +RANLIB = ranlib +MKDIR = mkdir -p +CP = cp +RM = rm -f + +FFLAGS = -O2 -fbounds-check -Wall -Wno-conversion +CFLAGS = -O2 -I. + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: ldpcsim + +OBJS = ldpcsim.o alloc.o rcode.o dec.o enc.o \ + intio.o blockio.o check.o open.o mod2dense.o \ + mod2sparse.o mod2convert.o distrib.o rand.o gran.o + +ldpcsim:$(OBJS) + $(FC) -o ldpcsim $(OBJS) + +rand.o: + $(CC) $(CFLAGS) -DRAND_FILE=\"./randfile\" -c rand.c + +clean: + $(RM) *.o msksim diff --git a/lib/ldpc/README b/lib/ldpc/README new file mode 100755 index 00000000..dd34af58 --- /dev/null +++ b/lib/ldpc/README @@ -0,0 +1,6 @@ +This is a collection of programs and modules, written in C, that +support research and education concerning Low Density Parity Check +(LDPC) codes. + +See index.html in this directory for an index to the documentation. +Copyright information can be found there, and in the file COPYRIGHT. diff --git a/lib/ldpc/alist-to-pchk.c b/lib/ldpc/alist-to-pchk.c new file mode 100755 index 00000000..21831ded --- /dev/null +++ b/lib/ldpc/alist-to-pchk.c @@ -0,0 +1,168 @@ +/* ALIST-TO-PCHK.C - Convert a parity check matrix from alist format. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include +#include + +#include "alloc.h" +#include "intio.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" + + +void bad_alist_file(void); +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + char *alist_file, *pchk_file; + FILE *af, *pf; + int mxrw, mxcw; + int *rw, *cw; + int i, j, k; + int tot, trans; + int nxt; + + trans = 0; + + for (;;) + { + if (argc>1 && strcmp(argv[1],"-t")==0) + { trans = 1; + argc -= 1; + argv += 1; + } + else + { break; + } + } + + if (argc!=3) + { usage(); + } + + pchk_file = argv[2]; + alist_file = argv[1]; + + af = open_file_std(alist_file,"r"); + + if (af==NULL) + { fprintf(stderr,"Can't open alist file: %s\n",alist_file); + exit(1); + } + + if (fscanf(af,"%d",&M)!=1 || M<1 + || fscanf(af,"%d",&N)!=1 || N<1 + || fscanf(af,"%d",&mxrw)!=1 || mxrw<0 || mxrw>N + || fscanf(af,"%d",&mxcw)!=1 || mxcw<0 || mxcw>M) + { bad_alist_file(); + } + + rw = (int *) chk_alloc (M, sizeof *rw); + + for (i = 0; iN) + { bad_alist_file(); + } + } + + cw = (int *) chk_alloc (N, sizeof *cw); + + for (j = 0; jM) + { bad_alist_file(); + } + } + + H = mod2sparse_allocate(M,N); + + do { if (fscanf(af,"%d",&nxt)!=1) nxt = -1; } while (nxt==0); + + tot = 0; + + for (i = 0; iN || mod2sparse_find(H,i,nxt-1)) + { bad_alist_file(); + } + mod2sparse_insert(H,i,nxt-1); + tot += 1; + do { if (fscanf(af,"%d",&nxt)!=1) nxt = -1; } while (nxt==0); + } + } + + for (j = 0; jM || !mod2sparse_find(H,nxt-1,j)) + { bad_alist_file(); + } + tot -= 1; + do { if (fscanf(af,"%d",&nxt)!=1) nxt = -1; } while (nxt==0); + } + } + + if (tot!=0 || nxt!=-1 || !feof(af)) + { bad_alist_file(); + } + + if (trans) + { mod2sparse *HT; + HT = H; + H = mod2sparse_allocate(N,M); + mod2sparse_transpose(HT,H); + } + + pf = open_file_std(pchk_file,"wb"); + if (pf==NULL) + { fprintf(stderr,"Can't create parity check file: %s\n",pchk_file); + exit(1); + } + + intio_write(pf,('P'<<8)+0x80); + + if (ferror(pf) || !mod2sparse_write(pf,H) || fclose(pf)!=0) + { fprintf(stderr,"Error writing to parity check file %s\n",pchk_file); + exit(1); + } + + return 0; +} + + +/* COMPLAIN THAT ALIST FILE IS BAD. */ + +void bad_alist_file() +{ fprintf(stderr,"Alist file doesn't have the right format\n"); + exit(1); +} + + +/* PRINT USAGE MESSAGE AND EXIT. */ + +void usage(void) +{ fprintf(stderr,"Usage: alist-to-pchk [ -t ] alist-file pchk-file\n"); + exit(1); +} diff --git a/lib/ldpc/alloc.c b/lib/ldpc/alloc.c new file mode 100755 index 00000000..f289ceb8 --- /dev/null +++ b/lib/ldpc/alloc.c @@ -0,0 +1,42 @@ +/* ALLOC.C - Routine to allocate memory and complain if it doesn't work. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include + +#include "alloc.h" + + +/* ALLOCATE SPACE AND CHECK FOR ERROR. Calls 'calloc' to allocate space, + and then displays an error message and exits if the space couldn't be + found. */ + +void *chk_alloc +( unsigned n, /* Number of elements */ + unsigned size /* Size of each element */ +) +{ + void *p; + + p = calloc(n,size); + + if (p==0) + { fprintf(stderr,"Ran out of memory (while trying to allocate %d bytes)\n", + n*size); + exit(1); + } + + return p; +} diff --git a/lib/ldpc/alloc.h b/lib/ldpc/alloc.h new file mode 100755 index 00000000..aa1fb173 --- /dev/null +++ b/lib/ldpc/alloc.h @@ -0,0 +1,18 @@ +/* ALLOC.H - Interface to memory allocation procedure. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + + +void *chk_alloc (unsigned, unsigned); /* Calls 'calloc' and exits with error + if it fails */ diff --git a/lib/ldpc/blockio.c b/lib/ldpc/blockio.c new file mode 100755 index 00000000..c9d08632 --- /dev/null +++ b/lib/ldpc/blockio.c @@ -0,0 +1,85 @@ +/* BLOCKIO.C - Routines to read/write blocks of bits from/to a text file. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include + +#include "blockio.h" + + +int blockio_flush = 0; /* Should blocks written be immediately flushed? */ + + +/* READ A BLOCK OF BITS. The bits must be given as '0' or '1' characters, + with whitespace allowed (but not required) between bits. Returns 0 if + a block is read successfully, and EOF if eof or an error occurs. If + EOF is returned, a warning will be printed if a partial block had already + been read. */ + +int blockio_read +( FILE *f, /* File to read from */ + char *b, /* Place to store bits read */ + int l /* Length of block */ +) +{ + int i, c; + + for (i = 0; i0) + { fprintf(stderr, + "Warning: Short block (%d long) at end of input file ignored\n",i); + } + return EOF; + } + } while (c==' ' || c=='\t' || c=='\n' || c=='\r'); + + if (c!='0' && c!='1') + { fprintf(stderr,"Bad character in binary file (not '0' or '1')\n"); + exit(1); + } + + b[i] = c=='1'; + } + + return 0; +} + + +/* WRITE A BLOCK OF BITS. Bits are written as '0' and '1' characters, with + no spaces between them, followed by a newline. */ + +void blockio_write +( FILE *f, /* File to write to */ + char *b, /* Block of bits to write */ + int l /* Length of block */ +) +{ + int i; + + for (i = 0; i +#include +#include +#include + +#include "channel.h" + + +/* GLOBAL VARIABLES. Declared in channel.h. */ + +channel_type channel; /* Type of channel */ + +double error_prob; /* Error probability for BSC */ +double std_dev; /* Noise standard deviation for AWGN */ +double lwidth; /* Width of noise distribution for AWLN */ + + +/* PARSE A COMMAND-LINE SPECIFICATION OF A CHANNEL. Takes a pointer to an + argument list and an argument count; returns the number of arguments that + make up a channel specification at this point in the command line. Returns + zero if the argument list does not start with a channel specification. + Returns -1 if there seems to be a channel specification here, but it's + invalid. + + Sets the variables declared in channel.h to the type and parameters of + the channel. + */ + +int channel_parse +( char **argv, /* Pointer to argument list */ + int argc /* Number of arguments in list */ +) +{ + char junk; + + if (argc==0) return 0; + + if (strcmp(argv[0],"bsc")==0 || strcmp(argv[0],"BSC")==0) + { + channel = BSC; + if (argc<2 || sscanf(argv[1],"%lf%c",&error_prob,&junk)!=1 + || error_prob<=0 || error_prob>=1) + { return -1; + } + else + { return 2; + } + } + else if (strcmp(argv[0],"awgn")==0 || strcmp(argv[0],"AWGN")==0) + { + channel = AWGN; + if (argc<2 || sscanf(argv[1],"%lf%c",&std_dev,&junk)!=1 + || std_dev<=0) + { return -1; + } + else + { return 2; + } + } + else if (strcmp(argv[0],"awln")==0 || strcmp(argv[0],"AWLN")==0) + { + channel = AWLN; + if (argc<2 || sscanf(argv[1],"%lf%c",&lwidth,&junk)!=1 + || lwidth<=0) + { return -1; + } + else + { return 2; + } + } + else + { + return 0; + } +} + + +/* PRINT USAGE MESSAGE REGARDING CHANNEL SPECIFICATIONS. */ + +void channel_usage(void) +{ + fprintf(stderr, + "Channel: bsc error-probability | awgn standard-deviation | awln width\n"); +} diff --git a/lib/ldpc/channel.h b/lib/ldpc/channel.h new file mode 100755 index 00000000..0522e856 --- /dev/null +++ b/lib/ldpc/channel.h @@ -0,0 +1,32 @@ +/* CHANNEL.H - Declarations regarding channels. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + + +/* TYPES OF CHANNEL, AND CHANNEL PARAMETERS. The global variables declared + here are located in channel.c. */ + +typedef enum { BSC, AWGN, AWLN } channel_type; + +extern channel_type channel; /* Type of channel */ + +extern double error_prob; /* Error probability for BSC */ +extern double std_dev; /* Noise standard deviation for AWGN */ +extern double lwidth; /* Width of noise distributoin for AWLN */ + + +/* PROCEDURES TO DO WITH CHANNELS. */ + +int channel_parse (char **, int); +void channel_usage (void); diff --git a/lib/ldpc/channel.html b/lib/ldpc/channel.html new file mode 100755 index 00000000..ad512919 --- /dev/null +++ b/lib/ldpc/channel.html @@ -0,0 +1,182 @@ + + + Transmission Through a Simulated Channel + + + + +

Transmission Through a Simulated Channel

+ +

Once a codeword has been found to represent a source message, it +can be sent through a channel, with the result that certain +data is received as the output of the channel, which will be related +to the codeword sent, but with random noise. This software currently +handles only memoryless binary channels, for which each bit sent +through the channel results in a separate piece of data being +received, and the noise affecting one bit is independent of the noise +affecting other bits. + +

For a Binary Symmetric Channel (BSC), each bit sent +results in a bit being received. The bit received differs from the +bit sent with some error probability, p, which is the same for +0 bits and for 1 bits. In other words, the probability distribution +for the bit received given the bit sent is as follows: +

+P(receive 1 | send 1) = P(receive 0 | send 0) = 1-p
+P(receive 1 | send 0) = P(receive 0 | send 1) = p +
+ +

For an Additive White Gaussian Noise (AWGN) channel, the +data received at each time is equal to the data sent plus Gaussian +noise with mean zero and some standard deviation, s, +independently for each bit. For this software, the data sent is -1 +for a 0 bit and +1 for a 1 bit. In other words, the distribution +of the received data given the bit sent is as follows: +

+data received | send 1 ~ N(+1,s2)
+data received | send 0 ~ N(-1,s2) +
+ +

It is typically assumed that the standard deviation of the noise +varies with the rate at which bits are sent, increasing in proportion +to the square root of the rate. The error rate obtained from sending +unencoded bits at rate R will then be the same as is obtained +using a code that repeats each bit n times, and sends these +bits at rate nR (assuming optimal decoding of each bit by +thresholding the sum of the n channel outputs corresponding to +that bit). Another way of looking at this scaling for s is +that when bits are send at a lower rate, the receiver will be +accumulating the channel output for a longer time, with the result +that the amount of noise will decrease (relative to the signal) as a +result of averaging. + +

To account for this, it is common to compare codes for AWGN +channels in terms of their bit error rate and the value of +

+Eb / N0 += 1 / 2Rs2 +
+at which they operate, where R=K/N is the rate +of the code, and s is the noise level at which the code +achieves the quoted bit error rate. Hence, a code operating at a lower +rate is allowed to assume a lower noise level to make the comparison fair. +It is common to quote +Eb / +N0 in decibels (db), equal to +10 log10(Eb +/ N0). + +

The Additive White Logistic Noise (AWLN) channel is similar +to the AWGN channel, except that the noise comes from a logistic rather +than a Gaussian distribution. The probability density function for the +noise is +

+(1/w) exp(-n/w) / [1 + exp(-n/w)]2 +
+where n is the amount of noise, and w is a width parameter +for the distribution, analogous to the s parameter for +Gaussian noise. (However, w is not equal to the standard deviation +for the logistic distribution, which is +sqrt(pi2/3)w.) Note: Although I've +named this channel in analogy with the AWGN channel, it does not share +the properties discussed above regarding how noise levels would be expected +to change when the data rate changes. + + +


transmit: Transmit bits through a +simulated channel. + +
+transmit encoded-file|n-zeros received-file seed channel
+
+
+where channel is one of the following: +
+bsc error-probability
+
+awgn standard-deviation
+
+awln width
+
+
+
+ +

Simulates the transmission of the bits in +encoded-file through a channel, with the received data +being stored in received-file. Typically, +encoded-file will have been produced by the encode program, but it could +also come from rand-src +or another program. If newlines separate blocks in +encoded-file, these block boundaries will be preserved +in received-file. + +

Alternatively, a count of zeros to transmit can be given, rather +than a encoded-file. This count can be the product of the +block size and the number of blocks, written with x +separating these numbers, with no spaces. The +received-file will mark the block boundaries with +newlines, assuming a block size of one if a simple bit count is given. +Note that zero messages are sufficient for assessing the performance +of a linear code with a symmetrical channel and a symmetrical decoding +algorithm. Warning: Ties, messages that lead to floating-point +overflow, and program bugs can easily make a decoding algorithm +non-symmetrical, so it's best not to test exclusively on zero +messages. Indeed, it is best not to do this at all unless you +really need to avoid the time needed to generate and encode random +messages. + +

The transmission will be corrupted by random noise, which will be +generated pseudo-randomly based on seed. The actual +random seed used will be seed times 10 plus 3, so that +the stream of pseudo-random numbers will not be the same as any that +might have been used by another program. + +

The fourth argument specifies the type of channel, currently either +bsc (or BSC) for the Binary Symmetric Channel, or +awgn (or AWGN) for the Additive White Gaussian +Noise channel, or awln (or AWLN) for the Additive White +Logistic Noise channel. The channel type is followed by an argument +specifying the characteristics of the channel, as follows: +

+

BSC: The probability that a bit will be flipped by noise - ie, the + probability that the bit received is an error. + +

AWGN: The standard deviation of the Gaussian noise that is added to the + encodings of the bits. + +

AWLN: The width parameter of the logistic distribution for the noise + that is added to the encodings of the bits. +

+ +See the description of channel transmission +for more details. + +

Examples: The command: +

    +
  • transmit 10x3 rec 1 bsc 0.1 +
+will simulate the transmission of 30 zero bits (3 blocks of size 10) through +a Binary Symmetric Channel with error probability of 0.1. The result will +be to store something like the following in the file rec: +
+0000000000
+1000000000
+0100000000
+
+If an AWGN channel is used instead, as follows: +
    +
  • transmit 10x3 rec 1 awgn 0.5 +
+then the file rec will contain data such as: +
+ -1.36 -0.86 -0.80 -1.19 -1.18 -0.64 -0.31 -1.16 -1.56 -0.79
+ -2.20 -1.62 -0.53 -1.29 -1.08 -2.05 -0.75 -1.22 -0.81 -0.52
+ -0.86 -0.34 -1.10 -1.30 -1.10 -1.20 -0.37 -1.07 -0.22 -1.46
+
+ +
+ +Back to index for LDPC software + + diff --git a/lib/ldpc/check.c b/lib/ldpc/check.c new file mode 100755 index 00000000..e22b1dd9 --- /dev/null +++ b/lib/ldpc/check.c @@ -0,0 +1,177 @@ +/* CHECK.C - Compute parity checks and other stats on decodings. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include + +#include "mod2sparse.h" +#include "check.h" + + + +/* COMPUTE PARITY CHECKS. Returns the number of parity checks violated by + dblk. The results of all the parity checks are stored in pchk. */ + +int check +( mod2sparse *H, /* Parity check matrix */ + char *dblk, /* Guess for codeword */ + char *pchk /* Place to store parity checks */ +) +{ + int M, i, c; + + M = mod2sparse_rows(H); + + mod2sparse_mulvec (H, dblk, pchk); + + c = 0; + for (i = 0; i1); + } + + return changed; +} + + +/* COMPUTE THE EXPECTED NUMBER OF PARITY CHECK ERRORS. Computes the + expected number of parity check errors with respect to the distribution + given by the bit probabilities passed, with bits assumed to be independent. + */ + +double expected_parity_errors +( mod2sparse *H, /* Parity check matrix */ + double *bpr /* Bit probabilities */ +) +{ + mod2entry *f; + double ee, p; + int M, i, j; + + M = mod2sparse_rows(H); + + ee = 0; + + for (i = 0; i0) + { ll -= bpr[j]*log(1+1/lratio[j]); + } + if (bpr[j]<1) + { ll -= (1-bpr[j])*log(1+lratio[j]); + } + } + + return ll; +} + + +/* COMPUTE ENTROPY FROM BIT PROBABILITIES. Computes the entropy of the + distribution given by the bit probabilities, on the assumption that + bits are independent. + */ + +double entropy +( double *bpr, /* Bit probabilities */ + int N /* Length of codeword */ +) +{ + double e; + int j; + + e = 0; + for (j = 0; j0 && bpr[j]<1) + { e -= bpr[j]*log(bpr[j]) + (1-bpr[j])*log(1-bpr[j]); + } + } + + return e/log(2.0); +} diff --git a/lib/ldpc/check.h b/lib/ldpc/check.h new file mode 100755 index 00000000..7ac00544 --- /dev/null +++ b/lib/ldpc/check.h @@ -0,0 +1,25 @@ +/* CHECK.H - Interface to procedure for computing parity checks, etc. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +int check (mod2sparse *, char *, char *); + +double changed (double *, char *, int); + +double expected_parity_errors (mod2sparse *, double *); + +double loglikelihood (double *, char *, int); +double expected_loglikelihood (double *, double *, int); + +double entropy (double *, int); diff --git a/lib/ldpc/dec.c b/lib/ldpc/dec.c new file mode 100755 index 00000000..68029115 --- /dev/null +++ b/lib/ldpc/dec.c @@ -0,0 +1,420 @@ +/* DEC.C - Decoding procedures. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + + +/* NOTE: See decoding.html for general documentation on the decoding methods */ + + +#include +#include +#include + +#include "alloc.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +/*#include "rand.h"*/ +#include "rcode.h" +#include "check.h" +#include "dec.h" +#include "enc.h" + + +/* GLOBAL VARIABLES. Declared in dec.h. */ + +decoding_method dec_method; /* Decoding method to use */ + +int ldpc_table; /* Trace option, 2 for a table of decoding details */ +int block_no; /* Number of current block, from zero */ + +int max_iter; /* Maximum number of iteratons of decoding to do */ +char *gen_file; /* Generator file for Enum_block and Enum_bit */ + + +/* DECODE BY EXHAUSTIVE ENUMERATION. Decodes by trying all possible source + messages (and hence all possible codewords, unless the parity check matrix + was redundant). If the last argument is 1, it sets dblk to the most likely + entire block; if this argument is 0, each bit of dblk is set to the most + likely value for that bit. The marginal probabilities of each bit being 1 + are returned in bitpr. + + The function value returned is the total number of codewords tried (which + will be the same for all blocks). The return valued is "unsigned" because + it might conceivably be as big as 2^31. + + The parity check matrix and other data are taken from the global variables + declared in rcode.h. + + The number of message bits should not be greater than 31 for this procedure. + The setup procedure immediately below checks this, reads the generator file, + and outputs headers for the detailed trace file, if required. + */ + +void enum_decode_setup(void) +{ + read_gen(gen_file,0,0); + + if (N-M>31) + { fprintf(stderr, +"Trying to decode messages with %d bits by exhaustive enumeration is absurd!\n", + N-M); + exit(1); + } + + if (ldpc_table==2) + { printf(" block decoding likelihood\n"); + } +} + +unsigned enum_decode +( double *lratio, /* Likelihood ratios for bits */ + char *dblk, /* Place to stored decoded message */ + double *bitpr, /* Place to store marginal bit probabilities */ + int max_block /* Maximize probability of whole block being correct? */ +) +{ + mod2dense *u, *v; + double lk, maxlk, tpr; + double *bpr, *lk0, *lk1; + char sblk[31]; + char *cblk; + unsigned d; + int i, j; + + if (N-M>31) abort(); + + /* Allocate needed space. */ + + bpr = bitpr; + if (bpr==0 && max_block==0) + { bpr = chk_alloc (N, sizeof *bpr); + } + + cblk = chk_alloc (N, sizeof *cblk); + + if (type=='d') + { u = mod2dense_allocate(N-M,1); + v = mod2dense_allocate(M,1); + } + + if (type=='m') + { u = mod2dense_allocate(M,1); + v = mod2dense_allocate(M,1); + } + + lk0 = chk_alloc (N, sizeof *lk0); + lk1 = chk_alloc (N, sizeof *lk1); + + /* Pre-compute likelihoods for bits. */ + + for (j = 0; j=0; i--) + { sblk[i] = (d>>i)&1; + } + + /* Find full codeword for this message. */ + + switch (type) + { case 's': + { sparse_encode (sblk, cblk); + break; + } + case 'd': + { dense_encode (sblk, cblk, u, v); + break; + } + case 'm': + { mixed_encode (sblk, cblk, u, v); + break; + } + } + + /* Compute likelihood for this decoding. */ + + lk = 1; + for (j = 0; jmaxlk) + { for (j = 0; j=0.5; + } + } + + /* Free space. */ + + if (bpr!=0 && bpr!=bitpr) free(bpr); + free(cblk); + free(lk0); + free(lk1); + + return 1<<(N-M); +} + + +/* DECODE USING PROBABILITY PROPAGATION. Tries to find the most probable + values for the bits of the codeword, given a parity check matrix (H), and + likelihood ratios (lratio) for each bit. If max_iter is positive, up to + that many iterations of probability propagation are done, stopping before + then if the tentative decoding is a valid codeword. If max_iter is + negative, abs(max_iter) iterations are done, regardless of whether a + codeword was found earlier. + + Returns the number of iterations done (as an "unsigned" for consistency + with enum_decode). Regardless of whether or not a valid codeword was + reached, the bit vector from thresholding the bit-by-bit probabilities is + stored in dblk, and the resulting parity checks are stored in pchk (all + will be zero if the codeword is valid). The final probabilities for each + bit being a 1 are stored in bprb. + + The setup procedure immediately below outputs headers for the detailed trace + file, if required. +*/ + +void prprp_decode_setup (void) +{ + if (ldpc_table==2) + { printf( + " block iter changed perrs loglik Eperrs Eloglik entropy\n"); + } +} + +unsigned prprp_decode +( mod2sparse *H, /* Parity check matrix */ + double *lratio, /* Likelihood ratios for bits */ + char *dblk, /* Place to store decoding */ + char *pchk, /* Place to store parity checks */ + double *bprb /* Place to store bit probabilities */ +) +{ + int N, n, c; + + N = mod2sparse_cols(H); + + /* Initialize probability and likelihood ratios, and find initial guess. */ + + initprp(H,lratio,dblk,bprb); + + /* Do up to abs(max_iter) iterations of probability propagation, stopping + early if a codeword is found, unless max_iter is negative. */ + + for (n = 0; ; n++) + { + c = check(H,dblk,pchk); + + if (ldpc_table==2) + { printf("%7d %5d %8.1f %6d %+9.2f %8.1f %+9.2f %7.1f\n", + block_no, n, changed(lratio,dblk,N), c, loglikelihood(lratio,dblk,N), + expected_parity_errors(H,bprb), expected_loglikelihood(lratio,bprb,N), + entropy(bprb,N)); + } + + if (n==max_iter || n==-max_iter || (max_iter>0 && c==0)) + { break; + } + + iterprp(H,lratio,dblk,bprb); + } + + return n; +} + + +/* INITIALIZE PROBABILITY PROPAGATION. Stores initial ratios, probabilities, + and guess at decoding. */ + +void initprp +( mod2sparse *H, /* Parity check matrix */ + double *lratio, /* Likelihood ratios for bits */ + char *dblk, /* Place to store decoding */ + double *bprb /* Place to store bit probabilities, 0 if not wanted */ +) +{ + mod2entry *e; + int N; + int j; + + N = mod2sparse_cols(H); + + for (j = 0; jpr = lratio[j]; + e->lr = 1; + } + if (bprb) bprb[j] = 1 - 1/(1+lratio[j]); + dblk[j] = lratio[j]>=1; + } +} + + +/* DO ONE ITERATION OF PROBABILITY PROPAGATION. */ + +void iterprp +( mod2sparse *H, /* Parity check matrix */ + double *lratio, /* Likelihood ratios for bits */ + char *dblk, /* Place to store decoding */ + double *bprb /* Place to store bit probabilities, 0 if not wanted */ +) +{ + double pr, dl, t; + mod2entry *e; + int N, M; + int i, j; + + M = mod2sparse_rows(H); + N = mod2sparse_cols(H); + + /* Recompute likelihood ratios. */ + + for (i = 0; ilr = dl; + dl *= 2/(1+e->pr) - 1; + } + dl = 1; + for (e = mod2sparse_last_in_row(H,i); + !mod2sparse_at_end(e); + e = mod2sparse_prev_in_row(e)) + { t = e->lr * dl; + e->lr = (1-t)/(1+t); + dl *= 2/(1+e->pr) - 1; + } + } + + /* Recompute probability ratios. Also find the next guess based on the + individually most likely values. */ + + for (j = 0; jpr = pr; + pr *= e->lr; + } + if (isnan(pr)) + { pr = 1; + } + if (bprb) bprb[j] = 1 - 1/(1+pr); + dblk[j] = pr>=1; + pr = 1; + for (e = mod2sparse_last_in_col(H,j); + !mod2sparse_at_end(e); + e = mod2sparse_prev_in_col(e)) + { e->pr *= pr; + if (isnan(e->pr)) + { e->pr = 1; + } + pr *= e->lr; + } + } +} + +void ldpc_decode_ ( double lratio[], char decoded[], int *max_iterations, int *niterations, int *max_dither, int *ndither) +{ + int i, j, itry, valid; + char dblk[N],pchk[M]; + double bprb[N],lr[N]; + float fac; + + max_iter=*max_iterations; + srand(-1); + for (itry=0; itry< *max_dither; itry++) { + for (i=0; i + + Detailed Decoding Trace Information + + + + +

Detailed Decoding Trace Information

+ +The -T option to decode +causes a detailed trace of information on the process of decoding to +be written to standard output, in a multi-column format, with the first +line containing the headers for each column. This format is suitable +for reading into S-Plus or R. + +The first column is always the number of the block being decoded; +several lines may be output for each block. The other columns vary +with the decoding method used, as described below. + + +

Enum-bit and Enum-block decoding methods

+ +For source messages with K bits, 2K lines are output +for each block, containing the following information: +
+ + + + + + + + + + +
block The number of the block, from zero
decoding A possible decoding for the message bits, expressed as a hexadecimal + number. The other bits are determined by the message bits.
likelihood The likelihood for this decoding (ie, the probability of obtaining + the data received if this was the message sent).
+
+ +For these methods, the number of "iterations" (output with the +-t option) is always 2K. + + +

Prprp decoding method

+ +Each block results in one line of output for the initial state (based +on individual likelihood ratios), and one line for each subsequent +iteration, containing the following information: +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
block The number of the block, from zero
iter The number of an iteration, zero for the initial state.
changed The number of bits in the decoding that differ from the bit that would + be chosen based just on the likelihood ratio for that bit. Bits whose + likelihood ratios are exactly one contribute 0.5 to this + count. (Likelihood ratios of exactly one can arise when the output + of an AWGN channel rounds to exactly 0.00.)
perrs The number of parity check errors in the current tentative + decoding.
loglik The log likelihood of the current tentative decoding.
Eperrs The expected number of parity check errors in a decoding found + by randomly picking a value for each bit, independently, according + to the current bit probabilities.
Eloglik The expected log likelihood of a decoding found by randomly picking + a value for each bit, independently, according to the current bit + probabilities. +
entropy The entropy (in bits) of the distribution defined by the current bit + probablities, assumed to apply to bits independently.
+
+ +The number of "iterations" (output with the -t option) is +the obvious count of probability propagation iterations. The +initial state does not count as an iteration. + +
+ +Back to decoding documentation
+Back to index for LDPC software + + diff --git a/lib/ldpc/decode.c b/lib/ldpc/decode.c new file mode 100755 index 00000000..ec04f2e4 --- /dev/null +++ b/lib/ldpc/decode.c @@ -0,0 +1,384 @@ +/* DECODE.C - Decode blocks of received data. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include +#include + +#include "rand.h" +#include "alloc.h" +#include "blockio.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "channel.h" +#include "rcode.h" +#include "check.h" +#include "dec.h" + + +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + char *pchk_file, *rfile, *dfile, *pfile; + char **meth; + FILE *rf, *df, *pf; + + char *dblk, *pchk; + double *lratio; + double *bitpr; + + double *awn_data; /* Places to store channel data */ + int *bsc_data; + + unsigned iters; /* Unsigned because can be huge for enum */ + double tot_iter; /* Double because can be huge for enum */ + double chngd, tot_changed; /* Double because can be fraction if lratio==1*/ + + int tot_valid; + char junk; + int valid; + + int i, j, k; + + /* Look at initial flag arguments. */ + + ldpc_table = 0; + blockio_flush = 0; + + while (argc>1) + { + if (strcmp(argv[1],"-t")==0) + { if (ldpc_table!=0) usage(); + ldpc_table = 1; + } + else if (strcmp(argv[1],"-T")==0) + { if (ldpc_table!=0) usage(); + ldpc_table = 2; + } + else if (strcmp(argv[1],"-f")==0) + { if (blockio_flush!=0) usage(); + blockio_flush = 1; + } + else + { break; + } + + argc -= 1; + argv += 1; + } + + /* Look at arguments up to the decoding method specification. */ + + if (!(pchk_file = argv[1]) + || !(rfile = argv[2]) + || !(dfile = argv[3])) + { usage(); + } + + if (argv[4]==0 || argv[5]==0) usage(); + + k = channel_parse(argv+4,argc-4); + if (k<=0) + { pfile = argv[4]; + k = channel_parse(argv+5,argc-5); + if (k<=0) usage(); + meth = argv+5+k; + } + else + { pfile = 0; + meth = argv+4+k; + } + + /* Look at the specification of the decoding method, which starts at meth and + continues to the end of the command line (marked by a zero pointer). */ + + if (!meth[0]) usage(); + + if (strcmp(meth[0],"prprp")==0) + { dec_method = Prprp; + if (!meth[1] || sscanf(meth[1],"%d%c",&max_iter,&junk)!=1 || meth[2]) + { usage(); + } + } + else if (strcmp(meth[0],"enum-block")==0) + { dec_method = Enum_block; + if (!(gen_file = meth[1]) || meth[2]) usage(); + } + else if (strcmp(meth[0],"enum-bit")==0) + { dec_method = Enum_bit; + if (!(gen_file = meth[1]) || meth[2]) usage(); + } + else + { usage(); + } + + /* Check that we aren't overusing standard input or output. */ + + if ((strcmp(pchk_file,"-")==0) + + (strcmp(rfile,"-")==0) > 1) + { fprintf(stderr,"Can't read more than one stream from standard input\n"); + exit(1); + } + if ((ldpc_table>0) + + (strcmp(dfile,"-")==0) + + (pfile!=0 && strcmp(pfile,"-")==0) > 1) + { fprintf(stderr,"Can't send more than one stream to standard output\n"); + exit(1); + } + + /* Read parity check file. */ + + read_pchk(pchk_file); + + if (N<=M) + { fprintf(stderr, + "Number of bits (%d) should be greater than number of checks (%d)\n",N,M); + exit(1); + } + + /* Open file of received data. */ + + rf = open_file_std(rfile,"r"); + if (rf==NULL) + { fprintf(stderr,"Can't open file of received data: %s\n",rfile); + exit(1); + } + + /* Create file for decoded data. */ + + df = open_file_std(dfile,"w"); + if (df==NULL) + { fprintf(stderr,"Can't create file for decoded data: %s\n",dfile); + exit(1); + } + + /* Create file for bit probabilities, if specified. */ + + if (pfile) + { pf = open_file_std(pfile,"w"); + if (pf==NULL) + { fprintf(stderr,"Can't create file for bit probabilities: %s\n",pfile); + exit(1); + } + } + + /* Allocate space for data from channel. */ + + switch (channel) + { case BSC: + { bsc_data = chk_alloc (N, sizeof *bsc_data); + break; + } + case AWGN: case AWLN: + { awn_data = chk_alloc (N, sizeof *awn_data); + break; + } + default: + { abort(); + } + } + + /* Allocate other space. */ + + dblk = chk_alloc (N, sizeof *dblk); + lratio = chk_alloc (N, sizeof *lratio); + pchk = chk_alloc (M, sizeof *pchk); + bitpr = chk_alloc (N, sizeof *bitpr); + + /* Print header for summary table. */ + + if (ldpc_table==1) + { printf(" block iterations valid changed\n"); + } + + /* Do the setup for the decoding method. */ + + switch (dec_method) + { case Prprp: + { prprp_decode_setup(); + break; + } + case Enum_block: case Enum_bit: + { enum_decode_setup(); + break; + } + default: abort(); + } + + /* Read received blocks, decode, and write decoded blocks. */ + + tot_iter = 0; + tot_valid = 0; + tot_changed = 0; + + for (block_no = 0; ; block_no++) + { + /* Read block from received file, exit if end-of-file encountered. */ + + for (i = 0; i0) + { fprintf(stderr, + "Warning: Short block (%d long) at end of received file ignored\n",i); + } + goto done; + } + if (c<1 || channel==BSC && bsc_data[i]!=0 && bsc_data[i]!=1) + { fprintf(stderr,"File of received data is garbled\n"); + exit(1); + } + } + + /* Find likelihood ratio for each bit. */ + + switch (channel) + { case BSC: + { for (i = 0; i= 2^31 */ + fflush(stdout); + } + + /* Write decoded block. */ + + blockio_write(df,dblk,N); + + /* Write bit probabilities, if asked to. */ + + if (pfile) + { for (j = 0; j + + Decoding Received Blocks + + + + +

Decoding Received Blocks

+ +Transmitted codewords are decoded from the received data on the basis +of the likelihood of the possible codewords, which is the +probability of receiving the data that was actually received if the +codeword is question were the one that was sent. This software +presently deals only with memoryless channels, in which the noise is +independent from bit to bit. For such a channel, the likelihood +factorizes into a product of likelihoods for each bit. + +For decoding purposes, all that matters is the relative likelihood +for a bit to be 1 versus 0. This is captured by the likelihood +ratio in favour of a 1, which is P(data | bit is 1) / P(data | +bit is 0). + +

For a Binary Symmetric Channel with error probability p, +the likelihood ratio in favour of a 1 bit is as follows: +

+ If the received data was +1: (1-p) / p
+ If the received data was -1: p / (1-p) +
+For an Additive White Gaussian Noise channel, with signals of +1 for a 1 bit +and or -1 for a 0 bit, and with noise standard deviation s, the +likelihood ratio in favour of a 1 bit when data y was received is +
+ exp ( 2y / s2 ) +
+For an Additive White Logistic Noise channel, the corresponding +likelihood ratio is +d1/d0, +where +d1=e1 +/ (1+e1)2 and +d0=e0 +/ (1+e0)2, +with e1=exp(-(y-1)/w) and +e0=exp(-(y+1)/w). +
+ +

It is usual to consider codewords to be equally likely a +priori. This is reasonable if the source messages are all equally +likely (any source redundancy being ignored, or remove by a +preliminary data compression stage), provided that the mapping from +source messages to codewords is onto. Decoding can then be done using +only the parity check matrix defining the codewords, without reference +to the generator matrix defining the mapping from source messages to +codewords. Note that the condition that this mapping be onto isn't +true with this software in the atypical case where the code is defined +by a parity check matrix with redundant rows; see the discussion of linear dependence in parity check matrices. +This minor complication is mostly ignored here, except by the exhaustive +enumeration decoding methods. + +

Assuming equal a priori probabilities for codewords, the +probability of correctly decoding an entire codeword is minimized by +picking the codeword with the highest likelihood. One might instead +wish to decode each bit to the value that is most probable. This +minimizes the bit error rate, but is not in general guaranteed to lead +a decoding for each block to the most probable complete codeword; +indeed, the decoding may not be a codeword at all. Minimizing the bit +error rate seems nevertheless to be the most sensible objective, +unless block boundaries have some significance in a wider context. + +

Optimal decoding by either criterion is infeasible for general +linear codes when messages are more than about 20 or 30 bits in +length. The fundamental advantage of Low Density Parity Check codes +is that good (though not optimal) decodings can be obtained by methods +such as probability propagation, described next. + +

Decoding by probability propagation

+ +

The probability propagation algorithm was originally devised by +Robert Gallager in the early 1960's and later reinvented by David +MacKay and myself. It can be seen as an instance of the sum-product +algorithm for inference on factor graphs, and as an instance of belief +propagation in probabilistic networks. See the references for details. Below, I give a fairly +intuitive description of the algorithm. + +

The algorithm uses only the parity check matrix for the code, whose +columns correspond to codeword bits, and whose rows correspond to +parity checks, and the likelihood ratios for the bits derived from the +data. It aims to find the probability of each bit of the transmitted +codeword being 1, though the results of the algorithm are in general +only approximate. + +

The begin, information about each bit of the codeword derived from +the received data for that bit alone is expressed as a probability +ratio, the probability of the bit being 1 divided by the +probability of the bit being 0. This probability ratio is equal to +the likelihood ratio (see above) for that bit, since 0 and 1 are +assumed to be equally likely a priori. As the algorithm +progresses, these probability ratios will be modified to take account +of information obtained from other bits, in conjunction with the +requirement that the parity checks be satisfied. To avoid double +counting of information, for every bit, the algorithm maintains a +separate probability ratio for each parity check that that bit +participates in, giving the probability for that bit to be 1 versus 0 +based only on information derived from other parity checks, +along with the data received for the bit. + +

For each parity check, the algorithm maintains separate +likelihood ratios (analogous to, but distinct from, the +likelihood ratios based on received data), for every bit that +participates in that parity check. These ratios give the probability +of that parity check being satisfied if the bit in question is 1 +divided by the probability of the check being satisfied if the bit is +0, taking account of the probabilities of each of the other +bits participating in this check being 1, as derived from the +probability ratios for these bits with respect to this check. + +

The algorithm alternates between recalculating the likelihood +ratios for each check, which are stored in the lr fields of the +parity check matrix entries, and recalculating the probability ratios +for each bit, which are stored in the pr fields of the entries +in the sparse matrix representation of the parity check matrix. (See +the documentation on representation of +sparse matrices for details on these entries.) + +

Recalculating the likelihood ratio for a check with respect to some +bit may appear time consuming, requiring that all possible +combinations of values for the other bits participating in the check +be considered. Fortunately, there is a short cut. One can calculate +

+ t + = product of [ 1 / (1+pi) + - pi / + (1+pi) ] + = product of [ 2 / (1+pi) - 1 ] +
+where the product is over the probability ratios +pi for the other bits participating +in this check. Factor i in this product is equal to probability +of bit i being 0 minus the probability that it is 1. The terms +in the expansion of this product (in the first form above) correspond to +possible combinations of values for the other bits, with the result that +t will be the probability of the check being satisfied if the bit +in question is 0 minus the probability if the bit in question is 1. The +likelihood ratio for this check with respect to the bit in question can then +be calculated as (1-t)/(1+t). + +

For a particular check, the product above differs for different +bits, with respect to which we wish to calculate a likelihood ratio, +only in that for each bit the factor corresponding to that bit is left +out. We can calculate all these products easily by ordering the bits +arbitrarily, computing running products of the factor for the first +bit, the factors for the first two bits, etc., and also running +products of the factor for the last bit, the factors for the last two +bits, etc. Multiplying the running product of the factors up to +i-1 by the running product of the factors from i+1 on +gives the product needed for bit i. The second form of the +factors above is used, as it requires less computation, and is still +well defined even if some ratios are infinite. + +

To recalculate the probability ratio for a bit with respect to a +check, all that is need is to multiply together the likelihood ratio +for this bit derived from the received data (see above), and the +current values of the likelihood ratios for all the other +checks that this bit participates in, with respect to this bit. To +save time, these products are computed by combining forward and +backward products, similarly to the method used for likelihood ratios. + +

By including likelihood ratios from all checks, a similar +calculation produces the current probability ratio for the bit to be 1 +versus 0 based on all information that has propagated to the bit so +far. This ratio can be thresholded at one to produce the current best +guess as to whether this bit is a 1 or a 0. + +

The hope is that this algorithm will eventually converge to a state +where these bit probabilities give a near-optimal decoding. This is +does not always occur, but the algorithm behaves well enough to +produce very good results at rates approaching (though not yet +reaching) the theoretical Shannon limit. + + +


decode: Decode blocks of received data +into codewords. + +
+decode [ -f ] [ -t | -T ] pchk-file received-file decoded-file [ bp-file ] channel method
+
+
+where channel is one of: +
+bsc error-probability
+
+awgn standard-deviation
+
+awln width
+
+and method is one of: +
+enum-block gen-file
+
+enum-bit gen-file
+
+prprp [-]max-iterations
+
+
+
+ +

Decodes the blocks in received-file, which are +assumed to be have been received through the specified channel. The +results written to decoded-file are the specified +decoding method's guesses as to what bits were sent through the +channel, given what was received. The probability of each bit being a +1, as judged by the decoding method being used, is written to +bp-file, if given. + +

A newline is output at the end of each block written to +decoded-file and bp-file. Newlines in +received-file are ignored. A warning is displayed on +standard error if the number of bits in received-file +is not a multiple of the block length. + +

A summary is displayed on standard error, giving the total number +of blocks decoded, the number of blocks that decoded to valid +codewords, the average number of iterations of the decoding algorithm +used, and the percent of bits that were changed from the values one +would guess for them based just on their individual likelihood ratios. + +

If the -t option is given, a line of information regarding each block +decoded is written to standard output, preceded by a line of headers. +The information for each block is as follows: +

+ + + + + + + + + + + + + +
block The number of the block, from zero
iterations The number of "iterations" used in decoding. What exactly an iteration + is depends on the decoding method used (see + here).
valid Has the value 1 if the decoding is a valid codeword, 0 if not.
changed The number of bits in the decoding that differ from the bit that would + be chosen based just on the likelihood ratio for that bit. Bits whose + likelihood ratios are exactly one contribute 0.5 to this count.
+
+The file produced is is suitable for +reading into the S-Plus or R statistics packages, with a command such as +
+data <- read.table(file,header=T)
+
+ +

If instead the -T option is given, detailed information on +the process of decoding each block will be written to standard output. +For a description, see the documentation +on detailed decoding trace information. + +

The type of channel that is assumed is specified after the file +name arguments. This may currently be either bsc (or +BSC) for the Binary Symmetric Channel, or awgn (or +AWGN) for the Additive White Gaussian Noise channel, or +awln (or AWLN) for the Additive White Logistic Noise +channel. The channel type is followed by an argument specifying the +assumed characteristics of the channel, as follows: +

+

BSC: The probability that a bit will be flipped by noise - ie, the + probability that the bit received is an error. + +

AWGN: The standard deviation of the Gaussian noise added to the + encodings of the bits. + +

AWLN: The width parameter of the logistic distribution for the noise + that is added to the encodings of the bits. +

+See the description of channel transmission +for more about these channels. + +

Following the channel specification is a specification of the +decoding method to use. The enum-block and enum-bit +methods find the optimal decoding by exhaustive enumeration of +codewords derived from all possible source messages. They differ in +that enum-block decodes to the most likely codeword, whereas +enum-bit decodes to the bits that are individually most +probable. These methods require that a file containing a +representation of a generator matrix be given, to allow enumeration of +codewords. If the parity check matrix has no redundant rows, any +valid generator matrix will give the same decoding (except perhaps if +there is a tie). If redundant rows exist, the generator matrix should +specify the same set of message bits as the generator matrix that was +used for the actual encoding, since the redundancy will lead to some +codeword bits being fixed at zero (see linear +dependence in parity check matrices). + +

The prprp decoding method decodes using probability propagation. The maximum number of +iterations of probability propagation to do is given following +prprp. If a minus sign precedes this number, the maximum +number of iterations is always done. If no minus sign is present, the +algorithm stops once the tentative decoding, based on bit-by-bit +probabilities, is a valid codeword. Note that continuing to the +maximum number of iterations will usually result in +at least slightly different bit probabilities (written to +bp-file if specified), and could conceivably change +the decoding compared to stopping at the first valid codeword, or +result in a failure to decode to a valid codeword even though one was +found earlier. + +

If the -f option is given, output to decoded-file +is flushed after each block. This allows one to use decode as a server, +reading blocks to decode from a named pipe, and writing the decoded block +to another named pipe. + + +


extract: Extract the message bits from a block. + +
+extract gen-file decoded-file extracted-file
+
+ +

Given a file of codewords in decoded-file (usually, +decoded blocks output by decode), and a +generator matrix from gen-file (needed only to +determine where the message bits are located in a codeword), this +program writes the message bits extracted from these codewords to the +file extracted-file. + +

A newline is output at the end of each block written to +extracted-file. Newlines in +decoded-file are ignored. A warning is displayed on +standard error if the number of bits in decoded-file +is not a multiple of the block length. + +


+ +Back to index for LDPC software + + diff --git a/lib/ldpc/dep-H.html b/lib/ldpc/dep-H.html new file mode 100755 index 00000000..b80b2a5c --- /dev/null +++ b/lib/ldpc/dep-H.html @@ -0,0 +1,85 @@ + + + Linear Dependence in Parity Check Matrices + + + + +

Linear Dependence in Parity Check Matrices

+ +

If a code is specified by means of a M by N parity +check matrix, H, in which some rows are linearly dependent - a +situation that is usually avoided - it would be possible to map more +than the usual K=N-M message bits into a codeword, since one or +more rows of H could have been deleted without affecting which +bit vectors are codewords. + +

However, this software does not increase the number of message bits +in this case, but instead produces a generator matrix in which some +rows are all zero, which will cause some bits of the codeword to +always be zero, regardless of the source message. Referring to the description of generator matrix +representations, this is accomplished by partially computing +what would normally be A-1 (for a +dense or mixed representations) or the L and U matrices +(for a sparse representation), even though singularity prevents this +computation from being carried out fully. + +

Example: The parity check matrix created below is redundant, +since the 10100 row is equal to the sum of the 11000 and 01100 rows. +

    +
  • make-pchk dep.pchk 4 5 0:0 0:1 1:1 1:2 2:0 2:2 3:3 3:4 +
  • print-pchk -d dep.pchk + +Parity check matrix in dep.pchk (dense format): + + 1 1 0 0 0 + 0 1 1 0 0 + 1 0 1 0 0 + 0 0 0 1 1 + +
  • make-gen dep.pchk dep.gen dense +Note: Parity check matrix has 1 redundant checks +Number of 1s per check in Inv(A) X B is 0.2 +
  • print-gen dep.gen + +Generator matrix (dense representation): + +Column order (message bits at end): + + 0 1 3 2 4 + +Inv(A) X B: + + 0 + 0 + 1 + 0 +
+The generator matrix above can be used to encode message blocks containing +one bit. This message bit is copied unchanged to the last bit (numbered 4) +of the codeword, and the first four bits of the codeword are set by multiplying +this message bit (seen as a vector of length one) by +A-1B, shown above, and then +storing the results in positions given by the column ordering. +The result is that bit 3 of the codeword produced is +also set to the message bit, and bits 0, 1, and 2 are set to zero. + +

Which bits are used for message bits, and which bits are fixed at +zero, depends on arbitrary choices in the algorithm, which may differ +from one encoding method to another. No attempt is made to make the +best choice. + +

Note that codeword bits that are always zero can arise even when H +does not have linearly dependent rows. For example, if a row of H +has just one 1 in it, the codeword bit at that position must be zero in any +codeword. The way the software handles parity check matrices with less +than M independent rows is equivalent to adding additional rows +to H in which only one bit is 1, in order to produce M +independent checks. + +


+ +Back to index for LDPC software + + diff --git a/lib/ldpc/distrib.c b/lib/ldpc/distrib.c new file mode 100755 index 00000000..879c54ad --- /dev/null +++ b/lib/ldpc/distrib.c @@ -0,0 +1,188 @@ +/* DISTRIB.C - Procedures for handling distributions over numbers. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal and Peter Junteng Liu. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include +#include + +#include "alloc.h" +#include "distrib.h" + + +/* CREATE A DISTRIBUTION AS SPECIFIED IN A STRING. Space for the distribution + is allocated; the string is not freed. + + The string must consist either of a single positive integer, representing + the distribution over just that number, or have a form such as the + following: + + 5x2/3.5x1/1.5x4 + + This specifies a distribution over 3 numbers, 2, 1, and 4, specified by + the second number in each pair, with proportions of 0.5, 0.35, and 0.15, + respectively, specified by the first number in each pair. The actual + proportions are found by dividing the first number in each pair by the sum + of these numbers. + + The distrib type represents the distribution list. It stores a pointer to + an array of distrib_entry elements along with the length of this array. + Each distrib_entry contains a (number,proportion) pair. +*/ + +distrib *distrib_create +( char *c /* String describing distribution over numbers */ +) +{ + distrib *d; + char *str, *tstr; + int i, n, scan_num, size; + double prop, sum; + char junk; + + /* Check for special case of a single number. */ + + if (sscanf(c,"%d%c",&n,&junk)==1 && n>0) + { tstr = chk_alloc ( (int)(4.1+log10(n)), sizeof(*tstr)); + sprintf(tstr,"1x%d",n); + d = distrib_create(tstr); + free(tstr); + return d; + } + + /* Initial scan of string for size and proper usage. */ + + str = c; + size = 0; + sum = 0; + + d = chk_alloc(1, sizeof *d); + + for (;;) + { + scan_num = sscanf(str, "%lgx%d%c", &prop, &n, &junk); + + if ((scan_num!=2 && scan_num!=3) || prop<=0 || n<=0) + { return 0; + } + if (scan_num==3 && junk!='/') + { return 0; + } + + size += 1; + sum += prop; + + if (scan_num==2) + { break; + } + else + { str = (char*)strchr(str, '/') + 1; + } + } + + /* Allocate memory for the list and fill it in */ + + d->size = size; + d->list = chk_alloc (size, sizeof(distrib_entry)); + + i = 0; + str = c; + + for (;;) + { + scan_num = sscanf(str, "%lgx%d%c", &prop, &n, &junk); + + d->list[i].prop = prop/sum; + d->list[i].num = n; + i += 1; + + if (scan_num==2) + { break; + } + else if (scan_num==3) + { str = (char*)strchr(str, '/') + 1; + } + else + { abort(); + } + } + + return d; +} + + +/* FREE SPACE OCCUPIED A DISTRIBUTION LIST. */ + +void distrib_free +( distrib *d /* List to free */ +) +{ free(d->list); + free(d); +} + + +/* RETURN THE MAXIMUM NUMBER IN A DISTRIBUTION LIST. Returns 0 if the list + pointer is 0. */ + +int distrib_max +( distrib *d /* List to examine */ +) +{ + int i; + int cur; + + if (d==0) return 0; + + cur = 0; + + for (i = 1; isize; i++) + { if (d->list[i].num > d->list[cur].num) + { cur = i; + } + } + + return d->list[cur].num; +} + + +/* TEST PROGRAM. */ + +#ifdef TEST_DISTRIB + +main +( int argc, + char **argv +) +{ + distrib *d; + int i, j; + + for (i = 1; ilist[]). */ + +typedef struct distrib_entry +{ int num; /* A positive number */ + double prop; /* Proportion for this number */ +} distrib_entry; + +typedef struct distrib +{ struct distrib_entry *list; /* The list of numbers and proportions */ + int size; /* Number of entries in the list */ +} distrib; + + +/* MACROS TO ACCESS ELEMENTS OF A DISTRIBUTION LIST. Note that indexes for + entries start at 0. */ + +#define distrib_num(d,i) \ + ((d)->list[i].num) /* The number for the i'th entry */ + +#define distrib_prop(d,i) \ + ((d)->list[i].prop) /* The i'th entry's proportion [probability] */ + +#define distrib_size(d) \ + ((d)->size) /* The length of the list (integer) */ + + +/* PROCEDURES FOR DISTRIBUTION LISTS. */ + +distrib *distrib_create (char *); +void distrib_free (distrib *); + +int distrib_max(distrib *); diff --git a/lib/ldpc/enc.c b/lib/ldpc/enc.c new file mode 100755 index 00000000..8b4cdbde --- /dev/null +++ b/lib/ldpc/enc.c @@ -0,0 +1,173 @@ +/* ENC.C - Encoding procedures. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include + +/*#include "rand.h"*/ +#include "alloc.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" +#include "enc.h" + + +/* The procedures in this module obtain the generator matrix to use for + encoding from the global variables declared in rcode.h */ + + +/* ENCODE A BLOCK USING A SPARSE REPRESENTATION OF THE GENERATOR MATRIX. */ + +void sparse_encode +( char *sblk, + char *cblk +) +{ + int i, j; + + mod2entry *e; + char *x, *y; + + x = chk_alloc (M, sizeof *x); + y = chk_alloc (M, sizeof *y); + + /* Multiply the vector of source bits by the systematic columns of the + parity check matrix, giving x. Also copy these bits to the coded block. */ + + for (i = 0; i +#include +#include +#include + +#include "rand.h" +#include "alloc.h" +#include "blockio.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" +#include "enc.h" + +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + char *source_file, *encoded_file; + char *pchk_file, *gen_file; + mod2dense *u, *v; + + FILE *srcf, *encf; + char *sblk, *cblk, *chks; + int i, n; + + /* Look at initial flag arguments. */ + + blockio_flush = 0; + + while (argc>1) + { + if (strcmp(argv[1],"-f")==0) + { if (blockio_flush!=0) usage(); + blockio_flush = 1; + } + else + { break; + } + + argc -= 1; + argv += 1; + } + + /* Look at remaining arguments. */ + + if (!(pchk_file = argv[1]) + || !(gen_file = argv[2]) + || !(source_file = argv[3]) + || !(encoded_file = argv[4]) + || argv[5]) + { usage(); + } + + if ((strcmp(pchk_file,"-")==0) + + (strcmp(gen_file,"-")==0) + + (strcmp(source_file,"-")==0) > 1) + { fprintf(stderr,"Can't read more than one stream from standard input\n"); + exit(1); + } + + /* Read parity check file */ + + read_pchk(pchk_file); + + if (N<=M) + { fprintf(stderr, + "Can't encode if number of bits (%d) not greater than number of checks (%d)\n", + N,M); + exit(1); + } + + /* Read generator matrix file. */ + + read_gen(gen_file,0,0); + + /* Allocate needed space. */ + + if (type=='d') + { u = mod2dense_allocate(N-M,1); + v = mod2dense_allocate(M,1); + } + + if (type=='m') + { u = mod2dense_allocate(M,1); + v = mod2dense_allocate(M,1); + } + + /* Open source file. */ + + srcf = open_file_std(source_file,"r"); + if (srcf==NULL) + { fprintf(stderr,"Can't open source file: %s\n",source_file); + exit(1); + } + + /* Create encoded output file. */ + + encf = open_file_std(encoded_file,"w"); + if (encf==NULL) + { fprintf(stderr,"Can't create file for encoded data: %s\n",encoded_file); + exit(1); + } + + sblk = chk_alloc (N-M, sizeof *sblk); + cblk = chk_alloc (N, sizeof *cblk); + chks = chk_alloc (M, sizeof *chks); + + /* Encode successive blocks. */ + + for (n = 0; ; n++) + { + /* Read block from source file. */ + + if (blockio_read(srcf,sblk,N-M)==EOF) + { break; + } + + /* Compute encoded block. */ + + switch (type) + { case 's': + { sparse_encode (sblk, cblk); + break; + } + case 'd': + { dense_encode (sblk, cblk, u, v); + break; + } + case 'm': + { mixed_encode (sblk, cblk, u, v); + break; + } + } + + /* Check that encoded block is a code word. */ + + mod2sparse_mulvec (H, cblk, chks); + + for (i = 0; i + + Encoding Message Blocks + + + + +

Encoding Message Blocks

+ +To use a code to send messages, we must define a mapping from a bit +vector, s, of length K, representing a source message, +to a codeword, x, of length N>K. We will +consider only linear mappings, which can be written in the form +x=GTs, where G +is a generator matrix. For a code with parity check matrix +H, whose codewords satisfy Hx=0, the generator +matrix must satisfy HGT=0. +This software assumes that the number of rows in the parity check +matrix, M, is equal to N-K, as would normally be the +case. + +

This software deals only with systematic encodings, in which +the K bits of s are copied unchanged to some subset of +the N bits of x (the message bits), and the +remaining M=N-K check bits of x are then set so +as to make the result a codeword. For a linear code, a systematic +encoding scheme always exists, for some choice of which bits of a +codeword are message bits. It is conventional to rearrange the order +of the bits in a codeword so that the message bits come first. The +first K columns of the K by N generator matrix +will then be the identity matrix. + +

However, this software does not assume that the message bits +come first, since different encoding methods prefer different +locations for the message bits. Instead, a vector of indexes of where +each message bit is located within a codeword is recorded in a file +along with a representation of the part of the generator matrix that +produces the check bits. More than one such generator matrix file can +be created for a single parity check file, in which the locations of +the message bits may be different. Decoding of a received message +into a codeword (with decode) does not depend on +knowing which are the message bits, though this does need to be known +in order to reconstruct the original message (with extract). + +

This software stores representations of generator matrices in files +in a format that is not human-readable (except by using the print-gen program). However, these +files are readable on a machine with a different architecture +than they were written on. + + +

Generator matrix representations

+ +

For simplicity of exposition, it will be assumed for the next few +paragraphs that the message bits are located at the end of the +codeword, so a codeword can be divided into M check bits, +c, followed by K message bits, s. + +

On the above assumption, the parity check matrix, H, can be divided +into an M by M matrix A occupying +the first M columns of H and an M by K matrix +B occupying the remaining columns of H. The requirement that +a codeword, x, satisfy all parity checks (ie, that Hx=0) +can then be written as +

+ Ac + Bs = 0 +
+Provided that A is non-singular, it follows that +
+ c = A-1Bs +
+A may be singular for some choices of which codeword bits are message +bits, but a choice for which A is non-singular always exists if the +rows of H are linearly independent. It is possible, however, that the +rows of H are not linearly independent (ie, some rows are redundant). +This is an exceptional +and not particularly interesting case, which is mostly ignored in the +descriptions below; see the discussion of linear +dependence in parity check matrices for the details. + +

The equation c = A-1Bs +defines what the check bits should be, but actual computation of these +check bits can be done in several ways, three of which are implemented +in this software. Each method involves a different representation of +the generator matrix. (Note that none of these methods involves the +explicit representation of the matrix G mentioned above.) + +

In the dense representation, the M by K matrix +A-1B is computed, and stored +in a dense format (see the dense modulo-2 +matrix package). A message is encoded by multiplying the +source bits, s, by this matrix to obtain the required check bits. + +

In the mixed representation, the M by M matrix +A-1 is computed and stored in a dense +format, and the M by K matrix B, the right +portion of the parity check matrix, is also stored, in a sparse format +(see the sparse modulo-2 matrix package). +To encode a message, the source vector s is first multiplied on +the left by B, an operation which can be done very quickly if +B is sparse (as it will be for LDPC codes). The result is then +multiplied on the left by A-1. If +M<K, the total time may be less than when using the +dense representation above. + +

The sparse representation goes further, and avoids +explicitly computing A-1, which tends +to be dense even if H is sparse. Instead, a LU +decomposition of A is found, consisting of a lower +triangular matrix L and an upper triangular matrix U for +which LU=A. The effect of multiplying Bs=z by +A-1 can then be obtained by +

+ Solving Ly=z for y using forward substitution.
+ Solving Uc=y for c using backward substitution. +
+Both of these operations will be fast if L and U are +sparse. Heuristics are used to try to achieve this, by rearranging the +rows and columns of H in the process of selecting A and +finding its LU decomposition. + + +


make-gen: Make a generator matrix from +a parity check matrix. + +
+make-gen pchk-file gen-file method
+
+
+where method is one of the following: +
+sparse [ first | mincol | minprod ] [ abandon-num abandon-when ]
+
+dense [ other-gen-file  ]
+
+mixed [ other-gen-file  ]
+
+
+
+ +

Finds a generator matrix for the code whose parity check matrix is +in pchk-file, and writes a representation of this +generator matrix to gen-file. The remaining arguments +specify what representation of the generator matrix is to be used (see +the description above), and the method to be +used in finding it. A message regarding the density of 1s in the +resulting representation is displayed on standard error. For a sparse +representation, a smaller number of 1s will produce faster encoding. + +

All representations include a specification for how the columns of +the parity check matrix should be re-ordered so that the message bits +come last. References to columns of the parity check matrix below +refer to their order after this reordering. For the dense and +mixed representations, an other-gen-file may be +specified, in which case the ordering of columns will be the same as +the ordering stored in that file (which must produce a non-singular +A matrix; redundant rows of H are not allowed with this +option). Otherwise, make-gen decides on an appropriate +ordering of columns itself. Note that the column rearrangement is +recorded as part of the representation of the generator matrix; the +parity check matrix as stored in its file is not altered. + +

The dense representation consists of a dense representation +of the matrix A-1B, where +A is the matrix consisting of the first M columns (after +reordering) of the parity check matrix, and B is the remaining +columns. If H contains redundant rows, there is an additional +reordering of columns of A in order create the same effect as +if the redundant rows came last. + +

The mixed representation consists of a dense representation +of the matrix A-1, where A is +the matrix consisting of the first M columns (after reordering) +of the parity check matrix. The remaining columns of the parity check +matrix, making up the matrix B, are also part of the +representation, but are not written to gen-file, since +they can be obtained from pchk-file. As for mixed +representations, an additional reordering of columns of A may +be needed if H has redundant rows. + +

A sparse representation consists of sparse representations +of the L and U matrices, whose product is A, the +first M columns of the parity check matrix (whose columns and +rows may both have been reordered). The matrix B, consisting +of the remaining columns of the parity check matrix, is also part of +the representation, but it is not written to gen-file, +since it can be obtained from pchk-file. + +

If a sparse representation is chosen, arguments after +sparse specify what heuristic is used when reordering columns +and rows in order to try to make L and U as sparse as +possible. The default if no heuristic is specified is +minprod. If the abandon-num and +abandon-when options are given, some information is +discarded in order to speed up the process of finding L and +U, at a possible cost in terms of how good a result is +obtained. For details on these heuristics, see the descriptions of sparse LU decomposition methods. + +

Example: A dense representation of a generator matrix for the +Hamming code created by the example for make-pchk can be created as follows: +

    +
  • make-gen ham7.pchk ham7.gen dense +Number of 1s per check in Inv(A) X B is 3.0 +
+ + +


print-gen: Print a representation of a +generator matrix. + +
+print-gen [ -d ] gen-file
+
+ +

Prints in human-readable form the representation of the generator +matrix that is stored in gen-file. The -d +option causes the matrices involved to be printed in a dense format, +even if they are stored in the file in a sparse format. See the description above for details of generator matrix +representations. Note that the L matrix for a sparse representation +will be lower triangular only after the rows are rearranged, and the U +matrix will be upper triangular only after the columns are rearranged. +The matrix B that is part of the sparse +and mixed representations is not printed, since it is not stored +in the gen-file, but is rather a subset of columns +of the parity check matrix. + +

Example: The generator matrix for the +Hamming code created by the example for make-gen can be printed as follows: +

    +
  • print-gen ham7.gen + +Generator matrix (dense representation): + +Column order: + + 0 1 2 3 4 5 6 + +Inv(A) X B: + + 1 1 1 0 + 1 1 0 1 + 0 1 1 1 +
+For this example, the columns did not need to be rearranged, and hence the +message bits will be in positions 3, 4, 5, and 6 of a codeword. + +


encode: Encode message blocks as codewords + +
+encode [ -f ] pchk-file gen-file source-file encoded-file
+
+ +Encodes message blocks of length K, read from +source-file, as codewords of length N, which +are written to encoded-file, replacing any previous +data in this file. Here, N is the number of columns in the +parity check matrix in pchk-file, and +K=N-M, where M is the number of rows in the +parity check matrix. The generator matrix used, from +gen-file, determines which bits of the codeword are +set to the message bits, and how the remaining check bits are +computed. The generator matrix is created from +pchk-file using
make-gen. + +

A newline is output at the end of each block written to +encoded-file. Newlines in source-file +are ignored. + +

If the -f option is given, output to encoded-file +is flushed after each block. This allows one to use encode as a server, +reading blocks to encode from a named pipe, and writing the encoded block +to another named pipe. + +


+ +Back to index for LDPC software + + diff --git a/lib/ldpc/ex-dep b/lib/ldpc/ex-dep new file mode 100755 index 00000000..3acebedc --- /dev/null +++ b/lib/ldpc/ex-dep @@ -0,0 +1,60 @@ +#!/bin/sh + +# Examples of a how a parity check matrix with dependent rows is handled. + +set -e # Stop if an error occurs +set -v # Echo commands as they are read + +# CODE 1 + +make-pchk ex-dep.pchk 4 6 0:0 0:5 3:1 3:2 +print-pchk -d ex-dep.pchk +echo 00011011 >ex-dep.src + +# SPARSE REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen sparse +print-gen -d ex-dep.gen +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src + +# DENSE REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen dense +print-gen -d ex-dep.gen +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src + +# MIXED REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen mixed +print-gen -d ex-dep.gen +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src + +# CODE 2 + +make-pchk ex-dep.pchk 4 5 0:0 0:1 1:1 1:2 2:0 2:2 3:3 3:4 +print-pchk -d ex-dep.pchk +echo 01 >ex-dep.src + +# SPARSE REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen sparse +print-gen -d ex-dep.gen +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src + +# DENSE REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen dense +print-gen -d ex-dep.gen +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src + +# MIXED REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen mixed +print-gen -d ex-dep.gen +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src diff --git a/lib/ldpc/ex-dep-out b/lib/ldpc/ex-dep-out new file mode 100755 index 00000000..c4df520a --- /dev/null +++ b/lib/ldpc/ex-dep-out @@ -0,0 +1,224 @@ + +# CODE 1 + +make-pchk ex-dep.pchk 4 6 0:0 0:5 3:1 3:2 +print-pchk -d ex-dep.pchk + +Parity check matrix in ex-dep.pchk (dense format): + + 1 0 0 0 0 1 + 0 0 0 0 0 0 + 0 0 0 0 0 0 + 0 1 1 0 0 0 + +echo 00011011 >ex-dep.src + +# SPARSE REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen sparse +Note: Parity check matrix has 2 redundant checks +Number of 1s per check in L is 0.8, U is 0.5, B is 0.2, total is 1.5 +print-gen -d ex-dep.gen + +Generator matrix in ex-dep.gen (sparse representation): + +Column order (message bits at end): + + 5 2 1 3 4 0 + +Row order: + + 0 3 2 1 + +L: + + 1 0 0 0 + 0 0 0 0 + 0 0 0 0 + 0 1 0 0 + +U: + + 0 0 0 0 0 1 + 0 1 1 0 0 0 + 0 0 0 0 0 0 + 0 0 0 0 0 0 + +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +Encoded 4 blocks, source block size 2, encoded block size 6 +000000 +100001 +000010 +100011 +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src +Block counts: tot 4, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 + +# DENSE REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen dense +Note: Parity check matrix has 2 redundant checks +Number of 1s per check in Inv(A) X B is 0.2 +print-gen -d ex-dep.gen + +Generator matrix in ex-dep.gen (dense representation): + +Column order (message bits at end): + + 0 1 2 3 4 5 + +Inv(A) X B: + + 0 1 + 0 0 + 0 0 + 0 0 + +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +Encoded 4 blocks, source block size 2, encoded block size 6 +000000 +100001 +000010 +100011 +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src +Block counts: tot 4, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 + +# MIXED REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen mixed +Note: Parity check matrix has 2 redundant checks +Number of 1s per check in Inv(A) is 0.5, in B is 0.2, total is 0.8 +print-gen -d ex-dep.gen + +Generator matrix in ex-dep.gen (mixed representation): + +Column order (message bits at end): + + 0 1 2 3 4 5 + +Inv(A): + + 1 0 0 0 + 0 0 0 1 + 0 0 0 0 + 0 0 0 0 + +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +Encoded 4 blocks, source block size 2, encoded block size 6 +000000 +100001 +000010 +100011 +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src +Block counts: tot 4, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 + +# CODE 2 + +make-pchk ex-dep.pchk 4 5 0:0 0:1 1:1 1:2 2:0 2:2 3:3 3:4 +print-pchk -d ex-dep.pchk + +Parity check matrix in ex-dep.pchk (dense format): + + 1 1 0 0 0 + 0 1 1 0 0 + 1 0 1 0 0 + 0 0 0 1 1 + +echo 01 >ex-dep.src + +# SPARSE REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen sparse +Note: Parity check matrix has 1 redundant checks +Number of 1s per check in L is 1.0, U is 1.2, B is 0.5, total is 2.8 +print-gen -d ex-dep.gen + +Generator matrix in ex-dep.gen (sparse representation): + +Column order (message bits at end): + + 4 1 2 3 0 + +Row order: + + 3 0 1 2 + +L: + + 0 1 0 0 + 0 1 1 0 + 0 0 1 0 + 1 0 0 0 + +U: + + 0 0 0 1 1 + 0 1 0 0 0 + 0 0 1 0 0 + 0 0 0 0 0 + +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +Encoded 2 blocks, source block size 1, encoded block size 5 +00000 +11100 +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src +Block counts: tot 2, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 + +# DENSE REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen dense +Note: Parity check matrix has 1 redundant checks +Number of 1s per check in Inv(A) X B is 0.2 +print-gen -d ex-dep.gen + +Generator matrix in ex-dep.gen (dense representation): + +Column order (message bits at end): + + 0 1 3 2 4 + +Inv(A) X B: + + 0 + 0 + 1 + 0 + +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +Encoded 2 blocks, source block size 1, encoded block size 5 +00000 +00011 +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src +Block counts: tot 2, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 + +# MIXED REPRESENTATION + +make-gen ex-dep.pchk ex-dep.gen mixed +Note: Parity check matrix has 1 redundant checks +Number of 1s per check in Inv(A) is 1.0, in B is 0.2, total is 1.2 +print-gen -d ex-dep.gen + +Generator matrix in ex-dep.gen (mixed representation): + +Column order (message bits at end): + + 0 1 3 2 4 + +Inv(A): + + 1 1 0 0 + 0 1 0 0 + 0 0 0 1 + 0 0 0 0 + +encode ex-dep.pchk ex-dep.gen ex-dep.src ex-dep.enc; cat ex-dep.enc +Encoded 2 blocks, source block size 1, encoded block size 5 +00000 +00011 +verify ex-dep.pchk ex-dep.enc ex-dep.gen ex-dep.src +Block counts: tot 2, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 diff --git a/lib/ldpc/ex-ham7a b/lib/ldpc/ex-ham7a new file mode 100755 index 00000000..7ccc0809 --- /dev/null +++ b/lib/ldpc/ex-ham7a @@ -0,0 +1,38 @@ +#!/bin/sh + +# Example of decoding a (7,4) Hamming code using exhaustive enumeration and +# probability propagation, with an Additive White Gaussian Noise channel with +# noise standard deviation of 0.5, for which Eb/N0 = 5.44 dB. +# +# Testing is done by transmitting zero blocks, which is sufficient because +# both the channel and the decoding procedure are symmetrical. WARNING: But +# things can easily become non-symmetrical with bugs, so this technique should +# be used with caution, and only when necessary for performance reasons. +# Decoding is done three times, once minimizing block error probability, once +# minimizing bit error probability, and once by up to 200 iterations of +# probability propagation. + +set -e # Stop if an error occurs +set -v # Echo commands as they are read + +make-pchk ex-ham7a.pchk 3 7 0:0 0:3 0:4 0:5 1:1 1:3 1:4 1:6 2:2 2:4 2:5 2:6 +make-gen ex-ham7a.pchk ex-ham7a.gen dense +transmit 7x100000 ex-ham7a.rec 1 awgn 0.5 + +# DECODE BY ENUMERATION TO MINIMIZE BLOCK ERROR PROBABILITY + +decode ex-ham7a.pchk ex-ham7a.rec ex-ham7a.dec-blk awgn 0.5 \ + enum-block ex-ham7a.gen +verify ex-ham7a.pchk ex-ham7a.dec-blk ex-ham7a.gen + +# DECODE BY ENUMERATION TO MINIMIZE BIT ERROR PROBABILITY + +decode ex-ham7a.pchk ex-ham7a.rec ex-ham7a.dec-bit awgn 0.5 \ + enum-bit ex-ham7a.gen +verify ex-ham7a.pchk ex-ham7a.dec-bit ex-ham7a.gen + +# DECODE BY PROBABILITY PROPAGATION + +decode ex-ham7a.pchk ex-ham7a.rec ex-ham7a.dec-prp awgn 0.5 \ + prprp 200 +verify ex-ham7a.pchk ex-ham7a.dec-prp ex-ham7a.gen diff --git a/lib/ldpc/ex-ham7a-out b/lib/ldpc/ex-ham7a-out new file mode 100755 index 00000000..eaa4ea52 --- /dev/null +++ b/lib/ldpc/ex-ham7a-out @@ -0,0 +1,33 @@ + +make-pchk ex-ham7a.pchk 3 7 0:0 0:3 0:4 0:5 1:1 1:3 1:4 1:6 2:2 2:4 2:5 2:6 +make-gen ex-ham7a.pchk ex-ham7a.gen dense +Number of 1s per check in Inv(A) X B is 3.0 +transmit 7x100000 ex-ham7a.rec 1 awgn 0.5 +Transmitted 700000 bits + +# DECODE BY ENUMERATION TO MINIMIZE BLOCK ERROR PROBABILITY + +decode ex-ham7a.pchk ex-ham7a.rec ex-ham7a.dec-blk awgn 0.5 \ + enum-block ex-ham7a.gen +Decoded 100000 blocks, 100000 valid. Average 16.0 iterations, 2% bit changes +verify ex-ham7a.pchk ex-ham7a.dec-blk ex-ham7a.gen +Block counts: tot 100000, with chk errs 0, with src errs 186, both 0 +Bit error rate (on message bits only): 7.950e-04 + +# DECODE BY ENUMERATION TO MINIMIZE BIT ERROR PROBABILITY + +decode ex-ham7a.pchk ex-ham7a.rec ex-ham7a.dec-bit awgn 0.5 \ + enum-bit ex-ham7a.gen +Decoded 100000 blocks, 99988 valid. Average 16.0 iterations, 2% bit changes +verify ex-ham7a.pchk ex-ham7a.dec-bit ex-ham7a.gen +Block counts: tot 100000, with chk errs 12, with src errs 186, both 7 +Bit error rate (on message bits only): 7.775e-04 + +# DECODE BY PROBABILITY PROPAGATION + +decode ex-ham7a.pchk ex-ham7a.rec ex-ham7a.dec-prp awgn 0.5 \ + prprp 200 +Decoded 100000 blocks, 99927 valid. Average 0.3 iterations, 2% bit changes +verify ex-ham7a.pchk ex-ham7a.dec-prp ex-ham7a.gen +Block counts: tot 100000, with chk errs 73, with src errs 276, both 52 +Bit error rate (on message bits only): 1.290e-03 diff --git a/lib/ldpc/ex-ham7b b/lib/ldpc/ex-ham7b new file mode 100755 index 00000000..3bdd4a60 --- /dev/null +++ b/lib/ldpc/ex-ham7b @@ -0,0 +1,21 @@ +#!/bin/sh + +# Example of coding using a (7,4) Hamming code, with transmission through +# a Binary Symmetric Channel with error probability of 0.05. +# +# This example shows how random source messages can be encoded as codewords, +# transmitted through the simulated channel, decoded, and the message bits +# extracted from the codewords. The final result is in ex-ham7b.ext, which can +# be compared to ex-ham7b.src. + +set -e # Stop if an error occurs +set -v # Echo commands as they are read + +make-pchk ex-ham7b.pchk 3 7 0:0 0:3 0:4 0:5 1:1 1:3 1:4 1:6 2:2 2:4 2:5 2:6 +make-gen ex-ham7b.pchk ex-ham7b.gen dense +rand-src ex-ham7b.src 1 4x1000 +encode ex-ham7b.pchk ex-ham7b.gen ex-ham7b.src ex-ham7b.enc +transmit ex-ham7b.enc ex-ham7b.rec 1 bsc 0.05 +decode ex-ham7b.pchk ex-ham7b.rec ex-ham7b.dec bsc 0.05 enum-bit ex-ham7b.gen +verify ex-ham7b.pchk ex-ham7b.dec ex-ham7b.gen ex-ham7b.src +extract ex-ham7b.gen ex-ham7b.dec ex-ham7b.ext diff --git a/lib/ldpc/ex-ham7b-out b/lib/ldpc/ex-ham7b-out new file mode 100755 index 00000000..37ecfc49 --- /dev/null +++ b/lib/ldpc/ex-ham7b-out @@ -0,0 +1,15 @@ + +make-pchk ex-ham7b.pchk 3 7 0:0 0:3 0:4 0:5 1:1 1:3 1:4 1:6 2:2 2:4 2:5 2:6 +make-gen ex-ham7b.pchk ex-ham7b.gen dense +Number of 1s per check in Inv(A) X B is 3.0 +rand-src ex-ham7b.src 1 4x1000 +encode ex-ham7b.pchk ex-ham7b.gen ex-ham7b.src ex-ham7b.enc +Encoded 1000 blocks, source block size 4, encoded block size 7 +transmit ex-ham7b.enc ex-ham7b.rec 1 bsc 0.05 +Transmitted 7000 bits +decode ex-ham7b.pchk ex-ham7b.rec ex-ham7b.dec bsc 0.05 enum-bit ex-ham7b.gen +Decoded 1000 blocks, 1000 valid. Average 16.0 iterations, 4% bit changes +verify ex-ham7b.pchk ex-ham7b.dec ex-ham7b.gen ex-ham7b.src +Block counts: tot 1000, with chk errs 0, with src errs 47, both 0 +Bit error rate (on message bits only): 2.000e-02 +extract ex-ham7b.gen ex-ham7b.dec ex-ham7b.ext diff --git a/lib/ldpc/ex-ldpc-encode b/lib/ldpc/ex-ldpc-encode new file mode 100755 index 00000000..7165e482 --- /dev/null +++ b/lib/ldpc/ex-ldpc-encode @@ -0,0 +1,45 @@ +#!/bin/sh + +# Example of how an LDPC code can be encoded using using sparse, +# dense, and mixed representations of the generator matrix. The dense +# and mixed representations are based on the same set of message bits +# as the sparse method with minprod heuristic. This allows the correctness +# of these methods to be checked by verifying that they all produce the same +# result when encoding random messages. The results are also checked by +# 'verify'. +# +# A (400,200) LDPC code with 3 checks per bit is used for the test. + +set -e # Stop if an error occurs +set -v # Echo commands as they are read + +make-ldpc ex-ldpc-encode.pchk 200 400 1 evenboth 3 + +make-gen ex-ldpc-encode.pchk ex-ldpc-encode.genf sparse first +make-gen ex-ldpc-encode.pchk ex-ldpc-encode.genc sparse mincol +make-gen ex-ldpc-encode.pchk ex-ldpc-encode.genp sparse minprod +make-gen ex-ldpc-encode.pchk ex-ldpc-encode.gend dense ex-ldpc-encode.genp +make-gen ex-ldpc-encode.pchk ex-ldpc-encode.genm mixed ex-ldpc-encode.genp + +rand-src ex-ldpc-encode.src 1 200x10 + +encode ex-ldpc-encode.pchk ex-ldpc-encode.genf ex-ldpc-encode.src \ + ex-ldpc-encode.encf +encode ex-ldpc-encode.pchk ex-ldpc-encode.genc ex-ldpc-encode.src \ + ex-ldpc-encode.encc +encode ex-ldpc-encode.pchk ex-ldpc-encode.genp ex-ldpc-encode.src \ + ex-ldpc-encode.encp +encode ex-ldpc-encode.pchk ex-ldpc-encode.gend ex-ldpc-encode.src \ + ex-ldpc-encode.encd +encode ex-ldpc-encode.pchk ex-ldpc-encode.genm ex-ldpc-encode.src \ + ex-ldpc-encode.encm + +cmp ex-ldpc-encode.encp ex-ldpc-encode.encd +cmp ex-ldpc-encode.encp ex-ldpc-encode.encm + +verify ex-ldpc-encode.pchk ex-ldpc-encode.encf ex-ldpc-encode.genf \ + ex-ldpc-encode.src +verify ex-ldpc-encode.pchk ex-ldpc-encode.encc ex-ldpc-encode.genc \ + ex-ldpc-encode.src +verify ex-ldpc-encode.pchk ex-ldpc-encode.encp ex-ldpc-encode.genp \ + ex-ldpc-encode.src diff --git a/lib/ldpc/ex-ldpc-encode-out b/lib/ldpc/ex-ldpc-encode-out new file mode 100755 index 00000000..0dc1a1cf --- /dev/null +++ b/lib/ldpc/ex-ldpc-encode-out @@ -0,0 +1,47 @@ + +make-ldpc ex-ldpc-encode.pchk 200 400 1 evenboth 3 + +make-gen ex-ldpc-encode.pchk ex-ldpc-encode.genf sparse first +Number of 1s per check in L is 6.4, U is 6.4, B is 3.0, total is 15.8 +make-gen ex-ldpc-encode.pchk ex-ldpc-encode.genc sparse mincol +Number of 1s per check in L is 3.0, U is 3.3, B is 3.0, total is 9.3 +make-gen ex-ldpc-encode.pchk ex-ldpc-encode.genp sparse minprod +Number of 1s per check in L is 2.4, U is 3.2, B is 3.0, total is 8.6 +make-gen ex-ldpc-encode.pchk ex-ldpc-encode.gend dense ex-ldpc-encode.genp +Number of 1s per check in Inv(A) X B is 69.2 +make-gen ex-ldpc-encode.pchk ex-ldpc-encode.genm mixed ex-ldpc-encode.genp +Number of 1s per check in Inv(A) is 64.7, in B is 3.0, total is 67.7 + +rand-src ex-ldpc-encode.src 1 200x10 + +encode ex-ldpc-encode.pchk ex-ldpc-encode.genf ex-ldpc-encode.src \ + ex-ldpc-encode.encf +Encoded 10 blocks, source block size 200, encoded block size 400 +encode ex-ldpc-encode.pchk ex-ldpc-encode.genc ex-ldpc-encode.src \ + ex-ldpc-encode.encc +Encoded 10 blocks, source block size 200, encoded block size 400 +encode ex-ldpc-encode.pchk ex-ldpc-encode.genp ex-ldpc-encode.src \ + ex-ldpc-encode.encp +Encoded 10 blocks, source block size 200, encoded block size 400 +encode ex-ldpc-encode.pchk ex-ldpc-encode.gend ex-ldpc-encode.src \ + ex-ldpc-encode.encd +Encoded 10 blocks, source block size 200, encoded block size 400 +encode ex-ldpc-encode.pchk ex-ldpc-encode.genm ex-ldpc-encode.src \ + ex-ldpc-encode.encm +Encoded 10 blocks, source block size 200, encoded block size 400 + +cmp ex-ldpc-encode.encp ex-ldpc-encode.encd +cmp ex-ldpc-encode.encp ex-ldpc-encode.encm + +verify ex-ldpc-encode.pchk ex-ldpc-encode.encf ex-ldpc-encode.genf \ + ex-ldpc-encode.src +Block counts: tot 10, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 +verify ex-ldpc-encode.pchk ex-ldpc-encode.encc ex-ldpc-encode.genc \ + ex-ldpc-encode.src +Block counts: tot 10, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 +verify ex-ldpc-encode.pchk ex-ldpc-encode.encp ex-ldpc-encode.genp \ + ex-ldpc-encode.src +Block counts: tot 10, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 diff --git a/lib/ldpc/ex-ldpc36-1000a b/lib/ldpc/ex-ldpc36-1000a new file mode 100755 index 00000000..19c4ba08 --- /dev/null +++ b/lib/ldpc/ex-ldpc36-1000a @@ -0,0 +1,50 @@ +#!/bin/sh + +# Example of a (2000,1000) LDPC code with 3 checks per bit and 6 bits per +# check, tested on Additive White Gaussian Noise channels with noise standard +# deviations varying from 0.80 to 0.95. +# +# Testing is done by transmitting random messages, which is safer (though +# slower) than using only zero messages. Decoding is done using a maximum +# of 250 iterations of probability propagation. + +set -e # Stop if an error occurs +set -v # Echo commands as they are read + +make-ldpc ex-ldpc36-1000a.pchk 1000 2000 1 evenboth 3 no4cycle +make-gen ex-ldpc36-1000a.pchk ex-ldpc36-1000a.gen dense +rand-src ex-ldpc36-1000a.src 1 1000x100 +encode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.gen ex-ldpc36-1000a.src \ + ex-ldpc36-1000a.enc + +# NOISE STANDARD DEVIATION 0.80, Eb/N0 = 1.94 dB + +transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.80 +decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.80\ + prprp 250 +verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \ + ex-ldpc36-1000a.src + +# NOISE STANDARD DEVIATION 0.85, Eb/N0 = 1.41 dB + +transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.85 +decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.85\ + prprp 250 +verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \ + ex-ldpc36-1000a.src + +# NOISE STANDARD DEVIATION 0.90, Eb/N0 = 0.92 dB + +transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.90 +decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.90\ + prprp 250 +verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \ + ex-ldpc36-1000a.src + +# NOISE STANDARD DEVIATION 0.95, Eb/N0 = 0.45 dB + +transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.95 +decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.95\ + prprp 250 +verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \ + ex-ldpc36-1000a.src diff --git a/lib/ldpc/ex-ldpc36-1000a-out b/lib/ldpc/ex-ldpc36-1000a-out new file mode 100755 index 00000000..418ed5c9 --- /dev/null +++ b/lib/ldpc/ex-ldpc36-1000a-out @@ -0,0 +1,57 @@ + +make-ldpc ex-ldpc36-1000a.pchk 1000 2000 1 evenboth 3 no4cycle +Eliminated 24 cycles of length four by moving checks within column +make-gen ex-ldpc36-1000a.pchk ex-ldpc36-1000a.gen dense +Number of 1s per check in Inv(A) X B is 400.3 +rand-src ex-ldpc36-1000a.src 1 1000x100 +encode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.gen ex-ldpc36-1000a.src \ + ex-ldpc36-1000a.enc +Encoded 100 blocks, source block size 1000, encoded block size 2000 + +# NOISE STANDARD DEVIATION 0.80, Eb/N0 = 1.94 dB + +transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.80 +Transmitted 200000 bits +decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.80\ + prprp 250 +Decoded 100 blocks, 100 valid. Average 10.8 iterations, 11% bit changes +verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \ + ex-ldpc36-1000a.src +Block counts: tot 100, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 + +# NOISE STANDARD DEVIATION 0.85, Eb/N0 = 1.41 dB + +transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.85 +Transmitted 200000 bits +decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.85\ + prprp 250 +Decoded 100 blocks, 88 valid. Average 52.2 iterations, 12% bit changes +verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \ + ex-ldpc36-1000a.src +Block counts: tot 100, with chk errs 12, with src errs 12, both 12 +Bit error rate (on message bits only): 7.490e-03 + +# NOISE STANDARD DEVIATION 0.90, Eb/N0 = 0.92 dB + +transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.90 +Transmitted 200000 bits +decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.90\ + prprp 250 +Decoded 100 blocks, 19 valid. Average 209.4 iterations, 11% bit changes +verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \ + ex-ldpc36-1000a.src +Block counts: tot 100, with chk errs 81, with src errs 81, both 81 +Bit error rate (on message bits only): 6.529e-02 + +# NOISE STANDARD DEVIATION 0.95, Eb/N0 = 0.45 dB + +transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.95 +Transmitted 200000 bits +decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.95\ + prprp 250 +Decoded 100 blocks, 1 valid. Average 248.0 iterations, 9% bit changes +verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \ + ex-ldpc36-1000a.src +Block counts: tot 100, with chk errs 99, with src errs 99, both 99 +Bit error rate (on message bits only): 1.055e-01 diff --git a/lib/ldpc/ex-ldpc36-5000a b/lib/ldpc/ex-ldpc36-5000a new file mode 100755 index 00000000..f791e056 --- /dev/null +++ b/lib/ldpc/ex-ldpc36-5000a @@ -0,0 +1,44 @@ +#!/bin/sh + +# Example of a (10000,5000) LDPC code with 3 checks per bit and 6 bits per +# check, tested on Additive White Gaussian Noise channels with noise standard +# deviations varying from 0.80 to 0.95. +# +# Testing is done by transmitting random messages, with pipes used so that +# intermediate files are avoided. Decoding is done using a maximum of 250 +# iterations of probability propagation. + +set -e # Stop if an error occurs +set -v # Echo commands as they are read + +make-ldpc ex-ldpc36-5000a.pchk 5000 10000 2 evenboth 3 no4cycle +make-gen ex-ldpc36-5000a.pchk ex-ldpc36-5000a.gen dense +rand-src ex-ldpc36-5000a.src 1 5000x100 + +# NOISE STANDARD DEVIATION 0.80, Eb/N0 = 1.94 dB + +encode ex-ldpc36-5000a.pchk ex-ldpc36-5000a.gen ex-ldpc36-5000a.src - \ + | transmit - - 1 awgn 0.80 \ + | decode ex-ldpc36-5000a.pchk - - awgn 0.80 prprp 250 \ + | verify ex-ldpc36-5000a.pchk - ex-ldpc36-5000a.gen ex-ldpc36-5000a.src + +# NOISE STANDARD DEVIATION 0.85, Eb/N0 = 1.41 dB + +encode ex-ldpc36-5000a.pchk ex-ldpc36-5000a.gen ex-ldpc36-5000a.src - \ + | transmit - - 1 awgn 0.85 \ + | decode ex-ldpc36-5000a.pchk - - awgn 0.85 prprp 250 \ + | verify ex-ldpc36-5000a.pchk - ex-ldpc36-5000a.gen ex-ldpc36-5000a.src + +# NOISE STANDARD DEVIATION 0.90, Eb/N0 = 0.92 dB + +encode ex-ldpc36-5000a.pchk ex-ldpc36-5000a.gen ex-ldpc36-5000a.src - \ + | transmit - - 1 awgn 0.90 \ + | decode ex-ldpc36-5000a.pchk - - awgn 0.90 prprp 250 \ + | verify ex-ldpc36-5000a.pchk - ex-ldpc36-5000a.gen ex-ldpc36-5000a.src + +# NOISE STANDARD DEVIATION 0.95, Eb/N0 = 0.45 dB + +encode ex-ldpc36-5000a.pchk ex-ldpc36-5000a.gen ex-ldpc36-5000a.src - \ + | transmit - - 1 awgn 0.95 \ + | decode ex-ldpc36-5000a.pchk - - awgn 0.95 prprp 250 \ + | verify ex-ldpc36-5000a.pchk - ex-ldpc36-5000a.gen ex-ldpc36-5000a.src diff --git a/lib/ldpc/ex-ldpc36-5000a-out b/lib/ldpc/ex-ldpc36-5000a-out new file mode 100755 index 00000000..f7bae5b9 --- /dev/null +++ b/lib/ldpc/ex-ldpc36-5000a-out @@ -0,0 +1,54 @@ + +make-ldpc ex-ldpc36-5000a.pchk 5000 10000 2 evenboth 3 no4cycle +Eliminated 25 cycles of length four by moving checks within column +make-gen ex-ldpc36-5000a.pchk ex-ldpc36-5000a.gen dense +Number of 1s per check in Inv(A) X B is 2068.3 +rand-src ex-ldpc36-5000a.src 1 5000x100 + +# NOISE STANDARD DEVIATION 0.80, Eb/N0 = 1.94 dB + +encode ex-ldpc36-5000a.pchk ex-ldpc36-5000a.gen ex-ldpc36-5000a.src - \ + | transmit - - 1 awgn 0.80 \ + | decode ex-ldpc36-5000a.pchk - - awgn 0.80 prprp 250 \ + | verify ex-ldpc36-5000a.pchk - ex-ldpc36-5000a.gen ex-ldpc36-5000a.src +Encoded 100 blocks, source block size 5000, encoded block size 10000 +Transmitted 1000000 bits +Decoded 100 blocks, 100 valid. Average 11.1 iterations, 11% bit changes +Block counts: tot 100, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 + +# NOISE STANDARD DEVIATION 0.85, Eb/N0 = 1.41 dB + +encode ex-ldpc36-5000a.pchk ex-ldpc36-5000a.gen ex-ldpc36-5000a.src - \ + | transmit - - 1 awgn 0.85 \ + | decode ex-ldpc36-5000a.pchk - - awgn 0.85 prprp 250 \ + | verify ex-ldpc36-5000a.pchk - ex-ldpc36-5000a.gen ex-ldpc36-5000a.src +Encoded 100 blocks, source block size 5000, encoded block size 10000 +Transmitted 1000000 bits +Decoded 100 blocks, 95 valid. Average 33.7 iterations, 12% bit changes +Block counts: tot 100, with chk errs 5, with src errs 5, both 5 +Bit error rate (on message bits only): 2.706e-03 + +# NOISE STANDARD DEVIATION 0.90, Eb/N0 = 0.92 dB + +encode ex-ldpc36-5000a.pchk ex-ldpc36-5000a.gen ex-ldpc36-5000a.src - \ + | transmit - - 1 awgn 0.90 \ + | decode ex-ldpc36-5000a.pchk - - awgn 0.90 prprp 250 \ + | verify ex-ldpc36-5000a.pchk - ex-ldpc36-5000a.gen ex-ldpc36-5000a.src +Encoded 100 blocks, source block size 5000, encoded block size 10000 +Transmitted 1000000 bits +Decoded 100 blocks, 2 valid. Average 246.2 iterations, 10% bit changes +Block counts: tot 100, with chk errs 98, with src errs 98, both 98 +Bit error rate (on message bits only): 7.650e-02 + +# NOISE STANDARD DEVIATION 0.95, Eb/N0 = 0.45 dB + +encode ex-ldpc36-5000a.pchk ex-ldpc36-5000a.gen ex-ldpc36-5000a.src - \ + | transmit - - 1 awgn 0.95 \ + | decode ex-ldpc36-5000a.pchk - - awgn 0.95 prprp 250 \ + | verify ex-ldpc36-5000a.pchk - ex-ldpc36-5000a.gen ex-ldpc36-5000a.src +Encoded 100 blocks, source block size 5000, encoded block size 10000 +Transmitted 1000000 bits +Decoded 100 blocks, 0 valid. Average 250.0 iterations, 9% bit changes +Block counts: tot 100, with chk errs 100, with src errs 100, both 100 +Bit error rate (on message bits only): 1.092e-01 diff --git a/lib/ldpc/ex-ldpcvar-5000a b/lib/ldpc/ex-ldpcvar-5000a new file mode 100755 index 00000000..e8995e54 --- /dev/null +++ b/lib/ldpc/ex-ldpcvar-5000a @@ -0,0 +1,46 @@ +#!/bin/sh + +# Example of a (10000,5000) LDPC code with varying numbers of check per bit, +# tested on Additive White Gaussian Noise channels with noise standard +# deviations varying from 0.80 to 0.95. The code has 20% columns with two +# check bits, 70% columns with three check bits, and 10% columns with seven +# check bits. +# +# Testing is done by transmitting random messages, with pipes used so that +# intermediate files are avoided. Decoding is done using a maximum of 250 +# iterations of probability propagation. + +set -e # Stop if an error occurs +set -v # Echo commands as they are read + +make-ldpc ex-ldpcvar-5000a.pchk 5000 10000 2 evenboth 2x2/7x3/1x7 no4cycle +make-gen ex-ldpcvar-5000a.pchk ex-ldpcvar-5000a.gen dense +rand-src ex-ldpcvar-5000a.src 1 5000x100 + +# NOISE STANDARD DEVIATION 0.80, Eb/N0 = 1.94 dB + +encode ex-ldpcvar-5000a.pchk ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src - \ + | transmit - - 1 awgn 0.80 \ + | decode ex-ldpcvar-5000a.pchk - - awgn 0.80 prprp 250 \ + | verify ex-ldpcvar-5000a.pchk - ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src + +# NOISE STANDARD DEVIATION 0.85, Eb/N0 = 1.41 dB + +encode ex-ldpcvar-5000a.pchk ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src - \ + | transmit - - 1 awgn 0.85 \ + | decode ex-ldpcvar-5000a.pchk - - awgn 0.85 prprp 250 \ + | verify ex-ldpcvar-5000a.pchk - ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src + +# NOISE STANDARD DEVIATION 0.90, Eb/N0 = 0.92 dB + +encode ex-ldpcvar-5000a.pchk ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src - \ + | transmit - - 1 awgn 0.90 \ + | decode ex-ldpcvar-5000a.pchk - - awgn 0.90 prprp 250 \ + | verify ex-ldpcvar-5000a.pchk - ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src + +# NOISE STANDARD DEVIATION 0.95, Eb/N0 = 0.45 dB + +encode ex-ldpcvar-5000a.pchk ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src - \ + | transmit - - 1 awgn 0.95 \ + | decode ex-ldpcvar-5000a.pchk - - awgn 0.95 prprp 250 \ + | verify ex-ldpcvar-5000a.pchk - ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src diff --git a/lib/ldpc/ex-ldpcvar-5000a-out b/lib/ldpc/ex-ldpcvar-5000a-out new file mode 100755 index 00000000..3cdb2081 --- /dev/null +++ b/lib/ldpc/ex-ldpcvar-5000a-out @@ -0,0 +1,54 @@ + +make-ldpc ex-ldpcvar-5000a.pchk 5000 10000 2 evenboth 2x2/7x3/1x7 no4cycle +Eliminated 46 cycles of length four by moving checks within column +make-gen ex-ldpcvar-5000a.pchk ex-ldpcvar-5000a.gen dense +Number of 1s per check in Inv(A) X B is 1437.1 +rand-src ex-ldpcvar-5000a.src 1 5000x100 + +# NOISE STANDARD DEVIATION 0.80, Eb/N0 = 1.94 dB + +encode ex-ldpcvar-5000a.pchk ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src - \ + | transmit - - 1 awgn 0.80 \ + | decode ex-ldpcvar-5000a.pchk - - awgn 0.80 prprp 250 \ + | verify ex-ldpcvar-5000a.pchk - ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src +Encoded 100 blocks, source block size 5000, encoded block size 10000 +Transmitted 1000000 bits +Decoded 100 blocks, 100 valid. Average 11.3 iterations, 11% bit changes +Block counts: tot 100, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 + +# NOISE STANDARD DEVIATION 0.85, Eb/N0 = 1.41 dB + +encode ex-ldpcvar-5000a.pchk ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src - \ + | transmit - - 1 awgn 0.85 \ + | decode ex-ldpcvar-5000a.pchk - - awgn 0.85 prprp 250 \ + | verify ex-ldpcvar-5000a.pchk - ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src +Encoded 100 blocks, source block size 5000, encoded block size 10000 +Transmitted 1000000 bits +Decoded 100 blocks, 100 valid. Average 18.0 iterations, 12% bit changes +Block counts: tot 100, with chk errs 0, with src errs 0, both 0 +Bit error rate (on message bits only): 0.000e+00 + +# NOISE STANDARD DEVIATION 0.90, Eb/N0 = 0.92 dB + +encode ex-ldpcvar-5000a.pchk ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src - \ + | transmit - - 1 awgn 0.90 \ + | decode ex-ldpcvar-5000a.pchk - - awgn 0.90 prprp 250 \ + | verify ex-ldpcvar-5000a.pchk - ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src +Encoded 100 blocks, source block size 5000, encoded block size 10000 +Transmitted 1000000 bits +Decoded 100 blocks, 65 valid. Average 119.8 iterations, 12% bit changes +Block counts: tot 100, with chk errs 35, with src errs 35, both 35 +Bit error rate (on message bits only): 2.438e-02 + +# NOISE STANDARD DEVIATION 0.95, Eb/N0 = 0.45 dB + +encode ex-ldpcvar-5000a.pchk ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src - \ + | transmit - - 1 awgn 0.95 \ + | decode ex-ldpcvar-5000a.pchk - - awgn 0.95 prprp 250 \ + | verify ex-ldpcvar-5000a.pchk - ex-ldpcvar-5000a.gen ex-ldpcvar-5000a.src +Encoded 100 blocks, source block size 5000, encoded block size 10000 +Transmitted 1000000 bits +Decoded 100 blocks, 0 valid. Average 250.0 iterations, 9% bit changes +Block counts: tot 100, with chk errs 100, with src errs 100, both 100 +Bit error rate (on message bits only): 1.017e-01 diff --git a/lib/ldpc/ex-wrong-model b/lib/ldpc/ex-wrong-model new file mode 100755 index 00000000..a8304c6c --- /dev/null +++ b/lib/ldpc/ex-wrong-model @@ -0,0 +1,124 @@ +#!/bin/sh + +# These tests investigate what happens when the wrong model is used for +# decoding. A (1800,1000) LDPC code with 3 check per bit is used. +# Testing is done by transmitting random messages. Decoding is done using +# a maximum of 100 iterations of probability propagation. +# +# The first set of tests compares decoding of messages sent through an +# AWGN channel using the correct AWGN model with sigma=0.90 to decoding +# using AWGN models with incorrect values for sigma and to decoding +# using AWLN models with varying width parameters for the logistic noise +# distribution. +# +# A second set of tests compares decoding of messages sent through an +# AWLN channel using the correct AWLN model with width=0.50 to decoding +# using AWLN models with incorrect values for width and to decoding +# using AWGN models with varying sigma parameters. + +set -e # Stop if an error occurs +set -v # Echo commands as they are read + +make-ldpc ex-wrong-model.pchk 1000 1800 1 evenboth 3 no4cycle +make-gen ex-wrong-model.pchk ex-wrong-model.gen dense +rand-src ex-wrong-model.src 1 800x1000 +encode ex-wrong-model.pchk ex-wrong-model.gen ex-wrong-model.src \ + ex-wrong-model.enc + +# FIRST SET OF TESTS, TRANSMITTING THROUGH AWGN CHANNEL WITH SIGMA=0.90 + +transmit ex-wrong-model.enc ex-wrong-model.rec 1 awgn 0.90 + +# DECODING WITH CORRECT AWGN NOISE MODEL, SIGMA=0.90 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.90 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.95 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.95 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.85 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.85 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.40 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.40 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.45 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.45 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.50 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.50 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.55 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.55 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.60 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.60 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.65 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.65 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# SECOND SET OF TESTS, TRANSMITTING THROUGH AWLN CHANNEL WITH WIDTH=0.50 + +transmit ex-wrong-model.enc ex-wrong-model.rec 1 awln 0.50 + +# DECODING WITH CORRECT AWLN NOISE MODEL, WIDTH=0.50 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.50 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.55 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.55 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.45 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.45 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.80 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.80 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.85 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.85 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.90 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.90 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.95 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.95 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWGN NOISE MODEL, SIGMA=1.00 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 1.00 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src + +# DECODING WITH AWGN NOISE MODEL, SIGMA=1.05 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 1.05 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src diff --git a/lib/ldpc/ex-wrong-model-out b/lib/ldpc/ex-wrong-model-out new file mode 100755 index 00000000..cde814c9 --- /dev/null +++ b/lib/ldpc/ex-wrong-model-out @@ -0,0 +1,163 @@ + +make-ldpc ex-wrong-model.pchk 1000 1800 1 evenboth 3 no4cycle +Eliminated 19 cycles of length four by moving checks within column +make-gen ex-wrong-model.pchk ex-wrong-model.gen dense +Number of 1s per check in Inv(A) X B is 318.6 +rand-src ex-wrong-model.src 1 800x1000 +encode ex-wrong-model.pchk ex-wrong-model.gen ex-wrong-model.src \ + ex-wrong-model.enc +Encoded 1000 blocks, source block size 800, encoded block size 1800 + +# FIRST SET OF TESTS, TRANSMITTING THROUGH AWGN CHANNEL WITH SIGMA=0.90 + +transmit ex-wrong-model.enc ex-wrong-model.rec 1 awgn 0.90 +Transmitted 1800000 bits + +# DECODING WITH CORRECT AWGN NOISE MODEL, SIGMA=0.90 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.90 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 910 valid. Average 25.8 iterations, 13% bit changes +Block counts: tot 1000, with chk errs 90, with src errs 89, both 89 +Bit error rate (on message bits only): 6.484e-03 + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.95 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.95 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 909 valid. Average 25.7 iterations, 13% bit changes +Block counts: tot 1000, with chk errs 91, with src errs 91, both 91 +Bit error rate (on message bits only): 6.540e-03 + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.85 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.85 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 900 valid. Average 27.7 iterations, 13% bit changes +Block counts: tot 1000, with chk errs 100, with src errs 100, both 100 +Bit error rate (on message bits only): 7.604e-03 + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.40 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.40 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 755 valid. Average 42.3 iterations, 13% bit changes +Block counts: tot 1000, with chk errs 245, with src errs 245, both 245 +Bit error rate (on message bits only): 1.884e-02 + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.45 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.45 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 827 valid. Average 34.7 iterations, 13% bit changes +Block counts: tot 1000, with chk errs 173, with src errs 172, both 172 +Bit error rate (on message bits only): 1.306e-02 + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.50 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.50 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 849 valid. Average 31.7 iterations, 13% bit changes +Block counts: tot 1000, with chk errs 151, with src errs 151, both 151 +Bit error rate (on message bits only): 1.069e-02 + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.55 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.55 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 855 valid. Average 32.3 iterations, 13% bit changes +Block counts: tot 1000, with chk errs 145, with src errs 145, both 145 +Bit error rate (on message bits only): 1.022e-02 + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.60 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.60 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 790 valid. Average 40.0 iterations, 13% bit changes +Block counts: tot 1000, with chk errs 210, with src errs 210, both 210 +Bit error rate (on message bits only): 1.452e-02 + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.65 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.65 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 540 valid. Average 63.3 iterations, 11% bit changes +Block counts: tot 1000, with chk errs 460, with src errs 460, both 460 +Bit error rate (on message bits only): 3.247e-02 + +# SECOND SET OF TESTS, TRANSMITTING THROUGH AWLN CHANNEL WITH WIDTH=0.50 + +transmit ex-wrong-model.enc ex-wrong-model.rec 1 awln 0.50 +Transmitted 1800000 bits + +# DECODING WITH CORRECT AWLN NOISE MODEL, WIDTH=0.50 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.50 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 914 valid. Average 25.1 iterations, 12% bit changes +Block counts: tot 1000, with chk errs 86, with src errs 86, both 86 +Bit error rate (on message bits only): 6.130e-03 + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.55 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.55 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 907 valid. Average 25.6 iterations, 12% bit changes +Block counts: tot 1000, with chk errs 93, with src errs 93, both 93 +Bit error rate (on message bits only): 6.474e-03 + +# DECODING WITH AWLN NOISE MODEL, WIDTH=0.45 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awln 0.45 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 893 valid. Average 27.5 iterations, 12% bit changes +Block counts: tot 1000, with chk errs 107, with src errs 107, both 107 +Bit error rate (on message bits only): 7.744e-03 + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.80 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.80 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 702 valid. Average 44.9 iterations, 12% bit changes +Block counts: tot 1000, with chk errs 298, with src errs 298, both 298 +Bit error rate (on message bits only): 2.245e-02 + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.85 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.85 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 765 valid. Average 39.4 iterations, 12% bit changes +Block counts: tot 1000, with chk errs 235, with src errs 235, both 235 +Bit error rate (on message bits only): 1.693e-02 + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.90 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.90 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 808 valid. Average 35.7 iterations, 12% bit changes +Block counts: tot 1000, with chk errs 192, with src errs 192, both 192 +Bit error rate (on message bits only): 1.374e-02 + +# DECODING WITH AWGN NOISE MODEL, SIGMA=0.95 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 0.95 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 814 valid. Average 34.6 iterations, 12% bit changes +Block counts: tot 1000, with chk errs 186, with src errs 186, both 186 +Bit error rate (on message bits only): 1.291e-02 + +# DECODING WITH AWGN NOISE MODEL, SIGMA=1.00 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 1.00 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 808 valid. Average 35.6 iterations, 12% bit changes +Block counts: tot 1000, with chk errs 192, with src errs 192, both 192 +Bit error rate (on message bits only): 1.320e-02 + +# DECODING WITH AWGN NOISE MODEL, SIGMA=1.05 + +decode ex-wrong-model.pchk ex-wrong-model.rec - awgn 1.05 prprp 100 \ + | verify ex-wrong-model.pchk - ex-wrong-model.gen ex-wrong-model.src +Decoded 1000 blocks, 771 valid. Average 40.7 iterations, 11% bit changes +Block counts: tot 1000, with chk errs 229, with src errs 228, both 228 +Bit error rate (on message bits only): 1.524e-02 diff --git a/lib/ldpc/examples.html b/lib/ldpc/examples.html new file mode 100755 index 00000000..bc94faed --- /dev/null +++ b/lib/ldpc/examples.html @@ -0,0 +1,87 @@ + + + Examples of LDPC Program Usage + + + + +

Examples of LDPC Program Usage

+ +

Below, are some command files containing examples of the use of +the LDPC programs, together with the output I +obtained for these examples. Output on other machines might +conceivably be slightly different, due to different round-off errors. +The run-examples script runs all the example +scripts and compares their output with the outputs that I obtained (on +a Pentium machine). + +

ex-ham7b, +output in ex-ham7b-out +

+A (7,4) Hamming code used with a BSC. +Demonstrates encoding of random messages and decoding to minimize +bit error rate by exhaustive enumeration. +
+ +

ex-ham7a, +output in ex-ham7a-out +

+A (7,4) Hamming code used with an AWGN channel. Tested using zero messages. +Decoded by exhaustive enumeration to minimize either block or bit error rate, +and by probability propagation. +
+ +

ex-dep, +output in ex-dep-out +

+Examples of how parity check matrices with linearly dependent rows (ie, +redundant parity checks) are handled. This is probably not of +great interest to most users. +
+ +

ex-ldpc-encode, +output in ex-ldpc-encode-out +

+Encodes messages with an LDPC code using sparse, dense, and mixed +representations of the generator matrix. +
+ +

ex-ldpc36-1000a, +output in ex-ldpc36-1000a-out +

+A (2000,1000) LDPC code with 3 checks per bit and 6 bits per check. +Three encoding methods are tried out, and the code is +tested on an AWGN channel at various noise levels, using random messages. +
+ +

ex-ldpc36-5000a, +output in ex-ldpc36-5000a-out +

+A (10000,5000) LDPC code with 3 checks per bit and 6 bits per check. +Tested on an AWGN channel at various noise levels, using random messages. +Pipes are used to avoid creating lots of files. +
+ +

ex-ldpcvar-5000a, +output in ex-ldpcvar-5000a-out +

+A (10000,5000) LDPC code with the number of checks per bit varying from 2 to 7. +Tested on an AWGN channel at various noise levels, using random messages. +Pipes are used to avoid creating lots of files. Performance is better than +for the code above in which the number of checks is the same for all bits. +
+ +

ex-wrong-model, +output in ex-wrong-model-out +

+Tests what happens when messages are decoded using the wrong noise +model, including using the right type of model but with the wrong +noise level, and using the wrong type of model (ie, using an AWLN model +for messages transmitted through an AWGN channel, or vice versa). +
+ +
+ +Back to index for LDPC software + + diff --git a/lib/ldpc/extract.c b/lib/ldpc/extract.c new file mode 100755 index 00000000..f969f897 --- /dev/null +++ b/lib/ldpc/extract.c @@ -0,0 +1,112 @@ +/* EXTRACT.C - Extract message bits from coded blocks. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include +#include + +#include "alloc.h" +#include "blockio.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" + +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + char *gen_file, *coded_file, *ext_file; + FILE *codef, *extf; + char *cblk; + int i; + + /* Look at arguments. */ + + if (!(gen_file = argv[1]) + || !(coded_file = argv[2]) + || !(ext_file = argv[3]) + || argv[4]) + { usage(); + } + + if ((strcmp(gen_file,"-")==0) + (strcmp(coded_file,"-")==0) > 1) + { fprintf(stderr,"Can't read more than one stream from standard input\n"); + exit(1); + } + + /* Read generator matrix file, up to the point of finding out which + are the message bits. */ + + read_gen(gen_file,1,1); + + /* Open decoded file. */ + + codef = open_file_std(coded_file,"r"); + if (codef==NULL) + { fprintf(stderr,"Can't open coded file: %s\n",coded_file); + exit(1); + } + + /* Open file to write extracted message bits to. */ + + extf = open_file_std(ext_file,"w"); + if (extf==NULL) + { fprintf(stderr,"Can't create file for extracted bits: %s\n",ext_file); + exit(1); + } + + cblk = chk_alloc (N, sizeof *cblk); + + for (;;) + { + /* Read block from coded file. */ + + if (blockio_read(codef,cblk,N)==EOF) break; + + /* Extract message bits and write to file, followed by newline to mark + block boundary. */ + + for (i = M; i + + Github Facilities + + + +

Github Facilities

+ +

Starting with the Version of 2012-02-11, the source code repository +for this software is hosted by Github, +and is located at http://github.com/radfordneal/LDPC-codes. +This repository includes the annotated log of changes made since the +Version of 2006-02-08. + +

You can use the facilities at Github to obtain the source-code +repository, report bugs, and contribute to the wiki. + +

Obtaining the source repository, and modifying it

+ +

To obtain a copy of the source-code repository, issue the following +command (in a Unix/Linux/Cygwin environment that has git installed): +

+git clone git://github.com/radfordneal/LDPC-codes
+
+This will retrieve the current state of the software, storing it +in the directory LDPC-codes, which you should ensure does not +exist before issuing this command above. + +

Note that if all you want to do is compile and use the current +version, you can instead download the source without development +history as described in the installation +instructions. + +

The LDPC-codes directory created by the git clone +command is a git repository, which can be manipulated with the various +forms of the git command, which are documented, for example, +here. + +

Each stable version of the software is a separate branch of the +repository. The documentation on the most recent stable version is in +the "gh-pages" branch. The current development version is on the +"master" branch. The are other branches for each stable version that +was released. + +

You can make local changes to your copy of the repository, and use +the modified software. If you wish, you can ask me +(radfordneal@gmail.com) to include your changes in a new release, or, +if you register as a Github user, you can set +up your own fork of the software for you and other people to use. + + +

Reporting Bugs

+ +You can use the Github "Issues" facility to report bugs in the +software. You have to register as a Github +user to do this (which is free). You can then go here and +click on "New issue" to report a bug. You can also use this facility +to suggest new features or other revisions. I may not have time to +implement them, but perhaps someone else will. + +
+ +Back to index for LDPC software + + diff --git a/lib/ldpc/index.html b/lib/ldpc/index.html new file mode 100755 index 00000000..11aa1248 --- /dev/null +++ b/lib/ldpc/index.html @@ -0,0 +1,89 @@ + + + Software for Low Density Parity Check Codes + + + + +

Software for Low Density Parity Check Codes

+ +

Version in development. + +

This collection of programs and modules, written in C, is intended +to support research and education concerning Low Density Parity Check +(LDPC) codes. (Note, however, that the copyright notice no longer +restricts use to these purposes). These error-correcting codes were +invented by Robert Gallager in the early 1960's, and re-invented and +shown to have very good performance by David MacKay and myself in the +mid-1990's. The decoding algorithm for LDPC codes is related to that +used for Turbo codes, and to probabilistic inference methods used in +other fields. Variations on LDPC and Turbo codes are currently the +best practical codes known, in terms of their ability to transmit data +at rates approaching channel capacity with very low error probability. + +

This and past versions of the software are available here, +from Radford Neal's +web page. The source code for this software is also hosted at Github, +where there is a copy +of these documentation pages for the latest release. Github also +provides facilities for bug reporting and discussion. + +

Index to Documentation

+ +Download and installation instructions +
+ How to get and compile the programs and modules. +
+Github facilities +
+ How to get the source repository, report bugs, etc. +
+Release notes +
+ A log of changes made in each release of this software. +
+Software and program usage documentation +
+ General documentation on the methods implemented, and details of + program usage. +
+Examples of program usage +
+ Examples using simple Hamming codes, and using more interesting LDPC codes. +
+How to modify the programs +
+ Notes on how to add new channel types, new decoding methods, etc. +
+Module documentation +
+ Modules used by the programs for modulo-2 matrix + operations and random number generation. +
+References +
+ Classic and more recent papers on LDPC codes and related topics. +
+ +

Copyright and Lack of Warranty

+ +

Except as otherwise specified, all of this software and +documentation is copyright © 1995-2012 by Radford M. Neal. + +

Permission is granted for anyone to copy, use, modify, and distribute +these programs and accompanying documents for any purpose, provided +this copyright notice is retained and prominently displayed, and note +is made of any changes made to these programs. These programs and +documents are distributed without any warranty, express or implied. +As the programs were written for research purposes only, they have not +been tested to the degree that would be advisable in any important +application. All use of these programs is entirely at the user's own +risk. + +

Some routines in the module rand.c are taken from the GNU C Library, +and are copyrighted as described there and in the file LGPL. + + + diff --git a/lib/ldpc/install.html b/lib/ldpc/install.html new file mode 100755 index 00000000..f6966ab5 --- /dev/null +++ b/lib/ldpc/install.html @@ -0,0 +1,82 @@ + + + Installing the LDPC Software + + + +

Installing the LDPC Software

+ +The LDPC software is written in C, and may well work with any C +compiler, though it has been tested only with gcc, in Unix and Linux +environments, and in the Cygwin +Unix-like environment that runs under Microsoft Windows. The +installation instructions below assume that you are using a Unix-like +system. + +

All the software, including the documentation you are viewing here, +is contained in a tar file, which you can download by clicking one +of the options below: +

+ Tar + file of LDPC software (0.9 Megabytes)
+ Gzipped + tar file of LDPC software (0.4 Megabytes) +
+ +

Once you obtain the tar file (and uncompress it with gunzip if +necessary), you should extract the files with the following Unix command: +

+tar xf LDPC-yyyy-mm-dd.tar
+
+This will create a source directory called LDPC-yyyy-mm-dd, and place +all the source, documentation, and other files in this directory. + +

If you prefer for this directory to be called something else, +rename it now, before compiling the programs, since the file +randfile in this directory, containing natural random numbers, +is accessed according to its path when the programs were compiled. + +

Once the tar command above has finished, you should change into the +newly-created directory, and type +

+make
+
+If all goes well, this should compile all the programs (except for some +test programs, which can be compiled with make test). You +may want to edit the file Makefile before running make +in order to change compilation options, such as the optimization level. + +

You can run the programs from this source directory, or you can copy +them to some other directory by running the LDPC-install +shell file. For instance, to install them in a bin directory in your +home directory, do the following: +

+./LDPC-install $HOME/bin
+
+ +

The source directory contains a copy of all the HTML files +documenting the software, such as the one you are reading now, with +the file index.html being the starting point. It is best to +use this local copy when referring to the documentation, rather than +get it off the web, since that is faster and also insures that the +documentation is for the version that you are using. Just tell your +browser to open the URL +

+file:path-to-software/index.html
+
+where path-to-software is the full path (starting with "/") +to the directory where you've put the software. + +

The command +

+make clean
+
+will remove all the compiled programs, as well as the files created when +the examples are run, and core, if it +exists. + +
+ +Back to index for LDPC software + + diff --git a/lib/ldpc/intio.c b/lib/ldpc/intio.c new file mode 100755 index 00000000..bfa8db9f --- /dev/null +++ b/lib/ldpc/intio.c @@ -0,0 +1,110 @@ +/* INTIO.C - Routines to read and write integers one byte at a time. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include + +#include "intio.h" + + +/* READ AN INTEGER ONE BYTE AT A TIME. Four bytes are read, ordered from + low to high order. These are considered to represent a signed integer, + in two's complement form. The value returned is this integer, converted + to whatever a C "int" is. The conversion should work as long as an "int" + is at least four bytes, even if it's not in two's complement representation + (except for the largest two's complement negative integer). + + If an error or eof is encountered, zero is returned. The caller can + check for these events using feof and ferror. + + The file read from should have been opened as "binary". +*/ + +int intio_read +( FILE *f /* File to read from */ +) +{ + unsigned char b[4]; + int top; + int i; + + for (i = 0; i<4; i++) + { if (fread(&b[i],1,1,f) != 1) return 0; + } + + top = b[3]>127 ? (int)b[3] - 256 : b[3]; + + return (top<<24) + (b[2]<<16) + (b[1]<<8) + b[0]; +} + + +/* WRITE AN INTEGER ONE BYTE AT A TIME. Four bytes are written, ordered from + low to high order. These are considered to represent a signed integer, + in two's complement form. This should work as long as the integer passed + can be represented in four bytes, even if a C "int" is longer than this. + + The file written to should have been opened as "binary". +*/ + +void intio_write +( FILE *f, /* File to write to */ + int v /* Value to write to file */ +) +{ + unsigned char b; + int i; + + for (i = 0; i<3; i++) + { b = v&0xff; + fwrite(&b,1,1,f); + v >>= 8; + } + + b = v>0 ? v : v+256; + fwrite(&b,1,1,f); +} + + +/* TEST PROGRAM. */ + +#ifdef TEST_INTIO + +main(void) +{ + FILE *f; + f = fopen("test","wb"); + intio_write(f,334); + intio_write(f,-40000); + intio_write(f,0x8fffffff); + intio_write(f,-0x8fffffff); + fclose(f); + f = fopen("test","rb"); + if (intio_read(f)!=334 + || intio_read(f)!=-40000 + || intio_read(f)!=0x8fffffff + || intio_read(f)!=-0x8fffffff) + { fprintf(stderr,"got back bad data\n"); + exit(1); + } + if (intio_read(f)!=0 || !feof(f) || ferror(f)) + { fprintf(stderr,"eof not handled correctly\n"); + exit(1); + } + fclose(f); + fprintf(stderr,"OK\n"); + exit(0); +} + +#endif diff --git a/lib/ldpc/intio.h b/lib/ldpc/intio.h new file mode 100755 index 00000000..03979d0c --- /dev/null +++ b/lib/ldpc/intio.h @@ -0,0 +1,17 @@ +/* INTIO.H - Interface for reading and writing integers one byte at a time. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +int intio_read (FILE *); /* Read an integer */ +void intio_write (FILE *, int); /* Write an integer */ diff --git a/lib/ldpc/jtmode_codes/jtmskcode.results b/lib/ldpc/jtmode_codes/jtmskcode.results new file mode 100644 index 00000000..e925b4a5 --- /dev/null +++ b/lib/ldpc/jtmode_codes/jtmskcode.results @@ -0,0 +1,12 @@ +rate 1/2 constraint len 13, bpsk, ngood, nbad 10^6 trials + 0.00 43968 30 + 0.50 111824 33 + 1.00 238157 21 + 1.50 425263 20 + 2.00 634824 14 + 2.50 812206 2 + 3.00 924507 2 + 3.50 975836 0 + 4.00 993832 0 + 4.50 998695 0 + 5.00 999771 0 diff --git a/lib/ldpc/jtmode_codes/peg-128-80-denev20.gen b/lib/ldpc/jtmode_codes/peg-128-80-denev20.gen new file mode 100644 index 00000000..ae887a46 Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-128-80-denev20.gen differ diff --git a/lib/ldpc/jtmode_codes/peg-128-80-denev20.pchk b/lib/ldpc/jtmode_codes/peg-128-80-denev20.pchk new file mode 100644 index 00000000..dac8ee61 Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-128-80-denev20.pchk differ diff --git a/lib/ldpc/jtmode_codes/peg-128-80-denev7.gen b/lib/ldpc/jtmode_codes/peg-128-80-denev7.gen new file mode 100644 index 00000000..9c73857d Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-128-80-denev7.gen differ diff --git a/lib/ldpc/jtmode_codes/peg-128-80-denev7.pchk b/lib/ldpc/jtmode_codes/peg-128-80-denev7.pchk new file mode 100644 index 00000000..0985c5a8 Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-128-80-denev7.pchk differ diff --git a/lib/ldpc/jtmode_codes/peg-128-80-reg3.gen b/lib/ldpc/jtmode_codes/peg-128-80-reg3.gen new file mode 100644 index 00000000..30414fdb Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-128-80-reg3.gen differ diff --git a/lib/ldpc/jtmode_codes/peg-128-80-reg3.pchk b/lib/ldpc/jtmode_codes/peg-128-80-reg3.pchk new file mode 100644 index 00000000..e257b2cf Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-128-80-reg3.pchk differ diff --git a/lib/ldpc/jtmode_codes/peg-128-80-reg4.gen b/lib/ldpc/jtmode_codes/peg-128-80-reg4.gen new file mode 100644 index 00000000..092a667e Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-128-80-reg4.gen differ diff --git a/lib/ldpc/jtmode_codes/peg-128-80-reg4.pchk b/lib/ldpc/jtmode_codes/peg-128-80-reg4.pchk new file mode 100644 index 00000000..9d8649c8 Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-128-80-reg4.pchk differ diff --git a/lib/ldpc/jtmode_codes/peg-198-72-irreg-8x3-2x4.gen b/lib/ldpc/jtmode_codes/peg-198-72-irreg-8x3-2x4.gen new file mode 100644 index 00000000..977aa911 Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-198-72-irreg-8x3-2x4.gen differ diff --git a/lib/ldpc/jtmode_codes/peg-198-72-irreg-8x3-2x4.pchk b/lib/ldpc/jtmode_codes/peg-198-72-irreg-8x3-2x4.pchk new file mode 100644 index 00000000..5fa60e7a Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-198-72-irreg-8x3-2x4.pchk differ diff --git a/lib/ldpc/jtmode_codes/peg-198-72-reg3.gen b/lib/ldpc/jtmode_codes/peg-198-72-reg3.gen new file mode 100644 index 00000000..15241c91 Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-198-72-reg3.gen differ diff --git a/lib/ldpc/jtmode_codes/peg-198-72-reg3.pchk b/lib/ldpc/jtmode_codes/peg-198-72-reg3.pchk new file mode 100644 index 00000000..dd8e4561 Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-198-72-reg3.pchk differ diff --git a/lib/ldpc/jtmode_codes/peg-198-72-reg4.gen b/lib/ldpc/jtmode_codes/peg-198-72-reg4.gen new file mode 100644 index 00000000..66c4bae9 Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-198-72-reg4.gen differ diff --git a/lib/ldpc/jtmode_codes/peg-198-72-reg4.pchk b/lib/ldpc/jtmode_codes/peg-198-72-reg4.pchk new file mode 100644 index 00000000..4de31430 Binary files /dev/null and b/lib/ldpc/jtmode_codes/peg-198-72-reg4.pchk differ diff --git a/lib/ldpc/make-gen.c b/lib/ldpc/make-gen.c new file mode 100755 index 00000000..4c948047 --- /dev/null +++ b/lib/ldpc/make-gen.c @@ -0,0 +1,350 @@ +/* MAKE-GEN.C - Make generator matrix from parity-check matrix. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include + +#include "alloc.h" +#include "intio.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" + +typedef enum { Sparse, Dense, Mixed } make_method; /* Ways of making it */ + +void make_dense_mixed (FILE *, make_method, char *); /* Procs to make it */ +void make_sparse (FILE *, mod2sparse_strategy, int, int); +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + char *pchk_file, *gen_file, *other_gen_file; + mod2sparse_strategy strategy; + int abandon_when, abandon_number; + make_method method; + char *meth; + char junk; + FILE *f; + + /* Look at arguments. */ + + if (!(pchk_file = argv[1]) + || !(gen_file = argv[2]) + || !(meth = argv[3])) + { usage(); + } + + if (strcmp(meth,"sparse")==0) + { method = Sparse; + strategy = Mod2sparse_minprod; + abandon_number = 0; + if (argv[4]) + { if (strcmp(argv[4],"first")==0) strategy = Mod2sparse_first; + else if (strcmp(argv[4],"mincol")==0) strategy = Mod2sparse_mincol; + else if (strcmp(argv[4],"minprod")==0) strategy = Mod2sparse_minprod; + else + { usage(); + } + if (argv[5]) + { if (sscanf(argv[5],"%d%c",&abandon_number,&junk)!=1 || abandon_number<=0 + || !argv[6] + || sscanf(argv[6],"%d%c",&abandon_when,&junk)!=1 || abandon_when<=0 + || argv[7]) + { usage(); + } + } + } + } + else if (strcmp(meth,"dense")==0) + { method = Dense; + other_gen_file = argv[4]; + if (other_gen_file && argv[5]) + { usage(); + } + } + else if (strcmp(meth,"mixed")==0) + { method = Mixed; + other_gen_file = argv[4]; + if (other_gen_file && argv[5]) + { usage(); + } + } + else + { usage(); + } + + /* Read parity check matrix. */ + + read_pchk(pchk_file); + + if (N<=M) + { fprintf(stderr, + "Can't encode if number of bits (%d) isn't greater than number of checks (%d)\n",N,M); + exit(1); + } + + /* Create generator matrix file. */ + + f = open_file_std(gen_file,"wb"); + if (f==NULL) + { fprintf(stderr,"Can't create generator matrix file: %s\n",gen_file); + exit(1); + } + + /* Allocate space for row and column permutations. */ + + cols = chk_alloc (N, sizeof *cols); + rows = chk_alloc (M, sizeof *rows); + + /* Create generator matrix with specified method. */ + + switch (method) + { case Sparse: + { make_sparse(f,strategy,abandon_number,abandon_when); + break; + } + case Dense: case Mixed: + { make_dense_mixed(f,method,other_gen_file); + break; + } + default: abort(); + } + + /* Check for error writing file. */ + + if (ferror(f) || fclose(f)!=0) + { fprintf(stderr,"Error writing to generator matrix file\n"); + exit(1); + } + + return 0; +} + + +/* MAKE DENSE OR MIXED REPRESENTATION OF GENERATOR MATRIX. */ + +void make_dense_mixed +( FILE *f, + make_method method, + char *other_gen_file +) +{ + mod2dense *DH, *A, *A2, *AI, *B; + int i, j, c, c2, n; + int *rows_inv; + + DH = mod2dense_allocate(M,N); + AI = mod2dense_allocate(M,M); + B = mod2dense_allocate(M,N-M); + G = mod2dense_allocate(M,N-M); + + mod2sparse_to_dense(H,DH); + + /* If another generator matrix was specified, invert using the set of + columns it specifies. */ + + if (other_gen_file) + { + read_gen(other_gen_file,1,0); + + A = mod2dense_allocate(M,M); + mod2dense_copycols(DH,A,cols); + + if (!mod2dense_invert(A,AI)) + { fprintf(stderr, + "Couldn't invert sub-matrix with column order given in other file\n"); + exit(1); + } + + mod2dense_copycols(DH,B,cols+M); + } + + /* If no other generator matrix was specified, invert using whatever + selection of rows/columns is needed to get a non-singular sub-matrix. */ + + if (!other_gen_file) + { + A = mod2dense_allocate(M,N); + A2 = mod2dense_allocate(M,N); + + n = mod2dense_invert_selected(DH,A2,rows,cols); + mod2sparse_to_dense(H,DH); /* DH was destroyed by invert_selected */ + + if (n>0) + { fprintf(stderr,"Note: Parity check matrix has %d redundant checks\n",n); + } + + rows_inv = chk_alloc (M, sizeof *rows_inv); + + for (i = 0; i0) + { fprintf(stderr, + "Note: Have %d dependent columns, but this could be due to abandonment.\n",n); + fprintf(stderr, + " Try again with lower abandonment number.\n"); + exit(1); + } + + /* Compute and print number of 1s. */ + + cL = cU = cB = 0; + + for (i = 0; i +#include +#include +#include + +#include "rand.h" +#include "alloc.h" +#include "intio.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" +#include "distrib.h" + + +/* METHODS FOR CONSTRUCTING CODES. */ + +typedef enum +{ Evencol, /* Uniform number of bits per column, with number specified */ + Evenboth /* Uniform (as possible) over both columns and rows */ +} make_method; + + +void make_ldpc (int, make_method, distrib *, int); +int *column_partition (distrib *, int); +void usage (void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + make_method method; + char *file, **meth; + int seed, no4cycle; + distrib *d; + char junk; + FILE *f; + + /* Look at initial arguments. */ + + if (!(file = argv[1]) + || !argv[2] || sscanf(argv[2],"%d%c",&M,&junk)!=1 || M<=0 + || !argv[3] || sscanf(argv[3],"%d%c",&N,&junk)!=1 || N<=0 + || !argv[4] || sscanf(argv[4],"%d%c",&seed,&junk)!=1) + { usage(); + } + + /* Look at the arguments specifying the method for producing the code. */ + + meth = argv+5; + + if (!meth[0]) usage(); + + no4cycle = 0; + + if (strcmp(meth[0],"evencol")==0 || strcmp(meth[0],"evenboth")==0) + { method = strcmp(meth[0],"evencol")==0 ? Evencol : Evenboth; + if (!meth[1]) + { usage(); + } + d = distrib_create(meth[1]); + if (d==0) + { usage(); + } + if (meth[2]) + { if (strcmp(meth[2],"no4cycle")==0) + { no4cycle = 1; + if (meth[3]) + { usage(); + } + } + else + { usage(); + } + } + } + else + { usage(); + } + + /* Check for some problems. */ + + if (distrib_max(d)>M) + { fprintf(stderr, + "At least one checks per bit (%d) is greater than total checks (%d)\n", + distrib_max(d), M); + exit(1); + } + + if (distrib_max(d)==M && N>1 && no4cycle) + { fprintf(stderr, + "Can't eliminate cycles of length four with this many checks per bit\n"); + exit(1); + } + + /* Make the parity check matrix. */ + + make_ldpc(seed,method,d,no4cycle); + + /* Write out the parity check matrix. */ + + f = open_file_std(file,"wb"); + if (f==NULL) + { fprintf(stderr,"Can't create parity check file: %s\n",file); + exit(1); + } + + intio_write(f,('P'<<8)+0x80); + + if (ferror(f) || !mod2sparse_write(f,H) || fclose(f)!=0) + { fprintf(stderr,"Error writing to parity check file %s\n",file); + exit(1); + } + + return 0; +} + + +/* PRINT USAGE MESSAGE AND EXIT. */ + +void usage(void) +{ fprintf(stderr,"Usage: make-ldpc pchk-file n-checks n-bits seed method\n"); + fprintf(stderr,"Method: evencol checks-per-col [ \"no4cycle\" ]\n"); + fprintf(stderr," or: evencol checks-distribution [ \"no4cycle\" ]\n"); + fprintf(stderr," or: evenboth checks-per-col [ \"no4cycle\" ]\n"); + fprintf(stderr," or: evenboth checks-distribution [ \"no4cycle\" ]\n"); + exit(1); +} + + +/* CREATE A SPARSE PARITY-CHECK MATRIX. Of size M by N, stored in H. */ + +void make_ldpc +( int seed, /* Random number seed */ + make_method method, /* How to make it */ + distrib *d, /* Distribution list specified */ + int no4cycle /* Eliminate cycles of length four? */ +) +{ + mod2entry *e, *f, *g, *h; + int added, uneven, elim4, all_even, n_full, left; + int i, j, k, t, z, cb_N; + int *part, *u; + + rand_seed(10*seed+1); + + H = mod2sparse_allocate(M,N); + part = column_partition(d,N); + + /* Create the initial version of the parity check matrix. */ + + switch (method) + { + case Evencol: + { + z = 0; + left = part[z]; + + for (j = 0; jdistrib_size(d)) + { abort(); + } + left = part[z]; + } + for (k = 0; k=0; k--) + { u[k] = k%M; + } + + uneven = 0; + t = 0; + z = 0; + left = part[z]; + + for (j = 0; jdistrib_size(d)) + { abort(); + } + left = part[z]; + } + + for (k = 0; k0) + { fprintf(stderr,"Had to place %d checks in rows unevenly\n",uneven); + } + + break; + } + + default: abort(); + } + + /* Add extra bits to avoid rows with less than two checks. */ + + added = 0; + + for (i = 0; i1) + { do + { j = rand_int(N); + } while (j==mod2sparse_col(e)); + mod2sparse_insert(H,i,j); + added += 1; + } + } + + if (added>0) + { fprintf(stderr, + "Added %d extra bit-checks to make row counts at least two\n", + added); + } + + /* Add extra bits to try to avoid problems with even column counts. */ + + n_full = 0; + all_even = 1; + for (z = 0; z1 && added<2) + { int a; + for (a = 0; added+a<2; a++) + { do + { i = rand_int(M); + j = rand_int(N); + } while (mod2sparse_find(H,i,j)); + mod2sparse_insert(H,i,j); + } + fprintf(stderr, + "Added %d extra bit-checks to try to avoid problems from even column counts\n", + a); + } + + /* Eliminate cycles of length four, if asked, and if possible. */ + + if (no4cycle) + { + elim4 = 0; + + for (t = 0; t<10; t++) + { k = 0; + for (j = 0; j0) + { fprintf(stderr, + "Eliminated %d cycles of length four by moving checks within column\n", + elim4); + } + + if (t==10) + { fprintf(stderr, + "Couldn't eliminate all cycles of length four in 10 passes\n"); + } + } +} + + +/* PARTITION THE COLUMNS ACCORDING TO THE SPECIFIED PROPORTIONS. It + may not be possible to do this exactly. Returns a pointer to an + array of integers containing the numbers of columns corresponding + to the entries in the distribution passed. */ + +int *column_partition +( distrib *d, /* List of proportions and number of check-bits */ + int n /* Total number of columns to partition */ +) +{ + double *trunc; + int *part; + int cur, used; + int i, j; + + trunc = chk_alloc (distrib_size(d), sizeof(double)); + part = chk_alloc (distrib_size(d), sizeof(int)); + + used = 0; + for (i = 0; in) + { abort(); + } + + while (usedtrunc[cur]) + { cur = j; + } + } + part[cur] += 1; + used += 1; + trunc[cur] = -1; + } + + free(trunc); + return part; +} diff --git a/lib/ldpc/make-pchk.c b/lib/ldpc/make-pchk.c new file mode 100755 index 00000000..7459ca9b --- /dev/null +++ b/lib/ldpc/make-pchk.c @@ -0,0 +1,93 @@ +/* MAKE-PCHK.C - Make a parity check matrix explicitly. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include +#include + +#include "alloc.h" +#include "intio.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" + + +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + char **bit_specs; + char *file; + FILE *f; + int i, j, k; + char junk; + + if (!(file = argv[1]) + || !argv[2] || sscanf(argv[2],"%d%c",&M,&junk)!=1 || M<=0 + || !argv[3] || sscanf(argv[3],"%d%c",&N,&junk)!=1 || N<=0) + { usage(); + } + + bit_specs = argv+4; + + if (bit_specs[0]==0) + { usage(); + } + + H = mod2sparse_allocate(M,N); + + for (k = 0; bit_specs[k]!=0; k++) + { if (sscanf(bit_specs[k],"%d:%d%c",&i,&j,&junk)!=2 || i<0 || j<0) + { usage(); + } + if (i>=M || j>=N) + { fprintf(stderr,"Bit %d:%d is out of range\n",i,j); + exit(1); + } + mod2sparse_insert(H,i,j); + } + + f = open_file_std(file,"wb"); + if (f==NULL) + { fprintf(stderr,"Can't create parity check file: %s\n",file); + exit(1); + } + + intio_write(f,('P'<<8)+0x80); + + if (ferror(f) || !mod2sparse_write(f,H) || fclose(f)!=0) + { fprintf(stderr,"Error writing to parity check file %s\n",file); + exit(1); + } + + return 0; +} + + +/* PRINT USAGE MESSAGE AND EXIT. */ + +void usage(void) +{ fprintf(stderr,"Usage: make-pchk pchk-file n-checks n-bits row:col ...\n"); + exit(1); +} diff --git a/lib/ldpc/mod2convert-test-out b/lib/ldpc/mod2convert-test-out new file mode 100755 index 00000000..430eec0b --- /dev/null +++ b/lib/ldpc/mod2convert-test-out @@ -0,0 +1,9 @@ + +Creating sparse matrix. +Converting from sparse to dense. +Converting back to dense again. +Testing for equality of two sparse matrices: OK. +Converting to dense once again. +Testing for equality of two dense matrices: OK. + +DONE WITH TESTS. diff --git a/lib/ldpc/mod2convert-test.c b/lib/ldpc/mod2convert-test.c new file mode 100755 index 00000000..eac257ff --- /dev/null +++ b/lib/ldpc/mod2convert-test.c @@ -0,0 +1,80 @@ +/* MOD2CONVERT-TEST. C - Program to test mod2convert module. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + + +/* Correct output for this program is saved in the file mod2convert-test-out */ + + +#include +#include +#include + +#include "mod2dense.h" +#include "mod2sparse.h" +#include "mod2convert.h" +#include "rand.h" + +#define Rows 40 /* Dimensions of matrix to use in test */ +#define Cols 13 + +#define N 100 /* Number of bits to set in test matrix (some may be + duplicates, leading to fewer 1's in matrix */ + +main(void) +{ + mod2sparse *sm1, *sm2; + mod2dense *dm1, *dm2; + int i; + + sm1 = mod2sparse_allocate(Rows,Cols); + sm2 = mod2sparse_allocate(Rows,Cols); + + dm1 = mod2dense_allocate(Rows,Cols); + dm2 = mod2dense_allocate(Rows,Cols); + + printf("\nCreating sparse matrix.\n"); + fflush(stdout); + + for (i = 0; i +#include +#include + +#include "mod2dense.h" +#include "mod2sparse.h" +#include "mod2convert.h" + + +/* CONVERT A MOD2 MATRIX FROM SPARSE TO DENSE FORM. */ + +void mod2sparse_to_dense +( mod2sparse *m, /* Sparse matrix to convert */ + mod2dense *r /* Place to store result */ +) +{ + mod2entry *e; + int i; + + if (mod2sparse_rows(m)>mod2dense_rows(r) + || mod2sparse_cols(m)>mod2dense_cols(r)) + { fprintf(stderr, + "mod2sparse_to_dense: Dimension of result matrix is less than source\n"); + exit(1); + } + + mod2dense_clear(r); + + for (i = 0; imod2sparse_rows(r) + || mod2dense_cols(m)>mod2sparse_cols(r)) + { fprintf(stderr, + "mod2dense_to_sparse: Dimension of result matrix is less than source\n"); + exit(1); + } + + mod2sparse_clear(r); + + for (i = 0; i + + Modulo-2 Matrix Sparse/Dense Conversion + + + + +

Modulo-2 Matrix Sparse/Dense Conversion

+ +

The routines below convert modulo-2 matrices between the form used by +the routines for dense modulo-2 matrices +and the form used by the routines for sparse +modulo-2 matrices. + +

Header files required: +mod2sparse.h mod2dense.h mod2convert.h + + +


mod2sparse_to_dense: +Convert a modulo-2 matrix from sparse to dense form. + +
+void mod2sparse_to_dense 
+( mod2sparse *m,  /* Sparse matrix to convert */
+  mod2dense *r    /* Place to store result */
+)
+
+ +The dense matrix, r, must already have been allocated, and must have at +least as many rows and columns as m, the sparse matrix to be converted. + + +


mod2dense_to_sparse: +Convert a modulo-2 matrix from dense to sparse form. + +
+void mod2dense_to_sparse 
+( mod2dense *m,  /* Dense matrix to convert */
+  mod2sparse *r  /* Place to store result */
+)
+
+ +The sparse matrix, r, must already have been allocated, and must have at +least as many rows and columns as m, the dense matrix to be converted. + + +
+ +Back to index for LDPC software + + diff --git a/lib/ldpc/mod2dense-test-out b/lib/ldpc/mod2dense-test-out new file mode 100755 index 00000000..e38525b6 --- /dev/null +++ b/lib/ldpc/mod2dense-test-out @@ -0,0 +1,699 @@ + +PART 1: + +Matrix m1: + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + +Matrix m2, as read from file. Should be same as m1 above. + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + +Test of equality of m1 & m2 (should be 1): 1 + +Matrix m3, copied from m1 above. + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + +Test of equality of m1 & m3 (should be 1): 1 + +Matrix m3 again, should now be all zeros. + + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + +Test of equality of m1 & m3 (should be 0): 0 + + +PART 2: + +Transpose of m1. + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + + +PART 3: + +Matrix s0. + + 0 0 0 0 0 0 0 + 0 0 0 1 1 0 0 + 1 0 0 0 0 0 0 + 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 + +Matrix s1. + + 0 0 0 0 0 0 0 + 0 0 0 1 0 1 0 + 0 0 0 0 0 0 0 + 1 1 0 0 0 0 1 + 0 0 0 0 0 0 0 + +Matrix s2. + + 1 0 0 0 + 0 1 0 0 + 0 0 0 0 + 0 0 0 0 + 0 0 0 0 + 0 1 1 1 + 0 0 0 0 + +Sum of s0 and s1. + + 0 0 0 0 0 0 0 + 0 0 0 0 1 1 0 + 1 0 0 0 0 0 0 + 1 0 0 0 0 0 1 + 0 0 0 0 0 0 0 + +Product of s1 and s2. + + 0 0 0 0 + 0 1 1 1 + 0 0 0 0 + 1 1 0 0 + 0 0 0 0 + +Above matrix with (1,2) cleared. + + 0 0 0 0 + 0 1 0 1 + 0 0 0 0 + 1 1 0 0 + 0 0 0 0 + + +PART 4: + +Matrix s1. + + 0 0 0 1 0 + 0 1 0 0 1 + 1 0 0 0 0 + 0 1 1 0 0 + 1 0 1 0 0 + +Matrix s3, the inverse of s1 (return code 1). + + 0 0 1 0 0 + 0 0 1 1 1 + 0 0 1 0 1 + 1 0 0 0 0 + 0 1 1 1 1 + +Original matrix times inverse (should be identity). + + 1 0 0 0 0 + 0 1 0 0 0 + 0 0 1 0 0 + 0 0 0 1 0 + 0 0 0 0 1 + +Inverse times original matrix (should be identity). + + 1 0 0 0 0 + 0 1 0 0 0 + 0 0 1 0 0 + 0 0 0 1 0 + 0 0 0 0 1 + +Inverse of inverse (should be same as original s1). + 0 0 0 1 0 + 0 1 0 0 1 + 1 0 0 0 0 + 0 1 1 0 0 + 1 0 1 0 0 + +Test of equality with original (should be 1): 1 + +Matrix s1. + + 0 0 0 0 1 0 0 + 0 1 0 0 0 0 1 + 1 0 0 0 0 0 0 + 0 1 1 0 0 0 0 + 1 0 1 0 0 0 0 + +Matrix s3, from invert_selected applied to s1 (return code 0). + + 0 0 0 0 1 0 0 + 1 0 1 0 0 0 1 + 1 0 0 0 0 0 0 + 1 0 0 0 0 0 1 + 1 1 1 0 0 0 1 + + row ordering returned: 0 1 2 3 4 + + column ordering returned: 4 1 0 2 6 5 3 + +Columns extracted in order from original matrix. + + 1 0 0 0 0 + 0 1 0 0 1 + 0 0 1 0 0 + 0 1 0 1 0 + 0 0 1 1 0 + +Inverse of above calculated using mod2dense_inverse (return code 1) + + 1 0 0 0 0 + 0 0 1 1 1 + 0 0 1 0 0 + 0 0 1 0 1 + 0 1 1 1 1 + +Columns extracted in order from s3 (should also be inverse of above). + + 1 0 0 0 0 + 0 0 1 1 1 + 0 0 1 0 0 + 0 0 1 0 1 + 0 1 1 1 1 + +Matrix s1. + + 1 1 0 0 0 0 0 + 0 1 1 0 0 0 0 + 1 0 1 0 0 0 0 + 0 0 0 1 1 0 0 + 0 0 0 0 0 0 0 + +Matrix s3, from invert_selected applied to s1 (return code 2). + + 1 1 0 0 0 0 0 + 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 + + row ordering returned: 0 1 3 4 2 + + column ordering returned: 0 1 3 2 4 5 6 + +Matrix s4, from copying rows in order from s3. + + 1 1 0 0 0 0 0 + 0 1 0 0 0 0 0 + 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 + +PART 5: + +Matrix s1. + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 + +Matrix s3, the inverse of s1 (return code 1). + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1 + 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 + 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 1 0 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 + 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 0 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1 + 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 0 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + +Original matrix times inverse (should be identity). + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + +Inverse times original matrix (should be identity). + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + +Inverse of inverse (should be same as original s1). + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 + +Test of equality with original (should be 1): 1 + + +PART 6: + +Matrix s1. + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + +Result of forcibly inverting s1 (needed to alter 7 elements). + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + +Altered elements at these indexes: + + 3 3 + 7 7 + 15 15 + 21 21 + 23 23 + 29 29 + 32 12 + +Inverse of inverse of altered matrix. + + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + + +DONE WITH TESTS. diff --git a/lib/ldpc/mod2dense-test.c b/lib/ldpc/mod2dense-test.c new file mode 100755 index 00000000..f38ad54f --- /dev/null +++ b/lib/ldpc/mod2dense-test.c @@ -0,0 +1,560 @@ +/* MOD2DENSE-TEST. C - Program to test mod2dense module. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + + +/* Correct output for this program is saved in the file mod2dense-test-out */ + + +#include +#include +#include + +#include "mod2dense.h" + + +main(void) +{ + mod2dense *m1, *m2, *m3, *m4; + mod2dense *s0, *s1, *s2, *s3, *s4, *s5; + int a_row[35], a_col[35]; + int code; + int i, j; + FILE *f; + + + printf("\nPART 1:\n\n"); + + /* Set up m1 with bits on a diagonal plus a few more set to 1. */ + + m1 = mod2dense_allocate(35,40); + + mod2dense_clear(m1); + + for (i = 0; i<35; i++) mod2dense_set(m1,i,i,1); + + mod2dense_set(m1,2,3,1); + mod2dense_set(m1,34,4,1); + mod2dense_set(m1,10,38,1); + + /* Print m1. */ + + printf("Matrix m1:\n\n"); + mod2dense_print(stdout,m1); + printf("\n"); fflush(stdout); + + /* Store m1 in a file. */ + + f = fopen("test-file","wb"); + if (f==0) + { fprintf(stderr,"Can't create test-file\n"); + exit(1); + } + + if (!mod2dense_write(f,m1)) + { printf("Error from mod2dense_write\n"); + } + + fclose(f); + + /* Read matrix written above back into m2. */ + + f = fopen("test-file","rb"); + if (f==0) + { fprintf(stderr,"Can't open test-file\n"); + exit(1); + } + + m2 = mod2dense_read(f); + + if (m2==0) + { printf("Error from mod2dense_read\n"); + exit(1); + } + + /* Print m2, along with result of equality test. */ + + printf("Matrix m2, as read from file. Should be same as m1 above.\n\n"); + mod2dense_print(stdout,m2); + printf("\n"); fflush(stdout); + + printf("Test of equality of m1 & m2 (should be 1): %d\n\n", + mod2dense_equal(m1,m2)); + + /* Copy m1 to m3. */ + + m3 = mod2dense_allocate(mod2dense_rows(m1),mod2dense_cols(m1)); + + mod2dense_copy(m1,m3); + + /* Print m3, along with result of equality test. */ + + printf("Matrix m3, copied from m1 above.\n\n"); + mod2dense_print(stdout,m3); + printf("\n"); fflush(stdout); + + printf("Test of equality of m1 & m3 (should be 1): %d\n\n", + mod2dense_equal(m1,m3)); + + /* Clear m3. */ + + mod2dense_clear(m3); + + /* Print m3 again. */ + + printf("Matrix m3 again, should now be all zeros.\n\n"); + mod2dense_print(stdout,m3); + printf("\n"); fflush(stdout); + + printf("Test of equality of m1 & m3 (should be 0): %d\n\n", + mod2dense_equal(m1,m3)); + + + printf("\nPART 2:\n\n"); + + /* Compute transpose of m1. */ + + m4 = mod2dense_allocate(mod2dense_cols(m1),mod2dense_rows(m1)); + + mod2dense_transpose(m1,m4); + + /* Print transpose. */ + + printf("Transpose of m1.\n\n"); + mod2dense_print(stdout,m4); + printf("\n"); fflush(stdout); + + /* Free space for m1, m2, and m3. */ + + mod2dense_free(m1); + mod2dense_free(m2); + mod2dense_free(m3); + + + printf("\nPART 3:\n\n"); + + /* Allocate some small matrices. */ + + s0 = mod2dense_allocate(5,7); + s1 = mod2dense_allocate(5,7); + s2 = mod2dense_allocate(7,4); + s3 = mod2dense_allocate(5,4); + s4 = mod2dense_allocate(5,7); + + /* Set up the contents of s0, s1, and s2. */ + + mod2dense_clear(s0); + mod2dense_clear(s1); + mod2dense_clear(s2); + + mod2dense_set(s0,1,3,1); + mod2dense_set(s0,1,4,1); + mod2dense_set(s0,2,0,1); + mod2dense_set(s0,3,1,1); + + mod2dense_set(s1,1,3,1); + mod2dense_set(s1,1,5,1); + mod2dense_set(s1,3,0,1); + mod2dense_set(s1,3,1,1); + mod2dense_set(s1,3,6,1); + + mod2dense_set(s2,5,1,1); + mod2dense_set(s2,5,2,1); + mod2dense_set(s2,5,3,1); + mod2dense_set(s2,0,0,1); + mod2dense_set(s2,1,1,1); + + /* Print s0, s1, and s2. */ + + printf("Matrix s0.\n\n"); + mod2dense_print(stdout,s0); + printf("\nMatrix s1.\n\n"); + mod2dense_print(stdout,s1); + printf("\nMatrix s2.\n\n"); + mod2dense_print(stdout,s2); + printf("\n"); fflush(stdout); + + /* Add s0 and s1, storing the result in s4, then print s4. */ + + mod2dense_add(s0,s1,s4); + + printf("Sum of s0 and s1.\n\n"); + mod2dense_print(stdout,s4); + printf("\n"); fflush(stdout); + + /* Multiply s1 and s2, storing the product in s3, and then print s3. */ + + mod2dense_multiply(s1,s2,s3); + + printf("Product of s1 and s2.\n\n"); + mod2dense_print(stdout,s3); + printf("\n"); fflush(stdout); + + /* Try clearing a bit in s3, then printing the result. */ + + mod2dense_set(s3,1,2,0); + + printf("Above matrix with (1,2) cleared.\n\n"); + mod2dense_print(stdout,s3); + printf("\n"); fflush(stdout); + + /* Free space for s0, s1, s2, s3, and s4. */ + + mod2dense_free(s0); + mod2dense_free(s1); + mod2dense_free(s2); + mod2dense_free(s3); + mod2dense_free(s4); + + + printf("\nPART 4:\n\n"); + + /* Set up a small square matrix, s1. Also copy it to s2. */ + + s1 = mod2dense_allocate(5,5); + s2 = mod2dense_allocate(5,5); + + mod2dense_clear(s1); + + mod2dense_set(s1,0,3,1); + mod2dense_set(s1,1,4,1); + mod2dense_set(s1,1,1,1); + mod2dense_set(s1,2,0,1); + mod2dense_set(s1,3,1,1); + mod2dense_set(s1,3,2,1); + mod2dense_set(s1,4,2,1); + mod2dense_set(s1,4,0,1); + + mod2dense_copy(s1,s2); + + /* Print s1. */ + + printf("Matrix s1.\n\n"); + mod2dense_print(stdout,s1); + printf("\n"); fflush(stdout); + + /* Compute inverse of s1, storing it in s3. */ + + s3 = mod2dense_allocate(5,5); + + code = mod2dense_invert(s1,s3); + + /* Print inverse (s3). */ + + printf("Matrix s3, the inverse of s1 (return code %d).\n\n",code); + mod2dense_print(stdout,s3); + printf("\n"); fflush(stdout); + + /* Compute and print product of inverse and original matrix, both ways. */ + + mod2dense_multiply(s2,s3,s1); + printf("Original matrix times inverse (should be identity).\n\n"); + mod2dense_print(stdout,s1); + + mod2dense_multiply(s3,s2,s1); + printf("\nInverse times original matrix (should be identity).\n\n"); + mod2dense_print(stdout,s1); + printf("\n"); fflush(stdout); + + /* Compute and print inverse of inverse, and do equality check. */ + + mod2dense_invert(s3,s1); + + printf("Inverse of inverse (should be same as original s1).\n"); + mod2dense_print(stdout,s1); + printf("\n"); fflush(stdout); + + printf("Test of equality with original (should be 1): %d\n\n", + mod2dense_equal(s1,s2)); + + /* Free s1, s2, and s3. */ + + mod2dense_free(s1); + mod2dense_free(s2); + mod2dense_free(s3); + + /* Set up a rectangular matrix like s1 above, but with two zero columns. + Copy to s4 as well. */ + + s1 = mod2dense_allocate(5,7); + + mod2dense_clear(s1); + + mod2dense_set(s1,0,4,1); + mod2dense_set(s1,1,6,1); + mod2dense_set(s1,1,1,1); + mod2dense_set(s1,2,0,1); + mod2dense_set(s1,3,1,1); + mod2dense_set(s1,3,2,1); + mod2dense_set(s1,4,2,1); + mod2dense_set(s1,4,0,1); + + s4 = mod2dense_allocate(5,7); + mod2dense_copy(s1,s4); + + /* Print s1. */ + + printf("Matrix s1.\n\n"); + mod2dense_print(stdout,s1); + printf("\n"); fflush(stdout); + + /* Compute inverse of sub-matrix of s1, storing it in s3. Print results. */ + + s3 = mod2dense_allocate(5,7); + + code = mod2dense_invert_selected(s1,s3,a_row,a_col); + + printf("Matrix s3, from invert_selected applied to s1 (return code %d).\n\n", + code); + + mod2dense_print(stdout,s3); + + printf("\n row ordering returned:"); + for (i = 0; i<5; i++) printf(" %d",a_row[i]); + printf("\n"); + + printf("\n column ordering returned:"); + for (j = 0; j<7; j++) printf(" %d",a_col[j]); + printf("\n"); + + printf("\n"); fflush(stdout); + + printf("Columns extracted in order from original matrix.\n\n"); + + s2 = mod2dense_allocate(5,5); + mod2dense_copycols(s4,s2,a_col); + mod2dense_print(stdout,s2); + printf("\n"); fflush(stdout); + + s5 = mod2dense_allocate(5,5); + code = mod2dense_invert(s2,s5); + + printf( + "Inverse of above calculated using mod2dense_inverse (return code %d)\n\n", + code); + + mod2dense_print(stdout,s5); + printf("\n"); fflush(stdout); + + printf( + "Columns extracted in order from s3 (should also be inverse of above).\n\n"); + mod2dense_copycols(s3,s2,a_col); + mod2dense_print(stdout,s2); + printf("\n"); fflush(stdout); + + /* Try out mod2dense_invert_selected again. */ + + mod2dense_clear(s1); + + mod2dense_set(s1,0,0,1); + mod2dense_set(s1,0,1,1); + mod2dense_set(s1,1,1,1); + mod2dense_set(s1,1,2,1); + mod2dense_set(s1,2,0,1); + mod2dense_set(s1,2,2,1); + mod2dense_set(s1,3,3,1); + mod2dense_set(s1,3,4,1); + + printf("Matrix s1.\n\n"); + mod2dense_print(stdout,s1); + printf("\n"); fflush(stdout); + + code = mod2dense_invert_selected(s1,s3,a_row,a_col); + + printf("Matrix s3, from invert_selected applied to s1 (return code %d).\n\n", + code); + + mod2dense_print(stdout,s3); + + printf("\n row ordering returned:"); + for (i = 0; i<5; i++) printf(" %d",a_row[i]); + printf("\n"); + printf("\n column ordering returned:"); + for (j = 0; j<7; j++) printf(" %d",a_col[j]); + printf("\n"); + + printf("\n"); fflush(stdout); + + printf("Matrix s4, from copying rows in order from s3.\n\n"); + + mod2dense_copyrows(s3,s4,a_row); + + mod2dense_print(stdout,s4); + + free(s1); + free(s2); + free(s3); + free(s4); + free(s5); + + + printf("\nPART 5:\n\n"); + + /* Set up a larger square matrix, s1. Also copy it to s2. */ + + s1 = mod2dense_allocate(35,35); + s2 = mod2dense_allocate(35,35); + + mod2dense_clear(s1); + + for (i = 0; i<35; i++) mod2dense_set(s1,i,i,1); + + mod2dense_set(s1,10,3,1); + mod2dense_set(s1,11,4,1); + mod2dense_set(s1,11,11,1); + mod2dense_set(s1,12,20,1); + mod2dense_set(s1,13,31,1); + mod2dense_set(s1,23,12,1); + mod2dense_set(s1,24,12,1); + mod2dense_set(s1,14,10,1); + mod2dense_set(s1,2,20,1); + mod2dense_set(s1,3,31,1); + mod2dense_set(s1,3,12,1); + mod2dense_set(s1,24,2,1); + mod2dense_set(s1,24,0,1); + mod2dense_set(s1,5,3,1); + mod2dense_set(s1,18,3,1); + mod2dense_set(s1,17,11,1); + mod2dense_set(s1,32,23,1); + mod2dense_set(s1,9,24,1); + mod2dense_set(s1,19,11,1); + mod2dense_set(s1,11,30,1); + mod2dense_set(s1,21,27,1); + mod2dense_set(s1,21,22,1); + mod2dense_set(s1,23,33,1); + mod2dense_set(s1,24,23,1); + mod2dense_set(s1,24,25,1); + mod2dense_set(s1,30,34,1); + mod2dense_set(s1,31,10,1); + mod2dense_set(s1,33,17,1); + mod2dense_set(s1,33,18,1); + mod2dense_set(s1,34,8,1); + mod2dense_set(s1,34,11,1); + mod2dense_set(s1,34,3,1); + mod2dense_set(s1,34,24,1); + mod2dense_set(s1,25,34,1); + mod2dense_set(s1,13,34,1); + + mod2dense_set(s1,3,3,0); + mod2dense_set(s1,11,11,0); + mod2dense_set(s1,23,23,0); + mod2dense_set(s1,24,24,0); + + mod2dense_copy(s1,s2); + + /* Print s1. */ + + printf("Matrix s1.\n\n"); + mod2dense_print(stdout,s1); + printf("\n"); fflush(stdout); + + /* Compute inverse of s1, storing it in s3. */ + + s3 = mod2dense_allocate(35,35); + + code = mod2dense_invert(s1,s3); + + /* Print inverse (s3). */ + + printf("Matrix s3, the inverse of s1 (return code %d).\n\n",code); + mod2dense_print(stdout,s3); + printf("\n"); fflush(stdout); + + /* Compute and print product of inverse and original matrix, both ways. */ + + mod2dense_multiply(s2,s3,s1); + printf("Original matrix times inverse (should be identity).\n\n"); + mod2dense_print(stdout,s1); + + mod2dense_multiply(s3,s2,s1); + printf("\nInverse times original matrix (should be identity).\n\n"); + mod2dense_print(stdout,s1); + printf("\n"); fflush(stdout); + + /* Compute and print inverse of inverse, and do equality check. */ + + mod2dense_invert(s3,s1); + + printf("Inverse of inverse (should be same as original s1).\n\n"); + mod2dense_print(stdout,s1); + printf("\n"); fflush(stdout); + + printf("Test of equality with original (should be 1): %d\n\n", + mod2dense_equal(s1,s2)); + + /* Free s1, s2, and s3. */ + + mod2dense_free(s1); + mod2dense_free(s2); + mod2dense_free(s3); + + + printf("\nPART 6:\n\n"); + + /* Set up a largish square matrix, s1. Also copy it to s2. */ + + s1 = mod2dense_allocate(35,35); + s2 = mod2dense_allocate(35,35); + + mod2dense_clear(s1); + + for (i = 0; i<10; i++) + { if (i!=3 && i!=7) + { mod2dense_set(s1,i,i,1); + } + } + for (i = 10; i<35; i++) + { if (i!=15 && i!=21 && i!=32) + { mod2dense_set(s1,i,34-(i-10),1); + } + } + + /* Print s1. */ + + printf("Matrix s1.\n\n"); + mod2dense_print(stdout,s1); + printf("\n"); fflush(stdout); + + /* Forcibly invert s1, storing inverse in s3. */ + + s3 = mod2dense_allocate(35,35); + + code = mod2dense_forcibly_invert(s1,s3,a_row,a_col); + + /* Print inverse, and list of altered elements. */ + + printf("Result of forcibly inverting s1 (needed to alter %d elements).\n\n", + code); + mod2dense_print(stdout,s3); + printf("\n"); fflush(stdout); + + printf("Altered elements at these indexes:\n\n"); + + for (i = 0; i +#include +#include + +#include "alloc.h" +#include "intio.h" +#include "mod2dense.h" + + +/* ALLOCATE SPACE FOR A DENSE MOD2 MATRIX. */ + +mod2dense *mod2dense_allocate +( int n_rows, /* Number of rows in matrix */ + int n_cols /* Number of columns in matrix */ +) +{ + mod2dense *m; + int j; + + if (n_rows<=0 || n_cols<=0) + { fprintf(stderr,"mod2dense_allocate: Invalid number of rows or columns\n"); + exit(1); + } + + m = chk_alloc (1, sizeof *m); + + m->n_rows = n_rows; + m->n_cols = n_cols; + + m->n_words = (n_rows+mod2_wordsize-1) >> mod2_wordsize_shift; + + m->col = chk_alloc (m->n_cols, sizeof *m->col); + + m->bits = chk_alloc(m->n_words*m->n_cols, sizeof *m->bits); + + for (j = 0; jn_cols; j++) + { m->col[j] = m->bits + j*m->n_words; + } + + return m; +} + + +/* FREE SPACE OCCUPIED BY A DENSE MOD2 MATRIX. */ + +void mod2dense_free +( mod2dense *m /* Matrix to free */ +) +{ if (m) + { free(m->bits); + free(m->col); + free(m); + } +} + + +/* CLEAR A DENSE MOD2 MATRIX. */ + +void mod2dense_clear +( mod2dense *r +) +{ + int k, j; + + for (j = 0; jn_words; k++) + { r->col[j][k] = 0; + } + } + +} + + +/* COPY A DENSE MOD2 MATRIX. */ + +void mod2dense_copy +( mod2dense *m, /* Matrix to copy */ + mod2dense *r /* Place to store copy of matrix */ +) +{ + int k, j; + + if (mod2dense_rows(m)>mod2dense_rows(r) + || mod2dense_cols(m)>mod2dense_cols(r)) + { fprintf(stderr,"mod2dense_copy: Destination matrix is too small\n"); + exit(1); + } + + for (j = 0; jn_words; k++) + { r->col[j][k] = m->col[j][k]; + } + for ( ; kn_words; k++) + { r->col[j][k] = 0; + } + } + + for ( ; jn_words; k++) + { r->col[j][k] = 0; + } + } +} + + +/* COPY ROWS OF A DENSE MOD2 MATRIX. */ + +void mod2dense_copyrows +( mod2dense *m, /* Matrix to copy */ + mod2dense *r, /* Place to store copy of matrix */ + int *rows /* Indexes of rows to copy, from 0 */ +) +{ + int i, j; + + if (mod2dense_cols(m)>mod2dense_cols(r)) + { fprintf(stderr, + "mod2dense_copyrows: Destination matrix has fewer columns than source\n"); + exit(1); + } + + mod2dense_clear(r); + + for (i = 0; i=mod2dense_rows(m)) + { fprintf(stderr,"mod2dense_copyrows: Row index out of range\n"); + exit(1); + } + for (j = 0; jmod2dense_rows(r)) + { fprintf(stderr, + "mod2dense_copycols: Destination matrix has fewer rows than source\n"); + exit(1); + } + + for (j = 0; j=mod2dense_cols(m)) + { fprintf(stderr,"mod2dense_copycols: Column index out of range\n"); + exit(1); + } + for (k = 0; kn_words; k++) + { r->col[j][k] = m->col[cols[j]][k]; + } + for ( ; kn_words; k++) + { r->col[j][k] = 0; + } + } +} + + +/* PRINT A DENSE MOD2 MATRIX IN HUMAN-READABLE FORM. */ + +void mod2dense_print +( FILE *f, + mod2dense *m +) +{ + int i, j; + + for (i = 0; in_rows); + if (ferror(f)) return 0; + + intio_write(f,m->n_cols); + if (ferror(f)) return 0; + + for (j = 0; jn_words; k++) + { intio_write(f,m->col[j][k]); + if (ferror(f)) return 0; + } + } + + return 1; +} + + +/* READ A DENSE MOD2 MATRIX STORED IN MACHINE-READABLE FORM FROM A FILE. */ + +mod2dense *mod2dense_read +( FILE *f +) +{ + int n_rows, n_cols; + mod2dense *m; + int j, k; + + n_rows = intio_read(f); + if (feof(f) || ferror(f) || n_rows<=0) return 0; + + n_cols = intio_read(f); + if (feof(f) || ferror(f) || n_cols<=0) return 0; + + m = mod2dense_allocate(n_rows,n_cols); + + for (j = 0; jn_words; k++) + { m->col[j][k] = intio_read(f); + if (feof(f) || ferror(f)) + { mod2dense_free(m); + return 0; + } + } + } + + return m; +} + + +/* GET AN ELEMENT FROM A DENSE MOD2 MATRIX. */ + +int mod2dense_get +( mod2dense *m, /* Matrix to get element from */ + int row, /* Row of element (starting with zero) */ + int col /* Column of element (starting with zero) */ +) +{ + if (row<0 || row>=mod2dense_rows(m) || col<0 || col>=mod2dense_cols(m)) + { fprintf(stderr,"mod2dense_get: row or column index out of bounds\n"); + exit(1); + } + + return mod2_getbit (m->col[col][row>>mod2_wordsize_shift], + row&mod2_wordsize_mask); +} + + +/* SET AN ELEMENT IN A DENSE MOD2 MATRIX. */ + +void mod2dense_set +( mod2dense *m, /* Matrix to modify element of */ + int row, /* Row of element (starting with zero) */ + int col, /* Column of element (starting with zero) */ + int value /* New value of element (0 or 1) */ +) +{ + mod2word *w; + + if (row<0 || row>=mod2dense_rows(m) || col<0 || col>=mod2dense_cols(m)) + { fprintf(stderr,"mod2dense_set: row or column index out of bounds\n"); + exit(1); + } + + w = &m->col[col][row>>mod2_wordsize_shift]; + + *w = value ? mod2_setbit1(*w,row&mod2_wordsize_mask) + : mod2_setbit0(*w,row&mod2_wordsize_mask); +} + + +/* FLIP AN ELEMENT OF A DENSE MOD2 MATRIX. */ + +int mod2dense_flip +( mod2dense *m, /* Matrix to flip element in */ + int row, /* Row of element (starting with zero) */ + int col /* Column of element (starting with zero) */ +) +{ + mod2word *w; + int b; + + if (row<0 || row>=mod2dense_rows(m) || col<0 || col>=mod2dense_cols(m)) + { fprintf(stderr,"mod2dense_flip: row or column index out of bounds\n"); + exit(1); + } + + b = 1 ^ mod2_getbit (m->col[col][row>>mod2_wordsize_shift], + row&mod2_wordsize_mask); + + w = &m->col[col][row>>mod2_wordsize_shift]; + + *w = b ? mod2_setbit1(*w,row&mod2_wordsize_mask) + : mod2_setbit0(*w,row&mod2_wordsize_mask); + + return b; +} + + +/* COMPUTE THE TRANSPOSE OF A DENSE MOD2 MATRIX. */ + +void mod2dense_transpose +( mod2dense *m, /* Matrix to compute transpose of (left unchanged) */ + mod2dense *r /* Result of transpose operation */ +) +{ + mod2word w, v, *p; + int k1, j1, i2, j2; + + if (mod2dense_rows(m)!=mod2dense_cols(r) + || mod2dense_cols(m)!=mod2dense_rows(r)) + { fprintf(stderr, + "mod2dense_transpose: Matrices have incompatible dimensions\n"); + exit(1); + } + + if (r==m) + { fprintf(stderr, + "mod2dense_transpose: Result matrix is the same as the operand\n"); + exit(1); + } + + mod2dense_clear(r); + + for (j1 = 0; j1> mod2_wordsize_shift; + v = 1 << (j1 & mod2_wordsize_mask); + + p = m->col[j1]; + k1 = 0; + + for (j2 = 0; j2col[j2][i2] |= v; + } + w >>= 1; + k1 -= 1; + } + } +} + + +/* ADD TWO DENSE MOD2 MATRICES. */ + +void mod2dense_add +( mod2dense *m1, /* Left operand of add */ + mod2dense *m2, /* Right operand of add */ + mod2dense *r /* Place to store result of add */ +) +{ + int j, k; + + if (mod2dense_rows(m1)!=mod2dense_rows(r) + || mod2dense_cols(m1)!=mod2dense_cols(r) + || mod2dense_rows(m2)!=mod2dense_rows(r) + || mod2dense_cols(m2)!=mod2dense_cols(r)) + { fprintf(stderr,"mod2dense_add: Matrices have different dimensions\n"); + exit(1); + } + + for (j = 0; jn_words; k++) + { r->col[j][k] = m1->col[j][k] ^ m2->col[j][k]; + } + } +} + + +/* MULTIPLY TWO DENSE MOD2 MATRICES. + + The algorithm used runs faster if the second matrix (right operand of the + multiply) is sparse, but it is also appropriate for dense matrices. This + procedure could be speeded up a bit by replacing the call of mod2dense_get + with in-line code that avoids division, but this doesn't seem worthwhile + at the moment. +*/ + +void mod2dense_multiply +( mod2dense *m1, /* Left operand of multiply */ + mod2dense *m2, /* Right operand of multiply */ + mod2dense *r /* Place to store result of multiply */ +) +{ + int i, j, k; + + if (mod2dense_cols(m1)!=mod2dense_rows(m2) + || mod2dense_rows(m1)!=mod2dense_rows(r) + || mod2dense_cols(m2)!=mod2dense_cols(r)) + { fprintf(stderr, + "mod2dense_multiply: Matrices have incompatible dimensions\n"); + exit(1); + } + + if (r==m1 || r==m2) + { fprintf(stderr, + "mod2dense_multiply: Result matrix is the same as one of the operands\n"); + exit(1); + } + + mod2dense_clear(r); + + for (j = 0; jn_words; k++) + { r->col[j][k] ^= m1->col[i][k]; + } + } + } + } +} + + +/* SEE WHETHER TWO DENSE MOD2 MATRICES ARE EQUAL. */ + +int mod2dense_equal +( mod2dense *m1, + mod2dense *m2 +) +{ + int k, j, w; + mod2word m; + + if (mod2dense_rows(m1)!=mod2dense_rows(m2) + || mod2dense_cols(m1)!=mod2dense_cols(m2)) + { fprintf(stderr,"mod2dense_equal: Matrices have different dimensions\n"); + exit(1); + } + + w = m1->n_words; + + /* Form a mask that has 1s in the lower bit positions corresponding to + bits that contain information in the last word of a matrix column. */ + + m = (1 << (mod2_wordsize - (w*mod2_wordsize-m1->n_rows))) - 1; + + for (j = 0; jcol[j][k] != m2->col[j][k]) return 0; + } + + if ((m1->col[j][k]&m) != (m2->col[j][k]&m)) return 0; + } + + return 1; +} + + +/* INVERT A DENSE MOD2 MATRIX. */ + +int mod2dense_invert +( mod2dense *m, /* The matrix to find the inverse of (destroyed) */ + mod2dense *r /* Place to store the inverse */ +) +{ + mod2word *s, *t; + int i, j, k, n, w, k0, b0; + + if (mod2dense_rows(m)!=mod2dense_cols(m)) + { fprintf(stderr,"mod2dense_invert: Matrix to invert is not square\n"); + exit(1); + } + + if (r==m) + { fprintf(stderr, + "mod2dense_invert: Result matrix is the same as the operand\n"); + exit(1); + } + + n = mod2dense_rows(m); + w = m->n_words; + + if (mod2dense_rows(r)!=n || mod2dense_cols(r)!=n) + { fprintf(stderr, + "mod2dense_invert: Matrix to receive inverse has wrong dimensions\n"); + exit(1); + } + + mod2dense_clear(r); + for (i = 0; i> mod2_wordsize_shift; + b0 = i & mod2_wordsize_mask; + + for (j = i; jcol[j][k0],b0)) break; + } + + if (j==n) return 0; + + if (j!=i) + { + t = m->col[i]; + m->col[i] = m->col[j]; + m->col[j] = t; + + t = r->col[i]; + r->col[i] = r->col[j]; + r->col[j] = t; + } + + for (j = 0; jcol[j][k0],b0)) + { s = m->col[j]; + t = m->col[i]; + for (k = k0; kcol[j]; + t = r->col[i]; + for (k = 0; kn_words; + + n2 = mod2dense_cols(m); + + if (mod2dense_rows(r)!=n || mod2dense_cols(r)!=n2) + { fprintf(stderr, +"mod2dense_invert_selected2: Matrix to receive inverse has wrong dimensions\n"); + exit(1); + } + + mod2dense_clear(r); + + for (i = 0; i> mod2_wordsize_shift; + b0 = rows[i] & mod2_wordsize_mask; + + for (j = i; jcol[cols[j]][k0],b0)) break; + } + + if (jcol[j][k0],b0)) + { s = m->col[j]; + t = m->col[c]; + for (k = 0; kcol[j]; + t = r->col[c]; + for (k = 0; kcol[cols[j]]; + for (k = 0; kn_words; + + if (mod2dense_rows(r)!=n || mod2dense_cols(r)!=n) + { fprintf(stderr, + "mod2dense_forcibly_invert: Matrix to receive inverse has wrong dimensions\n"); + exit(1); + } + + mod2dense_clear(r); + for (i = 0; i> mod2_wordsize_shift; + b0 = i & mod2_wordsize_mask; + + for (j = i; jcol[j][k0],b0)) break; + } + + if (j==n) + { j = i; + mod2dense_set(m,i,j,1); + a_row[i] = i; + } + + if (j!=i) + { + t = m->col[i]; + m->col[i] = m->col[j]; + m->col[j] = t; + + t = r->col[i]; + r->col[i] = r->col[j]; + r->col[j] = t; + + u = a_col[i]; + a_col[i] = a_col[j]; + a_col[j] = u; + } + + for (j = 0; jcol[j][k0],b0)) + { s = m->col[j]; + t = m->col[i]; + for (k = k0; kcol[j]; + t = r->col[i]; + for (k = 0; k /* Has the definition of uint32_t used below */ + +/* PACKING OF BITS INTO WORDS. Bits are packed into 32-bit words, with + the low-order bit coming first. */ + +typedef uint32_t mod2word; /* Data type that holds packed bits. If uint32_t + doesn't exist, change it to unsigned long */ + +#define mod2_wordsize 32 /* Number of bits that fit in a mod2word. Can't + be increased without changing intio module */ + +#define mod2_wordsize_shift 5 /* Amount to shift by to divide by wordsize */ +#define mod2_wordsize_mask 0x1f /* What to AND with to produce mod wordsize */ + +/* Extract the i'th bit of a mod2word. */ + +#define mod2_getbit(w,i) (((w)>>(i))&1) + +/* Make a word like w, but with the i'th bit set to 1 (if it wasn't already). */ + +#define mod2_setbit1(w,i) ((w)|(1<<(i))) + +/* Make a word like w, but with the i'th bit set to 0 (if it wasn't already). */ + +#define mod2_setbit0(w,i) ((w)&(~(1<<(i)))) + + +/* STRUCTURE REPRESENTING A DENSE MATRIX. These structures are dynamically + allocated using mod2dense_allocate (or by other procedures that call + mod2dense_allocate). They should be freed with mod2dense_free when no + longer required. + + Direct access to this structure should be avoided except in low-level + routines. Use the macros and procedures defined below instead. */ + +typedef struct +{ + int n_rows; /* Number of rows in the matrix */ + int n_cols; /* Number of columns in the matrix */ + + int n_words; /* Number of words used to store a column of bits */ + + mod2word **col; /* Pointer to array of pointers to columns */ + + mod2word *bits; /* Pointer to storage block for bits in this matrix + (pieces of this block are pointed to from col) */ +} mod2dense; + + +/* MACROS. */ + +#define mod2dense_rows(m) ((m)->n_rows) /* Get the number of rows or columns */ +#define mod2dense_cols(m) ((m)->n_cols) /* in a matrix */ + + +/* PROCEDURES. */ + +mod2dense *mod2dense_allocate (int, int); +void mod2dense_free (mod2dense *); + +void mod2dense_clear (mod2dense *); +void mod2dense_copy (mod2dense *, mod2dense *); +void mod2dense_copyrows (mod2dense*, mod2dense *, int *); +void mod2dense_copycols (mod2dense*, mod2dense *, int *); + +void mod2dense_print (FILE *, mod2dense *); +int mod2dense_write (FILE *, mod2dense *); +mod2dense *mod2dense_read (FILE *); + +int mod2dense_get (mod2dense *, int, int); +void mod2dense_set (mod2dense *, int, int, int); +int mod2dense_flip(mod2dense *, int, int); + +void mod2dense_transpose (mod2dense *, mod2dense *); +void mod2dense_add (mod2dense *, mod2dense *, mod2dense *); +void mod2dense_multiply (mod2dense *, mod2dense *, mod2dense *); + +int mod2dense_equal (mod2dense *, mod2dense *); + +int mod2dense_invert (mod2dense *, mod2dense *); +int mod2dense_forcibly_invert (mod2dense *, mod2dense *, int *, int *); +int mod2dense_invert_selected (mod2dense *, mod2dense *, int *, int *); diff --git a/lib/ldpc/mod2dense.html b/lib/ldpc/mod2dense.html new file mode 100755 index 00000000..2b831387 --- /dev/null +++ b/lib/ldpc/mod2dense.html @@ -0,0 +1,487 @@ + + + Dense Modulo-2 Matrix Routines + + + + +

Dense Modulo-2 Matrix Routines

+ +

This module implements operations on matrices in which the elements +are all 0 or 1, with addition and multiplication being done modulo 2. +The matrices are stored with consecutive bits of a column packed into +32-bit words, and the procedures are implemented where possible using +bit operations on these words. + +

This is an appropriate representation when the matrices are dense +(ie, 0s and 1s are about equally frequent). Matrices in which most +elements are 0s may be better handled with the sparse modulo-2 matrix routines. Matrices +can be converted between these two formats using the module-2 matrix conversion routines. + +

All procedures in this module display an error message on standard +error and terminate the program if passed an invalid argument +(indicative of a programming error), or if memory cannot be allocated. +Errors from invalid contents of a file result in an error code being +returned to the caller, with no message being printed by this module. + + +

Representation of dense matrices

+ +

This module represents a matrix by a pointer to a structure of type +mod2dense. This structure records the number of rows and +columns in the matrix, and contains an array of pointers to where the +bits making up each column are stored. These bits are packed 32 per +word. When possible, bits in a column are manipulated 32 bits at a +time, which operations such as adding one column to another much +faster than the corresponding operations on rows. The pointer +structure also allows the columns of a matrix to easily be rearranged, +which may be necessary when doing matrix inversion. + + +

Header files required: +mod2dense.h + + + +


+
Dimension Macros
+
+ +
The following macros take a pointer to a mod2dense structure as their +argument, and return the number of rows or the number of columns in +the matrix pointed to, which will have been fixed when the matrix was +created with mod2dense_allocate: +
+mod2dense_rows(m)   /* Returns the number of rows in m */
+
+mod2dense_cols(m)   /* Returns the number of columns in m */
+
+ + + +


+
Allocating and Freeing Dense Modulo-2 Matrices
+
+ + +
mod2dense_allocate: +Allocate space for a dense module-2 matrix.
+ +
+mod2dense *mod2dense_allocate 
+( int n_rows,    /* Number of rows in matrix */
+  int n_cols     /* Number of columns in matrix */
+)
+
+ +Allocates space for a matrix with the given number of rows and +columns, and returns a pointer to it. If there is not enough memory +available, a message is displayed on standard error and the program is +terminated. The matrix should be freed with mod2dense_free once it is no longer in use. + +


mod2dense_free: +Free the space occupied by a dense module-2 matrix. + +
+void mod2dense_free 
+( mod2dense *m   /* Pointer to matrix to free */
+)
+
+ +Frees the space occupied by the matrix for re-use. The pointer passed +should no longer be used. + + + +


+
Copying and Clearing Dense Modulo-2 Matrices
+
+ +
mod2dense_clear: +Set all elements of a matrix to zero.
+ +
+void mod2dense_clear
+( mod2dense *m   /* Pointer to matrix to clear */
+)
+
+ +Sets all of the elements of the matrix passed to 0. + +


mod2dense_copy: +Copy the contents of one matrix to another. + +
+void mod2dense_copy
+( mod2dense *m   /* Pointer to matrix to copy from */
+  mod2dense *r   /* Pointer to matrix to receive data */
+)
+
+ +Copies the contents of the first matrix passed, m, to the +second matrix passed, r, which must already have been +allocated, and must have at least as many rows and columns as the +first. If r is larger than m, its elements that have +row or column indexes greater than the dimension of m are set +to zeros. + + +


mod2dense_copyrows: +Copy selected rows from one matrix to another. + +
+void mod2dense_copyrows
+( mod2dense *m,   /* Pointer to matrix to copy columns from */
+  mod2dense *r,   /* Pointer to matrix in which to store data */
+  int *rows       /* Indexes of rows, numbered from 0 */
+)
+
+ +Copies selected rows of the first matrix, m, to the second +matrix, r, which must already have been allocated, and which +must have at least as many columns as m. The indexes of the +rows to copy are given in order as an array of length the same as +the number of rows in r; duplicates are allowed. Row +indexes start at 0. These rows are copied to r, with the +row indexed by the first entry in rows going to the first +row of r, and so forth. If r has more columns than +m, the extra entries in each row are set to zeros. + + +


mod2dense_copycols: +Copy selected columns from one matrix to another. + +
+void mod2dense_copycols
+( mod2dense *m,   /* Pointer to matrix to copy columns from */
+  mod2dense *r,   /* Pointer to matrix in which to store data */
+  int *cols       /* Indexes of columns, numbered from 0 */
+)
+
+ +Copies selected columns of the first matrix, m, to the second +matrix, r, which must already have been allocated, and which +must have at least as many rows as m. The indexes of the +columns to copy are given in order as an array of length the same as +the number of columns in r; duplicates are allowed. Column +indexes start at 0. These columns are copied to r, with the +column indexed by the first entry in cols going to the first +column of r, and so forth. If r has more rows than +m, the extra entries in each column are set to zeros. + + + +


+
Input and Output of Dense Modulo-2 Matrices
+
+ +
mod2dense_print: +Print a dense modulo-2 matrix in human-readable form.
+ +
+void mod2dense_print
+( FILE *f,       /* File to print to */
+  mod2dense *m   /* Pointer to matrix to print */
+)
+
+ +The matrix is printed on standard output as "0" and "1" characters, +each preceded by a space, with one line of "0"s and "1"s for each row +of the matrix. + +


mod2dense_write: +Write a dense modulo-2 matrix to a file in machine-readable format. + +
+int mod2dense_write
+( FILE *f,       /* File to write data to */
+  mod2dense *m   /* Pointer to matrix write out */
+)
+
+ +Writes a machine-readable representation the dense matrix m to +the file f. The file should have been opened in binary mode +(with a "b" in the mode passed to fopen). The contents written will +not be text, and will not be human-readable. Other binary data may +precede or follow the data for the matrix written. + +

The data written to the file consists of the number of rows and the +number of columns, followed by the bits in each column, packed into +32-bit words. The data should be readable by mod2dense_read even on a machine with a +different byte-ordering. + +

The value returned by mod2dense_write is one if the +operation was successful, zero if an error of some sort occurred. + +


mod2dense_read: +Read a dense modulo-2 matrix from a file. + +
+mod2dense *mod2dense_read
+( FILE *f,       /* File to read data from */
+)
+
+ +Reads a dense modulo-2 matrix from the file f. This file +should have been opened in binary mode (with a "b" in the mode passed +to fopen). The contents of the file at the point when +mod2dense_read is called should have been written by mod2dense_write. Other binary data may +precede or follow this data. + +

The value returned is a pointer to the matrix read, for which space +will have been allocated by mod2dense_read, or zero if an +error occurred (either an error reading the file, or data not in the +right format). + + + +


+
Elementary Operations on Dense Modulo-2 Matrices
+
+ +
mod2dense_get: +Get an element of a dense modulo-2 matrix.
+ +
+int mod2dense_get  
+( mod2dense *m,   /* Pointer to matrix to get element from */
+  int row,        /* Row of element (indexed from zero) */
+  int col         /* Column of element (indexed from zero) */
+)
+
+ +Returns the value (0 or 1) of the element in the given row and column +of the matrix m. + +


mod2dense_set: +Set an element of a dense modulo-2 matrix. + +
+void mod2dense_set
+( mod2dense *m,   /* Pointer to matrix to get element from */
+  int row,        /* Row of element (indexed from zero) */
+  int col,        /* Column of element (indexed from zero) */
+  int value       /* New value of element (0 or 1) */
+)
+
+ +Set the element in the given row and column of the matrix m to +the specified value. + +


mod2dense_flip: +Flip an element of a dense modulo-2 matrix. + +
+int mod2dense_flip
+( mod2dense *m,   /* Pointer to matrix to get element from */
+  int row,        /* Row of element (indexed from zero) */
+  int col         /* Column of element (indexed from zero) */
+)
+
+ +Flips the value of the element in the given row and column of the +matrix m, changing it to 0 if it was 1, and to 1 if it was 0. +Returns the new value of this element. + + + +


+
Dense Modulo-2 Matrix Arithmetic and Comparison
+
+ +
mod2dense_transpose: +Compute the transpose of a dense modulo-2 matrix.
+ +
+void mod2dense_transpose
+( mod2dense *m,   /* Matrix to compute transpose of */
+  mod2dense *r    /* Result of transpose operation */
+)
+
+ +Stores the transpose of its first argument, m, in the matrix +pointed to by its second argument, r, which must already have +been allocated, and which must have as many rows as m has +columns, and as many columns as m has rows. The two matrices +m and r must not be the same (ie, the two pointers +passed must be different). + +


mod2dense_add: +Add two dense modulo-2 matrices. + +
+void mod2dense_add
+( mod2dense *m1,  /* Left operand of add */
+  mod2dense *m2,  /* Right operand of add */
+  mod2dense *r    /* Place to store result of add */
+)
+
+ +Adds matrices m1 and m2, storing the result in the +matrix pointed to by r. All three matrices must have the same +numbers of rows and columns. It is permissible for r to be the +same as m1 and/or m2. Neither of the first two matrices is +changed by this procedure (unless they are the same as r). + + +


mod2dense_multiply: +Multiply two dense modulo-2 matrices. + +
+void mod2dense_multiply 
+( mod2dense *m1,  /* Left operand of multiply */
+  mod2dense *m2,  /* Right operand of multiply */
+  mod2dense *r    /* Place to store result of multiply */
+)
+
+ +Does a matrix multiplication of m1 by m2, and stores the +result in the matrix pointed to by r. The matrices must have +compatible numbers of rows and columns. Neither of the first two +matrices is changed by this procedure. The result matrix, r, +must not be the same as either m1 or m2. + +

The algorithm used runs faster if m2 contains mostly 0s, but +it is also appropriate for matrices with many 1s. + +


mod2dense_equal: +Check whether two dense modulo-2 matrices are equal. + +
+int mod2dense_equal
+( mod2dense *m1, /* Pointers to the two matrices */
+  mod2dense *m2  /*   to compare                 */
+)
+
+ +Returns one if every element of m1 is equal to the +corresponding element of m2, and otherwise returns zero. The +two matrices must have the same number of rows and the same number of +columns. + + +


+
Dense Modulo-2 Matrix Inversion
+
+ +
mod2dense_invert: +Invert a dense modulo-2 matrix.
+ +
+int mod2dense_invert
+( mod2dense *m,   /* Matrix to find inverse of (destroyed) */
+  mod2dense *r    /* Place to store the inverse */
+)
+
+ +

Inverts the first matrix passed, m, and stores its inverse in +the second matrix, r. The contents of m are destroyed +by this operation, though it remains a valid matrix for storing into +later. The matrix m must have the same number of rows as +columns. The matrix r must already have been allocated, and +must have the same number of rows and columns as m. The +two matrices passed must not be the same. + +

The value returned is one if the inversion was successful and zero +if the matrix turned out to be singular (in which case the contents of +both the original matrix and the result matrix will be garbage). + +

The algorithm used is based on inverting M by transforming the equation +MI = M to the equation MR = I using column operations, at which point R +is the inverse of M. The representation of matrices used allows easy +swapping of columns as needed by fiddling pointers. + +


mod2dense_forcibly_invert: +Forcibly invert a matrix by changing bits if necessary. + +
+int mod2dense_forcibly_invert
+( mod2dense *m,   /* Matrix to find inverse of (destroyed) */
+  mod2dense *r,   /* Place to store the inverse */
+  int *a_row,     /* Place to store row indexes of altered elements */
+  int *a_col      /* Place to store column indexes of altered elements */
+)
+
+ +

Inverts the first matrix passed, m, and stores its inverse +in the second matrix, r, proceeding with the inversion even if +m is singular, by changing some elements as necessary. The +contents of m are destroyed by this operation, though it +remains a valid matrix for storing into later. The matrix m +must have the same number of rows as columns. The matrix r +must already have been allocated, and must have the same number of +rows and columns as m. The two matrices passed must not be the +same. + +

The value returned is the number of elements of m that had +to be changed to make inversion possible (zero, if the original matrix +was non-singular). The row and column indexes of the elements of the +original matrix that were changed are stored in the arrays passed as +the last two elements. These arrays must have as many elements as the +dimension of the matrix. (This is so even if it is known that fewer +elements than this will be changed, as these arrays are also used as +temporary storage by this routine.) + +

See mod2dense_invert for the algorithm used. + +


mod2dense_invert_selected: +Invert a matrix with columns selected from a bigger matrix. + +
+int mod2dense_invert_selected 
+( mod2dense *m,   /* Matrix from which a submatrix is inverted (destroyed) */
+  mod2dense *r,   /* Place to store the inverse */
+  int *rows,      /* Place to store indexes of rows used and not used */
+  int *cols       /* Place to store indexes of columns used and not used */
+)
+
+ +

Inverts a matrix obtained by selecting certain columns from the +first matrix passed, m, which must have at least as many +columns as rows. The second matrix passed, r, must already +exist, and must have the same number of rows and columns as m. +The result of inverting the sub-matrix of m is stored in the +corresponding columns of r, with the other columns being set to +garbage (or zero, see below). Normally, one would extract just the +relevant columns afterwards using mod2dense_copycols.) The contents of +m are destroyed (though it remains a valid matrix for storing +into later. The two matrices passed must not be the same. + +

The indexes of the columns selected are stored, in order, in the last +argument, cols, followed by the columns not selected (in +arbitrary order). The argument rows is set to the indexes of +the rows used, which will be simply the indexes from zero up if the +matrix is invertible, and will otherwise give an ordering that allows +the inversion to proceed as far as possible. + +

The value returned is zero if an invertible matrix was found, and +is otherwise the number of columns/rows that are redundant (ie, the +amount by which matrix falls short of being of full rank). If +inversion fails, partial results are stored in the columns and rows of +r identified by the initial portions of cols and +rows, such that if these rows and columns were extracted in +their new order, they would constitute the inverse of the +corresponding re-ordered submatrix of m. The remaining portion +of cols up to the number of rows in m will contain +indexes of columns of r that are selected arbitrarily; these +columns will, however, be set to contain all zeros. + +

Note that when the first matrix is square, and non-singular, the +result is NOT in general the same as that obtained by calling mod2dense_invert, since that procedure +orders the columns of the inverse so that it applies to the original +ordering of the columns of the first matrix. + +

See mod2dense_invert for the algorithm used. + +


+ +Back to index for LDPC software + + diff --git a/lib/ldpc/mod2sparse-test-out b/lib/ldpc/mod2sparse-test-out new file mode 100755 index 00000000..5d17ddec --- /dev/null +++ b/lib/ldpc/mod2sparse-test-out @@ -0,0 +1,431 @@ + +PART 1: + +Matrix m1: + + 0: 0 + 1: 1 + 2: 2 3 + 3: 3 + 4: 4 + 5: 5 + 6: 6 + 7: 7 + 8: 8 + 9: 9 +10: 10 38 +11: 11 +12: 12 +13: 13 +14: 14 +15: 15 +16: 16 +17: 17 +18: 18 +19: 19 +20: 20 +21: 21 +22: 22 +23: 23 +24: 24 +25: 25 +26: 26 +27: 27 +28: 28 +29: 29 +30: 30 +31: 31 +32: 32 +33: 33 +34: 4 34 + +Matrix m2, as read from file. Should be same as m1 above. + + 0: 0 + 1: 1 + 2: 2 3 + 3: 3 + 4: 4 + 5: 5 + 6: 6 + 7: 7 + 8: 8 + 9: 9 +10: 10 38 +11: 11 +12: 12 +13: 13 +14: 14 +15: 15 +16: 16 +17: 17 +18: 18 +19: 19 +20: 20 +21: 21 +22: 22 +23: 23 +24: 24 +25: 25 +26: 26 +27: 27 +28: 28 +29: 29 +30: 30 +31: 31 +32: 32 +33: 33 +34: 4 34 + +Test of equality of m1 & m2 (should be 1): 1 + +Matrix m3, copied from m1 above. + + 0: 0 + 1: 1 + 2: 2 3 + 3: 3 + 4: 4 + 5: 5 + 6: 6 + 7: 7 + 8: 8 + 9: 9 +10: 10 38 +11: 11 +12: 12 +13: 13 +14: 14 +15: 15 +16: 16 +17: 17 +18: 18 +19: 19 +20: 20 +21: 21 +22: 22 +23: 23 +24: 24 +25: 25 +26: 26 +27: 27 +28: 28 +29: 29 +30: 30 +31: 31 +32: 32 +33: 33 +34: 4 34 + +Test of equality of m1 & m3 (should be 1): 1 + +Matrix m3 again, should now be all zeros. + + 0: + 1: + 2: + 3: + 4: + 5: + 6: + 7: + 8: + 9: +10: +11: +12: +13: +14: +15: +16: +17: +18: +19: +20: +21: +22: +23: +24: +25: +26: +27: +28: +29: +30: +31: +32: +33: +34: + +Test of equality of m1 & m3 (should be 0): 0 + + +PART 2: + +Transpose of m1. + + 0: 0 + 1: 1 + 2: 2 + 3: 2 3 + 4: 4 34 + 5: 5 + 6: 6 + 7: 7 + 8: 8 + 9: 9 +10: 10 +11: 11 +12: 12 +13: 13 +14: 14 +15: 15 +16: 16 +17: 17 +18: 18 +19: 19 +20: 20 +21: 21 +22: 22 +23: 23 +24: 24 +25: 25 +26: 26 +27: 27 +28: 28 +29: 29 +30: 30 +31: 31 +32: 32 +33: 33 +34: 34 +35: +36: +37: +38: 10 +39: + +Matrix m1 after adding rows 2 and 12 and 3 to 10. + + 0: 0 + 1: 1 + 2: 2 3 + 3: 3 + 4: 4 + 5: 5 + 6: 6 + 7: 7 + 8: 8 + 9: 9 +10: 2 10 12 38 +11: 11 +12: 12 +13: 13 +14: 14 +15: 15 +16: 16 +17: 17 +18: 18 +19: 19 +20: 20 +21: 21 +22: 22 +23: 23 +24: 24 +25: 25 +26: 26 +27: 27 +28: 28 +29: 29 +30: 30 +31: 31 +32: 32 +33: 33 +34: 4 34 + +Matrix m1 after further adding column 34 to 0. + + 0: 0 + 1: 1 + 2: 2 3 + 3: 3 + 4: 4 + 5: 5 + 6: 6 + 7: 7 + 8: 8 + 9: 9 +10: 2 10 12 38 +11: 11 +12: 12 +13: 13 +14: 14 +15: 15 +16: 16 +17: 17 +18: 18 +19: 19 +20: 20 +21: 21 +22: 22 +23: 23 +24: 24 +25: 25 +26: 26 +27: 27 +28: 28 +29: 29 +30: 30 +31: 31 +32: 32 +33: 33 +34: 0 4 34 + + +PART 3: + +Matrix s0. + +0: +1: 3 4 +2: 0 +3: 1 +4: + +Matrix s1. + +0: +1: 3 5 +2: +3: 0 1 6 +4: + +Matrix s2. + +0: 0 +1: 1 +2: +3: +4: +5: 1 2 3 +6: + +Maxtrix s1 times unpacked vector ( 1 0 0 1 0 1 0 ). + +( 0 0 0 1 0 ) + +Sum of s0 and s1. + +0: +1: 4 5 +2: 0 +3: 0 6 +4: + +Product of s1 and s2. + +0: +1: 1 2 3 +2: +3: 0 1 +4: + +Tried to find (1,2), actually found: (1,2) + +Above matrix with (1,2) cleared. + +0: +1: 1 3 +2: +3: 0 1 +4: + +Tried to find (1,1), actually found: (1,1) + +Matrix with (1,1) cleared as well. + +0: +1: 3 +2: +3: 0 1 +4: + + +PART 4: + +Matrix s1. + +0: 3 5 +1: 1 6 +2: 0 +3: 1 2 +4: 0 2 +5: 6 + +LU decomposition (returned value was 0). + +L= +0: 3 +1: 1 +2: 0 +3: 1 2 +4: 0 2 4 +5: + +U= +0: 0 +1: 1 6 +2: 2 6 +3: 3 +4: 6 + +cols: 0 1 2 3 6 5 4 +rows: 2 1 3 0 4 5 + +Product of L and U. + +0: 3 +1: 1 6 +2: 0 +3: 1 2 +4: 0 2 +5: + +Solution of Ly=x with x from ( 0 1 1 0 1 0 ) according to rows selected. + + 1 1 1 0 1 + +Returned value from forward_sub was 1 + +Solution of Uz=y. + + 1 0 0 0 0 0 1 + +Returned value from backward_sub was 1 + + +PART 5: + +Matrix m1: + +0: 3 +1: 1 +2: 2 +3: 0 + +Matrix m2, copyrows of m1 in order 3,1,2,0 (should be identity) + +0: 0 +1: 1 +2: 2 +3: 3 + +Matrix m3, copycols of m1 in order 3,1,2,0 (should be identity) + +0: 0 +1: 1 +2: 2 +3: 3 + + +DONE WITH TESTS. diff --git a/lib/ldpc/mod2sparse-test.c b/lib/ldpc/mod2sparse-test.c new file mode 100755 index 00000000..04c26250 --- /dev/null +++ b/lib/ldpc/mod2sparse-test.c @@ -0,0 +1,378 @@ +/* MOD2SPARSE-TEST. C - Program to test mod2sparse module. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + + +/* Correct output for this program is saved in the file mod2sparse-test-out */ + + +#include +#include +#include + +#include "mod2sparse.h" + + +main(void) +{ + mod2sparse *m1, *m2, *m3, *m4; + mod2sparse *s0, *s1, *s2, *s3, *s4; + mod2sparse *L, *U; + mod2entry *e; + int rows[5], cols[7]; + int i, j; + FILE *f; + + + printf("\nPART 1:\n\n"); + + /* Set up m1 with bits on a diagonal plus a few more set to 1. */ + + m1 = mod2sparse_allocate(35,40); + + mod2sparse_clear(m1); + + for (i = 0; i<35; i++) mod2sparse_insert(m1,i,i); + + mod2sparse_insert(m1,2,3); + mod2sparse_insert(m1,34,4); + mod2sparse_insert(m1,10,38); + + /* Print m1. */ + + printf("Matrix m1:\n\n"); + mod2sparse_print(stdout,m1); + printf("\n"); fflush(stdout); + + /* Store m1 in a file. */ + + f = fopen("test-file","wb"); + if (f==0) + { fprintf(stderr,"Can't create test-file\n"); + exit(1); + } + + if (!mod2sparse_write(f,m1)) + { printf("Error from mod2sparse_write\n"); + } + + fclose(f); + + /* Read matrix written above back into m2. */ + + f = fopen("test-file","rb"); + if (f==0) + { fprintf(stderr,"Can't open test-file\n"); + exit(1); + } + + m2 = mod2sparse_read(f); + + if (m2==0) + { printf("Error from mod2sparse_read\n"); + exit(1); + } + + /* Print m2, along with result of equality test. */ + + printf("Matrix m2, as read from file. Should be same as m1 above.\n\n"); + mod2sparse_print(stdout,m2); + printf("\n"); fflush(stdout); + + printf("Test of equality of m1 & m2 (should be 1): %d\n\n", + mod2sparse_equal(m1,m2)); + + /* Copy m1 to m3. */ + + m3 = mod2sparse_allocate(mod2sparse_rows(m1),mod2sparse_cols(m1)); + + mod2sparse_copy(m1,m3); + + /* Print m3, along with result of equality test. */ + + printf("Matrix m3, copied from m1 above.\n\n"); + mod2sparse_print(stdout,m3); + printf("\n"); fflush(stdout); + + printf("Test of equality of m1 & m3 (should be 1): %d\n\n", + mod2sparse_equal(m1,m3)); + + /* Clear m3. */ + + mod2sparse_clear(m3); + + /* Print m3 again. */ + + printf("Matrix m3 again, should now be all zeros.\n\n"); + mod2sparse_print(stdout,m3); + printf("\n"); fflush(stdout); + + printf("Test of equality of m1 & m3 (should be 0): %d\n\n", + mod2sparse_equal(m1,m3)); + + + printf("\nPART 2:\n\n"); + + /* Compute transpose of m1. */ + + m4 = mod2sparse_allocate(mod2sparse_cols(m1),mod2sparse_rows(m1)); + + mod2sparse_transpose(m1,m4); + + /* Print transpose. */ + + printf("Transpose of m1.\n\n"); + mod2sparse_print(stdout,m4); + printf("\n"); fflush(stdout); + + /* Add rows and columns in m1. */ + + mod2sparse_add_row(m1,10,m1,2); + mod2sparse_add_row(m1,10,m1,12); + mod2sparse_add_row(m1,10,m1,3); + printf("Matrix m1 after adding rows 2 and 12 and 3 to 10.\n\n"); + mod2sparse_print(stdout,m1); + printf("\n"); fflush(stdout); + printf("Matrix m1 after further adding column 34 to 0.\n\n"); + mod2sparse_add_col(m1,0,m1,34); + mod2sparse_print(stdout,m1); + printf("\n"); fflush(stdout); + + /* Free space for m1, m2, and m3. */ + + mod2sparse_free(m1); + mod2sparse_free(m2); + mod2sparse_free(m3); + + + printf("\nPART 3:\n\n"); + + /* Allocate some small matrices. */ + + s0 = mod2sparse_allocate(5,7); + s1 = mod2sparse_allocate(5,7); + s2 = mod2sparse_allocate(7,4); + s3 = mod2sparse_allocate(5,4); + s4 = mod2sparse_allocate(5,7); + + /* Set up the contents of s0, s1, and s2. */ + + mod2sparse_clear(s0); + mod2sparse_clear(s1); + mod2sparse_clear(s2); + + mod2sparse_insert(s0,1,3); + mod2sparse_insert(s0,1,4); + mod2sparse_insert(s0,2,0); + mod2sparse_insert(s0,3,1); + + mod2sparse_insert(s1,1,3); + mod2sparse_insert(s1,1,5); + mod2sparse_insert(s1,3,0); + mod2sparse_insert(s1,3,1); + mod2sparse_insert(s1,3,6); + + mod2sparse_insert(s2,5,1); + mod2sparse_insert(s2,5,2); + mod2sparse_insert(s2,5,3); + mod2sparse_insert(s2,0,0); + mod2sparse_insert(s2,1,1); + + /* Print s0, s1, and s2. */ + + printf("Matrix s0.\n\n"); + mod2sparse_print(stdout,s0); + printf("\nMatrix s1.\n\n"); + mod2sparse_print(stdout,s1); + printf("\nMatrix s2.\n\n"); + mod2sparse_print(stdout,s2); + printf("\n"); fflush(stdout); + + /* Multiply s1 by vector (1 1 0 1 0 1 0). */ + + { char u[7] = { 1, 0, 0, 1, 0, 1, 0 }; + char v[5]; + int i; + printf("Maxtrix s1 times unpacked vector ( 1 0 0 1 0 1 0 ).\n\n("); + mod2sparse_mulvec(s1,u,v); + for (i = 0; i<5; i++) printf(" %d",v[i]); + printf(" )\n\n"); + } + + /* Add s0 and s1, storing the result in s4, then print s4. */ + + mod2sparse_add(s0,s1,s4); + + printf("Sum of s0 and s1.\n\n"); + mod2sparse_print(stdout,s4); + printf("\n"); fflush(stdout); + + /* Multiply s1 and s2, storing the product in s3, and then print s3. */ + + mod2sparse_multiply(s1,s2,s3); + + printf("Product of s1 and s2.\n\n"); + mod2sparse_print(stdout,s3); + printf("\n"); fflush(stdout); + + /* Try clearing a bit in s3, then printing the result. */ + + e = mod2sparse_find(s3,1,2); + printf("Tried to find (1,2), actually found: (%d,%d)\n\n", + mod2sparse_row(e), mod2sparse_col(e)); + + mod2sparse_delete(s3,e); + + printf("Above matrix with (1,2) cleared.\n\n"); + mod2sparse_print(stdout,s3); + printf("\n"); fflush(stdout); + + /* Try clearing another bit in s3, then printing the result. */ + + e = mod2sparse_find(s3,1,1); + printf("Tried to find (1,1), actually found: (%d,%d)\n\n", + mod2sparse_row(e), mod2sparse_col(e)); + + mod2sparse_delete(s3,e); + + printf("Matrix with (1,1) cleared as well.\n\n"); + mod2sparse_print(stdout,s3); + printf("\n"); fflush(stdout); + + /* Free space for s0, s1, s2, s3, and s4. */ + + mod2sparse_free(s0); + mod2sparse_free(s1); + mod2sparse_free(s2); + mod2sparse_free(s3); + mod2sparse_free(s4); + + + printf("\nPART 4:\n\n"); + + /* Set up a small rectangular matrix, s1. */ + + s1 = mod2sparse_allocate(6,7); + + mod2sparse_clear(s1); + + mod2sparse_insert(s1,0,3); + mod2sparse_insert(s1,0,5); + mod2sparse_insert(s1,1,6); + mod2sparse_insert(s1,1,1); + mod2sparse_insert(s1,2,0); + mod2sparse_insert(s1,3,1); + mod2sparse_insert(s1,3,2); + mod2sparse_insert(s1,4,2); + mod2sparse_insert(s1,4,0); + mod2sparse_insert(s1,5,6); + + /* Print s1. */ + + printf("Matrix s1.\n\n"); + mod2sparse_print(stdout,s1); + printf("\n"); fflush(stdout); + + /* Compute and print LU decomposition. */ + + L = mod2sparse_allocate(6,5); + U = mod2sparse_allocate(5,7); + + i = mod2sparse_decomp(s1,5,L,U,rows,cols,Mod2sparse_first,0,0); + + printf("LU decomposition (returned value was %d).\n\n",i); + printf("L=\n"); + mod2sparse_print(stdout,L); + printf("\nU=\n"); + mod2sparse_print(stdout,U); + printf("\n"); + + printf("cols:"); + for (j = 0; j<7; j++) printf(" %d",cols[j]); + printf("\n"); + printf("rows:"); + for (i = 0; i<6; i++) printf(" %d",rows[i]); + printf("\n\n"); + fflush(stdout); + + /* Compute and print product of L and U. Should match s1 for the + sub-matrix found. */ + + s2 = mod2sparse_allocate(6,7); + mod2sparse_multiply(L,U,s2); + + printf("Product of L and U.\n\n"); + mod2sparse_print(stdout,s2); + printf("\n"); + fflush(stdout); + + /* Solve system by forward and backward substitution. */ + + { char x[6] = { 0, 1, 1, 0, 1, 0 }; + static char y[5], z[7]; + int i, r; + + r = mod2sparse_forward_sub (L, rows, x, y); + printf( +"Solution of Ly=x with x from ( 0 1 1 0 1 0 ) according to rows selected.\n\n"); + for (i = 0; i<5; i++) printf(" %d",y[i]); + printf("\n\nReturned value from forward_sub was %d\n\n",r); + fflush(stdout); + + r = mod2sparse_backward_sub (U, cols, y, z); + printf("Solution of Uz=y.\n\n"); + for (i = 0; i<7; i++) printf(" %d",z[i]); + printf("\n\nReturned value from backward_sub was %d\n\n",r); + fflush(stdout); + } + + printf("\nPART 5:\n\n"); + + m1 = mod2sparse_allocate(4,4); + m2 = mod2sparse_allocate(4,4); + m3 = mod2sparse_allocate(4,4); + + mod2sparse_insert(m1,0,3); + mod2sparse_insert(m1,1,1); + mod2sparse_insert(m1,2,2); + mod2sparse_insert(m1,3,0); + + printf("Matrix m1:\n\n"); + + mod2sparse_print(stdout,m1); + printf("\n"); fflush(stdout); + + printf("Matrix m2, copyrows of m1 in order 3,1,2,0 (should be identity)\n\n"); + + { int rows[] = { 3, 1, 2, 0 }; + mod2sparse_copyrows(m1,m2,rows); + } + + mod2sparse_print(stdout,m2); + printf("\n"); fflush(stdout); + + printf("Matrix m3, copycols of m1 in order 3,1,2,0 (should be identity)\n\n"); + + { int cols[] = { 3, 1, 2, 0 }; + mod2sparse_copycols(m1,m3,cols); + } + + mod2sparse_print(stdout,m3); + printf("\n"); fflush(stdout); + + + printf("\nDONE WITH TESTS.\n"); + + exit(0); +} diff --git a/lib/ldpc/mod2sparse.c b/lib/ldpc/mod2sparse.c new file mode 100755 index 00000000..f3f9ba9f --- /dev/null +++ b/lib/ldpc/mod2sparse.c @@ -0,0 +1,1365 @@ +/* MOD2SPARSE.C - Procedures for handling sparse mod2 matrices. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + + +/* NOTE: See mod2sparse.html for documentation on these procedures. */ + + +#include +#include +#include + +#include "alloc.h" +#include "intio.h" +#include "mod2sparse.h" + + +/* ALLOCATE AN ENTRY WITHIN A MATRIX. This local procedure is used to + allocate a new entry, representing a non-zero element, within a given + matrix. Entries in this matrix that were previously allocated and + then freed are re-used. If there are no such entries, a new block + of entries is allocated. */ + +static mod2entry *alloc_entry +( mod2sparse *m +) +{ + mod2block *b; + mod2entry *e; + int k; + + if (m->next_free==0) + { + b = chk_alloc (1, sizeof *b); + + b->next = m->blocks; + m->blocks = b; + + for (k = 0; kentry[k].left = m->next_free; + m->next_free = &b->entry[k]; + } + } + + e = m->next_free; + m->next_free = e->left; + + e->pr = 0; + e->lr = 0; + + return e; +} + + +/* ALLOCATE SPACE FOR A SPARSE MOD2 MATRIX. */ + +mod2sparse *mod2sparse_allocate +( int n_rows, /* Number of rows in matrix */ + int n_cols /* Number of columns in matrix */ +) +{ + mod2sparse *m; + mod2entry *e; + int i, j; + + if (n_rows<=0 || n_cols<=0) + { fprintf(stderr,"mod2sparse_allocate: Invalid number of rows or columns\n"); + exit(1); + } + + m = chk_alloc (1, sizeof *m); + + m->n_rows = n_rows; + m->n_cols = n_cols; + + m->rows = chk_alloc (n_rows, sizeof *m->rows); + m->cols = chk_alloc (n_cols, sizeof *m->cols); + + m->blocks = 0; + m->next_free = 0; + + for (i = 0; irows[i]; + e->left = e->right = e->up = e->down = e; + e->row = e->col = -1; + } + + for (j = 0; jcols[j]; + e->left = e->right = e->up = e->down = e; + e->row = e->col = -1; + } + + return m; +} + + +/* FREE SPACE OCCUPIED BY A SPARSE MOD2 MATRIX. */ + +void mod2sparse_free +( mod2sparse *m /* Matrix to free */ +) +{ + mod2block *b; + + if (m) + { free(m->rows); + free(m->cols); + + while (m->blocks!=0) + { b = m->blocks; + m->blocks = b->next; + free(b); + } + + free (m); + } +} + + +/* CLEAR A SPARSE MATRIX TO ALL ZEROS. */ + +void mod2sparse_clear +( mod2sparse *r +) +{ + mod2block *b; + mod2entry *e; + int i, j; + + for (i = 0; irows[i]; + e->left = e->right = e->up = e->down = e; + } + + for (j = 0; jcols[j]; + e->left = e->right = e->up = e->down = e; + } + + while (r->blocks!=0) + { b = r->blocks; + r->blocks = b->next; + free(b); + } +} + + +/* COPY A SPARSE MATRIX. */ + +void mod2sparse_copy +( mod2sparse *m, /* Matrix to copy */ + mod2sparse *r /* Place to store copy of matrix */ +) +{ + mod2entry *e, *f; + int i; + + if (mod2sparse_rows(m)>mod2sparse_rows(r) + || mod2sparse_cols(m)>mod2sparse_cols(r)) + { fprintf(stderr,"mod2sparse_copy: Destination matrix is too small\n"); + exit(1); + } + + mod2sparse_clear(r); + + for (i = 0; irow,e->col); + f->lr = e->lr; + f->pr = e->pr; + e = mod2sparse_next_in_row(e); + } + } +} + + +/* COPY ROWS OF A SPARSE MOD2 MATRIX. */ + +void mod2sparse_copyrows +( mod2sparse *m, /* Matrix to copy */ + mod2sparse *r, /* Place to store copy of matrix */ + int *rows /* Indexes of rows to copy, from 0 */ +) +{ + mod2entry *e; + int i; + + if (mod2sparse_cols(m)>mod2sparse_cols(r)) + { fprintf(stderr, + "mod2sparse_copyrows: Destination matrix has fewer columns than source\n"); + exit(1); + } + + mod2sparse_clear(r); + + for (i = 0; i=mod2sparse_rows(m)) + { fprintf(stderr,"mod2sparse_copyrows: Row index out of range\n"); + exit(1); + } + e = mod2sparse_first_in_row(m,rows[i]); + while (!mod2sparse_at_end(e)) + { mod2sparse_insert(r,i,e->col); + e = mod2sparse_next_in_row(e); + } + } +} + + +/* COPY COLUMNS OF A SPARSE MOD2 MATRIX. */ + +void mod2sparse_copycols +( mod2sparse *m, /* Matrix to copy */ + mod2sparse *r, /* Place to store copy of matrix */ + int *cols /* Indexes of columns to copy, from 0 */ +) +{ + mod2entry *e; + int j; + + if (mod2sparse_rows(m)>mod2sparse_rows(r)) + { fprintf(stderr, + "mod2sparse_copycols: Destination matrix has fewer rows than source\n"); + exit(1); + } + + mod2sparse_clear(r); + + for (j = 0; j=mod2sparse_cols(m)) + { fprintf(stderr,"mod2sparse_copycols: Column index out of range\n"); + exit(1); + } + e = mod2sparse_first_in_col(m,cols[j]); + while (!mod2sparse_at_end(e)) + { mod2sparse_insert(r,e->row,j); + e = mod2sparse_next_in_col(e); + } + } +} + + +/* PRINT A SPARSE MOD2 MATRIX IN HUMAN-READABLE FORM. */ + +void mod2sparse_print +( FILE *f, + mod2sparse *m +) +{ + int rdigits, cdigits; + mod2entry *e; + int i; + + rdigits = mod2sparse_rows(m)<=10 ? 1 + : mod2sparse_rows(m)<=100 ? 2 + : mod2sparse_rows(m)<=1000 ? 3 + : mod2sparse_rows(m)<=10000 ? 4 + : mod2sparse_rows(m)<=100000 ? 5 + : 6; + + cdigits = mod2sparse_cols(m)<=10 ? 1 + : mod2sparse_cols(m)<=100 ? 2 + : mod2sparse_cols(m)<=1000 ? 3 + : mod2sparse_cols(m)<=10000 ? 4 + : mod2sparse_cols(m)<=100000 ? 5 + : 6; + + for (i = 0; in_rows); + if (ferror(f)) return 0; + + intio_write(f,m->n_cols); + if (ferror(f)) return 0; + + for (i = 0; i=n_rows) break; + } + else + { col = v-1; + if (col>=n_cols) break; + if (row==-1) break; + mod2sparse_insert(m,row,col); + } + } + + /* Error if we get here. */ + + mod2sparse_free(m); + return 0; +} + + +/* LOOK FOR AN ENTRY WITH GIVEN ROW AND COLUMN. */ + +mod2entry *mod2sparse_find +( mod2sparse *m, + int row, + int col +) +{ + mod2entry *re, *ce; + + if (row<0 || row>=mod2sparse_rows(m) || col<0 || col>=mod2sparse_cols(m)) + { fprintf(stderr,"mod2sparse_find: row or column index out of bounds\n"); + exit(1); + } + + /* Check last entries in row and column. */ + + re = mod2sparse_last_in_row(m,row); + if (mod2sparse_at_end(re) || mod2sparse_col(re)col) + { return 0; + } + if (mod2sparse_col(re)==col) + { return re; + } + + if (mod2sparse_at_end(ce) || mod2sparse_row(ce)>row) + { return 0; + } + if (mod2sparse_row(ce)==row) + { return ce; + } + + re = mod2sparse_next_in_row(re); + ce = mod2sparse_next_in_col(ce); + } +} + + +/* INSERT AN ENTRY WITH GIVEN ROW AND COLUMN. */ + +mod2entry *mod2sparse_insert +( mod2sparse *m, + int row, + int col +) +{ + mod2entry *re, *ce, *ne; + + if (row<0 || row>=mod2sparse_rows(m) || col<0 || col>=mod2sparse_cols(m)) + { fprintf(stderr,"mod2sparse_insert: row or column index out of bounds\n"); + exit(1); + } + + /* Find old entry and return it, or allocate new entry and insert into row. */ + + re = mod2sparse_last_in_row(m,row); + + if (!mod2sparse_at_end(re) && mod2sparse_col(re)==col) + { return re; + } + + if (mod2sparse_at_end(re) || mod2sparse_col(re)right; + } + else + { + re = mod2sparse_first_in_row(m,row); + + for (;;) + { + if (!mod2sparse_at_end(re) && mod2sparse_col(re)==col) + { return re; + } + + if (mod2sparse_at_end(re) || mod2sparse_col(re)>col) + { break; + } + + re = mod2sparse_next_in_row(re); + } + } + + ne = alloc_entry(m); + + ne->row = row; + ne->col = col; + + ne->left = re->left; + ne->right = re; + ne->left->right = ne; + ne->right->left = ne; + + /* Insert new entry into column. If we find an existing entry here, + the matrix must be garbled, since we didn't find it in the row. */ + + ce = mod2sparse_last_in_col(m,col); + + if (!mod2sparse_at_end(ce) && mod2sparse_row(ce)==row) + { fprintf(stderr,"mod2sparse_insert: Garbled matrix\n"); + exit(1); + } + + if (mod2sparse_at_end(ce) || mod2sparse_row(ce)down; + } + else + { + ce = mod2sparse_first_in_col(m,col); + + for (;;) + { + if (!mod2sparse_at_end(ce) && mod2sparse_row(ce)==row) + { fprintf(stderr,"mod2sparse_insert: Garbled matrix\n"); + exit(1); + } + + if (mod2sparse_at_end(ce) || mod2sparse_row(ce)>row) + { break; + } + + ce = mod2sparse_next_in_col(ce); + } + } + + ne->up = ce->up; + ne->down = ce; + ne->up->down = ne; + ne->down->up = ne; + + /* Return the new entry. */ + + return ne; +} + + +/* DELETE AN ENTRY FROM A SPARSE MATRIX. */ + +void mod2sparse_delete +( mod2sparse *m, + mod2entry *e +) +{ + if (e==0) + { fprintf(stderr,"mod2sparse_delete: Trying to delete a null entry\n"); + exit(1); + } + + if (e->row<0 || e->col<0) + { fprintf(stderr,"mod2sparse_delete: Trying to delete a header entry\n"); + exit(1); + } + + e->left->right = e->right; + e->right->left = e->left; + + e->up->down = e->down; + e->down->up = e->up; + + e->left = m->next_free; + m->next_free = e; +} + + +/* TEST WHETHER TWO SPARSE MATRICES ARE EQUAL. */ + +int mod2sparse_equal +( mod2sparse *m1, + mod2sparse *m2 +) +{ + mod2entry *e1, *e2; + int i; + + if (mod2sparse_rows(m1)!=mod2sparse_rows(m2) + || mod2sparse_cols(m1)!=mod2sparse_cols(m2)) + { fprintf(stderr,"mod2sparse_equal: Matrices have different dimensions\n"); + exit(1); + } + + for (i = 0; i=mod2sparse_rows(m)) + { fprintf(stderr,"mod2sparse_count_row: row index out of bounds\n"); + exit(1); + } + + count = 0; + + for (e = mod2sparse_first_in_row(m,row); + !mod2sparse_at_end(e); + e = mod2sparse_next_in_row(e)) + { count += 1; + } + + return count; +} + + +/* COUNT ENTRIES IN A COLUMN. */ + +int mod2sparse_count_col +( mod2sparse *m, + int col +) +{ + mod2entry *e; + int count; + + if (col<0 || col>=mod2sparse_cols(m)) + { fprintf(stderr,"mod2sparse_count_col: column index out of bounds\n"); + exit(1); + } + + count = 0; + + for (e = mod2sparse_first_in_col(m,col); + !mod2sparse_at_end(e); + e = mod2sparse_next_in_col(e)) + { count += 1; + } + + return count; +} + + +/* ADD TO A ROW. */ + +void mod2sparse_add_row +( mod2sparse *m1, /* Matrix containing row to add to */ + int row1, /* Index in this matrix of row to add to */ + mod2sparse *m2, /* Matrix containing row to add from */ + int row2 /* Index in this matrix of row to add from */ +) +{ + mod2entry *f1, *f2, *ft; + + if (mod2sparse_cols(m1)=mod2sparse_rows(m1) + || row2<0 || row2>=mod2sparse_rows(m2)) + { fprintf (stderr,"mod2sparse_add_row: row index out of range\n"); + exit(1); + } + + f1 = mod2sparse_first_in_row(m1,row1); + f2 = mod2sparse_first_in_row(m2,row2); + + while (!mod2sparse_at_end(f1) && !mod2sparse_at_end(f2)) + { if (mod2sparse_col(f1)>mod2sparse_col(f2)) + { mod2sparse_insert(m1,row1,mod2sparse_col(f2)); + f2 = mod2sparse_next_in_row(f2); + } + else + { ft = mod2sparse_next_in_row(f1); + if (mod2sparse_col(f1)==mod2sparse_col(f2)) + { mod2sparse_delete(m1,f1); + f2 = mod2sparse_next_in_row(f2); + } + f1 = ft; + } + } + + while (!mod2sparse_at_end(f2)) + { mod2sparse_insert(m1,row1,mod2sparse_col(f2)); + f2 = mod2sparse_next_in_row(f2); + } +} + + +/* ADD TO A COLUMN. */ + +void mod2sparse_add_col +( mod2sparse *m1, /* Matrix containing column to add to */ + int col1, /* Index in this matrix of column to add to */ + mod2sparse *m2, /* Matrix containing column to add from */ + int col2 /* Index in this matrix of column to add from */ +) +{ + mod2entry *f1, *f2, *ft; + + if (mod2sparse_rows(m1)=mod2sparse_cols(m1) + || col2<0 || col2>=mod2sparse_cols(m2)) + { fprintf (stderr,"mod2sparse_add_col: Column index out of range\n"); + exit(1); + } + + f1 = mod2sparse_first_in_col(m1,col1); + f2 = mod2sparse_first_in_col(m2,col2); + + while (!mod2sparse_at_end(f1) && !mod2sparse_at_end(f2)) + { if (mod2sparse_row(f1)>mod2sparse_row(f2)) + { mod2sparse_insert(m1,mod2sparse_row(f2),col1); + f2 = mod2sparse_next_in_col(f2); + } + else + { ft = mod2sparse_next_in_col(f1); + if (mod2sparse_row(f1)==mod2sparse_row(f2)) + { mod2sparse_delete(m1,f1); + f2 = mod2sparse_next_in_col(f2); + } + f1 = ft; + } + } + + while (!mod2sparse_at_end(f2)) + { mod2sparse_insert(m1,mod2sparse_row(f2),col1); + f2 = mod2sparse_next_in_col(f2); + } +} + + +/* FIND AN LU DECOMPOSITION OF A SPARSE MATRIX. */ + +int mod2sparse_decomp +( mod2sparse *A, /* Input matrix, M by N */ + int K, /* Size of sub-matrix to find LU decomposition of */ + mod2sparse *L, /* Matrix in which L is stored, M by K */ + mod2sparse *U, /* Matrix in which U is stored, K by N */ + int *rows, /* Array where row indexes are stored, M long */ + int *cols, /* Array where column indexes are stored, N long */ + mod2sparse_strategy strategy, /* Strategy to follow in picking rows/columns */ + int abandon_number, /* Number of columns to abandon at some point */ + int abandon_when /* When to abandon these columns */ +) +{ + int *rinv, *cinv, *acnt, *rcnt; + mod2sparse *B; + int M, N; + + mod2entry *e, *f, *fn, *e2; + int i, j, k, cc, cc2, cc3, cr2, pr; + int found, nnf; + + M = mod2sparse_rows(A); + N = mod2sparse_cols(A); + + if (mod2sparse_cols(L)!=K || mod2sparse_rows(L)!=M + || mod2sparse_cols(U)!=N || mod2sparse_rows(U)!=K) + { fprintf (stderr, + "mod2sparse_decomp: Matrices have incompatible dimensions\n"); + exit(1); + } + + if (abandon_number>N-K) + { fprintf(stderr,"Trying to abandon more columns than allowed\n"); + exit(1); + } + + rinv = chk_alloc (M, sizeof *rinv); + cinv = chk_alloc (N, sizeof *cinv); + + if (abandon_number>0) + { acnt = chk_alloc (M+1, sizeof *acnt); + } + + if (strategy==Mod2sparse_minprod) + { rcnt = chk_alloc (M, sizeof *rcnt); + } + + mod2sparse_clear(L); + mod2sparse_clear(U); + + /* Copy A to B. B will be modified, then discarded. */ + + B = mod2sparse_allocate(M,N); + mod2sparse_copy(A,B); + + /* Count 1s in rows of B, if using minprod strategy. */ + + if (strategy==Mod2sparse_minprod) + { for (i = 0; i=i) + { found = 1; + goto out_first; + } + e = mod2sparse_next_in_col(e); + } + } + + out_first: + break; + } + + case Mod2sparse_mincol: + { + found = 0; + + for (j = i; j=i) + { found = 1; + cc = cc2; + e = e2; + k = j; + break; + } + e2 = mod2sparse_next_in_col(e2); + } + } + } + + break; + } + + case Mod2sparse_minprod: + { + found = 0; + + for (j = i; j=i) + { cr2 = rcnt[mod2sparse_row(e2)]; + if (!found || cc2==1 || (cc2-1)*(cr2-1)i) + { mod2sparse_add_row(B,k,B,mod2sparse_row(e)); + if (strategy==Mod2sparse_minprod) + { rcnt[k] = mod2sparse_count_row(B,k); + } + mod2sparse_insert(L,k,i); + } + else if (rinv[k]0 && i==abandon_when) + { + for (k = 0; kk || (cc3==k && cc>0)) + { if (cc3==k) cc -= 1; + for (;;) + { f = mod2sparse_first_in_col(B,j); + if (mod2sparse_at_end(f)) break; + mod2sparse_delete(B,f); + } + cc2 += 1; + } + } + + if (cc2!=abandon_number) abort(); + + if (strategy==Mod2sparse_minprod) + { for (j = 0; j0) free(acnt); + + return nnf; +} + + +/* SOLVE A LOWER-TRIANGULAR SYSTEM BY FORWARD SUBSTITUTION. */ + +int mod2sparse_forward_sub +( mod2sparse *L, /* Matrix that is lower triangular after reordering */ + int *rows, /* Array of indexes (from 0) of rows for new order */ + char *x, /* Vector on right of equation, also reordered */ + char *y /* Place to store solution */ +) +{ + int K, i, j, ii, b, d; + mod2entry *e; + + K = mod2sparse_cols(L); + + /* Make sure that L is lower-triangular, after row re-ordering. */ + + for (i = 0; ii) + { fprintf(stderr, + "mod2sparse_forward_sub: Matrix is not lower-triangular\n"); + exit(1); + } + } + + /* Solve system by forward substitution. */ + + for (i = 0; ii) + { fprintf(stderr, + "mod2sparse_backward_sub: Matrix is not upper-triangular\n"); + exit(1); + } + } + + /* Solve system by backward substitution. */ + + for (i = K-1; i>=0; i--) + { + ii = cols ? cols[i] : i; + + /* Look at bits in this row, forming inner product with partial + solution, and seeing if the diagonal is 1. */ + + d = 0; + b = 0; + + for (e = mod2sparse_first_in_row(U,i); + !mod2sparse_at_end(e); + e = mod2sparse_next_in_row(e)) + { + j = mod2sparse_col(e); + + if (j==ii) + { d = 1; + } + else + { b ^= z[j]; + } + } + + /* Check for no solution if the diagonal isn't 1. */ + + if (!d && b!=y[i]) + { return 0; + } + + /* Set bit of solution, zero if arbitrary. */ + + z[ii] = b^y[i]; + } + + return 1; +} diff --git a/lib/ldpc/mod2sparse.h b/lib/ldpc/mod2sparse.h new file mode 100755 index 00000000..23d8d79f --- /dev/null +++ b/lib/ldpc/mod2sparse.h @@ -0,0 +1,147 @@ +/* MOD2SPARSE.H - Interface to module for handling sparse mod2 matrices. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + + +/* This module implements operations on sparse matrices of mod2 elements + (bits, with addition and multiplication being done modulo 2). + + All procedures in this module display an error message on standard + error and terminate the program if passed an invalid argument (indicative + of a programming error), or if memory cannot be allocated. Errors from + invalid contents of a file result in an error code being returned to the + caller, with no message being printed by this module. +*/ + + +/* DATA STRUCTURES USED TO STORE A SPARSE MATRIX. Non-zero entries (ie, 1s) + are represented by nodes that are doubly-linked both by row and by column, + with the headers for these lists being kept in arrays. Nodes are allocated + in blocks to reduce time and space overhead. Freed nodes are kept for + reuse in the same matrix, rather than being freed for other uses, except + that they are all freed when the matrix is cleared to all zeros by the + mod2sparse_clear procedure, or copied into by mod2sparse_copy. + + Direct access to these structures should be avoided except in low-level + routines. Use the macros and procedures defined below instead. */ + +typedef struct mod2entry /* Structure representing a non-zero entry, or + the header for a row or column */ +{ + int row, col; /* Row and column indexes of this entry, starting + at 0, and with -1 for a row or column header */ + + struct mod2entry *left, *right, /* Pointers to entries adjacent in row */ + *up, *down; /* and column, or to headers. Free */ + /* entries are linked by 'left'. */ + + double pr, lr; /* Probability and likelihood ratios - not used */ + /* by the mod2sparse module itself */ +} mod2entry; + +#define Mod2sparse_block 10 /* Number of entries to block together for + memory allocation */ + +typedef struct mod2block /* Block of entries allocated all at once */ +{ + struct mod2block *next; /* Next block that has been allocated */ + + mod2entry entry[Mod2sparse_block]; /* Entries in this block */ + +} mod2block; + +typedef struct /* Representation of a sparse matrix */ +{ + int n_rows; /* Number of rows in the matrix */ + int n_cols; /* Number of columns in the matrix */ + + mod2entry *rows; /* Pointer to array of row headers */ + mod2entry *cols; /* Pointer to array of column headers */ + + mod2block *blocks; /* Blocks that have been allocated */ + mod2entry *next_free; /* Next free entry */ + +} mod2sparse; + + +/* MACROS TO GET AT ELEMENTS OF A SPARSE MATRIX. The 'first', 'last', 'next', + and 'prev' macros traverse the elements in a row or column. Moving past + the first/last element gets one to a header element, which can be identified + using the 'at_end' macro. Macros also exist for finding out the row + and column of an entry, and for finding out the dimensions of a matrix. */ + +#define mod2sparse_first_in_row(m,i) ((m)->rows[i].right) /* Find the first */ +#define mod2sparse_first_in_col(m,j) ((m)->cols[j].down) /* or last entry in */ +#define mod2sparse_last_in_row(m,i) ((m)->rows[i].left) /* a row or column */ +#define mod2sparse_last_in_col(m,j) ((m)->cols[j].up) + +#define mod2sparse_next_in_row(e) ((e)->right) /* Move from one entry to */ +#define mod2sparse_next_in_col(e) ((e)->down) /* another in any of the four */ +#define mod2sparse_prev_in_row(e) ((e)->left) /* possible directions */ +#define mod2sparse_prev_in_col(e) ((e)->up) + +#define mod2sparse_at_end(e) ((e)->row<0) /* See if we've reached the end */ + +#define mod2sparse_row(e) ((e)->row) /* Find out the row or column index */ +#define mod2sparse_col(e) ((e)->col) /* of an entry (indexes start at 0) */ + +#define mod2sparse_rows(m) ((m)->n_rows) /* Get the number of rows or columns*/ +#define mod2sparse_cols(m) ((m)->n_cols) /* in a matrix */ + + +/* POSSIBLE LU DECOMPOSITION STRATEGIES. For use with mod2sparse_decomp. */ + +typedef enum +{ Mod2sparse_first, + Mod2sparse_mincol, + Mod2sparse_minprod +} mod2sparse_strategy; + + +/* PROCEDURES TO MANIPULATE SPARSE MATRICES. */ + +mod2sparse *mod2sparse_allocate (int, int); +void mod2sparse_free (mod2sparse *); + +void mod2sparse_clear (mod2sparse *); +void mod2sparse_copy (mod2sparse *, mod2sparse *); +void mod2sparse_copyrows (mod2sparse *, mod2sparse *, int *); +void mod2sparse_copycols (mod2sparse *, mod2sparse *, int *); + +void mod2sparse_print (FILE *, mod2sparse *); +int mod2sparse_write (FILE *, mod2sparse *); +mod2sparse *mod2sparse_read (FILE *); + +mod2entry *mod2sparse_find (mod2sparse *, int, int); +mod2entry *mod2sparse_insert (mod2sparse *, int, int); +void mod2sparse_delete (mod2sparse *, mod2entry *); + +void mod2sparse_transpose (mod2sparse *, mod2sparse *); +void mod2sparse_add (mod2sparse *, mod2sparse *, mod2sparse *); +void mod2sparse_multiply (mod2sparse *, mod2sparse *, mod2sparse *); +void mod2sparse_mulvec (mod2sparse *, char *, char *); + +int mod2sparse_equal (mod2sparse *, mod2sparse *); + +int mod2sparse_count_row (mod2sparse *, int); +int mod2sparse_count_col (mod2sparse *, int); + +void mod2sparse_add_row (mod2sparse *, int, mod2sparse *, int); +void mod2sparse_add_col (mod2sparse *, int, mod2sparse *, int); + +int mod2sparse_decomp (mod2sparse *, int, mod2sparse *, mod2sparse *, + int *, int *, mod2sparse_strategy, int, int); + +int mod2sparse_forward_sub (mod2sparse *, int *, char *, char *); +int mod2sparse_backward_sub (mod2sparse *, int *, char *, char *); diff --git a/lib/ldpc/mod2sparse.html b/lib/ldpc/mod2sparse.html new file mode 100755 index 00000000..1681d4a7 --- /dev/null +++ b/lib/ldpc/mod2sparse.html @@ -0,0 +1,719 @@ + + + Sparse Modulo-2 Matrix Routines + + + + +

Sparse Modulo-2 Matrix Routines

+ +

This module implements operations on matrices in which the elements +are all 0 or 1, with addition and multiplication being done modulo 2. +The matrices are represented by doubly-linked lists of entries +representing the elements in each row and column that are 1s, with +other elements being assumed to be zero. + +

This is an appropriate representation when the matrices are sparse +(ie, 0s are much more frequent that 1s). Matrices in which 0s and 1s +are about equally likely may be better handled with the dense modulo-2 matrix routines. Matrices +can be converted between these two formats using the module-2 matrix conversion routines. + +

All procedures in this module display an error message on standard +error and terminate the program if passed an invalid argument (indicative +of a programming error), or if memory cannot be allocated. Errors from +invalid contents of a file result in an error code being returned to the +caller, with no message being printed by this module. + + +

Representation of sparse matrices

+ +

This module represents a non-zero element of a matrix (which must have +the value 1, since these are modulo-2 matrices) by a node of type +mod2entry, which contains the row and column of the element, +pointers to the next non-zero elements above and below in its column +and to the left and the right in its row, and two double-precision +floating-point numbers called pr and lr, which are +of no significance to this module, but which are used by the routines +for decoding LDPC codes by probability +propagation. + +

The mod2sparse type represents a matrix. It records the +number of rows and columns in the matrix, and contains arrays of +pointers to the mod2entry structures for the first non-zero +element in each row and the first non-zero element in each column. + +

Matrices must be created by the mod2sparse_allocate procedure, which +returns a pointer to a mod2sparse structure. When a matrix +is no longer needed, the space it occupies can be freed with mod2sparse_free. Elements within a matrix, +represented by mod2entry nodes, are allocated as needed, and +if deleted, they will be reused for new elements within the same +matrix. The space they occupy is not reusable for other matrices or +other purposes until the entire matrix is either freed, with mod2sparse_free, or cleared to all zeros, +with mod2sparse_clear, or used as +the result matrix for copying or arithmetic operations. + + +

Header files required: +mod2sparse.h + + + +


+
Dimension Macros
+
+ +
The following macros take a pointer to a mod2sparse structure as their +argument, and return the number of rows or the number of columns in +the matrix pointed to, which will have been fixed when the matrix was +created with mod2sparse_allocate: +
+mod2sparse_rows(m)   /* Returns the number of rows in m */
+
+mod2sparse_cols(m)   /* Returns the number of columns in m */
+
+ + + +


+
Traversal Macros
+
+ +
The following macros are used to move around a sparse matrix by +following the pointers from one non-zero element to the next or +previous non-zero element in the same row or column. If such a +movement takes one beyond the last or before first entry in a row or +column, or if one tries to find the first or last non-zero entry in a +row or column that has no non-zero entries, the entry returned will be +a special one that can be identified using the +mod2sparse_at_end macro. If one is already at this special +entry, moving further wraps one around to the first or last entry. + +

The macros for finding the first or last entry in a row or column +take as their arguments a pointer to the matrix (mod2sparse +*) and a row or column index, starting at zero. The other macros +take as their arguments a pointer to an entry (mod2entry *) +within some matrix. + +

+mod2sparse_first_in_row(m,i) /* Returns the first entry in row i of m */
+mod2sparse_first_in_col(m,j) /* Returns the first entry in column j of m */
+
+mod2sparse_last_in_row(m,i)  /* Returns the last entry in row i of m */
+mod2sparse_last_in_col(m,j)  /* Returns the last entry in column j of m */
+
+mod2sparse_next_in_row(e)    /* Returns the entry after e in its row */
+mod2sparse_next_in_col(e)    /* Returns the entry after e in its column */
+
+mod2sparse_prev_in_row(e)    /* Returns the entry before e in its row */
+mod2sparse_prev_in_col(e)    /* Returns the entry before e in its col */
+
+mod2sparse_row(e)            /* Returns the row index of entry e */
+mod2sparse_col(e)            /* Returns the column index of entry e */
+
+mod2sparse_at_end(e)         /* Returns 1 if e is a special entry obtained 
+                                by moving past the end, returns 0 otherwise */
+
+ + + +


+
Allocating and Freeing Sparse Modulo-2 Matrices
+
+ + +
mod2sparse_allocate: +Allocate space for a sparse module-2 matrix.
+ +
+mod2sparse *mod2sparse_allocate 
+( int n_rows,     /* Number of rows in matrix */
+  int n_cols      /* Number of columns in matrix */
+)
+
+ +Allocates space for a matrix with the given number of rows and +columns, and returns a pointer to it. The matrix will initially +be all zero. + +

If there is not enough memory available, a message is displayed on +standard error and the program is terminated. The matrix should be +freed with mod2sparse_free once it is no +longer in use. + +


mod2sparse_free: +Free the space occupied by a sparse module-2 matrix. + +
+void mod2sparse_free 
+( mod2sparse *m   /* Pointer to matrix to free */
+)
+
+ +Frees the space occupied by the matrix for re-use. The pointer passed +should not be used afterward. Note that space for the individual matrix +elements (but not the matrix as a whole) is also freed when mod2sparse_clear is called, or the matrix +is used as the destination for other operations. + + + +


+
Copying and Clearing Sparse Modulo-2 Matrices
+
+ +
mod2sparse_clear: +Set all elements of a matrix to zero.
+ +
+void mod2sparse_clear
+( mod2sparse *m   /* Pointer to matrix to clear */
+)
+
+ +Sets all of the elements of the matrix passed to 0. The space occupied +by the previous non-zero elements is freed for use in other matrices, or +other purposes. The matrix itself is not freed, however. To do that, +use mod2sparse_free. + + +


mod2sparse_copy: +Copy the contents of one matrix to another. + +
+void mod2sparse_copy
+( mod2sparse *m   /* Pointer to matrix to copy from */
+  mod2sparse *r   /* Pointer to matrix to receive data */
+)
+
+ +Copies the contents of the first matrix passed, m, to the +second matrix passed, r, which must already have been +allocated, and must have at least as many rows and columns as the +first. If r is larger than m, its elements that have +row or column indexes greater than the dimension of m are set +to zeros. + +

The space occupied by the previous non-zero entries of r is +freed for general use (which may include being reused immediately for +the copies of the entries in m). + + +


mod2sparse_copyrows: +Copy selected rows from one matrix to another. + +
+void mod2sparse_copyrows
+( mod2sparse *m,  /* Pointer to matrix to copy rows from */
+  mod2sparse *r,  /* Pointer to matrix in which to store data */
+  int *rows       /* Indexes of rows, numbered from 0 */
+)
+
+ +Copies selected rows of the first matrix, m, to the second +matrix, r, which must already have been allocated, and which +must have at least as many columns as m. The indexes of the +rows to copy are given in order as an array of length the same as +the number of rows in r; duplicates are allowed. Row +indexes start at 0. These rows are copied to r, with the +row indexed by the first entry in rows going to the +first row of r, and so forth. If r has more columns than +m, the extra entries in each row are set to zeros. + +

The space occupied by the previous non-zero entries of r is +freed for general use (which may include being reused immediately for +the copies of the entries in m). + + +


mod2sparse_copycols: +Copy selected columns from one matrix to another. + +
+void mod2sparse_copycols
+( mod2sparse *m,  /* Pointer to matrix to copy columns from */
+  mod2sparse *r,  /* Pointer to matrix in which to store data */
+  int *cols       /* Indexes of columns, numbered from 0 */
+)
+
+ +Copies selected columns of the first matrix, m, to the second +matrix, r, which must already have been allocated, and which +must have at least as many rows as m. The indexes of the +columns to copy are given in order as an array of length the same as +the number of columns in r; duplicates are allowed. Column +indexes start at 0. These columns are copied to r, with the +column indexed by the first entry in cols going to the +first column of r, and so forth. If r has more rows than +m, the extra entries in each column are set to zeros. + +

The space occupied by the previous non-zero entries of r is +freed for general use (which may include being reused immediately for +the copies of the entries in m). + + + +


+
Input and Output of Sparse Modulo-2 Matrices
+
+ +
mod2sparse_print: +Print a sparse modulo-2 matrix in human-readable form.
+ +
+void mod2sparse_print
+( FILE *f,        /* File to print to */
+  mod2sparse *m   /* Pointer to matrix to print */
+)
+
+ +The matrix is printed on standard output with one line of output per row, +of the form +
+row: col col col ...
+
+where row is the index of the row, and the col entries are +the indexes of columns that are non-zero in that row. Row and column +indexes start at zero. Rows with no entries are printed with no column +indexes after the colon. The number of columns is not indicated in the output. + +


mod2sparse_write: +Write a sparse modulo-2 matrix to a file in machine-readable format. + +
+int mod2sparse_write
+( FILE *f,        /* File to write data to */
+  mod2sparse *m   /* Pointer to matrix write out */
+)
+
+ +Writes a machine-readable representation the sparse matrix m to +the file f. The file should have been opened in binary mode +(with a "b" in the mode passed to fopen). The contents written will +not be text, and will not be human-readable. Other binary data may +precede or follow the data for the matrix written. + +

The data written to the file starts with the number of rows and the +number of columns. Following this are negative integers giving row +indexes (starting at 1), which apply until the next row index, and +positive integers giving column indexes (starting at 1) for a non-zero +entry in the matrix. The data should be readable by mod2sparse_read even on a machine with a +different byte-ordering. + +

The value returned by mod2sparse_write is one if the +operation was successful, zero if an error of some sort occurred. + +


mod2sparse_read: +Read a sparse modulo-2 matrix from a file. + +
+mod2sparse *mod2sparse_read
+( FILE *f,        /* File to read data from */
+)
+
+ +Reads a sparse modulo-2 matrix from the file f. This file +should have been opened in binary mode (with a "b" in the mode passed +to fopen). The contents of the file at the point when +mod2sparse_read is called should have been written by mod2sparse_write. Other binary data may +precede or follow this data. + +

The value returned is a pointer to the matrix read, for which space +will have been allocated by mod2sparse_read, or zero if an +error occurred (either an error reading the file, or data not in the +right format). + + + +


+
Elementary Operations on Sparse Modulo-2 Matrices
+
+ +
mod2sparse_find: +Look for an entry at a given row and column.
+ +
+mod2entry *mod2sparse_find
+( mod2sparse *m,  /* Matrix in which to look for entry */
+  int row,        /* Row index (from 0) */
+  int col         /* Column index (from 0) */
+)
+
+ +Looks for an entry at the given row and column in the matrix m, +representing a non-zero element (ie, one with value 1). Returns a +pointer to this entry if it exists, or zero (a null pointer) if it +does not exist (ie, if that element of the matrix has value 0). + +

The search strategy is to first look at the end of the row and the +end of the column. The entry might be found at one of these two +places, or it might be determinable from these end entries that no +entry exists at the given row and column. Otherwise, searches are +done from the start of the row and the start of the column, in +parallel, until an entry with the given row and column are found, or +until it can be determined that such an entry does not exist. +Searching in parallel ensures that the operation will be fast if +either the row is sparse or the column is sparse. + +


mod2sparse_insert: +Insert an entry at a given row and column. + +
+mod2entry *mod2sparse_insert
+( mod2sparse *m,  /* Matrix in which to insert an entry */
+  int row,        /* Row index (from 0) */
+  int col         /* Column index (from 0) */
+)
+
+ +Adds a new entry (representing an element with value 1) at the given +row and column position in the matrix m. If such an entry +already exists, nothing is done (this is not considered to be an +error). The new (or existing) entry is returned as the value of +this procedure. + +

The search strategy is to first look at the end of the row for an +existing entry or for the place where the new entry belongs. If this +fails, the row is searched from the beginning. If an existing entry +is found, it is returned. Otherwise, a new entry is created, it is +inserted in its correct place in the row, and it is inserted in its +correct place in its column, once again by first looking at the end, +and then if required searching from the beginning. + +

The effect of this strategy is that a sparse matrix can be efficiently +created by either adding entries in increasing order by row and column or in +decreasing order by row and column. + +


mod2sparse_delete: +Delete an entry from a sparse modulo-2 matrix. + +
+void mod2sparse_delete
+( mod2sparse *m,  /* Matrix in which to delete an entry */
+  mod2entry *e    /* Entry to delete - MUST be in m */
+)
+
+ +Deletes the entry e from the sparse matrix m, which +effectively sets to zero the element of the matrix that this entry +corresponded to. The entry is freed for future use in the same +matrix, but not (immediately, at least) for use in other matrices, or +generally. The pointer to this entry should not be used again once +it is deleted. + +

The time required for this operation does not depend on how many +entries are currently in the matrix. + +

Warning: It is an error if e is not an entry of +m. This error is not currently diagnosed, but doing this may +cause serious problems, as it may lead later to entries for m +being erroneously freed when the matrix to which e properly +belongs is freed. + + +


+
Sparse Modulo-2 Matrix Arithmetic and Comparison
+
+ +
mod2sparse_transpose: +Compute the transpose of a sparse modulo-2 matrix.
+ +
+void mod2sparse_transpose
+( mod2sparse *m,  /* Matrix to compute transpose of */
+  mod2sparse *r   /* Result of transpose operation */
+)
+
+ +Stores the transpose of its first argument, m, in the matrix +pointed to by its second argument, r, which must already have +been allocated, and which must have as many rows as m has +columns, and as many columns as m has rows. The two matrices +m and r must not be the same (ie, the two pointers +passed must be different). + +

The space occupied by the previous non-zero entries of r is +freed for general use. + +


mod2sparse_add: +Add two sparse modulo-2 matrices. + +
+void mod2sparse_add
+( mod2sparse *m1, /* Left operand of add */
+  mod2sparse *m2, /* Right operand of add */
+  mod2sparse *r   /* Place to store result of add */
+)
+
+ +Adds matrices m1 and m2, storing the result in the +matrix pointed to by r. All three matrices must have the same +numbers of rows and columns. It is permissible for r to be the +same as m1 and/or m2. Neither of the first two matrices is +changed by this procedure (unless they are the same as r). + +

The space occupied by the previous non-zero entries of r is +freed for general use. + + +


mod2sparse_multiply: +Multiply two sparse modulo-2 matrices. + +
+void mod2sparse_multiply 
+( mod2sparse *m1, /* Left operand of multiply */
+  mod2sparse *m2, /* Right operand of multiply */
+  mod2sparse *r   /* Place to store result of multiply */
+)
+
+ +Does a matrix multiplication of m1 by m2, and stores the +result in the matrix pointed to by r. The matrices must have +compatible numbers of rows and columns. Neither of the first two +matrices is changed by this procedure. The result matrix, r, +must not be the same as either m1 or m2. + +

The space occupied by the previous non-zero entries of r is +freed for general use. + +


mod2sparse_mulvec: +Multiply a vector by a sparse modulo-2 matrix. + +
+void mod2sparse_mulvec
+( mod2sparse *m,  /* Pointer to matrix to multiply by, M rows, N columns */
+  char *u,        /* Pointer to unpacked vector to multiply, N long */
+  char *v         /* Pointer to unpacked result vector, M long */
+)
+
+ +Multiplies the vector u on the left by the sparse modulo-2 +matrix m, storing the result in v. Both u and +v are modulo-2 vectors, but are stored unpacked, with one bit +per char. Any non-zero value in u is equivalent to '1'. +The vectors u and v must not overlap. + +


mod2sparse_equal: +Check whether two sparse modulo-2 matrices are equal. + +
+int mod2sparse_equal
+( mod2sparse *m1, /* Pointers to the two matrices */
+  mod2sparse *m2  /*   to compare                 */
+)
+
+ +Returns one if every element of m1 is equal to the +corresponding element of m2, and otherwise returns zero. The +two matrices must have the same number of rows and the same number of +columns. + + + +


+
Row/Column Operations on Sparse Modulo-2 Matrices +
+ +
mod2sparse_count_row: +Count the number of 1s in a row of a sparse matrix.
+ +
+int mod2sparse_count_row
+( mod2sparse *m,  /* Pointer to matrix */
+  int row         /* Index of row to count (from 0) */
+)
+
+ +Returns the number of 1s in the given row of the matrix, by counting +the number of entries in that row. + +


mod2sparse_count_col: +Count the number of 1s in a column of a sparse matrix. + +
+int mod2sparse_count_col
+( mod2sparse *m,  /* Pointer to matrix */
+  int col         /* Index of column to count (from 0) */
+)
+
+ +Returns the number of 1s in the given column of the matrix, by counting +the number of entries in that column. + +


mod2sparse_add_row: +Add a row to a row of a sparse matrix. + +
+void mod2sparse_add_row
+( mod2sparse *m1, /* Matrix containing row to add to */
+  int row1,       /* Index in this matrix of row to add to */
+  mod2sparse *m2, /* Matrix containing row to add from */
+  int row2        /* Index in this matrix of row to add from */
+)
+
+ +Modifies the row with index row1 in the matrix m1 by +adding to that row the row with index row2 in the matrix +m2. The matrix m1 must have at least as many columns as +m2. This operation is performed by inserting entries into the +row of m1 at positions where they exist in the row of m2 +but not in the row of m1, and deleting entries in the row of +m1 that exist in the same position in the row of m2. +The matrix m2 is not modified. + +


mod2sparse_add_col: +Add a column to a column of a sparse matrix. + +
+void mod2sparse_add_col
+( mod2sparse *m1, /* Matrix containing column to add to */
+  int col1,       /* Index in this matrix of col to add to */
+  mod2sparse *m2, /* Matrix containing column to add from */
+  int col2        /* Index in this matrix of column to add from */
+)
+
+ +Modifies the column with index col1 in the matrix m1 by +adding to that column the column with index col2 in the matrix +m2. The matrix m1 must have at least as many rows as +m2. This operation is performed by inserting entries into the +column of m1 at positions where they exist in the column of +m2 but not in the column of m1, and deleting entries in +the column of m1 that exist in the same position in the column +of m2. The matrix m2 is not modified. + + + +


+
LU Decomposition of Sparse Modulo-2 Matrices
+
+ +
mod2sparse_decomp: +Find an LU decomposition of a sparse modulo-2 (sub-)matrix.
+ +
+int mod2sparse_decomp
+( mod2sparse *A,      /* Matrix to find LU decomposition within, M by N */
+  int K,              /* Size of sub-matrix to find LU decomposition of */
+  mod2sparse *L,      /* Matrix in which L is stored, M by K */
+  mod2sparse *U,      /* Matrix in which U is stored, K by N */
+  int *rows,          /* Array where row indexes are stored, M long */
+  int *cols,          /* Array where column indexes are stored, N long */
+  mod2sparse_strategy strategy, /* Strategy to follow in picking rows/columns */
+  int abandon_number, /* Number of columns to abandon at some point */
+  int abandon_when    /* When to abandon these columns */
+)
+
+ +

Takes as input a matrix, A, having M rows and +N columns, and an integer K. Finds an LU decomposition +of a K by K sub-matrix of A. The decomposition +is stored in the matrix L, with M rows and K +columns, and the matrix U, with K rows and N +columns. The product of L and U will be equal to the +K by K submatrix of A obtained by taking only +rows and columns that are given in the first K elements of the +rows and cols arrays, which are set by this procedure, +with this sub-matrix distributed over the original M rows and +N columns. Furthermore, the ordering of the row and column +indexes in these arrays will be set so that if the rows of L +and the columns of U were rearranged in this order, L +would be lower triangular, with zeros in rows past row K, and +U would be upper triangular, with zeros in columns past column +K. The rows array is M long, and the cols +array is N long. The elements in both arrays after the first +K contain the indexes of the rows and columns not selected to +be part of the sub-matrix of A, in arbitrary order. + +

The rows and columns of A are selected in order to try to +make the LU decomposition as sparse as possible, using the strategy +identified by the strategy, abandon_number, and +abandon_when parameters. The possible strategies are +Mod2sparse_first, Mod2sparse_mincol, and +Mod2sparse_minprod. If abandon_number is greater than +zero, it is possible that the matrix will appear to have linearly +dependent rows when it actually does not. See the discussion of sparse LU decomposition +methods for details about these strategies. + +

If A is not of rank K or more, L will contain +some number less than K of non-zero columns, and U will +contain an equal number of non-zero rows. The entries in the +rows and cols arrays for the extra zero rows or columns +will be arbitrary (but valid). The number of extra zero columns is +returned as the value of this procedure (hence a return value of zero +indicates that a K by K sub-matrix of full rank was +found). + +

The matrix A is not altered. The previous contents of +L and U are cleared. + +


mod2sparse_forward_sub: +Solve a lower-triangular system by forward substitution. + +
+int mod2sparse_forward_sub
+( mod2sparse *L,  /* Matrix that is lower triangular after reordering */
+  int *rows,      /* Array of indexes (from 0) of rows for new order */
+  char *x,        /* Vector on right of equation, also reordered */
+  char *y         /* Place to store solution */
+)
+
+ +

Solves the system of equations Ly=x for y by +forward substitution, based on L being lower triangular after +its rows are reordered according to the given index array. The +vectors x and y are stored unpacked, one bit per +character. If L is M by K, then x should +be M long, but only the K bits indexed by rows +are looked at. The solution vector, y, must be K long. +Only K rows of L are used, as also determined by the +K indexes in the rows argument. If rows is null, +the first K rows of L and the first K elements of +x are used. + +

If the matrix L does not have 1s on its diagonal (after row +rearrangement), there may be no solution, depending on what x +is. If no solution exists, this procedure returns zero, otherwise it +returns one. Any arbitrary bits in the solution are set to zero. + +


mod2sparse_backward_sub: +Solve an upper-triangular system by backward substitution. + +
+int mod2sparse_backward_sub
+( mod2sparse *U,  /* Matrix that is upper triangular after reordering */
+  int *cols,      /* Array of indexes (from 0) of columns for new order */
+  char *y,        /* Vector on right of equation */
+  char *z         /* Place to store solution, also reordered */
+)
+
+ +

Solves Uz=y for z by backward substitution, +based on U being upper triangular after its columns are +reordered according to the given index array. The vectors y +and z are stored unpacked, one bit per character. If U +is K by N, then the solution vector, z, should be +N long, but only the K bits indexed by cols are +set. The vector y must be K long. Only K columns +of U are used, as also determined by the K indexes in +the cols argument. The other columns of U must be zero +(this is not checked, but is necessary for the method used to work). +If cols is null, the first K columns of U and the +first K elements of z are used. + +

If the matrix U does not have 1s on its diagonal (after +column rearrangement) there may be no solution, depending on what y +is. If no solution exists, this procedure returns zero, otherwise it +returns one. Any arbitrary bits in the solution are set to zero. + +


+ +Back to index for LDPC software + + diff --git a/lib/ldpc/modify.html b/lib/ldpc/modify.html new file mode 100755 index 00000000..209b3ea7 --- /dev/null +++ b/lib/ldpc/modify.html @@ -0,0 +1,125 @@ + + + Notes on Modifying the LDPC Programs + + + + +

Notes on Modifying the LDPC Programs

+ +

Here are a few notes on how to modify the programs to add new types of +channel, new decoding procedures, etc. You should also look at the module documentation. + +

Adding a new type of channel

+ +

Channels are involved in two programs: +transmit and +decode. +Adding another type of memoryless channel should be straightforward. +Adding a channel with memory may involve more work. Here are the +steps needed if no major reorganizations are required: +

    +
  1. Decide on a syntax for specifying the new channel type and its + parameters, and on an internal name for the channel type. Add + the internal name as a possibility in the enumerated channel_type + declared in channel.h. You + may also need to declare new global variables to store parameters of + the channel in channel.h and + channel.c. +
  2. Modify the channel_parse and + channel_usage procedures in + channel.c to + parse the specification of the new channel and display an appropriate + usage message. +
  3. Decide on how the new channel's output is represented in a file + (eg, for an erasure channel, what the symbol for an erasure is), and + update transmit.c to write the + new channel's output for each transmitted bit, after randomly generating + any noise (see + the documentation on random number generation). +
  4. Modify decode.c in three places to + accommodate the new channel. The three sections of code to modify + allocate space for data from the channel, read data from the channel, + and set likelihood ratios based on the data read. The setting of + likelihood ratios is based on the assumption that the channel is + memoryless (ie, data received for different bits is independent). + Adding a channel with memory would require changing this assumption, + which would involve modifications to the decoding procedures too. +
  5. Document the new channel type in channel.html + and decoding.html. +
+ +

Adding a new decoding procedure

+ +A new decoding method can be implemented as follows: +
    +
  1. Decide on a syntax for specifying the method and its parameters, + using the trailing arguments to the + decode program. Pick an + internal name for the method, and add it as a possibility in the + enumerated decoding_method type in + dec.h. You may also need to declare + new variables for the method's parameters in + dec.h and dec.c. +
  2. Modify the argument parsing code in + decode.c + to handle specifications of the new method, and change the usage + procedure to display the syntax for specifying the new method. +
  3. Write a setup procedure for your decoding method, putting it in + dec.c, with a declaration in + dec.h. At a minimum, this procedure + should print headers for the table of detailed decoding information + when the -T option was specified. +
  4. Write a decode procedure implementing your method, putting it in + dec.c, with a declaration in + dec.h. This procedure should output + detailed trace information when the -T option was specified. +
  5. Modify decode.c in the appropriate + places to call the setup procedure and the decode procedure you wrote. +
  6. Document the new decoding method in + decoding.html and + decode-detail.html. +
+ +

Adding a new method of making a low-density parity-check matrix

+ +

The make-ldpc program can be +changed to add a new method for generating a LDPC code by modifying +make-ldpc.c. A radically different +method might better be implemented by writing a new program of similar +structure. + + +

Adding a new encoding method

+ +

A new heuristic for finding a sparse LU decomposition can be +implemented by changing make-gen.c to allow +the new heuristic to be specified on the command line, changing the mod2sparse_decomp procedure +in mod2sparse.c to implement the +heuristic, and documenting the new heuristic in encoding.html, sparse-LU.html, and mod2sparse.html. + +

To implement a completely new encoding method, you will first need +to define a new file format for a generator matrix, modify make-gen.c appropriately to write out this new +format, and modify the read_gen procedure in rcode.c to read this format. You will +need to implement the new method in a procedure in enc.c, and modify encode.c so +that it will call this new procedure when the new method is used. The +enum_decode procedure in dec.c will also +need to be modified so it can call the new encoding method. Finally, +you should document the new method in encoding.html + +

+ +


+ +Back to index for LDPC software + + diff --git a/lib/ldpc/modules.html b/lib/ldpc/modules.html new file mode 100755 index 00000000..93228ffe --- /dev/null +++ b/lib/ldpc/modules.html @@ -0,0 +1,89 @@ + + + Modules Used in LDPC Programs + + + + +

Modules Used in LDPC Programs

+ +You may need to familiarize yourself with the modules documented here +in order to modify the LDPC programs. +These modules may also be useful for other purposes. + +

Click on the title of a module below for general information, or on +specific routines for detailed documentation. + +

Dense modulo-2 matrix routines: +

+Dimension macros:    mod2dense_rows  mod2dense_cols
+
+Allocation:          Copy/Clear:         Input/Output:    Elementary ops:
+
+mod2dense_allocate   mod2dense_clear     mod2dense_print  mod2dense_get
+mod2dense_free       mod2dense_copy      mod2dense_write  mod2dense_set
+                     mod2dense_copyrows  mod2dense_read   mod2dense_flip
+                     mod2dense_copycols
+
+Matrix arithmetic:   Matrix inversion:
+
+mod2dense_transpose  mod2dense_invert
+mod2dense_add        mod2dense_forcibly_invert
+mod2dense_multiply   mod2dense_invert_selected
+mod2dense_equal
+
+ +

Sparse modulo-2 matrix routines: +

+Dimension macros:    mod2sparse_rows  mod2sparse_cols
+
+Traversal macros:    mod2sparse_first_in_row  mod2sparse_next_in_row  ...
+
+Allocation:          Copy/Clear:         Input/Output:     Elementary ops:
+
+mod2sparse_allocate  mod2sparse_clear    mod2sparse_print  mod2sparse_find
+mod2sparse_free      mod2sparse_copy     mod2sparse_write  mod2sparse_insert
+                     mod2sparse_copyrows mod2sparse_read   mod2sparse_delete
+                     mod2sparse_copycols
+
+Matrix arithmetic:   Row/Column ops:       LU decomposition:
+
+mod2sparse_transpose mod2sparse_count_row  mod2sparse_decomp
+mod2sparse_add       mod2sparse_count_col  mod2sparse_forward_sub
+mod2sparse_multiply  mod2sparse_add_row    mod2sparse_backward_sub
+mod2sparse_mulvec    mod2sparse_add_col
+mod2sparse_equal
+
+Discussion of sparse LU decomposition methods. +
+ +

Modulo-2 matrix sparse/dense conversion: +

+mod2sparse_to_dense
+mod2dense_to_sparse
+
+ +

Random variate generation routines: +

+Set/Get state:   Uniform:       Discrete:         Continuous:
+
+rand_seed        rand_uniform   rand_int          rand_gaussian
+rand_get_state   rand_uniopen   rand_pickd        rand_logistic
+rand_use_state                  rand_pickf        rand_cauchy
+                                rand_poisson      rand_gamma
+                                rand_permutation  rand_exp
+                                                  rand_beta
+
+ +

Each of the modules above has a test program, called +module-test. These programs are compiled by the command +

+make tests 
+
+See the source files for these test programs for further information. + +
+ +Back to index for LDPC software + + diff --git a/lib/ldpc/msksim.f90 b/lib/ldpc/msksim.f90 new file mode 100644 index 00000000..6ef50de5 --- /dev/null +++ b/lib/ldpc/msksim.f90 @@ -0,0 +1,76 @@ +program msksim + +use, intrinsic :: iso_c_binding + +! To change to a new code, edit the following line and the filenames +! that contain the parity check and generator matrices. +parameter (N=198, M=126, K=72) ! M and N are global variables on the C side. + +character(50) pchk_file,gen_file +integer(1) codeword(1:N), decoded(1:K), message(1:K) +real*8 lratio(N), rxdata(N) + +pchk_file="./jtmode_codes/peg-198-72-irreg-8x3-2x4.pchk" +gen_file="./jtmode_codes/peg-198-72-irreg-8x3-2x4.gen" + +rate=real(K)/real(N) + +call init_ldpc(trim(pchk_file)//char(0),trim(gen_file)//char(0)) + +message(1:K/2)=1 +message((K/2+1):K)=0 +call ldpc_encode(message,codeword) + +max_iterations=50 +ntrials=1000000 + +write(*,*) "Eb/N0 ngood nundetected" +do idb = 0, 11 + db=idb/2.0-0.5 + sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) + + ngood=0 + nue=0 + + do itrial=1, ntrials + + do i=1,N + rxdata(i) = 2.0*(codeword(i)-0.5) + sigma*gran() + enddo + +! 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 + +! s can be tuned to trade a few tenth's dB of threshold +! for an order of magnitude in UER + do i=1,N + s=0.75 + lratio(i)=exp(2.0*rxdata(i)/(s*s)) + enddo + + call ldpc_decode(lratio, decoded, max_iterations, niterations) + + if( niterations .ge. 0 ) then + nueflag=0 + do i=1,K + if( message(i) .ne. decoded(i) ) then + nueflag=1 + endif + enddo + if( nueflag .eq. 1 ) then + nue=nue+1 + else + ngood=ngood+1; + endif + endif + + enddo + + write(*,"(f4.1,1x,i8,1x,i8)") db,ngood,nue + +enddo + +end program msksim diff --git a/lib/ldpc/open.c b/lib/ldpc/open.c new file mode 100755 index 00000000..8e850681 --- /dev/null +++ b/lib/ldpc/open.c @@ -0,0 +1,50 @@ +/* OPEN.C - Routine for opening file that might be stdin/stdout. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include + +#include "open.h" + + +/* OPEN A FILE THAT MIGHT BE STANDARD INPUT OR OUTPUT. If the file name + given is "-", this procedure just returns stdin or stdout, depending on + whether the mode is for reading or writing. Otherwise, fopen is called. +*/ + +FILE *open_file_std +( char *fname, /* Name of file to open, or "-" for stdin/stdout */ + char *mode /* Mode for opening: eg, "r" or "w" */ +) +{ + if (strcmp(fname,"-")==0) + { switch (mode[0]) + { case 'r': + { return stdin; + } + case 'w': + { return stdout; + } + default: + { fprintf(stderr,"Bad mode passed to open_file_std: %s\n",mode); + exit(1); + } + } + } + else + { return fopen(fname,mode); + } +} diff --git a/lib/ldpc/open.h b/lib/ldpc/open.h new file mode 100755 index 00000000..2cb88b26 --- /dev/null +++ b/lib/ldpc/open.h @@ -0,0 +1,16 @@ +/* OPEN.H - Interface to routine for opening file that might be stdin/stdout. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +FILE *open_file_std (char *, char *); diff --git a/lib/ldpc/pchk-to-alist.c b/lib/ldpc/pchk-to-alist.c new file mode 100755 index 00000000..9670105a --- /dev/null +++ b/lib/ldpc/pchk-to-alist.c @@ -0,0 +1,166 @@ +/* ALIST-TO-PCHK.C - Convert a parity check matrix to alist format. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include +#include + +#include "alloc.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" + + +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + char *alist_file, *pchk_file; + FILE *af, *pf; + int mxrw, mxcw; + int *rw, *cw; + int i, j, k; + mod2entry *e; + int trans; + int nozeros; + int last; + + trans = 0; + nozeros = 0; + + for (;;) + { + if (argc>1 && strcmp(argv[1],"-t")==0) + { trans = 1; + argc -= 1; + argv += 1; + } + else if (argc>1 && strcmp(argv[1],"-z")==0) + { nozeros = 1; + argc -= 1; + argv += 1; + } + else + { break; + } + } + + if (argc!=3) + { usage(); + } + + pchk_file = argv[1]; + alist_file = argv[2]; + + read_pchk(pchk_file); + + if (trans) + { mod2sparse *HT; + HT = H; + H = mod2sparse_allocate(N,M); + mod2sparse_transpose(HT,H); + M = mod2sparse_rows(H); + N = mod2sparse_cols(H); + } + + af = open_file_std(alist_file,"wb"); + + if (af==NULL) + { fprintf(stderr,"Can't create alist file: %s\n",alist_file); + exit(1); + } + + fprintf(af,"%d %d\n",M,N); + + rw = (int *) chk_alloc (M, sizeof *rw); + mxrw = 0; + + for (i = 0; imxrw) + { mxrw = rw[i]; + } + } + + cw = (int *) chk_alloc (N, sizeof *cw); + mxcw = 0; + + for (j = 0; jmxcw) + { mxcw = cw[j]; + } + } + + fprintf(af,"%d %d\n",mxrw,mxcw); + + for (i = 0; i + + Creating a Parity Check Matrix + + + + +

Creating a Parity Check Matrix

+ +

This software deals only with linear block codes for binary (ie, +modulo-2, GF(2)) vectors. The set of valid codewords for a linear +code can be specified by giving a parity check matrix, +H, with M rows and N columns. The valid +codewords are the vectors, x, of length N, for which +Hx=0, where all arithmetic is done modulo-2. Each row +of H represents a parity check on a subset of the bits in +x; all these parity checks must be satisfied for x to be +a codeword. Note that the parity check matrix for a given code (ie, +for a given set of valid codewords) is not unique, even after +eliminating rows of H that are redundant because they are +linear combinations of other rows. + +

This software stores parity check matrices in files in a sparse +format. These parity-check files are not human-readable +(except by using the print-pchk +program). However, they are readable on a machine with a +different architecture than they were written on. + +

Some LDPC software by David MacKay and others uses the +alist +format for parity check matrices. Two programs for converting +between this format and the format for sparse parity check matrices +used by this software are provided. + + +

Methods for constructing LDPC codes

+ +

This software is primarily intended for experimentation with Low +Density Parity Check (LDPC) codes. These codes can be constructed by +various methods, which generally involve some random selection of +where to put 1s in a parity check matrix. Any such method for +constructing LDPC codes will have the property that it produces parity +check matrices in which the number of 1s in a column is approximately +the same (perhaps on average) for any size parity check matrix. For a +given code rate, these matrices therefore become increasingly sparse +as the length of a codeword, and hence the number of parity checks, +increases. + +

Many methods for constructing LDPC matrices are described in the +references. Two simple methods are currently +implemented by this software, both of which operate according to the +following scheme: +

    +
  1. Create a preliminary parity check matrix by one of the methods. +
  2. Add 1s to the parity check matrix in order to avoid rows that have no + 1s in them, and hence are redundant, or which have only one 1 in them, + in which case the corresponding codeword bits will always be zero. + The places within such a row to add these 1s are selected randomly. +
  3. If the preliminary parity check matrix constructed in step (1) had + an even number of 1s in each column, add further 1s to avoid the problem + that this will cause the rows to add to zero, and hence at least + one check will be redundant. Up to two 1s are added (since it is also + undesirable for the sum of the rows to have only one 1 in it), at + positions selected randomly from the entire matrix. However, the + number of 1s to add in this step is reduced by the number already added + in step (2). (Note that although redundant checks are not disastrous, + they are better avoided; see the discussion of linear + dependence in parity check matrices.) +
  4. If requested, try to eliminate + situations where a pair of columns both have 1s in a particular pair of + rows, which correspond to cycles of length four in the factor graph of + the parity check matrix. When such a situation is detected, one of the + 1s involved is moved randomly within its column. This continues until + no such situations remain, or until 10 passes over all columns have + failed to eliminate all such situations. +
+ +

The evencol method is the simplest way of performing step +(1) of the above procedure. For each column of the parity check +matrix, independently, it places a specified number of 1s in positions +selected uniformly at random, with the only constraint being that +these 1s be in distinct rows. Note that despite the name, the columns +do not have to have the same number of 1s - a distribution over +several values for the number of 1s in a column can be specified +instead. Such codes with different-weight columns are sometimes +better than codes in which every column has the same weight. + +

The evenboth method also puts a specified number of 1s in +each column, but it tries as well to keep the numbers of 1s in the +rows approximately the same. Initially, it creates indicators for all +the 1s that will be required, and assigns these 1s to rows as evenly +as it can, favouring earlier rows if an exactly even split is not +possible. It then assigns 1s to successive columns by selecting +randomly, without replacement, from this initial supply of 1s, subject +only to the constraint that the 1s assigned to a column must be in +distinct rows. If at some point it is impossible to put the required +number of 1s in a column by picking from the 1s remaining, a 1 is set +in that column without reference to other columns, creating a possible +unevenness. + +

Note that regardless of how evenly 1s are distributed in the +preliminary parity check matrix created in step (1), steps (2) and (3) +can make the numbers of 1s in the both rows and columns be uneven, and +step (4), if done, can make the numbers of 1s in rows be uneven. + + +


make-pchk: Make a parity check +matrix by explicit specification. + +
+make-pchk pchk-file n-checks n-bits row:col ...
+
+ +

Creates a file named pchk-file in +which it stores a parity check matrix with n-checks +rows and n-bits columns. This parity check matrix +consists of all 0s except for 1s at the row:col +positions listed. Rows and columns are numbered starting at zero. +This program is intended primarily for testing and demonstration +purposes. + +

Example: The well-known Hamming code with codewords of +length N=7 and with M=3 parity checks can be can be +created as follows: +

    +
  • make-pchk ham7.pchk 3 7 0:0 0:3 0:4 0:5 1:1 1:3 1:4 1:6 2:2 2:4 2:5 2:6 +
+ + +


alist-to-pchk: Convert a parity +check matrix from alist format to the sparse matrix format used by +this software. + +
+alist-to-pchk [ -t ] alist-file pchk-file
+
+ +

Converts a parity check matrix in +alist +format stored in the file named alist-file to +the sparse matrix format used by this software, storing it in the +file named pchk-file. + +

If the -t option is given, the transpose of the parity check +matrix in alist-file is stored in the +pchk-file. + +

Any zeros indexes in the alist file are ignored, so that alist files +with zero padding (as required in the specification) are accepted, +but files without this zero padding are also accepted. Newlines +are ignored by alist-to-pchk, so no error is reported if +the set of indexes in a row or column description are not those +on a single line. + + +


pchk-to-alist: Convert a parity +check matrix to alist format. + +
+pchk-to-alist [ -t ] [ -z ] pchk-file alist-file
+
+ +

Converts a parity check matrix stored in the sparse matrix format +used by this software, in the file named pchk-file, to +the alist +format, storing it in the file named alist-file. + +

If the -t option is given, the transpose of the parity check +matrix is converted to alist format. + +

If the number of 1s is not +the same for each row or each column, the alist format specification +says that the list of indexes of 1s for each row or column should +be padded with zeros to the maximum number of indexes. By default, +pchk-to-alist does this, but output of these 0s can be +suppressed by specifying the -z option. (The alist-to-pchk +program will accept alist files produced with or without the -z +option.) + + +


print-pchk: Print a parity check matrix. + +
+print-pchk [ -d ] [ -t ] pchk-file
+
+ +

Prints a human-readable representation of the parity check matrix stored +in pchk-file. +The -d option causes the matrix to be printed in a dense +format, even though parity check matrices are always stored in the +file in a sparse format. If the -t option is present, what is +printed is the transpose of the parity check matrix. + +

The sparse display format consists of one line for every row of the +matrix, consisting of the row number, a colon, and the column numbers +at which 1s are located (possibly none). Row and columns numbers +start at zero. No attempt is made to wrap long lines. + +

The dense display is the obvious array of 0s and 1s. Long lines +are not wrapped. + +

Example: The parity check matrix for the Hamming code created +by the example for make-pchk would print +as follows: +

    +
  • print-pchk ham7.pchk + +Parity check matrix in ham7.pchk (sparse format): + +0: 0 3 4 5 +1: 1 3 4 6 +2: 2 4 5 6 + +
  • print-pchk -d ham7.pchk + +Parity check matrix in ham7.pchk (dense format): + + 1 0 0 1 1 1 0 + 0 1 0 1 1 0 1 + 0 0 1 0 1 1 1 +
+ + +


make-ldpc: Make a low density parity +check matrix, by random generation. + +
+make-ldpc pchk-file n-checks n-bits seed method
+
+
+where method is one of the following: +
+evencol checks-per-col [ no4cycle ]
+
+evencol checks-distribution [ no4cycle ]
+
+evenboth checks-per-col [ no4cycle ]
+
+evenboth checks-distribution [ no4cycle ]
+
+
+
+ +

Creates a Low Density Parity Check matrix with +n-checks rows and n-bits columns. The +parity check matrix will be generated pseudo-randomly by the indicated +method, using a pseudo-random number stream determined by seed. +The actual random number seed used is 10 times seed plus 1, +so as to avoid using the same stream as any of the other programs. + +

Two methods are currently available for creating the LDPC matrix, +specified by evencol or evenboth. Both methods +produce a matrix in which the number of 1s in each column is +approximately checks-per-col, or varies from column +to column according the the checks-distribution. +The evenboth method also tries to make the number of checks per row be +approximately uniform; if this is not achieved, a message saying that +how many bits were placed unevenly is displayed on standard error. + +

For both methods, the no4cycle option will cause cycles of +length four in the factor graph representation of the code to be +eliminated (if possible). A message is displayed on standard error if +this is not achieved. + +

A checks-distribution has the form +

+propxcount/propxcount/...
+
+Here, prop is a proportion of columns that have the +associated count. The proportions need not sum to one, +since they will be automatically normalized. For example, 0.3x4/0.2x5 +specifies that 60% of the columns will contain four 1s and 40% will +contain five 1s. + +

See the discussion above for more details +on how these methods construct LDPC matrices. + +

Example 1: The make-ldpc command below creates +a 20 by 40 low density parity check matrix with three 1s per +column and six 1s per row, using random seed 1. The matrix +is then printed in sparse format +using print-pchk. +

    +
  • make-ldpc ldpc.pchk 20 40 1 evenboth 3 +
  • print-pchk ldpc.pchk + +Parity check matrix in ldpc.pchk (sparse format): + + 0: 10 14 18 27 38 39 + 1: 2 3 5 11 27 30 + 2: 15 19 20 21 24 26 + 3: 2 4 25 28 32 38 + 4: 7 9 12 22 33 34 + 5: 5 6 21 22 26 32 + 6: 1 4 13 24 25 28 + 7: 1 14 28 29 30 36 + 8: 11 13 22 23 32 37 + 9: 6 8 13 20 31 33 +10: 0 3 24 29 31 38 +11: 7 12 15 16 17 23 +12: 3 16 29 34 35 39 +13: 0 8 10 18 36 37 +14: 6 11 18 20 35 39 +15: 0 7 14 16 25 37 +16: 2 4 9 19 30 31 +17: 5 9 10 17 19 23 +18: 8 15 17 21 26 27 +19: 1 12 33 34 35 36 +
+ +

Example 2: The two make-ldpc commands +below both create a 20 by 40 low density parity check matrix with 30% +of columns with two 1s, 60% of columns with three 1s, and 10% of +columns with seven 1s. The transpose of the parity check matrix +is then printed in sparse format. +

    +
  • make-ldpc ldpc.pchk 20 40 1 evenboth 0.3x2/0.6x3/0.1x7 +
  • make-ldpc ldpc.pchk 20 40 1 evenboth 3x2/6x3/1x7 +
  • print-pchk -t ldpc.pchk + +Transpose of parity check matrix in ldpc.pchk (sparse format): + + 0: 13 16 + 1: 9 18 + 2: 1 10 + 3: 3 15 + 4: 4 14 + 5: 14 17 + 6: 4 5 + 7: 1 8 + 8: 0 4 + 9: 9 14 +10: 5 8 +11: 6 16 +12: 2 12 19 +13: 3 17 18 +14: 2 16 17 +15: 2 11 18 +16: 12 13 19 +17: 7 13 18 +18: 2 5 11 +19: 10 12 14 +20: 1 8 16 +21: 10 18 19 +22: 3 6 17 +23: 7 11 12 +24: 1 2 19 +25: 0 6 7 +26: 5 8 15 +27: 1 4 7 +28: 6 13 19 +29: 3 4 11 +30: 3 8 17 +31: 4 5 9 +32: 0 10 15 +33: 7 11 13 +34: 8 12 19 +35: 0 2 10 +36: 0 5 9 11 15 17 18 +37: 0 1 2 6 7 14 16 +38: 0 1 3 9 12 13 15 +39: 3 6 9 10 14 15 16 +
+ +
+ +Back to index for LDPC software + + + diff --git a/lib/ldpc/peg/128-64-reg4.deg b/lib/ldpc/peg/128-64-reg4.deg new file mode 100644 index 00000000..7b72d067 --- /dev/null +++ b/lib/ldpc/peg/128-64-reg4.deg @@ -0,0 +1,4 @@ +1 +4 +1.0 + diff --git a/lib/ldpc/peg/BigGirth.C b/lib/ldpc/peg/BigGirth.C new file mode 100644 index 00000000..ad8b54a1 --- /dev/null +++ b/lib/ldpc/peg/BigGirth.C @@ -0,0 +1,573 @@ +#include +#include +#include +#include +#include "BigGirth.h" +#include "Random.h" + +using namespace std; + +NodesInGraph::NodesInGraph(void) { + connectionParityBit=NULL; + connectionSymbolBit=NULL; +} + +void NodesInGraph::setNumOfConnectionSymbolBit(int deg) { + if(deg<=0) {cout<<"Wrong NodesInGraph::setNumOfConnectionSymbolBit()"<M=M; + this->N=N; + this->filename=filename; + + mid=new int[M]; + + localGirth=new int[N]; + + nodesInGraph=new NodesInGraph [N]; + for(i=0;ilocalDepth)?localDepth:localGirth[k]; + if(k>0 && localGirth[k]=nodesInGraph[i].maxDegParity) + index++; + } + if(cpNumCur==numCur) {//can not expand any more + //additional handlement to select one having least connections + j=10000000; //dummy number + for(i=0;i=nodesInGraph[i].maxDegParity){ + tmp[i]=1; + } + } + } + index=0; + for(i=0;iEXPAND_DEPTH){//covering all parity nodes or meet the upper bound on cycles + + cycle=mincycles-1; + for(i=0;i=nodesInGraph[i].maxDegParity){ + tmp[i]=1; + } + } + } + + index=0; + for(i=0;inumCur && index!=M){ + delete [] current; + current=NULL; + numCur=cpNumCur; + current=new int[numCur]; + index=0; + for(i=0;imax_col) + max_col=nodesInGraph[i].numOfConnectionParityBit; + + parityCheck_compressed=new int * [M]; + for(i=0;i0;k--){ + for(i=k-1;i>=0;i--){ + if(H[i][k]==1) + for(j=k;jmax_row) max_row=imed; + } + generator_compressed=new int * [max_row]; + for(i=0;i=max_row-1) break; + index++; + } + } + } + for(j=0;jmax_col) max_col=imed; + } + parityCheck_compressed=new int * [M]; + for(i=0;i=max_col-1) break; + index++; + } + } + } + if(verbose) { + cout<<"****************************************************"< +#include // C++ I/O library header +#include "Random.h" + +class NodesInGraph{ + public: + int numOfConnectionParityBit; + int *connectionParityBit; + int numOfConnectionSymbolBit; + int *connectionSymbolBit; + int maxDegParity; + + NodesInGraph(void); + ~NodesInGraph(void); + void setNumOfConnectionSymbolBit(int deg); + void initConnectionParityBit(void); + void initConnectionParityBit(int deg); +}; + +class BigGirth { + public: + int M, N; + int K; + int EXPAND_DEPTH; + const char *filename; + int *(*H); + + int *localGirth; + + NodesInGraph *nodesInGraph; + Random *myrandom; + + BigGirth(int m, int n, int *symbolDegSequence, const char *filename, int sglConcent, int tgtGirth, bool verbose_ = true); + BigGirth(void); + + void writeToFile_Hcompressed(void); + void writeToFile_Hmatrix(void); + void writeToFile(void); + + void loadH(void); + + ~BigGirth(void); + + private: + int selectParityConnect(int kthSymbol, int mthConnection, int & cycle); + void updateConnection(int kthSymbol); + bool verbose; + +}; + +#endif diff --git a/lib/ldpc/peg/CodeName b/lib/ldpc/peg/CodeName new file mode 100644 index 00000000..118a6382 --- /dev/null +++ b/lib/ldpc/peg/CodeName @@ -0,0 +1,68 @@ +64 +16 +48 +14 +5 +3 1 3 6 1 4 1 1 1 1 2 1 1 1 1 6 6 2 2 1 1 2 2 1 2 6 2 6 1 1 2 1 1 6 3 2 6 2 1 1 6 1 1 2 1 1 1 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 +4 2 4 9 3 6 2 2 3 2 4 2 3 3 3 7 9 6 4 3 2 6 6 2 4 9 6 7 2 2 4 3 3 7 4 4 7 4 3 3 7 2 2 6 3 2 2 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +6 3 6 10 4 9 4 4 4 4 5 4 4 4 4 8 10 8 5 4 3 7 7 4 6 13 9 9 4 4 5 4 4 8 6 5 8 5 4 4 9 4 4 8 4 3 4 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +7 4 12 12 6 12 5 5 6 5 6 5 5 6 6 9 11 9 6 5 4 11 9 5 7 0 10 10 5 5 6 6 5 9 8 6 11 6 5 5 11 5 5 9 6 4 5 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +9 5 16 15 9 15 6 6 7 6 7 6 6 9 7 10 12 11 8 6 5 13 13 6 8 0 11 11 6 6 9 8 6 11 11 8 12 7 6 6 13 6 6 12 10 5 6 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +10 6 0 16 11 16 8 7 9 8 8 7 7 12 8 11 13 13 9 11 6 14 14 8 9 0 13 12 8 9 11 9 7 12 12 10 13 8 8 7 0 8 7 15 12 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +13 8 0 0 13 0 10 8 13 9 10 10 9 13 9 12 14 15 11 13 7 16 16 9 13 0 15 13 10 11 16 11 11 13 16 12 14 9 11 10 0 9 11 0 13 12 9 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +15 12 0 0 14 0 11 10 15 11 12 11 10 15 11 13 15 0 13 14 12 0 0 12 14 0 0 14 14 13 0 14 13 0 0 15 0 11 12 13 0 10 12 0 15 13 10 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 13 0 0 15 0 12 12 16 12 14 14 14 16 14 14 0 0 15 15 14 0 0 13 0 0 0 15 15 15 0 15 14 0 0 16 0 13 13 14 0 12 14 0 16 14 11 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 15 0 0 16 0 14 14 0 13 15 0 16 0 16 16 0 0 16 16 15 0 0 14 0 0 0 16 0 16 0 16 16 0 0 0 0 14 15 16 0 14 15 0 0 15 12 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 16 0 0 0 0 15 15 0 15 16 0 0 0 0 0 0 0 0 0 16 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 15 16 0 0 15 0 0 0 16 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 16 0 0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 0 0 0 0 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 9 49 58 64 +2 39 50 59 0 +3 6 51 57 63 +4 6 52 58 0 +5 20 53 57 0 +4 37 48 60 0 +7 36 49 59 62 +8 29 55 60 0 +9 14 55 60 0 +10 30 56 60 0 +11 31 48 61 64 +12 24 48 62 0 +13 40 57 61 0 +1 35 48 62 0 +15 32 55 63 0 +16 28 56 63 0 +17 28 55 64 0 +18 27 56 58 0 +19 31 56 61 63 +5 32 56 61 0 +21 43 51 59 64 +22 23 57 59 0 +22 44 48 58 0 +12 43 58 60 63 +25 38 53 59 63 +26 41 55 59 0 +18 44 59 60 61 +17 27 50 60 62 +29 42 57 60 64 +8 30 48 63 0 +19 38 55 62 64 +15 45 48 64 0 +20 33 55 63 0 +34 41 56 60 0 +14 45 57 58 0 +11 36 55 62 0 +34 37 57 62 0 +7 47 57 61 0 +2 46 56 62 0 +33 40 58 59 0 +3 35 56 59 0 +10 47 58 62 0 +21 46 55 61 0 +23 25 52 56 64 +13 39 48 64 0 +26 54 57 61 0 +24 42 58 61 0 +16 48 54 63 0 +49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 diff --git a/lib/ldpc/peg/CyclesOfGraph.C b/lib/ldpc/peg/CyclesOfGraph.C new file mode 100644 index 00000000..77c98b59 --- /dev/null +++ b/lib/ldpc/peg/CyclesOfGraph.C @@ -0,0 +1,237 @@ +#include "CyclesOfGraph.h" + +NodesOfGraph::NodesOfGraph(void) { parityConnections=NULL;symbolConnections=NULL; +} +NodesOfGraph::~NodesOfGraph(void) { + delete [] parityConnections; + delete [] symbolConnections; + delete [] symbolMapping; + +} + +void NodesOfGraph::setParityConnections(int num, int *value) { + numOfParityConnections=num; + parityConnections=new int[num]; + for(int i=0;itmpCycles[j]) + cyclesTable[i]=tmpCycles[j]; + } + //OUTPUT cycles per symbol node + //cout<<"i="<cyclesTable[i]) girth=cyclesTable[i]; + return(girth); +} + +void CyclesOfGraph::printCyclesTable(void){ + using namespace std; + int i, temp[20]; + /* + for(i=0;i +#include // C++ I/O library header +//#include + +class NodesOfGraph{ + public: + int numOfParityConnections; + int *parityConnections; + int numOfSymbolConnections; + int *symbolConnections; + int numOfSymbolMapping; + int *symbolMapping; + NodesOfGraph(void); + ~NodesOfGraph(void); + void setParityConnections(int num, int *value); + void setSymbolConnections(int num, int *value); + void setSymbolMapping(int num, int *values); +}; //Why this is necessary? + +class CyclesOfGraph { + public: + int M, N; + int *(*H); + int *cyclesTable; + NodesOfGraph *nodesOfGraph; + CyclesOfGraph(int mm, int n, int *(*h)); + ~CyclesOfGraph(void); + void getCyclesTable(void); + void printCyclesTable(void); + int girth(void); + private: + int *tmp, *med, *tmpCycles; +}; + +#endif + + diff --git a/lib/ldpc/peg/DenEvl_11.deg b/lib/ldpc/peg/DenEvl_11.deg new file mode 100644 index 00000000..18a77197 --- /dev/null +++ b/lib/ldpc/peg/DenEvl_11.deg @@ -0,0 +1,3 @@ +4 + 2 3 4 11 +0.450013 0.370771 0.0307238 0.1484922 diff --git a/lib/ldpc/peg/DenEvl_15.deg b/lib/ldpc/peg/DenEvl_15.deg new file mode 100644 index 00000000..3af8369d --- /dev/null +++ b/lib/ldpc/peg/DenEvl_15.deg @@ -0,0 +1,3 @@ +7 +2 3 4 5 7 14 15 +0.477081 0.280572 0.0349963 0.0963301 0.0090884 0.00137443 0.10055777 diff --git a/lib/ldpc/peg/DenEvl_20.deg b/lib/ldpc/peg/DenEvl_20.deg new file mode 100644 index 00000000..174d6465 --- /dev/null +++ b/lib/ldpc/peg/DenEvl_20.deg @@ -0,0 +1,4 @@ +9 +2 3 4 6 7 8 9 19 20 +0.457827 0.323775 0.0214226 0.0592851 0.0389015 0.0248109 0.00884569 +0.0176697 0.04746251 diff --git a/lib/ldpc/peg/DenEvl_7.deg b/lib/ldpc/peg/DenEvl_7.deg new file mode 100644 index 00000000..feb53aee --- /dev/null +++ b/lib/ldpc/peg/DenEvl_7.deg @@ -0,0 +1,3 @@ +3 + 2 3 7 +0.521814 0.271293 0.206893 diff --git a/lib/ldpc/peg/DenEvl_9.deg b/lib/ldpc/peg/DenEvl_9.deg new file mode 100644 index 00000000..3072b205 --- /dev/null +++ b/lib/ldpc/peg/DenEvl_9.deg @@ -0,0 +1,3 @@ +3 + 2 3 9 +0.491281 0.335305 0.173414 diff --git a/lib/ldpc/peg/MainPEG.C b/lib/ldpc/peg/MainPEG.C new file mode 100644 index 00000000..18600139 --- /dev/null +++ b/lib/ldpc/peg/MainPEG.C @@ -0,0 +1,200 @@ +/************************************************************************/ +/* */ +/* Free software: Progressive edge-growth (PEG) algorithm */ +/* Created by Xiaoyu Hu */ +/* Evangelos Eletheriou */ +/* Dieter Arnold */ +/* IBM Research, Zurich Research Lab., Switzerland */ +/* */ +/* The C++ sources files have been compiled using xlC compiler */ +/* at IBM RS/6000 running AIX. For other compilers and platforms,*/ +/* minor changes might be needed. */ +/* */ +/* Bug reporting to: xhu@zurich.ibm.com */ +/**********************************************************************/ + +//// +// Modified by F. P. Beekhof; 2008 / 08 / 19 +//// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "BigGirth.h" +#include "Random.h" +#include "CyclesOfGraph.h" + +const double EPS = 1e-6; + +using namespace std; + +void usage() +{ + cout<<"*******************************************************************************************"< " <= argc) usage(); + M=atoi(argv[i]); + } else if(strcmp(argv[i], "-numN")==0) { + if (++i >= argc) usage(); + N=atoi(argv[i]); + } else if(strcmp(argv[i], "-codeName")==0) { + if (++i >= argc) usage(); + codeName = argv[i]; + } else if(strcmp(argv[i], "-degFileName")==0) { + if (++i >= argc) usage(); + degFileName = argv[i]; + } else if(strcmp(argv[i], "-sglConcent")==0) { + if (++i >= argc) usage(); + sglConcent=atoi(argv[i]); + } else if(strcmp(argv[i], "-tgtGirth")==0) { + if (++i >= argc) usage(); + targetGirth=atoi(argv[i]); + } else if(strcmp(argv[i], "-outputMode")==0) { + if (++i >= argc) usage(); + output_mode=atoi(argv[i]); + } else if(strcmp(argv[i], "-q")==0) { + verbose=false; + } else{ + usage(); + } + } + if (M == -1 || N == -1) { + cout<<"Error: M or N not specified!"<N) { + cout<<"Error: M must be smaller than N!"< degSeq(N); + + ifstream infn(degFileName.c_str()); + if (!infn) {cout << "\nCannot open file " << degFileName << endl; exit(-1); } + int m; + infn >>m; + std::vector deg(m); + std::vector degFrac(m); + for(int i=0;i>deg[i]; + for(int i=0;i>degFrac[i]; + infn.close(); + double dtmp=0.0; + for(int i=0;iEPS) { + cout.setf(ios::fixed, ios::floatfield); + cout <<"\n Invalid degree distribution (node perspective): sum != 1.0 but "<=0;--j) { + if(dtmp>degFrac[j]) break; + } + if(dtmp +# Thu May 12 12:38:41 SAST 2005 + +PROGRAM = MainPEG +OBJECTS = MainPEG.o Random.o CyclesOfGraph.o BigGirth.o + +CXX = g++ +CXXFLAGS = -g -ansi -pedantic -Wno-deprecated -Wall -O2 +#CXXFLAGS = -g -ansi -pedantic -Wall -march=native -ftree-vectorize -O3 + +.SUFFIXES: .o .C + +all: ${OBJECTS} + $(CXX) -o ${PROGRAM} ${OBJECTS} + +.C.o: $< + $(CXX) ${CXXFLAGS} -c $< -o $@ + +.PHONY : clean + +clean: + rm -f ${OBJECTS} ${PROGRAM} *~ *.log + diff --git a/lib/ldpc/peg/Random.C b/lib/ldpc/peg/Random.C new file mode 100644 index 00000000..3c5d5438 --- /dev/null +++ b/lib/ldpc/peg/Random.C @@ -0,0 +1,101 @@ + +#include +#include +#include "Random.h" + +void Random::bubbleSort(int a[], int size) +{ + for(int pass=1; passa[i+1]){ + std::swap(a[i], a[i+1]); + } + } +} + +double Random::gauss(double sdev, double mean) +{ + double sum=0.0; + for (int i=1;i<=12;++i) + { + seed_u = 1664525lu * seed_u + 123456789lu; + sum+=double(seed_u); + } + return (sum/4.29497e9-6.0)*sdev+mean; +} + +double Random::uniform(double a, double b) +{ + double t; + for(int i=0; i<10;i++){ + seed=2045*seed+1; + //seed=seed -(seed/1048576)*1048576; + seed%=1048576; + } + t=seed/1048576.0; + t=a+(b-a)*t; + return(t); +} + +int Random::uniform(int a, int b) // [a, b-1] +{ + double t; + int i, tt; + if(b==a+1) return(a); + for(i=0; i<10;i++){ + seed=2045*seed+1; + //seed=seed -(seed/1048576)*1048576; + seed%=1048576; + } + t=seed/1048576.0; + t=a+(b-a)*t; + tt=(int)t; + if(tt=b) tt=b-1; + return(tt); +} + +int Random::nonUniform(int a, int b) // [a, b-1] +{ + double t; + int i, tt; + if(b==a+1) return(a); + for(i=0; i<10;i++){ + seed=2045*seed+1; + //seed=seed -(seed/1048576)*1048576; + seed%=1048576; + } + t=seed/1048576.0; + t=a+(b-a)*pow(t, 0.6667); //t^1.5 + tt=(int)t; + if(tt=b) tt=b-1; + return(tt); +} + +/* +void m_uniform(int a , int b, long int *seed, int *itmp, int num) +{ + int index, imed, i, k; + + index=0; + itmp[0]=uniform(a, b, seed); + Loop1: + imed=uniform(a, b, seed); + k=0; + for(i=0;i<=index;i++) + if(imed==itmp[i]) {k=1; break;} + if(k==0) {index++; itmp[index]=imed;} + if(index +// #include + +class Random{ + private: + + unsigned long int seed; //previously LONG INT + unsigned long int seed_u; + + public: + + Random(void) { + this->seed=987654321u; + this->seed_u=123456789lu; + } + ~Random(void){;} + void bubbleSort(int a[], int size); + double gauss(double sdev, double mean); + double uniform(double a, double b); + int uniform(int a, int b); // [a, b) + int nonUniform(int a, int b); + +}; + +#endif diff --git a/lib/ldpc/peg/Reg_2.deg b/lib/ldpc/peg/Reg_2.deg new file mode 100644 index 00000000..28d2c8f1 --- /dev/null +++ b/lib/ldpc/peg/Reg_2.deg @@ -0,0 +1,3 @@ +1 +2 +1.0 diff --git a/lib/ldpc/peg/Reg_3.deg b/lib/ldpc/peg/Reg_3.deg new file mode 100644 index 00000000..0fb5a574 --- /dev/null +++ b/lib/ldpc/peg/Reg_3.deg @@ -0,0 +1,3 @@ +1 +3 +1.0 diff --git a/lib/ldpc/peg/Reg_4.deg b/lib/ldpc/peg/Reg_4.deg new file mode 100644 index 00000000..b42df500 --- /dev/null +++ b/lib/ldpc/peg/Reg_4.deg @@ -0,0 +1,3 @@ +1 +4 +1.0 diff --git a/lib/ldpc/peg/ldpc-peg-128-80.alist b/lib/ldpc/peg/ldpc-peg-128-80.alist new file mode 100644 index 00000000..a25da9a3 --- /dev/null +++ b/lib/ldpc/peg/ldpc-peg-128-80.alist @@ -0,0 +1,180 @@ +48 128 +9 4 +9 9 9 9 9 8 8 8 8 8 9 9 8 8 9 9 8 8 8 8 9 9 9 8 9 9 9 9 9 9 8 8 8 9 8 9 9 9 8 9 8 8 8 9 8 8 8 9 +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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 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 +1 17 34 51 66 81 99 111 124 +2 18 35 50 67 82 100 112 125 +3 19 36 52 68 82 101 111 126 +2 20 36 51 69 83 102 113 127 +4 19 37 53 66 84 103 114 128 +5 21 38 54 70 85 92 114 0 +6 22 39 55 66 85 96 110 0 +7 23 32 56 71 86 103 115 0 +8 20 40 55 72 86 104 116 0 +9 19 41 57 73 87 105 116 0 +10 24 36 56 74 88 105 117 125 +10 17 33 47 75 89 106 118 128 +11 21 42 51 76 87 107 119 0 +1 25 40 58 74 84 107 113 0 +12 22 42 49 77 90 108 118 125 +13 26 43 59 68 89 104 120 124 +13 22 44 57 75 91 109 113 0 +12 23 37 46 78 88 107 112 0 +3 27 34 60 65 87 109 118 0 +6 27 45 61 79 89 98 112 0 +14 28 34 62 72 92 106 112 127 +8 27 42 59 71 92 110 121 126 +15 20 46 57 79 93 101 115 124 +9 29 45 62 74 94 108 121 0 +8 30 38 63 73 95 109 111 128 +16 29 47 64 69 96 109 117 126 +16 23 48 63 76 94 110 116 125 +7 25 39 52 70 97 106 117 124 +4 26 45 63 67 83 90 119 123 +15 28 39 50 76 88 103 121 123 +15 26 33 58 65 97 102 122 0 +14 31 47 52 77 81 93 116 0 +14 24 37 61 71 82 99 122 0 +4 31 40 54 80 91 106 115 122 +5 32 41 58 77 98 104 117 0 +9 18 49 65 79 85 104 119 128 +10 30 43 60 69 84 108 115 123 +1 18 43 48 73 91 98 114 127 +3 21 46 64 67 86 108 113 0 +5 24 48 55 75 93 107 120 126 +2 32 44 62 80 95 99 114 0 +16 28 41 59 80 83 100 118 0 +11 33 35 53 72 96 105 111 0 +11 25 44 60 78 90 100 120 122 +6 31 35 56 70 95 102 121 0 +12 17 50 54 68 94 105 119 0 +13 29 38 53 78 97 110 123 0 +7 30 49 61 64 81 101 120 127 +1 14 38 0 +2 4 41 0 +3 19 39 0 +5 29 34 0 +6 35 40 0 +7 20 45 0 +8 28 48 0 +9 22 25 0 +10 24 36 0 +11 12 37 0 +13 43 44 0 +15 18 46 0 +16 17 47 0 +21 32 33 0 +23 30 31 0 +26 27 42 0 +1 12 46 0 +2 36 38 0 +3 5 10 0 +4 9 23 0 +6 13 39 0 +7 15 17 0 +8 18 27 0 +11 33 40 0 +14 28 44 0 +16 29 31 0 +19 20 22 0 +21 30 42 0 +24 26 47 0 +25 37 48 0 +32 34 45 0 +8 35 41 0 +12 31 43 0 +1 19 21 0 +2 43 45 0 +3 4 11 0 +5 18 33 0 +6 25 47 0 +7 28 30 0 +9 14 34 0 +10 35 42 0 +13 15 22 0 +16 37 38 0 +17 41 44 0 +20 24 29 0 +18 23 39 0 +12 26 32 0 +27 38 40 0 +15 36 48 0 +2 30 46 0 +1 4 13 0 +3 28 32 0 +5 43 47 0 +6 34 46 0 +7 9 40 0 +8 11 45 0 +10 17 23 0 +14 31 35 0 +16 22 42 0 +19 37 44 0 +20 33 48 0 +21 24 41 0 +25 27 29 0 +26 39 48 0 +19 31 36 0 +1 5 7 0 +2 29 39 0 +3 16 46 0 +4 26 37 0 +6 28 45 0 +8 22 33 0 +9 21 43 0 +10 25 38 0 +11 14 24 0 +12 17 40 0 +13 27 30 0 +15 32 35 0 +18 44 47 0 +20 23 36 0 +34 41 42 0 +1 32 48 0 +2 3 33 0 +4 29 42 0 +5 14 37 0 +6 7 36 0 +8 9 39 0 +10 13 19 0 +11 18 30 0 +12 16 20 0 +15 29 44 0 +17 34 38 0 +6 21 22 0 +23 32 40 0 +24 27 46 0 +25 41 45 0 +7 26 43 0 +28 31 47 0 +20 35 38 0 +1 33 41 0 +2 42 44 0 +3 23 48 0 +4 31 45 0 +5 8 30 0 +9 16 35 36 +10 11 43 46 +12 21 28 34 +13 14 18 40 +15 24 37 39 +17 19 25 26 +7 22 27 47 +1 3 25 43 +2 18 20 21 +4 14 17 39 +5 6 38 41 +8 23 34 37 +9 10 27 32 +11 26 28 35 +12 15 19 42 +13 29 36 46 +16 40 44 48 +22 24 30 45 +31 33 34 44 +29 30 37 47 +1 16 23 28 +2 11 15 27 +3 22 26 40 +4 21 38 48 +5 12 25 36 diff --git a/lib/ldpc/peg/peg-128-64-reg4.alist b/lib/ldpc/peg/peg-128-64-reg4.alist new file mode 100644 index 00000000..30c8edf9 --- /dev/null +++ b/lib/ldpc/peg/peg-128-64-reg4.alist @@ -0,0 +1,196 @@ +64 128 +9 4 +8 8 8 8 9 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 7 8 8 8 8 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 8 8 8 8 8 8 8 +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 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 +1 17 33 50 67 83 98 114 0 +2 18 34 50 68 84 99 115 0 +3 19 35 51 69 85 100 115 0 +4 20 36 52 70 86 101 115 0 +2 20 35 53 71 87 102 113 128 +5 21 33 54 64 88 103 116 0 +6 19 37 55 72 89 98 117 0 +7 22 38 56 73 90 96 116 0 +8 23 34 57 72 91 104 118 0 +7 24 39 58 74 84 100 119 0 +9 22 40 59 74 92 105 120 0 +9 25 41 55 75 91 106 114 0 +10 25 36 51 67 74 107 121 0 +11 22 36 54 72 93 102 122 0 +12 25 42 60 76 89 103 123 0 +8 26 38 51 77 93 105 124 0 +13 27 40 61 77 94 99 119 0 +13 17 43 54 73 85 108 124 0 +1 28 40 62 71 84 108 125 0 +12 29 38 53 67 86 108 126 0 +14 28 43 51 78 94 96 117 0 +11 17 42 62 79 92 104 126 0 +4 29 39 57 65 87 109 116 0 +2 27 38 55 78 79 107 127 0 +13 24 44 53 66 83 103 117 0 +15 30 43 55 67 90 105 128 0 +6 22 45 48 78 88 106 119 0 +14 25 33 63 65 73 99 118 0 +6 31 46 64 80 95 102 125 0 +5 18 37 65 79 94 110 113 0 +14 23 44 59 71 88 111 123 0 +13 32 47 62 70 91 109 128 0 +15 23 41 56 76 95 112 0 0 +11 29 41 47 68 69 105 117 0 +10 30 37 64 73 86 111 119 0 +5 32 45 60 69 96 101 127 0 +15 24 48 62 65 96 97 115 0 +3 23 42 64 77 83 109 0 0 +16 18 40 52 69 89 102 112 0 +9 20 49 63 76 94 109 121 0 +15 20 33 66 77 84 110 127 0 +10 21 44 60 80 82 112 126 0 +16 26 41 58 81 92 107 125 0 +3 27 48 59 82 95 110 118 0 +10 27 49 57 71 89 101 124 0 +4 26 42 61 68 90 100 122 0 +6 26 44 50 75 85 101 118 0 +7 28 37 47 66 76 82 114 0 +12 19 43 52 80 88 104 121 0 +2 31 47 56 75 93 108 123 0 +1 31 36 59 81 87 104 124 0 +3 32 39 50 81 97 106 121 0 +12 24 34 54 79 90 98 120 0 +1 19 49 56 82 92 103 122 0 +7 21 35 61 70 93 106 125 0 +14 18 46 60 70 97 107 122 0 +8 31 39 61 63 86 98 127 128 +4 28 34 45 75 97 110 126 0 +16 30 45 63 72 95 100 113 0 +8 21 48 52 74 87 111 114 0 +9 32 46 58 68 83 113 123 0 +11 30 46 53 81 91 99 116 0 +5 29 49 58 78 85 112 120 0 +16 17 35 57 66 80 111 120 0 +1 19 51 54 +2 5 24 50 +3 38 44 52 +4 23 46 58 +6 30 36 63 +7 27 29 47 +8 10 48 55 +9 16 57 60 +11 12 40 61 +13 35 42 45 +14 22 34 62 +15 20 49 53 +17 18 25 32 +21 28 31 56 +26 33 37 41 +39 43 59 64 +1 18 22 64 +2 30 39 56 +3 7 49 54 +4 5 40 41 +6 42 55 60 +8 11 14 27 +9 31 33 38 +10 25 37 53 +12 13 15 28 +16 43 46 47 +17 24 44 45 +19 21 48 58 +20 23 34 63 +26 35 59 62 +29 50 51 57 +32 36 52 61 +1 6 28 41 +2 9 53 58 +3 5 55 64 +4 13 14 51 +7 30 35 48 +8 16 20 24 +10 23 52 57 +11 17 19 39 +12 33 34 43 +15 22 38 46 +18 21 26 49 +25 31 42 47 +27 36 58 59 +29 56 61 62 +32 34 48 50 +27 37 44 60 +40 45 54 63 +1 2 47 52 +3 13 16 21 +4 39 49 60 +5 20 25 62 +6 14 18 53 +7 12 24 26 +8 33 50 54 +9 23 45 64 +10 43 61 63 +11 31 44 51 +15 36 42 56 +17 46 55 57 +19 22 32 37 +28 40 57 59 +6 29 35 38 +23 28 30 37 +25 41 48 64 +1 13 20 26 +2 34 46 61 +3 34 36 39 +4 32 55 56 +5 19 31 45 +7 9 14 59 +8 18 28 35 +10 11 13 60 +12 47 50 58 +15 33 40 48 +16 17 38 41 +21 24 27 63 +22 24 30 53 +29 42 49 64 +43 51 52 62 +42 44 48 54 +1 25 38 61 +2 10 19 41 +3 18 47 63 +4 20 35 57 +5 23 51 60 +6 27 31 49 +7 15 39 45 +8 26 46 53 +9 12 32 62 +11 22 43 54 +14 16 50 55 +17 21 30 40 +29 33 44 59 +8 21 36 37 +37 52 56 58 +1 7 53 57 +2 17 28 62 +3 10 46 59 +4 36 45 47 +5 14 29 39 +6 15 25 54 +9 22 49 51 +11 16 26 34 +12 27 52 55 +13 24 43 56 +18 19 20 50 +23 32 38 40 +30 41 44 58 +31 35 60 64 +33 39 42 63 +5 30 59 61 +1 12 48 60 +2 3 4 37 +6 8 23 62 +7 21 25 34 +9 28 44 47 +10 17 27 35 +11 53 63 64 +13 40 49 52 +14 46 54 56 +15 31 50 61 +16 18 45 51 +19 29 43 55 +20 22 42 58 +24 36 41 57 +5 26 32 57 diff --git a/lib/ldpc/peg/peg-128-64-reg4.code b/lib/ldpc/peg/peg-128-64-reg4.code new file mode 100644 index 00000000..5e99ac6a --- /dev/null +++ b/lib/ldpc/peg/peg-128-64-reg4.code @@ -0,0 +1,67 @@ +128 +64 +9 +1 17 33 50 67 83 98 114 0 +2 18 34 50 68 84 99 115 0 +3 19 35 51 69 85 100 115 0 +4 20 36 52 70 86 101 115 0 +2 20 35 53 71 87 102 113 128 +5 21 33 54 64 88 103 116 0 +6 19 37 55 72 89 98 117 0 +7 22 38 56 73 90 96 116 0 +8 23 34 57 72 91 104 118 0 +7 24 39 58 74 84 100 119 0 +9 22 40 59 74 92 105 120 0 +9 25 41 55 75 91 106 114 0 +10 25 36 51 67 74 107 121 0 +11 22 36 54 72 93 102 122 0 +12 25 42 60 76 89 103 123 0 +8 26 38 51 77 93 105 124 0 +13 27 40 61 77 94 99 119 0 +13 17 43 54 73 85 108 124 0 +1 28 40 62 71 84 108 125 0 +12 29 38 53 67 86 108 126 0 +14 28 43 51 78 94 96 117 0 +11 17 42 62 79 92 104 126 0 +4 29 39 57 65 87 109 116 0 +2 27 38 55 78 79 107 127 0 +13 24 44 53 66 83 103 117 0 +15 30 43 55 67 90 105 128 0 +6 22 45 48 78 88 106 119 0 +14 25 33 63 65 73 99 118 0 +6 31 46 64 80 95 102 125 0 +5 18 37 65 79 94 110 113 0 +14 23 44 59 71 88 111 123 0 +13 32 47 62 70 91 109 128 0 +15 23 41 56 76 95 112 0 0 +11 29 41 47 68 69 105 117 0 +10 30 37 64 73 86 111 119 0 +5 32 45 60 69 96 101 127 0 +15 24 48 62 65 96 97 115 0 +3 23 42 64 77 83 109 0 0 +16 18 40 52 69 89 102 112 0 +9 20 49 63 76 94 109 121 0 +15 20 33 66 77 84 110 127 0 +10 21 44 60 80 82 112 126 0 +16 26 41 58 81 92 107 125 0 +3 27 48 59 82 95 110 118 0 +10 27 49 57 71 89 101 124 0 +4 26 42 61 68 90 100 122 0 +6 26 44 50 75 85 101 118 0 +7 28 37 47 66 76 82 114 0 +12 19 43 52 80 88 104 121 0 +2 31 47 56 75 93 108 123 0 +1 31 36 59 81 87 104 124 0 +3 32 39 50 81 97 106 121 0 +12 24 34 54 79 90 98 120 0 +1 19 49 56 82 92 103 122 0 +7 21 35 61 70 93 106 125 0 +14 18 46 60 70 97 107 122 0 +8 31 39 61 63 86 98 127 128 +4 28 34 45 75 97 110 126 0 +16 30 45 63 72 95 100 113 0 +8 21 48 52 74 87 111 114 0 +9 32 46 58 68 83 113 123 0 +11 30 46 53 81 91 99 116 0 +5 29 49 58 78 85 112 120 0 +16 17 35 57 66 80 111 120 0 diff --git a/lib/ldpc/peg/peg-128-72-reg4.alist b/lib/ldpc/peg/peg-128-72-reg4.alist new file mode 100644 index 00000000..6bb420a5 --- /dev/null +++ b/lib/ldpc/peg/peg-128-72-reg4.alist @@ -0,0 +1,188 @@ +56 128 +10 4 +9 9 9 9 9 9 9 9 10 9 9 9 9 9 9 9 9 10 9 9 9 9 10 9 10 9 9 9 9 9 10 9 9 9 9 9 9 9 9 9 9 9 10 9 9 9 10 10 9 9 9 10 9 9 9 8 +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 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 +1 15 30 44 58 71 84 100 115 0 +2 16 31 44 59 72 86 101 116 0 +3 17 31 45 60 73 87 102 117 0 +2 18 32 46 58 73 85 103 112 0 +4 19 32 47 61 74 88 104 118 0 +5 20 33 48 62 75 88 105 116 0 +6 19 34 49 63 76 89 105 119 0 +7 15 27 45 64 77 88 106 120 0 +8 15 35 50 59 75 90 107 121 127 +7 21 33 51 65 73 91 108 114 0 +9 22 30 46 59 78 92 99 122 0 +9 19 35 52 60 71 93 109 120 0 +10 20 31 53 63 79 93 107 123 0 +11 15 36 53 66 78 85 110 124 0 +8 23 37 49 67 71 86 111 118 0 +12 22 34 54 68 80 94 109 114 0 +1 24 34 52 65 75 87 97 123 0 +13 25 29 43 69 81 85 100 121 128 +12 17 38 55 63 82 90 101 125 0 +11 26 39 47 56 76 95 106 117 0 +2 27 40 49 69 74 94 108 117 0 +4 16 30 55 64 76 91 103 126 0 +13 17 28 47 65 80 96 111 124 126 +6 18 36 51 70 83 94 111 121 0 +13 16 34 48 57 82 95 112 120 127 +6 28 40 48 58 79 90 113 122 0 +5 27 41 46 67 83 91 109 127 0 +14 16 42 54 63 78 97 100 118 0 +13 27 39 52 70 84 90 114 118 0 +10 22 42 47 64 81 98 110 116 0 +11 22 29 55 60 84 97 108 111 127 +5 26 37 55 57 74 96 98 128 0 +3 21 35 54 62 82 98 104 113 0 +14 21 43 50 68 77 93 110 117 0 +9 24 33 56 69 72 89 110 112 0 +12 26 42 53 62 73 89 99 121 0 +10 25 35 41 57 76 97 101 122 0 +10 18 39 44 66 77 99 102 119 0 +3 29 40 44 61 83 93 106 125 0 +4 23 39 45 65 85 89 107 113 0 +6 26 30 43 61 80 86 108 123 0 +7 19 31 57 69 83 99 113 124 0 +3 24 37 43 66 84 92 105 120 126 +2 24 38 50 70 71 88 102 122 0 +1 20 32 51 68 81 86 102 124 0 +12 23 41 51 59 74 87 106 115 0 +14 28 37 46 62 72 95 114 115 125 +1 28 41 49 61 82 92 103 116 128 +7 25 38 56 60 75 98 103 115 0 +8 29 33 45 58 78 96 109 119 0 +4 25 36 54 67 77 96 105 123 0 +14 20 38 52 66 80 91 104 112 128 +8 18 42 56 68 79 87 104 125 0 +9 23 40 53 70 81 95 101 126 0 +11 21 32 48 67 72 94 107 119 0 +5 17 36 50 64 79 92 100 0 0 +1 17 45 48 +2 4 21 44 +3 33 39 43 +5 22 40 51 +6 27 32 56 +7 24 26 41 +8 10 42 49 +9 15 50 53 +11 12 35 54 +13 30 37 38 +14 20 31 55 +16 19 36 46 +18 23 25 29 +28 34 47 52 +1 8 9 14 +2 22 25 28 +3 19 23 56 +4 24 38 53 +5 7 12 42 +6 13 45 52 +10 33 34 55 +11 16 30 31 +15 40 46 54 +17 35 43 44 +18 37 49 51 +20 32 36 41 +8 21 27 29 +23 26 47 48 +18 31 39 50 +1 11 22 41 +2 3 13 42 +4 5 45 55 +6 10 35 50 +7 16 17 25 +9 12 33 37 +14 24 51 56 +15 32 43 47 +19 44 49 52 +20 29 38 40 +21 26 39 54 +27 37 46 48 +28 30 36 53 +18 34 41 43 +1 2 38 39 +3 8 40 50 +4 11 27 47 +5 20 23 30 +6 25 26 55 +7 15 21 48 +9 34 44 56 +10 24 45 46 +12 17 29 52 +13 14 36 54 +16 28 33 51 +19 22 31 32 +20 35 49 53 +25 32 37 42 +1 4 26 50 +2 9 11 46 +3 12 31 49 +5 39 41 48 +6 33 36 47 +7 13 19 28 +8 22 30 56 +10 17 23 40 +14 38 43 52 +15 27 51 55 +16 34 45 53 +18 21 35 42 +24 29 44 54 +1 12 15 44 +2 35 47 55 +3 4 10 36 +5 21 32 46 +6 9 17 49 +7 20 22 37 +8 34 38 51 +11 14 28 50 +13 26 53 56 +16 23 41 52 +18 30 45 54 +19 25 33 48 +24 27 39 42 +1 29 31 43 +4 14 18 40 +2 15 41 45 +3 17 46 53 +5 6 8 44 +7 35 36 40 +9 19 26 29 +10 22 27 52 +11 43 48 56 +12 13 34 39 +16 21 24 55 +20 25 47 54 +23 32 50 51 +17 28 31 37 +30 32 33 49 +11 36 38 42 +1 18 28 56 +2 19 37 54 +3 38 44 45 +4 22 48 49 +5 33 52 53 +6 7 43 51 +8 20 39 46 +9 13 40 55 +10 21 31 41 +12 16 27 50 +14 30 34 35 +15 23 24 31 +4 25 35 52 +26 33 40 42 +10 16 29 47 +1 46 47 49 +2 6 30 48 +3 20 21 34 +5 15 28 29 +7 38 50 55 +8 12 25 43 +9 18 24 36 +11 26 37 44 +13 17 41 51 +14 23 42 45 +19 39 47 53 +22 23 43 54 +9 25 27 31 +18 32 48 52 diff --git a/lib/ldpc/peg/peg-128-72-reg4.code b/lib/ldpc/peg/peg-128-72-reg4.code new file mode 100644 index 00000000..09108dbf --- /dev/null +++ b/lib/ldpc/peg/peg-128-72-reg4.code @@ -0,0 +1,59 @@ +128 +56 +10 +1 15 30 44 58 71 84 100 115 0 +2 16 31 44 59 72 86 101 116 0 +3 17 31 45 60 73 87 102 117 0 +2 18 32 46 58 73 85 103 112 0 +4 19 32 47 61 74 88 104 118 0 +5 20 33 48 62 75 88 105 116 0 +6 19 34 49 63 76 89 105 119 0 +7 15 27 45 64 77 88 106 120 0 +8 15 35 50 59 75 90 107 121 127 +7 21 33 51 65 73 91 108 114 0 +9 22 30 46 59 78 92 99 122 0 +9 19 35 52 60 71 93 109 120 0 +10 20 31 53 63 79 93 107 123 0 +11 15 36 53 66 78 85 110 124 0 +8 23 37 49 67 71 86 111 118 0 +12 22 34 54 68 80 94 109 114 0 +1 24 34 52 65 75 87 97 123 0 +13 25 29 43 69 81 85 100 121 128 +12 17 38 55 63 82 90 101 125 0 +11 26 39 47 56 76 95 106 117 0 +2 27 40 49 69 74 94 108 117 0 +4 16 30 55 64 76 91 103 126 0 +13 17 28 47 65 80 96 111 124 126 +6 18 36 51 70 83 94 111 121 0 +13 16 34 48 57 82 95 112 120 127 +6 28 40 48 58 79 90 113 122 0 +5 27 41 46 67 83 91 109 127 0 +14 16 42 54 63 78 97 100 118 0 +13 27 39 52 70 84 90 114 118 0 +10 22 42 47 64 81 98 110 116 0 +11 22 29 55 60 84 97 108 111 127 +5 26 37 55 57 74 96 98 128 0 +3 21 35 54 62 82 98 104 113 0 +14 21 43 50 68 77 93 110 117 0 +9 24 33 56 69 72 89 110 112 0 +12 26 42 53 62 73 89 99 121 0 +10 25 35 41 57 76 97 101 122 0 +10 18 39 44 66 77 99 102 119 0 +3 29 40 44 61 83 93 106 125 0 +4 23 39 45 65 85 89 107 113 0 +6 26 30 43 61 80 86 108 123 0 +7 19 31 57 69 83 99 113 124 0 +3 24 37 43 66 84 92 105 120 126 +2 24 38 50 70 71 88 102 122 0 +1 20 32 51 68 81 86 102 124 0 +12 23 41 51 59 74 87 106 115 0 +14 28 37 46 62 72 95 114 115 125 +1 28 41 49 61 82 92 103 116 128 +7 25 38 56 60 75 98 103 115 0 +8 29 33 45 58 78 96 109 119 0 +4 25 36 54 67 77 96 105 123 0 +14 20 38 52 66 80 91 104 112 128 +8 18 42 56 68 79 87 104 125 0 +9 23 40 53 70 81 95 101 126 0 +11 21 32 48 67 72 94 107 119 0 +5 17 36 50 64 79 92 100 0 0 diff --git a/lib/ldpc/peg/peg-128-80-reg3.alist b/lib/ldpc/peg/peg-128-80-reg3.alist new file mode 100644 index 00000000..e2d9e15f --- /dev/null +++ b/lib/ldpc/peg/peg-128-80-reg3.alist @@ -0,0 +1,180 @@ +48 128 +8 3 +8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 +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 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 +1 17 34 51 66 81 99 113 +2 18 35 50 67 82 100 114 +3 19 36 52 68 82 101 115 +2 20 36 51 69 83 102 116 +4 19 37 53 66 84 103 117 +5 21 38 54 70 85 92 114 +6 22 39 55 66 85 96 118 +7 23 32 56 71 86 103 119 +8 20 40 55 72 86 104 120 +9 19 41 57 73 87 105 121 +10 24 36 56 74 88 106 122 +10 17 33 47 75 89 107 119 +11 21 42 51 76 87 108 123 +1 25 40 58 74 84 109 124 +12 22 42 49 77 90 110 122 +13 26 43 59 68 89 104 113 +13 22 44 57 75 91 106 125 +12 23 37 46 78 88 109 113 +3 27 34 60 65 87 111 126 +6 27 45 61 79 89 98 114 +14 28 34 62 72 92 107 125 +8 27 42 59 71 92 112 117 +15 20 46 57 79 93 101 117 +9 29 45 62 74 94 108 127 +8 30 38 63 73 95 110 125 +16 29 47 64 69 96 110 128 +16 23 48 63 76 94 111 121 +7 25 39 52 70 97 108 116 +4 26 45 63 67 83 90 126 +15 28 39 50 76 88 103 115 +15 26 33 58 65 97 102 127 +14 31 47 52 77 81 93 121 +14 24 37 61 71 82 99 116 +4 31 40 54 80 91 107 122 +5 32 41 58 77 98 111 120 +9 18 49 65 79 85 104 123 +10 30 43 60 69 84 112 123 +1 18 43 48 73 91 98 119 +3 21 46 64 67 86 112 118 +5 24 48 55 75 93 105 128 +2 32 44 62 80 95 99 124 +16 28 41 59 80 83 100 118 +11 33 35 53 72 96 109 115 +11 25 44 60 78 90 100 128 +6 31 35 56 70 95 102 126 +12 17 50 54 68 94 106 120 +13 29 38 53 78 97 105 124 +7 30 49 61 64 81 101 127 +1 14 38 +2 4 41 +3 19 39 +5 29 34 +6 35 40 +7 20 45 +8 28 48 +9 22 25 +10 24 36 +11 12 37 +13 43 44 +15 18 46 +16 17 47 +21 32 33 +23 30 31 +26 27 42 +1 12 46 +2 36 38 +3 5 10 +4 9 23 +6 13 39 +7 15 17 +8 18 27 +11 33 40 +14 28 44 +16 29 31 +19 20 22 +21 30 42 +24 26 47 +25 37 48 +32 34 45 +8 35 41 +12 31 43 +1 19 21 +2 43 45 +3 4 11 +5 18 33 +6 25 47 +7 28 30 +9 14 34 +10 35 42 +13 15 22 +16 37 38 +17 41 44 +20 24 29 +18 23 39 +12 26 32 +27 38 40 +15 36 48 +2 30 46 +1 4 13 +3 28 32 +5 43 47 +6 34 46 +7 9 40 +8 11 45 +10 17 23 +14 31 35 +16 22 42 +19 37 44 +20 33 48 +21 24 41 +25 27 29 +26 39 48 +19 31 36 +1 5 7 +2 29 39 +3 16 46 +4 26 37 +6 28 45 +8 22 33 +9 21 43 +10 25 38 +11 14 24 +12 17 40 +13 27 30 +15 32 35 +18 44 47 +20 23 36 +34 41 42 +1 32 48 +2 3 33 +4 29 42 +5 14 37 +6 7 36 +8 9 39 +10 13 19 +11 18 30 +12 16 20 +15 29 44 +17 34 38 +6 21 22 +23 32 40 +24 27 46 +25 41 45 +7 26 43 +28 31 47 +20 35 38 +1 33 41 +2 42 44 +3 23 48 +4 31 45 +5 8 30 +9 16 36 +10 40 47 +11 17 46 +12 21 34 +13 24 28 +14 18 43 +15 25 26 +19 27 35 +22 37 39 +1 16 18 +2 6 20 +3 30 43 +4 28 33 +5 22 23 +7 39 42 +8 12 38 +9 35 46 +10 27 32 +11 15 34 +13 36 37 +14 41 47 +17 21 25 +19 29 45 +24 31 48 +26 40 44 diff --git a/lib/ldpc/peg/peg-128-80-reg3.code b/lib/ldpc/peg/peg-128-80-reg3.code new file mode 100644 index 00000000..10064e07 --- /dev/null +++ b/lib/ldpc/peg/peg-128-80-reg3.code @@ -0,0 +1,51 @@ +128 +48 +8 +1 17 34 51 66 81 99 113 +2 18 35 50 67 82 100 114 +3 19 36 52 68 82 101 115 +2 20 36 51 69 83 102 116 +4 19 37 53 66 84 103 117 +5 21 38 54 70 85 92 114 +6 22 39 55 66 85 96 118 +7 23 32 56 71 86 103 119 +8 20 40 55 72 86 104 120 +9 19 41 57 73 87 105 121 +10 24 36 56 74 88 106 122 +10 17 33 47 75 89 107 119 +11 21 42 51 76 87 108 123 +1 25 40 58 74 84 109 124 +12 22 42 49 77 90 110 122 +13 26 43 59 68 89 104 113 +13 22 44 57 75 91 106 125 +12 23 37 46 78 88 109 113 +3 27 34 60 65 87 111 126 +6 27 45 61 79 89 98 114 +14 28 34 62 72 92 107 125 +8 27 42 59 71 92 112 117 +15 20 46 57 79 93 101 117 +9 29 45 62 74 94 108 127 +8 30 38 63 73 95 110 125 +16 29 47 64 69 96 110 128 +16 23 48 63 76 94 111 121 +7 25 39 52 70 97 108 116 +4 26 45 63 67 83 90 126 +15 28 39 50 76 88 103 115 +15 26 33 58 65 97 102 127 +14 31 47 52 77 81 93 121 +14 24 37 61 71 82 99 116 +4 31 40 54 80 91 107 122 +5 32 41 58 77 98 111 120 +9 18 49 65 79 85 104 123 +10 30 43 60 69 84 112 123 +1 18 43 48 73 91 98 119 +3 21 46 64 67 86 112 118 +5 24 48 55 75 93 105 128 +2 32 44 62 80 95 99 124 +16 28 41 59 80 83 100 118 +11 33 35 53 72 96 109 115 +11 25 44 60 78 90 100 128 +6 31 35 56 70 95 102 126 +12 17 50 54 68 94 106 120 +13 29 38 53 78 97 105 124 +7 30 49 61 64 81 101 127 diff --git a/lib/ldpc/peg/peg-128-80-reg4.alist b/lib/ldpc/peg/peg-128-80-reg4.alist new file mode 100644 index 00000000..2487ea9b --- /dev/null +++ b/lib/ldpc/peg/peg-128-80-reg4.alist @@ -0,0 +1,180 @@ +48 128 +12 4 +11 11 11 11 11 11 11 11 11 11 11 11 11 10 11 11 11 10 10 11 10 11 10 11 10 10 10 10 10 11 10 12 11 11 10 11 11 11 11 11 10 10 11 10 10 11 11 10 +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 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 +1 13 26 38 51 62 75 86 99 111 124 0 +2 13 27 39 49 63 76 87 100 112 121 0 +3 14 27 40 52 64 74 88 101 104 123 0 +2 15 28 41 53 65 77 89 102 113 125 0 +4 16 26 41 54 66 71 90 101 114 122 0 +5 15 29 40 55 67 78 91 98 110 126 0 +6 17 30 42 56 63 79 90 103 115 124 0 +7 18 25 43 56 68 80 87 104 113 122 0 +7 13 29 44 52 69 81 92 102 114 127 0 +8 14 29 42 57 66 77 86 97 116 119 0 +9 19 26 45 56 69 76 93 97 110 128 0 +9 14 28 46 54 68 82 91 99 112 118 0 +8 20 31 47 49 69 78 88 105 109 124 0 +1 20 32 42 52 70 76 94 106 117 0 0 +10 15 33 48 52 62 80 93 100 118 119 0 +11 18 31 39 48 67 83 94 97 114 125 0 +12 15 34 37 49 64 73 85 99 116 127 0 +2 21 25 45 55 64 83 92 103 119 0 0 +4 22 33 46 55 65 84 86 107 108 0 0 +11 16 27 45 53 70 79 95 107 111 126 0 +6 13 33 45 57 68 85 96 101 120 0 0 +12 17 25 38 58 67 76 96 107 118 123 0 +5 18 30 44 59 71 77 93 106 120 0 0 +6 20 28 43 50 72 83 86 95 121 127 0 +11 23 28 38 59 73 81 88 108 115 0 0 +10 19 32 49 60 67 75 89 101 108 0 0 +5 22 27 48 54 69 73 96 103 113 0 0 +12 23 35 47 50 62 79 97 106 122 0 0 +3 18 26 47 53 61 82 85 98 108 0 0 +9 22 31 41 58 60 72 87 106 115 116 0 +10 16 30 50 58 65 73 91 104 109 0 0 +10 24 36 41 57 61 78 94 103 111 123 127 +4 17 29 43 59 74 85 89 109 112 128 0 +3 21 34 38 60 63 77 95 105 114 128 0 +7 24 37 46 53 71 74 96 105 110 0 0 +6 19 34 47 51 70 81 91 100 123 125 0 +2 24 31 40 56 66 81 84 95 118 120 0 +1 14 30 37 48 72 78 92 107 122 128 0 +3 23 24 42 55 68 75 93 109 121 125 0 +12 22 32 43 51 71 82 88 102 119 126 0 +1 23 36 44 58 64 80 90 110 112 0 0 +7 19 35 40 59 65 82 90 111 117 0 0 +9 17 36 39 50 66 75 92 105 117 126 0 +4 21 35 39 57 70 80 98 99 115 0 0 +8 25 33 37 54 60 79 94 98 121 0 0 +8 16 34 46 61 62 83 87 102 117 120 0 +11 21 32 44 61 72 74 84 100 113 124 0 +5 20 35 36 51 63 84 89 104 116 0 0 +1 14 38 41 +2 4 18 37 +3 29 34 39 +5 19 33 44 +6 23 27 48 +7 21 24 36 +8 9 35 42 +10 13 45 46 +11 12 30 43 +15 26 31 32 +16 20 25 47 +17 22 28 40 +1 2 9 21 +3 10 12 38 +4 6 15 17 +5 20 31 46 +7 22 33 43 +8 16 23 29 +11 26 36 42 +13 14 24 48 +18 34 44 47 +19 27 30 40 +25 28 39 41 +32 35 37 39 +8 18 22 45 +1 5 11 29 +2 3 20 27 +4 12 24 25 +6 9 10 33 +7 23 31 38 +13 16 30 37 +14 26 40 47 +15 19 21 45 +17 34 36 46 +28 42 44 48 +32 41 43 48 +17 35 38 45 +1 22 25 34 +2 16 43 44 +3 6 37 42 +4 5 30 32 +7 10 14 39 +8 24 33 40 +9 23 41 47 +11 18 20 21 +12 19 35 46 +13 28 29 36 +15 16 27 38 +2 13 17 26 +24 28 31 43 +1 36 40 48 +3 9 14 15 +4 20 29 35 +5 12 27 45 +6 18 19 39 +7 8 11 37 +10 21 32 44 +22 30 31 41 +23 25 33 42 +26 30 34 45 +29 32 46 47 +1 15 28 46 +2 7 34 48 +3 17 18 41 +4 19 31 42 +5 10 37 43 +6 16 22 26 +8 12 21 39 +9 11 13 27 +14 20 36 44 +5 23 35 40 +24 30 38 47 +17 25 27 31 +3 33 35 47 +1 26 39 43 +2 11 14 22 +4 10 23 34 +6 13 32 38 +7 20 28 45 +8 15 41 44 +9 25 36 37 +12 29 40 42 +16 18 24 46 +19 37 47 48 +17 21 29 33 +1 10 19 24 +2 8 30 46 +3 13 25 40 +4 26 33 48 +5 7 41 42 +6 12 31 36 +9 18 38 43 +11 15 23 39 +14 16 32 45 +20 24 34 37 +21 22 27 35 +10 11 16 28 +6 29 44 45 +1 12 17 44 +2 15 36 47 +3 5 21 26 +4 9 40 46 +7 18 27 32 +3 8 31 48 +13 34 35 43 +14 23 28 30 +19 20 22 38 +19 25 26 29 +13 31 33 39 +6 11 35 41 +1 20 32 42 +2 12 33 41 +4 8 27 47 +5 9 16 34 +7 25 30 44 +10 17 30 48 +14 42 43 46 +12 15 22 37 +10 15 18 40 +21 23 37 46 +2 24 39 45 +5 8 28 38 +3 22 32 36 +1 7 13 47 +4 16 36 39 +6 20 40 43 +9 17 24 32 +11 33 34 38 diff --git a/lib/ldpc/peg/peg-128-80-reg4.code b/lib/ldpc/peg/peg-128-80-reg4.code new file mode 100644 index 00000000..572e6221 --- /dev/null +++ b/lib/ldpc/peg/peg-128-80-reg4.code @@ -0,0 +1,51 @@ +128 +48 +12 +1 13 26 38 51 62 75 86 99 111 124 0 +2 13 27 39 49 63 76 87 100 112 121 0 +3 14 27 40 52 64 74 88 101 104 123 0 +2 15 28 41 53 65 77 89 102 113 125 0 +4 16 26 41 54 66 71 90 101 114 122 0 +5 15 29 40 55 67 78 91 98 110 126 0 +6 17 30 42 56 63 79 90 103 115 124 0 +7 18 25 43 56 68 80 87 104 113 122 0 +7 13 29 44 52 69 81 92 102 114 127 0 +8 14 29 42 57 66 77 86 97 116 119 0 +9 19 26 45 56 69 76 93 97 110 128 0 +9 14 28 46 54 68 82 91 99 112 118 0 +8 20 31 47 49 69 78 88 105 109 124 0 +1 20 32 42 52 70 76 94 106 117 0 0 +10 15 33 48 52 62 80 93 100 118 119 0 +11 18 31 39 48 67 83 94 97 114 125 0 +12 15 34 37 49 64 73 85 99 116 127 0 +2 21 25 45 55 64 83 92 103 119 0 0 +4 22 33 46 55 65 84 86 107 108 0 0 +11 16 27 45 53 70 79 95 107 111 126 0 +6 13 33 45 57 68 85 96 101 120 0 0 +12 17 25 38 58 67 76 96 107 118 123 0 +5 18 30 44 59 71 77 93 106 120 0 0 +6 20 28 43 50 72 83 86 95 121 127 0 +11 23 28 38 59 73 81 88 108 115 0 0 +10 19 32 49 60 67 75 89 101 108 0 0 +5 22 27 48 54 69 73 96 103 113 0 0 +12 23 35 47 50 62 79 97 106 122 0 0 +3 18 26 47 53 61 82 85 98 108 0 0 +9 22 31 41 58 60 72 87 106 115 116 0 +10 16 30 50 58 65 73 91 104 109 0 0 +10 24 36 41 57 61 78 94 103 111 123 127 +4 17 29 43 59 74 85 89 109 112 128 0 +3 21 34 38 60 63 77 95 105 114 128 0 +7 24 37 46 53 71 74 96 105 110 0 0 +6 19 34 47 51 70 81 91 100 123 125 0 +2 24 31 40 56 66 81 84 95 118 120 0 +1 14 30 37 48 72 78 92 107 122 128 0 +3 23 24 42 55 68 75 93 109 121 125 0 +12 22 32 43 51 71 82 88 102 119 126 0 +1 23 36 44 58 64 80 90 110 112 0 0 +7 19 35 40 59 65 82 90 111 117 0 0 +9 17 36 39 50 66 75 92 105 117 126 0 +4 21 35 39 57 70 80 98 99 115 0 0 +8 25 33 37 54 60 79 94 98 121 0 0 +8 16 34 46 61 62 83 87 102 117 120 0 +11 21 32 44 61 72 74 84 100 113 124 0 +5 20 35 36 51 63 84 89 104 116 0 0 diff --git a/lib/ldpc/peg/peg-144-72-reg4.alist b/lib/ldpc/peg/peg-144-72-reg4.alist new file mode 100644 index 00000000..cad34471 --- /dev/null +++ b/lib/ldpc/peg/peg-144-72-reg4.alist @@ -0,0 +1,220 @@ +72 144 +9 4 +8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 +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 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 4 4 +1 19 38 57 74 94 110 128 0 +2 20 39 58 75 95 111 129 0 +3 21 40 59 76 95 108 130 0 +4 22 41 60 69 96 112 131 0 +2 19 42 60 77 97 113 132 0 +5 20 43 61 78 98 114 133 0 +6 22 44 62 79 99 115 127 0 +7 23 41 58 73 100 113 134 0 +8 23 45 63 80 101 114 135 0 +7 24 46 64 81 98 112 136 0 +9 25 47 64 75 102 116 130 0 +9 22 48 59 82 98 117 137 0 +10 25 49 65 80 99 118 132 0 +11 26 50 66 75 96 119 127 0 +12 27 43 67 82 103 120 136 0 +13 28 50 68 82 97 121 138 0 +8 29 47 62 83 104 121 132 0 +13 25 38 53 61 100 111 135 0 +14 22 38 63 83 95 122 133 0 +15 30 41 63 81 105 123 129 0 +1 28 51 64 80 104 119 126 0 +12 24 40 69 84 100 124 133 0 +16 23 52 65 77 106 110 139 0 +11 31 37 55 85 101 118 140 0 +13 32 48 70 77 94 122 140 0 +2 27 53 71 78 101 110 131 0 +4 29 46 71 77 88 124 130 0 +14 24 49 56 86 107 119 130 144 +14 33 47 70 87 108 115 137 0 +6 32 52 69 78 91 125 141 0 +15 26 51 61 76 86 117 140 0 +17 33 51 59 88 109 113 142 0 +6 31 40 54 88 102 111 136 0 +5 33 54 62 86 103 118 141 0 +13 24 44 72 75 103 114 142 0 +15 34 47 67 85 99 110 143 0 +18 28 49 58 89 92 122 131 0 +18 21 38 68 85 91 115 129 0 +11 33 36 58 84 106 121 128 0 +10 20 50 59 90 94 120 135 0 +5 29 42 55 89 106 117 136 0 +3 30 45 61 84 104 115 144 0 +15 20 52 57 89 102 126 142 0 +16 35 53 72 80 102 125 143 0 +9 26 39 71 74 105 125 139 0 +16 30 44 71 85 90 112 134 0 +17 25 55 69 76 105 119 134 0 +10 35 37 63 91 108 113 144 0 +17 27 44 57 87 92 123 143 0 +3 32 46 67 92 96 109 0 0 +10 36 46 60 93 107 111 133 0 +4 35 54 56 74 100 117 138 0 +6 34 39 66 87 93 118 138 0 +7 34 48 55 83 96 120 139 0 +12 35 42 68 79 105 112 141 0 +2 31 51 67 79 107 116 128 0 +1 29 40 73 90 101 125 138 0 +3 19 37 72 87 99 122 139 0 +12 26 45 65 73 92 121 137 0 +14 30 42 66 74 109 114 140 0 +1 36 48 56 81 97 116 134 0 +7 19 50 62 91 107 109 143 0 +17 23 56 70 78 93 120 129 0 +8 36 53 68 86 108 123 142 0 +4 21 39 70 89 98 123 132 0 +18 27 54 66 81 104 106 137 0 +8 31 49 57 82 93 124 127 0 +9 37 43 73 84 95 126 131 0 +18 34 45 72 88 94 116 141 0 +11 21 52 64 79 103 124 135 0 +5 32 41 65 90 97 126 128 0 +16 28 43 60 76 83 127 144 0 +1 21 57 61 +2 5 26 56 +3 42 50 58 +4 27 52 65 +6 34 41 71 +7 30 33 53 +8 10 54 62 +9 17 64 67 +11 12 45 68 +13 40 48 51 +14 24 39 70 +15 22 55 59 +16 18 25 35 +19 28 29 60 +20 31 36 43 +23 44 46 72 +32 47 49 63 +37 38 66 69 +1 5 58 62 +2 6 40 43 +3 38 65 70 +4 7 12 19 +8 9 23 63 +10 22 28 35 +11 13 18 47 +14 31 45 59 +15 26 49 66 +16 21 37 72 +17 27 41 57 +20 42 46 60 +24 33 56 67 +25 30 50 71 +29 32 34 39 +36 53 54 69 +44 48 52 55 +39 51 61 64 +24 48 58 68 +1 18 19 38 +2 45 53 65 +3 22 33 57 +4 8 20 71 +5 41 55 60 +6 15 68 72 +7 35 46 49 +9 42 59 69 +10 27 50 51 +11 17 29 36 +12 25 54 61 +13 28 37 67 +14 16 40 62 +21 31 32 56 +23 30 43 70 +18 26 44 64 +33 34 52 66 +24 41 47 54 +28 52 61 63 +1 43 49 67 +2 8 37 39 +3 12 32 40 +4 5 51 72 +6 18 31 42 +7 17 34 62 +9 19 20 48 +10 11 21 70 +13 23 59 71 +14 53 60 66 +15 36 50 56 +16 38 55 64 +4 22 30 47 +25 29 63 65 +26 27 45 46 +35 44 58 69 +8 57 59 68 +1 45 52 60 +2 11 14 35 +3 31 47 72 +5 23 25 27 +6 26 30 63 +7 55 56 70 +9 13 21 44 +10 20 61 66 +12 15 16 67 +17 19 54 72 +22 39 42 68 +24 36 38 46 +28 31 34 64 +29 49 53 58 +27 32 33 69 +37 41 43 65 +40 46 57 71 +30 38 48 62 +37 49 50 59 +51 53 63 67 +1 25 40 69 +2 3 19 68 +4 14 50 54 +5 16 61 71 +6 10 12 65 +7 13 36 58 +8 18 22 52 +9 24 26 57 +11 33 43 44 +15 34 35 70 +17 21 42 66 +20 45 47 55 +23 39 41 66 +28 51 56 62 +3 29 48 64 +32 50 60 62 +1 23 26 36 +2 18 33 51 +4 10 46 55 +5 8 32 48 +6 9 35 60 +7 29 38 42 +11 56 61 69 +12 31 41 52 +13 24 34 53 +14 21 28 47 +15 40 54 63 +16 17 39 59 +19 25 37 58 +20 49 64 65 +22 27 67 70 +30 44 45 57 +21 43 68 71 +7 14 67 72 +1 39 56 71 +2 20 38 63 +3 11 27 28 +4 26 37 68 +5 13 17 65 +6 19 22 51 +8 46 47 61 +9 18 40 70 +10 15 33 41 +12 29 59 66 +16 52 53 57 +23 45 54 58 +24 25 31 60 +30 34 55 69 +32 35 43 64 +36 44 49 62 +28 42 48 72 diff --git a/lib/ldpc/peg/peg-144-72-reg4.code b/lib/ldpc/peg/peg-144-72-reg4.code new file mode 100644 index 00000000..78747e92 --- /dev/null +++ b/lib/ldpc/peg/peg-144-72-reg4.code @@ -0,0 +1,75 @@ +144 +72 +9 +1 19 38 57 74 94 110 128 0 +2 20 39 58 75 95 111 129 0 +3 21 40 59 76 95 108 130 0 +4 22 41 60 69 96 112 131 0 +2 19 42 60 77 97 113 132 0 +5 20 43 61 78 98 114 133 0 +6 22 44 62 79 99 115 127 0 +7 23 41 58 73 100 113 134 0 +8 23 45 63 80 101 114 135 0 +7 24 46 64 81 98 112 136 0 +9 25 47 64 75 102 116 130 0 +9 22 48 59 82 98 117 137 0 +10 25 49 65 80 99 118 132 0 +11 26 50 66 75 96 119 127 0 +12 27 43 67 82 103 120 136 0 +13 28 50 68 82 97 121 138 0 +8 29 47 62 83 104 121 132 0 +13 25 38 53 61 100 111 135 0 +14 22 38 63 83 95 122 133 0 +15 30 41 63 81 105 123 129 0 +1 28 51 64 80 104 119 126 0 +12 24 40 69 84 100 124 133 0 +16 23 52 65 77 106 110 139 0 +11 31 37 55 85 101 118 140 0 +13 32 48 70 77 94 122 140 0 +2 27 53 71 78 101 110 131 0 +4 29 46 71 77 88 124 130 0 +14 24 49 56 86 107 119 130 144 +14 33 47 70 87 108 115 137 0 +6 32 52 69 78 91 125 141 0 +15 26 51 61 76 86 117 140 0 +17 33 51 59 88 109 113 142 0 +6 31 40 54 88 102 111 136 0 +5 33 54 62 86 103 118 141 0 +13 24 44 72 75 103 114 142 0 +15 34 47 67 85 99 110 143 0 +18 28 49 58 89 92 122 131 0 +18 21 38 68 85 91 115 129 0 +11 33 36 58 84 106 121 128 0 +10 20 50 59 90 94 120 135 0 +5 29 42 55 89 106 117 136 0 +3 30 45 61 84 104 115 144 0 +15 20 52 57 89 102 126 142 0 +16 35 53 72 80 102 125 143 0 +9 26 39 71 74 105 125 139 0 +16 30 44 71 85 90 112 134 0 +17 25 55 69 76 105 119 134 0 +10 35 37 63 91 108 113 144 0 +17 27 44 57 87 92 123 143 0 +3 32 46 67 92 96 109 0 0 +10 36 46 60 93 107 111 133 0 +4 35 54 56 74 100 117 138 0 +6 34 39 66 87 93 118 138 0 +7 34 48 55 83 96 120 139 0 +12 35 42 68 79 105 112 141 0 +2 31 51 67 79 107 116 128 0 +1 29 40 73 90 101 125 138 0 +3 19 37 72 87 99 122 139 0 +12 26 45 65 73 92 121 137 0 +14 30 42 66 74 109 114 140 0 +1 36 48 56 81 97 116 134 0 +7 19 50 62 91 107 109 143 0 +17 23 56 70 78 93 120 129 0 +8 36 53 68 86 108 123 142 0 +4 21 39 70 89 98 123 132 0 +18 27 54 66 81 104 106 137 0 +8 31 49 57 82 93 124 127 0 +9 37 43 73 84 95 126 131 0 +18 34 45 72 88 94 116 141 0 +11 21 52 64 79 103 124 135 0 +5 32 41 65 90 97 126 128 0 +16 28 43 60 76 83 127 144 0 diff --git a/lib/ldpc/peg/peg2alist b/lib/ldpc/peg/peg2alist new file mode 100755 index 00000000..da710f92 --- /dev/null +++ b/lib/ldpc/peg/peg2alist @@ -0,0 +1,37 @@ +#!/opt/local/bin/octave -qf +# read a parity check matrix produced by the peg algorithm and +# convert to alist format so that it can be read using alist_to_pcheck +arg_list=argv(); +filename=arg_list{1}; +fid=fopen(filename,"r"); +N=fscanf(fid,"%d",[1]); +M=fscanf(fid,"%d",[1]); +pcheck=zeros(M,N); +max_bits_in_check=fscanf(fid,"%d",[1]); +for i=1:M + vec=fscanf(fid,"%d",[max_bits_in_check]); + pcheck(i,vec(vec>0))=1; +endfor + +max_bits_in_check2=max(sum(pcheck')); +max_checks_per_bit=max(sum(pcheck)); +printf("%d %d\n",M,N); +printf("%d %d\n",max_bits_in_check2,max_checks_per_bit); +printf("%d ",sum(pcheck')); +printf("\n"); +printf("%d ",sum(pcheck)); +printf("\n"); +for i=1:M + vec=find(pcheck(i,:)>0); + pr=zeros(1,max_bits_in_check2); + pr(1:size(vec)(2))=vec; + printf("%d ",pr); + printf("\n"); +endfor +for i=1:N + vec=find(pcheck(:,i)>0); + pr=zeros(1,max_checks_per_bit); + pr(1:size(vec)(1))=vec; + printf("%d ",pr) + printf("\n"); +endfor diff --git a/lib/ldpc/peg/peg_128_80.pchk b/lib/ldpc/peg/peg_128_80.pchk new file mode 100644 index 00000000..c3dc1b1b --- /dev/null +++ b/lib/ldpc/peg/peg_128_80.pchk @@ -0,0 +1,51 @@ +128 +48 +9 +1 17 34 51 66 81 99 111 124 +2 18 35 50 67 82 100 112 125 +3 19 36 52 68 82 101 111 126 +2 20 36 51 69 83 102 113 127 +4 19 37 53 66 84 103 114 128 +5 21 38 54 70 85 92 114 0 +6 22 39 55 66 85 96 110 0 +7 23 32 56 71 86 103 115 0 +8 20 40 55 72 86 104 116 0 +9 19 41 57 73 87 105 116 0 +10 24 36 56 74 88 105 117 125 +10 17 33 47 75 89 106 118 128 +11 21 42 51 76 87 107 119 0 +1 25 40 58 74 84 107 113 0 +12 22 42 49 77 90 108 118 125 +13 26 43 59 68 89 104 120 124 +13 22 44 57 75 91 109 113 0 +12 23 37 46 78 88 107 112 0 +3 27 34 60 65 87 109 118 0 +6 27 45 61 79 89 98 112 0 +14 28 34 62 72 92 106 112 127 +8 27 42 59 71 92 110 121 126 +15 20 46 57 79 93 101 115 124 +9 29 45 62 74 94 108 121 0 +8 30 38 63 73 95 109 111 128 +16 29 47 64 69 96 109 117 126 +16 23 48 63 76 94 110 116 125 +7 25 39 52 70 97 106 117 124 +4 26 45 63 67 83 90 119 123 +15 28 39 50 76 88 103 121 123 +15 26 33 58 65 97 102 122 0 +14 31 47 52 77 81 93 116 0 +14 24 37 61 71 82 99 122 0 +4 31 40 54 80 91 106 115 122 +5 32 41 58 77 98 104 117 0 +9 18 49 65 79 85 104 119 128 +10 30 43 60 69 84 108 115 123 +1 18 43 48 73 91 98 114 127 +3 21 46 64 67 86 108 113 0 +5 24 48 55 75 93 107 120 126 +2 32 44 62 80 95 99 114 0 +16 28 41 59 80 83 100 118 0 +11 33 35 53 72 96 105 111 0 +11 25 44 60 78 90 100 120 122 +6 31 35 56 70 95 102 121 0 +12 17 50 54 68 94 105 119 0 +13 29 38 53 78 97 110 123 0 +7 30 49 61 64 81 101 120 127 diff --git a/lib/ldpc/peg/sfpeg1.code b/lib/ldpc/peg/sfpeg1.code new file mode 100644 index 00000000..c3dc1b1b --- /dev/null +++ b/lib/ldpc/peg/sfpeg1.code @@ -0,0 +1,51 @@ +128 +48 +9 +1 17 34 51 66 81 99 111 124 +2 18 35 50 67 82 100 112 125 +3 19 36 52 68 82 101 111 126 +2 20 36 51 69 83 102 113 127 +4 19 37 53 66 84 103 114 128 +5 21 38 54 70 85 92 114 0 +6 22 39 55 66 85 96 110 0 +7 23 32 56 71 86 103 115 0 +8 20 40 55 72 86 104 116 0 +9 19 41 57 73 87 105 116 0 +10 24 36 56 74 88 105 117 125 +10 17 33 47 75 89 106 118 128 +11 21 42 51 76 87 107 119 0 +1 25 40 58 74 84 107 113 0 +12 22 42 49 77 90 108 118 125 +13 26 43 59 68 89 104 120 124 +13 22 44 57 75 91 109 113 0 +12 23 37 46 78 88 107 112 0 +3 27 34 60 65 87 109 118 0 +6 27 45 61 79 89 98 112 0 +14 28 34 62 72 92 106 112 127 +8 27 42 59 71 92 110 121 126 +15 20 46 57 79 93 101 115 124 +9 29 45 62 74 94 108 121 0 +8 30 38 63 73 95 109 111 128 +16 29 47 64 69 96 109 117 126 +16 23 48 63 76 94 110 116 125 +7 25 39 52 70 97 106 117 124 +4 26 45 63 67 83 90 119 123 +15 28 39 50 76 88 103 121 123 +15 26 33 58 65 97 102 122 0 +14 31 47 52 77 81 93 116 0 +14 24 37 61 71 82 99 122 0 +4 31 40 54 80 91 106 115 122 +5 32 41 58 77 98 104 117 0 +9 18 49 65 79 85 104 119 128 +10 30 43 60 69 84 108 115 123 +1 18 43 48 73 91 98 114 127 +3 21 46 64 67 86 108 113 0 +5 24 48 55 75 93 107 120 126 +2 32 44 62 80 95 99 114 0 +16 28 41 59 80 83 100 118 0 +11 33 35 53 72 96 105 111 0 +11 25 44 60 78 90 100 120 122 +6 31 35 56 70 95 102 121 0 +12 17 50 54 68 94 105 119 0 +13 29 38 53 78 97 110 123 0 +7 30 49 61 64 81 101 120 127 diff --git a/lib/ldpc/peg/sfpeg1.deg b/lib/ldpc/peg/sfpeg1.deg new file mode 100644 index 00000000..7d208a69 --- /dev/null +++ b/lib/ldpc/peg/sfpeg1.deg @@ -0,0 +1,3 @@ +2 +3 4 +.8 .2 diff --git a/lib/ldpc/peg/sfpeg2.alist b/lib/ldpc/peg/sfpeg2.alist new file mode 100644 index 00000000..410bae7e --- /dev/null +++ b/lib/ldpc/peg/sfpeg2.alist @@ -0,0 +1,180 @@ +48 128 +9 4 +9 9 8 8 8 8 8 8 8 8 8 9 8 9 8 8 8 9 8 8 9 8 8 9 8 8 8 9 8 8 9 8 8 8 9 8 9 8 8 8 8 8 8 8 9 8 8 8 +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 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 4 4 4 4 4 4 4 4 4 4 4 4 +1 17 34 51 66 81 99 113 127 +2 18 35 50 67 82 100 114 128 +3 19 36 52 68 82 101 115 0 +2 20 36 51 69 83 102 116 0 +4 19 37 53 66 84 103 117 0 +5 21 38 54 70 85 92 114 0 +6 22 39 55 66 85 96 118 0 +7 23 32 56 71 86 103 119 0 +8 20 40 55 72 86 104 120 0 +9 19 41 57 73 87 105 118 0 +10 24 36 56 74 88 106 120 0 +10 17 33 47 75 89 107 121 126 +11 21 42 51 76 87 108 122 0 +1 25 40 58 74 84 109 122 126 +12 22 42 49 77 90 110 123 0 +13 26 43 59 68 89 104 113 0 +13 22 44 57 75 91 106 124 0 +12 23 37 46 78 88 109 113 128 +3 27 34 60 65 87 111 123 0 +6 27 45 61 79 89 98 114 0 +14 28 34 62 72 92 107 122 125 +8 27 42 59 71 92 112 117 0 +15 20 46 57 79 93 101 117 0 +9 29 45 62 74 94 108 119 128 +8 30 38 63 73 95 110 124 0 +16 29 47 64 69 96 110 125 0 +16 23 48 63 76 94 111 120 0 +7 25 39 52 70 97 108 116 127 +4 26 45 63 67 83 90 121 0 +15 28 39 50 76 88 103 115 0 +15 26 33 58 65 97 102 125 128 +14 31 47 52 77 81 93 120 0 +14 24 37 61 71 82 99 116 0 +4 31 40 54 80 91 107 119 0 +5 32 41 58 77 98 111 124 127 +9 18 49 65 79 85 104 124 0 +10 30 43 60 69 84 112 119 127 +1 18 43 48 73 91 98 121 0 +3 21 46 64 67 86 112 118 0 +5 24 48 55 75 93 105 122 0 +2 32 44 62 80 95 99 118 0 +16 28 41 59 80 83 100 123 0 +11 33 35 53 72 96 109 115 0 +11 25 44 60 78 90 100 117 0 +6 31 35 56 70 95 102 123 126 +12 17 50 54 68 94 106 125 0 +13 29 38 53 78 97 105 121 0 +7 30 49 61 64 81 101 126 0 +1 14 38 0 +2 4 41 0 +3 19 39 0 +5 29 34 0 +6 35 40 0 +7 20 45 0 +8 28 48 0 +9 22 25 0 +10 24 36 0 +11 12 37 0 +13 43 44 0 +15 18 46 0 +16 17 47 0 +21 32 33 0 +23 30 31 0 +26 27 42 0 +1 12 46 0 +2 36 38 0 +3 5 10 0 +4 9 23 0 +6 13 39 0 +7 15 17 0 +8 18 27 0 +11 33 40 0 +14 28 44 0 +16 29 31 0 +19 20 22 0 +21 30 42 0 +24 26 47 0 +25 37 48 0 +32 34 45 0 +8 35 41 0 +12 31 43 0 +1 19 21 0 +2 43 45 0 +3 4 11 0 +5 18 33 0 +6 25 47 0 +7 28 30 0 +9 14 34 0 +10 35 42 0 +13 15 22 0 +16 37 38 0 +17 41 44 0 +20 24 29 0 +18 23 39 0 +12 26 32 0 +27 38 40 0 +15 36 48 0 +2 30 46 0 +1 4 13 0 +3 28 32 0 +5 43 47 0 +6 34 46 0 +7 9 40 0 +8 11 45 0 +10 17 23 0 +14 31 35 0 +16 22 42 0 +19 37 44 0 +20 33 48 0 +21 24 41 0 +25 27 29 0 +26 39 48 0 +19 31 36 0 +1 5 7 0 +2 29 39 0 +3 16 46 0 +4 26 37 0 +6 28 45 0 +8 22 33 0 +9 21 43 0 +10 25 38 0 +11 14 24 0 +12 17 40 0 +13 27 30 0 +15 32 35 0 +18 44 47 0 +20 23 36 0 +34 41 42 0 +1 32 48 0 +2 3 33 0 +4 29 42 0 +5 14 37 0 +6 7 36 0 +8 9 39 0 +10 13 19 0 +11 18 30 0 +12 16 20 0 +15 29 44 0 +17 34 38 0 +6 21 22 0 +23 32 40 0 +24 27 46 0 +25 41 45 0 +7 26 43 0 +28 31 47 0 +20 35 38 0 +1 33 41 0 +2 42 44 0 +3 23 48 0 +4 31 45 0 +5 8 30 0 +9 16 36 0 +10 40 47 0 +11 17 46 0 +12 21 34 0 +13 24 28 0 +14 18 43 0 +15 25 26 0 +19 27 35 0 +22 37 39 0 +1 16 18 0 +2 6 20 0 +3 30 43 0 +4 28 33 0 +5 22 23 44 +7 10 39 41 +8 24 34 37 +9 11 27 32 +12 29 38 47 +13 14 21 40 +15 19 42 45 +17 25 35 36 +21 26 31 46 +12 14 45 48 +1 28 35 37 +2 18 24 31 diff --git a/lib/ldpc/peg/sfpeg2.code b/lib/ldpc/peg/sfpeg2.code new file mode 100644 index 00000000..0082bd37 --- /dev/null +++ b/lib/ldpc/peg/sfpeg2.code @@ -0,0 +1,51 @@ +128 +48 +9 +1 17 34 51 66 81 99 113 127 +2 18 35 50 67 82 100 114 128 +3 19 36 52 68 82 101 115 0 +2 20 36 51 69 83 102 116 0 +4 19 37 53 66 84 103 117 0 +5 21 38 54 70 85 92 114 0 +6 22 39 55 66 85 96 118 0 +7 23 32 56 71 86 103 119 0 +8 20 40 55 72 86 104 120 0 +9 19 41 57 73 87 105 118 0 +10 24 36 56 74 88 106 120 0 +10 17 33 47 75 89 107 121 126 +11 21 42 51 76 87 108 122 0 +1 25 40 58 74 84 109 122 126 +12 22 42 49 77 90 110 123 0 +13 26 43 59 68 89 104 113 0 +13 22 44 57 75 91 106 124 0 +12 23 37 46 78 88 109 113 128 +3 27 34 60 65 87 111 123 0 +6 27 45 61 79 89 98 114 0 +14 28 34 62 72 92 107 122 125 +8 27 42 59 71 92 112 117 0 +15 20 46 57 79 93 101 117 0 +9 29 45 62 74 94 108 119 128 +8 30 38 63 73 95 110 124 0 +16 29 47 64 69 96 110 125 0 +16 23 48 63 76 94 111 120 0 +7 25 39 52 70 97 108 116 127 +4 26 45 63 67 83 90 121 0 +15 28 39 50 76 88 103 115 0 +15 26 33 58 65 97 102 125 128 +14 31 47 52 77 81 93 120 0 +14 24 37 61 71 82 99 116 0 +4 31 40 54 80 91 107 119 0 +5 32 41 58 77 98 111 124 127 +9 18 49 65 79 85 104 124 0 +10 30 43 60 69 84 112 119 127 +1 18 43 48 73 91 98 121 0 +3 21 46 64 67 86 112 118 0 +5 24 48 55 75 93 105 122 0 +2 32 44 62 80 95 99 118 0 +16 28 41 59 80 83 100 123 0 +11 33 35 53 72 96 109 115 0 +11 25 44 60 78 90 100 117 0 +6 31 35 56 70 95 102 123 126 +12 17 50 54 68 94 106 125 0 +13 29 38 53 78 97 105 121 0 +7 30 49 61 64 81 101 126 0 diff --git a/lib/ldpc/peg/sfpeg2.deg b/lib/ldpc/peg/sfpeg2.deg new file mode 100644 index 00000000..fb023b77 --- /dev/null +++ b/lib/ldpc/peg/sfpeg2.deg @@ -0,0 +1,3 @@ +2 +3 4 +.9 .1 diff --git a/lib/ldpc/peg/sfpeg3.alist b/lib/ldpc/peg/sfpeg3.alist new file mode 100644 index 00000000..e2d9e15f --- /dev/null +++ b/lib/ldpc/peg/sfpeg3.alist @@ -0,0 +1,180 @@ +48 128 +8 3 +8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 +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 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 +1 17 34 51 66 81 99 113 +2 18 35 50 67 82 100 114 +3 19 36 52 68 82 101 115 +2 20 36 51 69 83 102 116 +4 19 37 53 66 84 103 117 +5 21 38 54 70 85 92 114 +6 22 39 55 66 85 96 118 +7 23 32 56 71 86 103 119 +8 20 40 55 72 86 104 120 +9 19 41 57 73 87 105 121 +10 24 36 56 74 88 106 122 +10 17 33 47 75 89 107 119 +11 21 42 51 76 87 108 123 +1 25 40 58 74 84 109 124 +12 22 42 49 77 90 110 122 +13 26 43 59 68 89 104 113 +13 22 44 57 75 91 106 125 +12 23 37 46 78 88 109 113 +3 27 34 60 65 87 111 126 +6 27 45 61 79 89 98 114 +14 28 34 62 72 92 107 125 +8 27 42 59 71 92 112 117 +15 20 46 57 79 93 101 117 +9 29 45 62 74 94 108 127 +8 30 38 63 73 95 110 125 +16 29 47 64 69 96 110 128 +16 23 48 63 76 94 111 121 +7 25 39 52 70 97 108 116 +4 26 45 63 67 83 90 126 +15 28 39 50 76 88 103 115 +15 26 33 58 65 97 102 127 +14 31 47 52 77 81 93 121 +14 24 37 61 71 82 99 116 +4 31 40 54 80 91 107 122 +5 32 41 58 77 98 111 120 +9 18 49 65 79 85 104 123 +10 30 43 60 69 84 112 123 +1 18 43 48 73 91 98 119 +3 21 46 64 67 86 112 118 +5 24 48 55 75 93 105 128 +2 32 44 62 80 95 99 124 +16 28 41 59 80 83 100 118 +11 33 35 53 72 96 109 115 +11 25 44 60 78 90 100 128 +6 31 35 56 70 95 102 126 +12 17 50 54 68 94 106 120 +13 29 38 53 78 97 105 124 +7 30 49 61 64 81 101 127 +1 14 38 +2 4 41 +3 19 39 +5 29 34 +6 35 40 +7 20 45 +8 28 48 +9 22 25 +10 24 36 +11 12 37 +13 43 44 +15 18 46 +16 17 47 +21 32 33 +23 30 31 +26 27 42 +1 12 46 +2 36 38 +3 5 10 +4 9 23 +6 13 39 +7 15 17 +8 18 27 +11 33 40 +14 28 44 +16 29 31 +19 20 22 +21 30 42 +24 26 47 +25 37 48 +32 34 45 +8 35 41 +12 31 43 +1 19 21 +2 43 45 +3 4 11 +5 18 33 +6 25 47 +7 28 30 +9 14 34 +10 35 42 +13 15 22 +16 37 38 +17 41 44 +20 24 29 +18 23 39 +12 26 32 +27 38 40 +15 36 48 +2 30 46 +1 4 13 +3 28 32 +5 43 47 +6 34 46 +7 9 40 +8 11 45 +10 17 23 +14 31 35 +16 22 42 +19 37 44 +20 33 48 +21 24 41 +25 27 29 +26 39 48 +19 31 36 +1 5 7 +2 29 39 +3 16 46 +4 26 37 +6 28 45 +8 22 33 +9 21 43 +10 25 38 +11 14 24 +12 17 40 +13 27 30 +15 32 35 +18 44 47 +20 23 36 +34 41 42 +1 32 48 +2 3 33 +4 29 42 +5 14 37 +6 7 36 +8 9 39 +10 13 19 +11 18 30 +12 16 20 +15 29 44 +17 34 38 +6 21 22 +23 32 40 +24 27 46 +25 41 45 +7 26 43 +28 31 47 +20 35 38 +1 33 41 +2 42 44 +3 23 48 +4 31 45 +5 8 30 +9 16 36 +10 40 47 +11 17 46 +12 21 34 +13 24 28 +14 18 43 +15 25 26 +19 27 35 +22 37 39 +1 16 18 +2 6 20 +3 30 43 +4 28 33 +5 22 23 +7 39 42 +8 12 38 +9 35 46 +10 27 32 +11 15 34 +13 36 37 +14 41 47 +17 21 25 +19 29 45 +24 31 48 +26 40 44 diff --git a/lib/ldpc/peg/sfpeg3.code b/lib/ldpc/peg/sfpeg3.code new file mode 100644 index 00000000..10064e07 --- /dev/null +++ b/lib/ldpc/peg/sfpeg3.code @@ -0,0 +1,51 @@ +128 +48 +8 +1 17 34 51 66 81 99 113 +2 18 35 50 67 82 100 114 +3 19 36 52 68 82 101 115 +2 20 36 51 69 83 102 116 +4 19 37 53 66 84 103 117 +5 21 38 54 70 85 92 114 +6 22 39 55 66 85 96 118 +7 23 32 56 71 86 103 119 +8 20 40 55 72 86 104 120 +9 19 41 57 73 87 105 121 +10 24 36 56 74 88 106 122 +10 17 33 47 75 89 107 119 +11 21 42 51 76 87 108 123 +1 25 40 58 74 84 109 124 +12 22 42 49 77 90 110 122 +13 26 43 59 68 89 104 113 +13 22 44 57 75 91 106 125 +12 23 37 46 78 88 109 113 +3 27 34 60 65 87 111 126 +6 27 45 61 79 89 98 114 +14 28 34 62 72 92 107 125 +8 27 42 59 71 92 112 117 +15 20 46 57 79 93 101 117 +9 29 45 62 74 94 108 127 +8 30 38 63 73 95 110 125 +16 29 47 64 69 96 110 128 +16 23 48 63 76 94 111 121 +7 25 39 52 70 97 108 116 +4 26 45 63 67 83 90 126 +15 28 39 50 76 88 103 115 +15 26 33 58 65 97 102 127 +14 31 47 52 77 81 93 121 +14 24 37 61 71 82 99 116 +4 31 40 54 80 91 107 122 +5 32 41 58 77 98 111 120 +9 18 49 65 79 85 104 123 +10 30 43 60 69 84 112 123 +1 18 43 48 73 91 98 119 +3 21 46 64 67 86 112 118 +5 24 48 55 75 93 105 128 +2 32 44 62 80 95 99 124 +16 28 41 59 80 83 100 118 +11 33 35 53 72 96 109 115 +11 25 44 60 78 90 100 128 +6 31 35 56 70 95 102 126 +12 17 50 54 68 94 106 120 +13 29 38 53 78 97 105 124 +7 30 49 61 64 81 101 127 diff --git a/lib/ldpc/peg/sfpeg3.deg b/lib/ldpc/peg/sfpeg3.deg new file mode 100644 index 00000000..0fb5a574 --- /dev/null +++ b/lib/ldpc/peg/sfpeg3.deg @@ -0,0 +1,3 @@ +1 +3 +1.0 diff --git a/lib/ldpc/print-gen.c b/lib/ldpc/print-gen.c new file mode 100755 index 00000000..53d339e7 --- /dev/null +++ b/lib/ldpc/print-gen.c @@ -0,0 +1,139 @@ +/* PRINT-CODE.C - Print a Low Density Parity Check code's matrices. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include +#include + +#include "rand.h" +#include "alloc.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" + +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + char *gen_file; + int dprint; + int i, j; + + dprint = 0; + if (argc>1 && strcmp(argv[1],"-d")==0) + { dprint = 1; + argc -= 1; + argv += 1; + } + + if (!(gen_file = argv[1]) || argv[2]) + { usage(); + } + + read_gen(gen_file,0,1); + + switch (type) + { + case 's': + { + printf("\nGenerator matrix in %s (sparse representation):\n\n",gen_file); + + printf("Column order (message bits at end):\n"); + for (j = 0; j +#include +#include +#include + +#include "rand.h" +#include "alloc.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" + +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + mod2dense *D; + mod2sparse *T; + + char *pchk_file; + int dprint, trans; + + dprint = 0; + trans = 0; + + for (;;) + { + if (argc>1 && strcmp(argv[1],"-d")==0) + { dprint = 1; + argc -= 1; + argv += 1; + } + else if (argc>1 && strcmp(argv[1],"-t")==0) + { trans = 1; + argc -= 1; + argv += 1; + } + else + { break; + } + } + + if (!(pchk_file = argv[1]) || argv[2]) + { usage(); + } + + read_pchk(pchk_file); + + if (trans) + { T = mod2sparse_allocate(N,M); + mod2sparse_transpose(H,T); + } + + if (dprint) + { if (trans) + { D = mod2dense_allocate(N,M); + mod2sparse_to_dense(T,D); + printf("\nTranspose of parity check matrix in %s (dense format):\n\n", + pchk_file); + mod2dense_print(stdout,D); + } + else + { D = mod2dense_allocate(M,N); + mod2sparse_to_dense(H,D); + printf("\nParity check matrix in %s (dense format):\n\n",pchk_file); + mod2dense_print(stdout,D); + } + } + else /* sparse */ + { if (trans) + { printf("\nTranspose of parity check matrix in %s (sparse format):\n\n", + pchk_file); + mod2sparse_print(stdout,T); + } + else + { printf("\nParity check matrix in %s (sparse format):\n\n",pchk_file); + mod2sparse_print(stdout,H); + } + } + + printf("\n"); + + return 0; +} + + +/* PRINT USAGE MESSAGE AND EXIT. */ + +void usage(void) +{ fprintf(stderr,"Usage: print-pchk [ -d ] [ -t ] pchk-file\n"); + exit(1); +} diff --git a/lib/ldpc/progs.html b/lib/ldpc/progs.html new file mode 100755 index 00000000..8bb50d35 --- /dev/null +++ b/lib/ldpc/progs.html @@ -0,0 +1,80 @@ + + + Programs for Low Density Parity Check Codes + + + + +

Programs for Low Density Parity Check Codes

+ +Programs are available for creating LDPC codes, encoding messages, +simulating transmission through a channel, and decoding the received +message. There are links here to the general documentation on each of +these operations, and to the detailed documentation on the relevant +programs. + +

The programs names below are followed by the form of arguments they +take; a similar usage message is displayed when a program is run with +no arguments. In these descriptions, things to be entered literally +are in roman font, descriptions of something to be supplied are in +italic. Arguments in square brackets are optional. A vertical bar +separates alternatives. Dots represent indefinite repetition. + +

Many of the arguments are file names, which can be a dash ("-") in +order to specify that standard input or standard output is to be used. +(However, you can't use standard input or output for more than one thing.) + +

Click on a main title below for general information on that aspect +of the software, or on the name of a program for detailed information. + +

Creating a parity check matrix for a code: +

+make-pchk pchk-file n-checks n-bits row:col ...
+
+alist-to-pchk [ -t ] alist-file pchk-file
+
+pchk-to-alist [ -t ] [ -z ] pchk-file alist-file
+
+print-pchk [ -d ] [ -t ] pchk-file
+
+make-ldpc pchk-file n-checks n-bits seed method
+
+ +

Encoding message blocks as codewords: +

+make-gen pchk-file gen-file method
+
+print-gen [ -d ] gen-file 
+
+encode [ -f ] pchk-file gen-file source-file encoded-file
+
+ +

Transmitting bits through a simulated channel: +

+transmit encoded-file|n-zeros received-file seed channel
+
+ +

Decoding received blocks: +

+decode [ -f ] [ -t | -T ] pchk-file received-file decoded-file [ bp-file ] channel method
+
+extract gen-file decoded-file extracted-file
+
+ +

Support programs: +

+rand-src source-file seed n-bits
+
+verify [ -t ] pchk-file decoded-file [ gen-file [ source-file ] ]
+
+ +See also the discussions of linear dependence in +parity check matrices and of sparse LU +decomposition methods, and the examples +of program usage. + +
+ +Back to index for LDPC software + + diff --git a/lib/ldpc/rand-src.c b/lib/ldpc/rand-src.c new file mode 100755 index 00000000..31a2410d --- /dev/null +++ b/lib/ldpc/rand-src.c @@ -0,0 +1,86 @@ +/* RAND-SRC.C - Generate random message bits. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include + +#include "open.h" +#include "rand.h" + +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + int seed, bs, nb; + char *file, *n_bits; + char junk; + int i, j; + FILE *f; + + if (!(file = argv[1]) + || !argv[2] || sscanf(argv[2],"%d%c",&seed,&junk)!=1 + || !(n_bits = argv[3]) + || argv[4]) + { usage(); + } + + if (sscanf(n_bits,"%d%c",&nb,&junk)==1) + { if (nb<=0) usage(); + bs = 1; + } + else if (sscanf(n_bits,"%dx%d%c",&bs,&nb,&junk)==2) + { if (nb<=0 || bs<=0) usage(); + } + else + { usage(); + } + + f = open_file_std(file,"w"); + if (f==NULL) + { fprintf(stderr,"Can't create source file: %s\n",file); + exit(1); + } + + rand_seed(10*seed+2); + + for (i = 0; i +#include +#include +#include + +#include "rand.h" + + +#define Max_bins 1000 /* Maximum number of histogram bins */ + +static void usage (void); + + +/* MAIN PROGRAM. */ + +main +( int argc, + char **argv +) +{ + int seed, sample_size, bins, np; + double low, high; + char *generator; + double p1, p2; + + double mean, variance; + double tmean, tvariance; + int undef_mean, undef_variance; + + int count[Max_bins]; + int under, over; + + char **ap; + double x; + int i, n; + + bins = 0; + + if (argc<5) usage(); + + if ((seed = atoi(argv[1]))==0 && strcmp(argv[1],"0")!=0) usage(); + + generator = argv[2]; + + if (strcmp(generator,"uniform")==0) np = 0; + else if (strcmp(generator,"uniopen")==0) np = 0; + else if (strcmp(generator,"int")==0) np = 1; + else if (strcmp(generator,"poisson")==0) np = 1; + else if (strcmp(generator,"gaussian")==0) np = 0; + else if (strcmp(generator,"exp")==0) np = 0; + else if (strcmp(generator,"cauchy")==0) np = 0; + else if (strcmp(generator,"gamma")==0) np = 1; + else if (strcmp(generator,"beta")==0) np = 2; + else + { fprintf(stderr,"Unknown generator: %s\n",generator); + exit(1); + } + + ap = argv+3; + + if (np>0) + { if (*ap==0 || (p1 = atof(*ap++))<=0) usage(); + } + if (np>1) + { if (*ap==0 || (p2 = atof(*ap++))<=0) usage(); + } + + if (*ap==0 || strcmp(*ap++,"/")!=0) usage(); + + if (*ap==0 || (sample_size = atoi(*ap++))<=0) usage(); + + if (*ap!=0) + { low = atof(*ap++); + if (*ap==0) usage(); + high = atof(*ap++); + if (high<=low) usage(); + if (*ap==0 || (bins = atoi(*ap++))<=0) usage(); + if (bins>Max_bins) + { fprintf(stderr,"Too many histogram bins\n"); + exit(1); + } + } + + if (*ap!=0) usage(); + + printf("\nTest of %s(",generator); + if (np>0) printf("%.4f",p1); + if (np>1) printf(",%.4f",p2); + printf(") generator using sample of size %d with seed %d\n\n", + sample_size, seed); + + undef_mean = undef_variance = 0; + + if (strcmp(generator,"uniform")==0) + { tmean = 0.5; + tvariance = 1.0/12.0; + } + else if (strcmp(generator,"uniopen")==0) + { tmean = 0.5; + tvariance = 1.0/12.0; + } + else if (strcmp(generator,"int")==0) + { tmean = (p1-1)/2; + tvariance = p1*p1/3.0 - p1/2.0 + 1/6.0 - tmean*tmean; + } + else if (strcmp(generator,"poisson")==0) + { tmean = p1; + tvariance = p1; + } + else if (strcmp(generator,"gaussian")==0) + { tmean = 0; + tvariance = 1; + } + else if (strcmp(generator,"exp")==0) + { tmean = 1; + tvariance = 1; + } + else if (strcmp(generator,"cauchy")==0) + { undef_mean = 1; + undef_variance = 1; + } + else if (strcmp(generator,"gamma")==0) + { tmean = p1; + tvariance = p1; + } + else if (strcmp(generator,"beta")==0) + { tmean = p1 / (p1+p2); + tvariance = (p1*p2) / ((p1+p2)*(p1+p2)*(p1+p2+1)); + } + else + { abort(); + } + + mean = 0; + variance = 0; + + if (bins>0) + { for (i = 0; i0) + { if (x=bins) + { over += 1; + } + else + { count[i] += 1; + } + } + } + } + + mean /= sample_size; + variance /= sample_size; + variance -= mean*mean; + + printf("Sample mean: %.4f",mean); + if (undef_mean) + { printf(" (true value: undefined)\n"); + } + else + { printf(" (true value: %.4f)\n",tmean); + } + + printf("Sample variance: %.4f",variance); + if (undef_variance) + { printf(" (true value: undefined)\n"); + } + else + { printf(" (true value: %.4f)\n",tvariance); + } + printf("\n"); + + if (bins!=0) + { printf("Histogram:\n"); + printf(" under : %8d %.5f\n\n", + under, (double)under / sample_size); + for (i = 0; i +#include +#include +#include +#include + +#include "rand.h" + + +static long int this_nrand48 (unsigned short int [3]); + /* Local version of nrand48 */ + + +/* This module uses the 'this_nrand48' pseudo-random number generator from the + GNU C library, included below, but renamed to 'this_nrand48'. The + output of this generator is combined with a file of real random numbers. + + Many of the methods used in this module may be found in the following + reference: + + Devroye, L. (1986) Non-Uniform Random Variate Generation, + New York: Springer-Verlag. + + The methods used here are not necessarily the fastest available. They're + selected to be reasonably fast while also being easy to write. +*/ + + +/* CONSTANT PI. Defined here if not in . */ + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + + +/* TABLES OF REAL RANDOM NUMBERS. A file of 100000 real random numbers + (NOT pseudo-random) is used in conjunction with pseudo-random numbers + for extra insurance. These are employed in the form of five tables + of 5000 32-bit integers. + + The file must be located at the path given by RAND_FILE, which should + be defined on the "cc" command line. */ + +#define Table_size 5000 /* Number of words in each table */ + +static int rn[N_tables][Table_size]; /* Random number tables */ + + +/* STATE OF RANDOM NUMBER GENERATOR. */ + +static int initialized = 0; /* Has module been initialized? */ + +static rand_state state0; /* Default state structure */ + +static rand_state *state; /* Pointer to current state */ + + +/* INITIALIZE MODULE. Sets things up using the default state structure, + set as if rand_seed had been called with a seed of one. */ + +static void initialize (void) +{ + int i, j, k, w; + char b; + FILE *f; + + if (!initialized) + { + f = fopen(RAND_FILE,"rb"); + + if (f==NULL) + { fprintf(stderr,"Can't open file of random numbers (%s)\n",RAND_FILE); + exit(1); + } + + for (i = 0; iseed = seed; + + state->state48[0] = seed>>16; + state->state48[1] = seed&0xffff; + state->state48[2] = rn[0][(seed&0x7fffffff)%Table_size]; + + for (j = 0; jptr[j] = seed%Table_size; + seed /= Table_size; + } +} + + +/* SET STATE STRUCTURE TO USE. */ + +void rand_use_state +( rand_state *st +) +{ + if (!initialized) initialize(); + + state = st; +} + + +/* RETURN POINTER TO CURRENT STATE. */ + +rand_state *rand_get_state (void) +{ + if (!initialized) initialize(); + + return state; +} + + +/* GENERATE RANDOM 31-BIT INTEGER. Not really meant for use outside this + module. */ + +int rand_word(void) +{ + int v; + int j; + + if (!initialized) initialize(); + + v = this_nrand48(state->state48); + + for (j = 0; jptr[j]]; + } + + for (j = 0; jptr[j]==Table_size-1; j++) + { state->ptr[j] = 0; + } + + if (jptr[j] += 1; + } + + return v & 0x7fffffff; +} + + +/* GENERATE UNIFORMLY FROM [0,1). */ + +double rand_uniform (void) +{ + return (double)rand_word() / (1.0+(double)0x7fffffff); +} + + +/* GENERATE UNIFORMLY FORM (0,1). */ + +double rand_uniopen (void) +{ + return (0.5+(double)rand_word()) / (1.0+(double)0x7fffffff); +} + + +/* GENERATE RANDOM INTEGER FROM 0, 1, ..., (n-1). */ + +int rand_int +( int n +) +{ + return (int) (n * rand_uniform()); +} + + +/* GENERATE INTEGER FROM 0, 1, ..., (n-1), WITH GIVEN DISTRIBUTION. */ + +int rand_pickd +( double *p, + int n +) +{ + double t, r; + int i; + + t = 0; + for (i = 0; i0) return i; + } + + abort(); +} + + +/* SAME PROCEDURE AS ABOVE, BUT WITH FLOAT ARGUMENT. */ + +int rand_pickf +( float *p, + int n +) +{ + double t, r; + int i; + + t = 0; + for (i = 0; i0) return i; + } + + abort(); +} + + +/* GENERATE RANDOM PERMUTATION OF INTEGERS FROM 1 TO N. */ + +void rand_permutation +( int *perm, /* Place to store permutation */ + int n /* Number of integers to permute */ +) +{ + int i, j, t; + + for (i = 0; i10000) + { v = (int) (lambda + rand_gaussian()*sqrt(lambda) + 0.5); + } + else + { v = 0; + for (;;) + { lambda -= rand_exp(); + if (lambda<=0) break; + v += 1; + } + } + return v; +} + + +/* GAUSSIAN GENERATOR. Done by using the Box-Muller method, but only one + of the variates is retained (using both would require saving more state). + See Devroye, p. 235. + + As written, should never deliver exactly zero, which may sometimes be + helpful. */ + +double rand_gaussian (void) +{ + double a, b; + + a = rand_uniform(); + b = rand_uniopen(); + + return cos(2.0*M_PI*a) * sqrt(-2.0*log(b)); +} + + +/* EXPONENTIAL GENERATOR. See Devroye, p. 29. Written so as to never + return exactly zero. */ + +double rand_exp (void) +{ + return -log(rand_uniopen()); +} + + +/* LOGISTIC GENERATOR. Just inverts the CDF. */ + +double rand_logistic (void) +{ double u; + u = rand_uniopen(); + return log(u/(1-u)); +} + + +/* CAUCHY GENERATOR. See Devroye, p. 29. */ + +double rand_cauchy (void) +{ + return tan (M_PI * (rand_uniopen()-0.5)); +} + + +/* GAMMA GENERATOR. Generates a positive real number, r, with density + proportional to r^(a-1) * exp(-r). See Devroye, p. 410 and p. 420. + Things are fiddled to avoid ever returning a value that is very near + zero. */ + +double rand_gamma +( double a +) +{ + double b, c, X, Y, Z, U, V, W; + + if (a<0.00001) + { X = a; + } + + else if (a<=1) + { + U = rand_uniopen(); + X = rand_gamma(1+a) * pow(U,1/a); + } + + else if (a<1.00001) + { X = rand_exp(); + } + + else + { + b = a-1; + c = 3*a - 0.75; + + for (;;) + { + U = rand_uniopen(); + V = rand_uniopen(); + + W = U*(1-U); + Y = sqrt(c/W) * (U-0.5); + X = b+Y; + + if (X>=0) + { + Z = 64*W*W*W*V*V; + + if (Z <= 1 - 2*Y*Y/X || log(Z) <= 2 * (b*log(X/b) - Y)) break; + } + } + } + + return X<1e-30 && X=1.0); + + return r; +} + + +/* ROUTINES FROM THE GNU C LIBRARY. These were modified to extract + only the routines used here, and to allow them to be included in + this module without any possible name conflict with other modules. + Inclusion here ensures that these routines are always available, and + operate in exactly the same way on all systems. The routines as copied + below are still easily useable by other programs by simply inserting + this source code into an appropriate source file. + + The following is the copyright notice for these routines: + + Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , August 1995. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + The GNU Lesser General Public License is included with these source + files in the file LGPL. */ + +#include +#include +#include + +struct this_drand48_data + { + unsigned short int x[3]; /* Current state. */ + unsigned short int old_x[3]; /* Old state. */ + unsigned short int c; /* Additive const. in congruential formula. */ + unsigned short int init; /* Flag for initializing. */ + unsigned long long int a; /* Factor in congruential formula. */ + }; + +/* Global state for non-reentrant functions. */ + +struct this_drand48_data libc_this_drand48_data; + +static int this_nrand48_r (unsigned short int xsubi[3], + struct this_drand48_data *buffer, + long int *result); + +/* Internal function to compute next state of the generator. */ + +static int this_drand48_iterate (unsigned short int xsubi[3], + struct this_drand48_data *buffer); + +static long int this_nrand48 (xsubi) + unsigned short int xsubi[3]; +{ + long int result; + + (void) this_nrand48_r (xsubi, &libc_this_drand48_data, &result); + + return result; +} + +static int this_nrand48_r (xsubi, buffer, result) + unsigned short int xsubi[3]; + struct this_drand48_data *buffer; + long int *result; +{ + /* Compute next state. */ + if (this_drand48_iterate (xsubi, buffer) < 0) + return -1; + + /* Store the result. */ + if (sizeof (unsigned short int) == 2) + *result = xsubi[2] << 15 | xsubi[1] >> 1; + else + *result = xsubi[2] >> 1; + + return 0; +} + +static int this_drand48_iterate (xsubi, buffer) + unsigned short int xsubi[3]; + struct this_drand48_data *buffer; +{ + uint64_t X; + uint64_t result; + + /* Initialize buffer, if not yet done. */ + if (!buffer->init) + { + buffer->a = 0x5deece66dull; + buffer->c = 0xb; + buffer->init = 1; + } + + /* Do the real work. We choose a data type which contains at least + 48 bits. Because we compute the modulus it does not care how + many bits really are computed. */ + + X = (uint64_t) xsubi[2] << 32 | (uint32_t) xsubi[1] << 16 | xsubi[0]; + + result = X * buffer->a + buffer->c; + + xsubi[0] = result & 0xffff; + xsubi[1] = (result >> 16) & 0xffff; + xsubi[2] = (result >> 32) & 0xffff; + + return 0; +} diff --git a/lib/ldpc/rand.h b/lib/ldpc/rand.h new file mode 100755 index 00000000..bb896d40 --- /dev/null +++ b/lib/ldpc/rand.h @@ -0,0 +1,54 @@ +/* RAND.H - Interface to random number generation procedures. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + + +/* STATE OF RANDOM NUMBER GENERATOR. */ + +#define N_tables 5 /* Number of tables of real random numbers */ + +typedef struct +{ int seed; /* Seed state derives from */ + int ptr[N_tables]; /* Pointers for tables of real random numbers */ + unsigned short state48[3]; /* State of 'rand48' pseudo-random generator */ +} rand_state; + + +/* BASIC PSEUDO-RANDOM GENERATION PROCEDURES. */ + +void rand_seed (int); /* Initialize current state structure by seed */ + +void rand_use_state (rand_state *); /* Start using given state structure */ +rand_state *rand_get_state (void); /* Return pointer to current state */ + +int rand_word (void); /* Generate random 31-bit positive integer */ + + +/* GENERATORS FOR VARIOUS DISTRIBUTIONS. */ + +double rand_uniform (void); /* Uniform from [0,1) */ +double rand_uniopen (void); /* Uniform from (0,1) */ + +int rand_int (int); /* Uniform from 0, 1, ... (n-1) */ +int rand_pickd (double *, int); /* From 0 ... (n-1), with given distribution */ +int rand_pickf (float *, int); /* Same as above, but with floats */ +void rand_permutation (int *, int); /* Random permutation */ + +int rand_poisson (double); /* Poisson with given mean */ +double rand_gaussian (void); /* Gaussian with mean zero and unit variance */ +double rand_logistic (void); /* Logistic centred at zero with unit width */ +double rand_cauchy (void); /* Cauchy centred at zero with unit width */ +double rand_gamma (double); /* Gamma with given shape parameter */ +double rand_exp (void); /* Exponential with mean one */ +double rand_beta (double, double); /* Beta with given parameters */ diff --git a/lib/ldpc/rand.html b/lib/ldpc/rand.html new file mode 100755 index 00000000..5754b86a --- /dev/null +++ b/lib/ldpc/rand.html @@ -0,0 +1,306 @@ + + + Random Variate Generation Routines + + + + +

Random Variate Generation Routines

+ +

This module provides facilities for basic pseudo-random number generation, +and for generation of random variates from various common distributions. + +

All the random generation procedures use the same underlying +"stream" of random numbers. This stream is generated using the +nrand48 pseudo-random generation procedure found on most Unix +systems, with the output being combined with a limited supply of real +random numbers from the file "randfile" in the source +directory for this software, in order to reduce the chances that the +pseudo-random numbers aren't random enough. + +

A pseudo-random number stream is determined by an integer +seed, which is typically set by the user for each experimental +run (eg, to 1, 2, 3, etc. for successive runs). The state of the +random number stream can be saved in a structure of type +rand_state, and later restored. For example, the state could +be saved in a file at the end of a run, and restored if it is later +decided that the run should be continued for longer. + +

The methods for generating random variates from various distributions +are mostly taken from the following reference: +

+ Devroye, L. (1986) Non-Uniform Random Variate Generation, + New York: Springer-Verlag. +
+The methods used here are not necessarily the fastest available. They were +selected to be reasonably fast while also being easy to write. + +

Header file required: rand.h + + + +


+
Setting and saving the state
+
+ + +
rand_seed: +Set the state from an integer seed.
+ +
+void rand_seed
+( int seed;  /* Seed to set state based on */
+)
+
+ +

Sets the random number generator to a state that is determined from +the integer seed. Setting the seed the same on two occasions, +and then calling exactly the same sequence of random generation +procedures, should produce exactly the same sequence of random +variates. (Note: this may not be true, however, if computers with +different architectures are used on the two occasions.) + +

Sequential seeds should produce streams that are pretty much +independent (unlike the situation for some pseudo-random number +generators). Setting the seed randomly according to the time or day, +or some such, without recording what it was, is not +recommended, since the results are then not reproducible. + +


rand_get_state: +Get a pointer to the current state. + +
+rand_state *rand_get_state (void)
+
+ +Returns a pointer to the current state of the random number generator, +which is a structure of type rand_state. The only use for this +pointer is to use it to save a copy of the current state someplace. + + +


rand_use_state: +Set the state to use from now on. + +
+void rand_use_state 
+( rand_state *state  /* Pointer to a previously saved state */
+)
+
+ +Sets the random number generator to the state pointed to by the argument. +This state must be valid. The only way to get a valid state is by using +rand_get_state. + + + +


+
Generating uniform random variates
+
+ + +
rand_uniform: +Generate uniformly from [0,1).
+ +
+double rand_uniform (void)
+
+ +Returns a random number that is uniformly distributed between 0 and 1, +with a value of exactly 0 being possible, but with a value of exactly 1 +not being possible. + +


rand_uniopen: +Generate uniformly from (0,1). + +
+double rand_uniopen (void)
+
+ +Returns a random number that is uniformly distributed between 0 and 1, +with neither a value of exactly 0 nor a value of exactly 1 +being possible. + + + +


+
Generating discrete random variates
+
+ + +
rand_int: +Pick an integer uniformly from 0 to n-1.
+ +
+int rand_int 
+( int n  /* Number of integers (from 0) to pick from */
+)
+
+ +

Randomly picks an integer from the set { 0, 1, ..., n-1 }, +with each integer being equally probable. The probabilities may +become somewhat unequal, however, if n is very large, +approaching 231. + + +


rand_pickd: Pick an integer from 0 +to n-1 with given probabilities (as doubles). + +
+int rand_pickd
+( double *p,  /* Array of probabilities, of length n */
+  int n       /* Number of integers (from 0) to pick from */
+)
+
+ +

Randomly picks an integer from the set { 0, 1, ..., n-1 }, +with probabilities given by the array of double-precision numbers +passed as the first argument. These numbers need not sum to one, but they +must be non-negative, and must not all be zero. The actual +probabilities used are obtained by dividing each number in this array +by the sum of all the numbers. + +

If one of the probabilities is exactly zero, it is guaranteed that +the corresponding integer will not be picked. + + +


rand_pickf: Pick an integer from 0 +to n-1 with given probabilities (as floats). + +
+int rand_pickf
+( float *p,  /* Array of probabilities, of length n */
+  int n      /* Number of integers (from 0) to pick from */
+)
+
+ +

This procedure is the same as rand_pickd +except that the array giving the probabilities is an array of single-precision +floating point numbers, rather than double-precision. + + +


rand_poisson: +Generate a non-negative integer from a Poisson distribution. + +
+int rand_poisson
+( double lambda  /* Mean of the Poisson distribution */
+)
+
+ +

Generates a non-negative integer from the Poisson distribution with mean +lambda. + + +


rand_permutation: Generate a random +permutation of integers from 1 to n. + +
+int rand_permutation
+( int *perm,  /* Place to store the permutation */
+  int n       /* Number of integers to permute */
+)
+
+ +

Stores a random permutation of the integers from 1 to n in the +array perm, which must be at least n long. All permutations are +equally likely. + + + +


+
Generating continuous random variates
+
+ + +
rand_gaussian: +Generate a standard Gaussian (normal) random variate.
+ +
+double rand_gaussian (void)
+
+ +

Generates a random value drawn from the Gaussian (normal) distribution +with mean zero and standard deviation one, whose density function is +proportional to exp(-x2/2), with x +being any real value. + + +


rand_logistic: +Generate a logistic random variate. + +
+double rand_logistic (void)
+
+ +

Generates a random value drawn from the logistic distribution with +location parameter zero and width parameter one, whose density +function is proportional to +exp(-x) / [1 + exp(-x)]2, +with x being any real value. + + +


rand_cauchy: +Generate a Cauchy random variate. + +
+double rand_cauchy (void)
+
+ +

Generates a random value drawn from the Cauchy distribution with centre +at zero and width one, whose density function is proportional to +1 / (1+x2), with x being any real value. + + +


rand_gamma: +Generate a gamma-distributed random variate. + +
+double rand_gamma
+( double A   /* Shape parameter */
+)
+
+ +

Generates a random value drawn from the gamma distribution with +positive shape parameter A, whose density function is proportional +to xA-1 exp(-x), with x +being any positive real. This procedure will never return a value that is +exactly zero. + + +


rand_exp: +Generate an exponentially-distributed random variate. + +
+double rand_exponential (void)
+
+ +

Generates a random value drawn from the exponential distribution with +mean one, whose density function is exp(-x), with x being +any positive real. This procedure will never return a value that is +exactly zero. + +

Note: This is a common special case of the gamma distribution. + + +


rand_beta: +Generate a beta-distributed random variate. + +
+double rand_beta
+( double A,  /* Parameters of distribution */
+  double B
+)
+
+ +

Generates a random value drawn from the beta distribution with positive +parameters A and B, whose density function is proportional +to xA-1(1-x)B-1, +with x being any real in the interval (0,1). This procedure +will never return a value that is exactly zero or exactly one. + + +


+ +Back to index for LDPC software + + diff --git a/lib/ldpc/randfile b/lib/ldpc/randfile new file mode 100755 index 00000000..3d33d61e Binary files /dev/null and b/lib/ldpc/randfile differ diff --git a/lib/ldpc/rcode.c b/lib/ldpc/rcode.c new file mode 100755 index 00000000..84d6fd92 --- /dev/null +++ b/lib/ldpc/rcode.c @@ -0,0 +1,217 @@ +/* RCODE.C - Procedures to read parity check and generator matrices. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include + +#include "alloc.h" +#include "intio.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" + + +/* VARIABLES DECLARED IN RCODE.H. These global variables are set to + representations of the parity check and generator matrices by read_pchk + and read_gen. */ + +mod2sparse *H; /* Parity check matrix */ + +int M; /* Number of rows in parity check matrix */ +int N; /* Number of columns in parity check matrix */ + +char type; /* Type of generator matrix representation (s/d/m) */ +int *cols; /* Ordering of columns in generator matrix */ + +mod2sparse *L, *U; /* Sparse LU decomposition, if type=='s' */ +int *rows; /* Ordering of rows in generator matrix (type 's') */ + +mod2dense *G; /* Dense or mixed representation of generator matrix, + if type=='d' or type=='m' */ + + +/* READ PARITY CHECK MATRIX. Sets the H, M, and N global variables. If an + error is encountered, a message is displayed on standard error, and the + program is terminated. */ + +void read_pchk +( char *pchk_file +) +{ + FILE *f; + + f = open_file_std(pchk_file,"rb"); + if (f==NULL) + { fprintf(stderr,"Can't open parity check file: %s\n",pchk_file); + exit(1); + } + + if (intio_read(f)!=('P'<<8)+0x80) + { fprintf(stderr,"File %s doesn't contain a parity check matrix\n",pchk_file); + exit(1); + } + + H = mod2sparse_read(f); + + if (H==0) + { fprintf(stderr,"Error reading parity check matrix from %s\n",pchk_file); + exit(1); + } + + M = mod2sparse_rows(H); + N = mod2sparse_cols(H); + + fclose(f); +} + + +/* READ GENERATOR MATRIX. The parity check matrix must have already been + read, unless the last argument is set to 1. The generator matrix must be + compatible with the parity check matrix, if it has been read. If the + second argument is 1, only the column ordering (the last N-M of which are + the indexes of the message bits) is read, into the 'cols' global variable. + Otherwise, everything is read, into the global variables appropriate + to the representation. The 'type' global variable is set to a letter + indicating which represention is used. + + If an error is encountered, a message is displayed on standard error, + and the program is terminated. */ + +void read_gen +( char *gen_file, /* Name of generator matrix file */ + int cols_only, /* Read only column ordering? */ + int no_pchk_file /* No parity check file used? */ +) +{ + int M2, N2; + FILE *f; + int i; + + f = open_file_std(gen_file,"rb"); + if (f==NULL) + { fprintf(stderr,"Can't open generator matrix file: %s\n",gen_file); + exit(1); + } + + if (intio_read(f)!=('G'<<8)+0x80) + { fprintf(stderr,"File %s doesn't contain a generator matrix\n",gen_file); + exit(1); + } + + if (fread (&type, 1, 1, f) != 1) goto error; + + M2 = intio_read(f); + N2 = intio_read(f); + + if (feof(f) || ferror(f)) goto error; + + if (no_pchk_file) + { M = M2; + N = N2; + } + else + { if (M2!=M || N2!=N) + { fprintf(stderr, + "Generator matrix and parity-check matrix are incompatible\n"); + exit(1); + } + } + + cols = chk_alloc (N, sizeof *cols); + rows = chk_alloc (M, sizeof *rows); + + for (i = 0; i + + References on Low Density Parity Check Codes + + + + +

References on Low Density Parity Check Codes

+ +Robert Gallager's original work on low density parity check codes was published +as the following book, based his doctoral dissertation, and a related paper: +
+

Gallager, R. G. (1963) Low Density Parity Check Codes, + Cambridge, MA: MIT Press. +

Gallager, R. G. (1962) ``Low-density parity-check codes'', IRE + Transactions on Information Theory, vol. IT-8, pp. 21-28. +

+ +More recent work on these codes by David MacKay and myself was published +as follows: +
+

MacKay, D. J. C. and Neal, R. M. (1996) ``Near Shannon limit performance + of low density parity check codes'', Electronics Letters, + vol. 32, pp. 1645-1646. Reprinted with printing errors corrected + in vol. 33, pp. 457-458. +

MacKay, D. J. C. (1999) ``Good error-correcting codes based on very + sparse matrices'', IEEE Transactions on Information Theory, + vol. 45, pp. 399-431. +

+ +The decoding algorithms described in the above references can visualized +in terms of a ``factor graph'' representation of the code, as described +in the following paper: +
+

Kschischang, F. R., Frey, B. J., and Loeliger, H.-A. (1998) ``Factor graphs +and the sum-product algorithm'', IEEE Transactions on Information +Theory, vol. 47, pp. 498-519. +

+ +I presented the application of sparse matrix techniques to encoding of +LDPC codes at the IMA workshop on Codes, Systems and Graphical Models, +Minneapolis, 1999. You can view the slides of this talk here. Note: Due to a bug in the +program I used then, the results shown for the minimal product heuristic in +these slides are somewhat worse than the actual performance. For instance, +the number of bit operations per check bit for for M=3200 with +3 checks per bit is actually around 12.7, not the value around 17 shown +on one of the slides. + +

Text and references to many more recent and classical papers can be +obtained via the IMA workshop's +web page. + +


+ +Back to index for LDPC software + + diff --git a/lib/ldpc/release.html b/lib/ldpc/release.html new file mode 100755 index 00000000..558e7cda --- /dev/null +++ b/lib/ldpc/release.html @@ -0,0 +1,244 @@ + + +Release Notes for LDPC-codes Software + + + + +

Release Notes for LDPC-codes Software

+ +These notes describe all the stable public releases of this software. Old +and future releases can be obtained via +
+ +http://www.cs.toronto.edu/~radford/ldpc.software.html +
+The current development version is now maintained at +
+ +http://github.com/radfordneal/LDPC-code +
+ +

Version of 2012-02-11.

+This version has a few bug fixes and some minor new features. The major +change is that a source repository for the software is now hosted +at github.com, making it easier for people to create and release +their own versions of this software. +
    +
  1. Changed the copyright notice (in the file COPYRIGHT, and elsewhere) + to remove the requirement that my web site be referenced. (Nowadays, + I think users should have no problem finding the sources using a + search engine.) +
  2. Included a copy of the nrand48 routine from the GNU C library + in the rand.c module, to ensure that it is always available + and always the same. (This isn't so on some versions of cygwin.) +
  3. Added a -f option to encode and decode that forces flushing + after writing each block. Useful for allowing encode or + decode to be used as a server, reading and writing blocks + from named pipes. +
  4. Added a -z option for pchk-to-alist to suppress output of 0 + row and column indexes that pad up to the maximum number used. +
  5. Documented the previously undocumented -t options for pchk-to-alist + and alist-to-pchk. +
  6. Changed alist-to-pchk so that it no longer requires zero indexes + that pad out to the maximum needed for a row or column (thanks + to Monica Kolb for suggesting this). +
  7. Changed mod2word type in mod2dense.c to uint32_t, to avoid + wasted space when long is 64 bits (thanks to Mathieu Cunche + and Vincent Roca for suggesting this). +
  8. Fixed bug in distrib.c affecting distributions with a single + number (thanks to Mike Vicuna for pointing it out). +
  9. Fixed bug in -t option for pchk-to-alist (thanks to Andrea Fontana + for reporting this). +
  10. Fixed references in the documentation to mod2sparse_multvec + that should be to mod2sparse_mulvec (thanks to Andrea Fontana + for reporting this). +
+ + +

Version of 2006-02-08.

+ +The copyright notice has been changed in this release to no longer +restrict use to purposes of research or education. The new copyright +notice can be read here. It is now +possible to create LDPC codes with varying numbers of checks per bit +(an extension based on work by Peter Junteng Liu). New programs for +converting to and from the alist +format for parity check matrices, used by David MacKay and others, +have also been added. + +

The following new features have been added: +

    +
  1. The make-ldpc program can + new create LDPC codes with varying numbers of checks per bit. The + examples now include a code of this sort. +
  2. New programs pchk-to-alist + and alist-to-pchk have + been added, which convert to and from alist + format. +
  3. A run-examples script has been + added, which runs all the examples and + compares with the saved output that I obtained. +
+ + +

Version of 2001-11-18.

+ +This is a minor release, whose main purpose is fixing bug (1) below. +Also, this release has been tested and found to work with the cygwin Unix environment that runs +under Microsoft Windows. + +

The following new feature has been added: +

    +
  1. A new -t option has been added to + print-pchk, which + causes it to print the transpose of the parity check matrix. +
+ +The following program module change was made: +
    + +
  1. The behaviour of mod2dense_invert_selected + has been changed when the matrix has dependent rows. The result returned + contains the inverse of a sub-matrix in its initial columns. The contents + of the remaining columns up to the number of rows was previously undefined, + but these columns are now set to contain zeros. This was done to fix + bug (1) below. +
+ +The following bugs were fixed: +
    +
  1. A bug has been fixed in + make-gen + which sometimes + produced invalid `dense' or `mixed' generator matrices when the parity + check matrix had redundant rows. + The `sparse' generator matrices were not affected. The output of the + ex-dep example has changed slightly as a + result. +
  2. The open mode for reading the file of random numbers has been changed from + "r" to "rb", for compatibility with non-Unix systems. +
  3. mod2sparse_copy has + been fixed so that it copies the lr and pr fields + of entries. +
  4. The "set -v -e" in the command files for the examples has + been replaced by two commands, "set -e" and "set -v", since some + shells can't set two options at once. +
+ +A few minor fixes to the documentation have also been made. + + +

Version of 2001-05-04.

+ +Changes and new features regarding programs and associated +documentation and examples: +
    +
  1. Warnings have been added to the documentation about the dangers of + using zero codewords for testing (due to the possibility of the decoder + accidently being non-symmetric). The examples have been changed to + not use zero codewords, except for + ex-ham7a, which still + demonstrates this facility. +
  2. Decoding by probability propagation has been changed so that if + a probability ratio gets set to NaN ("not a number", the result of + infinite but conflicting evidence from different sources), the probability + ratio is changed to 1, in hopes that something sensible may result. +
  3. The decoding procedures have been changed to decode a bit to a 1 if + there is a tie, so that any resulting asymmetry in decoding will + make zero decoding less, rather than more, likely. See point (1) above. +
  4. All programs now allow a file name argument to be "-", which specifies + standard input or standard output, as appropriate. The + ex-ldpc36-5000a example has been + changed to use this facility in order to avoid creating lots of files. +
  5. Channels with noise from a logistic distribution (AWLN) have been + implemented. For details, + see the channel documentation. +
  6. The make-gen program for "dense" or "mixed" options was modified + so that when some parity checks are redundant, others are not declared + redundant when they aren't. This makes the result compatible with + what is obtained with the "sparse" option. The example in the + discussion of linear dependence in parity check + matrices has changed slightly as a result. +
  7. The messages displayed by the decode + program have changed slightly: The block size is no longer displayed, + and the percentage of bits changed is now shown. The data output + when the -t option is specified now includes the number of + bits changed in each block. +
  8. A new -T option to decode + for displaying + detailed information on decoding + has been added. +
  9. Doing a make clean will now remove the files created + by running the examples. +
  10. The files created by the examples now + start with "ex-" and contain a ".", to make them easier to + identify for cleanup, and the saved output file now ends in + "-out" rather than ".out". +
  11. The scripts for the examples now use the -v option of set + rather than -x, so that the command lines are echoed + faithfully as they are read. +
  12. Two new examples have been added: + ex-dep demonstrates what happens when parity check matrices + have redundant row, and ex-wrong-model investigates what + happens when the wrong model is used to decode. +
+Changes and new features regarding program modules and other internals: +
    +
  1. Instructions have been added on + how to modify the programs, and some + code has been reorganized to facilitate modifications. +
  2. The makefile has been made trivial, simply recompiling everything + from scratch every time. This is simpler and less error prone + than putting in dependencies. + Compiling all the programs takes only about five seconds on a + modern PC. +
  3. The + mod2dense_invert_selected + procedure has been changed + to take an additional argument in which a permutation of rows is + returned. This extension is needed in order for the result when + the matrix is not of full rank to include as many rows as possible, + as needed for the above modification of make-gen. +
  4. New routines + mod2dense_copyrows and + mod2sparse_copyrows have + been added, analogous to the previous routines for copying columns. +
  5. The decoding procedures have been changed to always return the bit + probabilities (previously, one could pass a null pointer to suppress + this). This makes things simpler, and facilitates the production of + detailed trace output when the -T option is used. +
+ +The following bugs were fixed: +
    +
  1. A problem with print-gen prevented the -d option from working + in most cases. The documentation was also fixed to note what + the L and U matrices printed will look like. +
  2. The documentation for + mod2sparse_copycols and + mod2dense_copycols + was ambiguous. It has been clarified. The dense and sparse + implementations were inconsistent. The sparse version has been changed + to match the dense version, which was and is the only version actually + used in the LDPC software. +
  3. In decode.c, a variable declared to be float was printed + using "%f", which strangely didn't work with one compiler. + It's now declared as double. +
+ +There were also numerous minor cleanups of program code and documentation. + +

Version of 2000-03-19.

+ +This was the first public release. + +
+ +Back to index for LDPC software + + diff --git a/lib/ldpc/run-examples b/lib/ldpc/run-examples new file mode 100755 index 00000000..7d8859e3 --- /dev/null +++ b/lib/ldpc/run-examples @@ -0,0 +1,12 @@ +#!/bin/sh + +# Run all the examples, and check the output against the corresponding -out +# file. Note that slight differences are possible when the examples are +# run on different machines, due to slightly different round-off errors. + +for e in `ls ex-* | grep -v "\\." | grep -v .-out` +do + echo Running $e: + $e 2>&1 | diff ${e}-out - + echo " " +done diff --git a/lib/ldpc/sparse-LU.html b/lib/ldpc/sparse-LU.html new file mode 100755 index 00000000..12874aaa --- /dev/null +++ b/lib/ldpc/sparse-LU.html @@ -0,0 +1,90 @@ + + + Sparse LU Decomposition Methods + + + + +

Sparse LU Decomposition Methods

+ +

The sparse modulo-2 matrix LU decomposition routine mod2sparse_decomp (which +is used by the make-gen +program when it is asked to create a sparse generator matrix) tries to +find an sub-matrix of a matrix (for make-gen, the parity +check matrix), and an ordering of rows and columns for this +sub-matrix, that leads to the lower-triangular matrix L and the +upper-triangular matrix U making up the LU decomposition being +as sparse as possible. Finding an optimal solution is too difficult, +so instead a heuristic strategy is used. + +

The overall algorithm finds L and U a column at a +time, from left to right (as reordered, in the case of U). As +this is done, a copy, B, of the original matrix is modified. +To create column i of L and U, some element with +value 1 in B whose row and column indexes, after reordering, +are both greater than i is found. The row and column of this +element are considered to come next in the reordering, and the +contents of the column containing this element is copied to L +and U (upper elements going to U, lower to L). +The row containing this element is then added to some later rows so as +to clear the lower part of this column to zeros. + +

At the first step of this process - selecting an element with value +1 from the later rows and columns - there will often be several +possibilities. Different choices can lead to the final result being +more or less sparse. The possible strategies for picking an element +are identified by the constants Mod2sparse_first, +Mod2sparse_mincol, and Mod2sparse_minprod. These +strategies operate as follows: + +

Mod2sparse_first +

+Select the first element with value 1 that is encountered in a top +to bottom, left to right search. +
+ +

Mod2sparse_mincol +

+Select the first element with value 1 that is contained in a column +of B that has the smallest number of 1s of any column. +
+ +

Mod2sparse_minprod +

+Select an element with value 1 for which the product of the number of +1s in that row of B minus one times the number of 1s in that +column of B minus one is as small as possible. +
+ +

The abandon_number and abandon_when parameters can +modify the basic strategy. If abandon_number is greater than +zero, then after abandon_when columns have been selected, +abandon_number of the remaining columns are abandoned as +candidates for possible future selection, the abandoned columns being +those with the greatest number of entries. Abandoning such columns +saves space and time, but may make the final result less sparse than +it would otherwise be, and can possibly result in the matrix appearing +to have lower rank than it actually has. + +

The methods described here are fairly straightforward adaptations +of standard methods for sparse square matrices of reals, as described, for +example, in +

+ I. S. Duff, A. M. Erisman, J. K. Reid (1986) Direct Methods for + Sparse Matrices, Oxford: Clarendon Press. +
+In the coding context, however, we are interested in matrices of +modulo-2 elements, and it is enough to find a sparse LU decomposition +of any square sub-matrix that can be obtained by selecting columns of +the rectangular parity check matrix. I talked about the application +of sparse matrix methods to encoding of LDPC codes at the 1999 IMA +workshop on Codes, Systems and Graphical Models (see the references). + + +
+ +Back to index for LDPC software + + diff --git a/lib/ldpc/sparse-encode.pdf b/lib/ldpc/sparse-encode.pdf new file mode 100755 index 00000000..30629f31 Binary files /dev/null and b/lib/ldpc/sparse-encode.pdf differ diff --git a/lib/ldpc/support.html b/lib/ldpc/support.html new file mode 100755 index 00000000..921881ab --- /dev/null +++ b/lib/ldpc/support.html @@ -0,0 +1,100 @@ + + + Support Programs + + + + +

Support Programs

+ +The following programs provide support for testing and performance +assessment. + + +


rand-src: Generate random message bits. + +
+rand-src source-file seed n-bits
+
+ +

Creates a file of random messages bits called +source-file, which is suitable for testing the +correctness and performance of other programs. The bits in the file +are independent, and are equally likely to be 0 or 1. They are +generated pseudo-randomly based on seed. The actual +random number seed used will be seed times 10 plus 2, +so that the stream of pseudo-random numbers will not be the same as +any that might have been used by another program. + +

The n-bits argument specifies the number of bits to +produce. It can be a single number, or it can consist of a block size +and a number of blocks, written with x separating these +numbers, with no spaces. Each block is written as a single line, with +the bits in the block represented by the characters '0' and '1', with +no intervening spaces. If the bit count is given by a single number, +the block size is assumed to be one. + +

Example: The following command produces a file containing +3 blocks, each consisting of 15 random bits, produced using the pseudo-random +number stream identified by the seed of 17: +

    +
  • rand-src rsrc 17 15x3 +
+The contents of the file rsrc after this command might be something +like the following: +
+111011000110000
+010010110010111
+100000000000111
+
+ + +


verify: Verify that decoded blocks are +codewords, and that they match the source. + +
+verify [ -t ] pchk-file decoded-file [ gen-file [ source-file ] ]
+
+ +

Checks whether or not the blocks in decoded-file +are codewords, according to the parity check matrix in +pchk-file. If gen-file is specified, +the message bits of the blocks are also checked against the +corresponding blocks of source-file, or against zero +if source-file is not given. (Normally, one would +leave out source-file only if the transmit command was used +with an argument specifying that zeros are to be transmitted, rather +than a file of encoded data.) + +

A summary of the results is displayed on standard error, giving the +total numbers of blocks, the number with parity check errors, and, if +gen-file was specified, the number of blocks with +source errors and the number with errors of both kinds. If +gen-file was specified, a second +summary line displays the bit error rate from +comparing the decoded message bits with the true message bits (zeros +if no source file was given). + +

If the -t option is given, block-by-block results are +printed on standard output in two or three columns, giving the block +number (from zero), the number of parity check errors for that block, +and the number of errors in source bits. The last column is omitted +if gen-file is not specified. The columns are +preceded by a line of headers, so the file is suitable for reading +into the S-Plus or R statistics packages, with a command such as +

+data <- read.table(file,header=T)
+
+ +

Warning messages are displayed on standard error if the number of +bits in decoded-file is not a multiple of the block +length, or if source-file is too short. Newlines +in these files are ignored, even though they would normally occur +at the ends of blocks. + +


+ +Back to index for LDPC software + + diff --git a/lib/ldpc/transmit.c b/lib/ldpc/transmit.c new file mode 100755 index 00000000..14657d68 --- /dev/null +++ b/lib/ldpc/transmit.c @@ -0,0 +1,170 @@ +/* TRANSMIT.C - Simulate transmission of bits through a channel. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include +#include + +#include "channel.h" +#include "open.h" +#include "rand.h" + +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + char *tfile, *rfile; + FILE *tf, *rf; + int block_size, n_bits; + char junk; + int seed; + int cnt; + int n, b; + + /* Look at arguments. The arguments specifying the channel are looked + at by channel_parse in channel.c */ + + if (!(tfile = argv[1]) + || !(rfile = argv[2]) + || !argv[3] || sscanf(argv[3],"%d%c",&seed,&junk)!=1) + { usage(); + } + + n = channel_parse(argv+4,argc-4); + if (n<=0 || argc-4-n!=0) + { usage(); + } + + /* See if the source is all zeros or a file. */ + + if (sscanf(tfile,"%d%c",&n_bits,&junk)==1 && n_bits>0) + { block_size = 1; + tf = NULL; + } + else if (sscanf(tfile,"%dx%d%c",&block_size,&n_bits,&junk)==2 + && block_size>0 && n_bits>0) + { n_bits *= block_size; + tf = NULL; + } + else + { tf = open_file_std(tfile,"r"); + if (tf==NULL) + { fprintf(stderr,"Can't open encoded file to transmit: %s\n",tfile); + exit(1); + } + } + + /* Open output file. */ + + rf = open_file_std(rfile,"w"); + if (rf==NULL) + { fprintf(stderr,"Can't create file for received data: %s\n",rfile); + exit(1); + } + + /* Set random seed to avoid duplications with other programs. */ + + rand_seed(10*seed+3); + + /* Transmit bits. */ + + for (cnt = 0; ; cnt++) + { + /* Get next bit to transmit. */ + + if (tf) /* Data comes from a file */ + { + for (;;) + { b = getc(tf); + if (b!=' ' && b!='\t' && b!='\n' && b!='\r') + { break; + } + putc(b,rf); + } + + if (b==EOF) break; + + if (b!='0' && b!='1') + { fprintf(stderr,"Bad character (code %d) file being transmitted\n",b); + exit(1); + } + } + + else /* Data is all zeros */ + { + if (cnt>0 && cnt%block_size==0) + { putc('\n',rf); + } + + if (cnt==n_bits) break; + + b = '0'; + } + + b = b=='1'; + + /* Produce the channel output for this transmitted bit. */ + + switch (channel) + { case BSC: + { int bsc_noise; + bsc_noise = rand_uniform() < error_prob; + fprintf (rf, "%d", b^bsc_noise); + break; + } + case AWGN: + { double awgn_noise; + awgn_noise = std_dev * rand_gaussian(); + fprintf (rf, " %+5.2f", b ? 1+awgn_noise : -1+awgn_noise); + break; + } + case AWLN: + { double awln_noise; + awln_noise = lwidth * rand_logistic(); + fprintf (rf, " %+5.2f", b ? 1+awln_noise : -1+awln_noise); + break; + } + default: + { abort(); + } + } + } + + fprintf(stderr,"Transmitted %d bits\n",cnt); + + if (ferror(rf) || fclose(rf)!=0) + { fprintf(stderr,"Error writing received bits to %s\n",rfile); + exit(1); + } + + return 0; +} + + +/* PRINT USAGE MESSAGE AND EXIT. */ + +void usage(void) +{ fprintf(stderr, + "Usage: transmit encoded-file|n-zeros received-file seed channel\n"); + channel_usage(); + exit(1); +} diff --git a/lib/ldpc/verify.c b/lib/ldpc/verify.c new file mode 100755 index 00000000..e52f79d8 --- /dev/null +++ b/lib/ldpc/verify.c @@ -0,0 +1,254 @@ +/* VERIFY.C - Verify encoded or decoded blocks. */ + +/* Copyright (c) 1995-2012 by Radford M. Neal. + * + * Permission is granted for anyone to copy, use, modify, and distribute + * these programs and accompanying documents for any purpose, provided + * this copyright notice is retained and prominently displayed, and note + * is made of any changes made to these programs. These programs and + * documents are distributed without any warranty, express or implied. + * As the programs were written for research purposes only, they have not + * been tested to the degree that would be advisable in any important + * application. All use of these programs is entirely at the user's own + * risk. + */ + +#include +#include +#include +#include + +#include "alloc.h" +#include "blockio.h" +#include "open.h" +#include "mod2sparse.h" +#include "mod2dense.h" +#include "mod2convert.h" +#include "rcode.h" +#include "check.h" + +void usage(void); + + +/* MAIN PROGRAM. */ + +int main +( int argc, + char **argv +) +{ + char *coded_file, *source_file; + char *pchk_file, *gen_file; + int table; + + char *sblk, *cblk, *chks; + int seof, ceof; + int srcerr, chkerr, bit_errs; + int i, n; + FILE *srcf, *codef; + + int tot_srcerrs, tot_chkerrs, tot_botherrs, tot_undeterrs, tot_good; + + /* Look at arguments. */ + + table = 0; + if (argc>1 && strcmp(argv[1],"-t")==0) + { table = 1; + argc -= 1; + argv += 1; + } + + if (argc<3 || argc>5) usage(); + + if (!(pchk_file = argv[1]) + || !(coded_file = argv[2])) + { usage(); + } + + gen_file = 0; + source_file = 0; + + if (argv[3]) + { gen_file = argv[3]; + if (argv[4]) + { source_file = argv[4]; + if (argv[5]) + { usage(); + } + } + } + + if ((strcmp(pchk_file,"-")==0) + + (strcmp(coded_file,"-")==0) + + (source_file!=0 && strcmp(source_file,"-")==0) + + (gen_file!=0 && strcmp(gen_file,"-")==0) > 1) + { fprintf(stderr,"Can't read more than one stream from standard input\n"); + exit(1); + } + + /* Read parity check file. */ + + read_pchk(pchk_file); + + if (N<=M) + { fprintf(stderr, + "Number of bits (%d) should be greater than number of checks (%d)\n",N,M); + exit(1); + } + + /* Read generator matrix file, if given, up to the point of finding + out which are the message bits. */ + + if (gen_file!=0) + { read_gen(gen_file,1,0); + } + + /* Open coded file to check. */ + + codef = open_file_std(coded_file,"r"); + if (codef==NULL) + { fprintf(stderr,"Can't open coded file: %s\n",coded_file); + exit(1); + } + + /* Open source file to verify against, if given. */ + + if (source_file!=0) + { + srcf = open_file_std(source_file,"r"); + if (srcf==NULL) + { fprintf(stderr,"Can't open source file: %s\n",source_file); + exit(1); + } + } + + sblk = chk_alloc (N-M, sizeof *sblk); + cblk = chk_alloc (N, sizeof *cblk); + chks = chk_alloc (M, sizeof *chks); + + /* Print header for table. */ + + if (table) + { if (gen_file!=0) + { printf(" block chkerrs srcerrs\n"); + } + else + { printf(" block chkerrs\n"); + } + } + + /* Verify successive blocks. */ + + tot_srcerrs = 0; + tot_chkerrs = 0; + tot_botherrs = 0; + tot_undeterrs = 0; + tot_good = 0; + + bit_errs = 0; + + seof = 0; + ceof = 0; + + for (n = 0; ; n++) + { + /* Read block from coded file. */ + + if (blockio_read(codef,cblk,N)==EOF) + { ceof = 1; + } + + /* Read block from source file, if given. */ + + if (source_file!=0 && !ceof && !seof) + { if (blockio_read(srcf,sblk,N-M)==EOF) + { fprintf(stderr,"Warning: Not enough source blocks (only %d)\n",n); + seof = 1; + } + } + + /* Stop if end of received file. */ + + if (ceof) break; + + /* Check that received block is a code word, and if not find the number of + parity check errors. */ + + chkerr = check(H,cblk,chks); + + /* Check against source block, if provided, or against zeros, if + the generator matrix was provided but no source file. */ + + if (gen_file!=0) + { srcerr = 0; + if (source_file!=0 && !seof) + { for (i = M; i> j & 1); + } + c[1] = (c[1] << 1) ^ aux; + } + cw[k]=65536*c[1] + c[0]; + } +} diff --git a/lib/ldpcsim144.f90 b/lib/ldpcsim144.f90 new file mode 100644 index 00000000..62c4838f --- /dev/null +++ b/lib/ldpcsim144.f90 @@ -0,0 +1,175 @@ +program ldpcsim + +use, intrinsic :: iso_c_binding +use iso_c_binding, only: c_loc,c_size_t +use hashing +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(10) +integer*1 i1hash(4) +integer*1 msgbits(80) +integer*4 i4Msg6BitWords(13) +integer ihash +integer nerrtot(128),nerrdec(128) +real*8, allocatable :: lratio(:), rxdata(:), rxavgd(:) +real, allocatable :: yy(:), llr(:) +equivalence(ihash,i1hash) + +do i=1,NRECENT + recent_calls(i)=' ' +enddo +nerrtot=0 +nerrdec=0 + +nargs=iargc() +if(nargs.ne.4) then + print*,'Usage: ldpcsim niter navg #trials s ' + print*,'eg: ldpcsim 10 1 1000 0.75' + return +endif +call getarg(1,arg) +read(arg,*) max_iterations +call getarg(2,arg) +read(arg,*) navg +call getarg(3,arg) +read(arg,*) ntrials +call getarg(4,arg) +read(arg,*) s + +! don't count hash bits as data bits +N=128 +K=72 +rate=real(K)/real(N) + +write(*,*) "rate: ",rate + +write(*,*) "niter= ",max_iterations," navg= ",navg," s= ",s + +allocate ( codeword(N), decoded(K), message(K) ) +allocate ( lratio(N), rxdata(N), rxavgd(N), yy(N), llr(N) ) + +msg="K9AN K1JT EN50" + call packmsg(msg,i4Msg6BitWords,itype,.false.) !Pack into 12 6-bit bytes + call unpackmsg(i4Msg6BitWords,msgsent,.false.,' ') !Unpack to get msgsent + write(*,*) "message sent ",msgsent + + i4=0 + ik=0 + im=0 + do i=1,12 + nn=i4Msg6BitWords(i) + do j=1, 6 + ik=ik+1 + i4=i4+i4+iand(1,ishft(nn,j-6)) + i4=iand(i4,255) + if(ik.eq.8) then + im=im+1 +! if(i4.gt.127) i4=i4-256 + i1Msg8BitBytes(im)=i4 + ik=0 + endif + enddo + enddo + + ihash=nhash(c_loc(i1Msg8BitBytes),int(9,c_size_t),146) + ihash=2*iand(ihash,32767) !Generate the 8-bit hash + i1Msg8BitBytes(10)=i1hash(1) !CRC to byte 10 + mbit=0 + do i=1, 10 + i1=i1Msg8BitBytes(i) + do ibit=1,8 + mbit=mbit+1 + msgbits(mbit)=iand(1,ishft(i1,ibit-8)) + enddo + enddo + call encode_msk144(msgbits,codeword) + call init_random_seed() + +write(*,*) "Eb/N0 SNR2500 ngood nundetected nbadhash sigma" +do idb = -6, 14 + db=idb/2.0-1.0 + sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) + ngood=0 + nue=0 + nbadhash=0 + + do itrial=1, ntrials + rxavgd=0d0 + do iav=1,navg + call sgran() +! Create a realization of a noisy received word + do i=1,N + rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() + enddo + rxavgd=rxavgd+rxdata + enddo + rxdata=rxavgd + 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 + +! 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) + lratio=exp(llr) + yy=rxdata + +! max_iterations is max number of belief propagation iterations +! call ldpc_decode(lratio, decoded, max_iterations, niterations, max_dither, ndither) +! call amsdecode(yy, max_iterations, decoded, niterations) +! call bitflipmsk144(rxdata, decoded, niterations) + call bpdecode144(llr, max_iterations, decoded, niterations) + +! If the decoder finds a valid codeword, niterations will be .ge. 0. + if( niterations .ge. 0 ) then + call extractmessage144(decoded,msgreceived,nhashflag,recent_calls,nrecent) + if( nhashflag .ne. 1 ) then + nbadhash=nbadhash+1 + endif + nueflag=0 + +! Check the message plus hash against what was sent. + do i=1,K + if( msgbits(i) .ne. decoded(i) ) then + nueflag=1 + endif + enddo + if( nhashflag .eq. 1 .and. nueflag .eq. 0 ) then + ngood=ngood+1 + nerrdec(nerr)=nerrdec(nerr)+1 + else if( nhashflag .eq. 1 .and. nueflag .eq. 1 ) then + nue=nue+1; + endif + endif + enddo + snr2500=db-3.5 + write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,1x,i8,8x,f5.2)") db,snr2500,ngood,nue,nbadhash,ss + +enddo + +open(unit=23,file='nerrhisto.dat',status='unknown') +do i=1,128 + write(23,'(i4,2x,i10,i10,f10.2)') i,nerrdec(i),nerrtot(i),real(nerrdec(i))/real(nerrtot(i)+1e-10) +enddo +close(23) + +end program ldpcsim diff --git a/lib/ldpcsim40.f90 b/lib/ldpcsim40.f90 new file mode 100644 index 00000000..b9c15e4d --- /dev/null +++ b/lib/ldpcsim40.f90 @@ -0,0 +1,138 @@ +program ldpcsim + +use, intrinsic :: iso_c_binding +use hashing +use packjt + +character*22 msg,msgsent,msgreceived +character*8 arg +integer*1, allocatable :: codeword(:), decoded(:), message(:) +real*8, allocatable :: rxdata(:), rxavgd(:) +real, allocatable :: llr(:) +integer ihash +integer*1 hardbits(32) + +nargs=iargc() +if(nargs.ne.4) then + print*,'Usage: ldpcsim niter navg #trials s ' + print*,'eg: ldpcsim 10 1 1000 0.75' + return +endif +call getarg(1,arg) +read(arg,*) max_iterations +call getarg(2,arg) +read(arg,*) navg +call getarg(3,arg) +read(arg,*) ntrials +call getarg(4,arg) +read(arg,*) s + +K=16 +N=32 +!rate=real(K)/real(N) +! don't count hash bits as data bits +rate=4.0/real(N) +write(*,*) "rate: ",rate +write(*,*) "niter= ",max_iterations,"navg= ",navg," s= ",s + +allocate ( codeword(N), decoded(K), message(K) ) +allocate ( rxdata(N), rxavgd(N), llr(N) ) + +msg="K1JT K9AN" +call fmtmsg(msg,iz) +call hash(msg,22,ihash) +irpt=14 +ihash=iand(ihash,4095) !12-bit hash +ig=16*ihash + irpt !4-bit report +write(*,*) irpt,ihash,ig + +do i=1,16 + message(i)=iand(1,ishft(ig,1-i)) +enddo +write(*,'(16i1)') message +call encode_msk40(message,codeword) +write(*,'(32i1)') codeword +call init_random_seed() + +write(*,*) "Eb/N0 SNR2500 ngood nundetected nbadhash" +do idb = 0, 30 + db=idb/2.0 + sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) + ngood=0 + nue=0 + nbadhash=0 + + itsum=0 + do itrial=1, ntrials + rxavgd=0d0 + do iav=1,navg + call sgran() +! Create a realization of a noisy received word + do i=1,N + rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() + enddo + rxavgd=rxavgd+rxdata + enddo + rxdata=rxavgd + +! 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 + if( s .le. 0 ) then + ss=sigma + else + ss=s + endif + + llr=2.0*rxdata/(ss*ss) + + call bpdecode40(llr, max_iterations, decoded, niterations) +! If the decoder finds a valid codeword, niterations will be .ge. 0. + if( niterations .ge. 0 ) then + nueflag=0 + nhashflag=0 + imsg=0 + do i=1,16 + imsg=ishft(imsg,1)+iand(1,decoded(17-i)) + enddo + nrxrpt=iand(imsg,15) + nrxhash=(imsg-nrxrpt)/16 + if( nrxhash .ne. ihash ) then + nbadhash=nbadhash+1 + nhashflag=1 + endif + +! Check the message plus hash against what was sent. + do i=1,K + if( message(i) .ne. decoded(i) ) then + nueflag=1 + endif + enddo + + if( nhashflag .eq. 0 .and. nueflag .eq. 0 ) then + ngood=ngood+1 + itsum=itsum+niterations + else if( nhashflag .eq. 0 .and. nueflag .eq. 1 ) then + nue=nue+1; + endif + else + hardbits=0 + where(llr .gt. 0) hardbits=1 +! write(*,'(32i1)') hardbits +! write(*,'(32i1)') codeword + isum=0 + do i=1,32 + if( hardbits(i) .ne. codeword(i) ) isum=isum+1 + enddo +! write(*,*) 'number of errors ',isum + endif + enddo + avits=real(itsum)/real(ngood+0.1) + snr2500=db-10.0 + write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,1x,i8,1x,f8.2,1x,f8.1)") db,snr2500,ngood,nue,nbadhash,ss,avits + +enddo + +end program ldpcsim diff --git a/lib/libration.f90 b/lib/libration.f90 new file mode 100644 index 00000000..7330d049 --- /dev/null +++ b/lib/libration.f90 @@ -0,0 +1,38 @@ +subroutine libration(jd,RA,Dec,xl,b) + +! Compute optical libration of moon at jd: that is, the sub-observer +! point (xl,b) in selenographic coordinates. RA and Dec are +! topocentric values. + + implicit real*8 (a-h,o-z) + parameter (RADS=0.0174532925199433d0) + parameter (TWOPI=6.28318530717959d0) + real*8 jd,j2000,mjd,lambda + + j2000=2451545.0d0 + RA2000=RA + Dec2000=Dec + year=2000.0d0 + (jd-j2000)/365.25d0 + mjd=jd-2400000.d0 + call sla_PRECES('FK5',year,2000.d0,RA2000,Dec2000) + call sla_EQECL(RA2000,Dec2000,mjd,lambda,beta) + day=jd - j2000 + t = day / 36525.d0 + xi = 1.54242 * RADS + ft = 93.2720993 + 483202.0175273 * t - .0034029 * t * t + b= ft / 360 + a = 360 * (b - floor(b)) + if (a.lt.0.d0) a = 360 + a; + f=a/57.2957795131d0 + omega=sla_dranrm(2.182439196d0 - t*33.7570446085d0 + t*t*3.6236526d-5) + w = lambda - omega + y = sin(w) * cos(beta) * cos(xi) - sin(beta) * sin(xi) + x = cos(w) * cos(beta) + a = sla_dranrm(atan2(y, x)) + xl = a - f + if(xl.lt.-0.25*TWOPI) xl=xl+TWOPI !Fix 'round the back' angles + if(xl.gt.0.25*TWOPI) xl=xl-TWOPI + b = asin(-sin(w) * cos(beta) * sin(xi) - sin(beta) * cos(xi)) + + return +end subroutine libration diff --git a/lib/lorentzian.f90 b/lib/lorentzian.f90 new file mode 100644 index 00000000..cd2257a7 --- /dev/null +++ b/lib/lorentzian.f90 @@ -0,0 +1,102 @@ +subroutine lorentzian(y,npts,a) + +! Input: y(npts); assume x(i)=i, i=1,npts +! Output: a(5) +! a(1) = baseline +! a(2) = amplitude +! a(3) = x0 +! a(4) = width +! a(5) = chisqr + + real y(npts) + real a(5) + real deltaa(4) + + a=0. + df=12000.0/8192.0 !df = 1.465 Hz + width=0. + ipk=0 + ymax=-1.e30 + do i=1,npts + if(y(i).gt.ymax) then + ymax=y(i) + ipk=i + endif +! write(50,3001) i,i*df,y(i) +!3001 format(i6,2f12.3) + enddo +! base=(sum(y(ipk-149:ipk-50)) + sum(y(ipk+51:ipk+150)))/200.0 + base=(sum(y(1:20)) + sum(y(npts-19:npts)))/40.0 + stest=ymax - 0.5*(ymax-base) + ssum=y(ipk) + do i=1,50 + if(ipk+i.gt.npts) exit + if(y(ipk+i).lt.stest) exit + ssum=ssum + y(ipk+i) + enddo + do i=1,50 + if(ipk-i.lt.1) exit + if(y(ipk-i).lt.stest) exit + ssum=ssum + y(ipk-i) + enddo + ww=ssum/y(ipk) + width=2 + t=ww*ww - 5.67 + if(t.gt.0.0) width=sqrt(t) + a(1)=base + a(2)=ymax-base + a(3)=ipk + a(4)=width + +! Now find Lorentzian parameters + + deltaa(1)=0.1 + deltaa(2)=0.1 + deltaa(3)=1.0 + deltaa(4)=1.0 + nterms=4 + +! Start the iteration + chisqr=0. + chisqr0=1.e6 + do iter=1,5 + do j=1,nterms + chisq1=fchisq0(y,npts,a) + fn=0. + delta=deltaa(j) +10 a(j)=a(j)+delta + chisq2=fchisq0(y,npts,a) + if(chisq2.eq.chisq1) go to 10 + if(chisq2.gt.chisq1) then + delta=-delta !Reverse direction + a(j)=a(j)+delta + tmp=chisq1 + chisq1=chisq2 + chisq2=tmp + endif +20 fn=fn+1.0 + a(j)=a(j)+delta + chisq3=fchisq0(y,npts,a) + if(chisq3.lt.chisq2) then + chisq1=chisq2 + chisq2=chisq3 + go to 20 + endif + +! Find minimum of parabola defined by last three points + delta=delta*(1./(1.+(chisq1-chisq2)/(chisq3-chisq2))+0.5) + a(j)=a(j)-delta + deltaa(j)=deltaa(j)*fn/3. +! write(*,4000) iter,j,a,chisq2 +!4000 format(i1,i2,4f10.4,f11.3) + enddo + chisqr=fchisq0(y,npts,a) +! write(*,4000) 0,0,a,chisqr + if(chisqr/chisqr0.gt.0.99) exit + chisqr0=chisqr + enddo + a(5)=chisqr + + return +end subroutine lorentzian + diff --git a/lib/lpf1.f90 b/lib/lpf1.f90 new file mode 100644 index 00000000..f2bb2377 --- /dev/null +++ b/lib/lpf1.f90 @@ -0,0 +1,29 @@ +subroutine lpf1(dd,jz,dat,jz2) + + parameter (NFFT1=64*11025,NFFT2=32*11025) + real dd(jz) + real dat(jz) + real x(NFFT1) + complex cx(0:NFFT1/2) + equivalence (x,cx) + save x,cx + + fac=1.0/float(NFFT1) + x(1:jz)=fac*dd(1:jz) + x(jz+1:NFFT1)=0.0 + call four2a(x,NFFT1,1,-1,0) !Forwarxd FFT, r2c + cx(NFFT2/2:)=0.0 + +! df=11025.0/NFFT1 +! do i=1,NFFT1/2 +! sx=real(cx(i))**2 + aimag(cx(i))**2 +! write(50,3000) i*df,sx +!3000 format(f15.6,e12.3) +! enddo + + call four2a(cx,NFFT2,1,1,-1) !Inverse FFT, c2r + jz2=jz/2 + dat(1:jz2)=x(1:jz2) + + return +end subroutine lpf1 diff --git a/lib/makepings.f90 b/lib/makepings.f90 new file mode 100644 index 00000000..beedcc79 --- /dev/null +++ b/lib/makepings.f90 @@ -0,0 +1,26 @@ +subroutine makepings(pings,npts,width,sig) + + real pings(npts) + real*8 t + real t0(14) + + iping0=-999 + dt=1.0/12000.0 + do i=1,14 + t0(i)=i !Make pings at t=1, 2, ... 14 s. + enddo + amp=sig + + do i=1,npts + iping=min(max(1,i/12000),14) + t=(i*dt-t0(iping))/width + if(t.lt.0.d0 .and. t.lt.10.0) then !???? + fac=0. + else + fac=2.718*t*dexp(-t) + endif + pings(i)=fac*amp + enddo + + return +end subroutine makepings diff --git a/lib/mixlpf.f90 b/lib/mixlpf.f90 new file mode 100644 index 00000000..cd775ab8 --- /dev/null +++ b/lib/mixlpf.f90 @@ -0,0 +1,25 @@ +subroutine mixlpf(x1,nbfo,c0) + + real*4 x1(512) + real*8 twopi,phi,dphi + complex c1(512),c2(105+512) + complex c0(64) + data phi/0.d0/ + save phi,c2 + + twopi=8.d0*atan(1.d0) + dphi=twopi*nbfo/12000.d0 + + do i=1,512 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + c1(i)=x1(i)*cmplx(cos(xphi),sin(xphi)) + enddo + c2(106:105+512)=c1 + + call fil3c(c2,105+512,c0,n2) + c2(1:105)=c1(512-104:512) !Save 105 trailing samples + + return +end subroutine mixlpf diff --git a/lib/moon2.f90 b/lib/moon2.f90 deleted file mode 100644 index 8498267e..00000000 --- a/lib/moon2.f90 +++ /dev/null @@ -1,166 +0,0 @@ -subroutine moon2(y,m,Day,UT,lon,lat,RA,Dec,topRA,topDec, & - LST,HA,Az,El,dist) - - implicit none - - integer y !Year - integer m !Month - integer Day !Day - real*8 UT !UTC in hours - real*8 RA,Dec !RA and Dec of moon - -! NB: Double caps are single caps in the writeup. - - real*8 NN !Longitude of ascending node - real*8 i !Inclination to the ecliptic - real*8 w !Argument of perigee - real*8 a !Semi-major axis - real*8 e !Eccentricity - real*8 MM !Mean anomaly - - real*8 v !True anomaly - real*8 EE !Eccentric anomaly - real*8 ecl !Obliquity of the ecliptic - - real*8 d !Ephemeris time argument in days - real*8 r !Distance to sun, AU - real*8 xv,yv !x and y coords in ecliptic - real*8 lonecl,latecl !Ecliptic long and lat of moon - real*8 xg,yg,zg !Ecliptic rectangular coords - real*8 Ms !Mean anomaly of sun - real*8 ws !Argument of perihelion of sun - real*8 Ls !Mean longitude of sun (Ns=0) - real*8 Lm !Mean longitude of moon - real*8 DD !Mean elongation of moon - real*8 FF !Argument of latitude for moon - real*8 xe,ye,ze !Equatorial geocentric coords of moon - real*8 mpar !Parallax of moon (r_E / d) - real*8 lat,lon !Station coordinates on earth - real*8 gclat !Geocentric latitude - real*8 rho !Earth radius factor - real*8 GMST0,LST,HA - real*8 g - real*8 topRA,topDec !Topocentric coordinates of Moon - real*8 Az,El - real*8 dist - - real*8 rad,twopi,pi,pio2 - data rad/57.2957795131d0/,twopi/6.283185307d0/ - - d=367*y - 7*(y+(m+9)/12)/4 + 275*m/9 + Day - 730530 + UT/24.d0 - ecl = 23.4393d0 - 3.563d-7 * d - -! Orbital elements for Moon: - NN = 125.1228d0 - 0.0529538083d0 * d - i = 5.1454d0 - w = mod(318.0634d0 + 0.1643573223d0 * d + 360000.d0,360.d0) - a = 60.2666d0 - e = 0.054900d0 - MM = mod(115.3654d0 + 13.0649929509d0 * d + 360000.d0,360.d0) - - EE = MM + e*rad*sin(MM/rad) * (1.d0 + e*cos(MM/rad)) - EE = EE - (EE - e*rad*sin(EE/rad)-MM) / (1.d0 - e*cos(EE/rad)) - EE = EE - (EE - e*rad*sin(EE/rad)-MM) / (1.d0 - e*cos(EE/rad)) - - xv = a * (cos(EE/rad) - e) - yv = a * (sqrt(1.d0-e*e) * sin(EE/rad)) - - v = mod(rad*atan2(yv,xv)+720.d0,360.d0) - r = sqrt(xv*xv + yv*yv) - -! Get geocentric position in ecliptic rectangular coordinates: - - xg = r * (cos(NN/rad)*cos((v+w)/rad) - & - sin(NN/rad)*sin((v+w)/rad)*cos(i/rad)) - yg = r * (sin(NN/rad)*cos((v+w)/rad) + & - cos(NN/rad)*sin((v+w)/rad)*cos(i/rad)) - zg = r * (sin((v+w)/rad)*sin(i/rad)) - -! Ecliptic longitude and latitude of moon: - lonecl = mod(rad*atan2(yg/rad,xg/rad)+720.d0,360.d0) - latecl = rad*atan2(zg/rad,sqrt(xg*xg + yg*yg)/rad) - -! Now include orbital perturbations: - Ms = mod(356.0470d0 + 0.9856002585d0 * d + 3600000.d0,360.d0) - ws = 282.9404d0 + 4.70935d-5*d - Ls = mod(Ms + ws + 720.d0,360.d0) - Lm = mod(MM + w + NN+720.d0,360.d0) - DD = mod(Lm - Ls + 360.d0,360.d0) - FF = mod(Lm - NN + 360.d0,360.d0) - - lonecl = lonecl & - -1.274d0 * sin((MM-2.d0*DD)/rad) & - +0.658d0 * sin(2.d0*DD/rad) & - -0.186d0 * sin(Ms/rad) & - -0.059d0 * sin((2.d0*MM-2.d0*DD)/rad) & - -0.057d0 * sin((MM-2.d0*DD+Ms)/rad) & - +0.053d0 * sin((MM+2.d0*DD)/rad) & - +0.046d0 * sin((2.d0*DD-Ms)/rad) & - +0.041d0 * sin((MM-Ms)/rad) & - -0.035d0 * sin(DD/rad) & - -0.031d0 * sin((MM+Ms)/rad) & - -0.015d0 * sin((2.d0*FF-2.d0*DD)/rad) & - +0.011d0 * sin((MM-4.d0*DD)/rad) - - latecl = latecl & - -0.173d0 * sin((FF-2.d0*DD)/rad) & - -0.055d0 * sin((MM-FF-2.d0*DD)/rad) & - -0.046d0 * sin((MM+FF-2.d0*DD)/rad) & - +0.033d0 * sin((FF+2.d0*DD)/rad) & - +0.017d0 * sin((2.d0*MM+FF)/rad) - - r = 60.36298d0 & - - 3.27746d0*cos(MM/rad) & - - 0.57994d0*cos((MM-2.d0*DD)/rad) & - - 0.46357d0*cos(2.d0*DD/rad) & - - 0.08904d0*cos(2.d0*MM/rad) & - + 0.03865d0*cos((2.d0*MM-2.d0*DD)/rad) & - - 0.03237d0*cos((2.d0*DD-Ms)/rad) & - - 0.02688d0*cos((MM+2.d0*DD)/rad) & - - 0.02358d0*cos((MM-2.d0*DD+Ms)/rad) & - - 0.02030d0*cos((MM-Ms)/rad) & - + 0.01719d0*cos(DD/rad) & - + 0.01671d0*cos((MM+Ms)/rad) - - dist=r*6378.140d0 - -! Geocentric coordinates: -! Rectangular ecliptic coordinates of the moon: - - xg = r * cos(lonecl/rad)*cos(latecl/rad) - yg = r * sin(lonecl/rad)*cos(latecl/rad) - zg = r * sin(latecl/rad) - -! Rectangular equatorial coordinates of the moon: - xe = xg - ye = yg*cos(ecl/rad) - zg*sin(ecl/rad) - ze = yg*sin(ecl/rad) + zg*cos(ecl/rad) - -! Right Ascension, Declination: - RA = mod(rad*atan2(ye,xe)+360.d0,360.d0) - Dec = rad*atan2(ze,sqrt(xe*xe + ye*ye)) - -! Now convert to topocentric system: - mpar=rad*asin(1.d0/r) -! alt_topoc = alt_geoc - mpar*cos(alt_geoc) - gclat = lat - 0.1924d0*sin(2.d0*lat/rad) - rho = 0.99883d0 + 0.00167d0*cos(2.d0*lat/rad) - GMST0 = (Ls + 180.d0)/15.d0 - LST = mod(GMST0+UT+lon/15.d0+48.d0,24.d0) !LST in hours - HA = 15.d0*LST - RA !HA in degrees - g = rad*atan(tan(gclat/rad)/cos(HA/rad)) - topRA = RA - mpar*rho*cos(gclat/rad)*sin(HA/rad)/cos(Dec/rad) - topDec = Dec - mpar*rho*sin(gclat/rad)*sin((g-Dec)/rad)/sin(g/rad) - - HA = 15.d0*LST - topRA !HA in degrees - if(HA.gt.180.d0) HA=HA-360.d0 - if(HA.lt.-180.d0) HA=HA+360.d0 - - pi=0.5d0*twopi - pio2=0.5d0*pi - call dcoord(pi,pio2-lat/rad,0.d0,lat/rad,ha*twopi/360,topDec/rad,az,el) - Az=az*rad - El=El*rad - - return -end subroutine moon2 diff --git a/lib/moondop.f90 b/lib/moondop.f90 deleted file mode 100644 index 21056586..00000000 --- a/lib/moondop.f90 +++ /dev/null @@ -1,72 +0,0 @@ -subroutine MoonDop(nyear,month,nday,uth4,lon4,lat4,RAMoon4, & - DecMoon4,LST4,HA4,AzMoon4,ElMoon4,vr4,dist4) - - implicit real*8 (a-h,o-z) - real*4 uth4 !UT in hours - real*4 lon4 !West longitude, degrees - real*4 lat4 !Latitude, degrees - real*4 RAMoon4 !Topocentric RA of moon, hours - real*4 DecMoon4 !Topocentric Dec of Moon, degrees - real*4 LST4 !Locat sidereal time, hours - real*4 HA4 !Local Hour angle, degrees - real*4 AzMoon4 !Topocentric Azimuth of moon, degrees - real*4 ElMoon4 !Topocentric Elevation of moon, degrees - real*4 vr4 !Radial velocity of moon wrt obs, km/s - real*4 dist4 !Echo time, seconds - - real*8 LST - real*8 RME(6) !Vector from Earth center to Moon - real*8 RAE(6) !Vector from Earth center to Obs - real*8 RMA(6) !Vector from Obs to Moon - real*8 rme0(6) - logical km - - data rad/57.2957795130823d0/,twopi/6.28310530717959d0/ - - km=.true. - dlat=lat4/rad - dlong1=lon4/rad - elev1=200.d0 - call geocentric(dlat,elev1,dlat1,erad1) - - dt=100.d0 !For numerical derivative, in seconds - UT=uth4 - -! NB: geodetic latitude used here, but geocentric latitude used when -! determining Earth-rotation contribution to Doppler. - - call moon2(nyear,month,nDay,UT-dt/3600.d0,dlong1*rad,dlat*rad, & - RA,Dec,topRA,topDec,LST,HA,Az0,El0,dist) - call toxyz(RA/rad,Dec/rad,dist,rme0) !Convert to rectangular coords - - call moon2(nyear,month,nDay,UT,dlong1*rad,dlat*rad, & - RA,Dec,topRA,topDec,LST,HA,Az,El,dist) - call toxyz(RA/rad,Dec/rad,dist,rme) !Convert to rectangular coords - - phi=LST*twopi/24.d0 - call toxyz(phi,dlat1,erad1,rae) !Gencentric numbers used here! - radps=twopi/(86400.d0/1.002737909d0) - rae(4)=-rae(2)*radps !Vel of Obs wrt Earth center - rae(5)=rae(1)*radps - rae(6)=0.d0 - - do i=1,3 - rme(i+3)=(rme(i)-rme0(i))/dt - rma(i)=rme(i)-rae(i) - rma(i+3)=rme(i+3)-rae(i+3) - enddo - - call fromxyz(rma,alpha1,delta1,dtopo0) !Get topocentric coords - vr=dot(rma(4),rma)/dtopo0 - - RAMoon4=topRA - DecMoon4=topDec - LST4=LST - HA4=HA - AzMoon4=Az - ElMoon4=El - vr4=vr - dist4=dist - - return -end subroutine MoonDop diff --git a/lib/moondopjpl.f90 b/lib/moondopjpl.f90 new file mode 100644 index 00000000..34271ea1 --- /dev/null +++ b/lib/moondopjpl.f90 @@ -0,0 +1,43 @@ +subroutine MoonDopJPL(nyear,month,nday,uth4,lon4,lat4,RAMoon4, & + DecMoon4,LST4,HA4,AzMoon4,ElMoon4,vr4,dist4) + + implicit real*8 (a-h,o-z) + real*4 uth4 !UT in hours + real*4 lon4 !East longitude, degrees + real*4 lat4 !Latitude, degrees + real*4 RAMoon4 !Topocentric RA of moon, hours + real*4 DecMoon4 !Topocentric Dec of Moon, degrees + real*4 LST4 !Locat sidereal time, hours + real*4 HA4 !Local Hour angle, degrees + real*4 AzMoon4 !Topocentric Azimuth of moon, degrees + real*4 ElMoon4 !Topocentric Elevation of moon, degrees + real*4 vr4 !Radial velocity of moon wrt obs, km/s + real*4 dist4 !Echo time, seconds + + twopi=8.d0*atan(1.d0) !Define some constants + rad=360.d0/twopi + clight=2.99792458d5 + + call sla_CLDJ(nyear,month,nday,djutc,j) + djutc=djutc + uth4/24.d0 + dut=-0.460d0 + + east_long=lon4/rad + geodetic_lat=lat4/rad + height=40. + nspecial=0 + + call ephem(djutc,dut,east_long,geodetic_lat,height,nspecial, & + RA,Dec,Az,El,techo,dop,fspread_1GHz,vr) + + RAMoon4=RA + DecMoon4=Dec + LST4=0. !These two variables not presently used + HA4=0. + AzMoon4=Az*rad + ElMoon4=El*rad + vr4=vr + dist4=techo + + return +end subroutine MoonDopJPL diff --git a/lib/msk144_freq_search.f90 b/lib/msk144_freq_search.f90 new file mode 100644 index 00000000..5029816a --- /dev/null +++ b/lib/msk144_freq_search.f90 @@ -0,0 +1,50 @@ +subroutine msk144_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & + cdat2,xmax,bestf,cs,xccs) + + parameter (NSPM=864,NZ=7*NSPM) + complex cdat(NZ) + complex cdat2(NZ) + complex c(NSPM) !Coherently averaged complex data + complex ct2(2*NSPM) + complex cs(NSPM) + complex cb(42) !Complex waveform for sync word + complex cc(0:NSPM-1) + real xcc(0:NSPM-1) + real xccs(0:NSPM-1) + integer navmask(nframes) !Tells which frames to average + + navg=sum(navmask) + n=nframes*NSPM + fac=1.0/(48.0*sqrt(float(navg))) + + do ifr=if1,if2 !Find freq that maximizes sync + ferr=ifr*delf + call tweak1(cdat,n,-(fc+ferr),cdat2) + c=0 + sumw=0. + do i=1,nframes + ib=(i-1)*NSPM+1 + ie=ib+NSPM-1 + if(navmask(i).eq.1) c=c + cdat2(ib:ie) + enddo + + cc=0 + ct2(1:NSPM)=c + ct2(NSPM+1:2*NSPM)=c + + do ish=0,NSPM-1 + cc(ish)=dot_product(ct2(1+ish:42+ish)+ct2(337+ish:378+ish),cb(1:42)) + enddo + + xcc=abs(cc) + xb=maxval(xcc)*fac + if(xb.gt.xmax) then + xmax=xb + bestf=ferr + cs=c + xccs=xcc + endif + enddo + + return +end subroutine msk144_freq_search diff --git a/lib/msk144code.f90 b/lib/msk144code.f90 new file mode 100644 index 00000000..f49bebca --- /dev/null +++ b/lib/msk144code.f90 @@ -0,0 +1,70 @@ +program msk144code + +! Provides examples of message packing, bit and symbol ordering, +! LDPC encoding, and other necessary details of the MSK144 protocol. + + use packjt + character msg*22,msgsent*22,decoded,bad*1,msgtype*13,mygrid*6 + integer*4 i4tone(144) + logical*1 bcontest + include 'testmsg.f90' + data mygrid/'FN20qi'/ + + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: msk144code "message"' + print*,' msk144code -t' + print*,' ' + print*,'Examples:' + print*,' msk144code "KA1ABC WB9XYZ EN37"' + print*,' msk144code " R-03"' + print*,' msk144code "KA1ABC WB9XYZ R EN37"' + go to 999 + endif + + call getarg(1,msg) + nmsg=1 + if(msg(1:2).eq."-t") then + testmsg(NTEST+1)=" -03" + testmsg(NTEST+2)=" R+03" + testmsg(NTEST+3)=" RRR" + testmsg(NTEST+4)=" 73" + testmsg(NTEST+5)="KA1ABC WB9XYZ R EN37" + nmsg=NTEST+5 + endif + + write(*,1010) +1010 format(" Message Decoded Err? Type"/ & + 74("-")) + do imsg=1,nmsg + if(nmsg.gt.1) msg=testmsg(imsg) + call fmtmsg(msg,iz) !To upper case, collapse multiple blanks + i1=len(trim(msg))-5 + bcontest=.false. + if(msg(i1:i1+1).eq.'R ') bcontest=.true. + ichk=0 + call genmsk144(msg,mygrid,ichk,bcontest,msgsent,i4tone,itype) + + msgtype="" + if(itype.eq.1) msgtype="Std Msg" + if(itype.eq.2) msgtype="Type 1 prefix" + if(itype.eq.3) msgtype="Type 1 suffix" + if(itype.eq.4) msgtype="Type 2 prefix" + if(itype.eq.5) msgtype="Type 2 suffix" + if(itype.eq.6) msgtype="Free text" + if(itype.eq.7) msgtype="Hashed calls" + + bad=" " + if(msgsent.ne.msg) bad="*" + write(*,1020) imsg,msg,msgsent,bad,itype,msgtype +1020 format(i2,'.',2x,a22,2x,a22,3x,a1,i3,": ",a13) + enddo + + if(nmsg.eq.1) then + n=144 + if(msg(1:1).eq."<") n=40 + write(*,1030) i4tone(1:n) +1030 format(/'Channel symbols'/(72i1)) + endif + +999 end program msk144code diff --git a/lib/msk144d2.f90 b/lib/msk144d2.f90 new file mode 100644 index 00000000..47eb43b6 --- /dev/null +++ b/lib/msk144d2.f90 @@ -0,0 +1,138 @@ +program msk144d2 + + ! Test the msk144 decoder for WSJT-X + + use options + use timer_module, only: timer + use timer_impl, only: init_timer + use readwav + + character c + character*80 line + character*512 datadir + character*500 infile + character*12 mycall,hiscall + character*6 mygrid + character(len=500) optarg + + logical :: display_help=.false. + logical*1 bShMsgs + logical*1 bcontest + logical*1 btrain + logical*1 bswl + + type(wav_header) :: wav + + integer*2 id2(30*12000) + integer*2 ichunk(7*1024) + + real*8 pcoeffs(5) + + type (option) :: long_options(9) = [ & + option ('ndepth',.true.,'c','ndepth',''), & + option ('dxcall',.true.,'d','hiscall',''), & + option ('evemode',.true.,'e','Must be used with -s.',''), & + option ('frequency',.true.,'f','rxfreq',''), & + option ('help',.false.,'h','Display this help message',''), & + option ('mycall',.true.,'m','mycall',''), & + option ('nftol',.true.,'n','nftol',''), & + option ('rxequalize',.false.,'r','Rx Equalize',''), & + option ('short',.false.,'s','enable Sh','') & + ] + t0=0.0 + ndepth=3 + ntol=100 + nrxfreq=1500 + mycall='' + mygrid='EN50WC' + hiscall='' + bShMsgs=.false. + bcontest=.false. + btrain=.false. + bswl=.false. + datadir='.' + pcoeffs=0.d0 + + do + call getopt('c:d:ef:hm:n:rs',long_options,c,optarg,narglen,nstat,noffset,nremain,.true.) + if( nstat .ne. 0 ) then + exit + end if + select case (c) + case ('c') + read (optarg(:narglen), *) ndepth + case ('d') + read (optarg(:narglen), *) hiscall + case ('e') + bswl=.true. + case ('f') + read (optarg(:narglen), *) nrxfreq + case ('h') + display_help = .true. + case ('m') + read (optarg(:narglen), *) mycall + case ('n') + read (optarg(:narglen), *) ntol + case ('r') + btrain=.true. + case ('s') + bShMsgs=.true. + end select + end do + + if(display_help .or. nstat.lt.0 .or. nremain.lt.1) then + print *, '' + print *, 'Usage: msk144d [OPTIONS] file1 [file2 ...]' + print *, '' + print *, ' msk144 decode pre-recorded .WAV file(s)' + print *, '' + print *, 'OPTIONS:' + do i = 1, size (long_options) + call long_options(i) % print (6) + end do + go to 999 + endif + + call init_timer ('timer.out') + call timer('msk144 ',0) + ndecoded=0 + do ifile=noffset+1,noffset+nremain + call get_command_argument(ifile,optarg,narglen) + infile=optarg(:narglen) + call timer('read ',0) + call wav%read (infile) + i1=index(infile,'.wav') + if( i1 .eq. 0 ) i1=index(infile,'.WAV') + read(infile(i1-6:i1-1),*,err=998) nutc + inquire(FILE=infile,SIZE=isize) + npts=min((isize-216)/2,360000) + read(unit=wav%lun) id2(1:npts) + close(unit=wav%lun) + call timer('read ',1) + + do i=1,npts-7*1024+1,7*512 + ichunk=id2(i:i+7*1024-1) + tsec=(i-1)/12000.0 + tt=sum(float(abs(id2(i:i+7*512-1)))) + if( tt .ne. 0.0 ) then + call mskrtd(ichunk,nutc,tsec,ntol,nrxfreq,ndepth,mycall,mygrid,hiscall,bShMsgs, & + bcontest,btrain,pcoeffs,bswl,datadir,line) + if( index(line,"&") .ne. 0 .or. & + index(line,"^") .ne. 0 .or. & + index(line,"!") .ne. 0 .or. & + index(line,"@") .ne. 0 ) then + write(*,*) line + endif + endif + enddo + enddo + + call timer('msk144 ',1) + call timer('msk144 ',101) + go to 999 + +998 print*,'Cannot read from file:' + print*,infile + +999 continue +end program msk144d2 diff --git a/lib/msk144decodeframe.f90 b/lib/msk144decodeframe.f90 new file mode 100644 index 00000000..37b9f802 --- /dev/null +++ b/lib/msk144decodeframe.f90 @@ -0,0 +1,107 @@ +subroutine msk144decodeframe(c,softbits,msgreceived,nsuccess,recent_calls,nrecent) +! use timer_module, only: timer + + parameter (NSPM=864) + character*22 msgreceived + character*12 recent_calls(nrecent) + complex cb(42) + complex cfac,cca,ccb + complex c(NSPM) + integer*1 decoded(80) + integer s8(8),hardbits(144) + real*8 dt, fs, pi, twopi + real cbi(42),cbq(42) + real pp(12) + real softbits(144) + real llr(128) + logical first + data first/.true./ + data s8/0,1,1,1,0,0,1,0/ + save first,cb,fs,pi,twopi,dt,s8,pp + + if(first) then +! define half-sine pulse and raised-cosine edge window + pi=4d0*datan(1d0) + twopi=8d0*datan(1d0) + fs=12000.0 + dt=1.0/fs + + do i=1,12 + angle=(i-1)*pi/12.0 + pp(i)=sin(angle) + enddo + +! define the sync word waveforms + s8=2*s8-1 + cbq(1:6)=pp(7:12)*s8(1) + cbq(7:18)=pp*s8(3) + cbq(19:30)=pp*s8(5) + cbq(31:42)=pp*s8(7) + cbi(1:12)=pp*s8(2) + cbi(13:24)=pp*s8(4) + cbi(25:36)=pp*s8(6) + cbi(37:42)=pp(1:6)*s8(8) + cb=cmplx(cbi,cbq) + first=.false. + endif + + nsuccess=0 + msgreceived=' ' + +! Estimate carrier phase. + cca=sum(c(1:1+41)*conjg(cb)) + ccb=sum(c(1+56*6:1+56*6+41)*conjg(cb)) + cfac=ccb*conjg(cca) + phase0=atan2(imag(cca+ccb),real(cca+ccb)) + +! Remove phase error - want constellation rotated so that sample points lie on I/Q axes + cfac=cmplx(cos(phase0),sin(phase0)) + c=c*conjg(cfac) + +! matched filter - + softbits(1)=sum(imag(c(1:6))*pp(7:12))+sum(imag(c(864-5:864))*pp(1:6)) + softbits(2)=sum(real(c(1:12))*pp) + do i=2,72 + softbits(2*i-1)=sum(imag(c(1+(i-1)*12-6:1+(i-1)*12+5))*pp) + softbits(2*i)=sum(real(c(7+(i-1)*12-6:7+(i-1)*12+5))*pp) + enddo + +! sync word hard error weight is used as a discriminator for +! frames that have reasonable probability of decoding + hardbits=0 + do i=1,144 + if( softbits(i) .ge. 0.0 ) then + hardbits(i)=1 + endif + enddo + nbadsync1=(8-sum( (2*hardbits(1:8)-1)*s8 ) )/2 + nbadsync2=(8-sum( (2*hardbits(1+56:8+56)-1)*s8 ) )/2 + nbadsync=nbadsync1+nbadsync2 + if( nbadsync .gt. 4 ) then + return + endif + +! normalize the softsymbols before submitting to decoder + sav=sum(softbits)/144 + s2av=sum(softbits*softbits)/144 + ssig=sqrt(s2av-sav*sav) + softbits=softbits/ssig + + sigma=0.75 + llr(1:48)=softbits(9:9+47) + llr(49:128)=softbits(65:65+80-1) + llr=2.0*llr/(sigma*sigma) + + max_iterations=10 +! call timer('bpdec144 ',0) + call bpdecode144(llr,max_iterations,decoded,niterations) +! call timer('bpdec144 ',1) + if( niterations .ge. 0.0 ) then + call extractmessage144(decoded,msgreceived,nhashflag,recent_calls,nrecent) + if( nhashflag .gt. 0 ) then ! CRCs match, so print it + nsuccess=1 + endif + endif + + return +end subroutine msk144decodeframe diff --git a/lib/msk144sd.f90 b/lib/msk144sd.f90 new file mode 100644 index 00000000..267fff54 --- /dev/null +++ b/lib/msk144sd.f90 @@ -0,0 +1,197 @@ +program msk144sd +! +! A simple decoder for slow msk144. +! Can be used as a (slow) brute-force multi-decoder by looping +! over a set of carrier frequencies. +! + use options + use timer_module, only: timer + use timer_impl, only: init_timer + use readwav + + parameter (NRECENT=10) + parameter (NSPM=864) + parameter (NPATTERNS=4) + + character ch + character*80 line + character*500 infile + character*12 mycall,hiscall + character*6 mygrid + character(len=500) optarg + character*22 msgreceived + character*12 recent_calls(NRECENT) + + complex cdat(30*375) + complex c(NSPM) + complex ct(NSPM) + + real softbits(144) + real xmc(NPATTERNS) + + logical :: display_help=.false. + + type(wav_header) :: wav + + integer iavmask(8) + integer iavpatterns(8,NPATTERNS) + integer npkloc(10) + + integer*2 id2(30*12000) + integer*2 ichunk(7*1024) + + data iavpatterns/ & + 1,1,1,1,0,0,0,0, & + 0,1,1,1,1,0,0,0, & + 0,0,1,1,1,1,0,0, & + 1,1,1,1,1,1,0,0/ + data xmc/2.0,4.5,2.5,3.0/ + + type (option) :: long_options(2) = [ & + option ('frequency',.true.,'f','rxfreq',''), & + option ('help',.false.,'h','Display this help message','') & + ] + t0=0.0 + ntol=100 + nrxfreq=1500 + + do + call getopt('f:h',long_options,ch,optarg,narglen,nstat,noffset,nremain,.true.) + if( nstat .ne. 0 ) then + exit + end if + select case (ch) + case ('f') + read (optarg(:narglen), *) nrxfreq + case ('h') + display_help = .true. + end select + end do + + if(display_help .or. nstat.lt.0 .or. nremain.lt.1) then + print *, '' + print *, 'Usage: msk144sd [OPTIONS] file1 [file2 ...]' + print *, '' + print *, ' decode pre-recorded .WAV file(s)' + print *, '' + print *, 'OPTIONS:' + do i = 1, size (long_options) + call long_options(i) % print (6) + end do + go to 999 + endif + + call init_timer ('timer.out') + call timer('msk144 ',0) + ndecoded=0 + do ifile=noffset+1,noffset+nremain + call get_command_argument(ifile,optarg,narglen) + infile=optarg(:narglen) + call timer('read ',0) + call wav%read (infile) + i1=index(infile,'.wav') + if( i1 .eq. 0 ) i1=index(infile,'.WAV') + read(infile(i1-6:i1-1),*,err=998) nutc + inquire(FILE=infile,SIZE=isize) + npts=min((isize-216)/2,360000) + read(unit=wav%lun) id2(1:npts) + close(unit=wav%lun) + call timer('read ',1) + +! do if=1,89 ! brute force multi-decoder + fo=nrxfreq +! fo=(if-1)*25.0+300.0 + call msksddc(id2,npts,fo,cdat) + np=npts/32 + ntol=200 ! actual ntol is ntol/32=6.25 Hz. Detection window is 12.5 Hz wide + fc=1500.0 + call msk144spd(cdat,np,ntol,ndecodesuccess,msgreceived,fc,fest,tdec,navg,ct, & + softbits,recent_calls,nrecent) + nsnr=0 ! need an snr estimate + if( ndecodesuccess .eq. 1 ) then + fest=fo+fest-fc ! fudging because spd thinks input signal is at 1500 Hz + goto 900 + endif +! If short ping decoder doesn't find a decode + npat=NPATTERNS + do iavg=1,npat + iavmask=iavpatterns(1:8,iavg) + navg=sum(iavmask) + deltaf=4.0/real(navg) ! search increment for frequency sync + npeaks=4 + ntol=200 + fc=1500.0 + call msk144sync(cdat(1:6*NSPM),6,ntol,deltaf,iavmask,npeaks,fc, & + fest,npkloc,nsyncsuccess,xmax,c) + if( nsyncsuccess .eq. 0 ) cycle + + do ipk=1,npeaks + do is=1,3 + ic0=npkloc(ipk) + if(is.eq.2) ic0=max(1,ic0-1) + if(is.eq.3) ic0=min(NSPM,ic0+1) + ct=cshift(c,ic0-1) + call msk144decodeframe(ct,softbits,msgreceived,ndecodesuccess, & + recent_calls,nrecent) + if(ndecodesuccess .gt. 0) then + tdec=tsec+xmc(iavg)*tframe + fest=fo+(fest-fc)/32.0 + goto 900 + endif + enddo !Slicer dither + enddo !Peak loop + enddo + +! enddo +900 continue + if( ndecodesuccess .gt. 0 ) then + write(*,1020) nutc,nsnr,tdec,nint(fest),' % ',msgreceived,navg +1020 format(i6.6,i4,f5.1,i5,a3,a22,i4) + endif + enddo + + call timer('msk144 ',1) + call timer('msk144 ',101) + go to 999 + +998 print*,'Cannot read from file:' + print*,infile + +999 continue +end program msk144sd + +subroutine msksddc(id2,npts,fc,cdat) + +! The msk144 detector/demodulator/decoder will decode signals +! with carrier frequency, fc, in the range fN/4 +/- 0.03333*fN. +! +! For slow MSK144 with nslow=32: +! fs=12000/32=375 Hz, fN=187.5 Hz +! +! This routine accepts input samples with fs=12000 Hz. It +! downconverts and decimates by 32 to center a signal with input carrier +! frequency fc at new carrier frequency 1500/32=46.875 Hz. +! The analytic signal is returned. + + parameter (NFFT1=30*12000,NFFT2=30*375) + integer*2 id2(npts) + complex cx(0:NFFT1) + complex cdat(30*375) + + dt=1.0/12000.0 + df=1.0/(NFFT1*dt) + icenter=int(fc/df+0.5) + i46p875=int(46.875/df+0.5) + ishift=icenter-i46p875 + cx=cmplx(0.0,0.0) + cx(1:npts)=id2 + call four2a(cx,NFFT1,1,-1,1) + cx=cshift(cx,ishift) + cx(1)=0.5*cx(1) + cx(2*i46p875+1:)=cmplx(0.0,0.0) + call four2a(cx,NFFT2,1,1,1) + cdat(1:npts/32)=cx(0:npts/32-1)/NFFT1 + return + +end subroutine msksddc + diff --git a/lib/msk144signalquality.f90 b/lib/msk144signalquality.f90 new file mode 100644 index 00000000..24a146c6 --- /dev/null +++ b/lib/msk144signalquality.f90 @@ -0,0 +1,219 @@ +subroutine msk144signalquality(cframe,snr,freq,t0,softbits,msg,dxcall, & + btrain,datadir,nbiterrors,eyeopening,pcoeffs) + + character*22 msg,msgsent + character*12 dxcall + character*12 training_dxcall + character*12 trained_dxcall + character*6 mygrid + character*512 pcoeff_filename + character*8 date + character*10 time + character*5 zone + character*512 datadir + + complex cframe(864) + complex cross(864) + complex cross_avg(864) + complex canalytic(1024) + complex cmodel(1024) + + integer i4tone(144) + integer hardbits(144) + integer msgbits(144) + integer values(8) + + logical*1 bcontest + logical*1 btrain + logical*1 first + logical*1 currently_training + logical*1 msg_has_dxcall + logical*1 is_training_frame + + real softbits(144) + real waveform(0:863) + real d(1024) + real phase(864) + real twopi,freq,phi,dphi0,dphi1,dphi + real*8 x(145),y(145),pp(145),sigmay(145),a(5),chisqr + real*8 pcoeffs(5) + + parameter (NFREQLOW=500,NFREQHIGH=2500) + data first/.true./ + save cross_avg,wt_avg,first,currently_training, & + navg,tlast,training_dxcall,trained_dxcall + + if (first) then + navg=0 + cross=cmplx(0.0,0.0) + cross_avg=cmplx(0.0,0.0) + wt_avg=0.0 + tlast=0.0 + trained_dxcall(1:12)=' ' + training_dxcall(1:12)=' ' + currently_training=.false. + first=.false. + endif + + if( (currently_training .and. (dxcall .ne. training_dxcall)) .or. & + (navg .gt. 10 )) then !reset and retrain + navg=0 + cross=cmplx(0.0,0.0) + cross_avg=cmplx(0.0,0.0) + wt_avg=0.0 + tlast=0.0 + trained_dxcall(1:12)=' ' + currently_training=.false. + training_dxcall(1:12)=' ' + trained_dxcall(1:12)=' ' +!write(*,*) 'reset to untrained state ' + endif + + indx_dxcall=index(msg,trim(dxcall)) + msg_has_dxcall = indx_dxcall .ge. 4 + + if( btrain .and. msg_has_dxcall .and. (.not. currently_training) ) then + currently_training=.true. + training_dxcall=trim(dxcall) + trained_dxcall(1:12)=' ' +!write(*,*) 'start training on call ',training_dxcall + endif + + if( msg_has_dxcall .and. currently_training ) then + trained_dxcall(1:12)=' ' + training_dxcall=dxcall + endif + +! use decoded message to figure out how many bit errors in the frame + do i=1, 144 + hardbits(i)=0 + if(softbits(i) .gt. 0 ) hardbits(i)=1 + enddo + +! generate tones from decoded message + mygrid="EN50" + ichk=0 + bcontest=.false. + call genmsk144(msg,mygrid,ichk,bcontest,msgsent,i4tone,itype) + +! reconstruct message bits from tones + msgbits(1)=0 + do i=1,143 + if( i4tone(i) .eq. 0 ) then + if( mod(i,2) .eq. 1 ) then + msgbits(i+1)=msgbits(i) + else + msgbits(i+1)=mod(msgbits(i)+1,2) + endif + else + if( mod(i,2) .eq. 1 ) then + msgbits(i+1)=mod(msgbits(i)+1,2) + else + msgbits(i+1)=msgbits(i) + endif + endif + enddo + + nbiterrors=0 + do i=1,144 + if( hardbits(i) .ne. msgbits(i) ) nbiterrors=nbiterrors+1 + enddo + + nplus=0 + nminus=0 + eyetop=1 + eyebot=-1 + do i=1,144 + if( msgbits(i) .eq. 1 ) then + if( softbits(i) .lt. eyetop ) eyetop=softbits(i) + else + if( softbits(i) .gt. eyebot ) eyebot=softbits(i) + endif + enddo + eyeopening=eyetop-eyebot + + is_training_frame = & + (snr.gt.5.0 .and.(nbiterrors.lt.7)) .and. & + (abs(t0-tlast) .gt. 0.072) .and. & + msg_has_dxcall + if( currently_training .and. is_training_frame ) then + twopi=8.0*atan(1.0) + nsym=144 + if( i4tone(41) .lt. 0 ) nsym=40 + dphi0=twopi*(freq-500)/12000.0 + dphi1=twopi*(freq+500)/12000.0 + phi=-twopi/8 + indx=0 + do i=1,nsym + if( i4tone(i) .eq. 0 ) then + dphi=dphi0 + else + dphi=dphi1 + endif + do j=1,6 + waveform(indx)=cos(phi); + indx=indx+1 + phi=mod(phi+dphi,twopi) + enddo + enddo +! convert the passband waveform to complex baseband + npts=864 + nfft=1024 + d=0 + d(1:864)=waveform(0:863) + call analytic(d,npts,nfft,canalytic,pcoeffs,.false.) ! don't equalize the model + call tweak1(canalytic,nfft,-freq,cmodel) + call four2a(cframe(1:864),864,1,-1,1) + call four2a(cmodel(1:864),864,1,-1,1) + +! Cross spectra from different messages can be averaged +! as long as all messages originate from dxcall. + cross=cmodel(1:864)*conjg(cframe)/1000.0 + cross=cshift(cross,864/2) + cross_avg=cross_avg+10**(snr/20.0)*cross + wt_avg=wt_avg+10**(snr/20.0) + navg=navg+1 + tlast=t0 + phase=atan2(imag(cross_avg),real(cross_avg)) + df=12000.0/864.0 + nm=145 + do i=1,145 + x(i)=(i-73)*df/1000.0 + enddo + y=phase((864/2-nm/2):(864/2+nm/2)) + sigmay=wt_avg/abs(cross_avg((864/2-nm/2):(864/2+nm/2))) + mode=1 + npts=145 + nterms=5 + call polyfit(x,y,sigmay,npts,nterms,mode,a,chisqr) + pp=a(1)+x*(a(2)+x*(a(3)+x*(a(4)+x*a(5)))) + rmsdiff=sum( (pp-phase((864/2-nm/2):(864/2+nm/2)))**2 )/145.0 +!write(*,*) 'training ',navg,sqrt(chisqr),rmsdiff + if( (sqrt(chisqr).lt.1.8) .and. (rmsdiff.lt.0.5) .and. (navg.ge.5) ) then + trained_dxcall=dxcall + call date_and_time(date,time,zone,values) + write(pcoeff_filename,'(i2.2,i2.2,i2.2,"_",i2.2,i2.2,i2.2)') & + values(1)-2000,values(2),values(3),values(5),values(6),values(7) + pcoeff_filename=trim(trained_dxcall)//"_"//trim(pcoeff_filename)//".pcoeff" + l1=index(datadir,char(0))-1 + datadir(l1+1:l1+1)="/" + pcoeff_filename=datadir(1:l1+1)//trim(pcoeff_filename) +!write(*,*) 'trained - writing coefficients to: ',pcoeff_filename + open(17,file=pcoeff_filename,status='new') + write(17,'(i4,2f10.2,3i5,5e25.16)') navg,sqrt(chisqr),rmsdiff,NFREQLOW,NFREQHIGH,nterms,a + do i=1, 145 + write(17,*) x(i),pp(i),y(i),sigmay(i) + enddo + do i=1,864 + write(17,*) i,real(cframe(i)),imag(cframe(i)),real(cross_avg(i)),imag(cross_avg(i)) + enddo + close(17) + training_dxcall(1:12)=' ' + currently_training=.false. + btrain=.false. + navg=0 + endif + endif + + return + end subroutine msk144signalquality diff --git a/lib/msk144sim.f90 b/lib/msk144sim.f90 new file mode 100644 index 00000000..28f17e61 --- /dev/null +++ b/lib/msk144sim.f90 @@ -0,0 +1,99 @@ +program msk144sim + + use wavhdr + parameter (NMAX=15*12000) + real pings(0:NMAX-1) + real waveform(0:NMAX-1) + character*6 mygrid + character arg*8,msg*22,msgsent*22,fname*40 + real wave(0:NMAX-1) !Simulated received waveform + real*8 twopi,freq,phi,dphi0,dphi1,dphi + type(hdr) h !Header for .wav file + integer*2 iwave(0:NMAX-1) + integer itone(144) !Message bits + logical*1 bcontest + data mygrid/"EN50wc"/ + + nargs=iargc() + if(nargs.ne.6) then + print*,'Usage: msk144sim message freq width nslow snr nfiles' + print*,'Example: msk144sim "K1ABC W9XYZ EN37" 1500 0.12 1 2 1' + print*,' msk144sim "K1ABC W9XYZ EN37" 1500 2.5 32 15 1' + go to 999 + endif + call getarg(1,msg) + call getarg(2,arg) + read(arg,*) freq + call getarg(3,arg) + read(arg,*) width + call getarg(4,arg) + read(arg,*) nslow + call getarg(5,arg) + read(arg,*) snrdb + call getarg(6,arg) + read(arg,*) nfiles + +!sig is the peak amplitude of the ping. + sig=sqrt(2.0)*10.0**(0.05*snrdb) + h=default_header(12000,NMAX) + i1=len(trim(msg))-5 + bcontest=.false. + if(msg(i1:i1+1).eq.'R ') bcontest=.true. + ichk=0 + call genmsk144(msg,mygrid,ichk,bcontest,msgsent,itone,itype) + twopi=8.d0*atan(1.d0) + + nsym=144 + nsps=6*nslow + if( itone(41) .lt. 0 ) nsym=40 + baud=2000.d0/nslow + dphi0=twopi*(freq-0.25d0*baud)/12000.d0 + dphi1=twopi*(freq+0.25d0*baud)/12000.d0 + phi=0.0 + k=0 + nreps=NMAX/(nsym*nsps) + print*,nsym,nslow,nsps,baud,freq + do jrep=1,nreps + do i=1,nsym + if( itone(i) .eq. 0 ) then + dphi=dphi0 + else + dphi=dphi1 + endif + do j=1,nsps + waveform(k)=cos(phi) + k=k+1 + phi=mod(phi+dphi,twopi) + enddo + enddo + enddo + + if(itype.lt.1 .or. itype.gt.7) then + print*,'Illegal message' + go to 999 + endif + + if(nslow.eq.1) call makepings(pings,NMAX,width,sig) + +! call sgran() + do ifile=1,nfiles !Loop over requested number of files + write(fname,1002) ifile !Output filename +1002 format('000000_',i6.6) + open(10,file=fname(1:13)//'.wav',access='stream',status='unknown') + + wave=0.0 + iwave=0 + fac=sqrt(6000.0/2500.0) + do i=0,NMAX-1 + xx=gran() + if(nslow.eq.1) wave(i)=pings(i)*waveform(i) + fac*xx + if(nslow.gt.1) wave(i)=sig*waveform(i) + fac*xx + iwave(i)=30.0*wave(i) + enddo + + write(10) h,iwave !Save the .wav file + close(10) + + enddo + +999 end program msk144sim diff --git a/lib/msk144spd.f90 b/lib/msk144spd.f90 new file mode 100644 index 00000000..dcba3599 --- /dev/null +++ b/lib/msk144spd.f90 @@ -0,0 +1,197 @@ +subroutine msk144spd(cbig,n,ntol,nsuccess,msgreceived,fc,fret,tret,navg,ct, & + softbits,recent_calls,nrecent) + +! MSK144 short-ping-decoder + + use timer_module, only: timer + + parameter (NSPM=864, MAXSTEPS=100, NFFT=NSPM, MAXCAND=5, NPATTERNS=6) + character*22 msgreceived + character*12 recent_calls(nrecent) + complex cbig(n) + complex cdat(3*NSPM) !Analytic signal + complex c(NSPM) + complex ct(NSPM) + complex ctmp(NFFT) + integer, dimension(1) :: iloc + integer indices(MAXSTEPS) + integer npkloc(10) + integer navpatterns(3,NPATTERNS) + integer navmask(3) + integer nstart(MAXCAND) + logical ismask(NFFT) + real detmet(-2:MAXSTEPS+3) + real detmet2(-2:MAXSTEPS+3) + real detfer(MAXSTEPS) + real rcw(12) + real ferrs(MAXCAND) + real snrs(MAXCAND) + real softbits(144) + real tonespec(NFFT) + real tpat(NPATTERNS) + real*8 dt, df, fs, pi, twopi + logical first + data first/.true./ + data navpatterns/ & + 0,1,0, & + 1,0,0, & + 0,0,1, & + 1,1,0, & + 0,1,1, & + 1,1,1/ + data tpat/1.5,0.5,2.5,1.0,2.0,1.5/ + + save df,first,fs,pi,twopi,dt,tframe,rcw + + if(first) then + nmatchedfilter=1 +! define half-sine pulse and raised-cosine edge window + pi=4d0*datan(1d0) + twopi=8d0*datan(1d0) + fs=12000.0 + dt=1.0/fs + df=fs/NFFT + tframe=NSPM/fs + + do i=1,12 + angle=(i-1)*pi/12.0 + rcw(i)=(1-cos(angle))/2 + enddo + + first=.false. + endif + + ! fill the detmet, detferr arrays + nstep=(n-NSPM)/216 ! 72ms/4=18ms steps + detmet=0 + detmet2=0 + detfer=-999.99 + nfhi=2*(fc+500) + nflo=2*(fc-500) + ihlo=nint((nfhi-2*ntol)/df) + 1 + ihhi=nint((nfhi+2*ntol)/df) + 1 + illo=nint((nflo-2*ntol)/df) + 1 + ilhi=nint((nflo+2*ntol)/df) + 1 + i2000=nint(nflo/df) + 1 + i4000=nint(nfhi/df) + 1 + do istp=1,nstep + ns=1+216*(istp-1) + ne=ns+NSPM-1 + if( ne .gt. n ) exit + ctmp=cmplx(0.0,0.0) + ctmp(1:NSPM)=cbig(ns:ne) + +! Coarse carrier frequency sync - seek tones at 2000 Hz and 4000 Hz in +! squared signal spectrum. + + ctmp=ctmp**2 + ctmp(1:12)=ctmp(1:12)*rcw + ctmp(NSPM-11:NSPM)=ctmp(NSPM-11:NSPM)*rcw(12:1:-1) + call four2a(ctmp,NFFT,1,-1,1) + tonespec=abs(ctmp)**2 + + ismask=.false. + ismask(ihlo:ihhi)=.true. ! high tone search window + iloc=maxloc(tonespec,ismask) + ihpk=iloc(1) + deltah=-real( (ctmp(ihpk-1)-ctmp(ihpk+1)) / (2*ctmp(ihpk)-ctmp(ihpk-1)-ctmp(ihpk+1)) ) + ah=tonespec(ihpk) + ahavp=(sum(tonespec,ismask)-ah)/count(ismask) + trath=ah/(ahavp+0.01) + ismask=.false. + ismask(illo:ilhi)=.true. ! window for low tone + iloc=maxloc(tonespec,ismask) + ilpk=iloc(1) + deltal=-real( (ctmp(ilpk-1)-ctmp(ilpk+1)) / (2*ctmp(ilpk)-ctmp(ilpk-1)-ctmp(ilpk+1)) ) + al=tonespec(ilpk) + alavp=(sum(tonespec,ismask)-al)/count(ismask) + tratl=al/(alavp+0.01) + fdiff=(ihpk+deltah-ilpk-deltal)*df + ferrh=(ihpk+deltah-i4000)*df/2.0 + ferrl=(ilpk+deltal-i2000)*df/2.0 + if( ah .ge. al ) then + ferr=ferrh + else + ferr=ferrl + endif + detmet(istp)=max(ah,al) + detmet2(istp)=max(trath,tratl) + detfer(istp)=ferr + enddo ! end of detection-metric and frequency error estimation loop + + call indexx(detmet(1:nstep),nstep,indices) !find median of detection metric vector + xmed=detmet(indices(nstep/4)) + detmet=detmet/xmed ! noise floor of detection metric is 1.0 + ndet=0 + + do ip=1,MAXCAND ! Find candidates + iloc=maxloc(detmet(1:nstep)) + il=iloc(1) + if( (detmet(il) .lt. 3.0) ) exit + if( abs(detfer(il)) .le. ntol ) then + ndet=ndet+1 + nstart(ndet)=1+(il-1)*216+1 + ferrs(ndet)=detfer(il) + snrs(ndet)=12.0*log10(detmet(il))/2-9.0 + endif + detmet(il)=0.0 + enddo + + if( ndet .lt. 3 ) then + do ip=1,MAXCAND-ndet ! Find candidates + iloc=maxloc(detmet2(1:nstep)) + il=iloc(1) + if( (detmet2(il) .lt. 12.0) ) exit + if( abs(detfer(il)) .le. ntol ) then + ndet=ndet+1 + nstart(ndet)=1+(il-1)*216+1 + ferrs(ndet)=detfer(il) + snrs(ndet)=12.0*log10(detmet2(il))/2-9.0 + endif + detmet2(il)=0.0 + enddo + endif + + nsuccess=0 + msgreceived=' ' + npeaks=2 + ntol0=8 + deltaf=2.0 + do icand=1,ndet ! Try to sync/demod/decode each candidate. + ib=max(1,nstart(icand)-NSPM) + ie=ib-1+3*NSPM + if( ie .gt. n ) then + ie=n + ib=ie-3*NSPM+1 + endif + cdat=cbig(ib:ie) + fo=fc+ferrs(icand) + do iav=1,NPATTERNS + navmask=navpatterns(1:3,iav) + call msk144sync(cdat,3,ntol0,deltaf,navmask,npeaks,fo,fest,npkloc, & + nsyncsuccess,xmax,c) + + if( nsyncsuccess .eq. 0 ) cycle + + do ipk=1,npeaks + do is=1,3 + ic0=npkloc(ipk) + if( is.eq.2) ic0=max(1,ic0-1) + if( is.eq.3) ic0=min(NSPM,ic0+1) + ct=cshift(c,ic0-1) + call msk144decodeframe(ct,softbits,msgreceived,ndecodesuccess, & + recent_calls,nrecent) + if( ndecodesuccess .gt. 0 ) then + tret=(nstart(icand)+NSPM/2)/fs + fret=fest + navg=sum(navmask) + nsuccess=1 + return + endif + enddo + enddo + enddo + enddo ! candidate loop + + return +end subroutine msk144spd diff --git a/lib/msk144sync.f90 b/lib/msk144sync.f90 new file mode 100644 index 00000000..dfae9a21 --- /dev/null +++ b/lib/msk144sync.f90 @@ -0,0 +1,101 @@ +subroutine msk144sync(cdat,nframes,ntol,delf,navmask,npeaks,fc,fest, & + npklocs,nsuccess,xmax,c) + +!$ use omp_lib + + parameter (NSPM=864) + complex cdat(NSPM*nframes) + complex cdat2(NSPM*nframes,8) + complex c(NSPM) !Coherently averaged complex data + complex cs(NSPM,8) + complex cb(42) !Complex waveform for sync word + + integer s8(8) + integer iloc(1) + integer npklocs(npeaks) + integer navmask(nframes) ! defines which frames to average + + real cbi(42),cbq(42) + real pkamps(npeaks) + real xcc(0:NSPM-1) + real xccs(0:NSPM-1,8) + real xm(8) + real bf(8) + real pp(12) !Half-sine pulse shape + logical first + data first/.true./ + data s8/0,1,1,1,0,0,1,0/ + save first,cb,fs,pi,twopi,dt,s8,pp + + if(first) then + pi=4.0*atan(1.0) + twopi=8.0*atan(1.0) + fs=12000.0 + dt=1.0/fs + + do i=1,12 !Define half-sine pulse + angle=(i-1)*pi/12.0 + pp(i)=sin(angle) + enddo + +! Define the sync word waveforms + s8=2*s8-1 + cbq(1:6)=pp(7:12)*s8(1) + cbq(7:18)=pp*s8(3) + cbq(19:30)=pp*s8(5) + cbq(31:42)=pp*s8(7) + cbi(1:12)=pp*s8(2) + cbi(13:24)=pp*s8(4) + cbi(25:36)=pp*s8(6) + cbi(37:42)=pp(1:6)*s8(8) + cb=cmplx(cbi,cbq) + + first=.false. + endif + + nfreqs=2*nint(ntol/delf) + 1 + xm=0.0 + bf=0.0 + nthreads=1 +!$ nthreads=min(8,int(OMP_GET_MAX_THREADS(),4)) + nstep=nfreqs/nthreads + +!$OMP PARALLEL NUM_THREADS(nthreads) PRIVATE(id,if1,if2) + id=1 +!$ id=OMP_GET_THREAD_NUM() + 1 !Thread id = 1,2,... + if1=-nint(ntol/delf) + (id-1)*nstep + if2=if1+nstep-1 + if(id.eq.nthreads) if2=nint(ntol/delf) + call msk144_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & + cdat2(1,id),xm(id),bf(id),cs(1,id),xccs(1,id)) +!$OMP END PARALLEL + + xmax=xm(1) + fest=fc+bf(1) + c=cs(1:NSPM,1) + xcc=xccs(0:NSPM-1,1) + if(nthreads.gt.1) then + do i=2,nthreads + if(xm(i).gt.xmax) then + xmax=xm(i) + fest=fc+bf(i) + c=cs(1:NSPM,i) + xcc=xccs(0:NSPM-1,i) + endif + enddo + endif + +! Find npeaks largest peaks + do ipk=1,npeaks + iloc=maxloc(xcc) + ic2=iloc(1) + npklocs(ipk)=ic2 + pkamps(ipk)=xcc(ic2-1) + xcc(max(0,ic2-7):min(NSPM-1,ic2+7))=0.0 + enddo + + nsuccess=0 + if(xmax.ge.1.3) nsuccess=1 + + return +end subroutine msk144sync diff --git a/lib/msk40_freq_search.f90 b/lib/msk40_freq_search.f90 new file mode 100644 index 00000000..97f74f5e --- /dev/null +++ b/lib/msk40_freq_search.f90 @@ -0,0 +1,53 @@ +subroutine msk40_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & + cdat2,xmax,bestf,cs,xccs) + + parameter (NSPM=240,NZ=7*NSPM) + complex cdat(NZ) + complex cdat2(NZ) + complex c(NSPM) !Coherently averaged complex data + complex ct2(2*NSPM) + complex cs(NSPM) + complex cb(42) !Complex waveform for sync word + complex cc(0:NSPM-1) + real xcc(0:NSPM-1) + real xccs(0:NSPM-1) + integer navmask(nframes) !Tells which frames to average + + navg=sum(navmask) + n=nframes*NSPM +! fac=1.0/(48.0*sqrt(float(navg))) + fac=1.0/(24.0*sqrt(float(navg))) + + do ifr=if1,if2 !Find freq that maximizes sync + ferr=ifr*delf + call tweak1(cdat,n,-(fc+ferr),cdat2) + c=0 + do i=1,nframes + ib=(i-1)*NSPM+1 + ie=ib+NSPM-1 + if( navmask(i) .eq. 1 ) c=c+cdat2(ib:ie) + enddo + + cc=0 + ct2(1:NSPM)=c + ct2(NSPM+1:2*NSPM)=c + + do ish=0,NSPM-1 + cc(ish)=dot_product(ct2(1+ish:42+ish),cb(1:42)) + enddo + + xcc=abs(cc) + xb=maxval(xcc)*fac + if(xb.gt.xmax) then + xmax=xb + bestf=ferr + cs=c + xccs=xcc + endif + enddo + +! write(71,3001) fc,delf,if1,if2,nframes,bestf,xmax +!3001 format(2f8.3,3i5,2f8.3) + + return +end subroutine msk40_freq_search diff --git a/lib/msk40decodeframe.f90 b/lib/msk40decodeframe.f90 new file mode 100644 index 00000000..ae75ddf9 --- /dev/null +++ b/lib/msk40decodeframe.f90 @@ -0,0 +1,169 @@ +subroutine msk40decodeframe(c,mycall,hiscall,xsnr,bswl,nhasharray, & + recent_calls,nrecent,msgreceived,nsuccess) +! use timer_module, only: timer + + parameter (NSPM=240) + character*4 rpt(0:15) + character*6 mycall,hiscall,mycall0,hiscall0 + character*22 hashmsg,msgreceived + character*12 recent_calls(nrecent) + complex cb(42) + complex cfac,cca + complex c(NSPM) + integer*1 cw(32) + integer*1 decoded(16) + integer s8r(8),hardbits(40) + integer nhasharray(nrecent,nrecent) + real*8 dt, fs, pi, twopi + real cbi(42),cbq(42) + real pp(12) + real softbits(40) + real llr(32) + logical first + logical*1 bswl + data first/.true./ + data s8r/1,0,1,1,0,0,0,1/ + data mycall0/'dummy'/,hiscall0/'dummy'/ + data rpt/"-03 ","+00 ","+03 ","+06 ","+10 ","+13 ","+16 ", & + "R-03","R+00","R+03","R+06","R+10","R+13","R+16", & + "RRR ","73 "/ + save first,cb,fs,pi,twopi,dt,s8r,pp,rpt,mycall0,hiscall0,ihash + + if(first) then +! define half-sine pulse and raised-cosine edge window + pi=4d0*datan(1d0) + twopi=8d0*datan(1d0) + fs=12000.0 + dt=1.0/fs + + do i=1,12 + angle=(i-1)*pi/12.0 + pp(i)=sin(angle) + enddo + +! define the sync word waveforms + s8r=2*s8r-1 + cbq(1:6)=pp(7:12)*s8r(1) + cbq(7:18)=pp*s8r(3) + cbq(19:30)=pp*s8r(5) + cbq(31:42)=pp*s8r(7) + cbi(1:12)=pp*s8r(2) + cbi(13:24)=pp*s8r(4) + cbi(25:36)=pp*s8r(6) + cbi(37:42)=pp(1:6)*s8r(8) + cb=cmplx(cbi,cbq) + first=.false. + endif + + if(mycall.ne.mycall0 .or. hiscall.ne.hiscall0) then + hashmsg=trim(mycall)//' '//trim(hiscall) + if( hashmsg .ne. ' ' .and. hiscall .ne. '' ) then ! protect against blank mycall/hiscall + call fmtmsg(hashmsg,iz) + call hash(hashmsg,22,ihash) + ihash=iand(ihash,4095) + else + ihash=9999 ! so that it can never match a received hash + endif + mycall0=mycall + hiscall0=hiscall + endif + + nsuccess=0 + msgreceived=' ' + +! Estimate carrier phase. + cca=sum(c(1:1+41)*conjg(cb)) + phase0=atan2(imag(cca),real(cca)) + +! Remove phase error - want constellation rotated so that sample points lie on I/Q axes + cfac=cmplx(cos(phase0),sin(phase0)) + c=c*conjg(cfac) + +! Matched filter. + softbits(1)=sum(imag(c(1:6))*pp(7:12))+sum(imag(c(NSPM-5:NSPM))*pp(1:6)) + softbits(2)=sum(real(c(1:12))*pp) + do i=2,20 + softbits(2*i-1)=sum(imag(c(1+(i-1)*12-6:1+(i-1)*12+5))*pp) + softbits(2*i)=sum(real(c(7+(i-1)*12-6:7+(i-1)*12+5))*pp) + enddo + +! Sync word hard error weight is used to reject frames that +! are unlikely to decode. + hardbits=0 + do i=1,40 + if( softbits(i) .ge. 0.0 ) then + hardbits(i)=1 + endif + enddo + nbadsync1=(8-sum( (2*hardbits(1:8)-1)*s8r ) )/2 + nbadsync=nbadsync1 + if( nbadsync .gt. 3 ) then + return + endif + +! Normalize the softsymbols before submitting to decoder. + sav=sum(softbits)/40 + s2av=sum(softbits*softbits)/40 + ssig=sqrt(s2av-sav*sav) + softbits=softbits/ssig + + sigma=0.75 +! if(xsnr.lt.0.0) sigma=0.75-0.0875*xsnr + if(xsnr.lt.0.0) sigma=0.75-0.11*xsnr + llr(1:32)=softbits(9:40) + llr=2.0*llr/(sigma*sigma) + + max_iterations=5 + call bpdecode40(llr,max_iterations,decoded,niterations) + + if( niterations .ge. 0.0 ) then + call encode_msk40(decoded,cw) + nhammd=0 + cord=0.0 + do i=1,32 + if( cw(i) .ne. hardbits(i+8) ) then + nhammd=nhammd+1 + cord=cord+abs(softbits(i+8)) + endif + enddo + + imsg=0 + do i=1,16 + imsg=ishft(imsg,1)+iand(1,decoded(17-i)) + enddo + nrxrpt=iand(imsg,15) + nrxhash=(imsg-nrxrpt)/16 + + if(nhammd.le.4 .and. cord .lt. 0.65 .and. & + nrxhash.eq.ihash .and. nrxrpt.ge.7) then +!write(*,*) 'decodeframe 1',nbadsync,nhammd,cord,nrxhash,nrxrpt,ihash,xsnr,sigma + nsuccess=1 + write(msgreceived,'(a1,a,1x,a,a1,1x,a4)') "<",trim(mycall), & + trim(hiscall),">",rpt(nrxrpt) + return + elseif(bswl .and. nhammd.le.4 .and. cord.lt.0.65 .and. nrxrpt.ge.7 ) then + do i=1,nrecent + do j=i+1,nrecent + if( nrxhash .eq. nhasharray(i,j) ) then + nsuccess=2 + write(msgreceived,'(a1,a,1x,a,a1,1x,a4)') "<",trim(recent_calls(i)), & + trim(recent_calls(j)),">",rpt(nrxrpt) +!write(*,*) 'decodeframe 2',nbadsync,nhammd,cord,nrxhash,nrxrpt,ihash,xsnr,sigma + elseif( nrxhash .eq. nhasharray(j,i) ) then + nsuccess=2 + write(msgreceived,'(a1,a,1x,a,a1,1x,a4)') "<",trim(recent_calls(j)), & + trim(recent_calls(i)),">",rpt(nrxrpt) +!write(*,*) 'decodeframe 3',nbadsync,nhammd,cord,nrxhash,nrxrpt,ihash,xsnr,sigma + endif + enddo + enddo + if(nsuccess.eq.0) then + nsuccess=3 +!write(*,*) 'decodeframe 4',bswl,nbadsync,nhammd,cord,nrxhash,nrxrpt,ihash,xsnr,sigma,nsuccess + write(msgreceived,'(a1,i4.4,a1,1x,a4)') "<",nrxhash,">",rpt(nrxrpt) + endif + endif + endif + + return +end subroutine msk40decodeframe diff --git a/lib/msk40spd.f90 b/lib/msk40spd.f90 new file mode 100644 index 00000000..c8af1a49 --- /dev/null +++ b/lib/msk40spd.f90 @@ -0,0 +1,199 @@ +subroutine msk40spd(cbig,n,ntol,mycall,hiscall,bswl,nhasharray,recent_calls, & + nrecent,nsuccess,msgreceived,fc,fret,tret,navg) +! msk40 short-ping-decoder + + use timer_module, only: timer + + parameter (NSPM=240, MAXSTEPS=150, NFFT=NSPM, MAXCAND=5, NPATTERNS=6) + character*6 mycall,hiscall + character*22 msgreceived + character*12 recent_calls(nrecent) + complex cbig(n) + complex cdat(3*NSPM) !Analytic signal + complex c(NSPM) + complex ct(NSPM) + complex ctmp(NFFT) + integer, dimension(1) :: iloc + integer indices(MAXSTEPS) + integer npkloc(10) + integer navpatterns(3,NPATTERNS) + integer navmask(3) + integer nstart(MAXCAND) + integer nhasharray(nrecent,nrecent) + logical ismask(NFFT) + logical*1 bswl + real detmet(-2:MAXSTEPS+3) + real detmet2(-2:MAXSTEPS+3) + real detfer(MAXSTEPS) + real rcw(12) + real ferrs(MAXCAND) + real snrs(MAXCAND) + real tonespec(NFFT) + real tpat(NPATTERNS) + real*8 dt, df, fs, pi, twopi + logical first + data first/.true./ + data navpatterns/ & + 0,1,0, & + 1,0,0, & + 0,0,1, & + 1,1,0, & + 0,1,1, & + 1,1,1/ + data tpat/1.5,0.5,2.5,1.0,2.0,1.5/ + save df,first,fs,pi,twopi,dt,tframe,rcw + + if(first) then + nmatchedfilter=1 +! define half-sine pulse and raised-cosine edge window + pi=4d0*datan(1d0) + twopi=8d0*datan(1d0) + fs=12000.0 + dt=1.0/fs + df=fs/NFFT + tframe=NSPM/fs + + do i=1,12 + angle=(i-1)*pi/12.0 + rcw(i)=(1-cos(angle))/2 + enddo + + first=.false. + endif + + + ! fill the detmet, detferr arrays + nstep=(n-NSPM)/60 ! 20ms/4=5ms steps + detmet=0 + detmet2=0 + detfer=-999.99 + nfhi=2*(fc+500) + nflo=2*(fc-500) + ihlo=nint((nfhi-2*ntol)/df)+1 + ihhi=nint((nfhi+2*ntol)/df)+1 + illo=nint((nflo-2*ntol)/df)+1 + ilhi=nint((nflo+2*ntol)/df)+1 + i2000=nint(nflo/df)+1 + i4000=nint(nfhi/df)+1 + do istp=1,nstep + ns=1+60*(istp-1) + ne=ns+NSPM-1 + if( ne .gt. n ) exit + ctmp=cmplx(0.0,0.0) + ctmp(1:NSPM)=cbig(ns:ne) + +! Coarse carrier frequency sync - seek tones at 2000 Hz and 4000 Hz in +! squared signal spectrum. + + ctmp=ctmp**2 + ctmp(1:12)=ctmp(1:12)*rcw + ctmp(NSPM-11:NSPM)=ctmp(NSPM-11:NSPM)*rcw(12:1:-1) + call four2a(ctmp,NFFT,1,-1,1) + tonespec=abs(ctmp)**2 + + ismask=.false. + ismask(ihlo:ihhi)=.true. ! high tone search window + iloc=maxloc(tonespec,ismask) + ihpk=iloc(1) + deltah=-real( (ctmp(ihpk-1)-ctmp(ihpk+1)) / (2*ctmp(ihpk)-ctmp(ihpk-1)-ctmp(ihpk+1)) ) + ah=tonespec(ihpk) + ahavp=(sum(tonespec,ismask)-ah)/count(ismask) + trath=ah/(ahavp+0.01) + ismask=.false. + ismask(illo:ilhi)=.true. ! window for low tone + iloc=maxloc(tonespec,ismask) + ilpk=iloc(1) + deltal=-real( (ctmp(ilpk-1)-ctmp(ilpk+1)) / (2*ctmp(ilpk)-ctmp(ilpk-1)-ctmp(ilpk+1)) ) + al=tonespec(ilpk) + alavp=(sum(tonespec,ismask)-al)/count(ismask) + tratl=al/(alavp+0.01) + fdiff=(ihpk+deltah-ilpk-deltal)*df + ferrh=(ihpk+deltah-i4000)*df/2.0 + ferrl=(ilpk+deltal-i2000)*df/2.0 + if( ah .ge. al ) then + ferr=ferrh + else + ferr=ferrl + endif + detmet(istp)=max(ah,al) + detmet2(istp)=max(trath,tratl) + detfer(istp)=ferr + enddo ! end of detection-metric and frequency error estimation loop + + call indexx(detmet(1:nstep),nstep,indices) !find median of detection metric vector + xmed=detmet(indices(nstep/4)) + detmet=detmet/xmed ! noise floor of detection metric is 1.0 + ndet=0 + + do ip=1,MAXCAND ! Find candidates + iloc=maxloc(detmet(1:nstep)) + il=iloc(1) + if( (detmet(il) .lt. 3.5) ) exit + if( abs(detfer(il)) .le. ntol ) then + ndet=ndet+1 + nstart(ndet)=1+(il-1)*60+1 + ferrs(ndet)=detfer(il) + snrs(ndet)=12.0*log10(detmet(il))/2-9.0 + endif + detmet(il)=0.0 + enddo + + if( ndet .lt. 3 ) then + do ip=1,MAXCAND-ndet ! Find candidates + iloc=maxloc(detmet2(1:nstep)) + il=iloc(1) + if( (detmet2(il) .lt. 12.0) ) exit + if( abs(detfer(il)) .le. ntol ) then + ndet=ndet+1 + nstart(ndet)=1+(il-1)*60+1 + ferrs(ndet)=detfer(il) + snrs(ndet)=12.0*log10(detmet2(il))/2-9.0 + endif + detmet2(il)=0.0 + enddo + endif + + nsuccess=0 + msgreceived=' ' + npeaks=2 + ntol0=29 + deltaf=7.2 + do icand=1,ndet ! Try to sync/demod/decode each candidate. + ib=max(1,nstart(icand)-NSPM) + ie=ib-1+3*NSPM + if( ie .gt. n ) then + ie=n + ib=ie-3*NSPM+1 + endif + cdat=cbig(ib:ie) + fo=fc+ferrs(icand) + xsnr=snrs(icand) + do iav=1,NPATTERNS + navmask=navpatterns(1:3,iav) + call msk40sync(cdat,3,ntol0,deltaf,navmask,npeaks,fo,fest,npkloc, & + nsyncsuccess,c) + if( nsyncsuccess .eq. 0 ) cycle + + do ipk=1,npeaks + do is=1,3 + ic0=npkloc(ipk) + if( is.eq.2) ic0=max(1,ic0-1) + if( is.eq.3) ic0=min(NSPM,ic0+1) + ct=cshift(c,ic0-1) + call msk40decodeframe(ct,mycall,hiscall,xsnr,bswl,nhasharray, & + recent_calls,nrecent,msgreceived,ndecodesuccess) + if( ndecodesuccess .gt. 0 ) then +!write(*,*) icand, iav, ipk, is, tret, fret, msgreceived + tret=(nstart(icand)+NSPM/2)/fs + fret=fest + navg=sum(navmask) + nsuccess=ndecodesuccess + return + endif + enddo + enddo + enddo + enddo ! candidate loop + + return +end subroutine msk40spd diff --git a/lib/msk40sync.f90 b/lib/msk40sync.f90 new file mode 100644 index 00000000..5a2ca1e7 --- /dev/null +++ b/lib/msk40sync.f90 @@ -0,0 +1,103 @@ +subroutine msk40sync(cdat,nframes,ntol,delf,navmask,npeaks,fc,fest, & + npklocs,nsuccess,c) + + !$ use omp_lib + + parameter (NSPM=240) + complex cdat(NSPM*nframes) + complex cdat2(NSPM*nframes,8) + complex c(NSPM) !Coherently averaged complex data + complex cs(NSPM,8) + complex cb(42) !Complex waveform for sync word + + integer s8r(8) + integer iloc(1) + integer npklocs(npeaks) + integer navmask(nframes) ! defines which frames to average + + real cbi(42),cbq(42) + real pkamps(npeaks) + real xcc(0:NSPM-1) + real xccs(0:NSPM-1,8) + real xm(8) + real bf(8) + real pp(12) !Half-sine pulse shape + logical first + data first/.true./ + data s8r/1,0,1,1,0,0,0,1/ + save first,cb,fs,pi,twopi,dt,s8r,pp + + if(first) then + pi=4.0*atan(1.0) + twopi=8.0*atan(1.0) + fs=12000.0 + dt=1.0/fs + + do i=1,12 !Define half-sine pulse + angle=(i-1)*pi/12.0 + pp(i)=sin(angle) + enddo + +! Define the sync word waveforms + s8r=2*s8r-1 + cbq(1:6)=pp(7:12)*s8r(1) + cbq(7:18)=pp*s8r(3) + cbq(19:30)=pp*s8r(5) + cbq(31:42)=pp*s8r(7) + cbi(1:12)=pp*s8r(2) + cbi(13:24)=pp*s8r(4) + cbi(25:36)=pp*s8r(6) + cbi(37:42)=pp(1:6)*s8r(8) + cb=cmplx(cbi,cbq) + + first=.false. + endif + + nfreqs=2*nint(ntol/delf) + 1 + xm=0.0 + bf=0.0 + nthreads=1 + !$ nthreads=min(8,int(OMP_GET_MAX_THREADS(),4)) + nstep=nfreqs/nthreads + + !$OMP PARALLEL NUM_THREADS(nthreads) PRIVATE(id,if1,if2) + id=1 + !$ id=OMP_GET_THREAD_NUM() + 1 !Thread id = 1,2,... + if1=-nint(ntol/delf) + (id-1)*nstep + if2=if1+nstep-1 + if(id.eq.nthreads) if2=nint(ntol/delf) + call msk40_freq_search(cdat,fc,if1,if2,delf,nframes,navmask,cb, & + cdat2(1,id),xm(id),bf(id),cs(1,id),xccs(1,id)) +! write(73,3002) id,if1,if2,nfreqs,nthreads,bf(id),xm(id) +!3002 format(5i5,2f10.3) + !$OMP END PARALLEL + + xmax=xm(1) + fest=fc+bf(1) + c=cs(1:NSPM,1) + xcc=xccs(0:NSPM-1,1) + if(nthreads.gt.1) then + do i=2,nthreads + if(xm(i).gt.xmax) then + xmax=xm(i) + fest=fc+bf(i) + c=cs(1:NSPM,i) + xcc=xccs(0:NSPM-1,i) + endif + enddo + endif + +! Find npeaks largest peaks + do ipk=1,npeaks + iloc=maxloc(xcc) + ic2=iloc(1) + npklocs(ipk)=ic2 + pkamps(ipk)=xcc(ic2-1) + xcc(max(0,ic2-7):min(NSPM-1,ic2+7))=0.0 + enddo + + nsuccess=0 + if( xmax .ge. 1.3 ) nsuccess=1 + + return +end subroutine msk40sync diff --git a/lib/mskber.f90 b/lib/mskber.f90 new file mode 100644 index 00000000..4b31127c --- /dev/null +++ b/lib/mskber.f90 @@ -0,0 +1,146 @@ +program mskber + +! Generate an MSK waveform, pass it through an AWGN channel, apply coherent +! MSK receiver, and count number of errors at each Eb/No. + + parameter (MAXSYM=1000*1000) + parameter (NSPS=5) !Samples per symbol + real ct(-NSPS:NSPS*MAXSYM-1) !cos(pi*t/2T) + real st(-NSPS:NSPS*MAXSYM-1) !sin(pi*t/2T) + real r(0:MAXSYM-1) !Random numbers to set test bits + real xsym(0:MAXSYM-1) !Soft Rx symbols + + complex xt(-NSPS:NSPS*MAXSYM-1) !Complex baseband Tx waveform + complex nt(-NSPS:NSPS*MAXSYM-1) !Generated AWGN channel noise + complex yt(-NSPS:NSPS*MAXSYM-1) !Received signal, yt = xt + fac*nt + complex cwave(-NSPS:NSPS*MAXSYM-1) !Audio waveform, Tx real part + complex z + + integer sym0(0:MAXSYM-1) !Generated test bits + integer sym(0:MAXSYM-1) !Hard-copy received bits + integer sym1(0:7) + + character*12 arg + data sym1/1,1,0,0,0,1,1,1/ + + nargs=iargc() + if(nargs.ne.2) then + print*,'Usage: mskber nsym EbNo' + go to 999 + endif + call getarg(1,arg) + read(arg,*) nsym + call getarg(2,arg) + read(arg,*) EbNo + + pi=4.0*atan(1.0) + + do i=-NSPS,NSPS*nsym-1 !Define ct, st arrays + t=i*pi/(2.0*NSPS) + ct(i)=cos(t) + st(i)=sin(t) + enddo + fac=1.0/sqrt(float(NSPS)) + + do iEbNo=0,10 !Loop over a range of Eb/No + sym0=0 + call random_number(r) + where(r(0:nsym-1).gt.0.5) sym0(0:nsym-1)=1 !Generate random data bits + if(nsym.eq.8) sym0(0:nsym-1)=sym1 + call mskmod(sym0,nsym,NSPS,ct,st,xt,cwave) !Generate Tx waveform + + do i=-NSPS,NSPS*nsym-1 !Generate Gaussian noise + xx=0.707*gran() + yy=0.707*gran() + nt(i)=cmplx(xx,yy) + enddo + fac_noise=10.0**(-iEbNo/20.0) + if(EbNo.ne.0.0) fac_noise=10.0**(-EbNo/20.0) + yt=xt + fac_noise*nt !Rx signal, with noise + + call mskdemod(yt,nsym,NSPS,ct,st,xsym) !MSK demodulator + + sym=0 + where(xsym.gt.0.0) sym=1 + + if(nsym.le.160 .and. EbNo.ne.0.0) then + write(*,1012) sym0(0:nsym-1) + if(nsym.gt.50) write(*,1012) + write(*,1012) sym(0:nsym-1) +1012 format(50i1) + do i=-nsps,nsps*nsym-1 + phi=i*2.0*pi*1500/12000.0 + z=cwave(i)*cmplx(cos(phi),sin(phi)) !Mix back to baseband + write(51,1014) float(i)/nsps,xt(i),abs(xt(i)),cwave(i),z +1014 format(8f8.4) + enddo + endif + +! Count the hard errors + nerr=count(sym(0:nsym-1).ne.sym0(0:nsym-1)) + thber=0.5*erfc(10.0**(iEbNo/20.0)) + xEbNo=iEbNo + if(EbNo.ne.0.0) xEbNo=EbNo + write(*,1000) xEbNo,thber,float(nerr)/nsym +1000 format(f6.1,2f10.6) + if(EbNo.ne.0.0) exit + enddo + +999 end program mskber + +subroutine mskmod(sym,nsym,nsps,ct,st,xt,cwave) + +! Generate MSK Tx waveform at baseband. + + integer sym(0:nsym-1) !Hard-copy received bits + complex xt(-nsps:nsps*nsym-1) !Complex baseband Tx waveform + complex cwave(-nsps:nsps*nsym-1) !Audio waveform, fc=1500 Hz. + real ct(-nsps:nsps*nsym-1) !cos(pi*t/2T) + real st(-nsps:nsps*nsym-1) !sin(pi*t/2T) + real ai(-nsps:nsps*nsym-1) !Rectangular pulses for even symbols + real aq(-nsps:nsps*nsym-1) !Rectangular pulses for odd symbols + + ai=0. + aq=0. + fac=1.0/sqrt(float(nsps)) + do j=0,nsym-1,2 + ia=(j-1)*nsps + ib=ia+2*nsps-1 + ai(ia:ib)=2*sym(j)-1 !Even bits as rectangular pulses + aq(ia+nsps:ib+nsps)=2*sym(j+1)-1 !Odd bits as rectangular pulses + enddo + xt=fac*cmplx(ai*ct,aq*st) !Baseband Tx waveform + + twopi=8.0*atan(1.0) + do i=-nsps,nsps*nsym-1 + phi=i*twopi*1500/12000.0 + cwave(i)=xt(i)*cmplx(cos(phi),-sin(phi)) + enddo + + return +end subroutine mskmod + +subroutine mskdemod(yt,nsym,nsps,ct,st,xsym) + +! MSK demodulator +! Rx phase must be known and stable; symbol sync must be established. + + complex yt(-nsps:nsps*nsym-1) !Received signal + real ct(-nsps:nsps*nsym-1) !cos(pi*t/2T) + real st(-nsps:nsps*nsym-1) !sin(pi*t/2T) + real xe(-nsps:nsps*nsym-1) !Temp array for received even symbols + real xo(-nsps:nsps*nsym-1) !Temp array for received odd symbols + real xsym(0:nsym-1) !Soft Rx symbols + + iz=nsps*(nsym+1) + xe(-nsps:nsps*nsym-1)=real(yt)*ct !Apply matched filters + xo(-nsps:nsps*nsym-1)=aimag(yt)*st + do j=0,nsym-1,2 + ia=(j-1)*nsps + ib=ia+2*nsps-1 + xsym(j)=sum(xe(ia:ib)) !Integrate over 2 symbol lengths + xsym(j+1)=sum(xo(ia+nsps:ib+nsps)) + enddo + + return +end subroutine mskdemod diff --git a/lib/mskdt.f90 b/lib/mskdt.f90 new file mode 100644 index 00000000..bca83599 --- /dev/null +++ b/lib/mskdt.f90 @@ -0,0 +1,78 @@ +subroutine mskdt(d,npts,ty,yellow,nyel) + + parameter (NFFT=1024,NH=NFFT/2) + real d(npts) + real x(0:NFFT-1) + real green(703) + real yellow(703) !703 = 30*12000/512 + real ty(703) + real y2(175) + real ty2(175) + integer indx(703) + logical ok + complex c(0:NH) + equivalence (x,c) + + df=12000.0/NFFT + i1=nint(300.0/df) + i2=nint(800.0/df) + i3=nint(2200.0/df) + i4=nint(2700.0/df) + nblks=npts/NH - 1 + + do j=1,nblks + ib=(j+1)*NH + ia=ib-NFFT+1 + x=d(ia:ib) + call four2a(x,NFFT,1,-1,0) !r2c FFT + sqlow=0. + do i=i1,i2 + sqlow=sqlow + real(c(i))**2 + aimag(c(i))**2 + enddo + sqmid=0. + do i=i2,i3 + sqmid=sqmid + real(c(i))**2 + aimag(c(i))**2 + enddo + sqhigh=0. + do i=i3,i4 + sqhigh=sqhigh + real(c(i))**2 + aimag(c(i))**2 + enddo + green(j)=db(sqlow+sqmid+sqhigh) + yellow(j)=db(sqmid/(sqlow+sqhigh)) + ty(j)=j*512.0/12000.0 + enddo + + npct=20 + call pctile(green,nblks,npct,base) + green(1:nblks)=green(1:nblks) - base - 0.3 + call pctile(yellow,nblks,npct,base) + yellow(1:nblks)=yellow(1:nblks) - base - 0.6 + call indexx(yellow,nblks,indx) + + do j=1,nblks/4 + k=indx(nblks+1-j) + ty(j)=ty(k) + yellow(j)=yellow(k) + if(yellow(j).lt.1.5) exit + enddo + nyel=j-1 + k=1 + y2(1)=yellow(1) + ty2(1)=ty(1) + do j=2,nyel + ok=.true. + do i=1,j-1 + if(abs(ty(i)-ty(j)).lt.0.117) ok=.false. + enddo + if(ok) then + k=k+1 + y2(k)=yellow(j) + ty2(k)=ty(j) + endif + enddo + nyel=k + yellow(1:nyel)=y2(1:nyel) + ty(1:nyel)=ty2(1:nyel) + + return +end subroutine mskdt diff --git a/lib/mskrtd.f90 b/lib/mskrtd.f90 new file mode 100644 index 00000000..71a1f039 --- /dev/null +++ b/lib/mskrtd.f90 @@ -0,0 +1,258 @@ +subroutine mskrtd(id2,nutc0,tsec,ntol,nrxfreq,ndepth,mycall,mygrid,hiscall, & + bshmsg,bcontest,btrain,pcoeffs,bswl,datadir,line) + +! Real-time decoder for MSK144. +! Analysis block size = NZ = 7168 samples, t_block = 0.597333 s +! Called from hspec() at half-block increments, about 0.3 s + + parameter (NZ=7168) !Block size + parameter (NSPM=864) !Number of samples per message frame + parameter (NFFT1=8192) !FFT size for making analytic signal + parameter (NPATTERNS=4) !Number of frame averaging patterns to try + parameter (NRECENT=10) !Number of recent calls to remember + parameter (NSHMEM=50) !Number of recent SWL messages to remember + + character*4 decsym !"&" for mskspd or "^" for long averages + character*22 msgreceived !Decoded message + character*22 msglast,msglastswl !Used for dupechecking + character*80 line !Formatted line with UTC dB T Freq Msg + character*12 mycall,hiscall + character*6 mygrid + character*12 recent_calls(NRECENT) + character*22 recent_shmsgs(NSHMEM) + character*512 datadir + + complex cdat(NFFT1) !Analytic signal + complex c(NSPM) !Coherently averaged complex data + complex ct(NSPM) + + integer*2 id2(NZ) !Raw 16-bit data + integer iavmask(8) + integer iavpatterns(8,NPATTERNS) + integer npkloc(10) + integer nhasharray(NRECENT,NRECENT) + integer nsnrlast,nsnrlastswl + + real d(NFFT1) + real pow(8) + real softbits(144) + real xmc(NPATTERNS) + real*8 pcoeffs(5) + + logical*1 bshmsg,bcontest,btrain,bswl + logical*1 first + logical*1 bshdecode + logical*1 seenb4 + logical*1 bflag + logical*1 bvar + + data first/.true./ + data iavpatterns/ & + 1,1,1,1,0,0,0,0, & + 0,0,1,1,1,1,0,0, & + 1,1,1,1,1,0,0,0, & + 1,1,1,1,1,1,1,0/ + data xmc/2.0,4.5,2.5,3.5/ !Used to set time at center of averaging mask + save first,tsec0,nutc00,pnoise,cdat,msglast,msglastswl, & + nsnrlast,nsnrlastswl,recent_calls,nhasharray,recent_shmsgs + + if(first) then + tsec0=tsec + nutc00=nutc0 + pnoise=-1.0 + do i=1,nrecent + recent_calls(i)(1:12)=' ' + enddo + do i=1,nshmem + recent_shmsgs(i)(1:22)=' ' + enddo + msglast=' ' + msglastswl=' ' + nsnrlast=-99 + nsnrlastswl=-99 + first=.false. + endif + + fc=nrxfreq + +! Dupe checking setup + if(nutc00.ne.nutc0 .or. tsec.lt.tsec0) then ! reset dupe checker + msglast=' ' + msglastswl=' ' + nsnrlast=-99 + nsnrlastswl=-99 + nutc00=nutc0 + endif + + tframe=float(NSPM)/12000.0 + line=char(0) + msgreceived=' ' + max_iterations=10 + niterations=0 + d(1:NZ)=id2 + rms=sqrt(sum(d(1:NZ)*d(1:NZ))/NZ) + if(rms.lt.1.0) go to 999 + fac=1.0/rms + d(1:NZ)=fac*d(1:NZ) + d(NZ+1:NFFT1)=0. + bvar=.true. + if( btrain ) bvar=.false. ! if training, turn off rx eq + call analytic(d,NZ,NFFT1,cdat,pcoeffs,bvar) + +! Calculate average power for each frame and for the entire block. +! If decode is successful, largest power will be taken as signal+noise. +! If no decode, entire-block average will be used to update noise estimate. + pmax=-99 + do i=1,8 + ib=(i-1)*NSPM+1 + ie=ib+NSPM-1 + pow(i)=real(dot_product(cdat(ib:ie),cdat(ib:ie)))*rms**2 + pmax=max(pmax,pow(i)) + enddo + pavg=sum(pow)/8.0 + +! Short ping decoder uses squared-signal spectrum to determine where to +! center a 3-frame analysis window and attempts to decode each of the +! 3 frames along with 2- and 3-frame averages. + np=8*NSPM + call msk144spd(cdat,np,ntol,ndecodesuccess,msgreceived,fc,fest,tdec,navg,ct, & + softbits,recent_calls,nrecent) + if(ndecodesuccess.eq.0 .and. (bshmsg.or.bswl)) then + call msk40spd(cdat,np,ntol,mycall(1:6),hiscall(1:6),bswl,nhasharray, & + recent_calls,nrecent,ndecodesuccess,msgreceived,fc,fest,tdec,navg) + endif + if( ndecodesuccess .ge. 1 ) then + tdec=tsec+tdec + ipk=0 + is=0 + goto 900 + endif + +! If short ping decoder doesn't find a decode, +! Fast - short ping decoder only. +! Normal - try 4-frame averages +! Deep - try 4-, 5- and 7-frame averages. + npat=NPATTERNS + if( ndepth .eq. 1 ) npat=0 + if( ndepth .eq. 2 ) npat=2 + do iavg=1,npat + iavmask=iavpatterns(1:8,iavg) + navg=sum(iavmask) + deltaf=10.0/real(navg) ! search increment for frequency sync + npeaks=2 + call msk144sync(cdat(1:8*NSPM),8,ntol,deltaf,iavmask,npeaks,fc, & + fest,npkloc,nsyncsuccess,xmax,c) + if( nsyncsuccess .eq. 0 ) cycle + + do ipk=1,npeaks + do is=1,3 + ic0=npkloc(ipk) + if(is.eq.2) ic0=max(1,ic0-1) + if(is.eq.3) ic0=min(NSPM,ic0+1) + ct=cshift(c,ic0-1) + call msk144decodeframe(ct,softbits,msgreceived,ndecodesuccess, & + recent_calls,nrecent) + if(ndecodesuccess .gt. 0) then + tdec=tsec+xmc(iavg)*tframe + goto 900 + endif + enddo !Slicer dither + enddo !Peak loop + enddo + + + msgreceived=' ' + +! no decode - update noise level used for calculating displayed snr. + if( pnoise .lt. 0 ) then ! initialize noise level + pnoise=pavg + elseif( pavg .gt. pnoise ) then ! noise level is slow to rise + pnoise=0.9*pnoise+0.1*pavg + elseif( pavg .lt. pnoise ) then ! and quick to fall + pnoise=pavg + endif + go to 999 + +900 continue +! Successful decode - estimate snr + if( pnoise .gt. 0.0 ) then + snr0=10.0*log10(pmax/pnoise-1.0) + else + snr0=0.0 + endif + nsnr=nint(snr0) + + bshdecode=.false. + if( msgreceived(1:1) .eq. '<' ) bshdecode=.true. + + if(.not. bshdecode) then + call msk144signalquality(ct,snr0,fest,tdec,softbits,msgreceived,hiscall, & + btrain,datadir,ncorrected,eyeopening,pcoeffs) + endif + + decsym=' & ' + if( btrain ) decsym=' ^ ' + if( msgreceived(1:1).eq.'<') then + ncorrected=0 + eyeopening=0.0 + endif + + if( nsnr .lt. -8 ) nsnr=-8 + if( nsnr .gt. 24 ) nsnr=24 + +! Dupe check. + bflag=ndecodesuccess.eq.1 .and. & + (msgreceived.ne.msglast .or. nsnr.gt.nsnrlast .or. tsec.lt.tsec0) + if(bflag) then + msglast=msgreceived + nsnrlast=nsnr + if(.not. bshdecode) then + call update_hasharray(recent_calls,nrecent,nhasharray) +! Should we call fix_contest_msg() only if bcontest is true? + call fix_contest_msg(mygrid,msgreceived) + endif + write(line,1020) nutc0,nsnr,tdec,nint(fest),decsym,msgreceived, & + navg,ncorrected,eyeopening,char(0) +1020 format(i6.6,i4,f5.1,i5,a4,a22,i2,i3,f5.1,a1) + elseif(bswl .and. ndecodesuccess.ge.2) then + seenb4=.false. + do i=1,nshmem + if( msgreceived .eq. recent_shmsgs(i) ) then + seenb4=.true. + endif + enddo + call update_recent_shmsgs(msgreceived,recent_shmsgs,nshmem) + bflag=seenb4 .and. & + (msgreceived.ne.msglastswl .or. nsnr.gt.nsnrlastswl .or. tsec.lt.tsec0) & + .and. nsnr.gt.-6 + if(bflag) then + msglastswl=msgreceived + nsnrlastswl=nsnr + write(line,1020) nutc0,nsnr,tdec,nint(fest),decsym,msgreceived, & + navg,ncorrected,eyeopening,char(0) + endif + endif +999 tsec0=tsec + + return +end subroutine mskrtd + +subroutine update_recent_shmsgs(message,msgs,nsize) + character*22 msgs(nsize) + character*22 message + logical*1 seen + + seen=.false. + do i=1,nsize + if( msgs(i) .eq. message ) seen=.true. + enddo + + if( .not. seen ) then + do i=nsize,2,-1 + msgs(i)=msgs(i-1) + enddo + msgs(1)=message + endif + + return +end subroutine update_recent_shmsgs diff --git a/lib/n2grid.f90 b/lib/n2grid.f90 deleted file mode 100644 index ed22a7d5..00000000 --- a/lib/n2grid.f90 +++ /dev/null @@ -1,14 +0,0 @@ -subroutine n2grid(n,grid) - character*4 grid - - if(n.gt.-31 .or. n.lt.-70) stop 'Error in n2grid' - i=-(n+31) !NB: 0 <= i <= 39 - i1=i/10 - i2=mod(i,10) - grid(1:1)=char(ichar('A')+i1) - grid(2:2)='A' - grid(3:3)=char(ichar('0')+i2) - grid(4:4)='0' - - return -end subroutine n2grid diff --git a/lib/nchar.f90 b/lib/nchar.f90 deleted file mode 100644 index 167992ae..00000000 --- a/lib/nchar.f90 +++ /dev/null @@ -1,23 +0,0 @@ -function nchar(c) - -! Convert ascii number, letter, or space to 0-36 for callsign packing. - - character c*1 - - n=0 !Silence compiler warning - if(c.ge.'0' .and. c.le.'9') then - n=ichar(c)-ichar('0') - else if(c.ge.'A' .and. c.le.'Z') then - n=ichar(c)-ichar('A') + 10 - else if(c.ge.'a' .and. c.le.'z') then - n=ichar(c)-ichar('a') + 10 - else if(c.ge.' ') then - n=36 - else - Print*,'Invalid character in callsign ',c,' ',ichar(c) - stop - endif - nchar=n - - return -end function nchar diff --git a/lib/nfft.out b/lib/nfft.out index 142607ad..7607b508 100644 --- a/lib/nfft.out +++ b/lib/nfft.out @@ -1,2067 +1,1546 @@ - 8 0.0000002 0.00000003 32.05 480.8 1000000 0.0 - 9 0.0000002 0.00000010 36.06 571.5 1000000 0.0 - 10 0.0000003 0.00000011 36.63 608.4 1000000 0.0 - 12 0.0000003 0.00000006 41.58 745.3 1000000 0.0 - 14 0.0000003 0.00000018 49.86 949.1 1000000 0.0 - 15 0.0000003 0.00000014 46.90 916.2 1000000 0.0 - 16 0.0000003 0.00000014 46.62 932.4 1000000 0.0 - 18 0.0000005 0.00000012 38.46 801.9 1000000 0.0 - 20 0.0000004 0.00000015 54.55 1178.9 1000000 0.0 - 21 0.0000007 0.00000013 29.54 648.6 713069 0.0 - 24 0.0000005 0.00000018 48.08 1102.1 1000000 0.0 - 25 0.0000005 0.00000012 46.86 1088.1 950368 0.0 - 27 0.0000008 0.00000013 34.88 829.2 654933 0.0 - 28 0.0000006 0.00000016 49.94 1200.4 904282 0.0 - 30 0.0000007 0.00000014 41.13 1009.1 695083 0.0 - 32 0.0000004 0.00000016 75.97 1899.3 1000000 0.0 - 35 0.0000009 0.00000015 40.99 1051.2 593730 0.0 - 36 0.0000006 0.00000016 64.10 1657.0 902775 0.0 - 40 0.0000006 0.00000015 65.49 1742.7 830089 0.0 - 42 0.0000009 0.00000016 49.30 1329.1 595083 0.0 - 45 0.0000010 0.00000016 45.24 1242.4 509755 0.0 - 48 0.0000007 0.00000016 70.88 1979.3 748657 0.0 - 49 0.0000009 0.00000019 56.12 1575.4 580638 0.0 - 50 0.0000008 0.00000019 64.04 1807.1 649334 0.0 - 54 0.0000009 0.00000020 59.11 1700.9 554979 0.0 - 56 0.0000007 0.00000018 83.07 2412.0 752054 0.0 - 60 0.0000008 0.00000017 71.05 2098.3 600342 0.0 - 63 0.0000014 0.00000017 45.62 1363.3 367097 0.0 - 64 0.0000008 0.00000016 79.63 2389.0 630847 0.0 - 70 0.0000011 0.00000019 66.21 2029.0 479524 0.0 - 72 0.0000012 0.00000018 58.27 1797.7 410335 0.0 - 75 0.0000015 0.00000017 51.01 1588.5 344802 0.0 - 80 0.0000010 0.00000018 76.77 2426.6 486510 0.0 - 81 0.0000012 0.00000018 66.71 2114.8 417583 0.0 - 84 0.0000011 0.00000019 74.58 2383.8 450162 0.0 - 90 0.0000015 0.00000018 61.29 1989.3 345250 0.0 - 96 0.0000011 0.00000017 90.90 2992.8 480059 0.1 - 98 0.0000013 0.00000019 73.29 2424.0 379166 0.0 - 100 0.0000012 0.00000020 82.16 2729.2 416548 0.0 - 105 0.0000016 0.00000021 64.79 2175.0 312826 0.0 - 108 0.0000015 0.00000020 72.91 2462.4 342256 0.0 - 112 0.0000014 0.00000017 80.48 2739.1 364301 0.0 - 120 0.0000014 0.00000020 83.73 2891.4 353744 0.1 - 125 0.0000020 0.00000020 61.20 2131.7 248249 0.0 - 126 0.0000019 0.00000019 64.98 2266.9 261472 0.0 - 128 0.0000013 0.00000017 102.07 3572.4 404292 0.0 - 135 0.0000020 0.00000019 66.30 2345.8 248983 0.0 - 140 0.0000016 0.00000021 84.96 3028.7 307695 0.0 - 144 0.0000012 0.00000018 116.47 4175.4 410073 0.1 - 147 0.0000023 0.00000021 62.65 2255.3 216082 0.0 - 150 0.0000015 0.00000023 99.81 3607.5 337364 0.0 - 160 0.0000010 0.00000018 157.76 5775.4 499890 0.1 - 162 0.0000018 0.00000021 89.38 3280.2 279724 0.0 - 168 0.0000012 0.00000019 135.89 5022.8 410109 0.0 - 175 0.0000023 0.00000022 76.10 2835.3 220478 0.0 - 180 0.0000018 0.00000020 101.05 3785.4 284633 0.1 - 189 0.0000029 0.00000022 65.77 2486.9 176433 0.0 - 192 0.0000013 0.00000021 144.48 5479.5 381532 0.1 - 196 0.0000019 0.00000020 103.67 3947.0 268163 0.0 - 200 0.0000017 0.00000020 116.52 4453.2 295374 0.1 - 210 0.0000022 0.00000021 95.01 3664.6 229379 0.0 - 216 0.0000019 0.00000021 111.71 4331.4 262198 0.1 - 224 0.0000016 0.00000021 143.62 5606.6 325073 0.0 - 225 0.0000028 0.00000024 80.24 3135.0 180813 0.0 - 240 0.0000018 0.00000019 136.65 5402.4 288678 0.1 - 243 0.0000037 0.00000022 65.75 2605.3 137187 0.0 - 245 0.0000035 0.00000022 69.66 2764.2 144150 0.0 - 250 0.0000026 0.00000022 96.56 3845.9 195828 0.0 - 252 0.0000027 0.00000022 94.86 3783.6 190847 0.1 - 256 0.0000018 0.00000020 144.00 5760.1 285202 0.0 - 270 0.0000030 0.00000022 90.44 3652.3 169827 0.1 - 280 0.0000018 0.00000020 153.57 6242.0 278071 0.1 - 288 0.0000024 0.00000020 120.47 4921.1 212077 0.1 - 294 0.0000034 0.00000023 85.65 3511.6 147709 0.0 - 300 0.0000023 0.00000020 130.04 5350.5 219771 0.1 - 315 0.0000042 0.00000023 74.49 3091.1 119897 0.0 - 320 0.0000022 0.00000020 143.84 5985.1 227893 0.1 - 324 0.0000035 0.00000023 92.99 3877.5 145508 0.1 - 336 0.0000031 0.00000021 107.57 4514.0 162322 0.1 - 343 0.0000051 0.00000023 67.61 2847.2 99940 0.0 - 350 0.0000038 0.00000024 91.20 3853.7 132109 0.0 - 360 0.0000033 0.00000022 109.15 4634.3 153716 0.2 - 375 0.0000054 0.00000024 69.05 2952.3 93361 0.0 - 378 0.0000038 0.00000023 100.29 4293.5 134514 0.0 - 384 0.0000029 0.00000022 133.04 5710.7 175655 0.1 - 392 0.0000041 0.00000022 94.58 4074.1 122333 0.0 - 400 0.0000030 0.00000021 132.30 5718.1 167698 0.1 - 405 0.0000057 0.00000023 71.36 3090.4 89328 0.0 - 420 0.0000040 0.00000023 105.23 4585.0 127032 0.1 - 432 0.0000039 0.00000022 111.37 4875.0 130702 0.1 - 441 0.0000073 0.00000024 60.29 2648.0 69310 0.0 - 448 0.0000035 0.00000021 128.02 5637.5 144878 0.1 - 450 0.0000045 0.00000023 100.94 4448.2 113724 0.1 - 480 0.0000042 0.00000021 115.27 5133.6 121758 0.2 - 486 0.0000053 0.00000024 91.52 4084.0 95475 0.0 - 490 0.0000054 0.00000023 90.51 4044.1 93646 0.0 - 500 0.0000054 0.00000023 92.18 4132.4 93472 0.1 - 504 0.0000047 0.00000022 108.33 4862.7 108981 0.1 - 512 0.0000032 0.00000020 157.83 7102.4 156292 0.0 - 525 0.0000063 0.00000023 82.97 3748.6 80126 0.0 - 540 0.0000046 0.00000022 116.98 5309.0 109830 0.1 - 560 0.0000049 0.00000021 115.38 5266.7 104464 0.1 - 567 0.0000086 0.00000024 66.26 3030.4 59247 0.0 - 576 0.0000045 0.00000021 128.17 5876.7 112819 0.2 - 588 0.0000057 0.00000024 102.49 4714.6 88379 0.0 - 600 0.0000053 0.00000022 112.66 5198.5 95195 0.2 - 625 0.0000084 0.00000026 74.25 3448.1 60231 0.0 - 630 0.0000054 0.00000023 115.65 5377.5 93074 0.1 - 640 0.0000039 0.00000020 165.92 7733.5 131443 0.2 - 648 0.0000057 0.00000023 113.93 5320.6 89140 0.1 - 672 0.0000059 0.00000023 113.15 5313.9 85367 0.1 - 675 0.0000088 0.00000024 77.13 3624.4 57930 0.1 - 686 0.0000065 0.00000023 106.10 4998.2 78411 0.0 - 700 0.0000072 0.00000023 97.15 4591.1 70368 0.1 - 720 0.0000060 0.00000022 119.85 5687.8 84388 0.3 - 729 0.0000097 0.00000024 74.86 3559.7 52066 0.0 - 735 0.0000097 0.00000024 75.90 3613.4 52355 0.0 - 750 0.0000068 0.00000025 111.07 5303.9 75083 0.1 - 756 0.0000073 0.00000024 104.04 4974.2 69771 0.1 - 768 0.0000051 0.00000022 149.42 7161.0 98641 0.2 - 784 0.0000072 0.00000024 108.16 5199.4 69943 0.1 - 800 0.0000065 0.00000023 124.02 5980.0 78593 0.2 - 810 0.0000073 0.00000024 111.58 5390.3 69839 0.1 - 840 0.0000067 0.00000023 124.60 6052.1 75206 0.2 - 864 0.0000071 0.00000024 120.93 5898.2 70962 0.2 - 875 0.0000114 0.00000025 77.01 3763.2 44622 0.0 - 882 0.0000088 0.00000024 100.07 4895.5 57520 0.0 - 896 0.0000064 0.00000023 140.21 6875.4 79337 0.1 - 900 0.0000078 0.00000023 115.27 5656.0 64935 0.2 - 945 0.0000122 0.00000024 77.64 3836.9 41652 0.1 - 960 0.0000073 0.00000024 131.61 6519.2 69506 0.3 - 972 0.0000103 0.00000024 94.08 4668.6 49072 0.1 - 980 0.0000089 0.00000023 109.95 5462.9 56884 0.1 - 1000 0.0000097 0.00000024 103.30 5147.2 52372 0.1 - 1008 0.0000085 0.00000023 118.42 5907.6 59564 0.2 - 1024 0.0000062 0.00000022 166.42 8321.0 82399 0.0 - 1029 0.0000169 0.00000026 61.00 3052.4 30058 0.0 - 1050 0.0000095 0.00000024 111.07 5573.6 53630 0.1 - 1080 0.0000095 0.00000023 114.00 5743.9 53519 0.3 - 1120 0.0000105 0.00000023 106.32 5384.9 48129 0.2 - 1125 0.0000150 0.00000026 74.83 3792.4 33724 0.1 - 1134 0.0000121 0.00000025 93.70 4754.1 41894 0.1 - 1152 0.0000095 0.00000024 121.83 6194.9 53617 0.3 - 1176 0.0000111 0.00000024 105.85 5398.1 45634 0.1 - 1200 0.0000095 0.00000024 125.75 6431.3 53129 0.3 - 1215 0.0000161 0.00000025 75.67 3877.1 31577 0.1 - 1225 0.0000174 0.00000026 70.49 3615.8 29176 0.0 - 1250 0.0000149 0.00000027 83.88 4314.8 34023 0.0 - 1260 0.0000113 0.00000025 111.18 5725.2 44737 0.2 - 1280 0.0000089 0.00000022 144.22 7443.3 57126 0.2 - 1296 0.0000120 0.00000023 107.71 5568.3 42134 0.2 - 1323 0.0000204 0.00000026 64.88 3363.8 24863 0.0 - 1344 0.0000110 0.00000026 122.35 6357.6 46155 0.2 - 1350 0.0000117 0.00000024 115.22 5990.5 43269 0.2 - 1372 0.0000159 0.00000024 86.29 4496.6 31888 0.0 - 1400 0.0000129 0.00000024 108.17 5652.7 39175 0.2 - 1440 0.0000109 0.00000025 132.63 6957.5 46695 0.4 - 1458 0.0000174 0.00000026 83.93 4410.3 29185 0.1 - 1470 0.0000141 0.00000026 104.57 5501.4 36068 0.1 - 1500 0.0000135 0.00000024 110.72 5840.9 37424 0.2 - 1512 0.0000144 0.00000025 104.89 5539.6 35173 0.2 - 1536 0.0000121 0.00000023 126.98 6720.5 41914 0.2 - 1568 0.0000143 0.00000025 109.51 5812.3 35411 0.1 - 1575 0.0000229 0.00000026 68.67 3646.9 22106 0.1 - 1600 0.0000132 0.00000023 120.78 6427.7 38272 0.3 - 1620 0.0000161 0.00000024 100.89 5378.4 31576 0.3 - 1680 0.0000135 0.00000025 124.52 6670.8 37579 0.3 - 1701 0.0000272 0.00000027 62.52 3355.0 18635 0.1 - 1715 0.0000268 0.00000027 63.96 3436.0 18908 0.0 - 1728 0.0000147 0.00000024 117.91 6340.7 34596 0.4 - 1750 0.0000183 0.00000027 95.88 5164.6 27778 0.1 - 1764 0.0000171 0.00000026 103.10 5559.5 29631 0.1 - 1792 0.0000141 0.00000025 127.25 6876.3 36002 0.2 - 1800 0.0000154 0.00000024 116.90 6320.5 32926 0.4 - 1875 0.0000258 0.00000027 72.75 3955.1 19673 0.1 - 1890 0.0000196 0.00000026 96.45 5249.0 25874 0.2 - 1920 0.0000156 0.00000024 122.71 6692.2 32404 0.4 - 1944 0.0000211 0.00000027 91.93 5021.6 23976 0.2 - 1960 0.0000194 0.00000024 100.83 5513.9 26083 0.1 - 2000 0.0000184 0.00000026 108.89 5970.1 27603 0.2 - 2016 0.0000191 0.00000025 105.55 5793.4 26545 0.4 - 2025 0.0000284 0.00000026 71.29 3915.1 17849 0.1 - 2048 0.0000129 0.00000024 158.66 8726.3 39279 0.0 - 2058 0.0000236 0.00000027 87.27 4802.9 21500 0.0 - 2100 0.0000193 0.00000025 108.66 5995.9 26234 0.3 - 2160 0.0000188 0.00000024 114.92 6364.8 26976 0.5 - 2187 0.0000377 0.00000027 57.94 3214.1 13432 0.0 - 2205 0.0000318 0.00000027 69.36 3851.8 15948 0.1 - 2240 0.0000209 0.00000024 106.94 5950.8 24204 0.3 - 2250 0.0000232 0.00000026 96.98 5400.0 21854 0.2 - 2268 0.0000260 0.00000027 87.26 4863.7 19507 0.2 - 2304 0.0000188 0.00000025 122.85 6861.0 27034 0.5 - 2352 0.0000246 0.00000026 95.53 5349.6 20593 0.2 - 2400 0.0000207 0.00000024 115.74 6498.3 24451 0.5 - 2401 0.0000407 0.00000027 58.94 3309.6 12447 0.0 - 2430 0.0000271 0.00000026 89.58 5037.6 18691 0.2 - 2450 0.0000296 0.00000027 82.67 4653.9 17109 0.1 - 2500 0.0000286 0.00000028 87.41 4933.2 17726 0.1 - 2520 0.0000243 0.00000025 103.83 5865.8 20889 0.4 - 2560 0.0000217 0.00000024 118.13 6687.5 23396 0.4 - 2592 0.0000255 0.00000026 101.69 5765.8 19891 0.4 - 2625 0.0000398 0.00000028 65.98 3747.0 12743 0.1 - 2646 0.0000331 0.00000028 79.92 4543.3 15314 0.1 - 2688 0.0000241 0.00000027 111.51 6351.9 21032 0.4 - 2700 0.0000255 0.00000026 105.77 6028.1 19861 0.4 - 2744 0.0000308 0.00000026 89.07 5086.6 16457 0.1 - 2800 0.0000276 0.00000025 101.39 5805.2 18359 0.3 - 2835 0.0000446 0.00000027 63.59 3646.5 11372 0.1 - 2880 0.0000245 0.00000024 117.36 6743.5 20660 0.8 - 2916 0.0000321 0.00000028 90.73 5221.5 15776 0.2 - 2940 0.0000328 0.00000027 89.62 5162.8 15455 0.2 - 3000 0.0000285 0.00000026 105.17 6074.2 17775 0.4 - 3024 0.0000321 0.00000026 94.27 5449.6 15805 0.4 - 3072 0.0000271 0.00000026 113.19 6556.5 18681 0.4 - 3087 0.0000514 0.00000028 60.10 3483.2 9870 0.0 - 3125 0.0000509 0.00000030 61.43 3565.7 9966 0.0 - 3136 0.0000324 0.00000027 96.80 5621.7 15650 0.2 - 3150 0.0000328 0.00000026 95.95 5575.2 15443 0.3 - 3200 0.0000277 0.00000024 115.73 6737.5 18335 0.5 - 3240 0.0000338 0.00000025 95.81 5586.4 14992 0.5 - 3360 0.0000322 0.00000026 104.28 6107.5 15734 0.6 - 3375 0.0000511 0.00000028 66.05 3870.8 9922 0.1 - 3402 0.0000425 0.00000028 80.08 4697.8 11935 0.2 - 3430 0.0000405 0.00000027 84.69 4972.9 12519 0.1 - 3456 0.0000353 0.00000026 97.91 5754.3 14363 0.6 - 3500 0.0000399 0.00000028 87.77 5166.7 12714 0.2 - 3528 0.0000382 0.00000027 92.34 5441.2 13271 0.3 - 3584 0.0000334 0.00000025 107.29 6334.0 15178 0.3 - 3600 0.0000339 0.00000025 106.06 6264.7 14937 0.8 - 3645 0.0000583 0.00000028 62.48 3696.5 8691 0.1 - 3675 0.0000574 0.00000028 63.99 3789.4 8828 0.1 - 3750 0.0000414 0.00000028 90.56 5376.2 12244 0.2 - 3780 0.0000426 0.00000026 88.65 5267.5 11890 0.5 - 3840 0.0000333 0.00000025 115.29 6863.7 15222 0.7 - 3888 0.0000428 0.00000027 90.75 5411.2 11835 0.5 - 3920 0.0000422 0.00000026 92.81 5539.1 12004 0.3 - 3969 0.0000713 0.00000029 55.64 3326.0 7108 0.1 - 4000 0.0000382 0.00000026 104.77 6268.4 13280 0.5 - 4032 0.0000427 0.00000028 94.43 5655.0 11874 0.7 - 4050 0.0000444 0.00000027 91.20 5464.7 11417 0.4 - 4096 0.0000328 0.00000027 124.70 7481.8 15434 0.0 - 4116 0.0000492 0.00000028 83.66 5022.6 10305 0.1 - 4200 0.0000401 0.00000027 104.83 6309.0 12655 0.6 - 4320 0.0000428 0.00000026 101.04 6101.1 11858 0.9 - 4374 0.0000585 0.00000029 74.78 4522.4 8668 0.1 - 4375 0.0000724 0.00000030 60.45 3655.7 7005 0.1 - 4410 0.0000505 0.00000027 87.33 5286.3 10040 0.2 - 4480 0.0000450 0.00000026 99.53 6036.2 11264 0.6 - 4500 0.0000464 0.00000027 96.97 5883.8 10925 0.6 - 4536 0.0000511 0.00000028 88.73 5389.1 9918 0.5 - 4608 0.0000432 0.00000027 106.66 6490.0 11735 0.7 - 4704 0.0000510 0.00000027 92.27 5628.3 9945 0.4 - 4725 0.0000743 0.00000028 63.61 3882.4 6826 0.2 - 4800 0.0000443 0.00000025 108.34 6624.1 11443 0.9 - 4802 0.0000622 0.00000028 77.17 4718.9 8148 0.0 - 4860 0.0000543 0.00000028 89.58 5485.2 9345 0.5 - 4900 0.0000589 0.00000028 83.20 5099.7 8609 0.3 - 5000 0.0000567 0.00000029 88.12 5413.7 8935 0.4 - 5040 0.0000559 0.00000027 90.09 5540.4 9063 0.9 - 5103 0.0000908 0.00000029 56.22 3462.5 5586 0.1 - 5120 0.0000433 0.00000025 118.26 7285.8 11710 0.6 - 5145 0.0000854 0.00000029 60.27 3715.3 5939 0.1 - 5184 0.0000528 0.00000027 98.26 6062.8 9610 0.8 - 5250 0.0000593 0.00000028 88.53 5470.1 8549 0.3 - 5292 0.0000639 0.00000029 82.81 5121.8 7934 0.3 - 5376 0.0000555 0.00000027 96.83 5999.6 9132 0.7 - 5400 0.0000584 0.00000027 92.48 5733.2 8683 0.9 - 5488 0.0000658 0.00000028 83.36 5177.6 7701 0.2 - 5600 0.0000589 0.00000027 95.02 5915.7 8603 0.7 - 5625 0.0001000 0.00000030 56.23 3502.3 5068 0.2 - 5670 0.0000688 0.00000028 82.42 5138.8 7370 0.4 - 5760 0.0000579 0.00000027 99.49 6213.9 8757 1.3 - 5832 0.0000688 0.00000028 84.79 5303.4 7371 0.5 - 5880 0.0000716 0.00000027 82.10 5140.1 7079 0.5 - 6000 0.0000572 0.00000027 104.91 6583.5 8865 0.9 - 6048 0.0000671 0.00000027 90.09 5658.7 7552 0.9 - 6075 0.0001024 0.00000029 59.35 3729.6 4953 0.2 - 6125 0.0000971 0.00000029 63.05 3965.9 5219 0.1 - 6144 0.0000530 0.00000027 115.85 7290.1 9560 0.7 - 6174 0.0000834 0.00000029 74.00 4659.2 6077 0.1 - 6250 0.0000907 0.00000031 68.93 4346.2 5592 0.2 - 6272 0.0000682 0.00000028 92.03 5804.7 7439 0.5 - 6300 0.0000716 0.00000027 87.99 5552.9 7081 0.8 - 6400 0.0000610 0.00000025 104.83 6627.4 8305 0.8 - 6480 0.0000693 0.00000027 93.55 5922.3 7319 1.1 - 6561 0.0001160 0.00000030 56.54 3584.3 4369 0.1 - 6615 0.0001087 0.00000029 60.84 3860.6 4663 0.2 - 6720 0.0000680 0.00000027 98.84 6283.4 7457 1.2 - 6750 0.0000789 0.00000028 85.53 5439.9 6424 0.5 - 6804 0.0000858 0.00000029 79.31 5048.9 5910 0.5 - 6860 0.0000876 0.00000028 78.27 4987.6 5785 0.2 - 6912 0.0000633 0.00000028 109.22 6965.5 8011 1.1 - 7000 0.0000849 0.00000029 82.46 5266.1 5972 0.6 - 7056 0.0000832 0.00000028 84.85 5424.0 6097 0.7 - 7168 0.0000721 0.00000028 99.47 6370.0 7036 0.5 - 7200 0.0000729 0.00000027 98.75 6327.1 6954 1.5 - 7203 0.0001417 0.00000031 50.85 3258.0 3579 0.0 - 7290 0.0000933 0.00000029 78.17 5015.5 5437 0.4 - 7350 0.0000874 0.00000028 84.11 5401.1 5802 0.4 - 7500 0.0000911 0.00000029 82.32 5298.5 5565 0.6 - 7560 0.0000880 0.00000028 85.92 5534.7 5762 1.1 - 7680 0.0000727 0.00000026 105.70 6821.6 6978 1.3 - 7776 0.0000912 0.00000028 85.23 5507.8 5557 0.9 - 7840 0.0000884 0.00000027 88.65 5734.3 5733 0.6 - 7875 0.0001371 0.00000030 57.45 3718.1 3699 0.3 - 7938 0.0001107 0.00000030 71.69 4643.8 4579 0.2 - 8000 0.0000790 0.00000027 101.32 6568.3 6421 0.9 - 8064 0.0000899 0.00000029 89.65 5817.4 5637 1.2 - 8100 0.0000940 0.00000028 86.19 5595.4 5395 1.0 - 8192 0.0000708 0.00000026 115.70 7520.6 7161 0.0 - 8232 0.0001013 0.00000029 81.26 5284.9 5005 0.3 - 8400 0.0000906 0.00000027 92.72 6043.4 5596 1.3 - 8505 0.0001480 0.00000029 57.47 3751.2 3426 0.3 - 8575 0.0001531 0.00000030 56.00 3658.5 3311 0.1 - 8640 0.0000854 0.00000026 101.14 6613.1 5935 1.8 - 8748 0.0001209 0.00000029 72.37 4738.1 4194 0.4 - 8750 0.0001166 0.00000030 75.06 4914.5 4349 0.3 - 8820 0.0001036 0.00000028 85.12 5578.2 4893 0.7 - 8960 0.0000907 0.00000027 98.77 6484.0 5589 1.1 - 9000 0.0000971 0.00000028 92.71 6089.2 5223 1.3 - 9072 0.0001067 0.00000029 84.99 5587.0 4750 1.1 - 9216 0.0000911 0.00000028 101.14 6659.8 5564 1.2 - 9261 0.0001883 0.00000031 49.17 3239.8 2692 0.1 - 9375 0.0001636 0.00000031 57.32 3781.6 3100 0.2 - 9408 0.0001097 0.00000029 85.78 5661.1 4623 0.9 - 9450 0.0001135 0.00000028 83.24 5496.6 4466 0.8 - 9600 0.0001036 0.00000026 92.71 6132.0 4896 1.7 - 9604 0.0001322 0.00000030 72.64 4804.7 3834 0.1 - 9720 0.0001090 0.00000028 89.17 5906.4 4651 1.2 - 9800 0.0001150 0.00000029 85.24 5650.8 4410 0.7 - 10000 0.0001157 0.00000029 86.41 5741.1 4381 0.8 - 10080 0.0001141 0.00000027 88.32 5872.7 4442 1.8 - 10125 0.0001838 0.00000031 55.10 3665.7 2759 0.4 - 10206 0.0001506 0.00000031 67.78 4512.9 3367 0.4 - 10240 0.0001002 0.00000026 102.19 6807.1 5060 1.0 - 10290 0.0001228 0.00000029 83.81 5585.4 4129 0.3 - 10368 0.0001172 0.00000029 88.45 5899.3 4325 1.6 - 10500 0.0001273 0.00000029 82.47 5508.2 3982 1.0 - 10584 0.0001373 0.00000029 77.07 5152.0 3692 0.7 - 10752 0.0001129 0.00000029 95.22 6376.2 4490 1.3 - 10800 0.0001133 0.00000028 95.32 6385.6 4475 1.9 - 10935 0.0001960 0.00000030 55.79 3742.9 2587 0.2 - 10976 0.0001338 0.00000030 82.05 5506.2 3790 0.4 - 11025 0.0002038 0.00000030 54.10 3632.2 2488 0.3 - 11200 0.0001160 0.00000027 96.54 6492.8 4370 1.4 - 11250 0.0001358 0.00000030 82.85 5574.6 3734 0.7 - 11340 0.0001359 0.00000029 83.43 5618.3 3730 1.2 - 11520 0.0001171 0.00000028 98.42 6639.1 4331 2.3 - 11664 0.0001419 0.00000029 82.23 5554.2 3574 1.1 - 11760 0.0001343 0.00000028 87.57 5920.4 3775 1.2 - 11907 0.0002425 0.00000032 49.11 3324.3 2091 0.2 - 12000 0.0001319 0.00000028 91.00 6165.8 3845 1.8 - 12005 0.0002249 0.00000031 53.37 3616.1 2254 0.1 - 12096 0.0001445 0.00000028 83.72 5677.1 3509 1.8 - 12150 0.0001611 0.00000029 75.42 5116.6 3147 0.8 - 12250 0.0001721 0.00000030 71.18 4833.4 2946 0.4 - 12288 0.0001231 0.00000030 99.83 6781.1 4119 1.2 - 12348 0.0001642 0.00000031 75.19 5109.9 3087 0.5 - 12500 0.0001733 0.00000032 72.14 4909.1 2926 0.6 - 12544 0.0001542 0.00000029 81.35 5537.6 3288 0.9 - 12600 0.0001485 0.00000029 84.84 5778.2 3414 1.9 - 12800 0.0001319 0.00000027 97.02 6619.0 3843 1.5 - 12960 0.0001357 0.00000028 95.48 6522.3 3735 2.3 - 13122 0.0002021 0.00000031 64.94 4441.7 2509 0.3 - 13125 0.0002455 0.00000031 53.46 3656.4 2065 0.4 - 13230 0.0001777 0.00000030 74.45 5096.7 2853 0.6 - 13440 0.0001463 0.00000029 91.89 6300.8 3466 2.3 - 13500 0.0001546 0.00000029 87.34 5992.1 3280 1.5 - 13608 0.0001810 0.00000030 75.18 5161.7 2801 1.2 - 13720 0.0001694 0.00000029 81.00 5566.0 2993 0.6 - 13824 0.0001446 0.00000029 95.63 6577.0 3507 1.9 - 14000 0.0001811 0.00000029 77.29 5322.7 2799 1.4 - 14112 0.0001714 0.00000029 82.31 5673.3 2957 1.4 - 14175 0.0002602 0.00000031 54.49 3757.1 1949 0.6 - 14336 0.0001544 0.00000030 92.83 6408.9 3283 1.0 - 14400 0.0001522 0.00000028 94.58 6532.7 3330 3.0 - 14406 0.0002123 0.00000031 67.85 4686.9 2388 0.2 - 14580 0.0001862 0.00000029 78.31 5415.7 2723 1.3 - 14700 0.0001859 0.00000029 79.07 5472.9 2727 1.1 - 15000 0.0001819 0.00000030 82.48 5721.2 2788 1.5 - 15120 0.0001809 0.00000028 83.59 5803.2 2803 2.5 - 15309 0.0003149 0.00000032 48.62 3379.3 1610 0.3 - 15360 0.0001543 0.00000028 99.52 6920.4 3285 2.3 - 15435 0.0003032 0.00000031 50.90 3541.3 1672 0.3 - 15552 0.0001849 0.00000029 84.11 5855.8 2742 2.0 - 15625 0.0003060 0.00000034 51.06 3557.0 1657 0.1 - 15680 0.0001883 0.00000029 83.28 5803.4 2693 1.4 - 15750 0.0002002 0.00000030 78.69 5485.9 2533 1.2 - 15876 0.0002314 0.00000031 68.61 4787.1 2191 0.8 - 16000 0.0001781 0.00000028 89.84 6273.6 2847 1.9 - 16128 0.0001852 0.00000030 87.10 6087.1 2738 2.3 - 16200 0.0001931 0.00000028 83.91 5866.8 2626 2.4 - 16384 0.0001589 0.00000028 103.12 7218.1 3191 0.0 - 16464 0.0002205 0.00000030 74.68 5230.3 2300 0.8 - 16800 0.0001976 0.00000028 85.03 5967.4 2566 2.6 - 16807 0.0003405 0.00000032 49.36 3464.2 1489 0.0 - 16875 0.0003167 0.00000032 53.29 3741.4 1601 0.5 - 17010 0.0002316 0.00000030 73.44 5160.6 2189 1.0 - 17150 0.0002507 0.00000031 68.40 4810.4 2022 0.4 - 17280 0.0001873 0.00000029 92.27 6494.3 2707 3.3 - 17496 0.0002608 0.00000031 67.08 4727.6 1944 1.2 - 17500 0.0002381 0.00000031 73.48 5178.8 2129 0.9 - 17640 0.0002287 0.00000029 77.13 5440.4 2217 1.7 - 17920 0.0001879 0.00000028 95.39 6738.8 2699 2.0 - 18000 0.0002015 0.00000028 89.33 6313.5 2516 2.7 - 18144 0.0002326 0.00000030 78.02 5518.6 2180 2.2 - 18225 0.0003426 0.00000031 53.20 3765.0 1480 0.6 - 18375 0.0003465 0.00000031 53.02 3755.6 1463 0.4 - 18432 0.0001985 0.00000029 92.88 6580.4 2555 2.2 - 18522 0.0002727 0.00000032 67.91 4813.9 1859 0.4 - 18750 0.0002630 0.00000032 71.30 5060.3 1928 0.8 - 18816 0.0002192 0.00000030 85.84 6094.7 2313 1.7 - 18900 0.0002211 0.00000029 85.48 6071.7 2293 2.3 - 19200 0.0002152 0.00000028 89.22 6347.3 2356 3.1 - 19208 0.0002705 0.00000031 71.00 5051.7 1874 0.4 - 19440 0.0002414 0.00000029 80.52 5735.6 2100 2.7 - 19600 0.0002515 0.00000029 77.94 5556.4 2016 1.6 - 19683 0.0004197 0.00000032 46.90 3345.0 1208 0.2 - 19845 0.0003936 0.00000031 50.41 3598.6 1288 0.5 - 20000 0.0002395 0.00000030 83.52 5966.4 2117 1.8 - 20160 0.0002311 0.00000029 87.24 6237.5 2194 3.8 - 20250 0.0002452 0.00000030 82.59 5907.8 2068 1.3 - 20412 0.0003009 0.00000032 67.84 4856.4 1685 1.2 - 20480 0.0002183 0.00000028 93.80 6717.3 2322 1.8 - 20580 0.0002904 0.00000030 70.87 5077.2 1746 1.0 - 20736 0.0002400 0.00000029 86.41 6195.7 2113 2.8 - 21000 0.0002531 0.00000030 82.96 5955.8 2003 2.4 - 21168 0.0002619 0.00000031 80.83 5807.3 1936 1.8 - 21504 0.0002227 0.00000031 96.57 6949.6 2277 2.3 - 21600 0.0002597 0.00000028 83.16 5986.9 1952 4.0 - 21609 0.0004584 0.00000032 47.14 3393.9 1106 0.2 - 21870 0.0003111 0.00000031 70.30 5067.8 1630 1.0 - 21875 0.0004359 0.00000033 50.18 3617.2 1163 0.3 - 21952 0.0002853 0.00000032 76.93 5547.6 1777 1.0 - 22050 0.0002864 0.00000030 76.99 5553.9 1770 1.3 - 22400 0.0002685 0.00000029 83.42 6027.3 1888 2.6 - 22500 0.0002609 0.00000031 86.23 6233.4 1943 2.1 - 22680 0.0002906 0.00000030 78.06 5647.1 1745 3.0 - 23040 0.0002484 0.00000029 92.75 6720.4 2041 4.1 - 23328 0.0003207 0.00000031 72.74 5277.3 1581 2.4 - 23520 0.0002970 0.00000030 79.19 5749.9 1707 2.5 - 23625 0.0004593 0.00000032 51.44 3736.7 1104 1.0 - 23814 0.0003604 0.00000032 66.08 4804.2 1407 0.7 - 24000 0.0002823 0.00000029 85.01 6184.8 1796 3.6 - 24010 0.0003693 0.00000031 65.01 4730.3 1373 0.4 - 24192 0.0003004 0.00000030 80.54 5864.3 1688 3.5 - 24300 0.0003097 0.00000030 78.47 5715.7 1637 2.5 - 24500 0.0003410 0.00000031 71.85 5238.4 1487 1.2 - 24576 0.0002509 0.00000030 97.96 7143.8 2021 2.1 - 24696 0.0003501 0.00000031 70.53 5146.1 1448 1.2 - 25000 0.0003461 0.00000033 72.24 5276.7 1465 1.5 - 25088 0.0002975 0.00000031 84.32 6161.3 1704 1.8 - 25200 0.0003093 0.00000029 81.46 5955.3 1639 4.4 - 25515 0.0005178 0.00000032 49.27 3606.5 979 0.8 - 25600 0.0002707 0.00000028 94.57 6924.3 1873 2.8 - 25725 0.0005221 0.00000031 49.27 3609.4 971 0.5 - 25920 0.0002946 0.00000028 87.97 6449.1 1721 4.7 - 26244 0.0004046 0.00000032 64.86 4760.4 1253 1.2 - 26250 0.0003909 0.00000032 67.15 4928.8 1297 1.4 - 26460 0.0003701 0.00000031 71.50 5252.0 1370 2.0 - 26880 0.0002958 0.00000029 90.86 6684.5 1714 4.5 - 27000 0.0003578 0.00000029 75.47 5554.7 1417 3.8 - 27216 0.0003817 0.00000031 71.29 5251.5 1328 2.9 - 27440 0.0003900 0.00000031 70.36 5186.7 1300 1.5 - 27648 0.0003262 0.00000030 84.75 6252.4 1554 3.6 - 27783 0.0006450 0.00000032 43.08 3179.4 786 0.3 - 28000 0.0003593 0.00000030 77.93 5756.5 1411 3.0 - 28125 0.0005578 0.00000034 50.42 3725.7 909 0.8 - 28224 0.0003692 0.00000030 76.44 5650.6 1373 3.3 - 28350 0.0003719 0.00000030 76.22 5637.0 1363 2.2 - 28672 0.0003376 0.00000031 84.94 6288.6 1502 2.0 - 28800 0.0003568 0.00000029 80.73 5979.3 1421 5.9 - 28812 0.0004552 0.00000032 63.30 4688.5 1114 0.7 - 29160 0.0004109 0.00000030 70.96 5262.4 1234 3.4 - 29400 0.0003829 0.00000030 76.77 5697.9 1324 2.9 - 30000 0.0003690 0.00000031 81.30 6045.6 1374 3.6 - 30240 0.0004076 0.00000030 74.20 5521.7 1244 5.6 - 30375 0.0006305 0.00000032 48.17 3586.6 804 1.0 - 30618 0.0005015 0.00000032 61.05 4549.1 1011 1.1 - 30625 0.0006244 0.00000033 49.05 3654.6 812 0.4 - 30720 0.0003567 0.00000030 86.12 6418.8 1421 4.3 - 30870 0.0004375 0.00000031 70.57 5262.1 1159 1.2 - 31104 0.0004232 0.00000030 73.50 5485.0 1198 4.0 - 31250 0.0004945 0.00000035 63.19 4717.7 1025 0.8 - 31360 0.0003864 0.00000030 81.15 6060.5 1312 2.8 - 31500 0.0004079 0.00000030 77.22 5769.9 1243 3.6 - 31752 0.0004560 0.00000032 69.63 5206.5 1112 2.2 - 32000 0.0003844 0.00000029 83.26 6230.1 1319 3.5 - 32256 0.0003853 0.00000031 83.72 6269.7 1316 4.5 - 32400 0.0003998 0.00000029 81.04 6071.3 1268 5.3 - 32768 0.0003706 0.00000029 88.41 6630.9 1368 0.0 - 32805 0.0006688 0.00000032 49.05 3679.1 758 0.7 - 32928 0.0004467 0.00000031 73.71 5531.0 1135 1.8 - 33075 0.0006459 0.00000032 51.21 3844.1 785 1.1 - 33600 0.0004089 0.00000029 82.17 6177.9 1240 5.7 - 33614 0.0004995 0.00000032 67.29 5059.3 1015 0.2 - 33750 0.0004639 0.00000031 72.75 5471.5 1093 2.1 - 34020 0.0004775 0.00000031 71.24 5362.3 1062 3.4 - 34300 0.0005031 0.00000031 68.18 5135.6 1008 1.4 - 34560 0.0004030 0.00000030 85.75 6464.1 1258 6.4 - 34992 0.0004917 0.00000031 71.16 5370.9 1031 2.9 - 35000 0.0004941 0.00000032 70.83 5346.2 1026 2.4 - 35280 0.0005085 0.00000030 69.37 5240.0 997 4.3 - 35721 0.0007456 0.00000033 47.91 3622.9 680 0.5 - 35840 0.0004371 0.00000029 82.00 6202.8 1160 3.9 - 36000 0.0004355 0.00000029 82.66 6255.4 1164 6.1 - 36015 0.0007203 0.00000032 50.00 3784.2 704 0.4 - 36288 0.0005101 0.00000031 71.13 5387.4 994 5.0 - 36450 0.0005016 0.00000031 72.67 5506.3 1011 2.4 - 36750 0.0005452 0.00000031 67.41 5111.4 930 1.6 - 36864 0.0004394 0.00000030 83.90 6364.1 1154 4.1 - 37044 0.0005728 0.00000032 64.67 4907.3 885 1.4 - 37500 0.0005464 0.00000033 68.64 5214.5 928 2.6 - 37632 0.0004577 0.00000031 82.23 6249.2 1108 3.5 - 37800 0.0005014 0.00000030 75.38 5731.4 1011 5.7 - 38400 0.0004389 0.00000029 87.49 6661.6 1155 6.1 - 38416 0.0005232 0.00000032 73.43 5591.4 969 1.0 - 38880 0.0005365 0.00000030 72.47 5525.0 945 6.1 - 39200 0.0004942 0.00000030 79.32 6051.2 1026 3.7 - 39366 0.0006361 0.00000033 61.89 4723.5 797 1.0 - 39375 0.0008380 0.00000034 46.98 3586.1 605 1.4 - 39690 0.0005808 0.00000032 68.34 5219.9 873 1.9 - 40000 0.0004824 0.00000031 82.92 6338.0 1051 3.9 - 40320 0.0004893 0.00000031 82.40 6303.0 1036 7.8 - 40500 0.0005019 0.00000030 80.69 6174.8 1010 4.3 - 40824 0.0006283 0.00000032 64.98 4976.4 807 3.2 - 40960 0.0004774 0.00000029 85.79 6572.7 1062 3.4 - 41160 0.0005762 0.00000031 71.44 5475.4 880 2.6 - 41472 0.0004856 0.00000031 85.41 6550.5 1044 5.4 - 42000 0.0005458 0.00000030 76.95 5908.8 929 5.9 - 42336 0.0005665 0.00000031 74.73 5743.0 895 4.1 - 42525 0.0008098 0.00000032 52.51 4037.0 626 1.7 - 42875 0.0008942 0.00000032 47.95 3689.0 567 0.5 - 43008 0.0004861 0.00000031 88.48 6809.8 1043 4.5 - 43200 0.0005348 0.00000029 80.78 6219.8 948 8.6 - 43218 0.0007338 0.00000033 58.89 4534.6 691 0.8 - 43740 0.0006716 0.00000031 65.13 5020.1 755 3.6 - 43750 0.0007500 0.00000034 58.33 4496.5 676 1.4 - 43904 0.0005493 0.00000032 79.93 6163.8 923 2.2 - 44100 0.0006117 0.00000031 72.10 5561.7 829 4.2 - 44800 0.0005800 0.00000029 77.24 5966.9 874 5.6 - 45000 0.0006759 0.00000032 66.57 5145.3 750 5.5 - 45360 0.0007080 0.00000031 64.06 4955.1 716 7.4 - 45927 0.0010453 0.00000033 43.94 3402.3 485 0.8 - 46080 0.0005216 0.00000029 88.34 6842.7 972 8.0 - 46305 0.0010741 0.00000033 43.11 3340.9 472 0.9 - 46656 0.0006044 0.00000031 77.20 5986.4 839 5.5 - 46875 0.0009772 0.00000035 47.97 3721.7 519 0.9 - 47040 0.0006680 0.00000031 70.42 5465.0 759 5.6 - 47250 0.0006094 0.00000031 77.54 6019.9 832 3.7 - 47628 0.0007151 0.00000033 66.60 5174.8 709 2.4 - 48000 0.0006029 0.00000029 79.62 6190.6 841 7.5 - 48020 0.0007885 0.00000032 60.90 4735.3 643 1.4 - 48384 0.0005915 0.00000032 81.80 6365.1 857 7.1 - 48600 0.0006458 0.00000031 75.25 5858.1 785 6.5 - 49000 0.0007072 0.00000032 69.28 5397.5 717 3.1 - 49152 0.0005677 0.00000031 86.58 6746.8 893 4.0 - 49392 0.0007489 0.00000032 65.95 5141.5 677 3.2 - 50000 0.0007041 0.00000033 71.01 5542.3 720 3.6 - 50176 0.0006198 0.00000032 80.95 6320.2 818 3.5 - 50400 0.0006064 0.00000030 83.11 6491.5 836 9.6 - 50421 0.0011419 0.00000034 44.15 3448.8 444 0.2 - 50625 0.0010741 0.00000034 47.13 3683.0 472 1.7 - 51030 0.0007578 0.00000032 67.34 5265.8 669 3.0 - 51200 0.0006243 0.00000029 82.01 6414.6 812 5.4 - 51450 0.0007824 0.00000032 65.76 5145.7 648 1.9 - 51840 0.0006993 0.00000031 74.14 5805.5 725 9.5 - 52488 0.0008060 0.00000032 65.12 5105.6 629 3.3 - 52500 0.0007567 0.00000032 69.38 5439.8 670 4.5 - 52920 0.0007294 0.00000031 72.55 5692.0 695 5.2 - 53760 0.0006510 0.00000030 82.58 6488.3 779 8.7 - 54000 0.0006815 0.00000030 79.24 6228.5 744 8.5 - 54432 0.0007523 0.00000032 72.36 5691.8 674 6.5 - 54675 0.0011471 0.00000033 47.66 3750.8 442 1.7 - 54880 0.0007730 0.00000031 71.00 5588.9 656 3.4 - 55125 0.0011392 0.00000033 48.39 3810.6 445 1.7 - 55296 0.0006388 0.00000031 86.56 6819.0 794 6.7 - 55566 0.0009219 0.00000033 60.28 4750.4 550 1.3 - 56000 0.0007498 0.00000030 74.68 5889.8 676 6.5 - 56250 0.0008311 0.00000033 67.68 5340.1 610 3.2 - 56448 0.0007959 0.00000032 70.93 5597.8 637 6.7 - 56700 0.0007886 0.00000031 71.90 5676.7 643 6.9 - 57344 0.0006788 0.00000031 84.48 6676.7 747 3.7 - 57600 0.0007122 0.00000030 80.88 6394.9 712 11.4 - 57624 0.0008817 0.00000032 65.36 5168.0 575 2.0 - 58320 0.0008366 0.00000031 69.71 5518.4 606 7.9 - 58800 0.0008639 0.00000031 68.07 5392.1 587 6.8 - 59049 0.0014244 0.00000034 41.46 3285.3 356 0.6 - 59535 0.0013306 0.00000033 44.74 3548.4 381 1.4 - 60000 0.0007799 0.00000031 76.93 6105.4 650 7.9 - 60025 0.0013480 0.00000033 44.53 3534.2 376 0.6 - 60480 0.0009601 0.00000030 62.99 5002.7 528 12.2 - 60750 0.0009463 0.00000031 64.20 5100.8 536 4.1 - 61236 0.0012580 0.00000033 48.68 3870.5 403 3.7 - 61250 0.0009904 0.00000034 61.84 4917.4 512 1.9 - 61440 0.0007811 0.00000029 78.65 6255.7 649 8.1 - 61740 0.0009388 0.00000032 65.76 5232.8 540 4.0 - 62208 0.0008482 0.00000031 73.34 5840.0 598 8.0 - 62500 0.0010562 0.00000036 59.18 4713.9 480 2.6 - 62720 0.0008801 0.00000031 71.26 5678.4 576 5.9 - 63000 0.0008959 0.00000031 70.32 5605.6 566 9.0 - 63504 0.0009529 0.00000033 66.64 5316.1 532 5.7 - 64000 0.0008595 0.00000030 74.47 5944.5 590 7.0 - 64512 0.0008009 0.00000031 80.55 6434.9 633 8.6 - 64800 0.0011291 0.00000031 57.39 4586.7 449 12.1 - 64827 0.0018707 0.00000034 34.65 2769.6 271 0.7 - 65536 0.0009882 0.00000030 66.32 5305.4 513 0.0 - 65610 0.0013702 0.00000032 47.89 3831.2 370 0.4 - 65625 0.0017073 0.00000033 38.44 3075.3 297 0.2 - 65856 0.0012248 0.00000032 53.77 4303.3 414 1.2 - 66150 0.0013271 0.00000033 49.84 3990.9 382 0.7 - 67200 0.0011762 0.00000030 57.13 4580.8 431 3.7 - 67228 0.0018106 0.00000034 37.13 2977.3 280 0.2 - 67500 0.0011069 0.00000032 60.98 4891.5 458 2.0 - 68040 0.0012520 0.00000032 54.34 4362.1 405 2.4 - 68600 0.0013705 0.00000032 50.06 4020.9 370 0.8 - 69120 0.0011266 0.00000031 61.35 4931.9 450 5.0 - 69984 0.0014655 0.00000033 47.75 3842.8 346 2.5 - 70000 0.0013168 0.00000033 53.16 4278.1 385 1.8 - 70560 0.0012517 0.00000031 56.37 4539.6 405 2.6 - 70875 0.0018992 0.00000033 37.32 3006.6 267 0.6 - 71442 0.0016517 0.00000033 43.25 3487.2 307 0.3 - 71680 0.0011574 0.00000030 61.93 4994.4 438 2.6 - 72000 0.0012611 0.00000031 57.09 4606.2 402 5.0 - 72030 0.0021946 0.00000033 32.82 2648.1 231 10.3 - 72576 0.0012933 0.00000032 56.12 4530.8 392 4.1 - 72900 0.0014784 0.00000033 49.31 3982.8 343 2.3 - 73500 0.0014244 0.00000032 51.60 4170.8 356 0.9 - 73728 0.0011519 0.00000031 64.01 5174.8 440 3.3 - 74088 0.0014958 0.00000033 49.53 4006.2 339 1.0 - 75000 0.0012368 0.00000033 60.64 4910.3 410 1.5 - 75264 0.0012939 0.00000033 58.17 4711.6 392 2.2 - 75600 0.0012963 0.00000031 58.32 4725.8 391 4.8 - 76545 0.0020442 0.00000033 37.45 3037.6 248 0.4 - 76800 0.0012305 0.00000030 62.41 5064.6 412 4.2 - 76832 0.0015651 0.00000033 49.09 3983.7 324 0.7 - 77175 0.0022047 0.00000033 35.00 2841.7 230 0.3 - 77760 0.0013519 0.00000031 57.52 4672.5 375 5.1 - 78125 0.0022632 0.00000036 34.52 2805.3 224 0.2 - 78400 0.0014568 0.00000032 53.82 4375.0 348 2.9 - 78732 0.0017248 0.00000033 45.65 3712.2 294 1.1 - 78750 0.0014402 0.00000033 54.68 4446.8 352 0.9 - 79380 0.0015595 0.00000032 50.90 4142.5 325 1.5 - 80000 0.0013776 0.00000031 58.07 4729.3 368 3.0 - 80640 0.0014086 0.00000031 57.25 4665.7 360 5.9 - 81000 0.0013927 0.00000032 58.16 4741.6 364 3.6 - 81648 0.0016517 0.00000033 49.43 4032.9 307 3.0 - 81920 0.0012614 0.00000030 64.94 5300.1 402 2.4 - 82320 0.0016622 0.00000032 49.53 4043.5 305 1.4 - 82944 0.0014324 0.00000031 57.90 4730.7 354 4.7 - 83349 0.0025475 0.00000035 32.72 2674.2 199 0.2 - 84000 0.0014958 0.00000031 56.16 4593.1 339 3.6 - 84035 0.0029481 0.00000034 28.50 2331.5 172 1.6 - 84375 0.0023255 0.00000034 36.28 2968.7 218 0.6 - 84672 0.0015551 0.00000033 54.45 4456.5 326 3.3 - 85050 0.0017918 0.00000033 47.47 3886.5 283 1.3 - 85750 0.0016731 0.00000033 51.25 4199.5 303 0.3 - 86016 0.0014491 0.00000032 59.36 4864.9 350 3.1 - 86400 0.0014694 0.00000030 58.80 4821.0 345 6.9 - 86436 0.0020442 0.00000034 42.28 3467.1 248 0.8 - 87480 0.0018306 0.00000033 47.79 3922.5 277 2.4 - 87500 0.0016098 0.00000034 54.36 4461.8 315 0.9 - 87808 0.0015992 0.00000033 54.91 4508.4 317 1.6 - 88200 0.0016149 0.00000032 54.62 4486.3 314 2.8 - 89600 0.0014698 0.00000032 60.96 5014.4 345 4.1 - 90000 0.0015842 0.00000032 56.81 4674.7 320 4.7 - 90720 0.0015266 0.00000032 59.43 4893.4 332 5.3 - 91125 0.0025348 0.00000033 35.95 2961.5 200 0.7 - 91854 0.0021306 0.00000034 43.11 3554.0 238 0.5 - 91875 0.0026830 0.00000033 34.24 2823.0 189 0.2 - 92160 0.0014406 0.00000031 63.97 5275.3 352 5.9 - 92610 0.0020525 0.00000033 45.12 3722.3 247 0.3 - 93312 0.0016787 0.00000032 55.59 4588.6 302 4.8 - 93750 0.0018707 0.00000035 50.12 4138.6 271 0.4 - 94080 0.0016847 0.00000031 55.85 4613.3 301 3.2 - 94500 0.0018435 0.00000033 51.26 4236.3 275 3.2 - 95256 0.0020038 0.00000034 47.54 3931.3 253 1.8 - 96000 0.0016676 0.00000031 57.57 4763.9 304 5.2 - 96040 0.0019803 0.00000033 48.50 4013.5 256 0.6 - 96768 0.0018106 0.00000031 53.45 4426.0 280 5.8 - 97200 0.0017302 0.00000032 56.18 4653.9 293 5.7 - 98000 0.0018851 0.00000032 51.99 4309.9 269 2.2 - 98304 0.0015224 0.00000032 64.57 5354.6 333 2.7 - 98415 0.0027256 0.00000033 36.11 2994.5 186 0.3 - 98784 0.0019350 0.00000033 51.05 4235.3 262 2.3 - 99225 0.0027559 0.00000033 36.00 2988.1 184 0.7 - 100000 0.0017914 0.00000034 55.82 4636.0 283 2.6 - 100352 0.0016513 0.00000032 60.77 5048.4 307 2.8 - 100800 0.0018368 0.00000031 54.88 4560.7 276 7.8 - 100842 0.0030920 0.00000035 32.61 2710.5 164 4.7 - 101250 0.0019424 0.00000033 52.13 4333.7 261 1.5 - 102060 0.0021946 0.00000032 46.50 3869.0 231 2.3 - 102400 0.0017127 0.00000030 59.79 4975.6 296 4.3 - 102900 0.0021573 0.00000033 47.70 3971.2 235 1.1 - 103680 0.0019140 0.00000031 54.17 4512.9 265 7.7 - 104976 0.0023362 0.00000034 44.93 3747.5 217 3.2 - 105000 0.0020360 0.00000033 51.57 4301.1 249 2.4 - 105840 0.0021946 0.00000032 48.23 4024.9 231 3.9 - 107163 0.0033573 0.00000035 31.92 2666.7 151 0.3 - 107520 0.0017546 0.00000032 61.28 5121.1 289 5.6 - 108000 0.0019574 0.00000031 55.18 4612.9 259 7.1 - 108045 0.0033142 0.00000034 32.60 2725.6 153 0.2 - 108864 0.0021941 0.00000033 49.62 4151.0 231 5.7 - 109350 0.0022338 0.00000034 48.95 4096.9 227 1.3 - 109375 0.0031884 0.00000035 34.30 2871.0 159 0.3 - 109760 0.0021758 0.00000032 50.45 4223.4 233 2.0 - 110250 0.0022235 0.00000033 49.58 4152.8 228 1.1 - 110592 0.0018570 0.00000032 59.55 4989.1 273 5.8 - 111132 0.0025740 0.00000035 43.17 3618.4 197 1.4 - 112000 0.0020782 0.00000032 53.89 4519.8 244 4.7 - 112500 0.0019574 0.00000034 57.48 4822.0 259 2.8 - 112896 0.0021573 0.00000032 52.33 4391.9 235 5.8 - 113400 0.0021852 0.00000032 51.90 4356.9 232 5.2 - 114688 0.0019654 0.00000032 58.35 4903.8 258 2.8 - 115200 0.0019498 0.00000031 59.08 4966.9 260 9.4 - 115248 0.0024373 0.00000034 47.29 3975.4 208 1.3 - 116640 0.0023690 0.00000033 49.24 4143.7 214 6.0 - 117600 0.0021578 0.00000032 54.50 4589.9 235 3.7 - 117649 0.0042247 0.00000035 27.85 2345.4 120 1.2 - 118098 0.0028171 0.00000035 41.92 3531.8 180 0.6 - 118125 0.0032927 0.00000033 35.87 3022.4 154 0.9 - 119070 0.0026542 0.00000033 44.86 3782.1 191 0.8 - 120000 0.0020692 0.00000032 57.99 4892.5 245 5.5 - 120050 0.0024491 0.00000033 49.02 4135.5 207 0.3 - 120960 0.0022235 0.00000031 54.40 4592.6 228 8.9 - 121500 0.0024256 0.00000033 50.09 4230.2 209 3.9 - 122472 0.0028009 0.00000034 43.73 3695.3 181 2.8 - 122500 0.0026138 0.00000034 46.87 3960.8 194 1.3 - 122880 0.0020365 0.00000031 60.34 5100.8 249 5.2 - 123480 0.0026132 0.00000033 47.25 3996.1 194 2.2 - 124416 0.0023807 0.00000032 52.26 4422.6 213 6.9 - 125000 0.0025481 0.00000036 49.06 4152.9 199 1.7 - 125440 0.0021306 0.00000032 58.88 4985.8 238 3.7 - 126000 0.0023913 0.00000032 52.69 4463.7 212 7.3 - 127008 0.0028009 0.00000033 45.35 3844.1 181 4.7 - 127575 0.0037833 0.00000034 33.72 2859.7 134 1.1 - 128000 0.0021946 0.00000031 58.32 4947.6 231 5.5 - 128625 0.0037276 0.00000032 34.51 2928.3 136 0.3 - 129024 0.0023368 0.00000032 55.21 4687.0 217 7.0 - 129600 0.0024497 0.00000032 52.91 4492.6 207 11.0 - 129654 0.0031488 0.00000035 41.18 3496.7 161 0.4 - 131072 0.0021391 0.00000032 61.28 5208.4 237 0.0 - 131220 0.0032919 0.00000033 39.86 3388.5 154 2.7 - 131250 0.0028164 0.00000035 46.60 3961.6 180 0.6 - 131712 0.0025481 0.00000032 51.69 4395.4 199 2.7 - 132300 0.0028969 0.00000033 45.67 3885.0 175 3.3 - 134400 0.0024616 0.00000032 54.60 4650.8 206 8.1 - 134456 0.0032497 0.00000034 41.37 3524.4 156 0.5 - 135000 0.0025222 0.00000033 53.53 4561.0 201 5.4 - 136080 0.0030912 0.00000032 44.02 3753.7 164 6.9 - 137200 0.0028322 0.00000033 48.44 4133.7 179 2.5 - 137781 0.0040894 0.00000035 33.69 2876.0 124 0.5 - 138240 0.0024985 0.00000031 55.33 4724.2 203 9.9 - 138915 0.0039299 0.00000034 35.35 3019.4 129 0.4 - 139968 0.0027403 0.00000033 51.08 4365.8 185 6.5 - 140000 0.0026542 0.00000033 52.75 4508.5 191 4.1 - 140625 0.0042612 0.00000036 33.00 2821.9 119 0.7 - 141120 0.0027256 0.00000032 51.78 4428.6 186 6.9 - 141750 0.0030364 0.00000034 46.68 3994.5 167 2.2 - 142884 0.0035452 0.00000035 40.30 3450.9 143 2.2 - 143360 0.0024736 0.00000031 57.96 4963.8 205 5.1 - 144000 0.0026966 0.00000032 53.40 4575.3 188 10.8 - 144060 0.0041564 0.00000034 34.66 2969.7 122 0.7 - 145152 0.0029304 0.00000032 49.53 4246.8 173 8.9 - 145800 0.0029304 0.00000033 49.75 4267.3 173 5.9 - 147000 0.0031102 0.00000033 47.26 4056.6 163 2.7 - 147456 0.0026132 0.00000033 56.43 4844.3 194 6.9 - 148176 0.0035205 0.00000034 42.09 3614.8 144 3.3 - 150000 0.0028976 0.00000034 51.77 4450.6 175 4.6 - 150528 0.0027262 0.00000033 55.21 4748.4 186 4.5 - 151200 0.0028178 0.00000033 53.66 4616.3 180 10.6 - 151263 0.0046510 0.00000036 32.52 2798.0 109 0.2 - 151875 0.0046087 0.00000034 32.95 2836.1 110 1.0 - 153090 0.0035460 0.00000034 43.17 3718.0 143 1.3 - 153125 0.0044073 0.00000035 34.74 2992.2 115 0.3 - 153600 0.0025469 0.00000031 60.31 5195.2 199 8.5 - 153664 0.0032086 0.00000033 47.89 4125.7 158 2.3 - 154350 0.0033581 0.00000034 45.96 3961.0 151 1.3 - 155520 0.0032086 0.00000032 48.47 4179.7 158 10.7 - 156250 0.0034740 0.00000038 44.98 3880.1 146 0.6 - 156800 0.0030183 0.00000033 51.95 4482.8 168 6.2 - 157464 0.0039299 0.00000035 40.07 3458.8 129 3.0 - 157500 0.0032919 0.00000034 47.84 4130.1 154 4.5 - 158760 0.0036220 0.00000033 43.83 3786.3 140 4.2 - 160000 0.0029136 0.00000032 54.92 4746.8 174 6.6 - 161280 0.0027262 0.00000032 59.16 5117.0 186 11.8 - 162000 0.0031693 0.00000033 51.12 4423.0 160 9.5 - 163296 0.0035954 0.00000034 45.42 3932.5 141 6.6 - 163840 0.0028976 0.00000031 56.54 4897.2 175 4.7 - 164025 0.0049726 0.00000034 32.99 2857.2 102 1.2 - 164640 0.0034254 0.00000033 48.06 4164.5 148 3.5 - 165375 0.0048282 0.00000034 34.25 2968.9 105 0.9 - 165888 0.0031884 0.00000032 52.03 4510.8 159 9.8 - 166698 0.0044470 0.00000036 37.49 3251.3 114 0.7 - 168000 0.0032927 0.00000032 51.02 4428.2 154 9.4 - 168070 0.0057609 0.00000034 29.17 2532.1 88 8.9 - 168750 0.0035710 0.00000035 47.26 4102.9 142 2.0 - 169344 0.0035954 0.00000034 47.10 4090.5 141 7.3 - 170100 0.0037285 0.00000034 45.62 3963.6 136 6.1 - 171500 0.0039918 0.00000034 42.96 3735.2 127 1.5 - 172032 0.0029481 0.00000033 58.35 5074.4 172 6.2 - 172800 0.0032715 0.00000032 52.82 4595.0 155 14.6 - 172872 0.0043330 0.00000033 39.90 3470.9 117 2.1 - 174960 0.0040235 0.00000032 43.48 3786.8 126 7.4 - 175000 0.0035205 0.00000035 49.71 4328.8 144 2.7 - 175616 0.0036472 0.00000033 48.15 4194.5 139 3.4 - 176400 0.0035963 0.00000033 49.05 4274.4 141 8.8 - 177147 0.0051730 0.00000036 34.24 2985.2 98 0.5 - 178605 0.0054525 0.00000035 32.76 2857.4 93 0.7 - 179200 0.0033135 0.00000033 54.08 4719.0 153 8.4 - 180000 0.0036220 0.00000033 49.70 4337.9 140 10.5 - 180075 0.0058949 0.00000034 30.55 2666.6 86 0.4 - 181440 0.0038997 0.00000033 46.53 4063.9 130 13.0 - 182250 0.0039606 0.00000034 46.02 4020.7 128 2.1 - 183708 0.0047379 0.00000035 38.77 3390.2 107 3.1 - 183750 0.0038708 0.00000035 47.47 4150.7 131 0.8 - 184320 0.0034479 0.00000032 53.46 4675.5 147 11.8 - 185220 0.0046929 0.00000034 39.47 3453.2 108 2.8 - 186624 0.0040547 0.00000033 46.03 4029.6 125 10.2 - 187500 0.0040244 0.00000036 46.59 4080.5 126 2.4 - 188160 0.0038690 0.00000032 48.63 4260.6 131 6.9 - 189000 0.0037842 0.00000034 49.94 4377.2 134 8.5 - 190512 0.0046544 0.00000035 40.93 3589.6 109 5.4 - 192000 0.0035443 0.00000032 54.17 4753.7 143 11.0 - 192080 0.0046076 0.00000034 41.69 3658.4 110 2.3 - 193536 0.0037842 0.00000033 51.14 4491.0 134 11.7 - 194400 0.0040894 0.00000033 47.54 4175.9 124 13.2 - 194481 0.0061094 0.00000036 31.83 2796.4 83 0.4 - 196000 0.0039908 0.00000033 49.11 4317.1 127 5.1 - 196608 0.0033805 0.00000033 58.16 5113.6 150 5.6 - 196830 0.0051743 0.00000035 38.04 3345.0 98 1.4 - 196875 0.0061809 0.00000035 31.85 2800.9 82 1.2 - 197568 0.0045253 0.00000034 43.66 3840.2 112 6.2 - 198450 0.0046098 0.00000035 43.05 3788.0 110 2.6 - 200000 0.0038108 0.00000034 52.48 4621.0 133 6.8 - 200704 0.0039928 0.00000034 50.27 4427.2 127 6.0 - 201600 0.0039309 0.00000032 51.29 4518.6 129 16.2 - 201684 0.0067611 0.00000036 29.83 2628.3 75 0.7 - 202500 0.0040874 0.00000034 49.54 4366.6 124 6.5 - 204120 0.0050206 0.00000033 40.66 3585.7 101 7.0 - 204800 0.0039309 0.00000031 52.10 4596.3 129 8.1 - 205800 0.0039908 0.00000034 51.57 4551.1 127 3.2 - 207360 0.0041544 0.00000032 49.91 4407.8 122 15.8 - 209952 0.0048758 0.00000035 43.06 3806.5 104 7.9 - 210000 0.0044094 0.00000034 47.63 4210.1 115 8.0 - 211680 0.0046929 0.00000033 45.11 3990.0 108 9.3 - 212625 0.0064156 0.00000034 33.14 2932.7 79 1.8 - 214326 0.0055091 0.00000036 38.90 3444.8 92 1.1 - 214375 0.0068524 0.00000034 31.28 2770.2 74 0.4 - 215040 0.0040244 0.00000033 53.43 4732.7 126 11.1 - 216000 0.0041544 0.00000033 51.99 4606.8 122 16.5 - 216090 0.0053377 0.00000035 40.48 3587.1 95 0.7 - 217728 0.0047838 0.00000035 45.51 4035.3 106 12.6 - 218700 0.0049255 0.00000035 44.40 3938.1 103 6.7 - 218750 0.0052821 0.00000037 41.41 3673.2 96 0.8 - 219520 0.0048293 0.00000034 45.46 4032.8 105 4.9 - 220500 0.0049207 0.00000034 44.81 3977.0 103 5.3 - 221184 0.0039908 0.00000033 55.42 4920.1 127 11.4 - 222264 0.0056975 0.00000035 39.01 3464.5 89 3.7 - 224000 0.0044481 0.00000033 50.36 4475.2 114 10.5 - 225000 0.0047391 0.00000035 47.48 4220.7 107 7.7 - 225792 0.0046952 0.00000034 48.09 4276.3 108 11.8 - 226800 0.0051220 0.00000034 44.28 3938.9 99 14.7 - 229376 0.0042994 0.00000033 53.35 4750.2 118 5.6 - 229635 0.0072475 0.00000035 31.68 2821.4 70 1.1 - 230400 0.0051743 0.00000031 44.53 3966.0 98 20.4 - 230496 0.0055696 0.00000035 41.38 3686.2 91 3.3 - 231525 0.0079193 0.00000034 29.24 2605.0 64 1.3 - 233280 0.0056342 0.00000033 41.40 3691.5 90 15.8 - 234375 0.0080450 0.00000037 29.13 2598.4 63 0.6 - 235200 0.0051718 0.00000034 45.48 4057.4 98 10.5 - 235298 0.0088961 0.00000035 26.45 2359.8 57 9.5 - 236196 0.0071420 0.00000036 33.07 2951.6 71 3.5 - 236250 0.0055091 0.00000034 42.88 3827.4 92 3.4 - 238140 0.0066689 0.00000034 35.71 3189.1 76 4.9 - 240000 0.0048270 0.00000033 49.72 4443.2 105 12.5 - 240100 0.0057623 0.00000035 41.67 3723.7 88 2.0 - 241920 0.0048293 0.00000033 50.09 4479.4 105 19.4 - 243000 0.0051743 0.00000034 46.96 4201.0 98 10.7 - 244944 0.0060338 0.00000035 40.60 3633.7 84 9.0 - 245000 0.0053351 0.00000035 45.92 4110.6 95 3.8 - 245760 0.0045275 0.00000032 54.28 4860.1 112 10.5 - 246960 0.0065855 0.00000034 37.50 3358.9 77 7.3 - 248832 0.0053945 0.00000034 46.13 4134.1 94 14.5 - 250000 0.0053919 0.00000037 46.37 4157.1 94 5.8 - 250047 0.0083128 0.00000036 30.08 2696.9 61 0.6 - 250880 0.0052251 0.00000033 48.01 4306.1 97 7.8 - 252000 0.0051743 0.00000033 48.70 4369.3 98 16.7 - 252105 0.0107269 0.00000033 23.50 2108.6 48 1.8 - 253125 0.0080489 0.00000035 31.45 2822.4 63 1.9 - 254016 0.0059656 0.00000035 42.58 3822.5 85 12.7 - 255150 0.0061839 0.00000035 41.26 3705.4 82 3.9 - 256000 0.0047838 0.00000032 53.51 4807.1 106 11.3 - 257250 0.0062602 0.00000035 41.09 3692.7 81 0.9 - 258048 0.0052276 0.00000033 49.36 4437.0 97 14.3 - 259200 0.0053377 0.00000033 48.56 4366.5 95 23.0 - 259308 0.0072440 0.00000036 35.80 3218.9 70 2.9 - 262144 0.0057595 0.00000033 45.52 4096.4 88 0.0 - 262440 0.0071420 0.00000034 36.75 3307.5 71 5.1 - 262500 0.0059656 0.00000036 44.00 3960.6 85 2.5 - 263424 0.0057623 0.00000035 45.72 4116.0 88 3.3 - 264600 0.0058963 0.00000034 44.88 4041.8 86 6.0 - 268800 0.0053945 0.00000032 49.83 4493.6 94 7.5 - 268912 0.0081787 0.00000035 32.88 2965.2 62 1.7 - 270000 0.0051196 0.00000034 52.74 4757.7 99 9.6 - 272160 0.0064979 0.00000034 41.88 3780.9 78 9.3 - 273375 0.0084473 0.00000035 32.36 2922.4 60 2.1 - 274400 0.0063385 0.00000034 43.29 3910.5 80 3.3 - 275562 0.0079231 0.00000036 34.78 3142.7 64 1.6 - 275625 0.0087428 0.00000034 31.53 2848.8 58 1.6 - 276480 0.0053377 0.00000033 51.80 4681.7 95 11.1 - 277830 0.0076830 0.00000035 36.16 3269.7 66 1.7 - 279936 0.0066753 0.00000035 41.94 3794.1 76 9.2 - 280000 0.0059656 0.00000034 46.94 4246.5 85 6.1 - 281250 0.0063385 0.00000036 44.37 4016.0 80 2.9 - 282240 0.0059628 0.00000034 47.33 4285.2 85 8.1 - 283500 0.0064979 0.00000034 43.63 3951.3 78 7.7 - 285768 0.0136983 0.00000036 20.86 1890.5 37 1.5 - 286720 0.0055144 0.00000032 51.99 4713.1 92 4.7 - 288000 0.0058963 0.00000033 48.84 4429.1 86 13.4 - 288120 0.0103486 0.00000036 27.84 2524.7 49 48.9 - 290304 0.0063385 0.00000035 45.80 4155.7 80 10.9 - 291600 0.0135562 0.00000032 21.51 1952.5 38 0.1 - 294000 0.0068491 0.00000034 42.93 3898.8 74 4.2 - 294912 0.0097468 0.00000034 30.26 2748.9 52 2.9 - 295245 0.0101416 0.00000035 29.11 2645.1 50 1.1 - 296352 0.0071454 0.00000035 41.47 3769.4 71 5.1 - 297675 0.0095629 0.00000035 31.13 2830.1 53 2.1 - 300000 0.0064218 0.00000035 46.72 4249.9 79 5.3 - 300125 0.0103486 0.00000034 29.00 2638.4 49 0.6 - 301056 0.0061094 0.00000034 49.28 4484.2 83 4.4 - 302400 0.0067611 0.00000033 44.73 4071.5 75 15.4 - 302526 0.0090506 0.00000036 33.43 3042.9 56 0.7 - 303750 0.0065823 0.00000035 46.15 4202.2 77 4.5 - 306180 0.0085946 0.00000035 35.62 3246.1 59 5.5 - 306250 0.0079231 0.00000037 38.65 3522.1 64 1.2 - 307200 0.0056948 0.00000032 53.94 4916.7 89 8.3 - 307328 0.0117926 0.00000035 26.06 2375.4 43 3.4 - 308700 0.0079231 0.00000035 38.96 3552.5 64 4.8 - 311040 0.0069463 0.00000034 44.78 4085.2 73 13.7 - 312500 0.0075647 0.00000039 41.31 3770.3 67 2.3 - 313600 0.0149069 0.00000031 21.04 1920.5 34 0.5 - 314928 0.0088919 0.00000035 35.42 3234.4 57 6.8 - 315000 0.0078012 0.00000035 40.38 3687.5 65 7.5 - 317520 0.0087386 0.00000033 36.34 3320.4 58 7.8 - 320000 0.0117021 0.00000032 27.35 2500.4 44 3.2 - 321489 0.0110235 0.00000037 29.16 2667.7 46 0.9 - 322560 0.0070428 0.00000033 45.80 4190.5 72 12.4 - 324000 0.0073490 0.00000033 44.09 4035.3 69 14.2 - 324135 0.0109552 0.00000035 29.59 2708.2 47 0.8 - 326592 0.0084513 0.00000035 38.64 3539.2 60 11.1 - 327680 0.0063385 0.00000033 51.70 4735.9 80 4.8 - 328050 0.0088961 0.00000036 36.88 3378.5 57 4.6 - 328125 0.0110235 0.00000036 29.77 2727.1 46 1.0 - 329280 0.0083047 0.00000034 39.65 3633.7 62 4.1 - 330750 0.0084554 0.00000035 39.12 3586.1 60 3.8 - 331776 0.0136983 0.00000034 24.22 2221.0 37 0.8 - 333396 0.0097468 0.00000036 34.21 3137.8 52 3.5 - 336000 0.0079231 0.00000034 42.41 3892.6 64 9.1 - 336140 0.0144880 0.00000036 23.20 2129.7 35 12.9 - 337500 0.0076793 0.00000035 43.95 4035.5 66 7.5 - 338688 0.0080489 0.00000035 42.08 3864.9 63 9.9 - 340200 0.0087229 0.00000035 39.00 3583.4 59 10.6 - 343000 0.0084409 0.00000035 40.64 3736.0 61 2.6 - 344064 0.0074535 0.00000034 46.16 4245.1 68 5.8 - 345600 0.0074535 0.00000033 46.37 4265.5 68 18.1 - 345744 0.0163574 0.00000036 21.14 1944.5 31 3.3 - 349920 0.0093617 0.00000034 37.38 3441.9 55 11.1 - 350000 0.0083128 0.00000036 42.10 3877.1 61 5.2 - 351232 0.0079269 0.00000035 44.31 4081.3 64 4.4 - 352800 0.0144810 0.00000032 24.36 2244.9 35 3.5 - 352947 0.0166016 0.00000037 21.26 1959.0 31 12.0 - 354294 0.0110288 0.00000037 32.12 2961.0 46 1.7 - 354375 0.0122652 0.00000035 28.89 2663.2 42 3.1 - 357210 0.0109552 0.00000035 32.61 3007.4 47 2.6 - 358400 0.0077975 0.00000032 45.96 4240.4 65 8.6 - 360000 0.0158463 0.00000034 22.72 2096.6 32 0.4 - 360150 0.0097515 0.00000036 36.93 3408.6 52 1.3 - 362880 0.0087428 0.00000034 41.51 3832.9 58 16.3 - 364500 0.0092196 0.00000035 39.54 3652.2 55 9.5 - 367416 0.0112684 0.00000035 32.61 3013.9 45 5.8 - 367500 0.0092241 0.00000035 39.84 3682.8 55 3.2 - 368640 0.0081748 0.00000033 45.09 4169.4 62 12.9 - 370440 0.0109552 0.00000034 33.81 3127.6 47 5.0 - 373248 0.0143094 0.00000034 26.08 2414.1 36 4.3 - 375000 0.0090289 0.00000037 41.53 3845.3 57 3.8 - 376320 0.0087428 0.00000034 43.04 3986.2 58 6.2 - 378000 0.0093859 0.00000034 40.27 3730.9 54 15.1 - 381024 0.0103486 0.00000035 36.82 3413.0 49 8.7 - 382725 0.0133378 0.00000035 28.69 2660.9 38 3.3 - 384000 0.0087270 0.00000033 44.00 4081.3 59 11.1 - 384160 0.0102930 0.00000035 37.32 3461.9 50 2.7 - 385875 0.0133378 0.00000034 28.93 2684.5 38 1.9 - 387072 0.0084409 0.00000034 45.86 4256.0 61 14.0 - 388800 0.0092196 0.00000034 42.17 3915.3 55 20.5 - 388962 0.0117869 0.00000036 33.00 3063.9 43 1.6 - 390625 0.0137049 0.00000040 28.50 2647.2 37 0.9 - 392000 0.0095675 0.00000034 40.97 3806.4 53 7.7 - 393216 0.0083128 0.00000034 47.30 4395.6 61 5.9 - 393660 0.0116966 0.00000035 33.66 3127.8 44 6.3 - 393750 0.0101514 0.00000036 38.79 3604.7 50 4.7 - 395136 0.0099475 0.00000035 39.72 3692.6 51 8.9 - 396900 0.0266884 0.00000033 14.87 1382.9 19 0.8 - 400000 0.0095629 0.00000035 41.83 3892.0 53 8.8 - 401408 0.0156028 0.00000034 25.73 2394.5 33 4.4 - 403200 0.0097103 0.00000033 41.52 3866.0 53 20.2 - 403368 0.0190701 0.00000036 21.15 1969.4 27 14.7 - 405000 0.0193594 0.00000035 20.92 1948.4 27 2.2 - 408240 0.0117869 0.00000033 34.64 3227.8 43 12.9 - 409600 0.0147042 0.00000031 27.86 2596.7 35 0.7 - 411600 0.0112684 0.00000035 36.53 3406.3 45 5.3 - 413343 0.0156102 0.00000037 26.48 2470.1 33 1.3 - 414720 0.0095675 0.00000033 43.35 4044.6 53 19.0 - 416745 0.0151439 0.00000036 27.52 2568.7 34 1.4 - 419904 0.0209082 0.00000034 20.08 1875.7 25 0.4 - 420000 0.0105693 0.00000035 39.74 3711.5 48 8.3 - 420175 0.0158386 0.00000035 26.53 2477.8 32 0.8 - 421875 0.0131961 0.00000037 31.97 2987.0 39 2.8 - 423360 0.0112684 0.00000034 37.57 3511.2 45 13.6 - 425250 0.0117926 0.00000036 36.06 3371.3 43 7.1 - 428652 0.0144810 0.00000036 29.60 2769.1 35 5.5 - 428750 0.0123619 0.00000036 34.68 3244.6 41 1.9 - 430080 0.0101367 0.00000034 42.43 3970.0 50 9.0 - 432000 0.0105642 0.00000034 40.89 3827.7 48 22.9 - 432180 0.0135498 0.00000035 31.90 2985.6 38 4.3 - 435456 0.0109552 0.00000035 39.75 3722.9 47 17.3 - 437400 0.0120733 0.00000035 36.23 3394.4 42 12.8 - 437500 0.0122535 0.00000038 35.70 3345.3 42 3.6 - 439040 0.0114366 0.00000034 38.39 3597.8 45 5.9 - 441000 0.0119742 0.00000035 36.83 3452.8 43 9.4 - 442368 0.0103486 0.00000034 42.75 4008.6 49 14.3 - 444528 0.0133442 0.00000036 33.31 3125.0 38 8.5 - 448000 0.0105642 0.00000033 42.41 3980.6 48 11.4 - 450000 0.0112630 0.00000035 39.95 3751.6 45 14.4 - 451584 0.0211182 0.00000035 21.38 2008.4 24 0.9 - 453600 0.0120733 0.00000035 37.57 3529.9 42 21.2 - 453789 0.0181100 0.00000038 25.06 2354.3 28 0.8 - 455625 0.0160828 0.00000035 28.33 2662.7 32 3.8 - 458752 0.0111933 0.00000034 40.98 3854.0 46 6.7 - 459270 0.0147042 0.00000036 31.23 2937.4 35 4.1 - 459375 0.0163574 0.00000036 28.08 2641.2 31 1.2 - 460800 0.0174855 0.00000032 26.35 2479.0 29 5.4 - 460992 0.0126770 0.00000035 36.36 3420.9 40 5.5 - 463050 0.0133378 0.00000036 34.72 3267.0 38 4.9 - 466560 0.0122593 0.00000035 38.06 3583.4 42 20.3 - 468750 0.0132086 0.00000039 35.49 3342.7 39 2.5 - 470400 0.0120675 0.00000035 38.98 3672.7 42 10.9 - 470596 0.0270996 0.00000036 17.37 1636.2 19 1.0 - 472392 0.0230380 0.00000036 20.50 1932.5 22 2.7 - 472500 0.0119742 0.00000035 39.46 3719.1 43 12.2 - 476280 0.0155954 0.00000034 30.54 2880.1 33 8.6 - 480000 0.0116966 0.00000034 41.04 3872.5 44 13.7 - 480200 0.0253418 0.00000035 18.95 1788.1 20 2.6 - 483840 0.0122593 0.00000034 39.47 3726.5 42 22.4 - 486000 0.0125584 0.00000034 38.70 3655.3 41 20.2 - 489888 0.0155954 0.00000036 31.41 2968.8 33 14.0 - 490000 0.0249023 0.00000035 19.68 1859.7 21 0.1 - 491520 0.0116966 0.00000033 42.02 3972.6 44 9.6 - 492075 0.0190701 0.00000036 25.80 2439.5 27 3.8 - 493920 0.0140856 0.00000035 35.07 3316.1 36 10.2 - 496125 0.0181013 0.00000035 27.41 2592.9 28 3.7 - 497664 0.0120733 0.00000034 41.22 3900.4 42 19.0 - 500000 0.0230380 0.00000037 21.70 2054.4 22 4.8 - 500094 0.0174855 0.00000037 28.60 2707.3 29 2.4 - 501760 0.0128662 0.00000034 39.00 3692.5 40 8.0 - 504000 0.0130021 0.00000034 38.76 3671.5 39 24.3 - 504210 0.0237482 0.00000036 21.23 2011.0 22 20.3 - 506250 0.0136983 0.00000036 36.96 3501.6 37 7.6 - 508032 0.0233931 0.00000035 21.72 2058.2 22 5.6 - 510300 0.0147112 0.00000036 34.69 3288.6 35 14.4 - 512000 0.0123619 0.00000033 41.42 3927.6 41 12.8 - 514500 0.0144810 0.00000036 35.53 3370.4 35 4.1 - 516096 0.0126709 0.00000036 40.73 3864.8 40 16.6 - 518400 0.0234042 0.00000031 22.15 2102.4 22 0.8 - 518616 0.0160904 0.00000036 32.23 3059.5 32 5.7 - 524288 0.0187807 0.00000034 27.92 2652.0 27 0.0 - 524880 0.0158463 0.00000034 33.12 3147.0 32 15.5 - 525000 0.0133442 0.00000036 39.34 3738.0 38 6.0 - 526848 0.0133378 0.00000035 39.50 3753.9 38 7.5 - 529200 0.0155954 0.00000035 33.93 3225.9 33 18.0 - 531441 0.0223760 0.00000037 23.75 2258.6 23 1.4 - 535815 0.0208984 0.00000036 25.64 2439.7 25 2.2 - 537600 0.0137115 0.00000033 39.21 3731.9 37 16.4 - 537824 0.0163495 0.00000036 32.90 3131.1 31 3.8 - 540000 0.0153587 0.00000034 35.16 3347.6 33 22.6 - 540225 0.0211182 0.00000035 25.58 2435.7 24 2.5 - 544320 0.0160828 0.00000034 33.84 3224.4 32 25.1 - 546750 0.0169108 0.00000036 32.33 3081.3 30 8.5 - 546875 0.0206055 0.00000039 26.54 2529.4 25 1.4 - 548800 0.0147042 0.00000035 37.32 3557.9 35 10.3 - 551124 0.0181013 0.00000037 30.45 2903.4 28 8.2 - 551250 0.0153735 0.00000035 35.86 3419.4 33 6.6 - 552960 0.0133378 0.00000033 41.46 3954.4 38 23.6 - 555660 0.0220363 0.00000036 25.22 2406.1 23 8.1 - 559872 0.0168536 0.00000035 33.22 3171.6 31 22.3 - 560000 0.0155954 0.00000035 35.91 3428.3 33 14.1 - 562500 0.0326843 0.00000035 17.21 1643.7 16 1.0 - 564480 0.0149213 0.00000034 37.83 3614.1 34 20.1 - 567000 0.0158386 0.00000035 35.80 3421.1 32 19.3 - 571536 0.0317078 0.00000035 18.03 1723.6 16 0.1 - 573440 0.0156102 0.00000033 36.73 3513.6 33 10.2 - 576000 0.0149069 0.00000034 38.64 3697.0 34 29.2 - 576240 0.0205859 0.00000035 27.99 2678.3 25 4.4 - 580608 0.0153587 0.00000035 37.80 3619.1 33 24.3 - 583200 0.0281576 0.00000032 20.71 1983.6 18 6.6 - 583443 0.0253418 0.00000039 23.02 2204.9 20 1.5 - 588000 0.0166173 0.00000035 35.38 3390.8 31 10.3 - 588245 0.0298139 0.00000037 19.73 1890.8 17 23.1 - 589824 0.0230380 0.00000034 25.60 2454.0 22 1.1 - 590490 0.0203125 0.00000036 29.07 2786.6 25 1.6 - 590625 0.0206055 0.00000036 28.66 2747.7 25 2.9 - 592704 0.0186593 0.00000036 31.76 3045.7 28 11.7 - 595350 0.0177465 0.00000036 33.55 3217.8 29 4.6 - 600000 0.0163495 0.00000035 36.70 3522.0 31 15.4 - 600250 0.0177465 0.00000036 33.82 3246.3 29 2.5 - 602112 0.0153735 0.00000036 39.17 3759.8 33 10.1 - 604800 0.0160980 0.00000034 37.57 3607.8 32 24.2 - 605052 0.0230602 0.00000036 26.24 2519.7 22 4.6 - 607500 0.0169108 0.00000035 35.92 3450.9 30 10.8 - 612360 0.0198130 0.00000034 30.91 2970.8 26 6.7 - 612500 0.0180159 0.00000037 34.00 3267.9 29 5.0 - 614400 0.0149069 0.00000033 41.22 3962.6 34 17.7 - 614656 0.0307617 0.00000035 19.98 1921.1 17 0.9 - 617400 0.0174939 0.00000036 35.29 3394.4 29 8.9 - 622080 0.0158386 0.00000034 39.28 3779.7 32 20.6 - 625000 0.0183977 0.00000040 33.97 3270.4 28 5.9 - 627200 0.0241350 0.00000033 25.99 2502.4 21 8.6 - 629856 0.0202930 0.00000035 31.04 2989.7 25 11.2 - 630000 0.0177465 0.00000035 35.50 3419.5 29 17.5 - 635040 0.0194937 0.00000034 32.58 3139.8 26 11.7 - 637875 0.0233931 0.00000035 27.27 2629.0 22 3.2 - 640000 0.0267013 0.00000033 23.97 2311.5 19 1.0 - 642978 0.0233931 0.00000037 27.49 2651.6 22 1.7 - 643125 0.0241350 0.00000035 26.65 2570.7 21 1.7 - 645120 0.0166173 0.00000034 38.82 3746.2 31 20.8 - 648000 0.0194937 0.00000033 33.24 3208.7 26 26.0 - 648270 0.0311926 0.00000037 20.78 2006.2 17 126.6 - 653184 0.0183803 0.00000036 35.54 3432.4 28 17.6 - 655360 0.0163495 0.00000033 40.08 3872.5 31 10.9 - 656100 0.0429281 0.00000035 15.28 1476.7 12 1.4 - 656250 0.0205859 0.00000038 31.88 3080.1 25 3.9 - 658560 0.0177633 0.00000035 37.07 3583.0 29 10.0 - 661500 0.0205859 0.00000036 32.13 3106.6 25 10.1 - 663552 0.0257568 0.00000034 25.76 2491.2 20 8.3 - 666792 0.0194937 0.00000036 34.21 3308.9 26 5.9 - 672000 0.0174154 0.00000034 38.59 3734.8 30 21.6 - 672280 0.0321655 0.00000037 20.90 2023.0 16 43.9 - 675000 0.0202734 0.00000036 33.29 3223.7 25 12.8 - 677376 0.0193685 0.00000036 34.97 3387.1 27 17.3 - 680400 0.0211385 0.00000034 32.19 3118.3 24 20.5 - 686000 0.0205859 0.00000036 33.32 3230.4 25 9.9 - 688128 0.0171549 0.00000035 40.11 3889.4 30 12.8 - 688905 0.0285916 0.00000036 24.09 2336.5 18 1.1 - 691200 0.0174939 0.00000034 39.51 3832.3 29 30.0 - 691488 0.0337891 0.00000038 20.46 1985.0 15 11.1 - 694575 0.0286187 0.00000036 24.27 2354.9 18 2.8 - 699840 0.0220576 0.00000033 31.73 3080.2 23 19.7 - 700000 0.0202734 0.00000036 34.53 3352.1 25 12.8 - 702464 0.0190611 0.00000036 36.85 3578.8 27 10.4 - 703125 0.0298139 0.00000038 23.58 2290.4 17 3.3 - 705600 0.0422363 0.00000030 16.71 1622.9 12 0.8 - 705894 0.0343099 0.00000038 20.57 1998.7 15 92.9 - 708588 0.0271382 0.00000037 26.11 2537.2 19 6.4 - 708750 0.0233931 0.00000036 30.30 2944.1 22 7.0 - 714420 0.0270868 0.00000035 26.38 2564.5 19 6.7 - 716800 0.0197942 0.00000033 36.21 3521.9 26 19.6 - 720000 0.0307330 0.00000034 23.43 2279.2 17 8.5 - 720300 0.0230380 0.00000036 31.27 3041.9 22 5.6 - 725760 0.0205859 0.00000034 35.26 3431.9 25 25.1 - 729000 0.0230554 0.00000036 31.62 3079.0 23 15.0 - 734832 0.0245071 0.00000036 29.98 2921.5 21 12.8 - 735000 0.0227157 0.00000036 32.36 3152.7 23 8.1 - 737280 0.0202734 0.00000034 36.37 3544.3 25 22.5 - 740880 0.0248791 0.00000034 29.78 2903.3 21 11.4 - 746496 0.0353841 0.00000034 21.10 2058.0 15 1.4 - 750000 0.0234153 0.00000037 32.03 3125.6 22 13.5 - 750141 0.0338216 0.00000038 22.18 2164.3 15 1.2 - 752640 0.0211385 0.00000034 35.61 3475.3 24 14.8 - 756000 0.0233931 0.00000035 32.32 3155.5 22 24.9 - 756315 0.0401893 0.00000037 18.82 1837.5 13 29.3 - 759375 0.0298139 0.00000037 25.47 2487.8 17 3.9 - 762048 0.0249023 0.00000036 30.60 2989.7 21 18.4 - 765450 0.0265137 0.00000037 28.87 2821.5 20 6.9 - 765625 0.0307617 0.00000038 24.89 2432.4 17 2.0 - 768000 0.0205859 0.00000034 37.31 3646.9 25 24.9 - 768320 0.0261475 0.00000035 29.38 2872.5 20 10.6 - 771750 0.0241583 0.00000036 31.95 3123.9 21 5.9 - 774144 0.0217692 0.00000035 35.56 3478.3 24 23.6 - 777600 0.0211182 0.00000035 36.82 3602.7 24 33.1 - 777924 0.0506836 0.00000037 15.35 1501.8 10 1.6 - 781250 0.0261230 0.00000042 29.91 2927.2 20 3.9 - 784000 0.0233931 0.00000035 33.51 3281.1 22 18.5 - 786432 0.0233931 0.00000035 33.62 3292.0 22 13.8 - 787320 0.0275236 0.00000035 28.61 2801.4 19 8.6 - 787500 0.0241583 0.00000037 32.60 3192.4 21 13.8 - 790272 0.0230380 0.00000037 34.30 3360.3 22 18.3 - 793800 0.0482067 0.00000034 16.47 1613.6 11 5.4 - 800000 0.0233931 0.00000035 34.20 3353.1 22 21.1 - 802816 0.0326538 0.00000035 24.59 2411.2 16 1.6 - 806400 0.0227157 0.00000034 35.50 3482.7 23 35.7 - 806736 0.0353516 0.00000037 22.82 2238.9 15 7.4 - 810000 0.0390249 0.00000034 20.76 2036.9 13 0.2 - 816480 0.0266756 0.00000034 30.61 3005.5 19 18.8 - 819200 0.0331421 0.00000033 24.72 2427.8 16 10.2 - 820125 0.0348307 0.00000036 23.55 2312.9 15 4.0 - 823200 0.0253418 0.00000036 32.48 3191.7 20 14.0 - 823543 0.0563151 0.00000038 14.62 1436.9 9 5.8 - 826686 0.0348307 0.00000038 23.73 2332.7 15 2.5 - 826875 0.0326538 0.00000036 25.32 2488.9 16 3.9 - 829440 0.0223972 0.00000034 37.03 3640.7 23 29.9 - 833490 0.0343099 0.00000036 24.29 2389.1 15 2.4 - 839808 0.0379116 0.00000038 22.15 2179.7 14 11.1 - 840000 0.0261475 0.00000035 32.13 3161.2 20 25.0 - 840350 0.0311926 0.00000037 26.94 2651.1 17 3.5 - 843750 0.0279091 0.00000037 30.23 2975.8 19 7.8 - 846720 0.0257324 0.00000035 32.90 3239.7 20 23.3 - 850500 0.0285916 0.00000036 29.75 2929.7 18 17.0 - 857304 0.0321655 0.00000037 26.65 2626.6 16 9.2 - 857500 0.0311926 0.00000037 27.49 2709.2 17 7.8 - 860160 0.0257324 0.00000035 33.43 3294.9 20 22.0 - 864000 0.0266756 0.00000035 32.39 3193.7 19 39.7 - 864360 0.0321655 0.00000035 26.87 2649.8 16 7.8 - 870912 0.0271125 0.00000036 32.12 3169.2 19 29.5 - 874800 0.0316772 0.00000034 27.62 2725.5 16 28.9 - 875000 0.0302734 0.00000039 28.90 2852.6 17 10.1 - 878080 0.0261475 0.00000035 33.58 3315.2 20 15.9 - 882000 0.0298139 0.00000036 29.58 2921.4 17 24.6 - 884736 0.0257568 0.00000036 34.35 3392.9 20 26.1 - 885735 0.0422770 0.00000036 20.95 2069.6 12 1.6 - 889056 0.0286187 0.00000036 31.07 3069.6 18 15.6 - 893025 0.0384347 0.00000036 23.23 2296.6 14 4.5 - 896000 0.0248791 0.00000034 36.01 3560.6 21 27.2 - 900000 0.0274979 0.00000036 32.73 3236.9 19 28.3 - 900375 0.0395883 0.00000035 22.74 2249.3 13 2.3 - 903168 0.0379116 0.00000035 23.82 2356.6 14 13.3 - 907200 0.0237482 0.00000034 38.20 3780.2 22 39.9 - 907578 0.0454915 0.00000038 19.95 1974.3 12 46.0 - 911250 0.0311926 0.00000036 29.21 2891.8 17 9.5 - 917504 0.0245071 0.00000036 37.44 3707.8 21 15.6 - 918540 0.0367606 0.00000036 24.99 2474.8 14 9.5 - 918750 0.0316772 0.00000037 29.00 2872.7 16 5.2 - 921600 0.0396259 0.00000032 23.26 2304.1 13 1.8 - 921984 0.0281576 0.00000037 32.74 3244.0 18 13.6 - 926100 0.0321655 0.00000037 28.79 2853.4 16 13.7 - 933120 0.0274979 0.00000036 33.93 3364.9 19 33.0 - 937500 0.0311926 0.00000040 30.06 2981.2 17 9.6 - 940800 0.0274979 0.00000035 34.21 3394.6 19 27.2 - 941192 0.0530762 0.00000038 17.73 1759.5 10 3.2 - 944784 0.0514648 0.00000036 18.36 1822.0 10 0.1 - 945000 0.0302734 0.00000036 31.22 3098.1 17 20.2 - 952560 0.0353841 0.00000035 26.92 2673.4 15 18.2 - 960000 0.0281847 0.00000035 34.06 3384.4 18 31.9 - 960400 0.0496271 0.00000035 19.35 1923.0 11 10.5 - 964467 0.0522461 0.00000039 18.46 1834.9 10 1.7 - 967680 0.0274979 0.00000034 35.19 3498.7 19 35.9 - 972000 0.0307330 0.00000033 31.63 3145.4 17 34.6 - 972405 0.0506836 0.00000038 19.19 1908.1 10 1.6 - 979776 0.0336304 0.00000036 29.13 2899.1 16 27.8 - 980000 0.0460760 0.00000036 21.27 2116.5 11 10.6 - 983040 0.0274979 0.00000034 35.75 3558.3 19 21.6 - 984150 0.0363932 0.00000037 27.04 2691.8 15 9.1 - 984375 0.0435384 0.00000037 22.61 2250.6 12 5.2 - 987840 0.0353516 0.00000035 27.94 2782.3 15 24.4 - 992250 0.0353516 0.00000037 28.07 2795.6 15 9.2 - 995328 0.0238095 0.00000035 41.80 4164.7 21 32.8 - 1000000 0.0474964 0.00000038 21.05 2098.2 11 0.9 - 1000188 0.0435384 0.00000037 22.97 2289.4 12 9.7 - 1003520 0.0294596 0.00000034 34.06 3395.6 18 19.5 - 1008000 0.0303022 0.00000035 33.26 3317.0 17 45.5 - 1008420 0.0496715 0.00000037 20.30 2024.5 11 109.5 - 1012500 0.0326538 0.00000036 31.01 3092.9 16 19.5 - 1016064 0.0545898 0.00000035 18.61 1857.0 10 1.4 - 1020600 0.0353516 0.00000034 28.87 2881.4 15 22.1 - 1024000 0.0298139 0.00000034 34.35 3428.8 17 29.9 - 1029000 0.0379116 0.00000036 27.14 2710.5 14 11.2 - 1032192 0.0298426 0.00000035 34.59 3454.9 17 31.9 - 1036800 0.0422363 0.00000033 24.55 2452.8 12 13.2 - 1037232 0.0378767 0.00000037 27.38 2736.3 14 17.2 - 1048576 0.0468306 0.00000035 22.39 2239.1 11 0.0 - 1049760 0.0379116 0.00000035 27.69 2769.2 14 24.2 - 1050000 0.0362374 0.00000037 28.98 2897.8 14 22.5 - 1053696 0.0307330 0.00000036 34.29 3429.8 17 18.8 - 1058400 0.0384347 0.00000035 27.54 2755.6 14 32.4 - 1058841 0.0580512 0.00000038 18.24 1825.3 9 23.8 - 1062882 0.0538086 0.00000039 19.75 1977.2 10 3.5 - 1063125 0.0467862 0.00000036 22.72 2274.6 11 6.3 - 1071630 0.0515137 0.00000037 20.80 2083.5 10 3.7 - 1071875 0.0467862 0.00000037 22.91 2294.6 11 2.9 - 1075200 0.0316772 0.00000034 33.94 3400.4 16 32.7 - 1075648 0.0435384 0.00000036 24.71 2475.1 12 18.7 - 1080000 0.0348307 0.00000035 31.01 3107.3 15 46.1 - 1080450 0.0395883 0.00000037 27.29 2735.1 13 8.6 - 1088640 0.0337891 0.00000036 32.22 3230.6 15 34.9 - 1093500 0.0402269 0.00000036 27.18 2726.6 13 23.3 - 1093750 0.0419922 0.00000041 26.05 2612.6 13 6.2 - 1097600 0.0367606 0.00000036 29.86 2995.6 14 26.9 - 1102248 0.0413912 0.00000037 26.63 2672.6 13 14.1 - 1102500 0.0844727 0.00000034 13.05 1309.9 6 2.8 - 1105920 0.0311926 0.00000035 35.45 3559.1 17 35.5 - 1111320 0.0413912 0.00000035 26.85 2696.2 13 13.7 - 1119744 0.0331726 0.00000037 33.76 3391.5 16 37.5 - 1120000 0.0348633 0.00000036 32.13 3227.8 15 34.1 - 1125000 0.0624457 0.00000035 18.02 1810.7 9 6.9 - 1128960 0.0353516 0.00000035 31.94 3210.5 15 33.7 - 1134000 0.0407903 0.00000034 27.80 2795.8 13 41.7 - 1143072 0.0625000 0.00000037 18.29 1840.3 8 14.7 - 1146880 0.0316772 0.00000034 36.21 3643.9 16 21.4 - 1148175 0.0538086 0.00000036 21.34 2147.8 10 6.3 - 1152000 0.0337891 0.00000034 34.09 3432.5 15 52.4 - 1152480 0.0545898 0.00000036 21.11 2125.6 10 517.3 - 1157625 0.0514648 0.00000036 22.49 2265.4 10 5.4 - 1161216 0.0389874 0.00000036 29.78 3000.4 13 38.8 - 1166400 0.0615234 0.00000033 18.96 1910.4 9 1.3 - 1166886 0.0581597 0.00000038 20.06 2021.8 9 3.7 - 1171875 0.0538086 0.00000040 21.78 2195.3 10 3.8 - 1176000 0.0419922 0.00000036 28.01 2823.7 13 32.6 - 1176490 0.0633545 0.00000037 18.57 1872.4 8 15.1 - 1179648 0.0489169 0.00000037 24.12 2432.0 11 15.8 - 1180980 0.0496271 0.00000036 23.80 2400.1 11 13.8 - 1181250 0.0413912 0.00000037 28.54 2878.4 13 12.6 - 1185408 0.0384615 0.00000037 30.82 3109.3 13 31.8 - 1190700 0.0441895 0.00000037 26.95 2719.2 12 23.9 - 1200000 0.0384347 0.00000037 31.22 3152.6 14 36.1 - 1200500 0.0454915 0.00000037 26.39 2664.7 12 12.1 - 1204224 0.0367606 0.00000036 32.76 3308.6 14 23.2 - 1209600 0.0395883 0.00000035 30.55 3086.9 13 58.0 - 1210104 0.0489169 0.00000037 24.74 2499.4 11 13.8 - 1215000 0.0413912 0.00000034 29.35 2966.6 13 32.4 - 1224720 0.0468750 0.00000035 26.13 2642.0 11 29.5 - 1225000 0.0467862 0.00000038 26.18 2647.7 11 15.9 - 1228800 0.0343099 0.00000034 35.81 3622.4 15 37.4 - 1229312 0.0571832 0.00000037 21.50 2174.4 9 18.5 - 1234800 0.0474964 0.00000036 26.00 2630.4 11 36.8 - 1240029 0.0757533 0.00000038 16.37 1656.7 7 2.5 - 1244160 0.0379464 0.00000035 32.79 3319.2 14 45.4 - 1250000 0.0454545 0.00000040 27.50 2784.9 11 25.1 - 1250235 0.0779855 0.00000037 16.03 1623.5 7 2.4 - 1254400 0.0653076 0.00000033 19.21 1945.6 8 2.5 - 1259712 0.0507812 0.00000036 24.81 2513.5 10 39.0 - 1260000 0.0467862 0.00000036 26.93 2728.8 11 45.8 - 1260525 0.0633545 0.00000037 19.90 2016.1 8 3.3 - 1265625 0.0606554 0.00000037 20.87 2114.9 9 7.6 - 1270080 0.0474964 0.00000035 26.74 2711.0 11 39.1 - 1275750 0.0489169 0.00000037 26.08 2644.9 11 14.8 - 1280000 0.0514648 0.00000033 24.87 2522.9 10 16.0 - 1285956 0.0935872 0.00000038 13.74 1394.3 6 2.8 - 1286250 0.0474964 0.00000037 27.08 2748.0 11 8.1 - 1290240 0.0395883 0.00000035 32.59 3307.9 13 43.1 - 1296000 0.0401893 0.00000035 32.25 3274.0 13 62.4 - 1296540 0.0555556 0.00000036 23.34 2369.5 9 13.8 - 1306368 0.0460760 0.00000037 28.35 2880.2 11 46.4 - 1310720 0.0407903 0.00000034 32.13 3265.0 13 25.4 - 1312200 0.0802176 0.00000035 16.36 1662.3 7 8.7 - 1312500 0.0496271 0.00000039 26.45 2687.6 11 17.1 - 1317120 0.0467862 0.00000036 28.15 2861.5 11 26.8 - 1323000 0.0474964 0.00000036 27.85 2832.2 11 30.8 - 1327104 0.0580512 0.00000035 22.86 2324.9 9 2.8 - 1333584 0.0538086 0.00000036 24.78 2521.4 10 29.2 - 1344000 0.0428874 0.00000035 31.34 3189.9 12 47.1 - 1344560 0.0692139 0.00000036 19.43 1977.5 8 159.4 - 1350000 0.0475852 0.00000037 28.37 2888.7 11 47.9 - 1354752 0.0441895 0.00000036 30.66 3122.4 12 43.5 - 1360800 0.0553711 0.00000036 24.58 2503.8 10 55.2 - 1361367 0.0909831 0.00000038 14.96 1524.5 6 2.8 - 1366875 0.0768694 0.00000036 17.78 1812.2 7 9.3 - 1372000 0.0530273 0.00000037 25.87 2637.5 10 30.0 - 1376256 0.0422363 0.00000036 32.58 3322.4 12 27.9 - 1377810 0.0779855 0.00000038 17.67 1801.6 7 5.6 - 1378125 0.0701904 0.00000037 19.63 2002.1 8 7.8 - 1382400 0.0435384 0.00000035 31.75 3238.4 12 67.5 - 1382976 0.0701904 0.00000039 19.70 2009.7 8 28.4 - 1389150 0.0580512 0.00000037 23.93 2441.5 9 13.5 - 1399680 0.0489169 0.00000037 28.61 2921.0 11 48.5 - 1400000 0.0514648 0.00000038 27.20 2777.0 10 42.4 - 1404928 0.0460760 0.00000037 30.49 3113.5 11 28.0 - 1406250 0.0572917 0.00000040 24.55 2506.5 9 15.2 - 1411200 0.0625000 0.00000035 22.58 2306.3 8 21.4 - 1411788 0.0791016 0.00000036 17.85 1823.1 7 19.1 - 1417176 0.0653076 0.00000038 21.70 2217.2 8 19.6 - 1417500 0.0563151 0.00000036 25.17 2571.8 9 35.1 - 1428840 0.0571832 0.00000036 24.99 2554.5 9 20.1 - 1433600 0.0461648 0.00000034 31.05 3175.5 11 44.9 - 1440000 0.0682373 0.00000035 21.10 2158.6 8 1.9 - 1440600 0.0597873 0.00000036 24.10 2464.7 9 18.2 - 1451520 0.0482067 0.00000036 30.11 3081.7 11 55.8 - 1458000 0.0555556 0.00000034 26.24 2686.8 9 57.4 - 1469664 0.0615234 0.00000037 23.89 2447.0 9 36.4 - 1470000 0.0633545 0.00000037 23.20 2376.8 8 34.2 - 1474560 0.0467862 0.00000034 31.52 3229.2 11 49.9 - 1476225 0.0844727 0.00000036 17.48 1790.7 6 8.4 - 1481760 0.0606554 0.00000035 24.43 2503.9 9 33.3 - 1488375 0.0779855 0.00000036 19.09 1956.7 7 8.8 - 1492992 0.0662842 0.00000037 22.52 2309.8 8 21.0 - 1500000 0.0563151 0.00000038 26.64 2732.4 9 37.1 - 1500282 0.0911458 0.00000038 16.46 1688.6 6 5.7 - 1500625 0.0802176 0.00000037 18.71 1919.1 7 4.6 - 1505280 0.0496271 0.00000035 30.33 3112.3 11 32.2 - 1512000 0.0580512 0.00000034 26.05 2673.4 9 75.1 - 1512630 0.0779855 0.00000038 19.40 1990.9 7 169.3 - 1518750 0.0662842 0.00000037 22.91 2352.5 8 19.2 - 1524096 0.0530273 0.00000038 28.74 2951.7 10 49.8 - 1530900 0.0701904 0.00000037 21.81 2240.6 8 36.5 - 1531250 0.0724051 0.00000040 21.15 2172.6 7 10.3 - 1536000 0.0497159 0.00000034 30.90 3174.6 11 55.0 - 1536640 0.0563151 0.00000037 27.29 2803.9 9 29.7 - 1543500 0.0672607 0.00000037 22.95 2358.8 8 32.1 - 1548288 0.0531250 0.00000036 29.14 2996.4 10 54.4 - 1555200 0.0538086 0.00000035 28.90 2972.4 10 83.8 - 1555848 0.0974935 0.00000038 15.96 1641.3 6 10.6 - 1562500 0.0948893 0.00000040 16.47 1694.0 6 2.9 - 1568000 0.0563151 0.00000036 27.84 2865.1 9 52.1 - 1572864 0.0522461 0.00000036 30.10 3098.5 10 33.0 - 1574640 0.0664062 0.00000036 23.71 2440.8 8 40.1 - 1575000 0.0653076 0.00000037 24.12 2482.4 8 43.1 - 1580544 0.0546875 0.00000037 28.90 2975.7 10 51.5 - 1587600 0.0922852 0.00000034 17.20 1771.8 6 0.2 - 1594323 0.1125000 0.00000038 14.17 1460.0 5 3.5 - 1600000 0.0643311 0.00000037 24.87 2562.9 8 55.8 - 1605632 0.0746373 0.00000038 21.51 2217.4 7 22.8 - 1607445 0.1169922 0.00000037 13.74 1416.3 5 3.9 - 1612800 0.0563151 0.00000035 28.64 2952.8 9 86.6 - 1613472 0.0813337 0.00000039 19.84 2045.4 7 200.8 - 1620000 0.0844727 0.00000034 19.18 1978.0 6 19.2 - 1620675 0.0974935 0.00000037 16.62 1714.6 6 8.7 - 1632960 0.0711670 0.00000035 22.95 2367.9 8 61.1 - 1638400 0.0724051 0.00000033 22.63 2335.7 7 3.3 - 1640250 0.0844727 0.00000036 19.42 2004.4 6 17.0 - 1640625 0.0948893 0.00000038 17.29 1784.8 6 4.4 - 1646400 0.0701904 0.00000035 23.46 2422.0 8 45.1 - 1647086 0.0896810 0.00000038 18.37 1896.4 6 101.0 - 1653372 0.0859375 0.00000037 19.24 1987.1 6 21.7 - 1653750 0.0802176 0.00000038 20.62 2129.3 7 15.2 - 1658880 0.0580512 0.00000034 28.58 2952.2 9 66.1 - 1666980 0.0833333 0.00000036 20.00 2067.3 6 21.3 - 1679616 0.0885417 0.00000035 18.97 1961.4 6 2.4 - 1680000 0.0623915 0.00000037 26.93 2784.2 9 49.3 - 1680700 0.1029297 0.00000035 16.33 1688.4 5 19.4 - 1687500 0.0768694 0.00000039 21.95 2270.6 7 33.2 - 1693440 0.0623915 0.00000036 27.14 2808.1 9 60.9 - 1701000 0.0724051 0.00000034 23.49 2431.3 7 43.2 - 1714608 0.0791016 0.00000037 21.68 2244.5 7 43.6 - 1715000 0.0883789 0.00000038 19.41 2009.4 6 21.2 - 1720320 0.0607639 0.00000034 28.31 2932.3 9 40.8 - 1728000 0.0606554 0.00000035 28.49 2951.5 9 85.2 - 1728720 0.0813337 0.00000036 21.25 2202.1 7 41.1 - 1741824 0.0662842 0.00000037 26.28 2724.0 8 69.6 - 1749600 0.0779855 0.00000035 22.43 2326.3 7 69.3 - 1750000 0.0857747 0.00000039 20.40 2115.6 6 36.3 - 1750329 0.1248047 0.00000040 14.02 1454.3 5 3.8 - 1756160 0.0644531 0.00000037 27.25 2826.1 8 39.5 - 1764000 0.0802176 0.00000035 21.99 2281.5 7 60.3 - 1764735 0.1060547 0.00000036 16.64 1726.5 5 19.2 - 1769472 0.0623915 0.00000036 28.36 2943.1 9 64.2 - 1771470 0.1169922 0.00000038 15.14 1571.5 5 7.9 - 1771875 0.1232422 0.00000036 14.38 1492.1 5 9.6 - 1778112 0.0779855 0.00000036 22.80 2366.9 7 60.5 - 1786050 0.0935872 0.00000037 19.08 1981.7 6 19.1 - 1792000 0.0633545 0.00000035 28.29 2937.9 8 58.1 - 1800000 0.0791016 0.00000037 22.76 2364.3 7 79.4 - 1800750 0.0896810 0.00000037 20.08 2086.3 6 367.2 - 1806336 0.0935872 0.00000036 19.30 2005.8 6 4.2 - 1814400 0.0643311 0.00000036 28.20 2932.0 8 89.3 - 1815156 0.1044922 0.00000039 17.37 1805.9 5 23.5 - 1822500 0.1232422 0.00000035 14.79 1537.8 5 4.1 - 1835008 0.0693359 0.00000037 26.47 2753.4 8 40.3 - 1837080 0.0857747 0.00000036 21.42 2228.4 6 30.6 - 1837500 0.0935872 0.00000037 19.63 2042.9 6 20.1 - 1843200 0.0746373 0.00000033 24.70 2570.0 7 25.0 - 1843968 0.0735212 0.00000037 25.08 2610.2 7 43.7 - 1852200 0.0883789 0.00000036 20.96 2181.8 6 42.6 - 1866240 0.0692139 0.00000036 26.96 2808.5 8 79.6 - 1875000 0.1015625 0.00000039 18.46 1923.6 5 24.1 - 1881600 0.0653076 0.00000036 28.81 3002.6 8 61.0 - 1882384 0.1091797 0.00000037 17.24 1796.9 5 11.2 - 1889568 0.1125000 0.00000038 16.80 1751.0 5 24.2 - 1890000 0.0922852 0.00000036 20.48 2135.0 6 68.1 - 1905120 0.0883789 0.00000036 21.56 2248.5 6 53.4 - 1913625 0.1201172 0.00000035 15.93 1662.3 5 10.9 - 1920000 0.0721436 0.00000036 26.61 2777.5 8 66.7 - 1920800 0.1000000 0.00000037 19.21 2004.7 5 32.2 - 1928934 0.1325684 0.00000039 14.55 1519.0 4 8.3 - 1929375 0.1267090 0.00000035 15.23 1589.7 4 10.0 - 1935360 0.0724051 0.00000036 26.73 2791.1 7 79.8 - 1944000 0.0857747 0.00000036 22.66 2367.3 6 97.2 - 1944810 0.1345215 0.00000038 14.46 1510.1 4 8.2 - 1953125 0.1286621 0.00000041 15.18 1586.1 4 5.9 - 1959552 0.0779855 0.00000038 25.13 2626.0 7 74.8 - 1960000 0.0987956 0.00000037 19.84 2073.4 6 1.9 - 1966080 0.0714286 0.00000036 27.53 2877.3 7 47.1 - 1968300 0.1107422 0.00000036 17.77 1858.1 5 46.7 - 1968750 0.1107422 0.00000038 17.78 1858.6 5 20.2 - 1975680 0.0757533 0.00000037 26.08 2727.2 7 66.5 - 1984500 0.1107422 0.00000037 17.92 1874.5 5 45.3 - 1990656 0.0757533 0.00000037 26.28 2749.3 7 81.6 - 2000000 0.0987956 0.00000037 20.24 2118.7 6 25.8 - 2000376 0.1013672 0.00000037 19.73 2065.3 5 30.7 - 2007040 0.0757533 0.00000036 26.49 2773.5 7 47.3 - 2016000 0.0844727 0.00000036 23.87 2499.1 6 106.1 - 2016840 0.1076172 0.00000037 18.74 1962.5 5 430.3 - 2025000 0.1044922 0.00000036 19.38 2029.9 5 54.0 - 2032128 0.0935872 0.00000039 21.71 2275.0 6 28.4 - 2041200 0.1000000 0.00000036 20.41 2139.3 5 84.9 - 2048000 0.0711670 0.00000035 28.78 3016.7 8 69.3 - 2058000 0.1185547 0.00000036 17.36 1820.3 5 46.5 - 2064384 0.0835658 0.00000036 24.70 2591.1 7 78.7 - 2066715 0.1520996 0.00000037 13.59 1425.3 4 5.3 - 2073600 0.1015625 0.00000034 20.42 2142.1 5 4.0 - 2074464 0.1093750 0.00000037 18.97 1990.0 5 53.8 - 2083725 0.1484375 0.00000036 14.04 1473.3 4 12.1 - 2097152 0.0896810 0.00000035 23.38 2455.4 6 0.0 - 2099520 0.1013672 0.00000036 20.71 2174.9 5 85.1 - 2100000 0.1171875 0.00000036 17.92 1881.8 5 50.4 - 2100875 0.1367188 0.00000035 15.37 1613.7 4 76.5 - 2107392 0.0859375 0.00000036 24.52 2575.7 6 50.6 - 2109375 0.1425781 0.00000037 14.79 1554.0 4 11.2 - 2116800 0.1046875 0.00000036 20.22 2124.5 5 102.6 - 2117682 0.1109375 0.00000039 19.09 2005.7 5 497.2 - 2125764 0.1479492 0.00000038 14.37 1510.1 4 4.5 - 2126250 0.1328125 0.00000035 16.01 1682.6 4 25.3 - 2143260 0.1250000 0.00000037 17.15 1803.0 4 31.4 - 2143750 0.1342773 0.00000037 15.97 1678.9 4 14.5 - 2150400 0.0859375 0.00000035 25.02 2631.9 6 83.0 - 2151296 0.0924479 0.00000038 23.27 2447.7 6 50.6 - 2160000 0.0898438 0.00000034 24.04 2529.5 6 124.3 - 2160900 0.1440430 0.00000035 15.00 1578.4 4 7.0 - 2177280 0.0924479 0.00000037 23.55 2479.3 6 100.2 - 2187000 0.1121094 0.00000035 19.51 2054.2 5 62.7 - 2187500 0.1406250 0.00000040 15.56 1638.1 4 26.6 - 2195200 0.0947266 0.00000036 23.17 2440.9 6 76.8 - 2204496 0.1171875 0.00000037 18.81 1982.0 5 63.9 - 2205000 0.1347656 0.00000036 16.36 1723.9 4 15.9 - 2211840 0.0856120 0.00000035 25.84 2722.7 6 93.3 - 2222640 0.1171875 0.00000036 18.97 1999.4 5 63.4 - 2239488 0.0973307 0.00000037 23.01 2426.8 6 98.6 - 2240000 0.0986328 0.00000037 22.71 2395.4 6 82.6 - 2250000 0.1199219 0.00000038 18.76 1979.6 5 0.3 - 2250423 0.1816406 0.00000039 12.39 1307.2 3 5.4 - 2257920 0.1000000 0.00000037 22.58 2382.8 5 91.7 - 2268000 0.1152344 0.00000035 19.68 2077.7 5 99.2 - 2268945 0.1401367 0.00000037 16.19 1709.2 4 96.2 - 2278125 0.1523438 0.00000036 14.95 1579.1 4 14.2 - 2286144 0.1284180 0.00000037 17.80 1880.3 4 2.4 - 2293760 0.0898438 0.00000036 25.53 2697.2 6 57.3 - 2296350 0.1484375 0.00000037 15.47 1634.5 4 29.9 - 2296875 0.1596680 0.00000036 14.39 1519.9 4 7.5 - 2304000 0.0973307 0.00000035 23.67 2501.6 6 126.2 - 2304960 0.1214844 0.00000036 18.97 2005.1 5 57.8 - 2315250 0.1459961 0.00000035 15.86 1676.4 4 26.2 - 2322432 0.1011719 0.00000037 22.96 2427.2 5 103.2 - 2332800 0.1167969 0.00000034 19.97 2112.5 5 34.9 - 2333772 0.1518555 0.00000039 15.37 1625.5 4 34.7 - 2343750 0.1542969 0.00000041 15.19 1607.1 4 16.6 - 2352000 0.1058594 0.00000037 22.22 2351.3 5 79.9 - 2352980 0.1542969 0.00000036 15.25 1613.9 4 35.3 - 2359296 0.1214844 0.00000036 19.42 2055.7 5 5.9 - 2361960 0.1538086 0.00000036 15.36 1625.6 4 50.2 - 2362500 0.1503906 0.00000036 15.71 1663.0 4 60.0 - 2370816 0.1093750 0.00000038 21.68 2295.2 5 97.9 - 2381400 0.1542969 0.00000036 15.43 1634.7 4 74.0 - 2400000 0.1078125 0.00000038 22.26 2359.1 5 91.5 - 2401000 0.1464844 0.00000037 16.39 1737.0 4 36.7 - 2408448 0.1093750 0.00000038 22.02 2334.1 5 62.7 - 2419200 0.1078125 0.00000035 22.44 2379.2 5 140.4 - 2420208 0.1518555 0.00000038 15.94 1689.9 4 74.2 - 2430000 0.1386719 0.00000036 17.52 1858.6 4 111.4 - 2449440 0.1323242 0.00000035 18.51 1964.4 4 83.1 - 2450000 0.1479492 0.00000038 16.56 1757.3 4 59.3 - 2457600 0.1089844 0.00000035 22.55 2393.6 5 94.5 - 2458624 0.1347656 0.00000036 18.24 1936.5 4 4.9 - 2460375 0.1712240 0.00000035 14.37 1525.3 3 19.4 - 2469600 0.1381836 0.00000036 17.87 1897.6 4 103.2 - 2470629 0.1640625 0.00000040 15.06 1599.0 4 144.2 - 2480058 0.1920573 0.00000040 12.91 1371.5 3 14.4 - 2480625 0.1744792 0.00000035 14.22 1510.0 3 19.3 - 2488320 0.1167969 0.00000036 21.30 2263.3 5 122.6 - 2500000 0.1503906 0.00000040 16.62 1766.5 4 64.2 - 2500470 0.1894531 0.00000038 13.20 1402.6 3 14.5 - 2508800 0.1303711 0.00000034 19.24 2045.4 4 41.1 - 2519424 0.1284180 0.00000039 19.62 2086.0 4 114.5 - 2520000 0.1445312 0.00000035 17.44 1853.8 4 144.1 - 2521050 0.1328125 0.00000038 18.98 2018.3 4 270.5 - 2531250 0.1640625 0.00000037 15.43 1640.9 4 37.3 - 2540160 0.1214844 0.00000037 20.91 2224.4 5 111.2 - 2551500 0.1770833 0.00000036 14.41 1533.3 3 82.1 - 2560000 0.1125000 0.00000035 22.76 2422.1 5 5.2 - 2571912 0.1692708 0.00000038 15.19 1617.7 3 17.7 - 2572500 0.1738281 0.00000035 14.80 1575.7 3 35.2 - 2580480 0.1187500 0.00000036 21.73 2314.2 5 119.7 - 2592000 0.1214844 0.00000036 21.34 2272.9 5 165.2 - 2593080 0.1425781 0.00000039 18.19 1937.5 41015.2 - 2612736 0.1289062 0.00000038 20.27 2160.3 4 126.9 - 2621440 0.1246094 0.00000035 21.04 2242.8 5 69.6 - 2624400 0.1518555 0.00000035 17.28 1842.6 4 0.3 - 2625000 0.1616211 0.00000038 16.24 1731.7 4 40.8 - 2634240 0.1289062 0.00000037 20.44 2179.3 4 70.8 - 2646000 0.1601562 0.00000036 16.52 1762.4 4 111.9 - 2654208 0.1308594 0.00000039 20.28 2164.2 4 39.3 - 2657205 0.2187500 0.00000038 12.15 1296.2 3 8.8 - 2667168 0.1523438 0.00000037 17.51 1868.7 4 88.4 - 2679075 0.1953125 0.00000036 13.72 1464.5 3 22.4 - 2688000 0.1289062 0.00000036 20.85 2226.8 4 109.4 - 2689120 0.1386719 0.00000039 19.39 2070.9 4 434.2 - 2700000 0.1518555 0.00000037 17.78 1899.3 4 120.8 - 2701125 0.1979167 0.00000035 13.65 1457.9 3 18.8 - 2709504 0.1323242 0.00000037 20.48 2187.8 4 121.2 - 2721600 0.1479492 0.00000034 18.40 1966.1 4 168.2 - 2722734 0.2128906 0.00000040 12.79 1367.0 3 15.0 - 2733750 0.1764323 0.00000035 15.49 1656.6 3 43.4 - 2734375 0.2233073 0.00000040 12.24 1309.1 3 10.1 - 2744000 0.1616211 0.00000037 16.98 1815.6 4 98.1 - 2752512 0.1484375 0.00000038 18.54 1983.4 4 77.0 - 2755620 0.1894531 0.00000037 14.55 1555.9 3 58.1 - 2756250 0.1868490 0.00000037 14.75 1578.0 3 37.3 - 2764800 0.1289062 0.00000035 21.45 2294.8 4 171.1 - 2765952 0.1406250 0.00000040 19.67 2104.5 4 58.2 - 2778300 0.1842448 0.00000037 15.08 1613.9 3 85.2 - 2799360 0.1445312 0.00000037 19.37 2074.0 4 142.9 - 2800000 0.1484375 0.00000039 18.86 2020.0 4 104.0 - 2809856 0.1459961 0.00000038 19.25 2061.5 4 76.3 - 2812500 0.1875000 0.00000038 15.00 1606.8 3 76.6 - 2822400 0.1582031 0.00000033 17.84 1911.5 4 4.5 - 2823576 0.1503906 0.00000039 18.77 2011.7 4 892.3 - 2834352 0.1848958 0.00000037 15.33 1642.9 3 99.2 - 2835000 0.1920573 0.00000035 14.76 1582.0 3 102.6 - 2857680 0.1796875 0.00000036 15.90 1705.4 3 100.1 - 2867200 0.1406250 0.00000036 20.39 2186.8 4 115.7 - 2880000 0.1323242 0.00000035 21.76 2335.1 4 40.2 - 2881200 0.1875000 0.00000036 15.37 1648.7 3 76.8 - 2893401 0.2617188 0.00000039 11.06 1186.5 2 9.9 - 2903040 0.1499023 0.00000034 19.37 2078.9 4 152.1 - 2916000 0.1640625 0.00000034 17.77 1908.5 4 148.5 - 2917215 0.2441406 0.00000038 11.95 1283.1 3 9.5 - 2939328 0.1686198 0.00000037 17.43 1872.8 3 140.2 - 2940000 0.1822917 0.00000036 16.13 1732.7 3 80.3 - 2941225 0.1946615 0.00000036 15.11 1623.4 3 75.8 - 2949120 0.1503906 0.00000036 19.61 2107.2 4 139.0 - 2952450 0.2050781 0.00000037 14.40 1547.2 3 49.9 - 2953125 0.2187500 0.00000037 13.50 1450.8 3 21.0 - 2963520 0.1744792 0.00000035 16.98 1825.8 3 128.9 - 2976750 0.2005208 0.00000035 14.85 1596.2 3 48.0 - 2985984 0.1464844 0.00000036 20.38 2192.3 4 6.7 - 3000000 0.1875000 0.00000038 16.00 1721.3 3 114.3 - 3000564 0.2180990 0.00000039 13.76 1480.1 3 59.1 - 3001250 0.2337240 0.00000037 12.84 1381.5 3 24.6 - 3010560 0.1557617 0.00000033 19.33 2079.8 4 87.4 - 3024000 0.1764323 0.00000036 17.14 1844.9 3 185.1 - 3025260 0.1946615 0.00000037 15.54 1672.9 3 553.5 - 3037500 0.1979167 0.00000036 15.35 1652.5 3 97.7 - 3048192 0.1744792 0.00000037 17.47 1881.5 3 155.7 - 3061800 0.1979167 0.00000035 15.47 1666.6 3 112.0 - 3062500 0.2213542 0.00000038 13.84 1490.5 3 7.4 - 3072000 0.1596680 0.00000035 19.24 2073.2 4 133.6 - 3073280 0.1686198 0.00000038 18.23 1964.0 3 90.7 - 3087000 0.2050781 0.00000036 15.05 1622.5 3 96.9 - 3096576 0.1655273 0.00000036 18.71 2016.9 4 149.9 - 3110400 0.1616211 0.00000034 19.25 2075.4 4 218.0 - 3111696 0.1842448 0.00000039 16.89 1821.4 3 0.3 - 3125000 0.1848958 0.00000040 16.90 1823.3 3 19.5 - 3136000 0.1744792 0.00000036 17.97 1939.4 3 129.7 - 3145728 0.1744792 0.00000036 18.03 1945.8 3 93.4 - 3149280 0.1901042 0.00000036 16.57 1788.0 3 118.2 - 3150000 0.1998698 0.00000038 15.76 1701.1 3 146.7 - 3161088 0.1718750 0.00000036 18.39 1985.6 3 148.9 - 3175200 0.1868490 0.00000036 16.99 1835.2 3 44.1 - 3176523 0.2109375 0.00000041 15.06 1626.3 3 328.8 - 3188646 0.2773438 0.00000039 11.50 1241.9 2 19.7 - 3189375 0.2317708 0.00000036 13.76 1486.5 3 27.1 - 3200000 0.1744792 0.00000037 18.34 1981.6 3 137.3 - 3211264 0.1744792 0.00000036 18.40 1989.1 3 8.2 - 3214890 0.2646484 0.00000039 12.15 1313.0 2 20.2 - 3215625 0.2724609 0.00000035 11.80 1275.6 2 11.7 - 3225600 0.1712240 0.00000034 18.84 2036.5 3 213.3 - 3226944 0.2285156 0.00000039 14.12 1526.6 3 90.7 - 3240000 0.1666667 0.00000036 19.44 2102.2 3 3.2 - 3241350 0.2265625 0.00000037 14.31 1547.1 3 44.7 - 3265920 0.1875000 0.00000036 17.42 1884.6 3 165.4 - 3276800 0.1440430 0.00000034 22.75 2461.9 4 48.8 - 3280500 0.2239583 0.00000036 14.65 1585.3 3 107.4 - 3281250 0.2617188 0.00000039 12.54 1356.9 2 27.2 - 3292800 0.2083333 0.00000037 15.81 1711.0 3 133.5 - 3294172 0.3779297 0.00000039 8.72 943.6 2 77.7 - 3306744 0.2207031 0.00000037 14.98 1622.4 3 72.8 - 3307500 0.2207031 0.00000036 14.99 1622.8 3 94.2 - 3317760 0.1848958 0.00000035 17.94 1943.5 3 180.8 - 3333960 0.2180990 0.00000036 15.29 1656.2 3 72.0 - 3359232 0.1718750 0.00000038 19.54 2118.6 3 52.3 - 3360000 0.1979167 0.00000035 16.98 1840.3 3 150.5 - 3361400 0.2369792 0.00000037 14.18 1537.6 3 55.7 - 3375000 0.2291667 0.00000037 14.73 1596.9 3 107.5 - 3386880 0.1822917 0.00000035 18.58 2015.1 3 166.2 - 3402000 0.2187500 0.00000036 15.55 1687.2 3 177.1 - 3429216 0.2109375 0.00000037 16.26 1764.7 3 124.8 - 3430000 0.2597656 0.00000037 13.20 1433.3 2 91.7 - 3440640 0.1875000 0.00000035 18.35 1992.3 3 110.8 - 3444525 0.2656250 0.00000036 12.97 1408.0 2 28.3 - 3456000 0.1875000 0.00000033 18.43 2001.8 3 231.7 - 3457440 0.2239583 0.00000036 15.44 1676.7 3 113.6 - 3472875 0.2695312 0.00000036 12.88 1399.8 2 26.9 - 3483648 0.1888021 0.00000035 18.45 2004.9 3 193.5 - 3499200 0.2031250 0.00000035 17.23 1872.4 3 232.4 - 3500000 0.2421875 0.00000039 14.45 1570.8 3 99.1 - 3500658 0.3066406 0.00000040 11.42 1240.9 2 20.0 - 3512320 0.1901042 0.00000034 18.48 2008.7 3 103.7 - 3515625 0.2656250 0.00000039 13.24 1439.0 2 23.2 - 3528000 0.2096354 0.00000036 16.83 1830.2 3 213.1 - 3529470 0.1875000 0.00000039 18.82 2047.2 31078.1 - 3538944 0.1875000 0.00000037 18.87 2053.0 3 174.1 - 3542940 0.2500000 0.00000037 14.17 1541.6 2 68.6 - 3543750 0.2434896 0.00000036 14.55 1583.2 3 56.3 - 3556224 0.2083333 0.00000037 17.07 1857.4 3 171.4 - 3572100 0.2539062 0.00000035 14.07 1531.2 2 8.0 - 3584000 0.2044271 0.00000033 17.53 1908.6 3 160.5 - 3600000 0.2500000 0.00000036 14.40 1568.1 2 250.4 - 3601500 0.3320312 0.00000036 10.85 1181.2 2 51.5 - 3612672 0.2239583 0.00000039 16.13 1757.0 3 65.3 - 3628800 0.2018229 0.00000035 17.98 1959.0 3 262.4 - 3630312 0.2500000 0.00000039 14.52 1582.2 2 262.8 - 3645000 0.2135417 0.00000036 17.07 1860.3 3 24.1 - 3670016 0.1953125 0.00000037 18.79 2048.9 3 108.8 - 3674160 0.2447917 0.00000036 15.01 1636.7 3 134.6 - 3675000 0.2656250 0.00000038 13.84 1508.7 2 61.4 - 3686400 0.1901042 0.00000034 19.39 2115.0 3 8.3 - 3687936 0.2109375 0.00000036 17.48 1907.0 3 107.9 - 3704400 0.2408854 0.00000037 15.38 1677.8 3 163.9 - 3720087 0.3554688 0.00000040 10.47 1142.1 2 11.7 - 3732480 0.2031250 0.00000035 18.38 2005.8 3 211.4 - 3750000 0.2812500 0.00000040 13.33 1455.9 2 98.3 - 3750705 0.3457031 0.00000039 10.85 1184.7 2 12.1 - 3763200 0.2031250 0.00000033 18.53 2023.4 3 166.8 - 3764768 0.2239583 0.00000038 16.81 1836.0 3 41.0 - 3779136 0.2083333 0.00000038 18.14 1981.7 3 3.9 - 3780000 0.2265625 0.00000037 16.68 1822.7 3 179.8 - 3781575 0.2968750 0.00000037 12.74 1391.7 2 23.2 - 3796875 0.2832031 0.00000037 13.41 1465.1 2 29.5 - 3810240 0.2792969 0.00000036 13.64 1491.2 2 192.7 - 3827250 0.2929688 0.00000037 13.06 1428.4 2 63.3 - 3828125 0.3828125 0.00000038 10.00 1093.4 2 11.9 - 3840000 0.2278646 0.00000035 16.85 1843.0 3 190.5 - 3841600 0.1979167 0.00000037 19.41 2122.8 3 82.9 - 3857868 0.3164062 0.00000039 12.19 1333.9 2 71.4 - 3858750 0.2773438 0.00000036 13.91 1522.1 2 50.0 - 3870720 0.2109375 0.00000034 18.35 2007.9 3 201.5 - 3888000 0.2291667 0.00000036 16.97 1857.0 3 264.5 - 3889620 0.2871094 0.00000038 13.55 1482.9 2 70.8 - 3906250 0.3242188 0.00000044 12.05 1319.1 2 27.5 - 3919104 0.2447917 0.00000036 16.01 1753.3 3 214.4 - 3920000 0.1888021 0.00000037 20.76 2273.7 3 55.7 - 3932160 0.2031250 0.00000034 19.36 2120.4 3 123.8 - 3936600 0.2656250 0.00000035 14.82 1623.4 2 141.8 - 3937500 0.2812500 0.00000038 14.00 1533.6 2 106.9 - 3951360 0.2500000 0.00000035 15.81 1731.8 2 193.4 - 3969000 0.2734375 0.00000037 14.52 1590.9 2 137.8 - 3981312 0.2161458 0.00000035 18.42 2019.2 3 217.9 - 4000000 0.2161458 0.00000038 18.51 2029.3 3 5.6 - 4000752 0.2773438 0.00000038 14.43 1581.9 2 140.6 - 4014080 0.2213542 0.00000036 18.13 1989.0 3 122.6 - 4032000 0.2265625 0.00000034 17.80 1952.5 3 270.2 - 4033680 0.2369792 0.00000037 17.02 1867.5 3 713.1 - 4050000 0.2773438 0.00000037 14.60 1602.6 2 201.6 - 4064256 0.2109375 0.00000037 19.27 2115.1 3 7.5 - 4082400 0.2539062 0.00000035 16.08 1765.5 2 211.9 - 4084101 0.4101562 0.00000041 9.96 1093.4 2 11.4 - 4096000 0.2317708 0.00000034 17.67 1941.0 3 177.7 - 4100625 0.3281250 0.00000036 12.50 1372.6 2 32.1 - 4116000 0.3125000 0.00000037 13.17 1447.0 2 107.0 - 4117715 0.2851562 0.00000040 14.44 1586.5 2 258.5 - 4128768 0.2278646 0.00000036 18.12 1991.1 3 208.1 - 4133430 0.3828125 0.00000038 10.80 1186.6 2 25.4 - 4134375 0.3164062 0.00000036 13.07 1436.0 2 25.1 - 4147200 0.1979167 0.00000034 20.95 2303.3 3 62.7 - 4148928 0.2695312 0.00000037 15.39 1692.0 2 180.7 - 4167450 0.3164062 0.00000038 13.17 1448.2 2 60.1 - 4194304 0.2018229 0.00000038 20.78 2286.0 3 0.0 - 4199040 0.2734375 0.00000036 15.36 1689.3 2 237.6 - 4200000 0.3203125 0.00000037 13.11 1442.5 2 178.0 - 4201750 0.2447917 0.00000040 17.16 1888.3 3 327.3 - 4214784 0.2539062 0.00000035 16.60 1826.6 2 147.6 - 4218750 0.3164062 0.00000038 13.33 1467.2 2 53.5 - 4233600 0.2734375 0.00000036 15.48 1704.2 2 284.1 - 4235364 0.4023438 0.00000040 10.53 1158.7 2 16.3 - 4251528 0.2812500 0.00000039 15.12 1664.3 2 31.7 - 4252500 0.3046875 0.00000036 13.96 1536.6 2 132.3 - 4286520 0.2968750 0.00000036 14.44 1590.5 2 90.3 - 4287500 0.3671875 0.00000039 11.68 1286.3 2 54.4 - 4300800 0.2447917 0.00000036 17.57 1935.8 3 213.2 - 4302592 0.2851562 0.00000037 15.09 1662.5 2 149.2 - 4320000 0.2792969 0.00000036 15.47 1704.7 2 316.8 - 4321800 0.2851562 0.00000036 15.16 1670.4 2 19.2 - 4354560 0.2578125 0.00000035 16.89 1862.5 2 264.7 - 4374000 0.3007812 0.00000035 14.54 1604.0 2 225.5 - 4375000 0.3574219 0.00000040 12.24 1350.2 2 69.3 - 4390400 0.2558594 0.00000036 17.16 1893.2 2 204.6 - 4408992 0.2968750 0.00000038 14.85 1639.0 2 162.1 - 4410000 0.2539062 0.00000036 17.37 1916.8 2 0.6 - 4423680 0.2434896 0.00000036 18.17 2005.4 3 250.7 - 4428675 0.3574219 0.00000037 12.39 1367.8 2 32.5 - 4445280 0.2968750 0.00000036 14.97 1653.4 2 159.3 - 4465125 0.3554688 0.00000036 12.56 1387.4 2 33.4 - 4478976 0.2617188 0.00000036 17.11 1890.6 2 276.6 - 4480000 0.2617188 0.00000036 17.12 1891.1 2 223.8 - 4500000 0.2617188 0.00000039 17.19 1900.1 2 57.2 - 4500846 0.4355469 0.00000040 10.33 1142.0 2 24.3 - 4501875 0.4296875 0.00000036 10.48 1157.8 2 12.4 - 4515840 0.2617188 0.00000034 17.25 1907.2 2 253.2 - 4536000 0.2871094 0.00000035 15.80 1746.8 2 325.8 - 4537890 0.3027344 0.00000039 14.99 1657.4 2 320.1 - 4556250 0.3437500 0.00000036 13.25 1465.9 2 66.1 - 4572288 0.2695312 0.00000038 16.96 1876.6 2 74.7 - 4587520 0.2578125 0.00000036 17.79 1968.8 2 158.1 - 4592700 0.3437500 0.00000037 13.36 1478.4 2 140.3 - 4593750 0.3945312 0.00000039 11.64 1288.4 2 28.8 - 4608000 0.2578125 0.00000034 17.87 1978.2 2 340.9 - 4609920 0.2395833 0.00000039 19.24 2129.7 32210.2 - 4630500 0.3632812 0.00000037 12.75 1411.2 2 114.0 - 4644864 0.2734375 0.00000037 16.99 1881.1 2 285.7 - 4665600 0.2434896 0.00000034 19.16 2122.5 3 6.7 - 4667544 0.3300781 0.00000039 14.14 1566.4 2 89.8 - 4687500 0.3984375 0.00000041 11.76 1303.6 2 56.3 - 4704000 0.2968750 0.00000035 15.85 1756.1 2 220.9 - 4705960 0.3691406 0.00000039 12.75 1412.9 2 105.9 - 4718592 0.2174479 0.00000040 21.70 2405.4 3 72.1 - 4723920 0.3281250 0.00000038 14.40 1596.0 2 169.1 - 4725000 0.3515625 0.00000036 13.44 1490.0 2 140.8 - 4741632 0.2929688 0.00000037 16.18 1794.6 2 253.3 - 4762800 0.3320312 0.00000036 14.34 1591.0 2 240.0 - 4782969 0.5156250 0.00000040 9.28 1029.2 1 13.0 - 4800000 0.2968750 0.00000036 16.17 1794.3 2 229.5 - 4802000 0.4023438 0.00000037 11.94 1324.5 2 116.1 - 4816896 0.2812500 0.00000037 17.13 1901.0 2 164.4 - 4822335 0.4785156 0.00000039 10.08 1118.7 2 15.1 - 4838400 0.2890625 0.00000034 16.74 1858.5 2 361.3 - 4840416 0.3789062 0.00000038 12.77 1418.4 2 154.4 - 4860000 0.3359375 0.00000034 14.47 1606.7 2 265.2 - 4862025 0.4023438 0.00000037 12.08 1342.1 2 32.2 - 4898880 0.3359375 0.00000036 14.58 1620.4 2 266.8 - 4900000 0.3984375 0.00000038 12.30 1366.6 2 129.7 - 4915200 0.2792969 0.00000035 17.60 1956.0 2 235.8 - 4917248 0.2851562 0.00000037 17.24 1916.6 2 83.4 - 4920750 0.3945312 0.00000037 12.47 1386.3 2 69.9 - 4921875 0.4160156 0.00000039 11.83 1315.1 2 27.0 - 4939200 0.3515625 0.00000036 14.05 1562.0 2 313.4 - 4941258 0.2890625 0.00000040 17.09 1900.6 21075.4 - 4960116 0.3984375 0.00000039 12.45 1384.4 2 86.7 - 4961250 0.3828125 0.00000036 12.96 1441.3 2 67.9 - 4976640 0.2968750 0.00000035 16.76 1864.7 2 313.5 - 5000000 0.3847656 0.00000040 12.99 1445.9 2 196.8 - 5000940 0.3769531 0.00000038 13.27 1476.2 2 86.5 - 5017600 0.2636719 0.00000034 19.03 2117.9 2 11.5 - 5038848 0.3261719 0.00000038 15.45 1719.8 2 302.6 - 5040000 0.3359375 0.00000035 15.00 1670.2 2 334.0 - 5042100 0.4882812 0.00000037 10.33 1149.6 2 60.3 - 5062500 0.3593750 0.00000038 14.09 1568.7 2 11.2 - 5080320 0.3281250 0.00000036 15.48 1724.5 2 299.5 - 5103000 0.3593750 0.00000035 14.20 1582.0 2 175.8 - 5120000 0.2408854 0.00000035 21.25 2368.6 3 71.2 - 5143824 0.3085938 0.00000040 16.67 1858.1 2 0.5 - 5145000 0.4433594 0.00000038 11.60 1293.6 2 75.3 - 5160960 0.3125000 0.00000035 16.52 1841.4 2 297.8 - 5184000 0.3125000 0.00000034 16.59 1850.1 2 403.2 - 5186160 0.4394531 0.00000038 11.80 1316.2 2 152.2 - 5225472 0.3261719 0.00000037 16.02 1787.7 2 321.9 - 5242880 0.3085938 0.00000036 16.99 1896.2 2 173.9 - 5248800 0.3125000 0.00000036 16.80 1874.8 2 66.8 - 5250000 0.4433594 0.00000037 11.84 1321.7 2 129.8 - 5250987 0.5625000 0.00000042 9.34 1042.0 1 14.6 - 5268480 0.3281250 0.00000035 16.06 1792.6 2 178.8 - 5292000 0.4238281 0.00000035 12.49 1394.4 2 248.5 - 5294205 0.3398438 0.00000040 15.58 1739.8 2 854.9 - 5308416 0.2714844 0.00000039 19.55 2184.1 2 12.2 - 5314410 0.7187500 0.00000039 7.39 826.0 1 26.6 - 5315625 0.4472656 0.00000036 11.88 1327.6 2 36.1 - 5334336 0.4023438 0.00000038 13.26 1481.4 2 264.8 - 5358150 0.4257812 0.00000037 12.58 1406.5 2 68.7 - 5359375 0.5156250 0.00000037 10.39 1161.7 1 12.1 - 5376000 0.3281250 0.00000034 16.38 1831.6 2 0.1 - 5378240 0.2968750 0.00000040 18.12 2025.3 2 787.2 - 5400000 0.3828125 0.00000036 14.11 1577.4 2 347.4 - 5402250 0.4316406 0.00000037 12.52 1399.6 2 55.7 - 5419008 0.3359375 0.00000035 16.13 1804.2 2 297.0 - 5443200 0.3515625 0.00000036 15.48 1732.2 2 379.8 - 5445468 0.4316406 0.00000039 12.62 1411.5 2 88.1 - 5467500 0.4179688 0.00000037 13.08 1463.9 2 151.9 - 5468750 0.4921875 0.00000042 11.11 1243.5 2 29.9 - 5488000 0.4375000 0.00000036 12.54 1404.2 2 214.7 - 5505024 0.3437500 0.00000036 16.01 1793.0 2 183.2 - 5511240 0.4140625 0.00000037 13.31 1490.3 2 101.7 - 5512500 0.4531250 0.00000037 12.17 1362.2 2 131.3 - 5529600 0.3515625 0.00000036 15.73 1761.5 2 406.8 - 5531904 0.2968750 0.00000041 18.63 2086.9 2 146.9 - 5556600 0.4101562 0.00000037 13.55 1517.7 2 173.0 - 5598720 0.3671875 0.00000036 15.25 1709.0 2 325.2 - 5600000 0.3945312 0.00000037 14.19 1590.9 2 255.2 - 5619712 0.3554688 0.00000037 15.81 1772.4 2 185.3 - 5625000 0.4921875 0.00000039 11.43 1281.3 2 159.7 - 5644800 0.3359375 0.00000035 16.80 1884.3 2 97.0 - 5647152 0.4609375 0.00000040 12.25 1373.9 2 95.8 - 5668704 0.4179688 0.00000038 13.56 1521.3 2 198.0 - 5670000 0.4017181 0.00000037 14.11 1583.3 2 273.5 - 5715360 0.3860931 0.00000036 14.80 1661.4 2 194.0 - 5734400 0.3470764 0.00000035 16.52 1854.7 2 262.5 - 5740875 0.4953308 0.00000037 11.59 1301.1 2 37.5 - 5760000 0.3237000 0.00000036 17.79 1998.1 2 9.6 - 5762400 0.6240234 0.00000037 9.23 1036.9 1 137.1 - 5764801 0.6083984 0.00000040 9.48 1064.0 1 38.1 - 5786802 0.8346558 0.00000039 6.93 778.7 1 29.9 - 5788125 0.4913940 0.00000035 11.78 1323.1 2 30.0 - 5806080 0.3510742 0.00000035 16.54 1858.0 2 337.2 - 5832000 0.4094849 0.00000034 14.24 1600.5 2 386.0 - 5834430 0.3822021 0.00000040 15.27 1715.5 21338.4 - 5859375 0.5615234 0.00000041 10.43 1173.0 1 13.2 - 5878656 0.3822021 0.00000038 15.38 1729.4 2 293.4 - 5880000 0.4484863 0.00000037 13.11 1474.1 2 214.2 - 5882450 0.5227051 0.00000039 11.25 1265.4 1 59.4 - 5898240 0.3548584 0.00000035 16.62 1869.2 2 310.8 - 5904900 0.4056396 0.00000037 14.56 1637.2 2 12.4 - 5906250 0.4758301 0.00000038 12.41 1396.0 2 59.8 - 5927040 0.3781738 0.00000036 15.67 1763.1 2 265.6 - 5953500 0.4445801 0.00000037 13.39 1506.9 2 155.4 - 5971968 0.3041992 0.00000037 19.63 2209.5 2 88.3 - 6000000 0.4562988 0.00000038 13.15 1480.4 2 228.2 - 6001128 0.4406738 0.00000040 13.62 1533.2 2 102.2 - 6002500 0.4135742 0.00000038 14.51 1634.0 2 12.7 - 6021120 0.3745117 0.00000036 16.08 1810.4 2 187.8 - 6048000 0.3820801 0.00000035 15.83 1783.0 2 418.0 - 6050520 0.3823242 0.00000039 15.83 1782.6 2 937.1 - 6075000 0.4484863 0.00000036 13.55 1526.2 2 189.3 - 6096384 0.3940430 0.00000038 15.47 1743.6 2 331.0 - 6123600 0.4328613 0.00000036 14.15 1594.8 2 286.7 - 6125000 0.3898926 0.00000039 15.71 1770.9 2 39.3 - 6144000 0.3745117 0.00000036 16.41 1849.8 2 280.3 - 6146560 0.3940430 0.00000036 15.60 1758.9 2 182.6 - 6174000 0.5029297 0.00000037 12.28 1384.6 2 255.1 - 6193152 0.3862305 0.00000036 16.03 1808.9 2 326.8 - 6200145 0.8808594 0.00000039 7.04 794.1 1 18.0 - 6220800 0.4174805 0.00000034 14.90 1681.5 2 470.0 - 6223392 0.4013672 0.00000039 15.51 1749.7 2 77.3 - 6250000 0.3549805 0.00000042 17.61 1987.4 2 0.8 - 6251175 0.6708984 0.00000037 9.32 1051.8 1 40.9 - 6272000 0.4018555 0.00000036 15.61 1762.1 2 283.9 - 6291456 0.4018555 0.00000037 15.66 1768.0 2 193.6 - 6298560 0.4365234 0.00000036 14.43 1629.5 2 301.4 - 6300000 0.4912109 0.00000037 12.83 1448.4 2 286.1 - 6302625 0.4407043 0.00000036 14.30 1615.1 2 136.0 - 6322176 0.4095001 0.00000037 15.44 1744.0 2 325.8 - 6328125 0.5538025 0.00000038 11.43 1290.8 1 41.0 - 6350400 0.3705139 0.00000034 17.14 1936.6 2 5.8 - 6353046 0.3665771 0.00000041 17.33 1958.3 22314.9 - 6377292 0.5068359 0.00000039 12.58 1422.1 1 95.6 - 6378750 0.5070801 0.00000036 12.58 1421.8 1 78.5 - 6400000 0.4016113 0.00000036 15.94 1801.5 2 286.2 - 6422528 0.3159180 0.00000038 20.33 2298.8 2 96.1 - 6429780 0.4914551 0.00000038 13.08 1479.5 2 95.2 - 6431250 0.5615234 0.00000038 11.45 1295.2 1 31.3 - 6451200 0.4095459 0.00000035 15.75 1781.6 2 451.0 - 6453888 0.3781738 0.00000040 17.07 1930.3 21022.9 - 6480000 0.3393555 0.00000036 19.10 2160.4 2 87.7 - 6482700 0.5302734 0.00000038 12.23 1383.2 1 137.3 - 6531840 0.4250488 0.00000036 15.37 1739.5 2 358.8 - 6553600 0.3510742 0.00000034 18.67 2113.5 2 12.8 - 6561000 0.4758301 0.00000036 13.79 1561.2 2 217.3 - 6562500 0.5693359 0.00000040 11.53 1305.1 1 84.2 - 6585600 0.4562988 0.00000036 14.43 1634.6 2 289.7 - 6588344 0.3977051 0.00000040 16.57 1876.2 2 935.8 - 6613488 0.4953613 0.00000040 13.35 1512.4 2 202.4 - 6615000 0.5385742 0.00000036 12.28 1391.4 1 195.3 - 6635520 0.4289551 0.00000037 15.47 1752.8 2 379.4 - 6667920 0.4875488 0.00000038 13.68 1550.1 2 196.6 - 6718464 0.3706055 0.00000039 18.13 2055.7 2 10.4 - 6720000 0.4482422 0.00000036 14.99 1700.1 2 305.9 - 6722800 0.6005859 0.00000036 11.19 1269.4 1 157.9 - 6750000 0.5380859 0.00000037 12.54 1422.9 1 309.3 - 6751269 1.0058594 0.00000042 6.71 761.4 1 16.3 - 6773760 0.4365234 0.00000036 15.52 1760.6 2 349.1 - 6804000 0.4873047 0.00000036 13.96 1584.6 2 351.9 - 6806835 0.5068359 0.00000041 13.43 1524.2 1 370.3 - 6834375 0.6162109 0.00000037 11.09 1259.1 1 51.1 - 6858432 0.5069885 0.00000038 13.53 1536.0 1 317.7 - 6860000 0.5849915 0.00000037 11.73 1331.5 1 179.2 - 6881280 0.4446411 0.00000036 15.48 1757.6 2 207.5 - 6889050 0.6162109 0.00000039 11.18 1269.8 1 87.6 - 6890625 0.6630249 0.00000038 10.39 1180.4 1 41.6 - 6912000 0.4523926 0.00000034 15.28 1735.7 2 504.3 - 6914880 0.4874878 0.00000037 14.18 1611.5 2 292.6 - 6945750 0.6083984 0.00000037 11.42 1297.3 1 85.7 - 6967296 0.4680176 0.00000036 14.89 1692.0 2 384.5 - 6998400 0.4641113 0.00000036 15.08 1714.4 2 487.5 - 7000000 0.5695801 0.00000039 12.29 1397.3 1 268.5 - 7001316 0.4874268 0.00000041 14.36 1633.1 2 21.2 - 7024640 0.4600830 0.00000036 15.27 1736.3 2 211.8 - 7031250 0.6315918 0.00000041 11.13 1266.1 1 80.7 - 7056000 0.4913330 0.00000036 14.36 1633.6 2 447.8 - 7058940 0.5695801 0.00000039 12.39 1409.8 1 109.7 - 7077888 0.4758301 0.00000039 14.87 1692.4 2 355.4 - 7085880 0.5537109 0.00000037 12.80 1456.1 1 117.4 - 7087500 0.5693359 0.00000038 12.45 1416.5 1 207.9 - 7112448 0.4797363 0.00000038 14.83 1687.3 2 374.1 - 7144200 0.4794922 0.00000036 14.90 1696.2 2 46.3 - 7168000 0.4641113 0.00000036 15.44 1758.6 2 332.2 - 7200000 0.4758301 0.00000037 15.13 1723.4 2 509.2 - 7203000 0.4370117 0.00000038 16.48 1877.4 22741.6 - 7225344 0.4331055 0.00000040 16.68 1900.5 2 12.6 - 7257600 0.4677734 0.00000034 15.52 1768.0 2 544.6 - 7260624 0.7324219 0.00000040 9.91 1129.7 1 188.1 - 7290000 0.4130859 0.00000037 17.65 2011.6 2 1.1 - 7340032 0.4956055 0.00000038 14.81 1688.9 2 217.9 - 7348320 0.5546875 0.00000037 13.25 1510.8 1 230.6 - 7350000 0.6474609 0.00000037 11.35 1294.7 1 171.5 - 7372800 0.3901367 0.00000036 18.90 2155.7 2 105.4 - 7375872 0.5460052 0.00000038 13.51 1541.0 1 227.5 - 7381125 0.6941833 0.00000038 10.63 1213.0 1 50.2 - 7408800 0.6240234 0.00000037 11.87 1354.7 1 336.3 - 7411887 0.6707764 0.00000041 11.05 1260.9 1 117.5 - 7440174 1.0841675 0.00000042 6.86 783.3 1 30.1 - 7441875 0.7254028 0.00000037 10.26 1170.9 1 54.8 - 7464960 0.4757690 0.00000036 15.69 1791.2 2 417.9 - 7500000 0.6318359 0.00000040 11.87 1355.5 1 188.6 - 7501410 1.0607910 0.00000040 7.07 807.5 1 30.0 - 7503125 0.7409668 0.00000037 10.13 1156.4 1 19.1 - 7526400 0.4953003 0.00000034 15.20 1735.6 2 342.9 - 7529536 0.4445801 0.00000039 16.94 1934.5 2 81.8 - 7558272 0.4484863 0.00000039 16.85 1925.4 2 104.2 - 7560000 0.5383301 0.00000036 14.04 1604.5 1 482.3 - 7563150 0.7019043 0.00000037 10.78 1231.1 1 75.1 - 7593750 0.6787109 0.00000039 11.19 1278.6 1 101.1 - 7620480 0.5070801 0.00000036 15.03 1717.8 1 350.3 - 7654500 0.6240234 0.00000036 12.27 1402.5 1 206.5 - 7656250 0.6940918 0.00000041 11.03 1261.3 1 38.9 - 7680000 0.5148926 0.00000035 14.92 1705.8 1 365.4 - 7683200 0.4056396 0.00000038 18.94 2166.2 2 149.6 - 7715736 0.6005859 0.00000039 12.85 1469.7 1 121.5 - 7717500 0.6865234 0.00000038 11.24 1286.0 1 184.5 - 7741440 0.5458984 0.00000037 14.18 1622.6 1 396.1 - 7776000 0.5068359 0.00000034 15.34 1756.0 1 575.2 - 7779240 0.6162109 0.00000038 12.62 1444.9 1 120.9 - 7812500 0.7021484 0.00000044 11.13 1273.8 1 86.5 - 7838208 0.5615234 0.00000038 13.96 1598.4 1 423.3 - 7840000 0.4562988 0.00000037 17.18 1967.5 2 8.2 - 7864320 0.5458984 0.00000036 14.41 1650.0 1 236.4 - 7873200 0.6083984 0.00000036 12.94 1482.3 1 367.4 - 7875000 0.6865234 0.00000038 11.47 1313.9 1 222.0 - 7902720 0.5224609 0.00000036 15.13 1733.0 1 368.5 - 7938000 0.6240234 0.00000036 12.72 1457.8 1 364.1 - 7962624 0.5229492 0.00000039 15.23 1745.3 1 428.4 - 7971615 1.1934090 0.00000040 6.68 765.7 1 18.5 - 8000000 0.3900032 0.00000038 20.51 2351.9 2 100.6 - 8001504 0.6473999 0.00000040 12.36 1417.1 1 238.7 - 8028160 0.5538330 0.00000036 14.50 1662.4 1 235.0 - 8037225 0.8346558 0.00000038 9.63 1104.4 1 51.4 - 8064000 0.5303955 0.00000034 15.20 1744.1 1 566.5 - 8067360 0.5693359 0.00000039 14.17 1625.5 11110.6 - 8100000 0.6240234 0.00000036 12.98 1489.5 1 410.8 - 8103375 0.8269043 0.00000037 9.80 1124.5 1 39.7 - 8128512 0.4094238 0.00000039 19.85 2278.6 2 108.6 - 8164800 0.5771484 0.00000036 14.15 1624.1 1 521.5 - 8168202 0.5615234 0.00000042 14.55 1670.1 1 447.0 - 8192000 0.6083984 0.00000034 13.46 1546.2 1 358.7 - 8201250 0.7568359 0.00000038 10.84 1244.4 1 116.2 - 8203125 0.7958984 0.00000040 10.31 1183.6 1 20.9 - 8232000 0.6865234 0.00000037 11.99 1377.3 1 275.3 - 8235430 0.7412109 0.00000040 11.11 1276.3 1 53.7 - 8257536 0.5385742 0.00000039 15.33 1761.5 1 403.0 - 8266860 0.6938477 0.00000038 11.91 1368.9 1 105.3 - 8268750 0.7563477 0.00000038 10.93 1256.1 1 91.4 - 8294400 0.4448242 0.00000034 18.65 2142.8 2 13.5 - 8297856 0.5620117 0.00000038 14.76 1696.8 1 324.3 - 8334900 0.7021484 0.00000038 11.87 1364.6 1 213.0 - 8388608 0.4135742 0.00000038 20.28 2332.6 2 0.0 + 8 0.0000002 0.00000003 51.20 768.0 1000000 0.0 + 9 0.0000002 0.00000008 46.08 730.4 1000000 0.0 + 10 0.0000002 0.00000011 60.95 1012.4 1000000 0.0 + 12 0.0000002 0.00000008 64.00 1147.2 1000000 0.0 + 14 0.0000001 0.00000018 99.56 1895.2 1000000 0.0 + 15 0.0000002 0.00000014 87.27 1704.8 1000000 0.0 + 16 0.0000002 0.00000014 97.52 1950.5 1000000 0.0 + 18 0.0000002 0.00000015 76.80 1601.3 1000000 0.0 + 20 0.0000002 0.00000017 116.36 2514.6 1000000 0.0 + 21 0.0000002 0.00000017 89.60 1967.8 1000000 0.0 + 24 0.0000001 0.00000015 161.68 3706.6 1000000 0.0 + 25 0.0000002 0.00000017 103.23 2396.8 1000000 0.0 + 27 0.0000002 0.00000014 144.00 3423.5 1000000 0.0 + 28 0.0000002 0.00000015 149.33 3589.5 1000000 0.0 + 30 0.0000002 0.00000013 153.60 3768.5 1000000 0.0 + 32 0.0000002 0.00000016 178.09 4452.2 1000000 0.0 + 35 0.0000003 0.00000018 128.00 3282.7 1000000 0.0 + 36 0.0000002 0.00000016 144.00 3722.3 1000000 0.0 + 40 0.0000002 0.00000015 189.63 5046.0 1000000 0.0 + 42 0.0000003 0.00000022 162.91 4392.3 1000000 0.0 + 45 0.0000004 0.00000016 128.00 3514.8 1000000 0.0 + 48 0.0000002 0.00000016 236.31 6598.8 1000000 0.0 + 49 0.0000003 0.00000019 152.98 4294.6 1000000 0.0 + 50 0.0000002 0.00000017 246.15 6946.3 1000000 0.0 + 54 0.0000002 0.00000020 230.40 6629.6 1000000 0.0 + 56 0.0000002 0.00000017 247.17 7177.1 1000000 0.0 + 60 0.0000002 0.00000018 256.00 7560.8 1000000 0.0 + 63 0.0000004 0.00000022 171.57 5127.7 1000000 0.0 + 64 0.0000002 0.00000017 341.33 10240.0 1000000 0.0 + 70 0.0000003 0.00000017 224.00 6864.8 1000000 0.0 + 72 0.0000002 0.00000017 341.33 10530.0 1000000 0.0 + 75 0.0000003 0.00000019 228.57 7118.6 1000000 0.0 + 80 0.0000002 0.00000016 393.85 12449.3 1000000 0.0 + 81 0.0000005 0.00000018 158.81 5034.1 980302 0.0 + 84 0.0000003 0.00000017 290.59 9287.9 1000000 0.0 + 90 0.0000003 0.00000017 261.82 8498.4 1000000 0.0 + 96 0.0000002 0.00000017 438.86 14449.3 1000000 0.0 + 98 0.0000004 0.00000019 266.89 8827.1 1000000 0.0 + 100 0.0000003 0.00000021 320.00 10630.2 1000000 0.0 + 105 0.0000005 0.00000021 227.80 7647.4 1000000 0.0 + 108 0.0000003 0.00000019 321.49 10858.1 1000000 0.0 + 112 0.0000003 0.00000018 409.60 13941.5 1000000 0.0 + 120 0.0000003 0.00000019 465.45 16074.2 1000000 0.0 + 125 0.0000006 0.00000020 215.68 7512.1 862738 0.0 + 126 0.0000004 0.00000020 282.95 9871.0 1000000 0.0 + 128 0.0000003 0.00000020 468.11 16384.0 1000000 0.0 + 135 0.0000006 0.00000021 222.32 7866.7 823422 0.0 + 140 0.0000003 0.00000019 437.07 15580.1 1000000 0.0 + 144 0.0000003 0.00000018 512.00 18355.0 1000000 0.0 + 147 0.0000010 0.00000021 152.23 5480.0 517788 0.0 + 150 0.0000005 0.00000019 320.00 11566.1 1000000 0.0 + 160 0.0000003 0.00000018 476.28 17436.4 1000000 0.0 + 162 0.0000007 0.00000021 248.49 9119.5 766951 0.0 + 168 0.0000004 0.00000019 477.87 17662.7 1000000 0.0 + 175 0.0000009 0.00000022 205.55 7657.9 587281 0.0 + 180 0.0000004 0.00000020 470.20 17613.5 1000000 0.0 + 189 0.0000012 0.00000022 152.31 5758.9 402928 0.0 + 192 0.0000003 0.00000021 646.74 24527.4 1000000 0.0 + 196 0.0000007 0.00000019 281.07 10701.4 717019 0.0 + 200 0.0000004 0.00000020 457.14 17471.7 1000000 0.0 + 210 0.0000006 0.00000021 339.65 13100.6 808684 0.0 + 216 0.0000005 0.00000020 445.94 17290.9 1000000 0.0 + 224 0.0000004 0.00000021 540.98 21118.2 1000000 0.0 + 225 0.0000011 0.00000024 201.03 7854.2 446741 0.0 + 240 0.0000003 0.00000019 853.33 33736.1 1000000 0.1 + 243 0.0000016 0.00000022 151.79 6014.3 312315 0.0 + 245 0.0000015 0.00000023 167.65 6652.8 342140 0.0 + 250 0.0000008 0.00000024 332.95 13261.0 665900 0.0 + 252 0.0000007 0.00000021 373.22 14886.3 740509 0.0 + 256 0.0000004 0.00000019 728.18 29127.1 1000000 0.0 + 270 0.0000008 0.00000022 322.93 13041.4 598027 0.0 + 280 0.0000005 0.00000020 578.06 23496.2 1000000 0.0 + 288 0.0000006 0.00000020 495.48 20240.2 860210 0.1 + 294 0.0000012 0.00000022 248.82 10201.3 423165 0.0 + 300 0.0000006 0.00000020 464.51 19111.9 774186 0.0 + 315 0.0000019 0.00000023 169.88 7049.5 269657 0.0 + 320 0.0000003 0.000000201024.00 42608.3 1000000 0.0 + 324 0.0000009 0.00000021 377.75 15752.1 582954 0.0 + 336 0.0000009 0.00000021 372.85 15645.6 554843 0.0 + 343 0.0000023 0.00000023 150.28 6328.3 219064 0.0 + 350 0.0000011 0.00000023 320.75 13553.4 458208 0.0 + 360 0.0000007 0.00000022 527.74 22407.3 732968 0.1 + 375 0.0000019 0.00000024 192.92 8248.1 257229 0.0 + 378 0.0000013 0.00000023 285.36 12216.7 377464 0.0 + 384 0.0000005 0.00000022 805.77 34587.5 1000000 0.1 + 392 0.0000010 0.00000024 409.69 17646.6 522559 0.0 + 400 0.0000005 0.00000021 729.04 31508.6 911300 0.0 + 405 0.0000023 0.00000023 175.76 7612.0 216988 0.0 + 420 0.0000011 0.00000022 398.06 17343.9 473878 0.0 + 432 0.0000009 0.00000022 463.56 20291.9 536523 0.1 + 441 0.0000029 0.00000024 151.23 6642.7 171467 0.0 + 448 0.0000007 0.00000021 613.30 27008.0 684492 0.0 + 450 0.0000015 0.00000022 305.81 13476.6 339787 0.0 + 480 0.0000008 0.00000021 589.46 26251.3 614022 0.1 + 486 0.0000018 0.00000024 263.15 11742.9 270733 0.0 + 490 0.0000017 0.00000023 283.60 12672.1 289387 0.0 + 500 0.0000012 0.00000024 426.57 19122.9 426575 0.0 + 504 0.0000013 0.00000022 399.80 17945.7 396629 0.1 + 512 0.0000005 0.00000022 961.52 43268.2 938980 0.0 + 525 0.0000027 0.00000023 194.17 8773.0 184928 0.0 + 540 0.0000012 0.00000022 458.43 20805.2 424468 0.1 + 560 0.0000012 0.00000022 486.46 22205.3 434343 0.1 + 567 0.0000035 0.00000025 163.76 7489.5 144405 0.0 + 576 0.0000012 0.00000022 500.04 22926.7 434063 0.1 + 588 0.0000014 0.00000024 410.30 18873.2 348895 0.0 + 600 0.0000012 0.00000022 505.51 23326.4 421260 0.1 + 625 0.0000036 0.00000026 171.64 7970.7 137312 0.0 + 630 0.0000020 0.00000022 308.54 14345.9 244874 0.0 + 640 0.0000007 0.00000020 894.82 41707.1 699075 0.1 + 648 0.0000015 0.00000023 425.03 19848.7 327958 0.1 + 672 0.0000014 0.00000023 489.27 22976.8 364039 0.1 + 675 0.0000035 0.00000024 195.05 9166.3 144484 0.0 + 686 0.0000025 0.00000023 274.30 12922.2 199924 0.0 + 700 0.0000017 0.00000024 420.54 19873.3 300389 0.0 + 720 0.0000012 0.00000023 599.40 28447.2 416251 0.1 + 729 0.0000048 0.00000024 150.48 7155.4 103213 0.0 + 735 0.0000041 0.00000024 180.62 8599.0 122871 0.0 + 750 0.0000024 0.00000025 306.71 14646.4 204471 0.0 + 756 0.0000019 0.00000024 403.45 19289.5 266833 0.0 + 768 0.0000009 0.00000022 868.76 41635.2 565599 0.1 + 784 0.0000018 0.00000024 427.41 20547.0 272581 0.0 + 800 0.0000013 0.00000022 592.60 28575.0 370378 0.1 + 810 0.0000030 0.00000024 270.48 13066.5 166962 0.0 + 840 0.0000018 0.00000023 465.39 22604.7 277019 0.1 + 864 0.0000017 0.00000023 498.16 24297.5 288287 0.1 + 875 0.0000053 0.00000025 165.78 8101.0 94732 0.0 + 882 0.0000034 0.00000024 259.19 12680.3 146932 0.0 + 896 0.0000017 0.00000023 529.41 25960.5 295429 0.1 + 900 0.0000021 0.00000023 435.99 21393.5 242216 0.1 + 945 0.0000059 0.00000024 161.31 7972.0 85348 0.0 + 960 0.0000018 0.00000022 539.97 26747.3 281236 0.1 + 972 0.0000024 0.00000024 404.45 20070.6 208052 0.0 + 980 0.0000026 0.00000024 371.13 18439.1 189354 0.0 + 1000 0.0000022 0.00000025 463.68 23104.6 231839 0.0 + 1008 0.0000021 0.00000023 474.10 23651.3 235170 0.1 + 1024 0.0000012 0.00000023 847.54 42376.9 413837 0.0 + 1029 0.0000077 0.00000026 133.62 6685.7 64927 0.0 + 1050 0.0000032 0.00000024 326.84 16401.2 155639 0.0 + 1080 0.0000024 0.00000023 456.54 23002.6 211363 0.1 + 1120 0.0000023 0.00000024 491.10 24872.6 219242 0.1 + 1125 0.0000069 0.00000026 162.30 8225.3 72135 0.0 + 1134 0.0000045 0.00000026 253.71 12872.2 111865 0.0 + 1152 0.0000022 0.00000024 516.81 26279.7 224311 0.1 + 1176 0.0000032 0.00000024 362.22 18472.7 154006 0.0 + 1200 0.0000021 0.00000023 580.19 29673.2 241745 0.1 + 1215 0.0000074 0.00000025 164.15 8410.2 67553 0.0 + 1225 0.0000072 0.00000026 169.83 8711.1 69319 0.0 + 1250 0.0000042 0.00000028 298.40 15349.0 119358 0.0 + 1260 0.0000033 0.00000024 381.43 19642.0 151360 0.1 + 1280 0.0000016 0.00000022 806.55 41625.8 315059 0.1 + 1296 0.0000027 0.00000023 487.92 25225.3 188242 0.1 + 1323 0.0000100 0.00000027 132.33 6860.9 50010 0.0 + 1344 0.0000028 0.00000025 473.87 24623.0 176291 0.1 + 1350 0.0000047 0.00000024 284.46 14790.1 105355 0.1 + 1372 0.0000050 0.00000026 275.29 14345.7 100326 0.0 + 1400 0.0000030 0.00000024 470.92 24608.3 168185 0.1 + 1440 0.0000030 0.00000022 487.29 25563.0 169199 0.2 + 1458 0.0000059 0.00000026 247.76 13019.2 84964 0.0 + 1470 0.0000044 0.00000026 331.91 17461.0 112894 0.0 + 1500 0.0000034 0.00000025 444.29 23437.8 148096 0.1 + 1512 0.0000039 0.00000026 390.46 20620.6 129120 0.1 + 1536 0.0000029 0.00000024 533.90 28256.5 173795 0.1 + 1568 0.0000039 0.00000025 405.36 21513.7 129259 0.0 + 1575 0.0000093 0.00000026 169.75 9014.5 53888 0.0 + 1600 0.0000030 0.00000024 540.70 28775.9 168970 0.1 + 1620 0.0000042 0.00000024 385.04 20525.8 118838 0.1 + 1680 0.0000030 0.00000024 563.58 30191.5 167731 0.1 + 1701 0.0000131 0.00000027 129.50 6948.9 38065 0.0 + 1715 0.0000131 0.00000027 131.06 7040.7 38211 0.0 + 1728 0.0000034 0.00000024 504.41 27124.6 145953 0.1 + 1750 0.0000067 0.00000027 259.41 13973.5 74118 0.0 + 1764 0.0000052 0.00000027 340.05 18336.6 96386 0.0 + 1792 0.0000037 0.00000026 481.92 26041.2 134463 0.1 + 1800 0.0000038 0.00000024 477.93 25841.3 132759 0.2 + 1875 0.0000126 0.00000027 149.01 8100.7 39736 0.0 + 1890 0.0000072 0.00000025 260.93 14200.0 69029 0.1 + 1920 0.0000035 0.00000024 553.23 30170.2 144071 0.2 + 1944 0.0000052 0.00000026 375.94 20535.5 96693 0.1 + 1960 0.0000052 0.00000025 379.85 20771.5 96901 0.1 + 2000 0.0000036 0.00000026 561.23 30771.5 140307 0.1 + 2016 0.0000045 0.00000025 448.89 24638.0 111332 0.2 + 2025 0.0000132 0.00000027 153.18 8412.1 37821 0.0 + 2048 0.0000029 0.00000024 713.17 39224.4 174114 0.1 + 2058 0.0000089 0.00000027 230.78 12701.0 56069 0.0 + 2100 0.0000047 0.00000025 449.06 24779.3 106918 0.1 + 2160 0.0000044 0.00000025 489.70 27121.5 113356 0.2 + 2187 0.0000181 0.00000028 120.79 6700.6 27615 0.0 + 2205 0.0000158 0.00000027 139.16 7727.8 31555 0.0 + 2240 0.0000042 0.00000025 539.63 30028.7 120454 0.1 + 2250 0.0000074 0.00000026 304.11 16932.4 67580 0.1 + 2268 0.0000059 0.00000027 382.09 21296.4 84236 0.1 + 2304 0.0000047 0.00000026 494.26 27604.4 107262 0.2 + 2352 0.0000067 0.00000027 353.04 19769.7 75051 0.1 + 2400 0.0000044 0.00000025 545.60 30632.3 113667 0.2 + 2401 0.0000186 0.00000027 129.23 7256.0 26912 0.0 + 2430 0.0000097 0.00000026 249.48 14029.1 51333 0.1 + 2450 0.0000095 0.00000026 256.73 14451.8 52393 0.0 + 2500 0.0000065 0.00000028 383.67 21653.5 76733 0.0 + 2520 0.0000067 0.00000026 377.82 21345.3 74964 0.2 + 2560 0.0000046 0.00000024 553.95 31358.8 108193 0.1 + 2592 0.0000059 0.00000026 436.68 24759.4 84236 0.2 + 2625 0.0000181 0.00000027 144.81 8223.9 27583 0.0 + 2646 0.0000123 0.00000027 214.37 12186.7 40509 0.0 + 2688 0.0000049 0.00000027 543.09 30935.5 101022 0.2 + 2700 0.0000063 0.00000025 429.38 24472.0 79515 0.2 + 2744 0.0000081 0.00000027 338.95 19357.5 61762 0.0 + 2800 0.0000059 0.00000025 477.71 27351.7 85305 0.1 + 2835 0.0000217 0.00000027 130.74 7497.6 23059 0.0 + 2880 0.0000053 0.00000024 538.84 30961.5 93549 0.3 + 2916 0.0000078 0.00000028 374.01 21524.0 64131 0.1 + 2940 0.0000083 0.00000027 356.16 20517.5 60571 0.1 + 3000 0.0000066 0.00000026 451.60 26081.7 75267 0.1 + 3024 0.0000072 0.00000027 420.31 24298.4 69495 0.2 + 3072 0.0000057 0.00000026 540.29 31296.3 87938 0.1 + 3087 0.0000236 0.00000028 130.84 7583.4 21192 0.0 + 3125 0.0000229 0.00000030 136.51 7923.9 21841 0.0 + 3136 0.0000078 0.00000027 402.13 23353.1 64115 0.1 + 3150 0.0000110 0.00000026 285.70 16601.1 45350 0.1 + 3200 0.0000058 0.00000025 555.42 32336.4 86785 0.2 + 3240 0.0000088 0.00000025 367.55 21431.2 56720 0.2 + 3360 0.0000076 0.00000025 444.14 26013.7 66092 0.2 + 3375 0.0000221 0.00000028 152.71 8949.0 22623 0.0 + 3402 0.0000154 0.00000028 220.94 12960.5 32472 0.0 + 3430 0.0000158 0.00000027 217.14 12750.4 31653 0.0 + 3456 0.0000080 0.00000027 430.06 25276.4 62219 0.2 + 3500 0.0000096 0.00000027 364.72 21469.6 52103 0.1 + 3528 0.0000095 0.00000027 370.67 21840.8 52532 0.1 + 3584 0.0000074 0.00000027 483.27 28530.5 67420 0.1 + 3600 0.0000075 0.00000025 477.71 28218.0 66349 0.3 + 3645 0.0000281 0.00000028 129.51 7661.9 17766 0.0 + 3675 0.0000273 0.00000028 134.51 7965.5 18301 0.0 + 3750 0.0000135 0.00000028 276.95 16440.4 36926 0.1 + 3780 0.0000099 0.00000026 380.25 22595.0 50298 0.2 + 3840 0.0000077 0.00000025 496.09 29534.4 64595 0.3 + 3888 0.0000103 0.00000027 378.60 22573.5 48688 0.2 + 3920 0.0000096 0.00000027 408.82 24400.0 52146 0.1 + 3969 0.0000319 0.00000029 124.45 7438.8 15678 0.0 + 4000 0.0000085 0.00000026 472.65 28278.0 59081 0.1 + 4032 0.0000100 0.00000027 402.14 24082.9 49869 0.2 + 4050 0.0000153 0.00000027 265.12 15885.7 32731 0.1 + 4096 0.0000059 0.00000027 696.50 41790.0 85022 0.1 + 4116 0.0000124 0.00000028 332.84 19982.4 40433 0.0 + 4200 0.0000117 0.00000026 359.28 21621.6 42771 0.2 + 4320 0.0000101 0.00000026 426.70 25766.1 49387 0.3 + 4374 0.0000218 0.00000029 200.70 12136.9 22942 0.0 + 4375 0.0000322 0.00000030 136.01 8225.2 15544 0.0 + 4410 0.0000176 0.00000027 250.61 15170.2 28414 0.1 + 4480 0.0000101 0.00000027 443.07 26870.7 49450 0.2 + 4500 0.0000099 0.00000027 453.25 27502.5 50361 0.2 + 4536 0.0000132 0.00000028 343.51 20863.5 37865 0.2 + 4608 0.0000087 0.00000026 530.82 32300.4 57598 0.3 + 4704 0.0000133 0.00000028 354.07 21597.7 37635 0.1 + 4725 0.0000342 0.00000028 138.26 8438.3 14631 0.1 + 4800 0.0000090 0.00000025 533.64 32628.6 55587 0.3 + 4802 0.0000229 0.00000028 209.42 12805.7 21806 0.0 + 4860 0.0000132 0.00000027 367.40 22497.1 37798 0.2 + 4900 0.0000142 0.00000028 346.18 21218.1 35324 0.1 + 5000 0.0000113 0.00000028 444.29 27296.5 44429 0.1 + 5040 0.0000128 0.00000027 394.86 24282.6 39173 0.3 + 5103 0.0000446 0.00000030 114.34 7041.6 11203 0.0 + 5120 0.0000098 0.00000026 521.01 32099.3 50880 0.2 + 5145 0.0000399 0.00000029 128.91 7946.8 12528 0.0 + 5184 0.0000123 0.00000027 420.36 25935.9 40544 0.3 + 5250 0.0000234 0.00000028 224.25 13856.4 21357 0.1 + 5292 0.0000168 0.00000028 315.03 19484.1 29765 0.1 + 5376 0.0000108 0.00000027 497.46 30823.6 46267 0.3 + 5400 0.0000141 0.00000027 383.92 23800.5 35548 0.3 + 5488 0.0000161 0.00000029 340.78 21166.1 31048 0.1 + 5600 0.0000135 0.00000026 415.84 25888.9 37129 0.2 + 5625 0.0000446 0.00000030 126.08 7853.2 11207 0.0 + 5670 0.0000248 0.00000028 228.69 14258.1 20167 0.1 + 5760 0.0000125 0.00000026 460.40 28756.0 39965 0.4 + 5832 0.0000191 0.00000028 305.47 19106.7 26189 0.1 + 5880 0.0000163 0.00000028 361.47 22630.7 30737 0.2 + 6000 0.0000131 0.00000027 457.74 28724.9 38145 0.3 + 6048 0.0000167 0.00000027 361.79 22724.6 29910 0.3 + 6075 0.0000448 0.00000029 135.70 8528.1 11169 0.1 + 6125 0.0000463 0.00000029 132.42 8329.7 10810 0.0 + 6144 0.0000125 0.00000028 491.26 30912.6 39979 0.2 + 6174 0.0000292 0.00000029 211.40 13309.6 17120 0.0 + 6250 0.0000274 0.00000031 228.40 14400.2 18272 0.0 + 6272 0.0000184 0.00000028 340.39 21469.9 27136 0.1 + 6300 0.0000172 0.00000027 366.74 23143.1 29106 0.3 + 6400 0.0000129 0.00000026 496.93 31415.8 38823 0.3 + 6480 0.0000158 0.00000027 408.85 25883.8 31547 0.4 + 6561 0.0000586 0.00000030 111.94 7097.1 8531 0.0 + 6615 0.0000478 0.00000029 138.25 8773.2 10450 0.0 + 6720 0.0000155 0.00000027 434.02 27591.1 32293 0.4 + 6750 0.0000256 0.00000028 263.76 16776.2 19538 0.1 + 6804 0.0000209 0.00000029 324.96 20687.2 23880 0.1 + 6860 0.0000216 0.00000028 317.04 20201.9 23108 0.1 + 6912 0.0000170 0.00000028 405.55 25864.0 29337 0.4 + 7000 0.0000181 0.00000029 387.18 24727.8 27656 0.2 + 7056 0.0000192 0.00000028 367.93 23519.1 26072 0.2 + 7168 0.0000158 0.00000028 452.40 28970.3 31557 0.2 + 7200 0.0000178 0.00000027 404.34 25905.5 28079 0.5 + 7203 0.0000697 0.00000031 103.28 6617.1 7169 0.0 + 7290 0.0000343 0.00000029 212.69 13646.1 14588 0.1 + 7350 0.0000319 0.00000029 230.38 14794.4 15672 0.1 + 7500 0.0000187 0.00000029 400.26 25762.1 26684 0.2 + 7560 0.0000189 0.00000028 400.11 25775.1 26462 0.4 + 7680 0.0000160 0.00000026 479.51 30944.8 31218 0.4 + 7776 0.0000210 0.00000028 370.78 23961.0 23841 0.3 + 7840 0.0000201 0.00000028 389.41 25188.5 24835 0.2 + 7875 0.0000617 0.00000030 127.73 8266.2 8110 0.1 + 7938 0.0000401 0.00000029 197.75 12808.9 12456 0.1 + 8000 0.0000165 0.00000027 484.90 31435.3 30306 0.3 + 8064 0.0000204 0.00000030 396.22 25709.1 24567 0.4 + 8100 0.0000207 0.00000028 390.87 25374.9 24128 0.3 + 8192 0.0000183 0.00000028 447.63 29095.8 27321 0.1 + 8232 0.0000275 0.00000029 299.20 19458.5 18173 0.1 + 8400 0.0000208 0.00000028 404.48 26364.2 24076 0.4 + 8505 0.0000675 0.00000029 125.91 8218.1 7402 0.1 + 8575 0.0000720 0.00000030 119.18 7785.7 6949 0.0 + 8640 0.0000180 0.00000026 479.09 31324.7 27725 0.6 + 8748 0.0000294 0.00000029 297.17 19456.8 16985 0.1 + 8750 0.0000399 0.00000031 219.43 14367.4 12539 0.1 + 8820 0.0000254 0.00000029 347.21 22753.5 19683 0.2 + 8960 0.0000202 0.00000027 443.13 29089.6 24728 0.4 + 9000 0.0000225 0.00000028 399.20 26219.1 22178 0.4 + 9072 0.0000254 0.00000029 357.49 23500.1 19703 0.3 + 9216 0.0000189 0.00000028 486.48 32034.2 26393 0.4 + 9261 0.0000938 0.00000031 98.72 6504.3 5330 0.0 + 9375 0.0000768 0.00000031 122.01 8049.1 6507 0.0 + 9408 0.0000244 0.00000030 385.24 25425.1 20474 0.3 + 9450 0.0000376 0.00000028 251.50 16606.8 13307 0.2 + 9600 0.0000218 0.00000027 439.93 29098.7 22913 0.6 + 9604 0.0000400 0.00000030 240.27 15893.4 12509 0.0 + 9720 0.0000255 0.00000028 380.44 25198.0 19570 0.4 + 9800 0.0000262 0.00000029 374.30 24813.5 19097 0.2 + 10000 0.0000258 0.00000029 388.34 25800.8 19417 0.2 + 10080 0.0000274 0.00000028 367.68 24449.1 18238 0.6 + 10125 0.0000802 0.00000031 126.32 8403.8 6238 0.1 + 10206 0.0000559 0.00000030 182.54 12154.8 8943 0.1 + 10240 0.0000236 0.00000027 433.52 28876.7 21168 0.3 + 10290 0.0000438 0.00000029 234.71 15642.5 11405 0.1 + 10368 0.0000267 0.00000028 387.80 25866.3 18702 0.5 + 10500 0.0000294 0.00000029 356.64 23820.4 16983 0.3 + 10584 0.0000328 0.00000030 322.81 21579.3 15250 0.2 + 10752 0.0000254 0.00000029 423.48 28356.8 19693 0.4 + 10800 0.0000276 0.00000027 391.18 26206.3 18110 0.6 + 10935 0.0000901 0.00000030 121.40 8143.9 5551 0.1 + 10976 0.0000352 0.00000030 311.98 20937.2 14212 0.1 + 11025 0.0000889 0.00000030 123.99 8324.8 5623 0.1 + 11200 0.0000295 0.00000027 380.04 25559.9 16966 0.4 + 11250 0.0000508 0.00000030 221.33 14893.1 9837 0.2 + 11340 0.0000364 0.00000029 311.85 21001.7 13750 0.4 + 11520 0.0000272 0.00000028 423.22 28550.2 18369 0.7 + 11664 0.0000359 0.00000030 324.89 21945.9 13927 0.3 + 11760 0.0000305 0.00000028 385.78 26081.5 16402 0.4 + 11907 0.0001183 0.00000032 100.69 6816.2 4228 0.0 + 12000 0.0000272 0.00000028 440.40 29838.7 18350 0.5 + 12005 0.0001191 0.00000031 100.82 6831.1 4199 0.0 + 12096 0.0000323 0.00000028 374.71 25409.5 15489 0.6 + 12150 0.0000573 0.00000029 212.19 14395.5 8732 0.2 + 12250 0.0000613 0.00000030 199.87 13571.7 8158 0.1 + 12288 0.0000282 0.00000029 435.14 29557.0 17706 0.4 + 12348 0.0000440 0.00000031 280.32 19050.8 11351 0.1 + 12500 0.0000423 0.00000032 295.23 20089.5 11809 0.1 + 12544 0.0000339 0.00000030 370.15 25197.3 14754 0.3 + 12600 0.0000383 0.00000028 329.09 22412.7 13059 0.6 + 12800 0.0000295 0.00000027 433.92 29601.7 16950 0.4 + 12960 0.0000346 0.00000028 374.49 25581.1 14448 0.7 + 13122 0.0000741 0.00000031 177.20 12120.2 6752 0.1 + 13125 0.0001062 0.00000031 123.59 8453.2 4708 0.1 + 13230 0.0000636 0.00000030 208.08 14244.8 7864 0.2 + 13440 0.0000314 0.00000028 428.14 29358.4 15928 0.8 + 13500 0.0000377 0.00000029 357.99 24559.5 13259 0.4 + 13608 0.0000466 0.00000030 291.86 20039.7 10724 0.4 + 13720 0.0000454 0.00000029 302.25 20770.7 11015 0.2 + 13824 0.0000348 0.00000030 397.41 27331.8 14374 0.6 + 14000 0.0000372 0.00000029 375.98 25892.4 13428 0.4 + 14112 0.0000433 0.00000029 325.56 22438.9 11535 0.5 + 14175 0.0001199 0.00000031 118.25 8153.8 4171 0.1 + 14336 0.0000383 0.00000030 374.63 25863.1 13066 0.3 + 14400 0.0000336 0.00000027 429.15 29640.8 14901 0.9 + 14406 0.0000829 0.00000031 173.82 12006.3 6033 0.0 + 14580 0.0000465 0.00000029 313.64 21691.2 10756 0.4 + 14700 0.0000424 0.00000029 347.04 24021.1 11804 0.4 + 15000 0.0000424 0.00000030 353.61 24527.6 11787 0.4 + 15120 0.0000415 0.00000028 364.12 25277.5 12041 0.8 + 15309 0.0001515 0.00000032 101.07 7025.4 3301 0.1 + 15360 0.0000350 0.00000028 439.11 30533.4 14294 0.7 + 15435 0.0001558 0.00000031 99.06 6891.7 3209 0.1 + 15552 0.0000445 0.00000029 349.24 24315.2 11228 0.6 + 15625 0.0001372 0.00000034 113.88 7932.3 3644 0.0 + 15680 0.0000387 0.00000029 405.01 28222.7 12915 0.4 + 15750 0.0000694 0.00000030 227.05 15829.0 7208 0.3 + 15876 0.0000592 0.00000031 268.24 18715.9 8448 0.2 + 16000 0.0000388 0.00000028 412.45 28800.8 12889 0.5 + 16128 0.0000411 0.00000030 392.62 27438.8 12172 0.7 + 16200 0.0000461 0.00000028 351.77 24595.0 10857 0.7 + 16384 0.0000455 0.00000029 360.22 25215.3 10993 0.3 + 16464 0.0000542 0.00000031 303.56 21260.1 9219 0.2 + 16800 0.0000485 0.00000028 346.72 24333.0 10319 0.9 + 16807 0.0001743 0.00000032 96.44 6768.4 2869 0.0 + 16875 0.0001448 0.00000032 116.54 8182.5 3453 0.1 + 17010 0.0000840 0.00000030 202.52 14231.3 5953 0.3 + 17150 0.0000919 0.00000031 186.59 13122.9 5440 0.1 + 17280 0.0000379 0.00000027 455.67 32072.2 13185 1.0 + 17496 0.0000633 0.00000031 276.51 19486.5 7902 0.3 + 17500 0.0000579 0.00000031 302.08 21289.5 8631 0.2 + 17640 0.0000559 0.00000029 315.72 22268.7 8949 0.5 + 17920 0.0000448 0.00000028 400.01 28259.3 11161 0.6 + 18000 0.0000458 0.00000029 392.98 27775.0 10916 0.8 + 18144 0.0000529 0.00000030 343.25 24280.0 9459 0.7 + 18225 0.0001575 0.00000032 115.73 8189.9 3175 0.1 + 18375 0.0001619 0.00000031 113.48 8037.8 3088 0.1 + 18432 0.0000451 0.00000029 408.75 28959.6 11088 0.6 + 18522 0.0001088 0.00000032 170.22 12065.8 4595 0.1 + 18750 0.0000867 0.00000032 216.38 15356.8 5770 0.2 + 18816 0.0000505 0.00000031 372.74 26464.3 9905 0.5 + 18900 0.0000578 0.00000029 326.97 23224.8 8650 0.7 + 19200 0.0000456 0.00000028 421.06 29955.6 10965 1.0 + 19208 0.0000736 0.00000031 261.00 18569.3 6794 0.1 + 19440 0.0000577 0.00000029 337.09 24012.1 8670 0.8 + 19600 0.0000529 0.00000029 370.24 26395.7 9445 0.5 + 19683 0.0002074 0.00000032 94.91 6769.4 2411 0.0 + 19845 0.0001979 0.00000031 100.30 7159.4 2527 0.1 + 20000 0.0000547 0.00000030 365.92 26140.8 9148 0.5 + 20160 0.0000535 0.00000028 376.95 26950.6 9349 1.2 + 20250 0.0001029 0.00000030 196.79 14076.0 4859 0.4 + 20412 0.0000805 0.00000031 253.56 18151.1 6211 0.3 + 20480 0.0000516 0.00000029 397.07 28433.8 9694 0.5 + 20580 0.0000760 0.00000031 270.83 19403.8 6580 0.3 + 20736 0.0000604 0.00000031 343.14 24602.8 8274 0.9 + 21000 0.0000636 0.00000030 330.33 23714.6 7865 0.7 + 21168 0.0000701 0.00000031 301.81 21684.7 7129 0.5 + 21504 0.0000597 0.00000030 360.19 25920.0 8375 0.7 + 21600 0.0000565 0.00000028 382.32 27524.6 8850 1.2 + 21609 0.0002164 0.00000032 99.88 7190.8 2311 0.0 + 21870 0.0001233 0.00000031 177.41 12788.3 4056 0.3 + 21875 0.0002032 0.00000033 107.67 7761.3 2461 0.1 + 21952 0.0000757 0.00000032 290.03 20914.1 6606 0.3 + 22050 0.0001093 0.00000030 201.71 14552.1 4574 0.4 + 22400 0.0000564 0.00000029 396.97 28683.7 8861 0.8 + 22500 0.0000699 0.00000031 322.02 23278.2 7156 0.6 + 22680 0.0000814 0.00000030 278.47 20145.7 6139 0.9 + 23040 0.0000606 0.00000029 379.93 27529.4 8245 1.2 + 23328 0.0000875 0.00000031 266.55 19337.6 5713 0.7 + 23520 0.0000743 0.00000030 316.53 22982.8 6729 0.8 + 23625 0.0002339 0.00000032 101.02 7338.1 2138 0.2 + 23814 0.0001577 0.00000032 150.98 10975.9 3170 0.2 + 24000 0.0000668 0.00000029 359.14 26128.5 7482 1.2 + 24010 0.0001425 0.00000031 168.45 12256.2 3508 0.1 + 24192 0.0000742 0.00000030 325.91 23730.2 6736 1.1 + 24300 0.0000797 0.00000030 304.77 22200.5 6271 0.7 + 24500 0.0000825 0.00000031 296.99 21651.2 6061 0.3 + 24576 0.0000649 0.00000030 378.96 27635.7 7710 0.6 + 24696 0.0000931 0.00000031 265.38 19362.3 5373 0.4 + 25000 0.0000772 0.00000033 323.90 23660.3 6478 0.4 + 25088 0.0000835 0.00000031 300.50 21958.9 5989 0.5 + 25200 0.0000689 0.00000029 365.80 26742.3 7258 1.4 + 25515 0.0002475 0.00000031 103.08 7545.0 2020 0.2 + 25600 0.0000713 0.00000027 359.22 26301.8 7016 0.8 + 25725 0.0002516 0.00000031 102.23 7488.9 1987 0.1 + 25920 0.0000849 0.00000028 305.34 22384.0 5890 1.4 + 26244 0.0001096 0.00000032 239.45 17575.3 4562 0.3 + 26250 0.0001374 0.00000032 191.10 14026.8 3640 0.4 + 26460 0.0000987 0.00000031 267.99 19685.7 5064 0.6 + 26880 0.0000784 0.00000029 342.77 25218.3 6376 1.4 + 27000 0.0000840 0.00000029 321.41 23656.7 5952 1.1 + 27216 0.0000975 0.00000031 279.24 20568.8 5130 0.9 + 27440 0.0001013 0.00000030 270.83 19965.8 4935 0.4 + 27648 0.0000705 0.00000030 392.05 28923.2 7090 1.0 + 27783 0.0002907 0.00000032 95.57 7054.2 1720 0.1 + 28000 0.0000893 0.00000030 313.43 23151.9 5597 0.9 + 28125 0.0002769 0.00000034 101.59 7507.1 1806 0.2 + 28224 0.0000984 0.00000030 286.76 21197.9 5080 1.0 + 28350 0.0001497 0.00000030 189.32 14001.3 3339 0.6 + 28672 0.0000857 0.00000031 334.37 24755.9 5831 0.5 + 28800 0.0000829 0.00000029 347.27 25721.9 6029 1.7 + 28812 0.0001276 0.00000032 225.89 16731.8 3920 0.2 + 29160 0.0001102 0.00000031 264.60 19622.2 4537 0.9 + 29400 0.0001008 0.00000030 291.77 21654.2 4962 0.9 + 30000 0.0000835 0.00000031 359.22 26712.8 5987 1.0 + 30240 0.0000988 0.00000030 306.15 22783.9 5062 1.7 + 30375 0.0002852 0.00000032 106.49 7928.9 1753 0.2 + 30618 0.0001878 0.00000032 163.01 12146.0 2662 0.3 + 30625 0.0003047 0.00000033 100.51 7489.3 1641 0.1 + 30720 0.0000844 0.00000029 363.91 27123.8 5923 1.2 + 30870 0.0001949 0.00000031 158.36 11809.1 2565 0.3 + 31104 0.0000896 0.00000030 347.31 25917.5 5583 1.2 + 31250 0.0001815 0.00000035 172.19 12855.1 2755 0.2 + 31360 0.0001111 0.00000030 282.18 21073.9 4499 0.8 + 31500 0.0000978 0.00000030 322.06 24062.5 5112 1.0 + 31752 0.0001141 0.00000032 278.27 20807.4 4382 0.6 + 32000 0.0000862 0.00000029 371.20 27776.5 5800 1.0 + 32256 0.0000918 0.00000031 351.46 26319.7 5448 1.4 + 32400 0.0000946 0.00000030 342.53 25662.1 5286 1.6 + 32768 0.0000959 0.00000029 341.70 25627.9 5214 0.5 + 32805 0.0003406 0.00000032 96.32 7224.4 1468 0.2 + 32928 0.0001104 0.00000032 298.13 22370.2 4527 0.5 + 33075 0.0003220 0.00000032 102.73 7711.7 1553 0.2 + 33600 0.0001107 0.00000029 303.48 22815.5 4516 1.8 + 33614 0.0001914 0.00000032 175.60 13202.3 2612 0.0 + 33750 0.0001693 0.00000031 199.40 14997.1 2954 0.5 + 34020 0.0001344 0.00000031 253.11 19051.6 3720 1.0 + 34300 0.0001505 0.00000031 227.89 17166.8 3322 0.4 + 34560 0.0001178 0.00000030 293.35 22113.6 4244 1.9 + 34992 0.0001258 0.00000031 278.26 21001.0 3976 0.9 + 35000 0.0001276 0.00000032 274.19 20694.6 3917 0.7 + 35280 0.0001219 0.00000031 289.51 21867.3 4103 1.3 + 35721 0.0003934 0.00000033 90.80 6866.7 1271 0.1 + 35840 0.0001169 0.00000029 306.50 23185.9 4276 1.1 + 36000 0.0000960 0.00000029 375.05 28383.1 5209 1.7 + 36015 0.0003631 0.00000032 99.19 7506.5 1377 0.1 + 36288 0.0001219 0.00000031 297.71 22547.1 4102 1.5 + 36450 0.0002147 0.00000031 169.78 12864.2 2329 0.6 + 36750 0.0002094 0.00000031 175.52 13309.1 2388 0.4 + 36864 0.0001286 0.00000030 286.58 21737.0 3887 1.4 + 37044 0.0001786 0.00000032 207.37 15736.4 2799 0.4 + 37500 0.0001390 0.00000033 269.85 20501.3 3598 0.7 + 37632 0.0001412 0.00000032 266.59 20260.0 3542 1.0 + 37800 0.0001342 0.00000030 281.76 21422.4 3727 1.7 + 38400 0.0001153 0.00000029 333.16 25368.0 4338 1.8 + 38416 0.0001544 0.00000032 248.78 18944.0 3238 0.2 + 38880 0.0001337 0.00000030 290.82 22170.5 3740 1.8 + 39200 0.0001433 0.00000030 273.46 20863.0 3488 1.1 + 39366 0.0002812 0.00000033 139.99 10684.2 1778 0.2 + 39375 0.0004006 0.00000033 98.28 7501.2 1248 0.3 + 39690 0.0002349 0.00000032 169.00 12908.6 2129 0.5 + 40000 0.0001257 0.00000031 318.32 24331.9 3979 1.1 + 40320 0.0001305 0.00000031 308.93 23632.1 3831 2.4 + 40500 0.0001572 0.00000030 257.66 19718.3 3181 1.2 + 40824 0.0001836 0.00000032 222.41 17033.3 2724 1.0 + 40960 0.0001444 0.00000030 283.69 21733.3 3463 0.9 + 41160 0.0001686 0.00000031 244.16 18713.7 2966 0.8 + 41472 0.0001338 0.00000032 309.96 23773.8 3737 1.6 + 42000 0.0001414 0.00000030 297.02 22808.6 3536 1.7 + 42336 0.0001521 0.00000031 278.40 21394.6 3288 1.2 + 42525 0.0004352 0.00000032 97.72 7512.9 1149 0.4 + 42875 0.0004533 0.00000032 94.58 7277.1 1103 0.1 + 43008 0.0001397 0.00000031 307.85 23692.7 3579 1.3 + 43200 0.0001386 0.00000029 311.73 24001.3 3608 2.5 + 43218 0.0002734 0.00000033 158.09 12172.5 1829 0.2 + 43740 0.0001801 0.00000032 242.84 18719.3 2776 1.0 + 43750 0.0002565 0.00000034 170.54 13145.9 1949 0.3 + 43904 0.0001640 0.00000033 267.73 20644.5 3049 0.6 + 44100 0.0001684 0.00000031 261.95 20207.8 2970 1.2 + 44800 0.0001340 0.00000030 334.39 25833.4 3732 1.6 + 45000 0.0001526 0.00000031 294.93 22794.6 3277 1.5 + 45360 0.0001649 0.00000031 275.06 21274.9 3032 2.2 + 45927 0.0005208 0.00000033 88.18 6828.2 960 0.2 + 46080 0.0001412 0.00000029 326.34 25277.9 3541 2.3 + 46305 0.0004562 0.00000032 101.50 7865.7 1096 0.2 + 46656 0.0001729 0.00000031 269.86 20927.2 2892 1.6 + 46875 0.0004873 0.00000035 96.19 7462.5 1026 0.2 + 47040 0.0001553 0.00000030 302.84 23503.1 3219 1.6 + 47250 0.0002550 0.00000031 185.31 14387.8 1961 1.0 + 47628 0.0002223 0.00000033 214.23 16645.2 2249 0.7 + 48000 0.0001499 0.00000029 320.26 24901.1 3336 2.2 + 48020 0.0002190 0.00000032 219.26 17048.9 2283 0.4 + 48384 0.0001638 0.00000032 295.43 22988.0 3053 2.2 + 48600 0.0001913 0.00000030 254.08 19778.5 2614 1.9 + 49000 0.0001825 0.00000032 268.52 20918.4 2740 0.9 + 49152 0.0001710 0.00000031 287.44 22398.8 2924 1.1 + 49392 0.0002032 0.00000032 243.11 18952.6 2461 0.9 + 50000 0.0001707 0.00000033 292.90 22860.3 2929 0.9 + 50176 0.0001932 0.00000032 259.71 20276.6 2588 1.0 + 50400 0.0001728 0.00000030 291.72 22784.6 2894 2.9 + 50421 0.0006211 0.00000034 81.18 6340.7 805 0.1 + 50625 0.0005382 0.00000034 94.06 7349.7 929 0.3 + 51030 0.0003058 0.00000032 166.87 13048.3 1635 0.8 + 51200 0.0001645 0.00000028 311.19 24341.3 3039 1.4 + 51450 0.0003025 0.00000032 170.09 13310.6 1653 0.5 + 51840 0.0001724 0.00000030 300.78 23553.4 2901 2.8 + 52488 0.0002327 0.00000032 225.59 17686.2 2149 0.9 + 52500 0.0001996 0.00000032 263.02 20621.2 2505 1.2 + 52920 0.0002064 0.00000031 256.45 20120.5 2423 1.5 + 53760 0.0001695 0.00000030 317.18 24921.5 2950 2.6 + 54000 0.0001765 0.00000030 305.96 24049.8 2833 2.4 + 54432 0.0002042 0.00000032 266.50 20963.0 2448 1.9 + 54675 0.0005855 0.00000033 93.38 7348.7 854 0.4 + 54880 0.0002320 0.00000031 236.53 18619.9 2155 1.0 + 55125 0.0006090 0.00000033 90.52 7128.3 821 0.4 + 55296 0.0001832 0.00000031 301.81 23774.6 2729 1.9 + 55566 0.0003852 0.00000033 144.25 11368.2 1298 0.4 + 56000 0.0001928 0.00000030 290.53 22912.7 2594 1.9 + 56250 0.0003463 0.00000033 162.45 12817.0 1444 0.8 + 56448 0.0002130 0.00000033 264.97 20912.0 2347 2.1 + 56700 0.0002266 0.00000031 250.27 19760.4 2207 2.0 + 57344 0.0002083 0.00000031 275.25 21755.0 2400 1.0 + 57600 0.0001936 0.00000030 297.45 23518.8 2582 3.3 + 57624 0.0002451 0.00000032 235.11 18590.3 2040 0.5 + 58320 0.0002113 0.00000031 275.97 21845.4 2366 2.3 + 58800 0.0002016 0.00000031 291.65 23103.7 2480 2.0 + 59049 0.0006702 0.00000034 88.10 6981.8 746 0.1 + 59535 0.0006477 0.00000033 91.92 7290.1 772 0.3 + 60000 0.0002087 0.00000031 287.52 22818.6 2396 2.1 + 60025 0.0006242 0.00000033 96.16 7631.9 801 0.1 + 60480 0.0001962 0.00000031 308.33 24487.6 2549 3.6 + 60750 0.0003455 0.00000031 175.81 13968.7 1447 1.0 + 61236 0.0002616 0.00000033 234.04 18608.9 1911 1.0 + 61250 0.0003660 0.00000033 167.34 13305.2 1366 0.5 + 61440 0.0002035 0.00000031 301.92 24012.7 2457 2.3 + 61740 0.0002830 0.00000032 218.19 17361.2 1767 1.1 + 62208 0.0002234 0.00000032 278.44 22170.8 2238 2.4 + 62500 0.0002622 0.00000035 238.38 18988.4 1907 0.6 + 62720 0.0002109 0.00000031 297.42 23699.2 2371 1.6 + 63000 0.0002270 0.00000031 277.58 22127.2 2203 2.7 + 63504 0.0002682 0.00000032 236.74 18885.6 1864 1.6 + 64000 0.0002108 0.00000030 303.62 24237.3 2372 1.8 + 64512 0.0002236 0.00000032 288.50 23047.0 2236 2.6 + 64800 0.0002272 0.00000030 285.25 22796.7 2201 3.4 + 64827 0.0007764 0.00000034 83.50 6673.2 644 0.1 + 65536 0.0002420 0.00000030 270.79 21663.6 2066 1.1 + 65610 0.0004198 0.00000033 156.28 12503.9 1191 0.8 + 65625 0.0007321 0.00000034 89.64 7172.4 683 0.4 + 65856 0.0002538 0.00000033 259.47 20766.9 1970 1.2 + 66150 0.0003937 0.00000032 168.02 13453.0 1270 1.1 + 67200 0.0002390 0.00000031 281.16 22544.0 2092 3.6 + 67228 0.0003521 0.00000034 190.93 15309.3 1420 0.2 + 67500 0.0002573 0.00000032 262.30 21040.3 1943 1.8 + 68040 0.0002719 0.00000032 250.25 20087.8 1839 2.6 + 68600 0.0002825 0.00000032 242.84 19507.6 1770 1.0 + 69120 0.0002535 0.00000031 272.61 21913.4 1972 3.6 + 69984 0.0002955 0.00000032 236.83 19058.2 1692 2.1 + 70000 0.0002608 0.00000032 268.38 21598.0 1917 1.7 + 70560 0.0002518 0.00000031 280.26 22570.5 1986 2.6 + 70875 0.0007728 0.00000034 91.71 7388.8 647 0.7 + 71442 0.0004836 0.00000034 147.74 11911.3 1034 0.6 + 71680 0.0002611 0.00000031 274.53 22140.2 1915 2.1 + 72000 0.0002371 0.00000031 303.70 24501.8 2109 3.7 + 72030 0.0004730 0.00000032 152.27 12285.5 1057 0.5 + 72576 0.0002746 0.00000032 264.32 21340.3 1821 3.2 + 72900 0.0003010 0.00000032 242.17 19559.9 1661 2.1 + 73500 0.0002952 0.00000032 249.02 20127.5 1694 1.5 + 73728 0.0002459 0.00000033 299.78 24236.9 2033 2.4 + 74088 0.0003406 0.00000033 217.52 17594.2 1468 1.0 + 75000 0.0002815 0.00000034 266.40 21571.2 1776 1.9 + 75264 0.0003071 0.00000033 245.06 19849.4 1628 2.0 + 75600 0.0002843 0.00000031 265.96 21550.9 1759 4.0 + 76545 0.0008278 0.00000033 92.47 7500.9 604 0.5 + 76800 0.0002579 0.00000030 297.83 24167.2 1939 3.3 + 76832 0.0003425 0.00000034 224.35 18205.3 1460 0.7 + 77175 0.0008772 0.00000033 87.98 7142.1 570 0.4 + 77760 0.0002851 0.00000031 272.78 22159.1 1754 4.0 + 78125 0.0008929 0.00000037 87.50 7110.9 560 0.2 + 78400 0.0002887 0.00000031 271.58 22077.3 1732 2.6 + 78732 0.0003876 0.00000034 203.13 16519.1 1290 1.0 + 78750 0.0004845 0.00000033 162.54 13218.6 1032 1.5 + 79380 0.0003794 0.00000032 209.25 17028.9 1318 1.8 + 80000 0.0002595 0.00000032 308.32 25109.1 1927 2.3 + 80640 0.0002695 0.00000032 299.17 24381.5 1855 4.9 + 81000 0.0002902 0.00000031 279.13 22756.6 1723 3.1 + 81648 0.0003487 0.00000033 234.17 19104.6 1434 2.5 + 81920 0.0002927 0.00000031 279.84 22837.5 1708 1.8 + 82320 0.0003546 0.00000032 232.14 18953.2 1410 2.0 + 82944 0.0002941 0.00000033 282.01 23040.0 1700 3.3 + 83349 0.0010776 0.00000035 77.35 6322.0 464 0.2 + 84000 0.0002761 0.00000031 304.25 24884.6 1811 3.9 + 84035 0.0010799 0.00000034 77.82 6364.9 463 0.1 + 84375 0.0009542 0.00000035 88.43 7235.2 524 0.6 + 84672 0.0003272 0.00000032 258.76 21178.8 1528 2.7 + 85050 0.0005371 0.00000032 158.36 12966.8 931 1.8 + 85750 0.0005794 0.00000033 148.00 12127.4 863 0.5 + 86016 0.0003270 0.00000032 263.04 21558.9 1529 2.6 + 86400 0.0003056 0.00000030 282.70 23179.7 1636 5.1 + 86436 0.0004230 0.00000034 204.33 16754.8 1182 0.8 + 87480 0.0003959 0.00000032 220.97 18138.3 1263 2.7 + 87500 0.0003906 0.00000034 224.00 18387.0 1280 1.2 + 87808 0.0003658 0.00000034 240.07 19712.0 1367 1.2 + 88200 0.0003559 0.00000032 247.84 20358.4 1405 3.3 + 89600 0.0003139 0.00000030 285.47 23481.3 1593 3.1 + 90000 0.0003228 0.00000032 278.82 22943.6 1549 3.8 + 90720 0.0003501 0.00000031 259.10 21335.5 1428 5.0 + 91125 0.0010163 0.00000034 89.67 7386.6 492 0.6 + 91854 0.0006935 0.00000034 132.45 10918.8 721 0.8 + 91875 0.0010246 0.00000034 89.67 7392.1 488 0.5 + 92160 0.0003119 0.00000031 295.46 24363.8 1603 4.3 + 92610 0.0006135 0.00000033 150.95 12452.9 815 1.0 + 93312 0.0003674 0.00000032 254.00 20967.0 1361 3.6 + 93750 0.0006075 0.00000036 154.31 12743.5 823 1.0 + 94080 0.0003762 0.00000032 250.06 20657.3 1329 3.3 + 94500 0.0003925 0.00000032 240.79 19898.6 1274 3.3 + 95256 0.0004717 0.00000033 201.94 16700.2 1060 1.9 + 96000 0.0003344 0.00000031 287.04 23753.6 1495 4.2 + 96040 0.0004405 0.00000032 218.01 18041.9 1135 1.0 + 96768 0.0003720 0.00000033 260.11 21540.2 1344 4.2 + 97200 0.0003776 0.00000031 257.39 21322.7 1324 4.5 + 98000 0.0003858 0.00000032 254.02 21058.6 1296 2.1 + 98304 0.0003660 0.00000032 268.57 22270.8 1366 2.2 + 98415 0.0010823 0.00000034 90.94 7541.5 462 0.5 + 98784 0.0004003 0.00000033 246.76 20471.4 1249 2.0 + 99225 0.0011111 0.00000034 89.30 7411.4 450 0.7 + 100000 0.0003320 0.00000034 301.20 25014.1 1506 2.1 + 100352 0.0003808 0.00000033 263.52 21891.9 1313 2.2 + 100800 0.0003429 0.00000031 293.93 24427.5 1458 6.3 + 100842 0.0007576 0.00000034 133.11 11062.7 660 0.3 + 101250 0.0005741 0.00000032 176.38 14663.6 871 1.7 + 102060 0.0004831 0.00000033 211.26 17576.2 1035 2.9 + 102400 0.0003608 0.00000031 283.85 23622.0 1386 3.0 + 102900 0.0004634 0.00000032 222.06 18487.3 1079 1.8 + 103680 0.0003956 0.00000031 262.10 21835.5 1264 5.6 + 104976 0.0004263 0.00000033 246.27 20538.9 1173 2.7 + 105000 0.0004132 0.00000033 254.10 21192.0 1210 3.4 + 105840 0.0004006 0.00000032 264.18 22047.6 1248 3.5 + 107163 0.0014368 0.00000035 74.59 6231.4 348 0.4 + 107520 0.0003840 0.00000031 279.98 23398.4 1302 5.2 + 108000 0.0004019 0.00000031 268.70 22464.6 1244 5.5 + 108045 0.0012690 0.00000034 85.14 7118.2 394 0.4 + 108864 0.0004448 0.00000032 244.73 20474.0 1124 4.7 + 109350 0.0007174 0.00000033 152.43 12757.6 697 1.9 + 109375 0.0012346 0.00000037 88.59 7414.8 405 0.4 + 109760 0.0004244 0.00000033 258.59 21649.5 1178 2.0 + 110250 0.0007215 0.00000033 152.81 12797.9 693 1.7 + 110592 0.0003900 0.00000033 283.56 23754.9 1282 3.6 + 111132 0.0005814 0.00000034 191.15 16020.0 860 1.2 + 112000 0.0004263 0.00000031 262.75 22035.9 1173 3.8 + 112500 0.0004348 0.00000034 258.75 21708.6 1150 2.7 + 112896 0.0004333 0.00000033 260.56 21867.4 1154 4.6 + 113400 0.0004690 0.00000032 241.77 20297.8 1066 5.2 + 114688 0.0004708 0.00000032 243.60 20471.1 1062 2.0 + 115200 0.0003639 0.00000030 316.57 26613.7 1374 6.7 + 115248 0.0005507 0.00000034 209.29 17595.4 908 1.4 + 116640 0.0004570 0.00000032 255.21 21478.0 1094 5.3 + 117600 0.0004798 0.00000032 245.08 20639.9 1042 4.3 + 117649 0.0015432 0.00000035 76.24 6420.7 324 0.1 + 118098 0.0008913 0.00000035 132.51 11163.4 561 0.8 + 118125 0.0013889 0.00000034 85.05 7165.4 360 1.1 + 119070 0.0008052 0.00000033 147.88 12467.8 621 1.6 + 120000 0.0004550 0.00000032 263.76 22251.7 1099 4.7 + 120050 0.0008772 0.00000033 136.86 11546.1 570 0.7 + 120960 0.0004216 0.00000031 286.92 24221.8 1186 7.7 + 121500 0.0005176 0.00000032 234.74 19824.3 966 3.6 + 122472 0.0006173 0.00000034 198.40 16767.3 810 2.9 + 122500 0.0005727 0.00000034 213.88 18075.9 873 1.6 + 122880 0.0004325 0.00000032 284.10 24016.1 1156 4.4 + 123480 0.0005525 0.00000033 223.50 18901.2 905 2.8 + 124416 0.0004822 0.00000032 258.04 21836.3 1037 4.7 + 125000 0.0005263 0.00000036 237.50 20106.2 950 1.9 + 125440 0.0005035 0.00000032 249.12 21096.6 993 3.0 + 126000 0.0005102 0.00000032 246.96 20921.3 980 6.4 + 127008 0.0005727 0.00000034 221.76 18798.9 873 4.1 + 127575 0.0014706 0.00000035 86.75 7356.9 340 1.2 + 128000 0.0004270 0.00000031 299.78 25429.7 1171 3.5 + 128625 0.0014706 0.00000034 87.46 7422.6 340 0.6 + 129024 0.0004785 0.00000033 269.66 22890.5 1045 5.0 + 129600 0.0004604 0.00000031 281.49 23903.8 1086 7.9 + 129654 0.0009881 0.00000035 131.21 11142.5 506 0.7 + 131072 0.0004850 0.00000031 270.27 22973.0 1031 2.1 + 131220 0.0005945 0.00000033 220.71 18762.3 841 3.0 + 131250 0.0008945 0.00000035 146.74 12474.1 559 1.9 + 131712 0.0005371 0.00000034 245.25 20854.7 931 2.5 + 132300 0.0005974 0.00000032 221.47 18839.9 837 3.7 + 134400 0.0005051 0.00000031 266.11 22667.7 990 7.4 + 134456 0.0007184 0.00000034 187.16 15943.2 696 0.6 + 135000 0.0005531 0.00000032 244.08 20798.8 904 5.0 + 136080 0.0005599 0.00000032 243.04 20724.0 893 6.5 + 137200 0.0005325 0.00000032 257.66 21986.2 939 2.4 + 137781 0.0018587 0.00000035 74.13 6327.4 269 0.5 + 138240 0.0004965 0.00000032 278.42 23772.2 1007 7.1 + 138915 0.0016611 0.00000034 83.63 7143.3 301 0.6 + 139968 0.0005794 0.00000033 241.58 20649.1 863 4.8 + 140000 0.0005394 0.00000033 259.56 22186.0 927 3.8 + 140625 0.0016393 0.00000037 85.78 7334.9 305 0.8 + 141120 0.0005005 0.00000032 281.96 24116.6 999 5.8 + 141750 0.0009208 0.00000032 153.94 13171.9 543 3.1 + 142884 0.0007440 0.00000035 192.04 16442.6 672 2.1 + 143360 0.0005701 0.00000032 251.45 21536.1 877 4.1 + 144000 0.0005365 0.00000031 268.42 22997.5 932 7.8 + 144060 0.0007564 0.00000034 190.45 16317.8 661 2.0 + 145152 0.0006010 0.00000033 241.53 20708.1 832 6.6 + 145800 0.0006579 0.00000032 221.62 19007.6 760 5.8 + 147000 0.0005767 0.00000033 254.90 21877.2 867 3.7 + 147456 0.0005441 0.00000031 271.02 23267.3 919 4.9 + 148176 0.0006831 0.00000034 216.93 18631.0 732 2.6 + 150000 0.0005308 0.00000034 282.60 24296.0 942 4.7 + 150528 0.0005889 0.00000034 255.60 21980.9 849 3.9 + 151200 0.0005695 0.00000032 265.51 22841.7 878 9.1 + 151263 0.0019305 0.00000036 78.35 6741.1 259 0.3 + 151875 0.0017668 0.00000035 85.96 7398.1 283 1.1 + 153090 0.0010823 0.00000034 141.46 12182.1 462 2.5 + 153125 0.0017921 0.00000036 85.44 7358.6 279 0.5 + 153600 0.0005441 0.00000031 282.32 24319.9 919 6.5 + 153664 0.0007728 0.00000034 198.84 17129.6 647 1.9 + 154350 0.0009901 0.00000033 155.89 13434.8 505 2.1 + 155520 0.0006519 0.00000031 238.57 20572.6 767 8.3 + 156250 0.0011547 0.00000038 135.31 11673.1 433 0.9 + 156800 0.0005959 0.00000032 263.11 22704.5 839 5.5 + 157464 0.0007987 0.00000035 197.14 17018.2 626 3.0 + 157500 0.0006720 0.00000033 234.36 20231.1 744 5.0 + 158760 0.0007610 0.00000033 208.61 18020.3 657 4.7 + 160000 0.0005952 0.00000032 268.80 23234.7 840 4.7 + 161280 0.0006024 0.00000032 267.72 23157.1 830 9.5 + 162000 0.0006112 0.00000033 265.03 22932.7 818 7.5 + 163296 0.0007364 0.00000034 221.76 19200.9 679 5.9 + 163840 0.0005995 0.00000032 273.29 23669.1 834 3.6 + 164025 0.0019455 0.00000035 84.31 7302.6 257 1.1 + 164640 0.0007519 0.00000033 218.97 18972.7 665 4.2 + 165375 0.0019455 0.00000034 85.00 7367.8 257 1.2 + 165888 0.0006596 0.00000034 251.49 21803.7 758 6.6 + 166698 0.0012346 0.00000035 135.03 11711.3 405 1.0 + 168000 0.0006105 0.00000032 275.18 23883.4 819 8.6 + 168070 0.0013477 0.00000034 124.71 10823.8 371 0.7 + 168750 0.0011312 0.00000034 149.17 12951.8 442 2.8 + 169344 0.0007184 0.00000035 235.73 20472.4 696 5.7 + 170100 0.0007987 0.00000033 212.97 18502.4 626 6.1 + 171500 0.0009009 0.00000034 190.36 16550.2 555 1.9 + 172032 0.0007052 0.00000034 243.94 21213.5 709 5.2 + 172800 0.0006313 0.00000031 273.72 23811.5 792 10.5 + 172872 0.0008850 0.00000035 195.35 16994.4 565 2.3 + 174960 0.0008197 0.00000033 213.45 18588.0 610 7.1 + 175000 0.0007874 0.00000035 222.25 19354.6 635 3.4 + 175616 0.0007407 0.00000035 237.08 20652.3 675 2.4 + 176400 0.0006993 0.00000032 252.25 21981.9 715 8.1 + 177147 0.0024752 0.00000036 71.57 6238.7 202 0.4 + 178605 0.0022727 0.00000035 78.59 6855.2 220 1.0 + 179200 0.0006916 0.00000031 259.12 22610.1 723 6.1 + 180000 0.0007072 0.00000033 254.52 22216.6 707 8.8 + 180075 0.0022831 0.00000034 78.87 6884.9 219 0.8 + 181440 0.0007924 0.00000032 228.98 20000.2 631 11.4 + 182250 0.0012107 0.00000033 150.54 13153.7 413 3.4 + 183708 0.0010246 0.00000035 179.30 15677.1 488 3.2 + 183750 0.0012723 0.00000034 144.43 12628.3 393 2.4 + 184320 0.0007194 0.00000033 256.20 22407.5 695 8.7 + 185220 0.0008757 0.00000034 211.52 18506.9 571 3.5 + 186624 0.0007849 0.00000033 237.76 20815.5 637 7.8 + 187500 0.0008183 0.00000036 229.12 20067.4 611 3.5 + 188160 0.0007396 0.00000033 254.39 22286.8 676 6.5 + 189000 0.0008052 0.00000033 234.74 20572.5 621 8.8 + 190512 0.0008897 0.00000035 214.14 18779.2 562 4.7 + 192000 0.0007321 0.00000031 262.27 23015.3 683 8.3 + 192080 0.0008183 0.00000034 234.72 20598.4 611 2.5 + 193536 0.0007440 0.00000034 260.11 22840.8 672 8.3 + 194400 0.0007911 0.00000032 245.72 21585.0 632 10.3 + 194481 0.0026455 0.00000036 73.51 6457.9 189 0.5 + 196000 0.0008651 0.00000033 226.58 19916.6 578 4.7 + 196608 0.0008000 0.00000033 245.76 21608.4 625 4.6 + 196830 0.0014451 0.00000035 136.21 11977.0 346 2.5 + 196875 0.0024272 0.00000036 81.11 7132.6 206 1.6 + 197568 0.0009025 0.00000036 218.91 19254.9 554 4.6 + 198450 0.0013193 0.00000034 150.43 13236.2 379 3.5 + 200000 0.0006897 0.00000035 290.00 25534.0 725 4.8 + 200704 0.0008117 0.00000034 247.27 21777.7 616 4.5 + 201600 0.0008347 0.00000032 241.52 21279.0 599 13.2 + 201684 0.0011086 0.00000035 181.92 16028.6 451 1.3 + 202500 0.0008897 0.00000033 227.61 20061.0 562 5.9 + 204120 0.0010246 0.00000034 199.22 17570.4 488 8.0 + 204800 0.0008091 0.00000031 253.13 22331.2 618 6.0 + 205800 0.0009346 0.00000033 220.21 19434.2 535 4.9 + 207360 0.0008993 0.00000033 230.58 20362.6 556 11.8 + 209952 0.0010730 0.00000034 195.68 17297.4 466 7.1 + 210000 0.0008834 0.00000033 237.72 21014.5 566 8.4 + 211680 0.0010163 0.00000033 208.29 18425.1 492 8.2 + 212625 0.0026882 0.00000035 79.10 6999.2 186 2.2 + 214326 0.0018868 0.00000036 113.59 10058.3 265 1.8 + 214375 0.0026596 0.00000036 80.61 7137.5 188 0.6 + 215040 0.0008264 0.00000032 260.20 23046.1 605 10.3 + 216000 0.0008547 0.00000032 252.72 22391.8 585 11.9 + 216090 0.0015723 0.00000034 137.43 12177.5 318 2.2 + 217728 0.0009398 0.00000035 231.66 20539.4 532 10.0 + 218700 0.0010753 0.00000033 203.39 18039.4 465 6.3 + 218750 0.0015480 0.00000038 141.31 12533.7 323 1.8 + 219520 0.0010040 0.00000034 218.64 19397.9 498 4.2 + 220500 0.0010142 0.00000033 217.41 19295.9 493 5.8 + 221184 0.0008726 0.00000034 253.48 22502.3 573 7.5 + 222264 0.0011521 0.00000035 192.93 17133.6 434 3.4 + 224000 0.0008772 0.00000032 255.36 22692.7 570 7.7 + 225000 0.0009980 0.00000034 225.45 20042.0 501 7.4 + 225792 0.0009242 0.00000034 244.31 21724.5 541 9.3 + 226800 0.0009579 0.00000033 236.78 21062.8 522 12.9 + 229376 0.0009158 0.00000033 250.48 22301.8 546 4.0 + 229635 0.0029586 0.00000035 77.62 6911.4 169 1.6 + 230400 0.0008547 0.00000031 269.57 24010.1 585 13.1 + 230496 0.0011364 0.00000036 202.84 18067.0 440 3.4 + 231525 0.0028571 0.00000035 81.03 7220.4 175 1.4 + 233280 0.0010352 0.00000033 225.35 20091.7 483 11.8 + 234375 0.0029762 0.00000038 78.75 7023.9 168 1.1 + 235200 0.0010309 0.00000032 228.14 20354.5 485 10.0 + 235298 0.0020243 0.00000035 116.24 10370.8 247 0.4 + 236196 0.0013369 0.00000036 176.67 15767.9 374 3.2 + 236250 0.0015723 0.00000034 150.26 13410.2 318 5.1 + 238140 0.0012690 0.00000034 187.65 16758.9 394 5.2 + 240000 0.0009328 0.00000033 257.28 22991.4 536 10.3 + 240100 0.0012255 0.00000034 195.92 17508.8 408 2.5 + 241920 0.0009980 0.00000034 242.40 21676.0 501 15.7 + 243000 0.0011038 0.00000033 220.16 19693.8 453 9.7 + 244944 0.0012165 0.00000035 201.34 18022.4 411 7.6 + 245000 0.0011416 0.00000035 214.62 19211.1 438 4.8 + 245760 0.0009940 0.00000032 247.23 22136.0 503 8.9 + 246960 0.0011416 0.00000034 216.34 19377.2 438 6.7 + 248832 0.0010040 0.00000034 247.84 22212.1 498 9.7 + 250000 0.0009921 0.00000037 252.00 22593.8 504 4.9 + 250047 0.0032895 0.00000036 76.01 6815.4 152 0.7 + 250880 0.0010593 0.00000033 236.83 21239.7 472 6.0 + 252000 0.0010417 0.00000032 241.92 21703.9 480 14.5 + 252105 0.0031056 0.00000035 81.18 7283.1 161 0.7 + 253125 0.0030303 0.00000037 83.53 7496.7 165 1.8 + 254016 0.0011494 0.00000034 220.99 19839.2 435 9.7 + 255150 0.0018315 0.00000034 139.31 12510.9 273 5.6 + 256000 0.0010163 0.00000031 251.90 22628.3 492 7.0 + 257250 0.0018450 0.00000034 139.43 12529.7 271 2.8 + 258048 0.0010482 0.00000034 246.18 22128.0 477 9.7 + 259200 0.0011013 0.00000032 235.35 21162.7 454 16.6 + 259308 0.0014663 0.00000035 176.85 15902.4 341 2.5 + 262144 0.0011442 0.00000032 229.11 20620.2 437 4.6 + 262440 0.0013850 0.00000034 189.48 17054.9 361 8.6 + 262500 0.0013193 0.00000035 198.97 17909.7 379 6.7 + 263424 0.0012019 0.00000035 219.17 19732.9 416 5.1 + 264600 0.0012953 0.00000033 204.27 18398.1 386 9.8 + 268800 0.0010776 0.00000032 249.45 22495.3 464 14.6 + 268912 0.0014409 0.00000035 186.62 16830.6 347 1.8 + 270000 0.0010730 0.00000033 251.64 22701.2 466 12.0 + 272160 0.0012690 0.00000034 214.46 19359.6 394 15.2 + 273375 0.0034247 0.00000035 79.83 7208.5 146 2.0 + 274400 0.0012107 0.00000033 226.65 20473.6 413 5.5 + 275562 0.0021930 0.00000036 125.66 11354.3 228 2.6 + 275625 0.0033784 0.00000036 81.58 7372.2 148 1.9 + 276480 0.0011261 0.00000033 245.51 22190.6 444 14.2 + 277830 0.0021645 0.00000035 128.36 11606.0 231 3.2 + 279936 0.0013514 0.00000036 207.15 18741.9 370 11.2 + 280000 0.0012469 0.00000034 224.56 20317.1 401 8.7 + 281250 0.0020000 0.00000036 140.62 12727.6 250 4.3 + 282240 0.0013587 0.00000034 207.73 18806.3 368 12.3 + 283500 0.0013699 0.00000034 206.95 18742.9 365 10.5 + 285768 0.0044248 0.00000035 64.58 5852.7 113 0.3 + 286720 0.0011287 0.00000032 254.03 23027.3 443 8.1 + 288000 0.0011962 0.00000032 240.77 21832.5 418 16.0 + 288120 0.0014327 0.00000034 201.11 18236.8 349 5.4 + 290304 0.0013123 0.00000035 221.21 20071.9 381 13.3 + 291600 0.0038760 0.00000032 75.23 6828.7 129 0.6 + 294000 0.0011905 0.00000033 246.96 22430.7 420 9.1 + 294912 0.0033333 0.00000034 88.47 8037.8 150 0.9 + 295245 0.0039370 0.00000036 74.99 6813.6 127 1.5 + 296352 0.0013850 0.00000035 213.97 19446.3 361 6.0 + 297675 0.0037879 0.00000035 78.59 7144.8 132 2.4 + 300000 0.0012887 0.00000034 232.80 21178.5 388 10.7 + 300125 0.0037594 0.00000036 79.83 7262.9 133 0.8 + 301056 0.0014045 0.00000036 214.35 19505.7 356 7.9 + 302400 0.0013477 0.00000032 224.38 20425.5 371 20.9 + 302526 0.0025253 0.00000036 119.80 10905.8 198 1.6 + 303750 0.0020408 0.00000034 148.84 13553.5 245 5.4 + 306180 0.0016026 0.00000035 191.06 17409.1 312 9.1 + 306250 0.0023474 0.00000037 130.46 11888.0 213 2.4 + 307200 0.0011338 0.00000033 270.95 24695.5 441 13.4 + 307328 0.0040000 0.00000035 76.83 7003.0 125 0.7 + 308700 0.0016667 0.00000034 185.22 16888.2 300 7.0 + 311040 0.0013587 0.00000033 228.93 20885.7 368 17.3 + 312500 0.0015385 0.00000039 203.12 18538.7 325 3.4 + 313600 0.0037037 0.00000032 84.67 7729.9 135 1.1 + 314928 0.0016779 0.00000035 187.70 17141.1 298 8.2 + 315000 0.0015576 0.00000034 202.23 18468.6 321 13.3 + 317520 0.0015625 0.00000034 203.21 18570.1 320 11.5 + 320000 0.0036496 0.00000032 87.68 8017.3 137 0.8 + 321489 0.0042373 0.00000036 75.87 6940.1 118 1.1 + 322560 0.0012853 0.00000033 250.95 22961.1 389 19.4 + 324000 0.0013812 0.00000033 234.58 21470.3 362 17.2 + 324135 0.0040000 0.00000035 81.03 7417.1 125 1.4 + 326592 0.0016393 0.00000035 199.22 18245.8 305 13.9 + 327680 0.0014368 0.00000032 228.07 20893.0 348 7.5 + 328050 0.0024390 0.00000035 134.50 12322.6 205 5.8 + 328125 0.0043103 0.00000037 76.12 6974.5 116 2.1 + 329280 0.0016181 0.00000034 203.50 18649.3 309 9.4 + 330750 0.0023474 0.00000034 140.90 12917.2 213 5.6 + 331776 0.0037594 0.00000034 88.25 8092.7 133 1.4 + 333396 0.0020080 0.00000036 166.03 15230.8 249 3.6 + 336000 0.0015528 0.00000033 216.38 19862.0 322 18.6 + 336140 0.0017921 0.00000035 187.57 17217.4 279 2.6 + 337500 0.0015106 0.00000035 223.43 20515.5 331 9.5 + 338688 0.0014409 0.00000035 235.05 21588.8 347 12.2 + 340200 0.0017857 0.00000033 190.51 17504.3 280 16.5 + 343000 0.0018657 0.00000035 183.85 16902.8 268 5.0 + 344064 0.0015152 0.00000035 227.08 20882.8 330 10.4 + 345600 0.0014577 0.00000033 237.08 21810.0 343 20.6 + 345744 0.0048544 0.00000035 71.22 6552.3 103 0.4 + 349920 0.0016835 0.00000034 207.85 19139.8 297 16.1 + 350000 0.0015106 0.00000036 231.70 21336.1 331 8.4 + 351232 0.0017921 0.00000035 195.99 18052.5 279 4.8 + 352800 0.0045045 0.00000032 78.32 7216.7 111 0.9 + 352947 0.0054945 0.00000037 64.24 5919.1 91 0.5 + 354294 0.0030488 0.00000037 116.21 10711.3 164 2.5 + 354375 0.0043860 0.00000036 80.80 7447.5 114 3.6 + 357210 0.0027933 0.00000035 127.88 11794.7 179 4.9 + 358400 0.0015480 0.00000032 231.53 21359.7 323 12.3 + 360000 0.0042373 0.00000032 84.96 7840.8 118 1.3 + 360150 0.0028090 0.00000035 128.21 11833.0 178 3.8 + 362880 0.0016447 0.00000034 220.63 20374.3 304 24.0 + 364500 0.0017857 0.00000034 204.12 18856.2 280 11.3 + 367416 0.0021008 0.00000036 174.89 16166.0 238 9.2 + 367500 0.0018382 0.00000035 199.92 18480.0 272 8.1 + 368640 0.0017065 0.00000033 216.02 19973.3 293 17.3 + 370440 0.0020000 0.00000035 185.22 17131.8 250 9.2 + 373248 0.0047170 0.00000033 79.13 7323.3 106 1.1 + 375000 0.0019084 0.00000037 196.50 18192.5 262 9.9 + 376320 0.0017065 0.00000034 220.52 20422.2 293 13.1 + 378000 0.0015480 0.00000033 244.19 22621.6 323 21.7 + 381024 0.0019841 0.00000035 192.04 17801.3 252 11.4 + 382725 0.0049020 0.00000036 78.08 7240.0 102 3.7 + 384000 0.0016835 0.00000032 228.10 21156.8 297 17.3 + 384160 0.0019608 0.00000035 195.92 18173.0 255 6.2 + 385875 0.0051546 0.00000036 74.86 6946.2 97 2.3 + 387072 0.0017606 0.00000034 219.86 20405.2 284 16.9 + 388800 0.0017544 0.00000033 221.62 20575.6 285 23.5 + 388962 0.0034247 0.00000036 113.58 10545.2 146 2.3 + 390625 0.0053763 0.00000041 72.66 6748.1 93 0.9 + 392000 0.0018587 0.00000034 210.90 19592.8 269 10.8 + 393216 0.0018450 0.00000034 213.12 19804.4 271 9.4 + 393660 0.0024155 0.00000035 162.98 15145.8 207 9.5 + 393750 0.0029240 0.00000036 134.66 12514.8 171 7.9 + 395136 0.0019685 0.00000037 200.73 18659.8 254 10.0 + 396900 0.0071429 0.00000034 55.57 5167.2 70 0.2 + 400000 0.0017730 0.00000035 225.60 20991.7 282 10.8 + 401408 0.0048544 0.00000035 82.69 7696.3 103 1.0 + 403200 0.0019305 0.00000034 208.86 19445.8 259 27.4 + 403368 0.0023697 0.00000036 170.22 15849.1 211 4.0 + 405000 0.0058824 0.00000033 68.85 6412.5 85 0.5 + 408240 0.0020921 0.00000035 195.14 18186.0 239 20.1 + 409600 0.0046729 0.00000031 87.65 8171.1 107 1.5 + 411600 0.0019531 0.00000034 210.74 19652.4 256 11.5 + 413343 0.0058824 0.00000037 70.27 6555.0 85 1.6 + 414720 0.0020833 0.00000034 199.07 18574.6 240 23.0 + 416745 0.0053763 0.00000036 77.51 7235.5 93 2.0 + 419904 0.0053191 0.00000034 78.94 7373.1 94 1.4 + 420000 0.0020243 0.00000034 207.48 19378.7 247 19.5 + 420175 0.0053763 0.00000036 78.15 7299.7 93 1.0 + 421875 0.0055556 0.00000038 75.94 7095.0 90 3.0 + 423360 0.0021459 0.00000034 197.29 18437.9 233 17.9 + 425250 0.0034965 0.00000034 121.62 11370.4 143 10.1 + 428652 0.0027174 0.00000036 157.74 14756.5 184 6.7 + 428750 0.0035971 0.00000036 119.19 11150.3 139 3.0 + 430080 0.0020408 0.00000034 210.74 19719.1 245 21.2 + 432000 0.0018519 0.00000033 233.28 21835.8 270 26.2 + 432180 0.0025510 0.00000035 169.41 15858.3 196 7.8 + 435456 0.0022321 0.00000035 195.08 18271.8 224 21.1 + 437400 0.0023474 0.00000034 186.33 17458.0 213 18.5 + 437500 0.0026596 0.00000038 164.50 15412.8 188 6.4 + 439040 0.0021834 0.00000034 201.08 18845.2 229 8.8 + 441000 0.0024390 0.00000034 180.81 16951.3 205 15.4 + 442368 0.0021097 0.00000035 209.68 19662.9 237 15.7 + 444528 0.0024631 0.00000036 180.48 16930.6 203 8.8 + 448000 0.0021834 0.00000034 205.18 19259.7 229 16.3 + 450000 0.0021739 0.00000035 207.00 19436.9 230 18.9 + 451584 0.0056818 0.00000034 79.48 7464.9 88 1.6 + 453600 0.0022222 0.00000034 204.12 19178.2 225 29.8 + 453789 0.0071429 0.00000037 63.53 5969.2 70 1.1 + 455625 0.0062500 0.00000037 72.90 6851.7 80 3.6 + 458752 0.0021645 0.00000035 211.94 19930.5 231 8.6 + 459270 0.0039683 0.00000036 115.74 10884.4 126 8.2 + 459375 0.0064103 0.00000037 71.66 6739.6 78 2.6 + 460800 0.0054945 0.00000032 83.87 7889.1 91 1.4 + 460992 0.0025773 0.00000037 178.86 16826.2 194 8.8 + 463050 0.0034014 0.00000035 136.14 12811.0 147 6.8 + 466560 0.0025510 0.00000034 182.89 17220.8 196 26.9 + 468750 0.0041322 0.00000039 113.44 10684.9 121 5.7 + 470400 0.0023585 0.00000034 199.45 18791.7 212 21.5 + 470596 0.0092593 0.00000036 50.82 4788.7 54 0.0 + 472392 0.0078125 0.00000036 60.47 5698.8 64 0.5 + 472500 0.0026178 0.00000034 180.49 17011.6 191 17.4 + 476280 0.0029070 0.00000035 163.84 15451.3 172 14.5 + 480000 0.0022124 0.00000034 216.96 20473.1 226 22.2 + 480200 0.0074627 0.00000034 64.35 6072.2 67 0.3 + 483840 0.0023041 0.00000034 209.99 19827.1 217 33.2 + 486000 0.0025510 0.00000033 190.51 17994.4 196 24.6 + 489888 0.0027933 0.00000035 175.38 16575.2 179 19.5 + 490000 0.0067568 0.00000034 72.52 6854.0 74 0.8 + 491520 0.0024272 0.00000034 202.51 19143.8 206 18.9 + 492075 0.0067568 0.00000036 72.83 6885.3 74 3.8 + 493920 0.0029586 0.00000035 166.94 15787.9 169 16.3 + 496125 0.0070423 0.00000036 70.45 6664.7 71 4.1 + 497664 0.0027473 0.00000035 181.15 17141.1 182 20.0 + 500000 0.0062500 0.00000036 80.00 7572.6 80 0.9 + 500094 0.0045045 0.00000037 111.02 10509.1 111 3.5 + 501760 0.0026882 0.00000035 186.65 17673.1 186 13.0 + 504000 0.0028409 0.00000034 177.41 16803.3 176 35.1 + 504210 0.0049020 0.00000036 102.86 9742.6 102 4.6 + 506250 0.0043860 0.00000035 115.42 10936.2 114 10.0 + 508032 0.0068493 0.00000035 74.17 7029.6 73 1.3 + 510300 0.0033784 0.00000035 151.05 14320.2 148 21.4 + 512000 0.0028902 0.00000032 177.15 16799.1 173 16.2 + 514500 0.0034722 0.00000035 148.18 14056.6 144 10.4 + 516096 0.0026738 0.00000036 193.02 18315.0 187 22.2 + 518400 0.0064103 0.00000032 80.87 7676.1 78 2.0 + 518616 0.0034014 0.00000036 152.47 14473.0 147 7.6 + 524288 0.0065789 0.00000034 79.69 7570.7 76 1.3 + 524880 0.0030120 0.00000035 174.26 16556.1 166 30.2 + 525000 0.0029940 0.00000037 175.35 16660.0 167 25.0 + 526848 0.0028571 0.00000037 184.40 17524.2 175 14.6 + 529200 0.0029762 0.00000034 177.81 16904.0 168 35.0 + 531441 0.0083333 0.00000037 63.77 6064.7 60 1.4 + 535815 0.0079365 0.00000036 67.51 6424.3 63 3.3 + 537600 0.0028736 0.00000032 187.08 17806.9 174 40.5 + 537824 0.0034722 0.00000037 154.89 14743.3 144 7.3 + 540000 0.0027174 0.00000033 198.72 18920.7 184 38.1 + 540225 0.0080645 0.00000036 66.99 6378.3 62 3.2 + 544320 0.0031646 0.00000035 172.01 16387.0 158 46.7 + 546750 0.0048544 0.00000035 112.63 10734.0 103 13.6 + 546875 0.0080645 0.00000040 67.81 6462.8 62 2.0 + 548800 0.0031447 0.00000035 174.52 16636.8 159 18.4 + 551124 0.0040323 0.00000037 136.68 13033.7 124 13.5 + 551250 0.0047619 0.00000035 115.76 11039.3 105 13.0 + 552960 0.0028409 0.00000034 194.64 18565.7 176 39.2 + 555660 0.0038760 0.00000036 143.36 13679.3 129 14.5 + 559872 0.0032468 0.00000035 172.44 16463.5 154 32.8 + 560000 0.0030675 0.00000035 182.56 17430.0 163 28.6 + 562500 0.0101562 0.00000036 55.38 5289.6 50 0.1 + 564480 0.0031847 0.00000036 177.25 16932.9 157 40.6 + 567000 0.0036232 0.00000034 156.49 14955.1 138 38.5 + 571536 0.0086207 0.00000035 66.30 6339.6 58 1.0 + 573440 0.0032258 0.00000034 177.77 17002.7 155 24.9 + 576000 0.0029586 0.00000033 194.69 18627.5 169 44.6 + 576240 0.0039370 0.00000035 146.36 14004.4 127 19.0 + 580608 0.0034965 0.00000036 166.05 15897.3 143 37.0 + 583200 0.0078125 0.00000033 74.65 7149.1 64 1.3 + 583443 0.0102041 0.00000038 57.18 5475.9 49 1.6 + 588000 0.0034247 0.00000034 171.70 16453.2 146 33.3 + 588245 0.0102041 0.00000037 57.65 5524.4 49 1.0 + 589824 0.0072464 0.00000036 81.40 7801.7 69 2.1 + 590490 0.0058140 0.00000036 101.56 9735.7 86 10.9 + 590625 0.0090909 0.00000037 64.97 6227.9 55 6.2 + 592704 0.0039683 0.00000035 149.36 14321.5 126 20.2 + 595350 0.0054348 0.00000035 109.54 10507.2 92 15.8 + 600000 0.0033784 0.00000036 177.60 17044.8 148 35.0 + 600250 0.0058140 0.00000036 103.24 9908.9 86 5.4 + 602112 0.0033557 0.00000038 179.43 17224.9 149 27.3 + 604800 0.0031447 0.00000034 192.33 18469.2 159 60.8 + 605052 0.0051020 0.00000037 118.59 11388.6 98 8.2 + 607500 0.0039370 0.00000035 154.30 14822.9 127 25.8 + 612360 0.0043478 0.00000036 140.84 13537.8 115 37.2 + 612500 0.0048077 0.00000038 127.40 12245.9 104 14.2 + 614400 0.0038760 0.00000032 158.52 15240.3 129 41.0 + 614656 0.0086207 0.00000035 71.30 6855.3 58 1.9 + 617400 0.0049020 0.00000035 125.95 12113.7 102 33.9 + 622080 0.0038462 0.00000034 161.74 15564.9 130 52.0 + 625000 0.0042017 0.00000040 148.75 14319.8 119 15.7 + 627200 0.0075758 0.00000032 82.79 7972.1 66 1.6 + 629856 0.0044248 0.00000036 142.35 13711.4 113 31.6 + 630000 0.0038462 0.00000034 163.80 15778.0 130 44.8 + 635040 0.0040650 0.00000035 156.22 15056.8 123 42.4 + 637875 0.0098039 0.00000037 65.06 6273.0 51 6.9 + 640000 0.0078125 0.00000033 81.92 7900.2 64 2.1 + 642978 0.0071429 0.00000037 90.02 8684.1 70 7.9 + 643125 0.0104167 0.00000037 61.74 5956.3 48 3.3 + 645120 0.0038760 0.00000034 166.44 16060.9 129 54.2 + 648000 0.0038760 0.00000033 167.18 16138.0 129 54.4 + 648270 0.0066667 0.00000036 97.24 9386.7 75 10.0 + 653184 0.0040650 0.00000035 160.68 15519.7 123 45.2 + 655360 0.0039370 0.00000033 166.46 16081.8 127 24.7 + 656100 0.0123857 0.00000034 52.97 5118.1 41 0.2 + 656250 0.0065789 0.00000038 99.75 9637.8 76 14.5 + 658560 0.0041667 0.00000036 158.05 15275.1 120 29.4 + 661500 0.0045045 0.00000035 146.85 14197.3 111 24.0 + 663552 0.0083333 0.00000034 79.63 7699.8 60 1.9 + 666792 0.0051020 0.00000037 130.69 12642.3 98 14.8 + 672000 0.0038462 0.00000034 174.72 16911.2 130 55.8 + 672280 0.0049020 0.00000035 137.15 13274.8 102 12.2 + 675000 0.0045045 0.00000036 149.85 14508.9 111 37.3 + 677376 0.0042735 0.00000037 158.51 15351.0 117 43.4 + 680400 0.0045455 0.00000035 149.69 14501.8 110 56.6 + 686000 0.0044643 0.00000036 153.66 14896.1 112 18.5 + 688128 0.0046729 0.00000036 147.26 14278.5 107 32.0 + 688905 0.0111111 0.00000037 62.00 6012.3 45 5.9 + 691200 0.0040984 0.00000032 168.65 16358.3 122 64.1 + 691488 0.0100000 0.00000036 69.15 6707.2 50 1.2 + 694575 0.0121951 0.00000036 56.96 5526.3 41 5.5 + 699840 0.0045455 0.00000035 153.96 14947.4 110 55.2 + 700000 0.0039370 0.00000037 177.80 17261.7 127 31.8 + 702464 0.0050000 0.00000037 140.49 13643.3 100 22.4 + 703125 0.0113636 0.00000040 61.87 6009.1 44 5.0 + 705600 0.0089286 0.00000033 79.03 7676.9 56 2.3 + 705894 0.0078125 0.00000038 90.35 8777.5 64 3.8 + 708588 0.0064935 0.00000037 109.12 10603.8 77 14.4 + 708750 0.0063291 0.00000035 111.98 10881.9 79 22.8 + 714420 0.0056818 0.00000036 125.74 12225.8 88 25.6 + 716800 0.0044643 0.00000034 160.56 15615.7 112 38.3 + 720000 0.0089286 0.00000033 80.64 7845.3 56 1.8 + 720300 0.0055556 0.00000035 129.65 12614.2 90 18.8 + 725760 0.0045455 0.00000035 159.67 15542.9 110 71.2 + 729000 0.0049020 0.00000035 148.72 14481.6 102 45.8 + 734832 0.0056180 0.00000036 130.80 12744.5 89 35.9 + 735000 0.0050000 0.00000036 147.00 14323.2 100 34.6 + 737280 0.0044643 0.00000034 165.15 16095.5 112 52.3 + 740880 0.0052632 0.00000035 140.77 13724.0 95 32.9 + 746496 0.0095814 0.00000034 77.91 7600.2 53 2.7 + 750000 0.0045872 0.00000038 163.50 15954.8 109 37.7 + 750141 0.0135135 0.00000038 55.51 5416.9 37 2.3 + 752640 0.0045455 0.00000034 165.58 16162.0 110 39.9 + 756000 0.0052632 0.00000034 143.64 14025.0 95 71.9 + 756315 0.0125000 0.00000037 60.51 5907.9 40 3.7 + 759375 0.0123857 0.00000038 61.31 5988.4 41 6.4 + 762048 0.0053191 0.00000036 143.27 13996.7 94 46.2 + 765450 0.0080645 0.00000036 94.92 9276.1 62 25.5 + 765625 0.0125000 0.00000039 61.25 5986.0 40 2.8 + 768000 0.0046296 0.00000034 165.89 16216.2 108 53.1 + 768320 0.0053191 0.00000036 144.44 14120.4 94 24.4 + 771750 0.0074627 0.00000036 103.41 10112.8 67 15.4 + 774144 0.0053191 0.00000038 145.54 14235.4 94 52.1 + 777600 0.0049020 0.00000034 158.63 15520.9 102 75.2 + 777924 0.0151515 0.00000038 51.34 5023.7 33 0.2 + 781250 0.0083333 0.00000042 93.75 9176.0 60 8.0 + 784000 0.0049505 0.00000035 158.37 15504.6 101 44.4 + 786432 0.0056180 0.00000034 139.98 13708.0 89 32.7 + 787320 0.0063291 0.00000036 124.40 12182.5 79 53.6 + 787500 0.0052083 0.00000037 151.20 14807.7 96 48.4 + 790272 0.0057471 0.00000037 137.51 13470.2 87 38.7 + 793800 0.0121951 0.00000034 65.09 6378.5 41 0.8 + 800000 0.0046296 0.00000036 172.80 16942.7 108 38.2 + 802816 0.0105794 0.00000036 75.88 7442.3 48 2.7 + 806400 0.0051546 0.00000035 156.44 15347.8 97 96.8 + 806736 0.0060241 0.00000037 133.92 13138.5 83 21.2 + 810000 0.0115412 0.00000034 70.18 6887.6 44 1.4 + 816480 0.0054945 0.00000036 148.60 14591.8 91 87.4 + 819200 0.0100000 0.00000032 81.92 8046.1 50 2.0 + 820125 0.0130208 0.00000037 62.99 6186.9 39 11.8 + 823200 0.0056818 0.00000035 144.88 14235.4 88 48.5 + 823543 0.0156250 0.00000038 52.71 5178.8 32 0.5 + 826686 0.0092593 0.00000038 89.28 8775.1 54 17.1 + 826875 0.0137247 0.00000037 60.25 5921.5 37 12.4 + 829440 0.0043860 0.00000035 189.11 18591.4 114 84.1 + 833490 0.0094340 0.00000037 88.35 8688.7 53 19.6 + 839808 0.0108696 0.00000035 77.26 7602.5 46 2.1 + 840000 0.0050505 0.00000036 166.32 16365.9 99 80.7 + 840350 0.0094340 0.00000036 89.08 8765.5 53 8.5 + 843750 0.0090909 0.00000037 92.81 9135.7 55 30.3 + 846720 0.0058140 0.00000035 145.64 14339.0 86 94.6 + 850500 0.0065789 0.00000035 129.28 12732.4 76 64.3 + 857304 0.0081967 0.00000037 104.59 10307.2 61 29.9 + 857500 0.0064935 0.00000038 132.05 13013.9 77 16.3 + 860160 0.0056180 0.00000035 153.11 15092.1 89 78.0 + 864000 0.0050505 0.00000034 171.07 16868.3 99 100.0 + 864360 0.0067568 0.00000036 127.93 12614.2 74 41.7 + 870912 0.0061728 0.00000038 141.09 13919.8 81 79.8 + 874800 0.0066667 0.00000036 131.22 12950.5 75 62.6 + 875000 0.0064935 0.00000039 134.75 13299.1 77 29.9 + 878080 0.0059524 0.00000036 147.52 14562.9 84 32.2 + 882000 0.0063291 0.00000036 139.36 13761.7 79 80.4 + 884736 0.0059524 0.00000034 148.64 14681.4 84 47.3 + 885735 0.0151515 0.00000037 58.46 5774.7 33 9.3 + 889056 0.0060976 0.00000037 145.81 14406.9 82 52.2 + 893025 0.0147059 0.00000037 60.73 6002.2 34 14.5 + 896000 0.0057471 0.00000034 155.90 15413.6 87 56.3 + 900000 0.0057471 0.00000037 156.60 15487.4 87 84.6 + 900375 0.0147059 0.00000037 61.23 6055.3 34 6.8 + 903168 0.0116279 0.00000035 77.67 7683.6 43 2.5 + 907200 0.0058824 0.00000034 154.22 15261.3 85 127.4 + 907578 0.0100000 0.00000038 90.76 8981.2 50 11.8 + 911250 0.0084746 0.00000035 107.53 10643.9 59 35.0 + 917504 0.0071429 0.00000036 128.45 12721.3 70 32.9 + 918540 0.0080645 0.00000037 113.90 11281.1 62 56.5 + 918750 0.0098039 0.00000038 93.71 9281.9 51 25.8 + 921600 0.0125000 0.00000032 73.73 7304.2 40 3.7 + 921984 0.0072464 0.00000037 127.23 12605.3 69 33.2 + 926100 0.0076923 0.00000036 120.39 11931.4 65 50.9 + 933120 0.0072464 0.00000035 128.77 12768.7 69 105.8 + 937500 0.0067568 0.00000040 138.75 13762.9 74 40.1 + 940800 0.0064935 0.00000034 144.88 14375.0 77 74.4 + 941192 0.0166667 0.00000037 56.47 5603.1 30 0.6 + 944784 0.0156250 0.00000036 60.47 6001.2 32 1.7 + 945000 0.0070423 0.00000037 134.19 13318.3 71 89.3 + 952560 0.0080645 0.00000036 118.12 11729.9 62 76.4 + 960000 0.0061728 0.00000034 155.52 15453.0 81 73.5 + 960400 0.0145089 0.00000035 66.19 6577.4 35 1.3 + 964467 0.0175108 0.00000038 55.08 5474.6 29 7.6 + 967680 0.0063291 0.00000037 152.89 15200.8 79 122.8 + 972000 0.0060976 0.00000036 159.41 15853.6 82 105.1 + 972405 0.0158691 0.00000037 61.28 6094.3 32 8.5 + 979776 0.0081967 0.00000037 119.53 11894.8 61 91.3 + 980000 0.0151515 0.00000035 64.68 6436.4 33 2.1 + 983040 0.0064935 0.00000034 151.39 15068.3 77 77.4 + 984150 0.0100000 0.00000037 98.42 9796.5 50 39.2 + 984375 0.0175108 0.00000039 56.22 5595.9 29 15.5 + 987840 0.0074627 0.00000036 132.37 13180.1 67 71.9 + 992250 0.0108696 0.00000035 91.29 9092.3 46 38.5 + 995328 0.0074627 0.00000036 133.37 13287.3 67 61.5 + 1000000 0.0138889 0.00000037 72.00 7175.4 36 2.9 + 1000188 0.0089286 0.00000038 112.02 11163.9 56 25.9 + 1003520 0.0075758 0.00000035 132.46 13204.5 66 54.9 + 1008000 0.0063291 0.00000035 159.26 15881.1 79 137.3 + 1008420 0.0081967 0.00000037 123.03 12268.1 61 32.0 + 1012500 0.0074627 0.00000037 135.68 13533.2 67 64.0 + 1016064 0.0131579 0.00000035 77.22 7704.5 38 3.6 + 1020600 0.0080645 0.00000036 126.55 12630.8 62 105.2 + 1024000 0.0069444 0.00000034 147.46 14720.4 72 54.8 + 1029000 0.0080645 0.00000037 127.60 12742.3 62 52.0 + 1032192 0.0078125 0.00000037 132.12 13197.0 64 83.7 + 1036800 0.0135135 0.00000033 76.72 7666.1 37 3.0 + 1037232 0.0094340 0.00000037 109.95 10986.0 53 31.1 + 1048576 0.0137247 0.00000035 76.40 7640.1 37 3.4 + 1049760 0.0074627 0.00000036 140.67 14067.9 67 143.2 + 1050000 0.0072464 0.00000037 144.90 14491.4 69 117.2 + 1053696 0.0080645 0.00000036 130.66 13070.4 62 77.1 + 1058400 0.0081967 0.00000036 129.12 12921.2 61 131.8 + 1058841 0.0217391 0.00000039 48.71 4874.1 23 4.5 + 1062882 0.0137247 0.00000038 77.44 7751.9 37 18.0 + 1063125 0.0190972 0.00000038 55.67 5572.4 27 20.3 + 1071630 0.0128205 0.00000037 83.59 8371.8 39 35.9 + 1071875 0.0211589 0.00000038 50.66 5073.9 24 4.0 + 1075200 0.0068493 0.00000035 156.98 15726.3 73 169.5 + 1075648 0.0087719 0.00000037 122.62 12284.9 57 36.5 + 1080000 0.0072464 0.00000036 149.04 14935.7 69 139.4 + 1080450 0.0119048 0.00000037 90.76 9095.4 42 30.9 + 1088640 0.0084746 0.00000035 128.46 12880.7 59 202.7 + 1093500 0.0089090 0.00000036 122.74 12311.3 57 90.9 + 1093750 0.0121951 0.00000041 89.69 8996.0 41 16.4 + 1097600 0.0094340 0.00000035 116.35 11672.9 53 92.4 + 1102248 0.0101562 0.00000038 108.53 10892.0 50 80.5 + 1102500 0.0234375 0.00000035 47.04 4721.0 22 0.3 + 1105920 0.0074627 0.00000036 148.19 14876.2 67 163.9 + 1111320 0.0092593 0.00000037 120.02 12052.6 54 78.7 + 1119744 0.0079365 0.00000036 141.09 14175.6 63 117.2 + 1120000 0.0076923 0.00000035 145.60 14629.2 65 114.0 + 1125000 0.0185185 0.00000037 60.75 6105.8 27 1.1 + 1128960 0.0080645 0.00000035 139.99 14073.7 62 178.9 + 1134000 0.0076923 0.00000036 147.42 14825.3 65 182.7 + 1143072 0.0178571 0.00000036 64.01 6441.0 28 2.7 + 1146880 0.0081967 0.00000035 139.92 14082.4 61 101.2 + 1148175 0.0195312 0.00000037 58.79 5917.1 26 22.6 + 1152000 0.0069444 0.00000034 165.89 16701.4 72 185.5 + 1152480 0.0096154 0.00000036 119.86 12067.5 52 101.1 + 1157625 0.0230824 0.00000037 50.15 5051.0 22 14.8 + 1161216 0.0081967 0.00000038 141.67 14271.1 61 156.0 + 1166400 0.0158691 0.00000034 73.50 7406.6 32 3.9 + 1166886 0.0135135 0.00000038 86.35 8701.5 37 16.8 + 1171875 0.0227273 0.00000037 51.56 5197.6 22 10.7 + 1176000 0.0080645 0.00000036 145.82 14703.0 62 152.7 + 1176490 0.0163810 0.00000037 71.82 7241.7 31 9.6 + 1179648 0.0169271 0.00000036 69.69 7028.2 30 3.3 + 1180980 0.0106383 0.00000037 111.01 11196.4 47 76.8 + 1181250 0.0120908 0.00000037 97.70 9853.8 42 55.6 + 1185408 0.0096154 0.00000038 123.28 12437.3 52 92.8 + 1190700 0.0104167 0.00000038 114.31 11535.5 48 74.2 + 1200000 0.0074627 0.00000037 160.80 16236.5 67 156.7 + 1200500 0.0100000 0.00000037 120.05 12122.2 50 30.1 + 1204224 0.0086207 0.00000037 139.69 14108.5 58 102.8 + 1209600 0.0081967 0.00000035 147.57 14909.2 61 244.7 + 1210104 0.0108696 0.00000038 111.33 11248.0 46 48.7 + 1215000 0.0092593 0.00000037 131.22 13261.4 54 104.1 + 1224720 0.0092330 0.00000037 132.65 13413.2 55 173.4 + 1225000 0.0099571 0.00000038 123.03 12440.8 51 62.6 + 1228800 0.0084746 0.00000034 145.00 14665.7 59 138.1 + 1229312 0.0185185 0.00000038 66.38 6714.4 27 3.3 + 1234800 0.0102041 0.00000037 121.01 12243.7 49 138.3 + 1240029 0.0271382 0.00000038 45.69 4624.6 19 11.2 + 1244160 0.0087719 0.00000035 141.83 14358.4 57 205.7 + 1250000 0.0090909 0.00000040 137.50 13924.3 55 68.8 + 1250235 0.0217391 0.00000038 57.51 5824.1 23 12.4 + 1254400 0.0172414 0.00000033 72.76 7369.6 29 4.4 + 1259712 0.0103635 0.00000037 121.55 12316.1 49 119.4 + 1260000 0.0086207 0.00000037 146.16 14809.7 58 199.3 + 1260525 0.0234375 0.00000037 53.78 5449.7 22 10.6 + 1265625 0.0241815 0.00000039 52.34 5304.9 21 19.9 + 1270080 0.0098039 0.00000036 129.55 13133.9 51 205.3 + 1275750 0.0133635 0.00000036 95.47 9681.6 38 66.4 + 1280000 0.0177802 0.00000033 71.99 7302.6 29 3.4 + 1285956 0.0298713 0.00000038 43.05 4368.4 17 0.3 + 1286250 0.0141059 0.00000038 91.19 9252.9 36 31.3 + 1290240 0.0094340 0.00000036 136.77 13881.2 53 221.5 + 1296000 0.0087719 0.00000035 147.74 15000.2 57 231.8 + 1296540 0.0112847 0.00000037 114.89 11665.3 45 67.6 + 1306368 0.0098039 0.00000038 133.25 13536.2 51 192.3 + 1310720 0.0096154 0.00000035 136.31 13850.9 52 99.5 + 1312200 0.0238095 0.00000035 55.11 5600.4 21 1.4 + 1312500 0.0104167 0.00000039 126.00 12804.0 48 107.1 + 1317120 0.0099571 0.00000037 132.28 13445.5 51 153.0 + 1323000 0.0102041 0.00000035 129.65 13182.8 49 166.7 + 1327104 0.0177802 0.00000035 74.64 7590.8 29 5.1 + 1333584 0.0110394 0.00000038 120.80 12289.7 46 89.1 + 1344000 0.0090909 0.00000035 147.84 15048.7 55 252.8 + 1344560 0.0116279 0.00000037 115.63 11770.6 43 65.9 + 1350000 0.0089286 0.00000036 151.20 15395.6 56 204.1 + 1354752 0.0105794 0.00000037 128.06 13042.2 48 155.2 + 1360800 0.0103635 0.00000036 131.31 13377.5 49 275.1 + 1361367 0.0286458 0.00000040 47.52 4841.9 18 7.4 + 1366875 0.0217391 0.00000038 62.88 6407.9 23 29.5 + 1372000 0.0111111 0.00000037 123.48 12587.5 45 95.2 + 1376256 0.0104167 0.00000036 132.12 13471.2 48 141.5 + 1377810 0.0153883 0.00000038 89.54 9130.0 33 63.4 + 1378125 0.0224185 0.00000039 61.47 6268.5 23 28.9 + 1382400 0.0102041 0.00000034 135.48 13817.6 49 234.7 + 1382976 0.0211589 0.00000036 65.36 6666.7 24 3.8 + 1389150 0.0156250 0.00000037 88.91 9070.9 32 60.9 + 1399680 0.0090909 0.00000036 153.96 15717.2 55 263.5 + 1400000 0.0090909 0.00000038 154.00 15721.1 55 155.9 + 1404928 0.0111111 0.00000037 126.44 12911.2 45 84.3 + 1406250 0.0158691 0.00000040 88.62 9049.1 32 65.0 + 1411200 0.0217391 0.00000034 64.92 6630.6 23 4.0 + 1411788 0.0195312 0.00000039 72.28 7383.4 26 23.6 + 1417176 0.0158691 0.00000038 89.30 9124.4 32 66.0 + 1417500 0.0116279 0.00000036 121.90 12455.6 43 159.6 + 1428840 0.0119048 0.00000037 120.02 12270.2 42 132.1 + 1433600 0.0102041 0.00000035 140.49 14366.2 49 168.3 + 1440000 0.0195312 0.00000034 73.73 7541.5 26 4.9 + 1440600 0.0116279 0.00000037 123.89 12673.0 43 98.8 + 1451520 0.0104167 0.00000037 139.35 14261.5 48 308.0 + 1458000 0.0120908 0.00000037 120.59 12345.5 42 206.6 + 1469664 0.0125000 0.00000038 117.57 12043.6 40 181.6 + 1470000 0.0100000 0.00000036 147.00 15058.2 50 162.5 + 1474560 0.0104167 0.00000035 141.56 14503.9 48 215.0 + 1476225 0.0250000 0.00000038 59.05 6050.6 20 30.3 + 1481760 0.0106383 0.00000037 139.29 14276.0 47 165.4 + 1488375 0.0238095 0.00000038 62.51 6409.1 21 35.9 + 1492992 0.0224185 0.00000036 66.60 6829.4 23 4.4 + 1500000 0.0099571 0.00000038 150.65 15453.7 51 167.1 + 1500282 0.0195312 0.00000039 76.81 7879.9 26 23.7 + 1500625 0.0253906 0.00000038 59.10 6063.0 20 8.6 + 1505280 0.0111111 0.00000037 135.48 13900.8 45 219.1 + 1512000 0.0090909 0.00000035 166.32 17071.1 55 341.4 + 1512630 0.0195312 0.00000038 77.45 7949.4 26 45.3 + 1518750 0.0147059 0.00000036 103.28 10603.5 34 78.5 + 1524096 0.0125000 0.00000037 121.93 12521.7 40 173.3 + 1530900 0.0137247 0.00000037 111.54 11458.9 37 184.7 + 1531250 0.0172414 0.00000039 88.81 9123.8 29 33.2 + 1536000 0.0101562 0.00000035 151.24 15540.2 50 243.8 + 1536640 0.0126953 0.00000036 121.04 12437.7 40 104.4 + 1543500 0.0131579 0.00000037 117.31 12057.8 38 119.0 + 1548288 0.0137247 0.00000038 112.81 11598.2 37 213.8 + 1555200 0.0106383 0.00000036 146.19 15034.5 47 290.5 + 1555848 0.0312500 0.00000038 49.79 5120.4 16 1.6 + 1562500 0.0343750 0.00000041 45.45 4676.2 15 0.3 + 1568000 0.0115412 0.00000035 135.86 13980.4 44 171.8 + 1572864 0.0126953 0.00000035 123.89 12751.7 40 117.3 + 1574640 0.0121951 0.00000037 129.12 13290.8 41 302.7 + 1575000 0.0113636 0.00000038 138.60 14266.7 44 285.5 + 1580544 0.0125000 0.00000037 126.44 13018.6 40 208.8 + 1587600 0.0241815 0.00000035 65.65 6761.8 21 3.0 + 1594323 0.0322266 0.00000039 49.47 5096.8 16 9.3 + 1600000 0.0111111 0.00000037 144.00 14838.9 45 144.4 + 1605632 0.0241815 0.00000037 66.40 6844.0 21 4.4 + 1607445 0.0290799 0.00000038 55.28 5698.0 18 26.5 + 1612800 0.0108045 0.00000035 149.27 15390.7 47 444.1 + 1613472 0.0156250 0.00000038 103.26 10647.2 32 115.4 + 1620000 0.0271382 0.00000034 59.69 6156.8 19 3.7 + 1620675 0.0263158 0.00000038 61.59 6352.0 19 26.1 + 1632960 0.0121951 0.00000037 133.90 13818.1 41 437.2 + 1638400 0.0227273 0.00000033 72.09 7441.0 22 5.8 + 1640250 0.0178571 0.00000037 91.85 9481.9 28 120.1 + 1640625 0.0317383 0.00000039 51.69 5336.1 16 31.3 + 1646400 0.0130208 0.00000036 126.44 13055.9 39 277.5 + 1647086 0.0271382 0.00000038 60.69 6267.0 19 5.3 + 1653372 0.0195312 0.00000039 84.65 8743.3 26 116.8 + 1653750 0.0175108 0.00000036 94.44 9754.6 29 114.8 + 1658880 0.0120908 0.00000038 137.20 14174.2 42 365.9 + 1666980 0.0177802 0.00000038 93.75 9689.0 29 134.3 + 1679616 0.0234375 0.00000035 71.66 7409.9 22 5.9 + 1680000 0.0112847 0.00000036 148.87 15393.6 45 393.9 + 1680700 0.0151515 0.00000037 110.93 11470.1 33 57.1 + 1687500 0.0121951 0.00000038 138.38 14312.4 41 157.8 + 1693440 0.0126953 0.00000037 133.39 13800.3 40 425.5 + 1701000 0.0137247 0.00000036 123.94 12826.3 37 356.2 + 1714608 0.0166667 0.00000038 102.88 10652.6 30 126.9 + 1715000 0.0145089 0.00000038 118.20 12239.8 35 102.6 + 1720320 0.0131579 0.00000036 130.74 13541.3 38 360.0 + 1728000 0.0116279 0.00000035 148.61 15396.3 43 466.1 + 1728720 0.0166667 0.00000037 103.72 10746.4 30 216.3 + 1741824 0.0131579 0.00000037 132.38 13722.5 38 354.6 + 1749600 0.0125000 0.00000036 139.97 14513.7 40 275.6 + 1750000 0.0130208 0.00000040 134.40 13936.6 39 150.8 + 1750329 0.0390625 0.00000040 44.81 4646.5 13 10.2 + 1756160 0.0145089 0.00000037 121.04 12554.3 35 154.3 + 1764000 0.0126953 0.00000036 138.95 14416.2 40 357.5 + 1764735 0.0362723 0.00000039 48.65 5047.9 14 13.8 + 1769472 0.0138889 0.00000036 127.40 13221.1 36 171.2 + 1771470 0.0217391 0.00000039 81.49 8457.0 23 91.5 + 1771875 0.0303309 0.00000039 58.42 6062.9 17 49.7 + 1778112 0.0158691 0.00000037 112.05 11631.7 32 227.6 + 1786050 0.0206250 0.00000037 86.60 8992.3 25 133.6 + 1792000 0.0111111 0.00000036 161.28 16751.5 45 237.2 + 1800000 0.0113636 0.00000037 158.40 16457.4 44 371.9 + 1800750 0.0208333 0.00000037 86.44 8980.8 24 70.6 + 1806336 0.0261719 0.00000038 69.02 7172.6 20 6.9 + 1814400 0.0130208 0.00000035 139.35 14485.7 39 570.3 + 1815156 0.0211589 0.00000039 85.79 8918.3 24 80.1 + 1822500 0.0402644 0.00000036 45.26 4706.8 13 0.5 + 1835008 0.0156250 0.00000035 117.44 12218.1 32 127.0 + 1837080 0.0161290 0.00000037 113.90 11850.6 31 365.5 + 1837500 0.0142857 0.00000039 128.62 13383.0 35 202.6 + 1843200 0.0271382 0.00000033 67.92 7068.3 19 5.8 + 1843968 0.0156250 0.00000038 118.01 12281.9 32 154.0 + 1852200 0.0141059 0.00000036 131.31 13669.6 36 317.5 + 1866240 0.0138889 0.00000036 134.37 13995.7 36 449.0 + 1875000 0.0145089 0.00000041 129.23 13464.9 35 228.7 + 1881600 0.0135135 0.00000036 139.24 14511.1 37 329.6 + 1882384 0.0327148 0.00000038 57.54 5996.8 16 2.4 + 1889568 0.0348958 0.00000038 54.15 5644.9 15 4.4 + 1890000 0.0147059 0.00000036 128.52 13398.2 34 496.6 + 1905120 0.0147059 0.00000036 129.55 13512.8 34 454.9 + 1913625 0.0333333 0.00000038 57.41 5990.0 15 67.5 + 1920000 0.0131579 0.00000035 145.92 15228.7 38 275.9 + 1920800 0.0327148 0.00000035 58.71 6127.7 16 3.5 + 1928934 0.0234375 0.00000039 82.30 8592.0 22 76.0 + 1929375 0.0343750 0.00000039 56.13 5859.6 15 44.3 + 1935360 0.0138889 0.00000036 139.35 14550.6 36 589.3 + 1944000 0.0142857 0.00000035 136.08 14214.0 35 539.0 + 1944810 0.0217391 0.00000038 89.46 9344.8 23 97.2 + 1953125 0.0390625 0.00000040 50.00 5224.3 13 12.5 + 1959552 0.0153883 0.00000038 127.34 13308.4 33 455.0 + 1960000 0.0282118 0.00000036 69.47 7260.9 18 5.9 + 1966080 0.0158691 0.00000036 123.89 12951.1 32 366.4 + 1968300 0.0192308 0.00000038 102.35 10700.1 26 203.5 + 1968750 0.0211589 0.00000039 93.05 9727.4 24 166.9 + 1975680 0.0166667 0.00000036 118.54 12395.8 30 392.8 + 1984500 0.0172414 0.00000036 115.10 12039.8 29 266.4 + 1990656 0.0166667 0.00000039 119.44 12496.2 30 209.8 + 2000000 0.0317383 0.00000037 63.02 6595.1 16 4.7 + 2000376 0.0190972 0.00000039 104.75 10962.7 27 146.4 + 2007040 0.0145089 0.00000036 138.33 14481.0 35 228.5 + 2016000 0.0130208 0.00000035 154.83 16212.9 39 646.8 + 2016840 0.0184152 0.00000037 109.52 11468.8 28 206.9 + 2025000 0.0156250 0.00000038 129.60 13575.3 32 325.1 + 2032128 0.0307904 0.00000037 66.00 6914.9 17 5.9 + 2041200 0.0161290 0.00000037 126.55 13263.5 31 515.9 + 2048000 0.0156250 0.00000035 131.07 13740.1 32 190.0 + 2058000 0.0153883 0.00000036 133.74 14024.3 33 310.0 + 2064384 0.0166667 0.00000037 123.86 12991.5 30 357.0 + 2066715 0.0390625 0.00000039 52.91 5549.8 13 51.1 + 2073600 0.0307904 0.00000033 67.35 7065.8 17 8.2 + 2074464 0.0166667 0.00000038 124.47 13059.4 30 146.2 + 2083725 0.0368304 0.00000038 56.58 5937.9 14 55.6 + 2097152 0.0282118 0.00000036 74.34 7805.3 18 5.2 + 2099520 0.0166667 0.00000037 125.97 13228.0 30 599.6 + 2100000 0.0130208 0.00000037 161.28 16936.0 39 563.5 + 2100875 0.0373884 0.00000038 56.19 5900.7 14 18.1 + 2107392 0.0163810 0.00000038 128.65 13512.6 31 338.6 + 2109375 0.0408654 0.00000041 51.62 5422.0 13 48.2 + 2116800 0.0141059 0.00000035 150.06 15766.9 36 556.5 + 2117682 0.0267270 0.00000039 79.23 8325.1 19 47.7 + 2125764 0.0531250 0.00000038 40.01 4205.4 10 0.4 + 2126250 0.0220788 0.00000036 96.30 10121.4 23 204.7 + 2143260 0.0208333 0.00000038 102.88 10818.2 24 273.1 + 2143750 0.0263158 0.00000039 81.46 8566.5 19 51.8 + 2150400 0.0145089 0.00000035 148.21 15589.1 35 705.5 + 2151296 0.0208333 0.00000038 103.26 10861.5 24 141.2 + 2160000 0.0153883 0.00000036 140.37 14768.4 33 517.9 + 2160900 0.0507812 0.00000037 42.55 4477.3 10 0.3 + 2177280 0.0156250 0.00000036 139.35 14669.0 32 854.1 + 2187000 0.0192308 0.00000037 113.72 11975.4 26 466.5 + 2187500 0.0172414 0.00000042 126.88 13360.5 29 126.0 + 2195200 0.0188079 0.00000037 116.72 12293.8 27 325.2 + 2204496 0.0185185 0.00000038 119.04 12542.4 27 408.1 + 2205000 0.0436198 0.00000036 50.55 5326.1 12 2.2 + 2211840 0.0161290 0.00000037 137.13 14451.7 31 679.1 + 2222640 0.0188079 0.00000037 118.18 12458.0 27 431.2 + 2239488 0.0208333 0.00000038 107.50 11337.9 24 393.5 + 2240000 0.0158691 0.00000037 141.15 14888.3 32 420.8 + 2250000 0.0368304 0.00000037 61.09 6445.5 14 3.7 + 2250423 0.0449219 0.00000039 50.10 5285.6 12 21.9 + 2257920 0.0172414 0.00000036 130.96 13820.5 29 709.7 + 2268000 0.0166667 0.00000036 136.08 14365.3 30 826.2 + 2268945 0.0408654 0.00000038 55.52 5861.4 13 37.0 + 2278125 0.0416667 0.00000039 54.67 5773.5 12 53.5 + 2286144 0.0384615 0.00000037 59.44 6278.2 13 7.7 + 2293760 0.0172414 0.00000036 133.04 14055.0 29 407.4 + 2296350 0.0250000 0.00000038 91.85 9704.8 20 227.0 + 2296875 0.0429688 0.00000040 53.45 5647.8 12 54.6 + 2304000 0.0156250 0.00000035 147.46 15582.9 32 698.9 diff --git a/lib/noisegen.f90 b/lib/noisegen.f90 index f92a9df0..b0aa174f 100644 --- a/lib/noisegen.f90 +++ b/lib/noisegen.f90 @@ -2,6 +2,9 @@ subroutine noisegen(d4,nmax) real*4 d4(4,nmax) + call init_random_seed() ! seed Fortran RANDOM_NUMBER generator + call sgran() ! see C rand generator (used in gran) + do i=1,nmax d4(1,i)=gran() d4(2,i)=gran() diff --git a/lib/packbits.f90 b/lib/packbits.f90 deleted file mode 100644 index 88851866..00000000 --- a/lib/packbits.f90 +++ /dev/null @@ -1,21 +0,0 @@ -subroutine packbits(dbits,nsymd,m0,sym) - -! Pack 0s and 1s from dbits() into sym() with m0 bits per word. -! NB: nsymd is the number of packed output words. - - integer sym(nsymd) - integer*1 dbits(*) - - k=0 - do i=1,nsymd - n=0 - do j=1,m0 - k=k+1 - m=dbits(k) - n=ior(ishft(n,1),m) - enddo - sym(i)=n - enddo - - return -end subroutine packbits diff --git a/lib/packcall.f90 b/lib/packcall.f90 deleted file mode 100644 index c4de474a..00000000 --- a/lib/packcall.f90 +++ /dev/null @@ -1,79 +0,0 @@ -subroutine packcall(callsign,ncall,text) - -! Pack a valid callsign into a 28-bit integer. - - parameter (NBASE=37*36*10*27*27*27) - character callsign*6,c*1,tmp*6 - logical text - - text=.false. - -! Work-around for Swaziland prefix: - if(callsign(1:4).eq.'3DA0') callsign='3D0'//callsign(5:6) - - if(callsign(1:3).eq.'CQ ') then - ncall=NBASE + 1 - if(callsign(4:4).ge.'0' .and. callsign(4:4).le.'9' .and. & - callsign(5:5).ge.'0' .and. callsign(5:5).le.'9' .and. & - callsign(6:6).ge.'0' .and. callsign(6:6).le.'9') then - read(callsign(4:6),*) nfreq - ncall=NBASE + 3 + nfreq - endif - return - else if(callsign(1:4).eq.'QRZ ') then - ncall=NBASE + 2 - return - else if(callsign(1:3).eq.'DE ') then - ncall=267796945 - return - endif - - tmp=' ' - if(callsign(3:3).ge.'0' .and. callsign(3:3).le.'9') then - tmp=callsign - else if(callsign(2:2).ge.'0' .and. callsign(2:2).le.'9') then - if(callsign(6:6).ne.' ') then - text=.true. - return - endif - tmp=' '//callsign(:5) - else - text=.true. - return - endif - - do i=1,6 - c=tmp(i:i) - if(c.ge.'a' .and. c.le.'z') & - tmp(i:i)=char(ichar(c)-ichar('a')+ichar('A')) - enddo - - n1=0 - if((tmp(1:1).ge.'A'.and.tmp(1:1).le.'Z').or.tmp(1:1).eq.' ') n1=1 - if(tmp(1:1).ge.'0' .and. tmp(1:1).le.'9') n1=1 - n2=0 - if(tmp(2:2).ge.'A' .and. tmp(2:2).le.'Z') n2=1 - if(tmp(2:2).ge.'0' .and. tmp(2:2).le.'9') n2=1 - n3=0 - if(tmp(3:3).ge.'0' .and. tmp(3:3).le.'9') n3=1 - n4=0 - if((tmp(4:4).ge.'A'.and.tmp(4:4).le.'Z').or.tmp(4:4).eq.' ') n4=1 - n5=0 - if((tmp(5:5).ge.'A'.and.tmp(5:5).le.'Z').or.tmp(5:5).eq.' ') n5=1 - n6=0 - if((tmp(6:6).ge.'A'.and.tmp(6:6).le.'Z').or.tmp(6:6).eq.' ') n6=1 - - if(n1+n2+n3+n4+n5+n6 .ne. 6) then - text=.true. - return - endif - - ncall=nchar(tmp(1:1)) - ncall=36*ncall+nchar(tmp(2:2)) - ncall=10*ncall+nchar(tmp(3:3)) - ncall=27*ncall+nchar(tmp(4:4))-10 - ncall=27*ncall+nchar(tmp(5:5))-10 - ncall=27*ncall+nchar(tmp(6:6))-10 - - return -end subroutine packcall diff --git a/lib/packdxcc.f90 b/lib/packdxcc.f90 deleted file mode 100644 index 74f2789b..00000000 --- a/lib/packdxcc.f90 +++ /dev/null @@ -1,64 +0,0 @@ -subroutine packdxcc(c,ng,ldxcc) - - character*3 c - logical ldxcc - - parameter (NZ=303) - character*5 pfx(NZ) - data pfx/ & - '1A ','1S ','3A ','3B6 ','3B8 ','3B9 ','3C ','3C0 ', & - '3D2 ', '3DA ','3V ','3W ','3X ','3Y ', & - '4J ','4L ','4S ','4U1 ', '4W ', & - '4X ','5A ','5B ','5H ','5N ','5R ','5T ','5U ', & - '5V ','5W ','5X ','5Z ','6W ','6Y ','7O ','7P ', & - '7Q ','7X ','8P ','8Q ','8R ','9A ','9G ','9H ', & - '9J ','9K ','9L ','9M2 ','9M6 ','9N ','9Q ','9U ', & - '9V ','9X ','9Y ','A2 ','A3 ','A4 ','A5 ','A6 ', & - 'A7 ','A9 ','AP ','BS7 ','BV ','BV9 ','BY ','C2 ', & - 'C3 ','C5 ','C6 ','C9 ','CE ','CE0 ', & - 'CE9 ','CM ','CN ','CP ','CT ','CT3 ','CU ','CX ', & - 'CY0 ','CY9 ','D2 ','D4 ','D6 ','DL ','DU ','E3 ', & - 'E4 ','EA ','EA6 ','EA8 ','EA9 ','EI ','EK ','EL ', & - 'EP ','ER ','ES ','ET ','EU ','EX ','EY ','EZ ', & - 'F ','FG ','FH ','FJ ','FK ', 'FM ','FO ', & - 'FP ','FR ', & - 'FT5 ', 'FW ','FY ','M ','MD ','MI ', & - 'MJ ','MM ', 'MU ','MW ','H4 ','H40 ','HA ', & - 'HB ','HB0 ','HC ','HC8 ','HH ','HI ','HK ','HK0 ', & - 'HL ','HM ','HP ','HR ','HS ','HV ','HZ ', & - 'I ','IG9 ','IS ','IT9 ','J2 ','J3 ','J5 ','J6 ', & - 'J7 ','J8 ','JA ','JD ', 'JT ','JW ', & - 'JX ','JY ','K ','KG4 ','KH0 ','KH1 ','KH2 ','KH3 ', & - 'KH4 ','KH5 ', 'KH6 ','KH7 ','KH8 ','KH9 ','KL ', & - 'KP1 ','KP2 ','KP4 ','KP5 ','LA ','LU ','LX ','LY ', & - 'LZ ','OA ','OD ','OE ','OH ','OH0 ','OJ0 ','OK ', & - 'OM ','ON ','OX ','OY ','OZ ','P2 ','P4 ','PA ', & - 'PJ2 ','PJ7 ','PY ','PY0 ', 'PZ ','R1F ', & - 'R1M ','S0 ','S2 ','S5 ','S7 ','S9 ','SM ','SP ', & - 'ST ','SU ','SV ', 'SV5 ','SV9 ','T2 ','T30 ', & - 'T31 ','T32 ','T33 ','T5 ','T7 ','T8 ','T9 ','TA ', & - 'TA1 ','TF ','TG ','TI ','TI9 ','TJ ','TK ','TL ', & - 'TN ','TR ','TT ','TU ','TY ','TZ ','UA ','UA2 ', & - 'UA9 ','UK ','UN ','UR ','V2 ','V3 ','V4 ','V5 ', & - 'V6 ','V7 ','V8 ','VE ','VK ','VK0 ', 'VK9 ', & - 'VP2 ', & - 'VP5 ','VP6 ', 'VP8 ', & - 'VP9 ','VQ9 ','VR ','VU ','VU4 ','VU7 ','XE ','XF4 ', & - 'XT ','XU ','XW ','XX9 ','XZ ','YA ','YB ','YI ', & - 'YJ ','YK ','YL ','YN ','YO ','YS ','YU ','YV ', & - 'YV0 ','Z2 ','Z3 ','ZA ','ZB ','ZC4 ','ZD7 ','ZD8 ', & - 'ZD9 ','ZF ','ZK1 ', 'ZK2 ','ZK3 ','ZL ','ZL7 ', & - 'ZL8 ','ZL9 ','ZP ','ZS ','ZS8 '/ - - ldxcc=.false. - ng=0 - do i=1,NZ - if(pfx(i)(1:3).eq.c) go to 10 - enddo - go to 20 - -10 ng=180*180+61+i - ldxcc=.true. - -20 return -end subroutine packdxcc diff --git a/lib/packgrid.f90 b/lib/packgrid.f90 deleted file mode 100644 index 1cdb7313..00000000 --- a/lib/packgrid.f90 +++ /dev/null @@ -1,76 +0,0 @@ -subroutine packgrid(grid,ng,text) - - parameter (NGBASE=180*180) - character*4 grid - character*1 c1 - logical text - - text=.false. - if(grid.eq.' ') go to 90 !Blank grid is OK - -! First, handle signal reports in the original range, -01 to -30 dB - if(grid(1:1).eq.'-') then - read(grid(2:3),*,err=800,end=800) n - if(n.ge.1 .and. n.le.30) then - ng=NGBASE+1+n - go to 900 - endif - go to 10 - else if(grid(1:2).eq.'R-') then - read(grid(3:4),*,err=800,end=800) n - if(n.ge.1 .and. n.le.30) then - ng=NGBASE+31+n - go to 900 - endif - go to 10 -! Now check for RO, RRR, or 73 in the message field normally used for grid - else if(grid(1:4).eq.'RO ') then - ng=NGBASE+62 - go to 900 - else if(grid(1:4).eq.'RRR ') then - ng=NGBASE+63 - go to 900 - else if(grid(1:4).eq.'73 ') then - ng=NGBASE+64 - go to 900 - endif - -! Now check for extended-range signal reports: -50 to -31, and 0 to +49. -10 n=99 - c1=grid(1:1) - read(grid,*,err=20,end=20) n - go to 30 -20 read(grid(2:4),*,err=30,end=30) n -30 if(n.ge.-50 .and. n.le.49) then - if(c1.eq.'R') then - write(grid,1002) n+50 -1002 format('LA',i2.2) - else - write(grid,1003) n+50 -1003 format('KA',i2.2) - endif - go to 40 - endif - -! Maybe it's free text ? - if(grid(1:1).lt.'A' .or. grid(1:1).gt.'R') text=.true. - if(grid(2:2).lt.'A' .or. grid(2:2).gt.'R') text=.true. - if(grid(3:3).lt.'0' .or. grid(3:3).gt.'9') text=.true. - if(grid(4:4).lt.'0' .or. grid(4:4).gt.'9') text=.true. - if(text) go to 900 - -! OK, we have a properly formatted grid locator -40 call grid2deg(grid//'mm',dlong,dlat) - long=int(dlong) - lat=int(dlat+ 90.0) - ng=((long+180)/2)*180 + lat - go to 900 - -90 ng=NGBASE + 1 - go to 900 - -800 text=.true. -900 continue - - return -end subroutine packgrid diff --git a/lib/packjt.f90 b/lib/packjt.f90 new file mode 100644 index 00000000..95ff5981 --- /dev/null +++ b/lib/packjt.f90 @@ -0,0 +1,1026 @@ +module packjt + +! These variables are accessible from outside via "use packjt": + integer jt_itype,jt_nc1,jt_nc2,jt_ng,jt_k1,jt_k2 + character*6 jt_c1,jt_c2,jt_c3 + + contains + +subroutine packbits(dbits,nsymd,m0,sym) + + ! Pack 0s and 1s from dbits() into sym() with m0 bits per word. + ! NB: nsymd is the number of packed output words. + + integer sym(:) + integer*1 dbits(:) + + k=0 + do i=1,nsymd + n=0 + do j=1,m0 + k=k+1 + m=dbits(k) + n=ior(ishft(n,1),m) + enddo + sym(i)=n + enddo + + return + end subroutine packbits + + subroutine unpackbits(sym,nsymd,m0,dbits) + + ! Unpack bits from sym() into dbits(), one bit per byte. + ! NB: nsymd is the number of input words, and m0 their length. + ! there will be m0*nsymd output bytes, each 0 or 1. + + integer sym(:) + integer*1 dbits(:) + + k=0 + do i=1,nsymd + mask=ishft(1,m0-1) + do j=1,m0 + k=k+1 + dbits(k)=0 + if(iand(mask,sym(i)).ne.0) dbits(k)=1 + mask=ishft(mask,-1) + enddo + enddo + + return + end subroutine unpackbits + + subroutine packcall(callsign,ncall,text) + + ! Pack a valid callsign into a 28-bit integer. + + parameter (NBASE=37*36*10*27*27*27) + character callsign*6,c*1,tmp*6 + logical text + + text=.false. + + ! Work-around for Swaziland prefix: + if(callsign(1:4).eq.'3DA0') callsign='3D0'//callsign(5:6) + + if(callsign(1:3).eq.'CQ ') then + ncall=NBASE + 1 + if(callsign(4:4).ge.'0' .and. callsign(4:4).le.'9' .and. & + callsign(5:5).ge.'0' .and. callsign(5:5).le.'9' .and. & + callsign(6:6).ge.'0' .and. callsign(6:6).le.'9') then + read(callsign(4:6),*) nfreq + ncall=NBASE + 3 + nfreq + endif + return + else if(callsign(1:4).eq.'QRZ ') then + ncall=NBASE + 2 + return + else if(callsign(1:3).eq.'DE ') then + ncall=267796945 + return + endif + + tmp=' ' + if(callsign(3:3).ge.'0' .and. callsign(3:3).le.'9') then + tmp=callsign + else if(callsign(2:2).ge.'0' .and. callsign(2:2).le.'9') then + if(callsign(6:6).ne.' ') then + text=.true. + return + endif + tmp=' '//callsign(:5) + else + text=.true. + return + endif + + do i=1,6 + c=tmp(i:i) + if(c.ge.'a' .and. c.le.'z') & + tmp(i:i)=char(ichar(c)-ichar('a')+ichar('A')) + enddo + + n1=0 + if((tmp(1:1).ge.'A'.and.tmp(1:1).le.'Z').or.tmp(1:1).eq.' ') n1=1 + if(tmp(1:1).ge.'0' .and. tmp(1:1).le.'9') n1=1 + n2=0 + if(tmp(2:2).ge.'A' .and. tmp(2:2).le.'Z') n2=1 + if(tmp(2:2).ge.'0' .and. tmp(2:2).le.'9') n2=1 + n3=0 + if(tmp(3:3).ge.'0' .and. tmp(3:3).le.'9') n3=1 + n4=0 + if((tmp(4:4).ge.'A'.and.tmp(4:4).le.'Z').or.tmp(4:4).eq.' ') n4=1 + n5=0 + if((tmp(5:5).ge.'A'.and.tmp(5:5).le.'Z').or.tmp(5:5).eq.' ') n5=1 + n6=0 + if((tmp(6:6).ge.'A'.and.tmp(6:6).le.'Z').or.tmp(6:6).eq.' ') n6=1 + + if(n1+n2+n3+n4+n5+n6 .ne. 6) then + text=.true. + return + endif + + ncall=nchar(tmp(1:1)) + ncall=36*ncall+nchar(tmp(2:2)) + ncall=10*ncall+nchar(tmp(3:3)) + ncall=27*ncall+nchar(tmp(4:4))-10 + ncall=27*ncall+nchar(tmp(5:5))-10 + ncall=27*ncall+nchar(tmp(6:6))-10 + + return + end subroutine packcall + + subroutine unpackcall(ncall,word,iv2,psfx) + + parameter (NBASE=37*36*10*27*27*27) + character word*12,c*37,psfx*4 + + data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ '/ + + word='......' + psfx=' ' + n=ncall + iv2=0 + if(n.ge.262177560) go to 20 + word='......' + ! if(n.ge.262177560) go to 999 !Plain text message ... + i=mod(n,27)+11 + word(6:6)=c(i:i) + n=n/27 + i=mod(n,27)+11 + word(5:5)=c(i:i) + n=n/27 + i=mod(n,27)+11 + word(4:4)=c(i:i) + n=n/27 + i=mod(n,10)+1 + word(3:3)=c(i:i) + n=n/10 + i=mod(n,36)+1 + word(2:2)=c(i:i) + n=n/36 + i=n+1 + word(1:1)=c(i:i) + do i=1,4 + if(word(i:i).ne.' ') go to 10 + enddo + go to 999 + 10 word=word(i:) + go to 999 + + 20 if(n.ge.267796946) go to 999 + + ! We have a JT65v2 message + if((n.ge.262178563) .and. (n.le.264002071)) then + ! CQ with prefix + iv2=1 + n=n-262178563 + i=mod(n,37)+1 + psfx(4:4)=c(i:i) + n=n/37 + i=mod(n,37)+1 + psfx(3:3)=c(i:i) + n=n/37 + i=mod(n,37)+1 + psfx(2:2)=c(i:i) + n=n/37 + i=n+1 + psfx(1:1)=c(i:i) + + else if((n.ge.264002072) .and. (n.le.265825580)) then + ! QRZ with prefix + iv2=2 + n=n-264002072 + i=mod(n,37)+1 + psfx(4:4)=c(i:i) + n=n/37 + i=mod(n,37)+1 + psfx(3:3)=c(i:i) + n=n/37 + i=mod(n,37)+1 + psfx(2:2)=c(i:i) + n=n/37 + i=n+1 + psfx(1:1)=c(i:i) + + else if((n.ge.265825581) .and. (n.le.267649089)) then + ! DE with prefix + iv2=3 + n=n-265825581 + i=mod(n,37)+1 + psfx(4:4)=c(i:i) + n=n/37 + i=mod(n,37)+1 + psfx(3:3)=c(i:i) + n=n/37 + i=mod(n,37)+1 + psfx(2:2)=c(i:i) + n=n/37 + i=n+1 + psfx(1:1)=c(i:i) + + else if((n.ge.267649090) .and. (n.le.267698374)) then + ! CQ with suffix + iv2=4 + n=n-267649090 + i=mod(n,37)+1 + psfx(3:3)=c(i:i) + n=n/37 + i=mod(n,37)+1 + psfx(2:2)=c(i:i) + n=n/37 + i=n+1 + psfx(1:1)=c(i:i) + + else if((n.ge.267698375) .and. (n.le.267747659)) then + ! QRZ with suffix + iv2=5 + n=n-267698375 + i=mod(n,37)+1 + psfx(3:3)=c(i:i) + n=n/37 + i=mod(n,37)+1 + psfx(2:2)=c(i:i) + n=n/37 + i=n+1 + psfx(1:1)=c(i:i) + + else if((n.ge.267747660) .and. (n.le.267796944)) then + ! DE with suffix + iv2=6 + n=n-267747660 + i=mod(n,37)+1 + psfx(3:3)=c(i:i) + n=n/37 + i=mod(n,37)+1 + psfx(2:2)=c(i:i) + n=n/37 + i=n+1 + psfx(1:1)=c(i:i) + + else if(n.eq.267796945) then + ! DE with no prefix or suffix + iv2=7 + psfx = ' ' + endif + + 999 if(word(1:3).eq.'3D0') word='3DA0'//word(4:) + + return + end subroutine unpackcall + + subroutine packgrid(grid,ng,text) + + parameter (NGBASE=180*180) + character*4 grid + character*1 c1 + logical text + + text=.false. + if(grid.eq.' ') go to 90 !Blank grid is OK + + ! First, handle signal reports in the original range, -01 to -30 dB + if(grid(1:1).eq.'-') then + read(grid(2:3),*,err=800,end=800) n + if(n.ge.1 .and. n.le.30) then + ng=NGBASE+1+n + go to 900 + endif + go to 10 + else if(grid(1:2).eq.'R-') then + read(grid(3:4),*,err=800,end=800) n + if(n.ge.1 .and. n.le.30) then + ng=NGBASE+31+n + go to 900 + endif + go to 10 + ! Now check for RO, RRR, or 73 in the message field normally used for grid + else if(grid(1:4).eq.'RO ') then + ng=NGBASE+62 + go to 900 + else if(grid(1:4).eq.'RRR ') then + ng=NGBASE+63 + go to 900 + else if(grid(1:4).eq.'73 ') then + ng=NGBASE+64 + go to 900 + endif + + ! Now check for extended-range signal reports: -50 to -31, and 0 to +49. + 10 n=99 + c1=grid(1:1) + read(grid,*,err=20,end=20) n + go to 30 + 20 read(grid(2:4),*,err=30,end=30) n + 30 if(n.ge.-50 .and. n.le.49) then + if(c1.eq.'R') then + write(grid,1002) n+50 + 1002 format('LA',i2.2) + else + write(grid,1003) n+50 + 1003 format('KA',i2.2) + endif + go to 40 + endif + + ! Maybe it's free text ? + if(grid(1:1).lt.'A' .or. grid(1:1).gt.'R') text=.true. + if(grid(2:2).lt.'A' .or. grid(2:2).gt.'R') text=.true. + if(grid(3:3).lt.'0' .or. grid(3:3).gt.'9') text=.true. + if(grid(4:4).lt.'0' .or. grid(4:4).gt.'9') text=.true. + if(text) go to 900 + + ! OK, we have a properly formatted grid locator + 40 call grid2deg(grid//'mm',dlong,dlat) + long=int(dlong) + lat=int(dlat+ 90.0) + ng=((long+180)/2)*180 + lat + go to 900 + + 90 ng=NGBASE + 1 + go to 900 + + 800 text=.true. + 900 continue + + return + end subroutine packgrid + + subroutine unpackgrid(ng,grid) + + parameter (NGBASE=180*180) + character grid*4,grid6*6 + + grid=' ' + if(ng.ge.32400) go to 10 + dlat=mod(ng,180)-90 + dlong=(ng/180)*2 - 180 + 2 + call deg2grid(dlong,dlat,grid6) + grid=grid6(:4) + if(grid(1:2).eq.'KA') then + read(grid(3:4),*) n + n=n-50 + write(grid,1001) n + 1001 format(i3.2) + if(grid(1:1).eq.' ') grid(1:1)='+' + else if(grid(1:2).eq.'LA') then + read(grid(3:4),*) n + n=n-50 + write(grid,1002) n + 1002 format('R',i3.2) + if(grid(2:2).eq.' ') grid(2:2)='+' + endif + go to 900 + + 10 n=ng-NGBASE-1 + if(n.ge.1 .and.n.le.30) then + write(grid,1012) -n + 1012 format(i3.2) + else if(n.ge.31 .and.n.le.60) then + n=n-30 + write(grid,1022) -n + 1022 format('R',i3.2) + else if(n.eq.61) then + grid='RO' + else if(n.eq.62) then + grid='RRR' + else if(n.eq.63) then + grid='73' + endif + + 900 return + end subroutine unpackgrid + + subroutine packmsg(msg0,dat,itype,bcontest) + + ! Packs a JT4/JT9/JT65 message into twelve 6-bit symbols + + ! itype Message Type + !-------------------- + ! 1 Standardd message + ! 2 Type 1 prefix + ! 3 Type 1 suffix + ! 4 Type 2 prefix + ! 5 Type 2 suffix + ! 6 Free text + ! -1 Does not decode correctly + + parameter (NBASE=37*36*10*27*27*27) + parameter (NBASE2=262178562) + character*22 msg0,msg + integer dat(:) + character*12 c1,c2 + character*4 c3 + character*6 grid6 + logical text1,text2,text3,bcontest + + itype=1 + if(bcontest) then + call to_contest_msg(msg0,msg) + else + msg=msg0 + end if + + call fmtmsg(msg,iz) + + if(msg(1:6).eq.'CQ DX ') msg(3:3)='9' + if(msg(1:3).eq.'CQ ' .and. & + msg(4:4).ge.'A' .and. msg(4:4).le.'Z' .and. & + msg(5:5).ge.'A' .and. msg(5:5).le.'Z' .and. & + msg(6:6).eq.' ') msg='E9'//msg(4:) + + ! See if it's a CQ message + if(msg(1:3).eq.'CQ ') then + i=3 + ! ... and if so, does it have a reply frequency? + if(msg(4:4).ge.'0' .and. msg(4:4).le.'9' .and. & + msg(5:5).ge.'0' .and. msg(5:5).le.'9' .and. & + msg(6:6).ge.'0' .and. msg(6:6).le.'9') i=7 + go to 1 + endif + + do i=1,22 + if(msg(i:i).eq.' ') go to 1 !Get 1st blank + enddo + go to 10 !Consider msg as plain text + + 1 ia=i + c1=msg(1:ia-1) + do i=ia+1,22 + if(msg(i:i).eq.' ') go to 2 !Get 2nd blank + enddo + go to 10 !Consider msg as plain text + + 2 ib=i + c2=msg(ia+1:ib-1) + + do i=ib+1,22 + if(msg(i:i).eq.' ') go to 3 !Get 3rd blank + enddo + go to 10 !Consider msg as plain text + + 3 ic=i + c3=' ' + if(ic.ge.ib+1) c3=msg(ib+1:ic) + if(c3.eq.'OOO ') c3=' ' !Strip out the OOO flag + call getpfx1(c1,k1,nv2a) + if(nv2a.ge.4) go to 10 + call packcall(c1,nc1,text1) + if(text1) go to 10 + call getpfx1(c2,k2,nv2b) + call packcall(c2,nc2,text2) + if(text2) go to 10 + if(nv2a.eq.2 .or. nv2a.eq.3 .or. nv2b.eq.2 .or. nv2b.eq.3) then + if(k1.lt.0 .or. k2.lt.0 .or. k1*k2.ne.0) go to 10 + if(k2.gt.0) k2=k2+450 + k=max(k1,k2) + if(k.gt.0) then + call k2grid(k,grid6) + c3=grid6(:4) + endif + endif + call packgrid(c3,ng,text3) + + if(nv2a.lt.4 .and. nv2b.lt.4 .and. (.not.text1) .and. (.not.text2) .and. & + (.not.text3)) go to 20 + + nc1=0 + if(nv2b.eq.4) then + if(c1(1:3).eq.'CQ ' .and. (.not.text3)) nc1=262178563 + k2 + if(c1(1:4).eq.'QRZ ' .and. (.not.text3)) nc1=264002072 + k2 + if(c1(1:3).eq.'DE ' .and. (.not.text3)) nc1=265825581 + k2 + else if(nv2b.eq.5) then + if(c1(1:3).eq.'CQ ' .and. (.not.text3)) nc1=267649090 + k2 + if(c1(1:4).eq.'QRZ ' .and. (.not.text3)) nc1=267698375 + k2 + if(c1(1:3).eq.'DE ' .and. (.not.text3)) nc1=267747660 + k2 + endif + if(nc1.ne.0) go to 20 + + ! The message will be treated as plain text. + 10 itype=6 + call packtext(msg,nc1,nc2,ng) + ng=ng+32768 + + ! Encode data into 6-bit words +20 continue + if(itype.ne.6) itype=max(nv2a,nv2b) + jt_itype=itype + jt_c1=c1(1:6) + jt_c2=c2(1:6) + jt_c3=c3 + jt_k1=k1 + jt_k2=k2 + jt_nc1=nc1 + jt_nc2=nc2 + jt_ng=ng + dat(1)=iand(ishft(nc1,-22),63) !6 bits + dat(2)=iand(ishft(nc1,-16),63) !6 bits + dat(3)=iand(ishft(nc1,-10),63) !6 bits + dat(4)=iand(ishft(nc1, -4),63) !6 bits + dat(5)=4*iand(nc1,15)+iand(ishft(nc2,-26),3) !4+2 bits + dat(6)=iand(ishft(nc2,-20),63) !6 bits + dat(7)=iand(ishft(nc2,-14),63) !6 bits + dat(8)=iand(ishft(nc2, -8),63) !6 bits + dat(9)=iand(ishft(nc2, -2),63) !6 bits + dat(10)=16*iand(nc2,3)+iand(ishft(ng,-12),15) !2+4 bits + dat(11)=iand(ishft(ng,-6),63) + dat(12)=iand(ng,63) + + return + end subroutine packmsg + + subroutine unpackmsg(dat,msg,bcontest,mygrid) + + parameter (NBASE=37*36*10*27*27*27) + parameter (NGBASE=180*180) + integer dat(:) + character c1*12,c2*12,grid*4,msg*22,grid6*6,psfx*4,junk2*4,mygrid*6 + logical cqnnn,bcontest + + cqnnn=.false. + nc1=ishft(dat(1),22) + ishft(dat(2),16) + ishft(dat(3),10)+ & + ishft(dat(4),4) + iand(ishft(dat(5),-2),15) + + nc2=ishft(iand(dat(5),3),26) + ishft(dat(6),20) + & + ishft(dat(7),14) + ishft(dat(8),8) + ishft(dat(9),2) + & + iand(ishft(dat(10),-4),3) + + ng=ishft(iand(dat(10),15),12) + ishft(dat(11),6) + dat(12) + + if(ng.ge.32768) then + call unpacktext(nc1,nc2,ng,msg) + go to 100 + endif + + call unpackcall(nc1,c1,iv2,psfx) + if(iv2.eq.0) then + ! This is an "original JT65" message + if(nc1.eq.NBASE+1) c1='CQ ' + if(nc1.eq.NBASE+2) c1='QRZ ' + nfreq=nc1-NBASE-3 + if(nfreq.ge.0 .and. nfreq.le.999) then + write(c1,1002) nfreq + 1002 format('CQ ',i3.3) + cqnnn=.true. + endif + endif + + call unpackcall(nc2,c2,junk1,junk2) + call unpackgrid(ng,grid) + + if(iv2.gt.0) then + ! This is a JT65v2 message + do i=1,4 + if(ichar(psfx(i:i)).eq.0) psfx(i:i)=' ' + enddo + + n1=len_trim(psfx) + n2=len_trim(c2) + if(iv2.eq.1) msg='CQ '//psfx(:n1)//'/'//c2(:n2)//' '//grid + if(iv2.eq.2) msg='QRZ '//psfx(:n1)//'/'//c2(:n2)//' '//grid + if(iv2.eq.3) msg='DE '//psfx(:n1)//'/'//c2(:n2)//' '//grid + if(iv2.eq.4) msg='CQ '//c2(:n2)//'/'//psfx(:n1)//' '//grid + if(iv2.eq.5) msg='QRZ '//c2(:n2)//'/'//psfx(:n1)//' '//grid + if(iv2.eq.6) msg='DE '//c2(:n2)//'/'//psfx(:n1)//' '//grid + if(iv2.eq.7) then + grid6=grid//'ma' + call grid2k(grid6,k) + if(k.ge.451 .and. k.le.900) then + call getpfx2(k,c2) + n2=len_trim(c2) + msg='DE '//c2(:n2) + else + msg='DE '//c2(:n2)//' '//grid + endif + endif + if(iv2.eq.8) msg=' ' + go to 100 + else + + endif + + grid6=grid//'ma' + call grid2k(grid6,k) + if(k.ge.1 .and. k.le.450) call getpfx2(k,c1) + if(k.ge.451 .and. k.le.900) call getpfx2(k,c2) + + i=index(c1,char(0)) + if(i.ge.3) c1=c1(1:i-1)//' ' + i=index(c2,char(0)) + if(i.ge.3) c2=c2(1:i-1)//' ' + + msg=' ' + j=0 + if(cqnnn) then + msg=c1//' ' + j=7 !### ??? ### + go to 10 + endif + + do i=1,12 + j=j+1 + msg(j:j)=c1(i:i) + if(c1(i:i).eq.' ') go to 10 + enddo + j=j+1 + msg(j:j)=' ' + + 10 do i=1,12 + if(j.le.21) j=j+1 + msg(j:j)=c2(i:i) + if(c2(i:i).eq.' ') go to 20 + enddo + if(j.le.21) j=j+1 + msg(j:j)=' ' + + 20 if(k.eq.0) then + do i=1,4 + if(j.le.21) j=j+1 + msg(j:j)=grid(i:i) + enddo + if(j.le.21) j=j+1 + msg(j:j)=' ' + endif + + 100 continue + if(msg(1:6).eq.'CQ9DX ') msg(3:3)=' ' + if(msg(1:2).eq.'E9' .and. & + msg(3:3).ge.'A' .and. msg(3:3).le.'Z' .and. & + msg(4:4).ge.'A' .and. msg(4:4).le.'Z' .and. & + msg(5:5).eq.' ') msg='CQ '//msg(3:) + + if(bcontest) call fix_contest_msg(mygrid,msg) + + return + end subroutine unpackmsg + + subroutine packtext(msg,nc1,nc2,nc3) + + parameter (MASK28=2**28 - 1) + character*22 msg + character*42 c + data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ +-./?'/ + + nc1=0 + nc2=0 + nc3=0 + + do i=1,5 !First 5 characters in nc1 + do j=1,42 !Get character code + if(msg(i:i).eq.c(j:j)) go to 10 + enddo + j=37 + 10 j=j-1 !Codes should start at zero + nc1=42*nc1 + j + enddo + + do i=6,10 !Characters 6-10 in nc2 + do j=1,42 !Get character code + if(msg(i:i).eq.c(j:j)) go to 20 + enddo + j=37 + 20 j=j-1 !Codes should start at zero + nc2=42*nc2 + j + enddo + + do i=11,13 !Characters 11-13 in nc3 + do j=1,42 !Get character code + if(msg(i:i).eq.c(j:j)) go to 30 + enddo + j=37 + 30 j=j-1 !Codes should start at zero + nc3=42*nc3 + j + enddo + + ! We now have used 17 bits in nc3. Must move one each to nc1 and nc2. + nc1=nc1+nc1 + if(iand(nc3,32768).ne.0) nc1=nc1+1 + nc2=nc2+nc2 + if(iand(nc3,65536).ne.0) nc2=nc2+1 + nc3=iand(nc3,32767) + + return + end subroutine packtext + + subroutine unpacktext(nc1,nc2,nc3,msg) + + character*22 msg + character*44 c + data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ +-./?'/ + + nc3=iand(nc3,32767) !Remove the "plain text" bit + if(iand(nc1,1).ne.0) nc3=nc3+32768 + nc1=nc1/2 + if(iand(nc2,1).ne.0) nc3=nc3+65536 + nc2=nc2/2 + + do i=5,1,-1 + j=mod(nc1,42)+1 + msg(i:i)=c(j:j) + nc1=nc1/42 + enddo + + do i=10,6,-1 + j=mod(nc2,42)+1 + msg(i:i)=c(j:j) + nc2=nc2/42 + enddo + + do i=13,11,-1 + j=mod(nc3,42)+1 + msg(i:i)=c(j:j) + nc3=nc3/42 + enddo + msg(14:22) = ' ' + + return + end subroutine unpacktext + + subroutine getpfx1(callsign,k,nv2) + + character*12 callsign0,callsign,lof,rof + character*8 c + character addpfx*8,tpfx*4,tsfx*3 + logical ispfx,issfx,invalid + common/pfxcom/addpfx + include 'pfx.f90' + + callsign0=callsign + nv2=1 + iz=index(callsign,' ') - 1 + if(iz.lt.0) iz=12 + islash=index(callsign(1:iz),'/') + k=0 + ! if(k.eq.0) go to 10 !Tnx to DL9RDZ for reminder:this was for tests only! + c=' ' + if(islash.gt.0 .and. islash.le.(iz-4)) then + ! Add-on prefix + c=callsign(1:islash-1) + callsign=callsign(islash+1:iz) + do i=1,NZ + if(pfx(i)(1:4).eq.c) then + k=i + nv2=2 + go to 10 + endif + enddo + if(addpfx.eq.c) then + k=449 + nv2=2 + go to 10 + endif + + else if(islash.eq.(iz-1)) then + ! Add-on suffix + c=callsign(islash+1:iz) + callsign=callsign(1:islash-1) + do i=1,NZ2 + if(sfx(i).eq.c(1:1)) then + k=400+i + nv2=3 + go to 10 + endif + enddo + endif + + 10 if(islash.ne.0 .and.k.eq.0) then + ! Original JT65 would force this compound callsign to be treated as + ! plain text. In JT65v2, we will encode the prefix or suffix into nc1. + ! The task here is to compute the proper value of k. + lof=callsign0(:islash-1) + rof=callsign0(islash+1:) + llof=len_trim(lof) + lrof=len_trim(rof) + ispfx=(llof.gt.0 .and. llof.le.4) + issfx=(lrof.gt.0 .and. lrof.le.3) + invalid=.not.(ispfx.or.issfx) + if(ispfx.and.issfx) then + if(llof.lt.3) issfx=.false. + if(lrof.lt.3) ispfx=.false. + if(ispfx.and.issfx) then + i=ichar(callsign0(islash-1:islash-1)) + if(i.ge.ichar('0') .and. i.le.ichar('9')) then + issfx=.false. + else + ispfx=.false. + endif + endif + endif + + if(invalid) then + k=-1 + else + if(ispfx) then + tpfx=lof(1:4) + k=nchar(tpfx(1:1)) + k=37*k + nchar(tpfx(2:2)) + k=37*k + nchar(tpfx(3:3)) + k=37*k + nchar(tpfx(4:4)) + nv2=4 + i=index(callsign0,'/') + callsign=callsign0(:i-1) + callsign=callsign0(i+1:) + endif + if(issfx) then + tsfx=rof(1:3) + k=nchar(tsfx(1:1)) + k=37*k + nchar(tsfx(2:2)) + k=37*k + nchar(tsfx(3:3)) + nv2=5 + i=index(callsign0,'/') + callsign=callsign0(:i-1) + endif + endif + endif + + return + end subroutine getpfx1 + + subroutine getpfx2(k0,callsign) + + character callsign*12 + include 'pfx.f90' + character addpfx*8 + common/pfxcom/addpfx + + k=k0 + if(k.gt.450) k=k-450 + if(k.ge.1 .and. k.le.NZ) then + iz=index(pfx(k),' ') - 1 + callsign=pfx(k)(1:iz)//'/'//callsign + else if(k.ge.401 .and. k.le.400+NZ2) then + iz=index(callsign,' ') - 1 + callsign=callsign(1:iz)//'/'//sfx(k-400) + else if(k.eq.449) then + iz=index(addpfx,' ') - 1 + if(iz.lt.1) iz=8 + callsign=addpfx(1:iz)//'/'//callsign + endif + + return + end subroutine getpfx2 + + subroutine grid2k(grid,k) + + character*6 grid + + call grid2deg(grid,xlong,xlat) + nlong=nint(xlong) + nlat=nint(xlat) + k=0 + if(nlat.ge.85) k=5*(nlong+179)/2 + nlat-84 + + return + end subroutine grid2k + + subroutine k2grid(k,grid) + character grid*6 + + nlong=2*mod((k-1)/5,90)-179 + if(k.gt.450) nlong=nlong+180 + nlat=mod(k-1,5)+ 85 + dlat=nlat + dlong=nlong + call deg2grid(dlong,dlat,grid) + + return + end subroutine k2grid + + subroutine grid2n(grid,n) + character*4 grid + + i1=ichar(grid(1:1))-ichar('A') + i2=ichar(grid(3:3))-ichar('0') + i=10*i1 + i2 + n=-i - 31 + + return + end subroutine grid2n + + subroutine n2grid(n,grid) + character*4 grid + + if(n.gt.-31 .or. n.lt.-70) stop 'Error in n2grid' + i=-(n+31) !NB: 0 <= i <= 39 + i1=i/10 + i2=mod(i,10) + grid(1:1)=char(ichar('A')+i1) + grid(2:2)='A' + grid(3:3)=char(ichar('0')+i2) + grid(4:4)='0' + + return + end subroutine n2grid + + function nchar(c) + + ! Convert ascii number, letter, or space to 0-36 for callsign packing. + + character c*1 + + n=0 !Silence compiler warning + if(c.ge.'0' .and. c.le.'9') then + n=ichar(c)-ichar('0') + else if(c.ge.'A' .and. c.le.'Z') then + n=ichar(c)-ichar('A') + 10 + else if(c.ge.'a' .and. c.le.'z') then + n=ichar(c)-ichar('a') + 10 + else if(c.ge.' ') then + n=36 + else + Print*,'Invalid character in callsign ',c,' ',ichar(c) + stop + endif + nchar=n + + return + end function nchar + + subroutine pack50(n1,n2,dat) + + integer*1 dat(:),i1 + + i1=iand(ishft(n1,-20),255) !8 bits + dat(1)=i1 + i1=iand(ishft(n1,-12),255) !8 bits + dat(2)=i1 + i1=iand(ishft(n1, -4),255) !8 bits + dat(3)=i1 + i1=16*iand(n1,15)+iand(ishft(n2,-18),15) !4+4 bits + dat(4)=i1 + i1=iand(ishft(n2,-10),255) !8 bits + dat(5)=i1 + i1=iand(ishft(n2, -2),255) !8 bits + dat(6)=i1 + i1=64*iand(n2,3) !2 bits + dat(7)=i1 + dat(8)=0 + dat(9)=0 + dat(10)=0 + dat(11)=0 + + return + end subroutine pack50 + +subroutine packpfx(call1,n1,ng,nadd) + + character*12 call1,call0 + character*3 pfx + logical text + + i1=index(call1,'/') + if(call1(i1+2:i1+2).eq.' ') then +! Single-character add-on suffix (maybe also fourth suffix letter?) + call0=call1(:i1-1) + call packcall(call0,n1,text) + nadd=1 + nc=ichar(call1(i1+1:i1+1)) + if(nc.ge.48 .and. nc.le.57) then + n=nc-48 + else if(nc.ge.65 .and. nc.le.90) then + n=nc-65+10 + else + n=38 + endif + nadd=1 + ng=60000-32768+n + else if(call1(i1+3:i1+3).eq.' ') then +! Two-character numerical suffix, /10 to /99 + call0=call1(:i1-1) + call packcall(call0,n1,text) + nadd=1 + n=10*(ichar(call1(i1+1:i1+1))-48) + ichar(call1(i1+2:i1+2)) - 48 + nadd=1 + ng=60000 + 26 + n + else +! Prefix of 1 to 3 characters + pfx=call1(:i1-1) + if(pfx(3:3).eq.' ') pfx=' '//pfx(1:2) + if(pfx(3:3).eq.' ') pfx=' '//pfx(1:2) + call0=call1(i1+1:) + call packcall(call0,n1,text) + + ng=0 + do i=1,3 + nc=ichar(pfx(i:i)) + if(nc.ge.48 .and. nc.le.57) then + n=nc-48 + else if(nc.ge.65 .and. nc.le.90) then + n=nc-65+10 + else + n=36 + endif + ng=37*ng + n + enddo + nadd=0 + if(ng.ge.32768) then + ng=ng-32768 + nadd=1 + endif + endif + + return +end subroutine packpfx + +end module packjt diff --git a/lib/packmsg.f90 b/lib/packmsg.f90 deleted file mode 100644 index 00485087..00000000 --- a/lib/packmsg.f90 +++ /dev/null @@ -1,119 +0,0 @@ -subroutine packmsg(msg,dat,itype) - -! Packs a JT4/JT9/JT65 message into twelve 6-bit symbols - -! itype Message Type -!-------------------- -! 1 Standardd message -! 2 Type 1 prefix -! 3 Type 1 suffix -! 4 Type 2 prefix -! 5 Type 2 suffix -! 6 Free text -! -1 Does not decode correctly - - parameter (NBASE=37*36*10*27*27*27) - parameter (NBASE2=262178562) - character*22 msg - integer dat(12) - character*12 c1,c2 - character*4 c3 - character*6 grid6 - logical text1,text2,text3 - - itype=1 - call fmtmsg(msg,iz) - - if(msg(1:6).eq.'CQ DX ') msg(3:3)='9' - -! See if it's a CQ message - if(msg(1:3).eq.'CQ ') then - i=3 -! ... and if so, does it have a reply frequency? - if(msg(4:4).ge.'0' .and. msg(4:4).le.'9' .and. & - msg(5:5).ge.'0' .and. msg(5:5).le.'9' .and. & - msg(6:6).ge.'0' .and. msg(6:6).le.'9') i=7 - go to 1 - endif - - do i=1,22 - if(msg(i:i).eq.' ') go to 1 !Get 1st blank - enddo - go to 10 !Consider msg as plain text - -1 ia=i - c1=msg(1:ia-1) - do i=ia+1,22 - if(msg(i:i).eq.' ') go to 2 !Get 2nd blank - enddo - go to 10 !Consider msg as plain text - -2 ib=i - c2=msg(ia+1:ib-1) - - do i=ib+1,22 - if(msg(i:i).eq.' ') go to 3 !Get 3rd blank - enddo - go to 10 !Consider msg as plain text - -3 ic=i - c3=' ' - if(ic.ge.ib+1) c3=msg(ib+1:ic) - if(c3.eq.'OOO ') c3=' ' !Strip out the OOO flag - call getpfx1(c1,k1,nv2a) - if(nv2a.ge.4) go to 10 - call packcall(c1,nc1,text1) - if(text1) go to 10 - call getpfx1(c2,k2,nv2b) - call packcall(c2,nc2,text2) - if(text2) go to 10 - if(nv2a.eq.2 .or. nv2a.eq.3 .or. nv2b.eq.2 .or. nv2b.eq.3) then - if(k1.lt.0 .or. k2.lt.0 .or. k1*k2.ne.0) go to 10 - if(k2.gt.0) k2=k2+450 - k=max(k1,k2) - if(k.gt.0) then - call k2grid(k,grid6) - c3=grid6(:4) - endif - endif - call packgrid(c3,ng,text3) - - if(nv2a.lt.4 .and. nv2b.lt.4 .and. (.not.text1) .and. (.not.text2) .and. & - (.not.text3)) go to 20 - - nc1=0 - if(nv2b.eq.4) then - if(c1(1:3).eq.'CQ ') nc1=262178563 + k2 - if(c1(1:4).eq.'QRZ ') nc1=264002072 + k2 - if(c1(1:3).eq.'DE ') nc1=265825581 + k2 - else if(nv2b.eq.5) then - if(c1(1:3).eq.'CQ ') nc1=267649090 + k2 - if(c1(1:4).eq.'QRZ ') nc1=267698375 + k2 - if(c1(1:3).eq.'DE ') nc1=267747660 + k2 - endif - if(nc1.ne.0) go to 20 - -! The message will be treated as plain text. -10 itype=6 - call packtext(msg,nc1,nc2,ng) - ng=ng+32768 - -! Encode data into 6-bit words -20 continue - if(itype.ne.6) itype=max(nv2a,nv2b) - dat(1)=iand(ishft(nc1,-22),63) !6 bits - dat(2)=iand(ishft(nc1,-16),63) !6 bits - dat(3)=iand(ishft(nc1,-10),63) !6 bits - dat(4)=iand(ishft(nc1, -4),63) !6 bits - dat(5)=4*iand(nc1,15)+iand(ishft(nc2,-26),3) !4+2 bits - dat(6)=iand(ishft(nc2,-20),63) !6 bits - dat(7)=iand(ishft(nc2,-14),63) !6 bits - dat(8)=iand(ishft(nc2, -8),63) !6 bits - dat(9)=iand(ishft(nc2, -2),63) !6 bits - dat(10)=16*iand(nc2,3)+iand(ishft(ng,-12),15) !2+4 bits - dat(11)=iand(ishft(ng,-6),63) - dat(12)=iand(ng,63) - - return -end subroutine packmsg - diff --git a/lib/packtext.f90 b/lib/packtext.f90 deleted file mode 100644 index 10f34887..00000000 --- a/lib/packtext.f90 +++ /dev/null @@ -1,47 +0,0 @@ -subroutine packtext(msg,nc1,nc2,nc3) - - parameter (MASK28=2**28 - 1) - character*13 msg - character*42 c - data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ +-./?'/ - - nc1=0 - nc2=0 - nc3=0 - - do i=1,5 !First 5 characters in nc1 - do j=1,42 !Get character code - if(msg(i:i).eq.c(j:j)) go to 10 - enddo - j=37 -10 j=j-1 !Codes should start at zero - nc1=42*nc1 + j - enddo - - do i=6,10 !Characters 6-10 in nc2 - do j=1,42 !Get character code - if(msg(i:i).eq.c(j:j)) go to 20 - enddo - j=37 -20 j=j-1 !Codes should start at zero - nc2=42*nc2 + j - enddo - - do i=11,13 !Characters 11-13 in nc3 - do j=1,42 !Get character code - if(msg(i:i).eq.c(j:j)) go to 30 - enddo - j=37 -30 j=j-1 !Codes should start at zero - nc3=42*nc3 + j - enddo - -! We now have used 17 bits in nc3. Must move one each to nc1 and nc2. - nc1=nc1+nc1 - if(iand(nc3,32768).ne.0) nc1=nc1+1 - nc2=nc2+nc2 - if(iand(nc3,65536).ne.0) nc2=nc2+1 - nc3=iand(nc3,32767) - - return -end subroutine packtext diff --git a/lib/pctile.f90 b/lib/pctile.f90 index 35ee3a7d..7a039b05 100644 --- a/lib/pctile.f90 +++ b/lib/pctile.f90 @@ -1,6 +1,6 @@ subroutine pctile(x,npts,npct,xpct) - parameter (NMAX=32768) + parameter (NMAX=128*1024) real*4 x(npts) real*4 tmp(NMAX) @@ -10,8 +10,8 @@ subroutine pctile(x,npts,npct,xpct) endif if(npts.gt.NMAX) stop - tmp(1:npts)=x - call sort(npts,tmp) + tmp(1:npts)=x + call shell(npts,tmp) j=nint(npts*0.01*npct) if(j.lt.1) j=1 if(j.gt.npts) j=npts diff --git a/lib/peakdt9.f90 b/lib/peakdt9.f90 index eac256ef..946d4534 100644 --- a/lib/peakdt9.f90 +++ b/lib/peakdt9.f90 @@ -1,14 +1,15 @@ -subroutine peakdt9(c2,nz2,nsps8,nspsd,c3,nz3,xdt) +subroutine peakdt9(c2,nsps8,nspsd,c3,xdt) - complex c2(0:4096-1) - complex c3(0:4096-1) + parameter (NZ2=1512,NZ3=1360) + complex c2(0:NZ2-1) + complex c3(0:NZ3-1) complex z real p(0:3300) include 'jt9sync.f90' p=0. - i0=5*nspsd - do i=0,nz2-1 + i0=5*nspsd + do i=0,NZ2-1 z=1.e-3*sum(c2(max(i-(nspsd-1),0):i)) p(i0+i)=real(z)**2 + aimag(z)**2 !Integrated symbol power at freq=0 enddo @@ -40,10 +41,9 @@ subroutine peakdt9(c2,nz2,nsps8,nspsd,c3,nz3,xdt) xdt=(lagpk-lag0)*dtlag - nz3=nspsd*85 - do i=0,nz3-1 + do i=0,NZ3-1 j=i+lagpk-i0-nspsd+1 - if(j.ge.0 .and. j.le.nz2) then + if(j.ge.0 .and. j.lt.NZ2) then c3(i)=c2(j) else c3(i)=0. diff --git a/lib/peakup.f90 b/lib/peakup.f90 index 8e5aedaf..92327ab6 100644 --- a/lib/peakup.f90 +++ b/lib/peakup.f90 @@ -1,8 +1,8 @@ -subroutine peakup(ym,y0,yp,dx) - - b=(yp-ym)/2.0 - c=(yp+ym-2.0*y0)/2.0 - dx=-b/(2.0*c) - - return -end subroutine peakup +subroutine peakup(ym,y0,yp,dx) + + b=(yp-ym)/2.0 + c=(yp+ym-2.0*y0)/2.0 + dx=-b/(2.0*c) + + return +end subroutine peakup diff --git a/lib/pfx.f90 b/lib/pfx.f90 index ca487181..eb81fef8 100644 --- a/lib/pfx.f90 +++ b/lib/pfx.f90 @@ -23,7 +23,7 @@ 'FOA ','FOC ','FOM ','FP ','FR ','FRG ','FRJ ','FRT ', & 'FT5W ','FT5X ','FT5Z ','FW ','FY ','M ','MD ','MI ', & 'MJ ','MM ', 'MU ','MW ','H4 ','H40 ','HA ', & - 'HB ','HB0 ','HC ','HC8 ','HH ','HI ','HK ','HK0A ', & + 'HB ','HB0 ','HC ','HC8 ','HH ','HI ','HK ','HK0 ', & 'HK0M ','HL ','HM ','HP ','HR ','HS ','HV ','HZ ', & 'I ','IS ','IS0 ', 'J2 ','J3 ','J5 ','J6 ', & 'J7 ','J8 ','JA ','JDM ','JDO ','JT ','JW ', & diff --git a/lib/pfxdump.f90 b/lib/pfxdump.f90 deleted file mode 100644 index 7587dbf7..00000000 --- a/lib/pfxdump.f90 +++ /dev/null @@ -1,13 +0,0 @@ -subroutine pfxdump(fname) - character*(*) fname - include 'pfx.f90' - - open(11,file=fname,status='unknown') - write(11,1001) sfx -1001 format('Supported Suffixes:'/(11('/',a1,2x))) - write(11,1002) pfx -1002 format(/'Supported Add-On DXCC Prefixes:'/(15(a5,1x))) - close(11) - - return -end subroutine pfxdump diff --git a/lib/polfit.f90 b/lib/polfit.f90 deleted file mode 100644 index ea7ffc9f..00000000 --- a/lib/polfit.f90 +++ /dev/null @@ -1,72 +0,0 @@ -subroutine polfit(x,y,sigmay,npts,nterms,mode,a,chisqr) - implicit real*8 (a-h,o-z) - real*8 x(npts), y(npts), sigmay(npts), a(nterms) - real*8 sumx(19), sumy(10), array(10,10) - -! Accumulate weighted sums - nmax = 2*nterms-1 - sumx=0. - sumy=0. - chisq=0. - do i=1,npts - xi=x(i) - yi=y(i) - if(mode.lt.0) then - weight=1./abs(yi) - else if(mode.eq.0) then - weight=1 - else - weight=1./sigmay(i)**2 - end if - xterm=weight - do n=1,nmax - sumx(n)=sumx(n)+xterm - xterm=xterm*xi - enddo - yterm=weight*yi - do n=1,nterms - sumy(n)=sumy(n)+yterm - yterm=yterm*xi - enddo - chisq=chisq+weight*yi**2 - enddo - -! Construct matrices and calculate coefficients - do j=1,nterms - do k=1,nterms - n=j+k-1 - array(j,k)=sumx(n) - enddo - enddo - - delta=determ(array,nterms) - if(delta.eq.0) then - chisqr=0. - a=0. - else - do l=1,nterms - do j=1,nterms - do k=1,nterms - n=j+k-1 - array(j,k)=sumx(n) - enddo - array(j,l)=sumy(j) - enddo - a(l)=determ(array,nterms)/delta - enddo - -! Calculate chi square - - do j=1,nterms - chisq=chisq-2*a(j)*sumy(j) - do k=1,nterms - n=j+k-1 - chisq=chisq+a(j)*a(k)*sumx(n) - enddo - enddo - free=npts-nterms - chisqr=chisq/free - end if - - return -end subroutine polfit diff --git a/lib/polyfit.f90 b/lib/polyfit.f90 new file mode 100644 index 00000000..63222304 --- /dev/null +++ b/lib/polyfit.f90 @@ -0,0 +1,72 @@ +subroutine polyfit(x,y,sigmay,npts,nterms,mode,a,chisqr) + implicit real*8 (a-h,o-z) + real*8 x(npts), y(npts), sigmay(npts), a(nterms) + real*8 sumx(10), sumy(10), array(10,10) + +! Accumulate weighted sums + nmax = 2*nterms-1 + sumx=0. + sumy=0. + chisq=0. + do i=1,npts + xi=x(i) + yi=y(i) + if(mode.lt.0) then + weight=1./abs(yi) + else if(mode.eq.0) then + weight=1 + else + weight=1./sigmay(i)**2 + end if + xterm=weight + do n=1,nmax + sumx(n)=sumx(n)+xterm + xterm=xterm*xi + enddo + yterm=weight*yi + do n=1,nterms + sumy(n)=sumy(n)+yterm + yterm=yterm*xi + enddo + chisq=chisq+weight*yi**2 + enddo + +! Construct matrices and calculate coefficients + do j=1,nterms + do k=1,nterms + n=j+k-1 + array(j,k)=sumx(n) + enddo + enddo + + delta=determ(array,nterms) + if(delta.eq.0) then + chisqr=0. + a=0. + else + do l=1,nterms + do j=1,nterms + do k=1,nterms + n=j+k-1 + array(j,k)=sumx(n) + enddo + array(j,l)=sumy(j) + enddo + a(l)=determ(array,nterms)/delta + enddo + +! Calculate chi square + + do j=1,nterms + chisq=chisq-2*a(j)*sumy(j) + do k=1,nterms + n=j+k-1 + chisq=chisq+a(j)*a(k)*sumx(n) + enddo + enddo + free=npts-nterms + chisqr=chisq/free + end if + + return +end subroutine polyfit diff --git a/lib/prcom.f90 b/lib/prcom.f90 new file mode 100644 index 00000000..ac333b6d --- /dev/null +++ b/lib/prcom.f90 @@ -0,0 +1 @@ + common/prcom/pr(126),mdat(126),mref(126,2),mdat2(126),mref2(126,2) diff --git a/lib/ps24.f90 b/lib/ps24.f90 deleted file mode 100644 index 241e49fa..00000000 --- a/lib/ps24.f90 +++ /dev/null @@ -1,27 +0,0 @@ -subroutine ps24(dat,nfft,s) - - parameter (NMAX=2520+2) - parameter (NHMAX=NMAX/2-1) - real dat(nfft) - real dat2(NMAX) - real s(NHMAX) - complex c(0:NMAX) - equivalence(dat2,c) - - nh=nfft/2 - do i=1,nh - dat2(i)=dat(i)/128.0 !### Why 128 ?? - enddo - do i=nh+1,nfft - dat2(i)=0. - enddo - - call four2a(c,nfft,1,-1,0) - - fac=1.0/nfft - do i=1,nh - s(i)=fac*(real(c(i))**2 + aimag(c(i))**2) - enddo - - return -end subroutine ps24 diff --git a/lib/ps4.f90 b/lib/ps4.f90 new file mode 100644 index 00000000..782ab50d --- /dev/null +++ b/lib/ps4.f90 @@ -0,0 +1,27 @@ +subroutine ps4(dat,nfft,s) + + parameter (NMAX=2520+2) + parameter (NHMAX=NMAX/2-1) + real dat(nfft) + real dat2(NMAX) + real s(NHMAX) + complex c(0:NMAX) + equivalence(dat2,c) + + nh=nfft/2 + do i=1,nh + dat2(i)=dat(i)/128.0 !### Why 128 ?? + enddo + do i=nh+1,nfft + dat2(i)=0. + enddo + + call four2a(c,nfft,1,-1,0) + + fac=1.0/nfft + do i=1,nh + s(i)=fac*(real(c(i))**2 + aimag(c(i))**2) + enddo + + return +end subroutine ps4 diff --git a/lib/psk_parse.f90 b/lib/psk_parse.f90 new file mode 100644 index 00000000..5f97732c --- /dev/null +++ b/lib/psk_parse.f90 @@ -0,0 +1,108 @@ +program psk_parse + + character line*256,callsign*12,callsign0*12,progname*30 + integer nc(6),ntot(6),nsingle(6) + logical zap + data callsign0/' '/ + + open(10,file='jt65-2',status='old') + nc=0 + ntot=0 + ncalls=0 + nsingle=0 + zap=.false. + + do iline=1,9999999 + read(10,'(a256)',end=900) line + n=len(trim(line)) + i1=0 + i2=0 + i3=0 + do i=1,n + if(ichar(line(i:i)).eq.9) then + if(i1.eq.0) then + i1=i + cycle + endif + if(i2.eq.0) then + i2=i + cycle + endif + if(i3.eq.0) then + i3=i + exit + endif + endif + enddo + callsign=line(1:i1-1) + + if(zap) then + if(callsign(1:1).ge.'0' .and. callsign(1:1).le.'9' .and. & + callsign(2:2).ge.'0' .and. callsign(2:2).le.'9' .and. & + callsign(3:3).ge.'0' .and. callsign(3:3).le.'9') cycle + + if(callsign(1:1).ge.'A' .and. callsign(1:1).le.'Z' .and. & + callsign(2:2).ge.'A' .and. callsign(2:2).le.'Z' .and. & + callsign(3:3).ge.'A' .and. callsign(3:3).le.'Z' .and. & + callsign(4:4).ge.'A' .and. callsign(4:4).le.'Z') cycle + + if(callsign(1:1).eq.'N' .and. & + callsign(2:2).ge.'0' .and. callsign(2:2).le.'9' .and. & + callsign(3:3).ge.'0' .and. callsign(3:3).le.'9') cycle + + endif + + progname=line(i1+1:i2-1) + do i=1,len(trim(progname)) + if(progname(i:i).eq.' ') progname(i:i)='_' + enddo + read(line(i2+1:i3-1),*) ndecodes + read(line(i3+1:),*) nreporters + + j=6 + if(index(progname,'WSJT-X').gt.0) j=1 + if(index(progname,'HB9HQX').gt.0) j=2 + if(index(progname,'JTDX').gt.0) j=3 + if(index(progname,'Comfort').gt.0) j=4 + if(index(progname,'COMFORT').gt.0) j=4 + if(index(progname,'JT65-HF').gt.0 .and. j.eq.6) j=5 + + nctot=sum(nc) + if(callsign.ne.callsign0 .and. nctot.gt.0) then + write(13,1000) callsign0,nc,nctot +1000 format(a12,6i8,i10) + if(nctot.eq.1) nsingle(j)=nsingle(j)+1 + nc=0 + callsign0=callsign + ncalls=ncalls+1 + endif + nc(j)=nc(j) + ndecodes + ntot(j)=ntot(j) + ndecodes + write(12,1010) iline,callsign,ndecodes,nreporters,progname +1010 format(i8,2x,a12,2x,2i8,2x,a30) + enddo + +900 nctot=sum(nc) + if(nctot.gt.0) write(13,1000) callsign0,nc,nctot + + write(*,1018) +1018 format(' Total WSJT-X HB9HQX JTDX Comfort JT65-HF Other'/ & + '----------------------------------------------------------') + write(*,1019) +1019 format('Spots reported; fraction of total:') + write(*,1020) sum(ntot),ntot +1020 format(i8,2x,6i8) + fac=1.0/sum(ntot) + write(*,1030) 1.0000,fac*ntot +1030 format(f8.4,2x,6f8.4,f10.4) + + write(*,1038) +1038 format(/'Singletons; as fraction of spots by same program') + write(*,1040) sum(nsingle),nsingle +1040 format(i8,2x,6i8) + write(*,1030) float(sum(nsingle))/sum(ntot),float(nsingle)/ntot + + write(*,1050) ncalls +1050 format(/'Distinct calls spotted:',i6) + +end program psk_parse diff --git a/lib/qra/qra64/Makefile.Win b/lib/qra/qra64/Makefile.Win new file mode 100644 index 00000000..7bd10c2d --- /dev/null +++ b/lib/qra/qra64/Makefile.Win @@ -0,0 +1,30 @@ +FC = gfortran +CC = gcc +CFLAGS = -O2 -Wall -I. -D_WIN32 + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: qra64.exe + +OBJS1 = main.o qra64.o +qra64.exe: $(OBJS1) + ${CC} -o qra64.exe $(OBJS1) ../qracodes/libqra64.a -lm + +OBJS2 = qra64sim.o options.o wavhdr.o +qra64sim.exe: $(OBJS2) + ${FC} -o qra64sim.exe $(OBJS2) ../qracodes/libqra64.a -lm + +.PHONY : clean + +clean: + $(RM) *.o qra64.exe qra64sim.exe diff --git a/lib/qra/qra64/fadengauss.c b/lib/qra/qra64/fadengauss.c new file mode 100644 index 00000000..c229626f --- /dev/null +++ b/lib/qra/qra64/fadengauss.c @@ -0,0 +1,302 @@ +// Gaussian energy fading tables for QRA64 +static const int glen_tab_gauss[64] = { + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, 5, 5, 5, 6, + 6, 6, 7, 7, 8, 8, 9, 10, + 10, 11, 12, 13, 14, 15, 17, 18, + 19, 21, 23, 25, 27, 29, 32, 34, + 37, 41, 44, 48, 52, 57, 62, 65 +}; +static const float ggauss1[2] = { +0.0296f, 0.9101f +}; +static const float ggauss2[2] = { +0.0350f, 0.8954f +}; +static const float ggauss3[2] = { +0.0411f, 0.8787f +}; +static const float ggauss4[2] = { +0.0483f, 0.8598f +}; +static const float ggauss5[2] = { +0.0566f, 0.8387f +}; +static const float ggauss6[2] = { +0.0660f, 0.8154f +}; +static const float ggauss7[2] = { +0.0767f, 0.7898f +}; +static const float ggauss8[2] = { +0.0886f, 0.7621f +}; +static const float ggauss9[2] = { +0.1017f, 0.7325f +}; +static const float ggauss10[2] = { +0.1159f, 0.7012f +}; +static const float ggauss11[2] = { +0.1310f, 0.6687f +}; +static const float ggauss12[2] = { +0.1465f, 0.6352f +}; +static const float ggauss13[2] = { +0.1621f, 0.6013f +}; +static const float ggauss14[2] = { +0.1771f, 0.5674f +}; +static const float ggauss15[2] = { +0.1911f, 0.5339f +}; +static const float ggauss16[2] = { +0.2034f, 0.5010f +}; +static const float ggauss17[3] = { +0.0299f, 0.2135f, 0.4690f +}; +static const float ggauss18[3] = { +0.0369f, 0.2212f, 0.4383f +}; +static const float ggauss19[3] = { +0.0454f, 0.2263f, 0.4088f +}; +static const float ggauss20[3] = { +0.0552f, 0.2286f, 0.3806f +}; +static const float ggauss21[3] = { +0.0658f, 0.2284f, 0.3539f +}; +static const float ggauss22[3] = { +0.0766f, 0.2258f, 0.3287f +}; +static const float ggauss23[3] = { +0.0869f, 0.2212f, 0.3049f +}; +static const float ggauss24[3] = { +0.0962f, 0.2148f, 0.2826f +}; +static const float ggauss25[4] = { +0.0351f, 0.1041f, 0.2071f, 0.2616f +}; +static const float ggauss26[4] = { +0.0429f, 0.1102f, 0.1984f, 0.2420f +}; +static const float ggauss27[4] = { +0.0508f, 0.1145f, 0.1890f, 0.2237f +}; +static const float ggauss28[4] = { +0.0582f, 0.1169f, 0.1791f, 0.2067f +}; +static const float ggauss29[5] = { +0.0289f, 0.0648f, 0.1176f, 0.1689f, 0.1908f +}; +static const float ggauss30[5] = { +0.0351f, 0.0703f, 0.1168f, 0.1588f, 0.1760f +}; +static const float ggauss31[5] = { +0.0411f, 0.0745f, 0.1146f, 0.1488f, 0.1623f +}; +static const float ggauss32[6] = { +0.0246f, 0.0466f, 0.0773f, 0.1115f, 0.1390f, 0.1497f +}; +static const float ggauss33[6] = { +0.0297f, 0.0512f, 0.0788f, 0.1075f, 0.1295f, 0.1379f +}; +static const float ggauss34[6] = { +0.0345f, 0.0549f, 0.0791f, 0.1029f, 0.1205f, 0.1270f +}; +static const float ggauss35[7] = { +0.0240f, 0.0387f, 0.0575f, 0.0784f, 0.0979f, 0.1118f, 0.1169f +}; +static const float ggauss36[7] = { +0.0281f, 0.0422f, 0.0590f, 0.0767f, 0.0926f, 0.1037f, 0.1076f +}; +static const float ggauss37[8] = { +0.0212f, 0.0318f, 0.0449f, 0.0596f, 0.0744f, 0.0872f, 0.0960f, 0.0991f +}; +static const float ggauss38[8] = { +0.0247f, 0.0348f, 0.0467f, 0.0593f, 0.0716f, 0.0819f, 0.0887f, 0.0911f +}; +static const float ggauss39[9] = { +0.0199f, 0.0278f, 0.0372f, 0.0476f, 0.0584f, 0.0684f, 0.0766f, 0.0819f, +0.0838f +}; +static const float ggauss40[10] = { +0.0166f, 0.0228f, 0.0303f, 0.0388f, 0.0478f, 0.0568f, 0.0649f, 0.0714f, +0.0756f, 0.0771f +}; +static const float ggauss41[10] = { +0.0193f, 0.0254f, 0.0322f, 0.0397f, 0.0474f, 0.0548f, 0.0613f, 0.0664f, +0.0697f, 0.0709f +}; +static const float ggauss42[11] = { +0.0168f, 0.0217f, 0.0273f, 0.0335f, 0.0399f, 0.0464f, 0.0524f, 0.0576f, +0.0617f, 0.0643f, 0.0651f +}; +static const float ggauss43[12] = { +0.0151f, 0.0191f, 0.0237f, 0.0288f, 0.0342f, 0.0396f, 0.0449f, 0.0498f, +0.0540f, 0.0572f, 0.0592f, 0.0599f +}; +static const float ggauss44[13] = { +0.0138f, 0.0171f, 0.0210f, 0.0252f, 0.0297f, 0.0343f, 0.0388f, 0.0432f, +0.0471f, 0.0504f, 0.0529f, 0.0545f, 0.0550f +}; +static const float ggauss45[14] = { +0.0128f, 0.0157f, 0.0189f, 0.0224f, 0.0261f, 0.0300f, 0.0339f, 0.0377f, +0.0412f, 0.0444f, 0.0470f, 0.0489f, 0.0501f, 0.0505f +}; +static const float ggauss46[15] = { +0.0121f, 0.0146f, 0.0173f, 0.0202f, 0.0234f, 0.0266f, 0.0299f, 0.0332f, +0.0363f, 0.0391f, 0.0416f, 0.0437f, 0.0452f, 0.0461f, 0.0464f +}; +static const float ggauss47[17] = { +0.0097f, 0.0116f, 0.0138f, 0.0161f, 0.0186f, 0.0212f, 0.0239f, 0.0267f, +0.0294f, 0.0321f, 0.0346f, 0.0369f, 0.0389f, 0.0405f, 0.0417f, 0.0424f, +0.0427f +}; +static const float ggauss48[18] = { +0.0096f, 0.0113f, 0.0131f, 0.0151f, 0.0172f, 0.0194f, 0.0217f, 0.0241f, +0.0264f, 0.0287f, 0.0308f, 0.0329f, 0.0347f, 0.0362f, 0.0375f, 0.0384f, +0.0390f, 0.0392f +}; +static const float ggauss49[19] = { +0.0095f, 0.0110f, 0.0126f, 0.0143f, 0.0161f, 0.0180f, 0.0199f, 0.0219f, +0.0239f, 0.0258f, 0.0277f, 0.0294f, 0.0310f, 0.0325f, 0.0337f, 0.0347f, +0.0354f, 0.0358f, 0.0360f +}; +static const float ggauss50[21] = { +0.0083f, 0.0095f, 0.0108f, 0.0122f, 0.0136f, 0.0152f, 0.0168f, 0.0184f, +0.0201f, 0.0217f, 0.0234f, 0.0250f, 0.0265f, 0.0279f, 0.0292f, 0.0303f, +0.0313f, 0.0320f, 0.0326f, 0.0329f, 0.0330f +}; +static const float ggauss51[23] = { +0.0074f, 0.0084f, 0.0095f, 0.0106f, 0.0118f, 0.0131f, 0.0144f, 0.0157f, +0.0171f, 0.0185f, 0.0199f, 0.0213f, 0.0227f, 0.0240f, 0.0252f, 0.0263f, +0.0273f, 0.0282f, 0.0290f, 0.0296f, 0.0300f, 0.0303f, 0.0303f +}; +static const float ggauss52[25] = { +0.0068f, 0.0076f, 0.0085f, 0.0094f, 0.0104f, 0.0115f, 0.0126f, 0.0137f, +0.0149f, 0.0160f, 0.0172f, 0.0184f, 0.0196f, 0.0207f, 0.0218f, 0.0228f, +0.0238f, 0.0247f, 0.0255f, 0.0262f, 0.0268f, 0.0273f, 0.0276f, 0.0278f, +0.0279f +}; +static const float ggauss53[27] = { +0.0063f, 0.0070f, 0.0078f, 0.0086f, 0.0094f, 0.0103f, 0.0112f, 0.0121f, +0.0131f, 0.0141f, 0.0151f, 0.0161f, 0.0170f, 0.0180f, 0.0190f, 0.0199f, +0.0208f, 0.0216f, 0.0224f, 0.0231f, 0.0237f, 0.0243f, 0.0247f, 0.0251f, +0.0254f, 0.0255f, 0.0256f +}; +static const float ggauss54[29] = { +0.0060f, 0.0066f, 0.0072f, 0.0079f, 0.0086f, 0.0093f, 0.0101f, 0.0109f, +0.0117f, 0.0125f, 0.0133f, 0.0142f, 0.0150f, 0.0159f, 0.0167f, 0.0175f, +0.0183f, 0.0190f, 0.0197f, 0.0204f, 0.0210f, 0.0216f, 0.0221f, 0.0225f, +0.0228f, 0.0231f, 0.0233f, 0.0234f, 0.0235f +}; +static const float ggauss55[32] = { +0.0053f, 0.0058f, 0.0063f, 0.0068f, 0.0074f, 0.0080f, 0.0086f, 0.0093f, +0.0099f, 0.0106f, 0.0113f, 0.0120f, 0.0127f, 0.0134f, 0.0141f, 0.0148f, +0.0155f, 0.0162f, 0.0168f, 0.0174f, 0.0180f, 0.0186f, 0.0191f, 0.0196f, +0.0201f, 0.0204f, 0.0208f, 0.0211f, 0.0213f, 0.0214f, 0.0215f, 0.0216f +}; +static const float ggauss56[34] = { +0.0052f, 0.0056f, 0.0060f, 0.0065f, 0.0070f, 0.0075f, 0.0080f, 0.0086f, +0.0091f, 0.0097f, 0.0103f, 0.0109f, 0.0115f, 0.0121f, 0.0127f, 0.0133f, +0.0138f, 0.0144f, 0.0150f, 0.0155f, 0.0161f, 0.0166f, 0.0170f, 0.0175f, +0.0179f, 0.0183f, 0.0186f, 0.0189f, 0.0192f, 0.0194f, 0.0196f, 0.0197f, +0.0198f, 0.0198f +}; +static const float ggauss57[37] = { +0.0047f, 0.0051f, 0.0055f, 0.0058f, 0.0063f, 0.0067f, 0.0071f, 0.0076f, +0.0080f, 0.0085f, 0.0090f, 0.0095f, 0.0100f, 0.0105f, 0.0110f, 0.0115f, +0.0120f, 0.0125f, 0.0130f, 0.0134f, 0.0139f, 0.0144f, 0.0148f, 0.0152f, +0.0156f, 0.0160f, 0.0164f, 0.0167f, 0.0170f, 0.0173f, 0.0175f, 0.0177f, +0.0179f, 0.0180f, 0.0181f, 0.0181f, 0.0182f +}; +static const float ggauss58[41] = { +0.0041f, 0.0044f, 0.0047f, 0.0050f, 0.0054f, 0.0057f, 0.0060f, 0.0064f, +0.0068f, 0.0072f, 0.0076f, 0.0080f, 0.0084f, 0.0088f, 0.0092f, 0.0096f, +0.0101f, 0.0105f, 0.0109f, 0.0113f, 0.0117f, 0.0121f, 0.0125f, 0.0129f, +0.0133f, 0.0137f, 0.0140f, 0.0144f, 0.0147f, 0.0150f, 0.0153f, 0.0155f, +0.0158f, 0.0160f, 0.0162f, 0.0163f, 0.0164f, 0.0165f, 0.0166f, 0.0167f, +0.0167f +}; +static const float ggauss59[44] = { +0.0039f, 0.0042f, 0.0044f, 0.0047f, 0.0050f, 0.0053f, 0.0056f, 0.0059f, +0.0062f, 0.0065f, 0.0068f, 0.0072f, 0.0075f, 0.0079f, 0.0082f, 0.0086f, +0.0089f, 0.0093f, 0.0096f, 0.0100f, 0.0104f, 0.0107f, 0.0110f, 0.0114f, +0.0117f, 0.0120f, 0.0124f, 0.0127f, 0.0130f, 0.0132f, 0.0135f, 0.0138f, +0.0140f, 0.0142f, 0.0144f, 0.0146f, 0.0148f, 0.0149f, 0.0150f, 0.0151f, +0.0152f, 0.0153f, 0.0153f, 0.0153f +}; +static const float ggauss60[48] = { +0.0036f, 0.0038f, 0.0040f, 0.0042f, 0.0044f, 0.0047f, 0.0049f, 0.0052f, +0.0055f, 0.0057f, 0.0060f, 0.0063f, 0.0066f, 0.0068f, 0.0071f, 0.0074f, +0.0077f, 0.0080f, 0.0083f, 0.0086f, 0.0089f, 0.0092f, 0.0095f, 0.0098f, +0.0101f, 0.0104f, 0.0107f, 0.0109f, 0.0112f, 0.0115f, 0.0117f, 0.0120f, +0.0122f, 0.0124f, 0.0126f, 0.0128f, 0.0130f, 0.0132f, 0.0134f, 0.0135f, +0.0136f, 0.0137f, 0.0138f, 0.0139f, 0.0140f, 0.0140f, 0.0140f, 0.0140f +}; +static const float ggauss61[52] = { +0.0033f, 0.0035f, 0.0037f, 0.0039f, 0.0041f, 0.0043f, 0.0045f, 0.0047f, +0.0049f, 0.0051f, 0.0053f, 0.0056f, 0.0058f, 0.0060f, 0.0063f, 0.0065f, +0.0068f, 0.0070f, 0.0073f, 0.0075f, 0.0078f, 0.0080f, 0.0083f, 0.0085f, +0.0088f, 0.0090f, 0.0093f, 0.0095f, 0.0098f, 0.0100f, 0.0102f, 0.0105f, +0.0107f, 0.0109f, 0.0111f, 0.0113f, 0.0115f, 0.0116f, 0.0118f, 0.0120f, +0.0121f, 0.0122f, 0.0124f, 0.0125f, 0.0126f, 0.0126f, 0.0127f, 0.0128f, +0.0128f, 0.0129f, 0.0129f, 0.0129f +}; +static const float ggauss62[57] = { +0.0030f, 0.0031f, 0.0033f, 0.0034f, 0.0036f, 0.0038f, 0.0039f, 0.0041f, +0.0043f, 0.0045f, 0.0047f, 0.0048f, 0.0050f, 0.0052f, 0.0054f, 0.0056f, +0.0058f, 0.0060f, 0.0063f, 0.0065f, 0.0067f, 0.0069f, 0.0071f, 0.0073f, +0.0075f, 0.0077f, 0.0080f, 0.0082f, 0.0084f, 0.0086f, 0.0088f, 0.0090f, +0.0092f, 0.0094f, 0.0096f, 0.0097f, 0.0099f, 0.0101f, 0.0103f, 0.0104f, +0.0106f, 0.0107f, 0.0108f, 0.0110f, 0.0111f, 0.0112f, 0.0113f, 0.0114f, +0.0115f, 0.0116f, 0.0116f, 0.0117f, 0.0117f, 0.0118f, 0.0118f, 0.0118f, +0.0118f +}; +static const float ggauss63[62] = { +0.0027f, 0.0029f, 0.0030f, 0.0031f, 0.0032f, 0.0034f, 0.0035f, 0.0037f, +0.0038f, 0.0040f, 0.0041f, 0.0043f, 0.0045f, 0.0046f, 0.0048f, 0.0049f, +0.0051f, 0.0053f, 0.0055f, 0.0056f, 0.0058f, 0.0060f, 0.0062f, 0.0063f, +0.0065f, 0.0067f, 0.0069f, 0.0071f, 0.0072f, 0.0074f, 0.0076f, 0.0078f, +0.0079f, 0.0081f, 0.0083f, 0.0084f, 0.0086f, 0.0088f, 0.0089f, 0.0091f, +0.0092f, 0.0094f, 0.0095f, 0.0096f, 0.0098f, 0.0099f, 0.0100f, 0.0101f, +0.0102f, 0.0103f, 0.0104f, 0.0105f, 0.0105f, 0.0106f, 0.0107f, 0.0107f, +0.0108f, 0.0108f, 0.0108f, 0.0108f, 0.0109f, 0.0109f +}; +static const float ggauss64[65] = { +0.0028f, 0.0029f, 0.0030f, 0.0031f, 0.0032f, 0.0034f, 0.0035f, 0.0036f, +0.0037f, 0.0039f, 0.0040f, 0.0041f, 0.0043f, 0.0044f, 0.0046f, 0.0047f, +0.0048f, 0.0050f, 0.0051f, 0.0053f, 0.0054f, 0.0056f, 0.0057f, 0.0059f, +0.0060f, 0.0062f, 0.0063f, 0.0065f, 0.0066f, 0.0068f, 0.0069f, 0.0071f, +0.0072f, 0.0074f, 0.0075f, 0.0077f, 0.0078f, 0.0079f, 0.0081f, 0.0082f, +0.0083f, 0.0084f, 0.0086f, 0.0087f, 0.0088f, 0.0089f, 0.0090f, 0.0091f, +0.0092f, 0.0093f, 0.0094f, 0.0094f, 0.0095f, 0.0096f, 0.0097f, 0.0097f, +0.0098f, 0.0098f, 0.0099f, 0.0099f, 0.0099f, 0.0099f, 0.0100f, 0.0100f, +0.0100f +}; +static const float *gptr_tab_gauss[64] = { +ggauss1, ggauss2, ggauss3, ggauss4, +ggauss5, ggauss6, ggauss7, ggauss8, +ggauss9, ggauss10, ggauss11, ggauss12, +ggauss13, ggauss14, ggauss15, ggauss16, +ggauss17, ggauss18, ggauss19, ggauss20, +ggauss21, ggauss22, ggauss23, ggauss24, +ggauss25, ggauss26, ggauss27, ggauss28, +ggauss29, ggauss30, ggauss31, ggauss32, +ggauss33, ggauss34, ggauss35, ggauss36, +ggauss37, ggauss38, ggauss39, ggauss40, +ggauss41, ggauss42, ggauss43, ggauss44, +ggauss45, ggauss46, ggauss47, ggauss48, +ggauss49, ggauss50, ggauss51, ggauss52, +ggauss53, ggauss54, ggauss55, ggauss56, +ggauss57, ggauss58, ggauss59, ggauss60, +ggauss61, ggauss62, ggauss63, ggauss64 +}; diff --git a/lib/qra/qra64/fadenlorentz.c b/lib/qra/qra64/fadenlorentz.c new file mode 100644 index 00000000..673a8903 --- /dev/null +++ b/lib/qra/qra64/fadenlorentz.c @@ -0,0 +1,304 @@ +// Lorentz energy fading tables for QRA64 +static const int glen_tab_lorentz[64] = { + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 4, 4, 4, + 4, 4, 5, 5, 5, 5, 6, 6, + 7, 7, 7, 8, 8, 9, 10, 10, + 11, 12, 13, 14, 15, 16, 17, 19, + 20, 22, 23, 25, 27, 30, 32, 35, + 38, 41, 45, 49, 53, 57, 62, 65 +}; +static const float glorentz1[2] = { +0.0214f, 0.9107f +}; +static const float glorentz2[2] = { +0.0244f, 0.9030f +}; +static const float glorentz3[2] = { +0.0280f, 0.8950f +}; +static const float glorentz4[2] = { +0.0314f, 0.8865f +}; +static const float glorentz5[2] = { +0.0349f, 0.8773f +}; +static const float glorentz6[2] = { +0.0388f, 0.8675f +}; +static const float glorentz7[2] = { +0.0426f, 0.8571f +}; +static const float glorentz8[2] = { +0.0463f, 0.8459f +}; +static const float glorentz9[2] = { +0.0500f, 0.8339f +}; +static const float glorentz10[2] = { +0.0538f, 0.8210f +}; +static const float glorentz11[2] = { +0.0579f, 0.8074f +}; +static const float glorentz12[2] = { +0.0622f, 0.7930f +}; +static const float glorentz13[2] = { +0.0668f, 0.7777f +}; +static const float glorentz14[2] = { +0.0715f, 0.7616f +}; +static const float glorentz15[3] = { +0.0196f, 0.0765f, 0.7445f +}; +static const float glorentz16[3] = { +0.0210f, 0.0816f, 0.7267f +}; +static const float glorentz17[3] = { +0.0226f, 0.0870f, 0.7080f +}; +static const float glorentz18[3] = { +0.0242f, 0.0925f, 0.6885f +}; +static const float glorentz19[3] = { +0.0259f, 0.0981f, 0.6682f +}; +static const float glorentz20[3] = { +0.0277f, 0.1039f, 0.6472f +}; +static const float glorentz21[3] = { +0.0296f, 0.1097f, 0.6255f +}; +static const float glorentz22[4] = { +0.0143f, 0.0316f, 0.1155f, 0.6031f +}; +static const float glorentz23[4] = { +0.0153f, 0.0337f, 0.1213f, 0.5803f +}; +static const float glorentz24[4] = { +0.0163f, 0.0358f, 0.1270f, 0.5570f +}; +static const float glorentz25[4] = { +0.0174f, 0.0381f, 0.1325f, 0.5333f +}; +static const float glorentz26[4] = { +0.0186f, 0.0405f, 0.1378f, 0.5095f +}; +static const float glorentz27[5] = { +0.0113f, 0.0198f, 0.0429f, 0.1428f, 0.4855f +}; +static const float glorentz28[5] = { +0.0120f, 0.0211f, 0.0455f, 0.1473f, 0.4615f +}; +static const float glorentz29[5] = { +0.0129f, 0.0225f, 0.0481f, 0.1514f, 0.4376f +}; +static const float glorentz30[5] = { +0.0137f, 0.0239f, 0.0508f, 0.1549f, 0.4140f +}; +static const float glorentz31[6] = { +0.0095f, 0.0147f, 0.0254f, 0.0536f, 0.1578f, 0.3907f +}; +static const float glorentz32[6] = { +0.0101f, 0.0156f, 0.0270f, 0.0564f, 0.1600f, 0.3680f +}; +static const float glorentz33[7] = { +0.0076f, 0.0109f, 0.0167f, 0.0287f, 0.0592f, 0.1614f, 0.3458f +}; +static const float glorentz34[7] = { +0.0081f, 0.0116f, 0.0178f, 0.0305f, 0.0621f, 0.1620f, 0.3243f +}; +static const float glorentz35[7] = { +0.0087f, 0.0124f, 0.0190f, 0.0324f, 0.0649f, 0.1618f, 0.3035f +}; +static const float glorentz36[8] = { +0.0069f, 0.0093f, 0.0133f, 0.0203f, 0.0343f, 0.0676f, 0.1607f, 0.2836f +}; +static const float glorentz37[8] = { +0.0074f, 0.0100f, 0.0142f, 0.0216f, 0.0362f, 0.0702f, 0.1588f, 0.2645f +}; +static const float glorentz38[9] = { +0.0061f, 0.0080f, 0.0107f, 0.0152f, 0.0230f, 0.0382f, 0.0726f, 0.1561f, +0.2464f +}; +static const float glorentz39[10] = { +0.0052f, 0.0066f, 0.0086f, 0.0115f, 0.0162f, 0.0244f, 0.0402f, 0.0747f, +0.1526f, 0.2291f +}; +static const float glorentz40[10] = { +0.0056f, 0.0071f, 0.0092f, 0.0123f, 0.0173f, 0.0259f, 0.0422f, 0.0766f, +0.1484f, 0.2128f +}; +static const float glorentz41[11] = { +0.0049f, 0.0061f, 0.0076f, 0.0098f, 0.0132f, 0.0184f, 0.0274f, 0.0441f, +0.0780f, 0.1437f, 0.1975f +}; +static const float glorentz42[12] = { +0.0044f, 0.0053f, 0.0065f, 0.0082f, 0.0106f, 0.0141f, 0.0196f, 0.0290f, +0.0460f, 0.0791f, 0.1384f, 0.1831f +}; +static const float glorentz43[13] = { +0.0040f, 0.0048f, 0.0057f, 0.0070f, 0.0088f, 0.0113f, 0.0150f, 0.0209f, +0.0305f, 0.0477f, 0.0797f, 0.1327f, 0.1695f +}; +static const float glorentz44[14] = { +0.0037f, 0.0043f, 0.0051f, 0.0062f, 0.0075f, 0.0094f, 0.0121f, 0.0160f, +0.0221f, 0.0321f, 0.0493f, 0.0799f, 0.1267f, 0.1568f +}; +static const float glorentz45[15] = { +0.0035f, 0.0040f, 0.0047f, 0.0055f, 0.0066f, 0.0081f, 0.0101f, 0.0129f, +0.0171f, 0.0234f, 0.0335f, 0.0506f, 0.0795f, 0.1204f, 0.1450f +}; +static const float glorentz46[16] = { +0.0033f, 0.0037f, 0.0043f, 0.0050f, 0.0059f, 0.0071f, 0.0087f, 0.0108f, +0.0138f, 0.0181f, 0.0246f, 0.0349f, 0.0517f, 0.0786f, 0.1141f, 0.1340f +}; +static const float glorentz47[17] = { +0.0031f, 0.0035f, 0.0040f, 0.0046f, 0.0054f, 0.0064f, 0.0077f, 0.0093f, +0.0116f, 0.0147f, 0.0192f, 0.0259f, 0.0362f, 0.0525f, 0.0773f, 0.1076f, +0.1237f +}; +static const float glorentz48[19] = { +0.0027f, 0.0030f, 0.0034f, 0.0038f, 0.0043f, 0.0050f, 0.0058f, 0.0069f, +0.0082f, 0.0100f, 0.0123f, 0.0156f, 0.0203f, 0.0271f, 0.0374f, 0.0530f, +0.0755f, 0.1013f, 0.1141f +}; +static const float glorentz49[20] = { +0.0026f, 0.0029f, 0.0032f, 0.0036f, 0.0041f, 0.0047f, 0.0054f, 0.0063f, +0.0074f, 0.0088f, 0.0107f, 0.0131f, 0.0165f, 0.0213f, 0.0282f, 0.0383f, +0.0531f, 0.0734f, 0.0950f, 0.1053f +}; +static const float glorentz50[22] = { +0.0023f, 0.0025f, 0.0028f, 0.0031f, 0.0035f, 0.0039f, 0.0044f, 0.0050f, +0.0058f, 0.0067f, 0.0079f, 0.0094f, 0.0114f, 0.0139f, 0.0175f, 0.0223f, +0.0292f, 0.0391f, 0.0529f, 0.0709f, 0.0889f, 0.0971f +}; +static const float glorentz51[23] = { +0.0023f, 0.0025f, 0.0027f, 0.0030f, 0.0034f, 0.0037f, 0.0042f, 0.0048f, +0.0054f, 0.0062f, 0.0072f, 0.0085f, 0.0100f, 0.0121f, 0.0148f, 0.0184f, +0.0233f, 0.0301f, 0.0396f, 0.0524f, 0.0681f, 0.0829f, 0.0894f +}; +static const float glorentz52[25] = { +0.0021f, 0.0023f, 0.0025f, 0.0027f, 0.0030f, 0.0033f, 0.0036f, 0.0040f, +0.0045f, 0.0051f, 0.0058f, 0.0067f, 0.0077f, 0.0090f, 0.0107f, 0.0128f, +0.0156f, 0.0192f, 0.0242f, 0.0308f, 0.0398f, 0.0515f, 0.0650f, 0.0772f, +0.0824f +}; +static const float glorentz53[27] = { +0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0027f, 0.0029f, 0.0032f, 0.0035f, +0.0039f, 0.0044f, 0.0049f, 0.0055f, 0.0062f, 0.0072f, 0.0083f, 0.0096f, +0.0113f, 0.0135f, 0.0164f, 0.0201f, 0.0249f, 0.0314f, 0.0398f, 0.0502f, +0.0619f, 0.0718f, 0.0759f +}; +static const float glorentz54[30] = { +0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0026f, 0.0029f, +0.0031f, 0.0034f, 0.0038f, 0.0042f, 0.0047f, 0.0052f, 0.0059f, 0.0067f, +0.0076f, 0.0088f, 0.0102f, 0.0120f, 0.0143f, 0.0171f, 0.0208f, 0.0256f, +0.0317f, 0.0395f, 0.0488f, 0.0586f, 0.0666f, 0.0698f +}; +static const float glorentz55[32] = { +0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0026f, +0.0028f, 0.0031f, 0.0034f, 0.0037f, 0.0041f, 0.0045f, 0.0050f, 0.0056f, +0.0063f, 0.0071f, 0.0081f, 0.0094f, 0.0108f, 0.0127f, 0.0149f, 0.0178f, +0.0214f, 0.0261f, 0.0318f, 0.0389f, 0.0470f, 0.0553f, 0.0618f, 0.0643f +}; +static const float glorentz56[35] = { +0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0020f, 0.0021f, 0.0023f, +0.0024f, 0.0026f, 0.0028f, 0.0031f, 0.0033f, 0.0036f, 0.0040f, 0.0044f, +0.0049f, 0.0054f, 0.0060f, 0.0067f, 0.0076f, 0.0087f, 0.0099f, 0.0114f, +0.0133f, 0.0156f, 0.0184f, 0.0220f, 0.0264f, 0.0318f, 0.0381f, 0.0451f, +0.0520f, 0.0572f, 0.0591f +}; +static const float glorentz57[38] = { +0.0013f, 0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, +0.0021f, 0.0023f, 0.0024f, 0.0026f, 0.0028f, 0.0031f, 0.0033f, 0.0036f, +0.0039f, 0.0043f, 0.0047f, 0.0052f, 0.0058f, 0.0064f, 0.0072f, 0.0081f, +0.0092f, 0.0104f, 0.0120f, 0.0139f, 0.0162f, 0.0190f, 0.0224f, 0.0265f, +0.0315f, 0.0371f, 0.0431f, 0.0487f, 0.0529f, 0.0544f +}; +static const float glorentz58[41] = { +0.0012f, 0.0013f, 0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, +0.0019f, 0.0020f, 0.0022f, 0.0023f, 0.0025f, 0.0026f, 0.0028f, 0.0030f, +0.0033f, 0.0036f, 0.0039f, 0.0042f, 0.0046f, 0.0050f, 0.0056f, 0.0061f, +0.0068f, 0.0076f, 0.0086f, 0.0097f, 0.0110f, 0.0125f, 0.0144f, 0.0167f, +0.0194f, 0.0226f, 0.0265f, 0.0309f, 0.0359f, 0.0409f, 0.0455f, 0.0488f, +0.0500f +}; +static const float glorentz59[45] = { +0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, 0.0015f, 0.0016f, +0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0023f, 0.0025f, +0.0026f, 0.0028f, 0.0030f, 0.0033f, 0.0035f, 0.0038f, 0.0041f, 0.0045f, +0.0049f, 0.0054f, 0.0059f, 0.0065f, 0.0072f, 0.0081f, 0.0090f, 0.0102f, +0.0115f, 0.0130f, 0.0149f, 0.0171f, 0.0197f, 0.0227f, 0.0263f, 0.0302f, +0.0345f, 0.0387f, 0.0425f, 0.0451f, 0.0460f +}; +static const float glorentz60[49] = { +0.0010f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, +0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, 0.0021f, +0.0022f, 0.0024f, 0.0025f, 0.0027f, 0.0028f, 0.0030f, 0.0033f, 0.0035f, +0.0038f, 0.0041f, 0.0044f, 0.0048f, 0.0052f, 0.0057f, 0.0063f, 0.0069f, +0.0077f, 0.0085f, 0.0095f, 0.0106f, 0.0119f, 0.0135f, 0.0153f, 0.0174f, +0.0199f, 0.0227f, 0.0259f, 0.0293f, 0.0330f, 0.0365f, 0.0395f, 0.0415f, +0.0423f +}; +static const float glorentz61[53] = { +0.0009f, 0.0010f, 0.0010f, 0.0011f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, +0.0013f, 0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0016f, 0.0017f, 0.0018f, +0.0019f, 0.0020f, 0.0021f, 0.0023f, 0.0024f, 0.0025f, 0.0027f, 0.0029f, +0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0041f, 0.0044f, 0.0047f, 0.0051f, +0.0056f, 0.0061f, 0.0067f, 0.0073f, 0.0081f, 0.0089f, 0.0099f, 0.0110f, +0.0124f, 0.0139f, 0.0156f, 0.0176f, 0.0199f, 0.0225f, 0.0253f, 0.0283f, +0.0314f, 0.0343f, 0.0367f, 0.0383f, 0.0389f +}; +static const float glorentz62[57] = { +0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, 0.0011f, 0.0011f, 0.0011f, +0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, 0.0015f, 0.0015f, 0.0016f, +0.0017f, 0.0018f, 0.0019f, 0.0020f, 0.0021f, 0.0022f, 0.0023f, 0.0024f, +0.0026f, 0.0027f, 0.0029f, 0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0040f, +0.0043f, 0.0047f, 0.0050f, 0.0055f, 0.0059f, 0.0064f, 0.0070f, 0.0077f, +0.0085f, 0.0093f, 0.0103f, 0.0114f, 0.0127f, 0.0142f, 0.0158f, 0.0177f, +0.0198f, 0.0221f, 0.0246f, 0.0272f, 0.0297f, 0.0321f, 0.0340f, 0.0353f, +0.0357f +}; +static const float glorentz63[62] = { +0.0008f, 0.0008f, 0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, 0.0010f, +0.0011f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, +0.0015f, 0.0015f, 0.0016f, 0.0017f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, +0.0021f, 0.0022f, 0.0023f, 0.0025f, 0.0026f, 0.0028f, 0.0029f, 0.0031f, +0.0033f, 0.0035f, 0.0038f, 0.0040f, 0.0043f, 0.0046f, 0.0050f, 0.0053f, +0.0058f, 0.0062f, 0.0068f, 0.0074f, 0.0081f, 0.0088f, 0.0097f, 0.0106f, +0.0117f, 0.0130f, 0.0144f, 0.0159f, 0.0176f, 0.0195f, 0.0216f, 0.0237f, +0.0259f, 0.0280f, 0.0299f, 0.0315f, 0.0325f, 0.0328f +}; +static const float glorentz64[65] = { +0.0008f, 0.0008f, 0.0008f, 0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, +0.0010f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, +0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, +0.0020f, 0.0021f, 0.0022f, 0.0023f, 0.0024f, 0.0025f, 0.0027f, 0.0028f, +0.0030f, 0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0040f, 0.0043f, 0.0046f, +0.0049f, 0.0052f, 0.0056f, 0.0061f, 0.0066f, 0.0071f, 0.0077f, 0.0084f, +0.0091f, 0.0100f, 0.0109f, 0.0120f, 0.0132f, 0.0145f, 0.0159f, 0.0175f, +0.0192f, 0.0209f, 0.0228f, 0.0246f, 0.0264f, 0.0279f, 0.0291f, 0.0299f, +0.0301f +}; +static const float *gptr_tab_lorentz[64] = { +glorentz1, glorentz2, glorentz3, glorentz4, +glorentz5, glorentz6, glorentz7, glorentz8, +glorentz9, glorentz10, glorentz11, glorentz12, +glorentz13, glorentz14, glorentz15, glorentz16, +glorentz17, glorentz18, glorentz19, glorentz20, +glorentz21, glorentz22, glorentz23, glorentz24, +glorentz25, glorentz26, glorentz27, glorentz28, +glorentz29, glorentz30, glorentz31, glorentz32, +glorentz33, glorentz34, glorentz35, glorentz36, +glorentz37, glorentz38, glorentz39, glorentz40, +glorentz41, glorentz42, glorentz43, glorentz44, +glorentz45, glorentz46, glorentz47, glorentz48, +glorentz49, glorentz50, glorentz51, glorentz52, +glorentz53, glorentz54, glorentz55, glorentz56, +glorentz57, glorentz58, glorentz59, glorentz60, +glorentz61, glorentz62, glorentz63, glorentz64 +}; diff --git a/lib/qra/qra64/main.c b/lib/qra/qra64/main.c new file mode 100644 index 00000000..b685fd31 --- /dev/null +++ b/lib/qra/qra64/main.c @@ -0,0 +1,746 @@ +/* +main.c +QRA64 mode encode/decode tests + +(c) 2016 - Nico Palermo, IV3NWV + +Thanks to Andrea Montefusco IW0HDV for his help on adapting the sources +to OSs other than MS Windows + +------------------------------------------------------------------------------ +This file is part of the qracodes project, a Forward Error Control +encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. + +Files in this package: + main.c - this file + qra64.c/.h - qra64 mode encode/decoding functions + + ../qracodes/normrnd.{c,h} - random gaussian number generator + ../qracodes/npfwht.{c,h} - Fast Walsh-Hadamard Transforms + ../qracodes/pdmath.{c,h} - Elementary math on probability distributions + ../qracodes/qra12_63_64_irr_b.{c,h} - Tables for a QRA(12,63) irregular RA + code over GF(64) + ../qracodes/qra13_64_64_irr_e.{c,h} - Tables for a QRA(13,64) irregular RA + code over GF(64) + ../qracodes/qracodes.{c,h} - QRA codes encoding/decoding functions + +------------------------------------------------------------------------------- + + qracodes 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 of the License, or + (at your option) any later version. + qracodes 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 qracodes source distribution. + If not, see . + +----------------------------------------------------------------------------- + +The code used by the QRA64 mode is the code: QRA13_64_64_IRR_E: K=13 +N=64 Q=64 irregular QRA code (defined in qra13_64_64_irr_e.{h,c}). + +This code has been designed to include a CRC as the 13th information +symbol and improve the code UER (Undetected Error Rate). The CRC +symbol is not sent along the channel (the codes are punctured) and the +resulting code is still a (12,63) code with an effective code rate of +R = 12/63. +*/ + +// OS dependent defines and includes ------------------------------------------ + +#if _WIN32 // note the underscore: without it, it's not msdn official! +// Windows (x64 and x86) +#include // required only for GetTickCount(...) +#include // _beginthread +#endif + +#if __linux__ +#include +#include + +unsigned GetTickCount(void) { + struct timespec ts; + unsigned theTick = 0U; + clock_gettime( CLOCK_REALTIME, &ts ); + theTick = ts.tv_nsec / 1000000; + theTick += ts.tv_sec * 1000; + return theTick; +} +#endif + +#if __APPLE__ +#endif + +#include +#include +#include + +#include "qra64.h" +#include "../qracodes/normrnd.h" // gaussian numbers generator + +// ---------------------------------------------------------------------------- + +// channel types +#define CHANNEL_AWGN 0 +#define CHANNEL_RAYLEIGH 1 +#define CHANNEL_FASTFADE 2 + +#define JT65_SNR_EBNO_OFFSET 29.1f // with the synch used in JT65 +#define QRA64_SNR_EBNO_OFFSET 31.0f // with the costas array synch + +void printwordd(char *msg, int *x, int size) +{ + int k; + printf("\n%s ",msg); + for (k=0;k-15) + if (channel_type == CHANNEL_AWGN) + for (k=0;k=0) { // decoded + printf("K1JT rx: received with apcode=%d %s\n",rc, decode_type[rc]); + +// Step 2a: K1JT replies to IV3NWV (with no grid) + printf("K1JT tx: IV3NWV K1JT\n"); + encodemsg_jt65(x,CALL_IV3NWV,CALL_K1JT, GRID_BLANK); + qra64_encode(codec_k1jt, y, x); + rx = mfskchannel(y,channel_type,EbNodB); + +// Step 2b: IV3NWV attempts to decode [? ? ?], [IV3NWV ? ?] or [IV3NWV ?] + rc = qra64_decode(codec_iv3nwv, 0, xdec,rx); + if (rc>=0) { // decoded + printf("IV3NWV rx: received with apcode=%d %s\n",rc, decode_type[rc]); + +// Step 3a: IV3NWV replies to K1JT with a 73 + printf("IV3NWV tx: K1JT IV3NWV 73\n"); + encodemsg_jt65(x,CALL_K1JT,CALL_IV3NWV, GRID_73); + qra64_encode(codec_iv3nwv, y, x); + rx = mfskchannel(y,channel_type,EbNodB); + +// Step 3b: K1JT attempts to decode [? ? ?] or [K1JT IV3NWV ?] + rc = qra64_decode(codec_k1jt, 0, xdec,rx); + if (rc>=0) { // decoded + printf("K1JT rx: received with apcode=%d %s\n",rc, decode_type[rc]); + +// Step 4a: K1JT replies to IV3NWV with a 73 + printf("K1JT tx: IV3NWV K1JT 73\n"); + encodemsg_jt65(x,CALL_IV3NWV,CALL_K1JT, GRID_73); + qra64_encode(codec_k1jt, y, x); + rx = mfskchannel(y,channel_type,EbNodB); + +// Step 4b: IV3NWV attempts to decode [? ? ?], [IV3NWV ? ?], or [IV3NWV ?] + rc = qra64_decode(codec_iv3nwv, 0, xdec,rx); + if (rc>=0) { // decoded + printf("IV3NWV rx: received with apcode=%d %s\n",rc, decode_type[rc]); + return 0; + } + } + } + } + printf("no decode\n"); + return -1; +} + +int test_proc_2(int channel_type, float EbNodB, int mode) +{ +/* +Here we simulate the decoder of K1JT after K1JT has sent a msg [IV3NWV K1JT] +and IV3NWV sends him the msg [K1JT IV3NWV JN66]. + +If mode=QRA_NOAP, K1JT decoder attempts to decode only msgs of type [? ? ?]. + +If mode=QRA_AUTOP, K1JT decoder will attempt to decode also the msgs +[K1JT IV3NWV] and [K1JT IV3NWV ?]. + +In the case a decode is successful the return code of the qra64_decode function +indicates the amount of a-priori information required to decode the received +message according to this table: + + rc=0 [? ? ?] AP0 + rc=1 [CQ ? ?] AP27 + rc=2 [CQ ? ] AP42 + rc=3 [CALL ? ?] AP29 + rc=4 [CALL ? ] AP44 + rc=5 [CALL CALL ?] AP57 + rc=6 [? CALL ?] AP29 + rc=7 [? CALL ] AP44 + rc=8 [CALL CALL GRID] AP72 + rc=9 [CQ CALL ?] AP55 + rc=10 [CQ CALL ] AP70 + rc=11 [CQ CALL GRID] AP70 + +The return code is <0 when decoding is unsuccessful + +This test simulates the situation ntx times and reports how many times +a particular type decode among the above 6 cases succeded. +*/ + + int x[QRA64_K], xdec[QRA64_K]; + int y[QRA64_N]; + float *rx; + float ebnodbest, ebnodbavg=0; + int rc,k; + + int ndecok[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + int nundet = 0; + int ntx = 200,ndec=0; + + qra64codec *codec_iv3nwv = qra64_init(mode); // codec for IV3NWV + qra64codec *codec_k1jt = qra64_init(mode); // codec for K1JT + + printf("\nQRA64 Test #2 - Decoding with AP knowledge (SNR-Eb/No offset = %.1f dB)\n\n", + QRA64_SNR_EBNO_OFFSET); + +// This will enable K1JT's decoder to look for calls directed to him [K1JT ? ?/b] +// printf("K1JT decoder enabled for [K1JT ? ?/blank]\n"); +// qra64_apset(codec_k1jt, CALL_K1JT,0,0,APTYPE_MYCALL); + +// This will enable K1JT's decoder to look for IV3NWV calls directed to him [K1JT IV3NWV ?/b] +// printf("K1JT decoder enabled for [K1JT IV3NWV ?]\n"); +// qra64_apset(codec_k1jt, CALL_CQ,CALL_IV3NWV,0,APTYPE_BOTHCALLS); + +// This will enable K1JT's decoder to look for msges sent by IV3NWV [? IV3NWV ?] +// printf("K1JT decoder enabled for [? IV3NWV ?/blank]\n"); +// qra64_apset(codec_k1jt, 0,CALL_IV3NWV,GRID_BLANK,APTYPE_HISCALL); + +// This will enable K1JT's decoder to look for full-knowledge [K1JT IV3NWV JN66] msgs + printf("K1JT decoder enabled for [K1JT IV3NWV JN66]\n"); + qra64_apset(codec_k1jt, CALL_K1JT,CALL_IV3NWV,GRID_JN66,APTYPE_FULL); + +// This will enable K1JT's decoder to look for calls from IV3NWV [CQ IV3NWV ?/b] msgs + printf("K1JT decoder enabled for [CQ IV3NWV ?/b/JN66]\n"); + qra64_apset(codec_k1jt, 0,CALL_IV3NWV,GRID_JN66,APTYPE_CQHISCALL); + + + // Dx station IV3NWV calls + printf("\nIV3NWV encoder sends msg: [K1JT IV3NWV JN66]\n\n"); + encodemsg_jt65(x,CALL_CQ,CALL_IV3NWV,GRID_JN66); + +// printf("\nIV3NWV encoder sends msg: [CQ IV3NWV JN66]\n\n"); +// encodemsg_jt65(x,CALL_CQ,CALL_IV3NWV,GRID_JN66); + +// printf("\nIV3NWV encoder sends msg: [CQ IV3NWV]\n\n"); +// encodemsg_jt65(x,CALL_CQ,CALL_IV3NWV,GRID_BLANK); + qra64_encode(codec_iv3nwv, y, x); + + printf("Simulating K1JT decoder up to AP72\n"); + + for (k=0;k=0) { + ebnodbavg +=ebnodbest; + if (memcmp(xdec,x,12*sizeof(int))==0) + ndecok[rc]++; + else + nundet++; + } + } + printf("\n\n"); + + + printf("Transimtted msgs:%d\nDecoded msgs:\n\n",ntx); + for (k=0;k<12;k++) { + printf("%3d with %s\n",ndecok[k],decode_type[k]); + ndec += ndecok[k]; + } + printf("\nTotal: %d/%d (%d undetected errors)\n\n",ndec,ntx,nundet); + printf(""); + + ebnodbavg/=(ndec+nundet); + printf("Estimated SNR (average in dB) = %.2f dB\n\n",ebnodbavg-QRA64_SNR_EBNO_OFFSET); + + return 0; +} + +int test_fastfading(float EbNodB, float B90, int fadingModel, int submode, int apmode, int olddec, int channel_type, int ntx) +{ + int x[QRA64_K], xdec[QRA64_K]; + int y[QRA64_N]; + float *rx; + float ebnodbest, ebnodbavg=0; + int rc,k; + float rxolddec[QRA64_N*QRA64_M]; // holds the energies at nominal tone freqs + + int ndecok[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + int nundet = 0; + int ndec=0; + + qra64codec *codec_iv3nwv; + qra64codec *codec_k1jt; + + codec_iv3nwv=qra64_init(QRA_NOAP); + codec_k1jt =qra64_init(apmode); + + if (channel_type==2) { // fast-fading case + printf("Simulating the fast-fading channel\n"); + printf("B90=%.2f Hz - Fading Model=%s - Submode=QRA64%c\n",B90,fadingModel?"Lorentz":"Gauss",submode+'A'); + printf("Decoder metric = %s\n",olddec?"AWGN":"Matched to fast-fading signal"); + } + else { + printf("Simulating the %s channel\n",channel_type?"Rayleigh block fading":"AWGN"); + printf("Decoder metric = AWGN\n"); + } + + + printf("\nEncoding msg [K1JT IV3NWV JN66]\n"); + encodemsg_jt65(x,CALL_K1JT,CALL_IV3NWV,GRID_JN66); +// printf("["); +// for (k=0;k<11;k++) printf("%02hX ",x[k]); printf("%02hX]\n",x[11]); + + qra64_encode(codec_iv3nwv, y, x); + printf("%d transmissions will be simulated\n\n",ntx); + + if (apmode==QRA_USERAP) { + // This will enable K1JT's decoder to look for cq/qrz calls [CQ/QRZ ? ?/b] + printf("K1JT decoder enabled for [CQ ? ?/blank]\n"); + qra64_apset(codec_k1jt, CALL_K1JT,0,0,APTYPE_CQQRZ); + + // This will enable K1JT's decoder to look for calls directed to him [K1JT ? ?/b] + printf("K1JT decoder enabled for [K1JT ? ?/blank]\n"); + qra64_apset(codec_k1jt, CALL_K1JT,0,0,APTYPE_MYCALL); + + // This will enable K1JT's decoder to look for msges sent by IV3NWV [? IV3NWV ?] + printf("K1JT decoder enabled for [? IV3NWV ?/blank]\n"); + qra64_apset(codec_k1jt, 0,CALL_IV3NWV,GRID_BLANK,APTYPE_HISCALL); + + // This will enable K1JT's decoder to look for IV3NWV calls directed to him [K1JT IV3NWV ?/b] + printf("K1JT decoder enabled for [K1JT IV3NWV ?]\n"); + qra64_apset(codec_k1jt, CALL_K1JT,CALL_IV3NWV,0,APTYPE_BOTHCALLS); + + // This will enable K1JT's decoder to look for full-knowledge [K1JT IV3NWV JN66] msgs + printf("K1JT decoder enabled for [K1JT IV3NWV JN66]\n"); + qra64_apset(codec_k1jt, CALL_K1JT,CALL_IV3NWV,GRID_JN66,APTYPE_FULL); + + // This will enable K1JT's decoder to look for calls from IV3NWV [CQ IV3NWV ?/b] msgs + printf("K1JT decoder enabled for [CQ IV3NWV ?/b/JN66]\n"); + qra64_apset(codec_k1jt, 0,CALL_IV3NWV,GRID_JN66,APTYPE_CQHISCALL); + + } + + printf("\nNow decoding with K1JT's decoder...\n"); +/* + if (channel_type==2) // simulate a fast-faded signal + printf("Simulating a fast-fading channel with given B90 and spread type\n"); + else + printf("Simulating a %s channel\n",channel_type?"Rayleigh block fading":"AWGN"); +*/ + for (k=0;k=0) { + ebnodbavg +=ebnodbest; + if (memcmp(xdec,x,12*sizeof(int))==0) + ndecok[rc]++; + else { + fprintf(stderr,"\nUndetected error with rc=%d\n",rc); + nundet++; + } + } + + } + printf(" %5.1f %%\r",100.0*k/ntx); + + printf("\n\n"); + + printf("Msgs transmitted:%d\nMsg decoded:\n\n",ntx); + for (k=0;k<12;k++) { + printf("rc=%2d %3d with %s\n",k,ndecok[k],decode_type[k]); + ndec += ndecok[k]; + } + printf("\nTotal: %d/%d (%d undetected errors)\n\n",ndec,ntx,nundet); + printf(""); + + if (ndec>0) { + ebnodbavg/=(ndec+nundet); + printf("Estimated SNR (average in dB) = %.2f dB\n\n",ebnodbavg-QRA64_SNR_EBNO_OFFSET); + } + + return 0; +} + + + +void syntax(void) +{ + + printf("\nQRA64 Mode Tests\n"); + printf("2016, Nico Palermo - IV3NWV\n\n"); + printf("---------------------------\n\n"); + printf("Syntax: qra64 [-s] [-c] [-a] [-t] [-h]\n"); + printf("Options: \n"); + printf(" -s : set simulation SNR in 2500 Hz BW (default:-27.5 dB)\n"); + printf(" -c : set channel type 0=AWGN (default) 1=Rayleigh 2=Fast-fading\n"); + printf(" -a : set decode type 0=NOAP 1=AUTOAP (default) 2=USERAP\n"); + printf(" -t: 0=simulate seq of msgs between IV3NWV and K1JT (default)\n"); + printf(" 1=simulate K1JT receiving K1JT IV3NWV JN66\n"); + printf(" 2=simulate fast-fading/awgn/rayliegh decoders performance\n"); + printf(" -n : simulate the transmission of ntx codewords (default=100)\n"); + + printf("Options used only for fast-fading simulations (-c2):\n"); + printf(" -b : 90%% fading bandwidth in Hz [1..230 Hz] (default = 2.5 Hz)\n"); + printf(" -m : fading model. 0=Gauss, 1=Lorentz (default = Lorentz)\n"); + printf(" -q : qra64 submode. 0=QRA64A,... 4=QRA64E (default = QRA64A)\n"); + printf(" -d : use the old awgn decoder\n"); + printf(" -h: this help\n"); + printf("Example:\n"); + printf(" qra64 -t2 -c2 -a2 -b50 -m1 -q2 -n10000 -s-26\n"); + printf(" runs the error performance test (-t2)\n"); + printf(" with USER_AP (-a2)\n"); + printf(" simulating a fast fading channel (-c2)\n"); + printf(" with B90 = 50 Hz (-b50), Lorentz Doppler (-m1), mode QRA64C (-q2)\n"); + printf(" ntx = 10000 codewords (-n10000) and SNR = -26 dB (-s-26)\n"); + +} + +int main(int argc, char* argv[]) +{ + int k, rc, nok=0; + float SNRdB = -27.5f; + unsigned int channel = CHANNEL_AWGN; + unsigned int mode = QRA_AUTOAP; + unsigned int testtype=0; + int nqso = 100; + float EbNodB; + float B90 = 2.5; + int fadingModel = 1; + int submode = 0; + int olddec = 0; + int ntx = 100; + +// Parse the command line + while(--argc) { + argv++; + + if (strncmp(*argv,"-h",2)==0) { + syntax(); + return 0; + } + else + if (strncmp(*argv,"-n",2)==0) { + ntx = ( int)atoi((*argv)+2); + if (ntx<100 || ntx>1000000) { + printf("Invalid -n option. ntx must be in the range [100..1000000]\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-a",2)==0) { + mode = ( int)atoi((*argv)+2); + if (mode>2) { + printf("Invalid decoding mode\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-s",2)==0) { + SNRdB = (float)atof((*argv)+2); + if (SNRdB>20 || SNRdB<-50) { + printf("SNR should be in the range [-50..20]\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-t",2)==0) { + testtype = ( int)atoi((*argv)+2); + if (testtype>2) { + printf("Invalid test type\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-c",2)==0) { + channel = ( int)atoi((*argv)+2); + if (channel>CHANNEL_FASTFADE) { + printf("Invalid channel type\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-b",2)==0) { + B90 = (float)atof((*argv)+2); + if (B90<1 || B90>230) { + printf("Invalid B90\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-m",2)==0) { + fadingModel = (int)atoi((*argv)+2); + if (fadingModel<0 || fadingModel>1) { + printf("Invalid fading model\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-q",2)==0) { + submode = (int)atoi((*argv)+2); + if (submode<0 || submode>4) { + printf("Invalid submode\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-d",2)==0) { + olddec = 1; + } + else { + printf("Invalid option\n"); + syntax(); + return -1; + } + } + + if (testtype<2) // old tests + if (channel==CHANNEL_FASTFADE) { + printf("Invalid Option. Test type 0 and 1 supports only AWGN or Rayleigh Channel model\n"); + return -1; + } + + EbNodB = SNRdB+QRA64_SNR_EBNO_OFFSET; + +#if defined(__linux__) || defined(__unix__) + srand48(GetTickCount()); +#endif + + if (testtype==0) { + for (k=0;k. + +----------------------------------------------------------------------------- + +QRA code used in this sowftware release: + +QRA13_64_64_IRR_E: K=13 N=64 Q=64 irregular QRA code (defined in +qra13_64_64_irr_e.h /.c) + +Codes with K=13 are designed to include a CRC as the 13th information symbol +and improve the code UER (Undetected Error Rate). +The CRC symbol is not sent along the channel (the codes are punctured) and the +resulting code is a (12,63) code +*/ +//---------------------------------------------------------------------------- + +#include +#include + +#include "qra64.h" +#include "../qracodes/qracodes.h" +#include "../qracodes/qra13_64_64_irr_e.h" +#include "../qracodes/pdmath.h" +#include "../qracodes/normrnd.h" + +// Code parameters of the QRA64 mode +#define QRA64_CODE qra_13_64_64_irr_e +#define QRA64_NMSG 218 // Must much value indicated in QRA64_CODE.NMSG + +#define QRA64_KC (QRA64_K+1) // Information symbols (crc included) +#define QRA64_NC (QRA64_N+1) // Codeword length (as defined in the code) +#define QRA64_NITER 100 // max number of iterations per decode + +// static functions declarations ---------------------------------------------- +static int calc_crc6(const int *x, int sz); +static void ix_mask(float *dst, const float *src, const int *mask, + const int *x); +static int qra64_decode_attempts(qra64codec *pcodec, int *xdec, const float *ix); +static int qra64_do_decode(int *x, const float *pix, const int *ap_mask, + const int *ap_x); +static float qra64_fastfading_estim_noise_std( + const float *rxen, + const float esnometric, + const int submode); + +static void qra64_fastfading_intrinsics( + float *pix, + const float *rxen, + const float *hptr, + const int hlen, + const float sigma, + const float EsNoMetric, + const int submode); + +static float qra64_fastfading_msg_esno( + const int *ydec, + const float *rxen, + const float sigma, + const float EsNoMetric, + const int hlen, + const int submode); + + +// a-priori information masks for fields in JT65-like msgs -------------------- + +// when defined limits the AP masks to reduce the false decode rate +#define LIMIT_AP_MASKS + +#ifdef LIMIT_AP_MASKS +#define MASK_CQQRZ 0xFFFFFFC +#define MASK_CALL1 0xFFFFFFC +#define MASK_CALL2 0xFFFFFFC +#define MASK_GRIDFULL 0x3FFC +#define MASK_GRIDFULL12 0x3FFC +#define MASK_GRIDBIT 0x8000 +#else +#define MASK_CQQRZ 0xFFFFFFC +#define MASK_CALL1 0xFFFFFFF +#define MASK_CALL2 0xFFFFFFF +#define MASK_GRIDFULL 0xFFFF +#define MASK_GRIDFULL12 0x3FFC +#define MASK_GRIDBIT 0x8000 // b[15] is 1 for free text, 0 otherwise +#endif + +// ---------------------------------------------------------------------------- + + + + +qra64codec *qra64_init(int flags) +{ + + // Eb/No value for which we optimize the decoder metric + const float EbNodBMetric = 2.8f; + const float EbNoMetric = (float)pow(10,EbNodBMetric/10); + const float R = 1.0f*(QRA64_KC)/(QRA64_NC); + + qra64codec *pcodec = (qra64codec*)malloc(sizeof(qra64codec)); + + if (!pcodec) + return 0; // can't allocate memory + + pcodec->decEsNoMetric = 1.0f*QRA64_m*R*EbNoMetric; + pcodec->apflags = flags; + + memset(pcodec->apmsg_set,0,APTYPE_SIZE*sizeof(int)); + + if (flags==QRA_NOAP) + return pcodec; + + // for QRA_USERAP and QRA_AUTOAP modes we always enable [CQ/QRZ ? ?] mgs look-up. + // encode CQ/QRZ AP messages + // NOTE: Here we handle only CQ and QRZ msgs. + // 'CQ nnn', 'CQ DX' and 'DE' msgs will be handled by the decoder + // as messages with no a-priori knowledge + qra64_apset(pcodec, CALL_CQ, 0, GRID_BLANK, APTYPE_CQQRZ); + + // initialize masks for decoding with a-priori information + encodemsg_jt65(pcodec->apmask_cqqrz, MASK_CQQRZ, 0, MASK_GRIDBIT); + encodemsg_jt65(pcodec->apmask_cqqrz_ooo, MASK_CQQRZ, 0, MASK_GRIDFULL); + encodemsg_jt65(pcodec->apmask_call1, MASK_CALL1, 0, MASK_GRIDBIT); + encodemsg_jt65(pcodec->apmask_call1_ooo, MASK_CALL1, 0, MASK_GRIDFULL); + encodemsg_jt65(pcodec->apmask_call2, 0, MASK_CALL2, MASK_GRIDBIT); + encodemsg_jt65(pcodec->apmask_call2_ooo, 0, MASK_CALL2, MASK_GRIDFULL); + encodemsg_jt65(pcodec->apmask_call1_call2, MASK_CALL1,MASK_CALL2, MASK_GRIDBIT); + encodemsg_jt65(pcodec->apmask_call1_call2_grid,MASK_CALL1,MASK_CALL2, MASK_GRIDFULL12); + encodemsg_jt65(pcodec->apmask_cq_call2, MASK_CQQRZ, MASK_CALL2, MASK_GRIDBIT); + encodemsg_jt65(pcodec->apmask_cq_call2_ooo, MASK_CQQRZ, MASK_CALL2, MASK_GRIDFULL12); + + return pcodec; +} + +void qra64_close(qra64codec *pcodec) +{ + free(pcodec); +} + +int qra64_apset(qra64codec *pcodec, const int mycall, const int hiscall, const int grid, const int aptype) +{ +// Set decoder a-priori knowledge accordingly to the type of the message to look up for +// arguments: +// pcodec = pointer to a qra64codec data structure as returned by qra64_init +// mycall = mycall to look for +// hiscall = hiscall to look for +// grid = grid to look for +// aptype = define and masks the type of AP to be set accordingly to the following: +// APTYPE_CQQRZ set [cq/qrz ? ?/blank] +// APTYPE_MYCALL set [mycall ? ?/blank] +// APTYPE_HISCALL set [? hiscall ?/blank] +// APTYPE_BOTHCALLS set [mycall hiscall ?] +// APTYPE_FULL set [mycall hiscall grid] +// APTYPE_CQHISCALL set [cq/qrz hiscall ?/blank] and [cq/qrz hiscall grid] +// returns: +// 0 on success +// -1 when qra64_init was called with the QRA_NOAP flag +// -2 invalid apytpe + + if (pcodec->apflags==QRA_NOAP) + return -1; + + switch (aptype) { + case APTYPE_CQQRZ: + encodemsg_jt65(pcodec->apmsg_cqqrz, CALL_CQ, 0, GRID_BLANK); + break; + case APTYPE_MYCALL: + encodemsg_jt65(pcodec->apmsg_call1, mycall, 0, GRID_BLANK); + break; + case APTYPE_HISCALL: + encodemsg_jt65(pcodec->apmsg_call2, 0, hiscall, GRID_BLANK); + break; + case APTYPE_BOTHCALLS: + encodemsg_jt65(pcodec->apmsg_call1_call2, mycall, hiscall, GRID_BLANK); + break; + case APTYPE_FULL: + encodemsg_jt65(pcodec->apmsg_call1_call2_grid, mycall, hiscall, grid); + break; + case APTYPE_CQHISCALL: + encodemsg_jt65(pcodec->apmsg_cq_call2, CALL_CQ, hiscall, GRID_BLANK); + encodemsg_jt65(pcodec->apmsg_cq_call2_grid, CALL_CQ, hiscall, grid); + break; + default: + return -2; // invalid ap type + } + + pcodec->apmsg_set[aptype]=1; // signal the decoder to look-up for the specified type + + + return 0; +} +void qra64_apdisable(qra64codec *pcodec, const int aptype) +{ + if (pcodec->apflags==QRA_NOAP) + return; + + if (aptype=APTYPE_SIZE) + return; + + pcodec->apmsg_set[aptype] = 0; // signal the decoder not to look-up to the specified type +} + +void qra64_encode(qra64codec *pcodec, int *y, const int *x) +{ + int encx[QRA64_KC]; // encoder input buffer + int ency[QRA64_NC]; // encoder output buffer + + int hiscall,mycall,grid; + + memcpy(encx,x,QRA64_K*sizeof(int)); // Copy input to encoder buffer + encx[QRA64_K]=calc_crc6(encx,QRA64_K); // Compute and add crc symbol + qra_encode(&QRA64_CODE, ency, encx); // encode msg+crc using given QRA code + + // copy codeword to output puncturing the crc symbol + memcpy(y,ency,QRA64_K*sizeof(int)); // copy information symbols + memcpy(y+QRA64_K,ency+QRA64_KC,QRA64_C*sizeof(int)); // copy parity symbols + + if (pcodec->apflags!=QRA_AUTOAP) + return; + + // Here we handle the QRA_AUTOAP mode -------------------------------------------- + + // When a [hiscall mycall ?] msg is detected we instruct the decoder + // to look for [mycall hiscall ?] msgs + // otherwise when a [cq mycall ?] msg is sent we reset the APTYPE_BOTHCALLS + + // look if the msg sent is a std type message (bit15 of grid field = 0) + if ((x[9]&0x80)==1) + return; // no, it's a text message, nothing to do + + // It's a [hiscall mycall grid] message + + // We assume that mycall is our call (but we don't check it) + // hiscall the station we are calling or a general call (CQ/QRZ/etc..) + decodemsg_jt65(&hiscall,&mycall,&grid,x); + + + if ((hiscall>=CALL_CQ && hiscall<=CALL_CQ999) || hiscall==CALL_CQDX || + hiscall==CALL_DE) { + // tell the decoder to look for msgs directed to us + qra64_apset(pcodec,mycall,0,0,APTYPE_MYCALL); + // We are making a general call and don't know who might reply + // Reset APTYPE_BOTHCALLS so decoder won't look for [mycall hiscall ?] msgs + qra64_apdisable(pcodec,APTYPE_BOTHCALLS); + } else { + // We are replying to someone named hiscall + // Set APTYPE_BOTHCALLS so decoder will try for [mycall hiscall ?] msgs + qra64_apset(pcodec,mycall, hiscall, GRID_BLANK, APTYPE_BOTHCALLS); + } + +} + +#define EBNO_MIN -10.0f // minimum Eb/No value returned by the decoder (in dB) +// AWGN metric decoder +int qra64_decode(qra64codec *pcodec, float *ebno, int *x, const float *rxen) +{ + int k; + float *srctmp, *dsttmp; + float ix[QRA64_NC*QRA64_M]; // (depunctured) intrisic information + int xdec[QRA64_KC]; // decoded message (with crc) + int ydec[QRA64_NC]; // re-encoded message (for snr calculations) + float noisestd; // estimated noise variance + float msge; // estimated message energy + float ebnoval; // estimated Eb/No + int rc; + + if (QRA64_NMSG!=QRA64_CODE.NMSG) // sanity check + return -16; // QRA64_NMSG define is wrong + + // compute symbols intrinsic probabilities from received energy observations + noisestd = qra_mfskbesselmetric(ix, rxen, QRA64_m, QRA64_N,pcodec->decEsNoMetric); + + // de-puncture observations adding a uniform distribution for the crc symbol + + // move check symbols distributions one symbol towards the end + dsttmp = PD_ROWADDR(ix,QRA64_M, QRA64_NC-1); //Point to last symbol prob dist + srctmp = dsttmp-QRA64_M; // source is the previous pd + for (k=0;k57.004f) + ebnoval=57.004f; + ebnoval = ebnoval*57.03f/(57.03f-ebnoval); + + // compute value in dB + if (ebnoval<=0) { + ebnoval = EBNO_MIN; // assume a minimum, positive value + } + else { + ebnoval = 10.0f*(float)log10(ebnoval); + if (ebnoval4) + return -17; // invalid submode + + if (B90<1.0f || B90>238.0f) + return -18; // B90 out of range + + // compute index to most appropriate amplitude weighting function coefficients + hidx = (int)(log((float)B90)/log(1.09f) - 0.499f); + + if (hidx<0 || hidx > 64) + return -19; // index of weighting function out of range + + if (fadingModel==0) { // gaussian fading model + // point to gaussian energy weighting taps + hlen = glen_tab_gauss[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) + hptr = gptr_tab_gauss[hidx]; // pointer to the first (L+1)/2 coefficients of w fun + } + else if (fadingModel==1) { + // point to lorentzian energy weighting taps + hlen = glen_tab_lorentz[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) + hptr = gptr_tab_lorentz[hidx]; // pointer to the first (L+1)/2 coefficients of w fun + } + else + return -20; // invalid fading model index + + + // compute (euristically) the optimal decoder metric accordingly the given spread amount + // We assume that the decoder threshold is: + // Es/No(dB) = Es/No(AWGN)(dB) + 8*log(B90)/log(240)(dB) + // that's to say, at the maximum Doppler spread bandwidth (240 Hz) there's a ~8 dB Es/No degradation + // over the AWGN case + tempf = 8.0f*(float)log((float)B90)/(float)log(240.0f); + EsNoMetric = pcodec->decEsNoMetric*(float)pow(10.0f,tempf/10.0f); + + + + // Step 1 ----------------------------------------------------------------------------------- + // Evaluate the noise stdev from the received energies at nominal tone frequencies + noisestd = qra64_fastfading_estim_noise_std(rxen, EsNoMetric, submode); + + // Step 2 ----------------------------------------------------------------------------------- + // Compute message symbols probability distributions + qra64_fastfading_intrinsics(ix, rxen, hptr, hlen, noisestd, EsNoMetric, submode); + + // Step 3 --------------------------------------------------------------------------- + // De-puncture observations adding a uniform distribution for the crc symbol + // Move check symbols distributions one symbol towards the end + dsttmp = PD_ROWADDR(ix,QRA64_M, QRA64_NC-1); //Point to last symbol prob dist + srctmp = dsttmp-QRA64_M; // source is the previous pd + for (k=0;k Eb/N0 conversion + ebnoval = 1.0f/(1.0f*QRA64_K/QRA64_N*QRA64_m)*esno; + + // compute value in dB + if (ebnoval<=0) { + ebnoval = EBNO_MIN; // assume a minimum, positive value + } + else { + ebnoval = 10.0f*(float)log10(ebnoval); + if (ebnoval238.0f) + return -18; // B90 out of range + + // compute index to most appropriate energy weighting function coefficients + hidx = (int)(log((float)B90)/log(1.09f) - 0.499f); + + if (hidx<0 || hidx > 64) + return -19; // index of weighting function out of range + + if (fadingModel==0) { // gaussian fading model + // point to gaussian weighting taps + hlen = glen_tab_gauss[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) + hptr = gptr_tab_gauss[hidx]; // pointer to the first (L+1)/2 coefficients of w fun + } + else if (fadingModel==1) { + // point to lorentzian weighting taps + hlen = glen_tab_lorentz[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) + hptr = gptr_tab_lorentz[hidx]; // pointer to the first (L+1)/2 coefficients of w fun + } + else + return -20; // invalid fading model index + + + // Compute the unfaded tone amplitudes from the Eb/No value passed to the call + N0 = 1.0f; // assume unitary noise PSD + sigmanoise = (float)sqrt(N0/2); + EsN0 = (float)pow(10.0f,EbN0dB/10.0f)*QRA64_m*QRA64_K/QRA64_N; // Es/No = m*R*Eb/No + Es = EsN0*N0; + + // compute signal bin sigmas + for (n=0;n=0;j--) { + normrnd_s(iq, 2, 0 , sigmasig[j]); + *curi++ += iq[0]; + *curq++ += iq[1]; + } + + } + + // compute total bin energies (S+N) and store in first half of buffer + curi = channel_out; + curq = channel_out+bpm; + for (n=0;nmaxloglh) // keep track of the max loglikelihood + maxloglh = loglh; + curix[k]=loglh; + } + + // scale to likelihoods + sumix = 0.f; + for (k=0;k1 + if (u<1) + return 0.f; + + // check u(bps/tothlen)) + return 10000.f; + + // solve for Es/No + esno = (u-1.0f)/(1.0f/tothlen-u/bps); + + return esno; + + +} + +#ifdef LIMIT_AP_MASKS + +static int call1_match(const int *papmsg, const int *pdec) +{ + // assumes MASK_CALL1 = 0xFFFFFFC + int u = papmsg[4]^pdec[4]; + return (u&0x3C)==0; +} +static int call2_match(const int *papmsg, const int *pdec) +{ + // assumes MASK_CALL2 = 0xFFFFFFC + int u = papmsg[9]^pdec[9]; + return (u&0x30)==0; +} +static int grid_match(const int *papmsg, const int *pdec) +{ + // assumes MASK_GRIDFULL = 0x3FFC + int u = papmsg[11]^pdec[11]; + int rc = (u&0x03)==0; + + u = papmsg[9]^pdec[9]; + + return (u&0x0C)==0 && rc; +} + +#else +#define call1_match(a,b) (1) +#define call2_match(a,b) (1) +#define grid_match(a,b) (1) +#endif + + + + +// Attempt to decode given intrisic information +static int qra64_decode_attempts(qra64codec *pcodec, int *xdec, const float *ix) +{ + int rc; + + // Attempt to decode without a-priori info -------------------------------- + rc = qra64_do_decode(xdec, ix, NULL, NULL); + if (rc>=0) + return 0; // successfull decode with AP0 + else + if (pcodec->apflags==QRA_NOAP) + // nothing more to do + return rc; // rc<0 = unsuccessful decode + + // Here we handle decoding with AP knowledge + + + // Attempt to decode CQ calls + rc = qra64_do_decode(xdec,ix,pcodec->apmask_cqqrz, pcodec->apmsg_cqqrz); + if (rc>=0) + return 1; // decoded [cq/qrz ? ?] + + rc = qra64_do_decode(xdec, ix, pcodec->apmask_cqqrz_ooo, + pcodec->apmsg_cqqrz); + if (rc>=0) + // check that ooo really matches + if (grid_match(pcodec->apmsg_cqqrz,xdec)) + return 2; // decoded [cq/qrz ? ooo] + + // attempt to decode calls directed to us + if (pcodec->apmsg_set[APTYPE_MYCALL]) { + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1, + pcodec->apmsg_call1); + if (rc>=0) + // check that mycall really matches + if (call1_match(pcodec->apmsg_call1,xdec)) + return 3; // decoded [mycall ? ?] + + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_ooo, + pcodec->apmsg_call1); + if (rc>=0) + // check that mycall and ooo really match + if (call1_match(pcodec->apmsg_call1,xdec) && + grid_match(pcodec->apmsg_call1,xdec)) + return 4; // decoded [mycall ? ooo] + } + + // attempt to decode [mycall hiscall ?] msgs + if (pcodec->apmsg_set[APTYPE_BOTHCALLS]) { + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_call2, + pcodec->apmsg_call1_call2); + if (rc>=0) + // check that mycall and hiscall really match + if (call1_match(pcodec->apmsg_call1_call2,xdec) && + call2_match(pcodec->apmsg_call1_call2,xdec)) + return 5; // decoded [mycall srccall ?] + } + + // attempt to decode [? hiscall ?/b] msgs + if (pcodec->apmsg_set[APTYPE_HISCALL]) { + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call2, + pcodec->apmsg_call2); + if (rc>=0) + // check that hiscall really match + if (call2_match(pcodec->apmsg_call2,xdec)) + return 6; // decoded [? hiscall ?] + + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call2_ooo, + pcodec->apmsg_call2); + if (rc>=0) + // check that hiscall and ooo match + if (call2_match(pcodec->apmsg_call2,xdec) && + grid_match(pcodec->apmsg_call2,xdec)) + return 7; // decoded [? hiscall ooo] + } + + // attempt to decode [cq/qrz hiscall ?/b/grid] msgs + if (pcodec->apmsg_set[APTYPE_CQHISCALL]) { + + rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2, + pcodec->apmsg_cq_call2); + if (rc>=0) + // check that hiscall matches + if (call2_match(pcodec->apmsg_call2,xdec)) + return 9; // decoded [cq/qrz hiscall ?] + + rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2_ooo, + pcodec->apmsg_cq_call2_grid); + if (rc>=0) { + // Full AP mask need special handling + // To minimize false decodes we check the decoded message + // with what passed in the ap_set call + if (memcmp(pcodec->apmsg_cq_call2_grid,xdec, QRA64_K*sizeof(int))==0) + return 11; // decoded [cq/qrz hiscall grid] + } + + rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2_ooo, + pcodec->apmsg_cq_call2); + if (rc>=0) { + // Full AP mask need special handling + // To minimize false decodes we check the decoded message + // with what passed in the ap_set call + if (memcmp(pcodec->apmsg_cq_call2,xdec, QRA64_K*sizeof(int))==0) + return 10; // decoded [cq/qrz hiscall ] + } + } + + // attempt to decode [mycall hiscall grid] + if (pcodec->apmsg_set[APTYPE_FULL]) { + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_call2_grid, + pcodec->apmsg_call1_call2_grid); + if (rc>=0) { + // Full AP mask need special handling + // All the three msg fields were given. + // To minimize false decodes we check the decoded message + // with what passed in the ap_set call + if (memcmp(pcodec->apmsg_call1_call2_grid,xdec, QRA64_K*sizeof(int))==0) + return 8; // decoded [mycall hiscall grid] + } + } + + // all decoding attempts failed + return -1; +} + + + +// Decode with given a-priori information +static int qra64_do_decode(int *xdec, const float *pix, const int *ap_mask, + const int *ap_x) +{ + int rc; + const float *ixsrc; + float ix_masked[QRA64_NC*QRA64_M]; // Masked intrinsic information + float ex[QRA64_NC*QRA64_M]; // Extrinsic information from the decoder + + float v2cmsg[QRA64_NMSG*QRA64_M]; // buffers for the decoder messages + float c2vmsg[QRA64_NMSG*QRA64_M]; + + if (ap_mask==NULL) { // no a-priori information + ixsrc = pix; // intrinsic source is what passed as argument + } else { + // a-priori information provided + // mask channel observations with a-priori + ix_mask(ix_masked,pix,ap_mask,ap_x); + ixsrc = ix_masked; // intrinsic source is the masked version + } + + // run the decoding algorithm + rc = qra_extrinsic(&QRA64_CODE,ex,ixsrc,QRA64_NITER,v2cmsg,c2vmsg); + if (rc<0) + return -1; // no convergence in given iterations + + // decode + qra_mapdecode(&QRA64_CODE,xdec,ex,ixsrc); + + // verify crc + if (calc_crc6(xdec,QRA64_K)!=xdec[QRA64_K]) // crc doesn't match (detected error) + return -2; // decoding was succesfull but crc doesn't match + + return 0; +} + + +// crc functions -------------------------------------------------------------- +// crc-6 generator polynomial +// g(x) = x^6 + a5*x^5 + ... + a1*x + a0 + +// g(x) = x^6 + x + 1 +#define CRC6_GEN_POL 0x30 // MSB=a0 LSB=a5 + +// g(x) = x^6 + x^2 + x + 1 (See: https://users.ece.cmu.edu/~koopman/crc/) +// #define CRC6_GEN_POL 0x38 // MSB=a0 LSB=a5. Simulation results are similar + +static int calc_crc6(const int *x, int sz) +{ + // todo: compute it faster using a look up table + int k,j,t,sr = 0; + for (k=0;k>1) ^ CRC6_GEN_POL; + else + sr = (sr>>1); + t>>=1; + } + } + return sr; +} + +static void ix_mask(float *dst, const float *src, const int *mask, + const int *x) +{ + // mask intrinsic information (channel observations) with a priori knowledge + + int k,kk, smask; + float *row; + + memcpy(dst,src,(QRA64_NC*QRA64_M)*sizeof(float)); + + for (k=0;k>22)&0x3F; + y[1]= (call1>>16)&0x3F; + y[2]= (call1>>10)&0x3F; + y[3]= (call1>>4)&0x3F; + y[4]= (call1<<2)&0x3F; + + y[4] |= (call2>>26)&0x3F; + y[5]= (call2>>20)&0x3F; + y[6]= (call2>>14)&0x3F; + y[7]= (call2>>8)&0x3F; + y[8]= (call2>>2)&0x3F; + y[9]= (call2<<4)&0x3F; + + y[9] |= (grid>>12)&0x3F; + y[10]= (grid>>6)&0x3F; + y[11]= (grid)&0x3F; + +} +void decodemsg_jt65(int *call1, int *call2, int *grid, const int *x) +{ + int nc1, nc2, ng; + + nc1 = x[4]>>2; + nc1 |= x[3]<<4; + nc1 |= x[2]<<10; + nc1 |= x[1]<<16; + nc1 |= x[0]<<22; + + nc2 = x[9]>>4; + nc2 |= x[8]<<2; + nc2 |= x[7]<<8; + nc2 |= x[6]<<14; + nc2 |= x[5]<<20; + nc2 |= (x[4]&0x03)<<26; + + ng = x[11]; + ng |= x[10]<<6; + ng |= (x[9]&0x0F)<<12; + + *call1 = nc1; + *call2 = nc2; + *grid = ng; +} diff --git a/lib/qra/qra64/qra64.h b/lib/qra/qra64/qra64.h new file mode 100644 index 00000000..3b2b5bd3 --- /dev/null +++ b/lib/qra/qra64/qra64.h @@ -0,0 +1,269 @@ +// qra64.h +// Encoding/decoding functions for the QRA64 mode +// +// (c) 2016 - Nico Palermo, IV3NWV +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +#ifndef _qra64_h_ +#define _qra64_h_ + +// qra64_init(...) initialization flags +#define QRA_NOAP 0 // don't use a-priori knowledge +#define QRA_AUTOAP 1 // use auto a-priori knowledge +#define QRA_USERAP 2 // a-priori knowledge messages provided by the user + +// QRA code parameters +#define QRA64_K 12 // information symbols +#define QRA64_N 63 // codeword length +#define QRA64_C 51 // (number of parity checks C=(N-K)) +#define QRA64_M 64 // code alphabet size +#define QRA64_m 6 // bits per symbol + +// packed predefined callsigns and fields as defined in JT65 +#define CALL_CQ 0xFA08319 +#define CALL_QRZ 0xFA0831A +#define CALL_CQ000 0xFA0831B +#define CALL_CQ999 0xFA08702 +#define CALL_CQDX 0x5624C39 +#define CALL_DE 0xFF641D1 +#define GRID_BLANK 0x7E91 + +// Types of a-priori knowledge messages +#define APTYPE_CQQRZ 0 // [cq/qrz ? ?/blank] +#define APTYPE_MYCALL 1 // [mycall ? ?/blank] +#define APTYPE_HISCALL 2 // [? hiscall ?/blank] +#define APTYPE_BOTHCALLS 3 // [mycall hiscall ?] +#define APTYPE_FULL 4 // [mycall hiscall grid] +#define APTYPE_CQHISCALL 5 // [cq/qrz hiscall ?/blank] +#define APTYPE_SIZE (APTYPE_CQHISCALL+1) + +typedef struct { + float decEsNoMetric; + int apflags; + int apmsg_set[APTYPE_SIZE]; // indicate which ap type knowledge has + // been set by the user +// ap messages buffers + int apmsg_cqqrz[12]; // [cq/qrz ? ?/blank] + int apmsg_call1[12]; // [mycall ? ?/blank] + int apmsg_call2[12]; // [? hiscall ?/blank] + int apmsg_call1_call2[12]; // [mycall hiscall ?] + int apmsg_call1_call2_grid[12]; // [mycall hiscall grid] + int apmsg_cq_call2[12]; // [cq hiscall ?/blank] + int apmsg_cq_call2_grid[12]; // [cq hiscall grid] + +// ap messages masks + int apmask_cqqrz[12]; + int apmask_cqqrz_ooo[12]; + int apmask_call1[12]; + int apmask_call1_ooo[12]; + int apmask_call2[12]; + int apmask_call2_ooo[12]; + int apmask_call1_call2[12]; + int apmask_call1_call2_grid[12]; + int apmask_cq_call2[12]; + int apmask_cq_call2_ooo[12]; +} qra64codec; + +#ifdef __cplusplus +extern "C" { +#endif + +qra64codec *qra64_init(int flags); +// QRA64 mode initialization function +// arguments: +// flags: set the decoder mode +// QRA_NOAP use no a-priori information +// QRA_AUTOAP use any relevant previous decodes +// QRA_USERAP use a-priori information provided via qra64_apset(...) +// returns: +// Pointer to initialized qra64codec data structure +// this pointer should be passed to the encoding/decoding functions +// +// 0 if unsuccessful (can't allocate memory) +// ---------------------------------------------------------------------------- + +void qra64_encode(qra64codec *pcodec, int *y, const int *x); +// QRA64 encoder +// arguments: +// pcodec = pointer to a qra64codec data structure as returned by qra64_init +// x = pointer to the message to be encoded, int x[12] +// x must point to an array of integers (i.e. defined as int x[12]) +// y = pointer to encoded message, int y[63]= +// ---------------------------------------------------------------------------- + +int qra64_decode(qra64codec *pcodec, float *ebno, int *x, const float *r); +// QRA64 mode decoder +// arguments: +// pcodec = pointer to a qra64codec data structure as returned by qra64_init +// ebno = pointer to a float where the avg Eb/No (in dB) will be stored +// in case of successfull decoding +// (pass a null pointer if not interested) +// x = pointer to decoded message, int x[12] +// r = pointer to received symbol energies (squared amplitudes) +// r must point to an array of length QRA64_M*QRA64_N (=64*63=4032) +// The first QRA_M entries should be the energies of the first +// symbol in the codeword; the last QRA_M entries should be the +// energies of the last symbol in the codeword +// +// return code: +// +// The return code is <0 when decoding is unsuccessful +// -16 indicates that the definition of QRA64_NMSG does not match what required by the code +// If the decoding process is successfull the return code is accordingly to the following table +// rc=0 [? ? ?] AP0 (decoding with no a-priori) +// rc=1 [CQ ? ?] AP27 +// rc=2 [CQ ? ] AP44 +// rc=3 [CALL ? ?] AP29 +// rc=4 [CALL ? ] AP45 +// rc=5 [CALL CALL ?] AP57 +// rc=6 [? CALL ?] AP29 +// rc=7 [? CALL ] AP45 +// rc=8 [CALL CALL GRID] AP72 (actually a AP68 mask to reduce false decodes) +// rc=9 [CQ CALL ?] AP55 +// rc=10 [CQ CALL ] AP70 (actaully a AP68 mask to reduce false decodes) + +// return codes in the range 1-10 indicate the amount and the type of a-priori +// information was required to decode the received message. + + +// Decode a QRA64 msg using a fast-fading metric +int qra64_decode_fastfading( + qra64codec *pcodec, // ptr to the codec structure + float *ebno, // ptr to where the estimated Eb/No value will be saved + int *x, // ptr to decoded message + const float *rxen, // ptr to received symbol energies array + const int submode, // submode idx (0=QRA64A ... 4=QRA64E) + const float B90, // spread bandwidth (90% fractional energy) + const int fadingModel); // 0=Gaussian 1=Lorentzian fade model +// +// rxen: The array of the received bin energies +// Bins must be spaced by integer multiples of the symbol rate (1/Ts Hz) +// The array must be an array of total length U = L x N where: +// L: is the number of frequency bins per message symbol (see after) +// N: is the number of symbols in a QRA64 msg (63) +// +// The number of bins/symbol L depends on the selected submode accordingly to +// the following rule: +// L = (64+64*2^submode+64) = 64*(2+2^submode) +// Tone 0 is always supposed to be at offset 64 in the array. +// The m-th tone nominal frequency is located at offset 64 + m*2^submode (m=0..63) +// +// Submode A: (2^submode = 1) +// L = 64*3 = 196 bins/symbol +// Total length of the energies array: U = 192*63 = 12096 floats +// +// Submode B: (2^submode = 2) +// L = 64*4 = 256 bins/symbol +// Total length of the energies array: U = 256*63 = 16128 floats +// +// Submode C: (2^submode = 4) +// L = 64*6 = 384 bins/symbol +// Total length of the energies array: U = 384*63 = 24192 floats +// +// Submode D: (2^submode = 8) +// L = 64*10 = 640 bins/symbol +// Total length of the energies array: U = 640*63 = 40320 floats +// +// Submode E: (2^submode = 16) +// L = 64*18 = 1152 bins/symbol +// Total length of the energies array: U = 1152*63 = 72576 floats +// +// Note: The rxen array is modified and reused for internal calculations. +// +// +// B90: spread fading bandwidth in Hz (90% fractional average energy) +// +// B90 should be in the range 1 Hz ... 238 Hz +// The value passed to the call is rounded to the closest value among the +// 64 available values: +// B = 1.09^k Hz, with k=0,1,...,63 +// +// I.e. B90=27 Hz will be approximated in this way: +// k = rnd(log(27)/log(1.09)) = 38 +// B90 = 1.09^k = 1.09^38 = 26.4 Hz +// +// For any input value the maximum rounding error is not larger than +/- 5% +// +// return codes: same return codes of qra64_decode (+some additional error codes) + + +// Simulate the fast-fading channel (to be used with qra64_decode_fastfading) +int qra64_fastfading_channel( + float **rxen, + const int *xmsg, + const int submode, + const float EbN0dB, + const float B90, + const int fadingModel); +// Simulate transmission over a fading channel with given B90, fading model and submode +// and non coherent detection. +// Sets rxen to point to an array of bin energies formatted as required +// by the (fast-fading) decoding routine. +// returns 0 on success or negative values on error conditions + + +int qra64_apset(qra64codec *pcodec, const int mycall, const int hiscall, const int grid, const int aptype); +// Set decoder a-priori knowledge accordingly to the type of the message to +// look up for +// arguments: +// pcodec = pointer to a qra64codec data structure as returned by qra64_init +// mycall = mycall to look for +// hiscall = hiscall to look for +// grid = grid to look for +// aptype = define the type of AP to be set: +// APTYPE_CQQRZ set [cq/qrz ? ?/blank] +// APTYPE_MYCALL set [mycall ? ?/blank] +// APTYPE_HISCALL set [? hiscall ?/blank] +// APTYPE_BOTHCALLS set [mycall hiscall ?] +// APTYPE_FULL set [mycall hiscall grid] +// APTYPE_CQHISCALL set [cq/qrz hiscall ?/blank] + +// returns: +// 0 on success +// -1 when qra64_init was called with the QRA_NOAP flag +// -2 invalid apytpe (valid range [APTYPE_CQQRZ..APTYPE_CQHISCALL] +// (APTYPE_CQQRZ [cq/qrz ? ?] is set by default ) + +void qra64_apdisable(qra64codec *pcodec, const int aptype); +// disable specific AP type +// arguments: +// pcodec = pointer to a qra64codec data structure as returned by qra64_init +// aptype = define the type of AP to be disabled +// APTYPE_CQQRZ disable [cq/qrz ? ?/blank] +// APTYPE_MYCALL disable [mycall ? ?/blank] +// APTYPE_HISCALL disable [ ? hiscall ?/blank] +// APTYPE_BOTHCALLS disable [mycall hiscall ? ] +// APTYPE_FULL disable [mycall hiscall grid] +// APTYPE_CQHISCALL set [cq/qrz hiscall ?/blank] + +void qra64_close(qra64codec *pcodec); +// Free memory allocated by qra64_init +// arguments: +// pcodec = pointer to a qra64codec data structure as returned by qra64_init + +// ---------------------------------------------------------------------------- + +// encode/decode std msgs in 12 symbols as done in jt65 +void encodemsg_jt65(int *y, const int call1, const int call2, const int grid); +void decodemsg_jt65(int *call1, int *call2, int *grid, const int *x); + +#ifdef __cplusplus +} +#endif + +#endif // _qra64_h_ diff --git a/lib/qra/qra64/qra64_all.c b/lib/qra/qra64/qra64_all.c new file mode 100644 index 00000000..28f8ab92 --- /dev/null +++ b/lib/qra/qra64/qra64_all.c @@ -0,0 +1,1050 @@ +/* +qra64.c +Encoding/decoding functions for the QRA64 mode + +(c) 2016 - Nico Palermo, IV3NWV + +------------------------------------------------------------------------------- + + qracodes 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 of the License, or + (at your option) any later version. + qracodes 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 qracodes source distribution. + If not, see . + +----------------------------------------------------------------------------- + +QRA code used in this sowftware release: + +QRA13_64_64_IRR_E: K=13 N=64 Q=64 irregular QRA code (defined in +qra13_64_64_irr_e.h /.c) + +Codes with K=13 are designed to include a CRC as the 13th information symbol +and improve the code UER (Undetected Error Rate). +The CRC symbol is not sent along the channel (the codes are punctured) and the +resulting code is a (12,63) code +*/ +//---------------------------------------------------------------------------- + +#include +#include + +#include "qra64.h" +#include "../qracodes/qracodes.h" +#include "../qracodes/qra13_64_64_irr_e.h" +#include "../qracodes/pdmath.h" +#include "../qracodes/normrnd.h" + +// Code parameters of the QRA64 mode +#define QRA64_CODE qra_13_64_64_irr_e +#define QRA64_NMSG 218 // Must much value indicated in QRA64_CODE.NMSG + +#define QRA64_KC (QRA64_K+1) // Information symbols (crc included) +#define QRA64_NC (QRA64_N+1) // Codeword length (as defined in the code) +#define QRA64_NITER 100 // max number of iterations per decode + +// static functions declarations ---------------------------------------------- +static int calc_crc6(const int *x, int sz); +static void ix_mask(float *dst, const float *src, const int *mask, + const int *x); +static int qra64_decode_attempts(qra64codec *pcodec, int *xdec, const float *ix); +static int qra64_do_decode(int *x, const float *pix, const int *ap_mask, + const int *ap_x); +static float qra64_fastfading_estim_noise_std( + float *rxen, + const float esnometric, + const int submode); +static void qra64_fastfading_intrinsics( + float *pix, + const float *rxamp, + const float *hptr, + const int hlen, + const float cmetric, + const int submode); +static float qra64_fastfading_msg_esno( + const int *ydec, + const float *rxamp, + const float sigma, + const float EsNoMetric, + const int hlen, + const int submode); + + +// a-priori information masks for fields in JT65-like msgs -------------------- +#define MASK_CQQRZ 0xFFFFFFC // CQ/QRZ calls common bits +#define MASK_CALL1 0xFFFFFFF +#define MASK_CALL2 0xFFFFFFF +#define MASK_GRIDFULL 0xFFFF +#define MASK_GRIDFULL12 0x3FFC // less aggressive mask (to be used with full AP decoding) +#define MASK_GRIDBIT 0x8000 // b[15] is 1 for free text, 0 otherwise +// ---------------------------------------------------------------------------- + +qra64codec *qra64_init(int flags) +{ + + // Eb/No value for which we optimize the decoder metric + const float EbNodBMetric = 2.8f; + const float EbNoMetric = (float)pow(10,EbNodBMetric/10); + const float R = 1.0f*(QRA64_KC)/(QRA64_NC); + + qra64codec *pcodec = (qra64codec*)malloc(sizeof(qra64codec)); + + if (!pcodec) + return 0; // can't allocate memory + + pcodec->decEsNoMetric = 1.0f*QRA64_m*R*EbNoMetric; + pcodec->apflags = flags; + + memset(pcodec->apmsg_set,0,APTYPE_SIZE*sizeof(int)); + + if (flags==QRA_NOAP) + return pcodec; + + // for QRA_USERAP and QRA_AUTOAP modes we always enable [CQ/QRZ ? ?] mgs look-up. + // encode CQ/QRZ AP messages + // NOTE: Here we handle only CQ and QRZ msgs. + // 'CQ nnn', 'CQ DX' and 'DE' msgs will be handled by the decoder + // as messages with no a-priori knowledge + qra64_apset(pcodec, CALL_CQ, 0, GRID_BLANK, APTYPE_CQQRZ); + + // initialize masks for decoding with a-priori information + encodemsg_jt65(pcodec->apmask_cqqrz, MASK_CQQRZ, 0, MASK_GRIDBIT); + encodemsg_jt65(pcodec->apmask_cqqrz_ooo, MASK_CQQRZ, 0, MASK_GRIDFULL); + encodemsg_jt65(pcodec->apmask_call1, MASK_CALL1, 0, MASK_GRIDBIT); + encodemsg_jt65(pcodec->apmask_call1_ooo, MASK_CALL1, 0, MASK_GRIDFULL); + encodemsg_jt65(pcodec->apmask_call2, 0, MASK_CALL2, MASK_GRIDBIT); + encodemsg_jt65(pcodec->apmask_call2_ooo, 0, MASK_CALL2, MASK_GRIDFULL); + encodemsg_jt65(pcodec->apmask_call1_call2, MASK_CALL1,MASK_CALL2, MASK_GRIDBIT); + encodemsg_jt65(pcodec->apmask_call1_call2_grid,MASK_CALL1,MASK_CALL2, MASK_GRIDFULL12); + encodemsg_jt65(pcodec->apmask_cq_call2, MASK_CQQRZ, MASK_CALL2, MASK_GRIDBIT); + encodemsg_jt65(pcodec->apmask_cq_call2_ooo, MASK_CQQRZ, MASK_CALL2, MASK_GRIDFULL12); + + return pcodec; +} + +void qra64_close(qra64codec *pcodec) +{ + free(pcodec); +} + +int qra64_apset(qra64codec *pcodec, const int mycall, const int hiscall, const int grid, const int aptype) +{ +// Set decoder a-priori knowledge accordingly to the type of the message to look up for +// arguments: +// pcodec = pointer to a qra64codec data structure as returned by qra64_init +// mycall = mycall to look for +// hiscall = hiscall to look for +// grid = grid to look for +// aptype = define and masks the type of AP to be set accordingly to the following: +// APTYPE_CQQRZ set [cq/qrz ? ?/blank] +// APTYPE_MYCALL set [mycall ? ?/blank] +// APTYPE_HISCALL set [? hiscall ?/blank] +// APTYPE_BOTHCALLS set [mycall hiscall ?] +// APTYPE_FULL set [mycall hiscall grid] +// APTYPE_CQHISCALL set [cq/qrz hiscall ?/blank] and [cq/qrz hiscall grid] +// returns: +// 0 on success +// -1 when qra64_init was called with the QRA_NOAP flag +// -2 invalid apytpe + + if (pcodec->apflags==QRA_NOAP) + return -1; + + switch (aptype) { + case APTYPE_CQQRZ: + encodemsg_jt65(pcodec->apmsg_cqqrz, CALL_CQ, 0, GRID_BLANK); + break; + case APTYPE_MYCALL: + encodemsg_jt65(pcodec->apmsg_call1, mycall, 0, GRID_BLANK); + break; + case APTYPE_HISCALL: + encodemsg_jt65(pcodec->apmsg_call2, 0, hiscall, GRID_BLANK); + break; + case APTYPE_BOTHCALLS: + encodemsg_jt65(pcodec->apmsg_call1_call2, mycall, hiscall, GRID_BLANK); + break; + case APTYPE_FULL: + encodemsg_jt65(pcodec->apmsg_call1_call2_grid, mycall, hiscall, grid); + break; + case APTYPE_CQHISCALL: + encodemsg_jt65(pcodec->apmsg_cq_call2, CALL_CQ, hiscall, GRID_BLANK); + encodemsg_jt65(pcodec->apmsg_cq_call2_grid, CALL_CQ, hiscall, grid); + break; + default: + return -2; // invalid ap type + } + + pcodec->apmsg_set[aptype]=1; // signal the decoder to look-up for the specified type + + + return 0; +} +void qra64_apdisable(qra64codec *pcodec, const int aptype) +{ + if (pcodec->apflags==QRA_NOAP) + return; + + if (aptype=APTYPE_SIZE) + return; + + pcodec->apmsg_set[aptype] = 0; // signal the decoder not to look-up to the specified type +} + +void qra64_encode(qra64codec *pcodec, int *y, const int *x) +{ + int encx[QRA64_KC]; // encoder input buffer + int ency[QRA64_NC]; // encoder output buffer + + int hiscall,mycall,grid; + + memcpy(encx,x,QRA64_K*sizeof(int)); // Copy input to encoder buffer + encx[QRA64_K]=calc_crc6(encx,QRA64_K); // Compute and add crc symbol + qra_encode(&QRA64_CODE, ency, encx); // encode msg+crc using given QRA code + + // copy codeword to output puncturing the crc symbol + memcpy(y,ency,QRA64_K*sizeof(int)); // copy information symbols + memcpy(y+QRA64_K,ency+QRA64_KC,QRA64_C*sizeof(int)); // copy parity symbols + + if (pcodec->apflags!=QRA_AUTOAP) + return; + + // Here we handle the QRA_AUTOAP mode -------------------------------------------- + + // When a [hiscall mycall ?] msg is detected we instruct the decoder + // to look for [mycall hiscall ?] msgs + // otherwise when a [cq mycall ?] msg is sent we reset the APTYPE_BOTHCALLS + + // look if the msg sent is a std type message (bit15 of grid field = 0) + if ((x[9]&0x80)==1) + return; // no, it's a text message, nothing to do + + // It's a [hiscall mycall grid] message + + // We assume that mycall is our call (but we don't check it) + // hiscall the station we are calling or a general call (CQ/QRZ/etc..) + decodemsg_jt65(&hiscall,&mycall,&grid,x); + + + if ((hiscall>=CALL_CQ && hiscall<=CALL_CQ999) || hiscall==CALL_CQDX || + hiscall==CALL_DE) { + // tell the decoder to look for msgs directed to us + qra64_apset(pcodec,mycall,0,0,APTYPE_MYCALL); + // We are making a general call and don't know who might reply + // Reset APTYPE_BOTHCALLS so decoder won't look for [mycall hiscall ?] msgs + qra64_apdisable(pcodec,APTYPE_BOTHCALLS); + } else { + // We are replying to someone named hiscall + // Set APTYPE_BOTHCALLS so decoder will try for [mycall hiscall ?] msgs + qra64_apset(pcodec,mycall, hiscall, GRID_BLANK, APTYPE_BOTHCALLS); + } + +} + +#define EBNO_MIN -10.0f // minimum Eb/No value returned by the decoder (in dB) +int qra64_decode(qra64codec *pcodec, float *ebno, int *x, const float *rxen) +{ + int k; + float *srctmp, *dsttmp; + float ix[QRA64_NC*QRA64_M]; // (depunctured) intrisic information + int xdec[QRA64_KC]; // decoded message (with crc) + int ydec[QRA64_NC]; // re-encoded message (for snr calculations) + float noisestd; // estimated noise variance + float msge; // estimated message energy + float ebnoval; // estimated Eb/No + int rc; + + if (QRA64_NMSG!=QRA64_CODE.NMSG) // sanity check + return -16; // QRA64_NMSG define is wrong + + // compute symbols intrinsic probabilities from received energy observations + noisestd = qra_mfskbesselmetric(ix, rxen, QRA64_m, QRA64_N,pcodec->decEsNoMetric); + + // de-puncture observations adding a uniform distribution for the crc symbol + + // move check symbols distributions one symbol towards the end + dsttmp = PD_ROWADDR(ix,QRA64_M, QRA64_NC-1); //Point to last symbol prob dist + srctmp = dsttmp-QRA64_M; // source is the previous pd + for (k=0;k57.004f) + ebnoval=57.004f; + ebnoval = ebnoval*57.03f/(57.03f-ebnoval); + + // compute value in dB + if (ebnoval<=0) + ebnoval = EBNO_MIN; // assume a minimum, positive value + else + ebnoval = 10.0f*(float)log10(ebnoval); + if (ebnoval4) + return -17; // invalid submode + + if (B90<1.0f || B90>238.0f) + return -18; // B90 out of range + + // compute index to most appropriate amplitude weighting function coefficients + hidx = (int)(log((float)B90)/log(1.09f) - 0.499f); + + if (hidx<0 || hidx > 64) + return -19; // index of weighting function out of range + + if (fadingModel==0) { // gaussian fading model + // point to gaussian weighting taps + hlen = hlen_tab_gauss[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) + hptr = hptr_tab_gauss[hidx]; // pointer to the first (L+1)/2 coefficients of w fun + } + else if (fadingModel==1) { + // point to lorentzian weighting taps + hlen = hlen_tab_lorentz[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) + hptr = hptr_tab_lorentz[hidx]; // pointer to the first (L+1)/2 coefficients of w fun + } + else + return -20; // invalid fading model index + + + // compute (euristically) the optimal decoder metric accordingly the given spread amount + // We assume that the decoder threshold is: + // Es/No(dB) = Es/No(AWGN)(dB) + 8*log(B90)/log(240)(dB) + // that's to say, at the maximum Doppler spread bandwidth (240 Hz) there's a ~8 dB Es/No degradation + // over the AWGN case + tempf = 8.0f*(float)log((float)B90)/(float)log(240.0f); + EsNoMetric = pcodec->decEsNoMetric*(float)pow(10.0f,tempf/10.0f); + + // Step 1 ----------------------------------------------------------------------------------- + // Evaluate the noise stdev from the received energies at nominal tone frequencies + // and transform energies to amplitudes + tempf = hptr[hlen-1]; // amplitude weigth at nominal freq; + tempf = tempf*tempf; // fractional energy at nominal freq. bin + + noisestd = qra64_fastfading_estim_noise_std(rxen, EsNoMetric, submode); + cmetric = (float)sqrt(M_PI_2*EsNoMetric)/noisestd; + + // Step 2 ----------------------------------------------------------------------------------- + // Compute message symbols probability distributions + qra64_fastfading_intrinsics(ix, rxen, hptr, hlen, cmetric, submode); + + // Step 3 --------------------------------------------------------------------------- + // De-puncture observations adding a uniform distribution for the crc symbol + // Move check symbols distributions one symbol towards the end + dsttmp = PD_ROWADDR(ix,QRA64_M, QRA64_NC-1); //Point to last symbol prob dist + srctmp = dsttmp-QRA64_M; // source is the previous pd + for (k=0;k238.0f) + return -18; // B90 out of range + + // compute index to most appropriate amplitude weighting function coefficients + hidx = (int)(log((float)B90)/log(1.09f) - 0.499f); + + if (hidx<0 || hidx > 64) + return -19; // index of weighting function out of range + + if (fadingModel==0) { // gaussian fading model + // point to gaussian weighting taps + hlen = hlen_tab_gauss[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) + hptr = hptr_tab_gauss[hidx]; // pointer to the first (L+1)/2 coefficients of w fun + } + else if (fadingModel==1) { + // point to lorentzian weighting taps + hlen = hlen_tab_lorentz[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) + hptr = hptr_tab_lorentz[hidx]; // pointer to the first (L+1)/2 coefficients of w fun + } + else + return -20; // invalid fading model index + + + // Compute the unfaded tone amplitudes from the Eb/No value passed to the call + N0 = 1.0f; // assume unitary noise PSD + sigmanoise = (float)sqrt(N0/2); + EsN0 = (float)pow(10.0f,EbN0dB/10.0f)*QRA64_m*QRA64_K/QRA64_N; // Es/No = m*R*Eb/No + Es = EsN0*N0; + A = (float)sqrt(Es/2.0f); // unfaded tone amplitude (i^2+q^2 = Es/2+Es/2 = Es) + + + // Generate gaussian noise iq components + normrnd_s(channel_out, bpm*2, 0 , sigmanoise); + + // Add message symbols energies + for (n=0;n=0;j--) { + sigmasig = A*hptr[j]; + normrnd_s(iq, 2, 0 , sigmasig); +// iq[0]=sigmasig*sqrt(2); iq[1]=0; debug: used to verify Eb/No + *curi++ += iq[0]; + *curq++ += iq[1]; +// tote +=iq[0]*iq[0]+iq[1]*iq[1]; // debug + } + + } + +// tote = tote/QRA64_N; // debug + + // compute total bin energies (S+N) and store in first half of buffer + curi = channel_out; + curq = channel_out+bpm; + for (n=0;n=0;j--) { + u = *curbin++ * hptr[j]*cmetric; + u = u*u/(u+(float)M_E); // log(I0(u)) approx. + loglh = loglh + u; + } + if (loglh>maxloglh) // keep track of the max loglikelihood + maxloglh = loglh; + curix[k]=loglh; + } + // scale to likelihoods + sumix = 0.f; + for (k=0;k=0;j--) { + u = *curbin++; + msgsn += u*u; + } + + } + + msgsn = msgsn/(QRA64_N*tothlen); // avg msg energy per bin (noise included) + + // as sigma is overestimated (sigmatrue = sigma*sqrt((1+EsNoMetric/bps)/(1+EsNo/bps)) + // we have: msgsn = (1+x/hlen)/(1+x/bps)*2*sigma^2*(1+EsnoMetric/bps), where x = Es/N0(true) + // + // we can then write: + // u = msgsn/2.0f/(sigma*sigma)/(1.0f+EsNoMetric/bps); + // (1+x/hlen)/(1+x/bps) = u + + u = msgsn/(2.0f*sigma*sigma)/(1.0f+EsNoMetric/bps); + + // check u>1 + if (u<1) + return 0.f; + + // check u(bps/tothlen)) + return 10000.f; + + // solve for Es/No + esno = (u-1.0f)/(1.0f/tothlen-u/bps); + + return esno; + + +} + + +// Attempt to decode given intrisic information +static int qra64_decode_attempts(qra64codec *pcodec, int *xdec, const float *ix) +{ + int rc; + + // Attempt to decode without a-priori info -------------------------------- + rc = qra64_do_decode(xdec, ix, NULL, NULL); + if (rc>=0) + return 0; // successfull decode with AP0 + else + if (pcodec->apflags==QRA_NOAP) + // nothing more to do + return rc; // rc<0 = unsuccessful decode + + // Here we handle decoding with AP knowledge + + // Attempt to decode CQ calls + rc = qra64_do_decode(xdec,ix,pcodec->apmask_cqqrz, pcodec->apmsg_cqqrz); + if (rc>=0) return 1; // decoded [cq/qrz ? ?] + + rc = qra64_do_decode(xdec, ix, pcodec->apmask_cqqrz_ooo, + pcodec->apmsg_cqqrz); + if (rc>=0) return 2; // decoded [cq ? ooo] + + // attempt to decode calls directed to us + if (pcodec->apmsg_set[APTYPE_MYCALL]) { + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1, + pcodec->apmsg_call1); + if (rc>=0) return 3; // decoded [mycall ? ?] + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_ooo, + pcodec->apmsg_call1); + if (rc>=0) return 4; // decoded [mycall ? ooo] + } + + // attempt to decode [mycall srccall ?] msgs + if (pcodec->apmsg_set[APTYPE_BOTHCALLS]) { + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_call2, + pcodec->apmsg_call1_call2); + if (rc>=0) return 5; // decoded [mycall srccall ?] + } + + // attempt to decode [? hiscall ?/b] msgs + if (pcodec->apmsg_set[APTYPE_HISCALL]) { + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call2, + pcodec->apmsg_call2); + if (rc>=0) return 6; // decoded [? hiscall ?] + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call2_ooo, + pcodec->apmsg_call2); + if (rc>=0) return 7; // decoded [? hiscall ooo] + } + + // attempt to decode [cq/qrz hiscall ?/b/grid] msgs + if (pcodec->apmsg_set[APTYPE_CQHISCALL]) { + + rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2, + pcodec->apmsg_cq_call2); + if (rc>=0) return 9; // decoded [cq/qrz hiscall ?] + + rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2_ooo, + pcodec->apmsg_cq_call2_grid); + if (rc>=0) { + // Full AP mask need special handling + // To minimize false decodes we check the decoded message + // with what passed in the ap_set call + if (memcmp(pcodec->apmsg_cq_call2_grid,xdec, QRA64_K*sizeof(int))!=0) + return -1; + else + return 11; // decoded [cq/qrz hiscall grid] + }; + + rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2_ooo, + pcodec->apmsg_cq_call2); + if (rc>=0) { + // Full AP mask need special handling + // To minimize false decodes we check the decoded message + // with what passed in the ap_set call + if (memcmp(pcodec->apmsg_cq_call2,xdec, QRA64_K*sizeof(int))!=0) + return -1; + else + return 10; // decoded [cq/qrz hiscall ] + } + } + + // attempt to decode [mycall hiscall grid] + if (pcodec->apmsg_set[APTYPE_FULL]) { + rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_call2_grid, + pcodec->apmsg_call1_call2_grid); + if (rc>=0) { + // Full AP mask need special handling + // All the three msg fields were given. + // To minimize false decodes we check the decoded message + // with what passed in the ap_set call + if (memcmp(pcodec->apmsg_call1_call2_grid,xdec, QRA64_K*sizeof(int))!=0) + return -1; + else + return 8; // decoded [mycall hiscall grid] + } + } + + // all decoding attempts failed + return rc; +} + + + +// Decode with given a-priori information +static int qra64_do_decode(int *xdec, const float *pix, const int *ap_mask, + const int *ap_x) +{ + int rc; + const float *ixsrc; + float ix_masked[QRA64_NC*QRA64_M]; // Masked intrinsic information + float ex[QRA64_NC*QRA64_M]; // Extrinsic information from the decoder + + float v2cmsg[QRA64_NMSG*QRA64_M]; // buffers for the decoder messages + float c2vmsg[QRA64_NMSG*QRA64_M]; + + if (ap_mask==NULL) { // no a-priori information + ixsrc = pix; // intrinsic source is what passed as argument + } else { + // a-priori information provided + // mask channel observations with a-priori + ix_mask(ix_masked,pix,ap_mask,ap_x); + ixsrc = ix_masked; // intrinsic source is the masked version + } + + // run the decoding algorithm + rc = qra_extrinsic(&QRA64_CODE,ex,ixsrc,QRA64_NITER,v2cmsg,c2vmsg); + if (rc<0) + return -1; // no convergence in given iterations + + // decode + qra_mapdecode(&QRA64_CODE,xdec,ex,ixsrc); + + // verify crc + if (calc_crc6(xdec,QRA64_K)!=xdec[QRA64_K]) // crc doesn't match (detected error) + return -2; // decoding was succesfull but crc doesn't match + + return 0; +} + + +// crc functions -------------------------------------------------------------- +// crc-6 generator polynomial +// g(x) = x^6 + a5*x^5 + ... + a1*x + a0 + +// g(x) = x^6 + x + 1 +#define CRC6_GEN_POL 0x30 // MSB=a0 LSB=a5 + +// g(x) = x^6 + x^2 + x + 1 (See: https://users.ece.cmu.edu/~koopman/crc/) +// #define CRC6_GEN_POL 0x38 // MSB=a0 LSB=a5. Simulation results are similar + +static int calc_crc6(const int *x, int sz) +{ + // todo: compute it faster using a look up table + int k,j,t,sr = 0; + for (k=0;k>1) ^ CRC6_GEN_POL; + else + sr = (sr>>1); + t>>=1; + } + } + return sr; +} + +static void ix_mask(float *dst, const float *src, const int *mask, + const int *x) +{ + // mask intrinsic information (channel observations) with a priori knowledge + + int k,kk, smask; + float *row; + + memcpy(dst,src,(QRA64_NC*QRA64_M)*sizeof(float)); + + for (k=0;k>22)&0x3F; + y[1]= (call1>>16)&0x3F; + y[2]= (call1>>10)&0x3F; + y[3]= (call1>>4)&0x3F; + y[4]= (call1<<2)&0x3F; + + y[4] |= (call2>>26)&0x3F; + y[5]= (call2>>20)&0x3F; + y[6]= (call2>>14)&0x3F; + y[7]= (call2>>8)&0x3F; + y[8]= (call2>>2)&0x3F; + y[9]= (call2<<4)&0x3F; + + y[9] |= (grid>>12)&0x3F; + y[10]= (grid>>6)&0x3F; + y[11]= (grid)&0x3F; + +} +void decodemsg_jt65(int *call1, int *call2, int *grid, const int *x) +{ + int nc1, nc2, ng; + + nc1 = x[4]>>2; + nc1 |= x[3]<<4; + nc1 |= x[2]<<10; + nc1 |= x[1]<<16; + nc1 |= x[0]<<22; + + nc2 = x[9]>>4; + nc2 |= x[8]<<2; + nc2 |= x[7]<<8; + nc2 |= x[6]<<14; + nc2 |= x[5]<<20; + nc2 |= (x[4]&0x03)<<26; + + ng = x[11]; + ng |= x[10]<<6; + ng |= (x[9]&0x0F)<<12; + + *call1 = nc1; + *call2 = nc2; + *grid = ng; +} diff --git a/lib/qra/qra64/qra64_subs.c b/lib/qra/qra64/qra64_subs.c new file mode 100644 index 00000000..b60f9faf --- /dev/null +++ b/lib/qra/qra64/qra64_subs.c @@ -0,0 +1,65 @@ +// qra64_subs.c +// Fortran interface routines for QRA64 + +#include "qra64.h" +#include + +static qra64codec *pqra64codec = NULL; + +void qra64_enc_(int x[], int y[]) +{ + if (pqra64codec==NULL) pqra64codec = qra64_init(QRA_USERAP); + qra64_encode(pqra64codec, y, x); +} + +void qra64_dec_(float r[], int* nc1, int* nc2, int* ng2, int* APtype, + int* iset, int* ns0, float* b0, int* nf0, + int xdec[], float* snr, int* rc) +{ +/* + APtype: AP +----------------------------------------------------------------------- + -1 0 (no AP information) + 0 [CQ/QRZ ? ? ] 25/37 + 1 [MyCall ? ? ] 25/37 + 2 [ ? HisCall ? ] 25/37 + 3 [MyCall HisCall ? ] 49/68 + 4 [MyCall HisCall grid] 68 + 5 [CQ/QRZ HisCall ? ] 49/68 + + rc Message format AP APTYPE Comments +------------------------------------------------------------------------ + -16 Failed sanity check + -2 Decoded but CRC failed + -1 No decode + 0 [ ? ? ? ] 0 -1 Decode with no AP info + 1 [CQ/QRZ ? ? ] 25 0 + 2 [CQ/QRZ ? _ ] 37 0 + 3 [MyCall ? ? ] 25 1 + 4 [MyCall ? _ ] 37 1 + 5 [MyCall HisCall ? ] 49 3 + 6 [ ? HisCall ? ] 25 2 Optional + 7 [ ? HisCall _ ] 37 2 Optional + 8 [MyCall HisCall Grid] 68 4 + 9 [CQ/QRZ HisCall ? ] 49 5 Optional (not needed?) + 10 [CQ/QRZ HisCall _ ] 68 5 Optional + 11 [CQ/QRZ HisCall Grid] 68 ? Optional +*/ + + float EbNodBEstimated; + int err=0; + int nSubmode=*ns0; + float b90=*b0; + int nFadingModel=*nf0; + + if(pqra64codec==NULL) pqra64codec = qra64_init(QRA_USERAP); + err=qra64_apset(pqra64codec,*nc1,*nc2,*ng2,*APtype); + if(err<0) printf("ERROR: qra64_apset returned %d\n",err); + + if(*iset==0) { + *rc = qra64_decode_fastfading(pqra64codec,&EbNodBEstimated,xdec,r, + nSubmode,b90,nFadingModel); + *snr = EbNodBEstimated - 31.0; + } +} + diff --git a/lib/qra/qra64/qra64example.txt b/lib/qra/qra64/qra64example.txt new file mode 100644 index 00000000..3add33d3 --- /dev/null +++ b/lib/qra/qra64/qra64example.txt @@ -0,0 +1,88 @@ +$ qra64_nico -h + +QRA64 Mode Tests +2016, Nico Palermo - IV3NWV + +--------------------------- + +Syntax: qra64 [-s] [-c] [-a] [-t] [-h] +Options: + -s : set simulation SNR in 2500 Hz BW (default:-27.5 dB) + -c : set channel type 0=AWGN (default) 1=Rayleigh + -a : set decode type 0=NOAP 1=AUTOAP (default) 2=USERAP + -t: 0=simulate seq of msgs between IV3NWV and K1JT (default) + 1=simulate K1JT receiving K1JT IV3NWV JN66 + 2=simulate fast-fading routines (option -c ignored) +Options used only for fast-fading simulations: + -b : 90% fading bandwidth in Hz [1..230 Hz] (default = 2.5 Hz) + -m : fading model. 0=Gauss, 1=Lorentz (default = Lorentz) + -q : qra64 submode. 0=QRA64A,... 4=QRA64E (default = QRA64A) + -h: this help + + +############################################################################# +Usage example: + +qra64 -c2 -t2 -a2 -b50 -m1 -q2 -s-26.0 -n50000 + +Simulate a fast-fading channel (-c2) +Evaluate decoder performance (-t2) with +USER_AP (-a2) +B90 = 50 Hz (-b50) +Lorentz model (-m1) +submode QRA64C (-q2) +Input SNR = -26.0 dB (-s-26.0) +Simulate 50000 transmissions (-n50000) + +(type qra64 -h for command syntax) + +Command Output: + +Input SNR = -26.0dB ap-mode=USER AP + +Simulating the fast-fading channel +B90=50.00 Hz - Fading Model=Lorentz - Submode=QRA64C +Decoder metric = Matched to fast-fading signal + +Encoding msg [K1JT IV3NWV JN66] +50000 transmissions will be simulated + +K1JT decoder enabled for [CQ ? ?/blank] +K1JT decoder enabled for [K1JT ? ?/blank] +K1JT decoder enabled for [? IV3NWV ?/blank] +K1JT decoder enabled for [K1JT IV3NWV ?] +K1JT decoder enabled for [K1JT IV3NWV JN66] +K1JT decoder enabled for [CQ IV3NWV ?/b/JN66] + +Now decoding with K1JT's decoder... + 5.5 % +Undetected error with rc=6 + 13.1 % +Undetected error with rc=7 + 70.8 % +Undetected error with rc=1 + 75.8 % +Undetected error with rc=9 + 88.9 % +Undetected error with rc=6 + 100.0 % + +Msgs transmitted:50000 +Msg decoded: + +rc= 0 0 with [? ? ?] AP0 +rc= 1 0 with [CQ ? ?] AP27 +rc= 2 0 with [CQ ? ] AP42 +rc= 3 145 with [CALL ? ?] AP29 +rc= 4 0 with [CALL ? ] AP44 +rc= 5 12085 with [CALL CALL ?] AP57 +rc= 6 0 with [? CALL ?] AP29 +rc= 7 0 with [? CALL ] AP44 +rc= 8 24307 with [CALL CALL G] AP72 +rc= 9 0 with [CQ CALL ?] AP55 +rc=10 0 with [CQ CALL ] AP70 +rc=11 0 with [CQ CALL G] AP70 + +Total: 36537/50000 (5 undetected errors) + +Estimated SNR (average in dB) = -26.26 dB diff --git a/lib/qra/qra64/qra64sim.f90 b/lib/qra/qra64/qra64sim.f90 new file mode 100644 index 00000000..b7ca2e13 --- /dev/null +++ b/lib/qra/qra64/qra64sim.f90 @@ -0,0 +1,170 @@ +program qra64sim + +! Generate simulated QRA64 data for testing the decoder. + + use wavhdr + use packjt + parameter (NMAX=54*12000) ! = 648,000 + parameter (NFFT=10*65536,NH=NFFT/2) + type(hdr) h !Header for .wav file + integer*2 iwave(NMAX) !Generated waveform + integer*4 itone(84) !Channel symbols (values 0-63) + real*4 xnoise(NMAX) !Generated random noise + real*4 dat(NMAX) !Generated real data + complex cdat(NMAX) !Generated complex waveform + complex cspread(0:NFFT-1) !Complex amplitude for Rayleigh fading + complex z + real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq + character msg*22,fname*11,csubmode*1,arg*12 + character msgsent*22 + + nargs=iargc() + if(nargs.ne. 7) then + print *, 'Usage: qra64sim "msg" A-E Nsigs fDop DT Nfiles SNR' + print *, 'Example qra64sim "K1ABC W9XYZ EN37" A 10 0.2 0.0 1 0' + go to 999 + endif + call getarg(1,msg) + call getarg(2,csubmode) + mode64=2**(ichar(csubmode)-ichar('A')) + call getarg(3,arg) + read(arg,*) nsigs + call getarg(4,arg) + read(arg,*) fspread + call getarg(5,arg) + read(arg,*) xdt + call getarg(6,arg) + read(arg,*) nfiles + call getarg(7,arg) + read(arg,*) snrdb + + if(mode64.ge.8) nsigs=1 + rms=100. + fsample=12000.d0 !Sample rate (Hz) + dt=1.d0/fsample !Sample interval (s) + twopi=8.d0*atan(1.d0) + npts=54*12000 !Total samples in .wav file + nsps=6912 + baud=12000.d0/nsps !Keying rate = 1.7361111111 + nsym=84 !Number of channel symbols + h=default_header(12000,npts) + dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz) + ichk=0 + + write(*,1000) +1000 format('File Sig Freq A-E S/N DT Dop Message'/60('-')) + + do ifile=1,nfiles !Loop over requested number of files + write(fname,1002) ifile !Output filename +1002 format('000000_',i4.4) + open(10,file=fname//'.wav',access='stream',status='unknown') + xnoise=0. + cdat=0. + if(snrdb.lt.90) then + do i=1,npts + xnoise(i)=gran() !Generate gaussian noise + enddo + endif + + do isig=1,nsigs !Generate requested number of sigs + if(mod(nsigs,2).eq.0) f0=1500.0 + dfsig*(isig-0.5-nsigs/2) + if(mod(nsigs,2).eq.1) f0=1500.0 + dfsig*(isig-(nsigs+1)/2) + if(nsigs.eq.1) f0=1000.0 + xsnr=snrdb + if(snrdb.eq.0.0) xsnr=-20 - isig + + call genqra64(msg,ichk,msgsent,itone,itype) + + bandwidth_ratio=2500.0/6000.0 + sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*xsnr) + if(xsnr.gt.90.0) sig=1.0 + write(*,1020) ifile,isig,f0,csubmode,xsnr,xdt,fspread,msg +1020 format(i4,i4,f10.3,2x,a1,2x,f5.1,f6.2,f6.1,1x,a22) + + phi=0.d0 + dphi=0.d0 + k=(xdt+1.0)*12000 !Start audio at t = xdt + 1.0 s + isym0=-99 + do i=1,npts !Add this signal into cdat() + isym=i/nsps + 1 + if(isym.gt.nsym) exit + if(isym.ne.isym0) then + freq=f0 + itone(isym)*baud*mode64 + dphi=twopi*freq*dt + isym0=isym + endif + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + xphi=phi + z=cmplx(cos(xphi),sin(xphi)) + k=k+1 + if(k.ge.1) cdat(k)=cdat(k) + sig*z + enddo + enddo + + if(fspread.ne.0) then !Apply specified Doppler spread + df=12000.0/nfft + twopi=8*atan(1.0) + cspread(0)=1.0 + cspread(NH)=0. + b=6.0 !Lorenzian 3/28 onward + do i=1,NH + f=i*df + x=b*f/fspread + z=0. + a=0. + if(x.lt.3.0) then !Cutoff beyond x=3 + a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian + call random_number(r1) + phi1=twopi*r1 + z=a*cmplx(cos(phi1),sin(phi1)) + endif + cspread(i)=z + z=0. + if(x.lt.50.0) then + call random_number(r2) + phi2=twopi*r2 + z=a*cmplx(cos(phi2),sin(phi2)) + endif + cspread(NFFT-i)=z + enddo + + do i=0,NFFT-1 + f=i*df + if(i.gt.NH) f=(i-nfft)*df + s=real(cspread(i))**2 + aimag(cspread(i))**2 +! write(13,3000) i,f,s,cspread(i) +!3000 format(i5,f10.3,3f12.6) + enddo +! s=real(cspread(0))**2 + aimag(cspread(0))**2 +! write(13,3000) 1024,0.0,s,cspread(0) + + call four2a(cspread,NFFT,1,1,1) !Transform to time domain + + sum=0. + do i=0,NFFT-1 + p=real(cspread(i))**2 + aimag(cspread(i))**2 + sum=sum+p + enddo + avep=sum/NFFT + fac=sqrt(1.0/avep) + cspread=fac*cspread !Normalize to constant avg power + cdat=cspread(1:npts)*cdat !Apply Rayleigh fading + +! do i=0,NFFT-1 +! p=real(cspread(i))**2 + aimag(cspread(i))**2 +! write(14,3010) i,p,cspread(i) +!3010 format(i8,3f12.6) +! enddo + + endif + + dat=aimag(cdat) + xnoise !Add the generated noise + fac=32767.0/nsigs + if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts)) + if(snrdb.lt.90.0) iwave(1:npts)=nint(rms*dat(1:npts)) + write(10) h,iwave(1:npts) !Save the .wav file + close(10) + enddo + +999 end program qra64sim diff --git a/lib/qra/qracodes/Makefile.Win b/lib/qra/qracodes/Makefile.Win new file mode 100644 index 00000000..fb30504e --- /dev/null +++ b/lib/qra/qracodes/Makefile.Win @@ -0,0 +1,33 @@ +CC = gcc +CFLAGS = -O2 -Wall -I. -D_WIN32 + +# Default rules +%.o: %.c + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: libqra64.a qracodes.exe + +OBJS1 = normrnd.o npfwht.o pdmath.o qra12_63_64_irr_b.o \ + qra13_64_64_irr_e.o qracodes.o + +libqra64.a: $(OBJS1) + ar cr libqra64.a $(OBJS1) + ranlib libqra64.a + +OBJS2 = main.o + +qracodes.exe: $(OBJS2) + ${CC} -o qracodes.exe $(OBJS2) libqra64.a -lm + +.PHONY : clean + +clean: + $(RM) *.o libqra64.a qracodes.exe diff --git a/lib/qra/qracodes/ebno10000.txt b/lib/qra/qracodes/ebno10000.txt new file mode 100644 index 00000000..c41174b9 --- /dev/null +++ b/lib/qra/qracodes/ebno10000.txt @@ -0,0 +1,7 @@ +# Eb/No Values to be used during the code simulation +# Each line of this file indicates the Eb/No value to be simulated (in dB) +# and the number of errors to be detected by the decoder +0.6 10000 +1.1 10000 +1.6 10000 +2.1 10000 diff --git a/lib/qra/qracodes/ebnovalues.txt b/lib/qra/qracodes/ebnovalues.txt new file mode 100644 index 00000000..7dba138f --- /dev/null +++ b/lib/qra/qracodes/ebnovalues.txt @@ -0,0 +1,15 @@ +# Eb/No Values to be used during the code simulation +# Each line of this file indicates the Eb/No value to be simulated (in dB) +# and the number of errors to be detected by the decoder +1.1 1000 +1.6 1000 +2.1 1000 +2.6 1000 +3.1 1000 +3.6 1000 +4.1 1000 +4.6 1000 +5.1 500 +5.6 200 +6.1 100 +6.6 50 \ No newline at end of file diff --git a/lib/qra/qracodes/ebnovaluesfast.txt b/lib/qra/qracodes/ebnovaluesfast.txt new file mode 100644 index 00000000..b057b312 --- /dev/null +++ b/lib/qra/qracodes/ebnovaluesfast.txt @@ -0,0 +1,11 @@ +# Eb/No Values to be used during the code simulation +# Each line of this file indicates the Eb/No value to be simulated (in dB) +# and the number of errors to be detected by the decoder +1.1 500 +1.6 500 +2.1 500 +2.6 500 +3.1 500 +3.6 500 +4.1 200 +4.6 50 diff --git a/lib/qra/qracodes/main.c b/lib/qra/qracodes/main.c new file mode 100644 index 00000000..5f9f067d --- /dev/null +++ b/lib/qra/qracodes/main.c @@ -0,0 +1,737 @@ +// main.c +// Word Error Rate test example for Q-ary RA codes over GF(64) +// +// (c) 2016 - Nico Palermo, IV3NWV +// +// Thanks to Andrea Montefusco IW0HDV for his help on adapting the sources +// to OSs other than MS Windows +// +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// Files in this package: +// main.c - this file +// normrnd.c/.h - random gaussian number generator +// npfwht.c/.h - Fast Walsh-Hadamard Transforms +// pdmath.c/.h - Elementary math on probability distributions +// qra12_63_64_irr_b.c/.h - Tables for a QRA(12,63) irregular RA code over GF(64) +// qra13_64_64_irr_e.c/.h - Tables for a QRA(13,64) irregular RA code " " +// qracodes.c/.h - QRA codes encoding/decoding functions +// +// ------------------------------------------------------------------------------- +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +// ----------------------------------------------------------------------------- + +// Two codes are available for simulations in this sowftware release: + +// QRA12_63_64_IRR_B: K=12 N=63 Q=64 irregular QRA code (defined in qra12_63_64_irr_b.h /.c) +// QRA13_64_64_IRR_E: K=13 N=64 Q=64 irregular QRA code (defined in qra13_64_64_irr_b.h /.c) + +// Codes with K=13 are designed to include a CRC as the 13th information symbol +// and improve the code UER (Undetected Error Rate). +// The CRC symbol is not sent along the channel (the codes are punctured) and the +// resulting code is still a (12,63) code with an effective code rate of R = 12/63. + +// ------------------------------------------------------------------------------ + +// OS dependent defines and includes -------------------------------------------- + +#if _WIN32 // note the underscore: without it, it's not msdn official! + // Windows (x64 and x86) + #include // required only for GetTickCount(...) + #include // _beginthread +#endif + +#if defined(__linux__) + +// remove unwanted macros +#define __cdecl + +// implements Windows API +#include + + unsigned int GetTickCount(void) { + struct timespec ts; + unsigned int theTick = 0U; + clock_gettime( CLOCK_REALTIME, &ts ); + theTick = ts.tv_nsec / 1000000; + theTick += ts.tv_sec * 1000; + return theTick; +} + +// Convert Windows millisecond sleep +// +// VOID WINAPI Sleep(_In_ DWORD dwMilliseconds); +// +// to Posix usleep (in microseconds) +// +// int usleep(useconds_t usec); +// +#include +#define Sleep(x) usleep(x*1000) + +#endif + +#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) ) +#include +#endif + +#if __APPLE__ +#endif + +#include +#include + +#include "qracodes.h" +#include "normrnd.h" // gaussian numbers generator +#include "pdmath.h" // operations on probability distributions + +// defined codes +#include "qra12_63_64_irr_b.h" +#include "qra13_64_64_irr_e.h" + +// ----------------------------------------------------------------------------------- + +#define NTHREADS_MAX 160 + +// channel types +#define CHANNEL_AWGN 0 +#define CHANNEL_RAYLEIGH 1 + +// amount of a-priori information provided to the decoder +#define AP_NONE 0 +#define AP_28 1 +#define AP_44 2 +#define AP_56 3 + +const char ap_str[4][16] = { + "None", + "28 bit", + "44 bit", + "56 bit" +}; + +const char fnameout_pfx[2][64] = { + "wer-awgn-", + "wer-rayleigh-" +}; +const char fnameout_sfx[4][64] = { + "-ap00.txt", + "-ap28.txt", + "-ap44.txt", + "-ap56.txt" +}; + +const int ap_masks_jt65[4][13] = { +// Each row must be 13 entries long (to handle puntc. codes 13,64) +// The mask of 13th symbol (crc) is alway initializated to 0 + // AP0 - no a-priori knowledge + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // AP28 - 1st field known [cq ? ?] or [dst ? ?] + {0x3F,0x3F,0x3F,0x3F,0x3C, 0, 0, 0, 0, 0, 0, 0}, + // AP44 - 1st and 3rd fields known [cq ? 0] or [dst ? 0] + {0x3F,0x3F,0x3F,0x3F,0x3C, 0, 0, 0, 0,0x0F,0x3F,0x3F}, + // AP56 - 1st and 2nd fields known [dst src ?] + {0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x30, 0, 0} +}; + +void ix_mask(const qracode *pcode, float *r, const int *mask, const int *x); + +void printword(char *msg, int *x, int size) +{ + int k; + printf("\n%s ",msg); + for (k=0;kc msg buffer + float *qra_c2vmsg; //[qra_NMSG*qra_M]; MP decoder c->v msg buffer + float *rp; // [qra_N*qra_M]; received samples (real component) buffer + float *rq; // [qra_N*qra_M]; received samples (imag component) buffer + float *chp; //[qra_N]; channel gains (real component) buffer + float *chq; //[qra_N]; channel gains (imag component) buffer + float *r; //[qra_N*qra_M]; received samples (amplitude) buffer + float *ix; // [qra_N*qra_M]; // intrinsic information to the MP algorithm + float *ex; // [qra_N*qra_M]; // extrinsic information from the MP algorithm + +} wer_test_ds; + +typedef void( __cdecl *pwer_test_thread)(wer_test_ds*); + +// crc-6 generator polynomial +// g(x) = x^6 + a5*x^5 + ... + a1*x + a0 + +// g(x) = x^6 + x + 1 +#define CRC6_GEN_POL 0x30 // MSB=a0 LSB=a5 + +// g(x) = x^6 + x^2 + x + 1 (as suggested by Joe. See: https://users.ece.cmu.edu/~koopman/crc/) +// #define CRC6_GEN_POL 0x38 // MSB=a0 LSB=a5. Simulation results are similar + +int calc_crc6(int *x, int sz) +{ + int k,j,t,sr = 0; + for (k=0;k>1) ^ CRC6_GEN_POL; + else + sr = (sr>>1); + t>>=1; + } + } + return sr; +} + +void wer_test_thread(wer_test_ds *pdata) +{ + const qracode *pcode=pdata->pcode; + const int qra_K = pcode->K; + const int qra_N = pcode->N; + const int qra_M = pcode->M; + const int qra_m = pcode->m; + const int NSAMPLES = pcode->N*pcode->M; + + const float No = 1.0f; // noise spectral density + const float sigma = (float)sqrt(No/2.0f); // std dev of noise I/Q components + const float sigmach = (float)sqrt(1/2.0f); // std dev of channel I/Q gains + + // Eb/No value for which we optimize the bessel metric + const float EbNodBMetric = 2.8f; + const float EbNoMetric = (float)pow(10,EbNodBMetric/10); + + int k,t,j,diff; + float R; + float EsNoMetric; + float EbNo, EsNo, Es, A; + int channel_type, code_type; + int nt=0; // transmitted codewords + int nerrs = 0; // total number of errors + int nerrsu = 0; // number of undetected errors + int rc; + + + // inizialize pointer to required buffers + int *x=pdata->x; // message buffer + int *y=pdata->y, *ydec=pdata->ydec; // encoded/decoded codeword buffers + float *qra_v2cmsg=pdata->qra_v2cmsg; // table of the v->c messages + float *qra_c2vmsg=pdata->qra_c2vmsg; // table of the c->v messages + float *rp=pdata->rp; // received samples (real component) + float *rq=pdata->rq; // received samples (imag component) + float *chp=pdata->chp; // channel gains (real component) + float *chq=pdata->chq; // channel gains (imag component) + float *r=pdata->r; // received samples amplitudes + float *ix=pdata->ix; // intrinsic information to the MP algorithm + float *ex=pdata->ex; // extrinsic information from the MP algorithm + + channel_type = pdata->channel_type; + code_type = pcode->type; + + // define the (true) code rate accordingly to the code type + switch(code_type) { + case QRATYPE_CRC: + R = 1.0f*(qra_K-1)/qra_N; + break; + case QRATYPE_CRCPUNCTURED: + R = 1.0f*(qra_K-1)/(qra_N-1); + break; + case QRATYPE_NORMAL: + default: + R = 1.0f*(qra_K)/(qra_N); + } + + EsNoMetric = 1.0f*qra_m*R*EbNoMetric; + + EbNo = (float)pow(10,pdata->EbNodB/10); + EsNo = 1.0f*qra_m*R*EbNo; + Es = EsNo*No; + A = (float)sqrt(Es); + + + // encode the input + if (code_type==QRATYPE_CRC || code_type==QRATYPE_CRCPUNCTURED) { + // compute the information message symbol check as the (negated) xor of all the + // information message symbols + for (k=0;k<(qra_K-1);k++) + x[k]=k%qra_M; + x[k]=calc_crc6(x,qra_K-1); + } + else + for (k=0;kstop==0) { + + // simulate the channel + // NOTE: in the case that the code is punctured, for simplicity + // we compute the channel outputs and the metric also for the crc symbol + // then we ignore its observation. + normrnd_s(rp,NSAMPLES,0,sigma); + normrnd_s(rq,NSAMPLES,0,sigma); + + if (channel_type == CHANNEL_AWGN) { + for (k=0;kdone = 1; + return; // unknown channel type + } + + // compute the squares of the amplitudes of the received samples + for (k=0;km,pcode->N,EsNoMetric); + + if (code_type==QRATYPE_CRCPUNCTURED) { + // ignore observations of the CRC symbol as it is not actually sent + // over the channel + pd_init(PD_ROWADDR(ix,qra_M,qra_K),pd_uniform(qra_m),qra_M); + } + + + if (pdata->ap_index!=0) + // mask channel observations with a priori knowledge + ix_mask(pcode,ix,ap_masks_jt65[pdata->ap_index],x); + + + // compute the extrinsic symbols probabilities with the message-passing algorithm + // stop if extrinsic information does not converges to 1 within the given number of iterations + rc = qra_extrinsic(pcode,ex,ix,100,qra_v2cmsg,qra_c2vmsg); + + if (rc>=0) { // the MP algorithm converged to Iex~1 in rc iterations + + // decode the codeword + qra_mapdecode(pcode,ydec,ex,ix); + + // look for undetected errors + if (code_type==QRATYPE_CRC || code_type==QRATYPE_CRCPUNCTURED) { + + j = 0; diff = 0; + for (k=0;k<(qra_K-1);k++) + diff |= (ydec[k]!=x[k]); + t = calc_crc6(ydec,qra_K-1); + if (t!=ydec[k]) // error detected - crc doesn't matches + nerrs += 1; + else + if (diff) { // decoded message is not equal to the transmitted one but + // the crc test passed + // add as undetected error + nerrsu += 1; + nerrs += 1; + // uncomment to see what the undetected error pattern looks like + //printword("U", ydec); + } + } + else + for (k=0;knt=nt; + pdata->nerrs=nerrs; + pdata->nerrsu=nerrsu; + + } + + pdata->done=1; + + #if _WIN32 + _endthread(); + #endif +} + +#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) ) + +void *wer_test_pthread(void *p) +{ + wer_test_thread ((wer_test_ds *)p); + return 0; +} + +#endif + +void ix_mask(const qracode *pcode, float *r, const int *mask, const int *x) +{ + // mask intrinsic information (channel observations) with a priori knowledge + + int k,kk, smask; + const int qra_K=pcode->K; + const int qra_M=pcode->M; + const int qra_m=pcode->m; + + for (k=0;kNTHREADS_MAX) { + printf("Error: nthreads should be <=%d\n",NTHREADS_MAX); + return -1; + } + + sprintf(fnameout,"%s%s%s", + fnameout_pfx[chtype], + pcode->name, + fnameout_sfx[ap_index]); + + fout = fopen(fnameout,"w"); + fprintf(fout,"# Channel (0=AWGN,1=Rayleigh), Eb/No (dB), Transmitted codewords, Errors, Undetected Errors, Avg dec. time (ms), WER\n"); + + printf("\nTesting the code %s over the %s channel\nSimulation data will be saved to %s\n", + pcode->name, + chtype==CHANNEL_AWGN?"AWGN":"Rayleigh", + fnameout); + fflush (stdout); + + // init fixed thread parameters and preallocate buffers + for (j=0;jK*sizeof(int)); + wt[j].y = (int*)malloc(pcode->N*sizeof(int)); + wt[j].ydec = (int*)malloc(pcode->N*sizeof(int)); + wt[j].qra_v2cmsg = (float*)malloc(pcode->NMSG*pcode->M*sizeof(float)); + wt[j].qra_c2vmsg = (float*)malloc(pcode->NMSG*pcode->M*sizeof(float)); + wt[j].rp = (float*)malloc(pcode->N*pcode->M*sizeof(float)); + wt[j].rq = (float*)malloc(pcode->N*pcode->M*sizeof(float)); + wt[j].chp = (float*)malloc(pcode->N*sizeof(float)); + wt[j].chq = (float*)malloc(pcode->N*sizeof(float)); + wt[j].r = (float*)malloc(pcode->N*pcode->M*sizeof(float)); + wt[j].ix = (float*)malloc(pcode->N*pcode->M*sizeof(float)); + wt[j].ex = (float*)malloc(pcode->N*pcode->M*sizeof(float)); + } + + + for (k=0;k=nerrstgt[k]) { + for (j=0;j] [-t] [-c] [-a] [-f[-h]\n"); + printf("Options: \n"); + printf(" -q: code to simulate. 0=qra_12_63_64_irr_b\n"); + printf(" 1=qra_13_64_64_irr_e (default)\n"); + printf(" -t : number of threads to be used for the simulation [1..24]\n"); + printf(" (default=8)\n"); + printf(" -c : channel_type. 0=AWGN 1=Rayleigh \n"); + printf(" (default=AWGN)\n"); + printf(" -a : amount of a-priori information provided to decoder. \n"); + printf(" 0= No a-priori (default)\n"); + printf(" 1= 28 bit \n"); + printf(" 2= 44 bit \n"); + printf(" 3= 56 bit \n"); + printf(" -f : name of the file containing the Eb/No values to be simulated\n"); + printf(" (default=ebnovalues.txt)\n"); + printf(" This file should contain lines in this format:\n"); + printf(" # Eb/No(dB) Target Errors\n"); + printf(" 0.1 5000\n"); + printf(" 0.6 5000\n"); + printf(" 1.1 1000\n"); + printf(" 1.6 1000\n"); + printf(" ...\n"); + printf(" (lines beginning with a # are treated as comments\n\n"); +} + +#define SIM_POINTS_MAX 20 + +int main(int argc, char* argv[]) +{ + + float EbNodB[SIM_POINTS_MAX]; + int nerrstgt[SIM_POINTS_MAX]; + FILE *fin; + + char fnamein[128]= "ebnovalues.txt"; + char buf[128]; + + int nitems = 0; + int code_idx = 1; + int nthreads = 8; + int ch_type = CHANNEL_AWGN; + int ap_index = AP_NONE; + + // parse command line + while(--argc) { + argv++; + if (strncmp(*argv,"-h",2)==0) { + syntax(); + return 0; + } + else + if (strncmp(*argv,"-q",2)==0) { + code_idx = (int)atoi((*argv)+2); + if (code_idx>1) { + printf("Invalid code index\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-t",2)==0) { + nthreads = (int)atoi((*argv)+2); + printf("nthreads = %d\n",nthreads); + if (nthreads>NTHREADS_MAX) { + printf("Invalid number of threads\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-c",2)==0) { + ch_type = (int)atoi((*argv)+2); + if (ch_type>CHANNEL_RAYLEIGH) { + printf("Invalid channel type\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-a",2)==0) { + ap_index = (int)atoi((*argv)+2); + if (ap_index>AP_56) { + printf("Invalid a-priori information index\n"); + syntax(); + return -1; + } + } + else + if (strncmp(*argv,"-f",2)==0) { + strncpy(fnamein,(*argv)+2,127); + } + else + if (strncmp(*argv,"-h",2)==0) { + syntax(); + return -1; + } + else { + printf("Invalid option\n"); + syntax(); + return -1; + } + } + + // parse points to be simulated from the input file + fin = fopen(fnamein,"r"); + if (!fin) { + printf("Can't open file: %s\n",fnamein); + syntax(); + } + + while (fgets(buf,128,fin)!=0) + if (*buf=='#' || *buf=='\n' ) + continue; + else + if (nitems==SIM_POINTS_MAX) + break; + else + if (sscanf(buf,"%f %u",&EbNodB[nitems],&nerrstgt[nitems])!=2) { + printf("Invalid input file format\n"); + syntax(); + return -1; + } + else + nitems++; + + fclose(fin); + + if (nitems==0) { + printf("No Eb/No point specified in file %s\n",fnamein); + syntax(); + return -1; + } + + printf("\nQ-ary Repeat-Accumulate Code Word Error Rate Simulator\n"); + printf("2016, Nico Palermo - IV3NWV\n\n"); + + printf("Nthreads = %d\n",nthreads); + printf("Channel = %s\n",ch_type==CHANNEL_AWGN?"AWGN":"Rayleigh"); + printf("Codename = %s\n",codetotest[code_idx]->name); + printf("A-priori = %s\n",ap_str[ap_index]); + printf("Eb/No input file = %s\n\n",fnamein); + + wer_test_proc(codetotest[code_idx], nthreads, ch_type, ap_index, EbNodB, nerrstgt, nitems); + + return 0; +} + diff --git a/lib/qra/qracodes/normrnd.c b/lib/qra/qracodes/normrnd.c new file mode 100644 index 00000000..90abfa42 --- /dev/null +++ b/lib/qra/qracodes/normrnd.c @@ -0,0 +1,82 @@ +// normrnd.c +// functions to generate gaussian distributed numbers +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// +// Credits to Andrea Montefusco - IW0HDV for his help on adapting the sources +// to OSs other than MS Windows +// +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + + +#include "normrnd.h" + +#if _WIN32 // note the underscore: without it, it's not msdn official! + // Windows (x64 and x86) + #include // required only for GetTickCount(...) + #define K_RAND_MAX UINT_MAX +#elif _SVID_SOURCE || _XOPEN_SOURCE || __unix__ || (defined (__APPLE__) && defined(__MACH__)) /* POSIX or Unix or Apple */ + #include + #define rand_s(x) (*x)=(unsigned int)lrand48() // returns unsigned integers in the range 0..0x7FFFFFFF + #define K_RAND_MAX 0x7FFFFFFF // that's the max number + // generated by lrand48 +#else + #error "No good quality PRNG found" +#endif + + +// use MS rand_s(...) function +void normrnd_s(float *dst, int nitems, float mean, float stdev) +{ + unsigned int r; + float phi=0, u=0; + int set = 0; + + while (nitems--) + if (set==1) { + *dst++ = (float)sin(phi)*u*stdev+mean; + set = 0; + } + else { + rand_s((unsigned int*)&r); phi = (M_2PI/(1.0f+K_RAND_MAX))*r; + rand_s((unsigned int*)&r); u = (float)sqrt(-2.0f* log( (1.0f/(1.0f+K_RAND_MAX))*(1.0f+r) ) ); + *dst++ = (float)cos(phi)*u*stdev+mean; + set=1; + } +} + +/* NOT USED +// use MS rand() function +void normrnd(float *dst, int nitems, float mean, float stdev) +{ + float phi=0, u=0; + int set = 0; + + while (nitems--) + if (set==1) { + *dst++ = (float)sin(phi)*u*stdev+mean; + set = 0; + } + else { + phi = (M_2PI/(1.0f+RAND_MAX))*rand(); + u = (float)sqrt(-2.0f* log( (1.0f/(1.0f+RAND_MAX))*(1.0f+rand()) ) ); + *dst++ = (float)cos(phi)*u*stdev+mean; + set=1; + } +} +*/ diff --git a/lib/qra/qracodes/normrnd.h b/lib/qra/qracodes/normrnd.h new file mode 100644 index 00000000..dd4b65bb --- /dev/null +++ b/lib/qra/qracodes/normrnd.h @@ -0,0 +1,51 @@ +// normrnd.h +// Functions to generate gaussian distributed numbers +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +#ifndef _normrnd_h_ +#define _normrnd_h_ + +#define _CRT_RAND_S +#include + +#define _USE_MATH_DEFINES +#include +#define M_2PI (2.0f*(float)M_PI) + +#ifdef __cplusplus +extern "C" { +#endif + +void normrnd_s(float *dst, int nitems, float mean, float stdev); +// generate a random array of numbers with a gaussian distribution of given mean and stdev +// use MS rand_s(...) function + +/* not used +void normrnd(float *dst, int nitems, float mean, float stdev); +// generate a random array of numbers with a gaussian distribution of given mean and stdev +// use MS rand() function +*/ + +#ifdef __cplusplus +} +#endif + +#endif // _normrnd_h_ + diff --git a/lib/qra/qracodes/npfwht.c b/lib/qra/qracodes/npfwht.c new file mode 100644 index 00000000..5732ce91 --- /dev/null +++ b/lib/qra/qracodes/npfwht.c @@ -0,0 +1,216 @@ +// npfwht.c +// Basic implementation of the Fast Walsh-Hadamard Transforms +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +#include "npfwht.h" + +#define WHBFY(dst,src,base,offs,dist) { dst[base+offs]=src[base+offs]+src[base+offs+dist]; dst[base+offs+dist]=src[base+offs]-src[base+offs+dist]; } + +typedef void (*pnp_fwht)(float*,float*); + +static void np_fwht2(float *dst, float *src); + +static void np_fwht1(float *dst, float *src); +static void np_fwht2(float *dst, float *src); +static void np_fwht4(float *dst, float *src); +static void np_fwht8(float *dst, float *src); +static void np_fwht16(float *dst, float *src); +static void np_fwht32(float *dst, float *src); +static void np_fwht64(float *dst, float *src); + +static pnp_fwht np_fwht_tab[7] = { + np_fwht1, + np_fwht2, + np_fwht4, + np_fwht8, + np_fwht16, + np_fwht32, + np_fwht64 +}; + +void np_fwht(int nlogdim, float *dst, float *src) +{ + np_fwht_tab[nlogdim](dst,src); +} + +static void np_fwht1(float *dst, float *src) +{ + dst[0] = src[0]; +} + + +static void np_fwht2(float *dst, float *src) +{ + float t[2]; + + WHBFY(t,src,0,0,1); + dst[0]= t[0]; + dst[1]= t[1]; +} + +static void np_fwht4(float *dst, float *src) +{ + float t[4]; + + // group 1 + WHBFY(t,src,0,0,2); WHBFY(t,src,0,1,2); + // group 2 + WHBFY(dst,t,0,0,1); WHBFY(dst,t,2,0,1); +}; + + +static void np_fwht8(float *dst, float *src) +{ + float t[16]; + float *t1=t, *t2=t+8; + + // group 1 + WHBFY(t1,src,0,0,4); WHBFY(t1,src,0,1,4); WHBFY(t1,src,0,2,4); WHBFY(t1,src,0,3,4); + // group 2 + WHBFY(t2,t1,0,0,2); WHBFY(t2,t1,0,1,2); WHBFY(t2,t1,4,0,2); WHBFY(t2,t1,4,1,2); + // group 3 + WHBFY(dst,t2,0,0,1); WHBFY(dst,t2,2,0,1); WHBFY(dst,t2,4,0,1); WHBFY(dst,t2,6,0,1); +}; + + +static void np_fwht16(float *dst, float *src) +{ + float t[32]; + float *t1=t, *t2=t+16; + + // group 1 + WHBFY(t1,src,0,0,8); WHBFY(t1,src,0,1,8); WHBFY(t1,src,0,2,8); WHBFY(t1,src,0,3,8); + WHBFY(t1,src,0,4,8); WHBFY(t1,src,0,5,8); WHBFY(t1,src,0,6,8); WHBFY(t1,src,0,7,8); + // group 2 + WHBFY(t2,t1,0,0,4); WHBFY(t2,t1,0,1,4); WHBFY(t2,t1,0,2,4); WHBFY(t2,t1,0,3,4); + WHBFY(t2,t1,8,0,4); WHBFY(t2,t1,8,1,4); WHBFY(t2,t1,8,2,4); WHBFY(t2,t1,8,3,4); + // group 3 + WHBFY(t1,t2,0,0,2); WHBFY(t1,t2,0,1,2); WHBFY(t1,t2,4,0,2); WHBFY(t1,t2,4,1,2); + WHBFY(t1,t2,8,0,2); WHBFY(t1,t2,8,1,2); WHBFY(t1,t2,12,0,2); WHBFY(t1,t2,12,1,2); + // group 4 + WHBFY(dst,t1,0,0,1); WHBFY(dst,t1,2,0,1); WHBFY(dst,t1,4,0,1); WHBFY(dst,t1,6,0,1); + WHBFY(dst,t1,8,0,1); WHBFY(dst,t1,10,0,1); WHBFY(dst,t1,12,0,1); WHBFY(dst,t1,14,0,1); + +} + +static void np_fwht32(float *dst, float *src) +{ + float t[64]; + float *t1=t, *t2=t+32; + + // group 1 + WHBFY(t1,src,0,0,16); WHBFY(t1,src,0,1,16); WHBFY(t1,src,0,2,16); WHBFY(t1,src,0,3,16); + WHBFY(t1,src,0,4,16); WHBFY(t1,src,0,5,16); WHBFY(t1,src,0,6,16); WHBFY(t1,src,0,7,16); + WHBFY(t1,src,0,8,16); WHBFY(t1,src,0,9,16); WHBFY(t1,src,0,10,16); WHBFY(t1,src,0,11,16); + WHBFY(t1,src,0,12,16); WHBFY(t1,src,0,13,16); WHBFY(t1,src,0,14,16); WHBFY(t1,src,0,15,16); + + // group 2 + WHBFY(t2,t1,0,0,8); WHBFY(t2,t1,0,1,8); WHBFY(t2,t1,0,2,8); WHBFY(t2,t1,0,3,8); + WHBFY(t2,t1,0,4,8); WHBFY(t2,t1,0,5,8); WHBFY(t2,t1,0,6,8); WHBFY(t2,t1,0,7,8); + WHBFY(t2,t1,16,0,8); WHBFY(t2,t1,16,1,8); WHBFY(t2,t1,16,2,8); WHBFY(t2,t1,16,3,8); + WHBFY(t2,t1,16,4,8); WHBFY(t2,t1,16,5,8); WHBFY(t2,t1,16,6,8); WHBFY(t2,t1,16,7,8); + + // group 3 + WHBFY(t1,t2,0,0,4); WHBFY(t1,t2,0,1,4); WHBFY(t1,t2,0,2,4); WHBFY(t1,t2,0,3,4); + WHBFY(t1,t2,8,0,4); WHBFY(t1,t2,8,1,4); WHBFY(t1,t2,8,2,4); WHBFY(t1,t2,8,3,4); + WHBFY(t1,t2,16,0,4); WHBFY(t1,t2,16,1,4); WHBFY(t1,t2,16,2,4); WHBFY(t1,t2,16,3,4); + WHBFY(t1,t2,24,0,4); WHBFY(t1,t2,24,1,4); WHBFY(t1,t2,24,2,4); WHBFY(t1,t2,24,3,4); + + // group 4 + WHBFY(t2,t1,0,0,2); WHBFY(t2,t1,0,1,2); WHBFY(t2,t1,4,0,2); WHBFY(t2,t1,4,1,2); + WHBFY(t2,t1,8,0,2); WHBFY(t2,t1,8,1,2); WHBFY(t2,t1,12,0,2); WHBFY(t2,t1,12,1,2); + WHBFY(t2,t1,16,0,2); WHBFY(t2,t1,16,1,2); WHBFY(t2,t1,20,0,2); WHBFY(t2,t1,20,1,2); + WHBFY(t2,t1,24,0,2); WHBFY(t2,t1,24,1,2); WHBFY(t2,t1,28,0,2); WHBFY(t2,t1,28,1,2); + + // group 5 + WHBFY(dst,t2,0,0,1); WHBFY(dst,t2,2,0,1); WHBFY(dst,t2,4,0,1); WHBFY(dst,t2,6,0,1); + WHBFY(dst,t2,8,0,1); WHBFY(dst,t2,10,0,1); WHBFY(dst,t2,12,0,1); WHBFY(dst,t2,14,0,1); + WHBFY(dst,t2,16,0,1); WHBFY(dst,t2,18,0,1); WHBFY(dst,t2,20,0,1); WHBFY(dst,t2,22,0,1); + WHBFY(dst,t2,24,0,1); WHBFY(dst,t2,26,0,1); WHBFY(dst,t2,28,0,1); WHBFY(dst,t2,30,0,1); + +} + +static void np_fwht64(float *dst, float *src) +{ + float t[128]; + float *t1=t, *t2=t+64; + + + // group 1 + WHBFY(t1,src,0,0,32); WHBFY(t1,src,0,1,32); WHBFY(t1,src,0,2,32); WHBFY(t1,src,0,3,32); + WHBFY(t1,src,0,4,32); WHBFY(t1,src,0,5,32); WHBFY(t1,src,0,6,32); WHBFY(t1,src,0,7,32); + WHBFY(t1,src,0,8,32); WHBFY(t1,src,0,9,32); WHBFY(t1,src,0,10,32); WHBFY(t1,src,0,11,32); + WHBFY(t1,src,0,12,32); WHBFY(t1,src,0,13,32); WHBFY(t1,src,0,14,32); WHBFY(t1,src,0,15,32); + WHBFY(t1,src,0,16,32); WHBFY(t1,src,0,17,32); WHBFY(t1,src,0,18,32); WHBFY(t1,src,0,19,32); + WHBFY(t1,src,0,20,32); WHBFY(t1,src,0,21,32); WHBFY(t1,src,0,22,32); WHBFY(t1,src,0,23,32); + WHBFY(t1,src,0,24,32); WHBFY(t1,src,0,25,32); WHBFY(t1,src,0,26,32); WHBFY(t1,src,0,27,32); + WHBFY(t1,src,0,28,32); WHBFY(t1,src,0,29,32); WHBFY(t1,src,0,30,32); WHBFY(t1,src,0,31,32); + + // group 2 + WHBFY(t2,t1,0,0,16); WHBFY(t2,t1,0,1,16); WHBFY(t2,t1,0,2,16); WHBFY(t2,t1,0,3,16); + WHBFY(t2,t1,0,4,16); WHBFY(t2,t1,0,5,16); WHBFY(t2,t1,0,6,16); WHBFY(t2,t1,0,7,16); + WHBFY(t2,t1,0,8,16); WHBFY(t2,t1,0,9,16); WHBFY(t2,t1,0,10,16); WHBFY(t2,t1,0,11,16); + WHBFY(t2,t1,0,12,16); WHBFY(t2,t1,0,13,16); WHBFY(t2,t1,0,14,16); WHBFY(t2,t1,0,15,16); + + WHBFY(t2,t1,32,0,16); WHBFY(t2,t1,32,1,16); WHBFY(t2,t1,32,2,16); WHBFY(t2,t1,32,3,16); + WHBFY(t2,t1,32,4,16); WHBFY(t2,t1,32,5,16); WHBFY(t2,t1,32,6,16); WHBFY(t2,t1,32,7,16); + WHBFY(t2,t1,32,8,16); WHBFY(t2,t1,32,9,16); WHBFY(t2,t1,32,10,16); WHBFY(t2,t1,32,11,16); + WHBFY(t2,t1,32,12,16); WHBFY(t2,t1,32,13,16); WHBFY(t2,t1,32,14,16); WHBFY(t2,t1,32,15,16); + + // group 3 + WHBFY(t1,t2,0,0,8); WHBFY(t1,t2,0,1,8); WHBFY(t1,t2,0,2,8); WHBFY(t1,t2,0,3,8); + WHBFY(t1,t2,0,4,8); WHBFY(t1,t2,0,5,8); WHBFY(t1,t2,0,6,8); WHBFY(t1,t2,0,7,8); + WHBFY(t1,t2,16,0,8); WHBFY(t1,t2,16,1,8); WHBFY(t1,t2,16,2,8); WHBFY(t1,t2,16,3,8); + WHBFY(t1,t2,16,4,8); WHBFY(t1,t2,16,5,8); WHBFY(t1,t2,16,6,8); WHBFY(t1,t2,16,7,8); + WHBFY(t1,t2,32,0,8); WHBFY(t1,t2,32,1,8); WHBFY(t1,t2,32,2,8); WHBFY(t1,t2,32,3,8); + WHBFY(t1,t2,32,4,8); WHBFY(t1,t2,32,5,8); WHBFY(t1,t2,32,6,8); WHBFY(t1,t2,32,7,8); + WHBFY(t1,t2,48,0,8); WHBFY(t1,t2,48,1,8); WHBFY(t1,t2,48,2,8); WHBFY(t1,t2,48,3,8); + WHBFY(t1,t2,48,4,8); WHBFY(t1,t2,48,5,8); WHBFY(t1,t2,48,6,8); WHBFY(t1,t2,48,7,8); + + // group 4 + WHBFY(t2,t1,0,0,4); WHBFY(t2,t1,0,1,4); WHBFY(t2,t1,0,2,4); WHBFY(t2,t1,0,3,4); + WHBFY(t2,t1,8,0,4); WHBFY(t2,t1,8,1,4); WHBFY(t2,t1,8,2,4); WHBFY(t2,t1,8,3,4); + WHBFY(t2,t1,16,0,4); WHBFY(t2,t1,16,1,4); WHBFY(t2,t1,16,2,4); WHBFY(t2,t1,16,3,4); + WHBFY(t2,t1,24,0,4); WHBFY(t2,t1,24,1,4); WHBFY(t2,t1,24,2,4); WHBFY(t2,t1,24,3,4); + WHBFY(t2,t1,32,0,4); WHBFY(t2,t1,32,1,4); WHBFY(t2,t1,32,2,4); WHBFY(t2,t1,32,3,4); + WHBFY(t2,t1,40,0,4); WHBFY(t2,t1,40,1,4); WHBFY(t2,t1,40,2,4); WHBFY(t2,t1,40,3,4); + WHBFY(t2,t1,48,0,4); WHBFY(t2,t1,48,1,4); WHBFY(t2,t1,48,2,4); WHBFY(t2,t1,48,3,4); + WHBFY(t2,t1,56,0,4); WHBFY(t2,t1,56,1,4); WHBFY(t2,t1,56,2,4); WHBFY(t2,t1,56,3,4); + + // group 5 + WHBFY(t1,t2,0,0,2); WHBFY(t1,t2,0,1,2); WHBFY(t1,t2,4,0,2); WHBFY(t1,t2,4,1,2); + WHBFY(t1,t2,8,0,2); WHBFY(t1,t2,8,1,2); WHBFY(t1,t2,12,0,2); WHBFY(t1,t2,12,1,2); + WHBFY(t1,t2,16,0,2); WHBFY(t1,t2,16,1,2); WHBFY(t1,t2,20,0,2); WHBFY(t1,t2,20,1,2); + WHBFY(t1,t2,24,0,2); WHBFY(t1,t2,24,1,2); WHBFY(t1,t2,28,0,2); WHBFY(t1,t2,28,1,2); + WHBFY(t1,t2,32,0,2); WHBFY(t1,t2,32,1,2); WHBFY(t1,t2,36,0,2); WHBFY(t1,t2,36,1,2); + WHBFY(t1,t2,40,0,2); WHBFY(t1,t2,40,1,2); WHBFY(t1,t2,44,0,2); WHBFY(t1,t2,44,1,2); + WHBFY(t1,t2,48,0,2); WHBFY(t1,t2,48,1,2); WHBFY(t1,t2,52,0,2); WHBFY(t1,t2,52,1,2); + WHBFY(t1,t2,56,0,2); WHBFY(t1,t2,56,1,2); WHBFY(t1,t2,60,0,2); WHBFY(t1,t2,60,1,2); + + // group 6 + WHBFY(dst,t1,0,0,1); WHBFY(dst,t1,2,0,1); WHBFY(dst,t1,4,0,1); WHBFY(dst,t1,6,0,1); + WHBFY(dst,t1,8,0,1); WHBFY(dst,t1,10,0,1); WHBFY(dst,t1,12,0,1); WHBFY(dst,t1,14,0,1); + WHBFY(dst,t1,16,0,1); WHBFY(dst,t1,18,0,1); WHBFY(dst,t1,20,0,1); WHBFY(dst,t1,22,0,1); + WHBFY(dst,t1,24,0,1); WHBFY(dst,t1,26,0,1); WHBFY(dst,t1,28,0,1); WHBFY(dst,t1,30,0,1); + WHBFY(dst,t1,32,0,1); WHBFY(dst,t1,34,0,1); WHBFY(dst,t1,36,0,1); WHBFY(dst,t1,38,0,1); + WHBFY(dst,t1,40,0,1); WHBFY(dst,t1,42,0,1); WHBFY(dst,t1,44,0,1); WHBFY(dst,t1,46,0,1); + WHBFY(dst,t1,48,0,1); WHBFY(dst,t1,50,0,1); WHBFY(dst,t1,52,0,1); WHBFY(dst,t1,54,0,1); + WHBFY(dst,t1,56,0,1); WHBFY(dst,t1,58,0,1); WHBFY(dst,t1,60,0,1); WHBFY(dst,t1,62,0,1); +} \ No newline at end of file diff --git a/lib/qra/qracodes/npfwht.h b/lib/qra/qracodes/npfwht.h new file mode 100644 index 00000000..9452e207 --- /dev/null +++ b/lib/qra/qracodes/npfwht.h @@ -0,0 +1,45 @@ +// np_fwht.h +// Basic implementation of the Fast Walsh-Hadamard Transforms +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +#ifndef _npfwht_h_ +#define _npfwht_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +void np_fwht(int nlogdim, float *dst, float *src); +// Compute the Walsh-Hadamard transform of the given data up to a +// 64-dimensional transform +// +// Input parameters: +// nlogdim: log2 of the transform size. Must be in the range [0..6] +// src : pointer to the input data buffer. +// dst : pointer to the output data buffer. +// +// src and dst must point to preallocated data buffers of size 2^nlogdim*sizeof(float) +// src and dst buffers can overlap + +#ifdef __cplusplus +} +#endif + +#endif // _npfwht_ diff --git a/lib/qra/qracodes/pdmath.c b/lib/qra/qracodes/pdmath.c new file mode 100644 index 00000000..47ecab91 --- /dev/null +++ b/lib/qra/qracodes/pdmath.c @@ -0,0 +1,385 @@ +// pdmath.c +// Elementary math on probability distributions +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +#include "pdmath.h" + +typedef const float *ppd_uniform; +typedef void (*ppd_imul)(float*,const float*); +typedef float (*ppd_norm)(float*); + +// define vector size in function of its logarithm in base 2 +static const int pd_log2dim[7] = { + 1,2,4,8,16,32,64 +}; + +// define uniform distributions of given size +static const float pd_uniform1[1] = { + 1. +}; +static const float pd_uniform2[2] = { + 1./2., 1./2. +}; +static const float pd_uniform4[4] = { + 1./4., 1./4.,1./4., 1./4. +}; +static const float pd_uniform8[8] = { + 1./8., 1./8.,1./8., 1./8.,1./8., 1./8.,1./8., 1./8. +}; +static const float pd_uniform16[16] = { + 1./16., 1./16., 1./16., 1./16.,1./16., 1./16.,1./16., 1./16., + 1./16., 1./16., 1./16., 1./16.,1./16., 1./16.,1./16., 1./16. +}; +static const float pd_uniform32[32] = { + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32., + 1./32., 1./32., 1./32., 1./32.,1./32., 1./32.,1./32., 1./32. +}; +static const float pd_uniform64[64] = { + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64., + 1./64., 1./64., 1./64., 1./64.,1./64., 1./64.,1./64., 1./64. + +}; + +static const ppd_uniform pd_uniform_tab[7] = { + pd_uniform1, + pd_uniform2, + pd_uniform4, + pd_uniform8, + pd_uniform16, + pd_uniform32, + pd_uniform64 +}; + +// returns a pointer to the uniform distribution of the given logsize +const float *pd_uniform(int nlogdim) +{ + return pd_uniform_tab[nlogdim]; +} + +// in-place multiplication functions +// compute dst = dst*src for any element of the distrib + +static void pd_imul1(float *dst, const float *src) +{ + dst[0] *= src[0]; +} + +static void pd_imul2(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; +} +static void pd_imul4(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; + dst[2] *= src[2]; dst[3] *= src[3]; +} +static void pd_imul8(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; dst[2] *= src[2]; dst[3] *= src[3]; + dst[4] *= src[4]; dst[5] *= src[5]; dst[6] *= src[6]; dst[7] *= src[7]; +} +static void pd_imul16(float *dst, const float *src) +{ + dst[0] *= src[0]; dst[1] *= src[1]; dst[2] *= src[2]; dst[3] *= src[3]; + dst[4] *= src[4]; dst[5] *= src[5]; dst[6] *= src[6]; dst[7] *= src[7]; + dst[8] *= src[8]; dst[9] *= src[9]; dst[10]*= src[10]; dst[11]*= src[11]; + dst[12]*= src[12]; dst[13]*= src[13]; dst[14]*= src[14]; dst[15]*= src[15]; +} +static void pd_imul32(float *dst, const float *src) +{ + pd_imul16(dst,src); + pd_imul16(dst+16,src+16); +} +static void pd_imul64(float *dst, const float *src) +{ + pd_imul16(dst, src); + pd_imul16(dst+16, src+16); + pd_imul16(dst+32, src+32); + pd_imul16(dst+48, src+48); +} + +static const ppd_imul pd_imul_tab[7] = { + pd_imul1, + pd_imul2, + pd_imul4, + pd_imul8, + pd_imul16, + pd_imul32, + pd_imul64 +}; + +// in place multiplication +// compute dst = dst*src for any element of the distrib give their log2 size +// arguments must be pointers to array of floats of the given size +void pd_imul(float *dst, const float *src, int nlogdim) +{ + pd_imul_tab[nlogdim](dst,src); +} + +static float pd_norm1(float *ppd) +{ + float t = ppd[0]; + ppd[0] = 1.f; + return t; +} + +static float pd_norm2(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; + + if (t<=0) { + pd_init(ppd,pd_uniform(1),pd_log2dim[1]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; + return to; + +} + +static float pd_norm4(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + + if (t<=0) { + pd_init(ppd,pd_uniform(2),pd_log2dim[2]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + return to; +} + +static float pd_norm8(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + + if (t<=0) { + pd_init(ppd,pd_uniform(3),pd_log2dim[3]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + return to; +} +static float pd_norm16(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; + t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; + + if (t<=0) { + pd_init(ppd,pd_uniform(4),pd_log2dim[4]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; + ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; + + return to; +} +static float pd_norm32(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; + t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; + t +=ppd[16]; t +=ppd[17]; t +=ppd[18]; t +=ppd[19]; + t +=ppd[20]; t +=ppd[21]; t +=ppd[22]; t +=ppd[23]; + t +=ppd[24]; t +=ppd[25]; t +=ppd[26]; t +=ppd[27]; + t +=ppd[28]; t +=ppd[29]; t +=ppd[30]; t +=ppd[31]; + + if (t<=0) { + pd_init(ppd,pd_uniform(5),pd_log2dim[5]); + return t; + } + + to = t; + t = 1.f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; + ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; + ppd[16] *=t; ppd[17] *=t; ppd[18] *=t; ppd[19] *=t; + ppd[20] *=t; ppd[21] *=t; ppd[22] *=t; ppd[23] *=t; + ppd[24] *=t; ppd[25] *=t; ppd[26] *=t; ppd[27] *=t; + ppd[28] *=t; ppd[29] *=t; ppd[30] *=t; ppd[31] *=t; + + return to; +} + +static float pd_norm64(float *ppd) +{ + float t,to; + + t =ppd[0]; t +=ppd[1]; t +=ppd[2]; t +=ppd[3]; + t +=ppd[4]; t +=ppd[5]; t +=ppd[6]; t +=ppd[7]; + t +=ppd[8]; t +=ppd[9]; t +=ppd[10]; t +=ppd[11]; + t +=ppd[12]; t +=ppd[13]; t +=ppd[14]; t +=ppd[15]; + t +=ppd[16]; t +=ppd[17]; t +=ppd[18]; t +=ppd[19]; + t +=ppd[20]; t +=ppd[21]; t +=ppd[22]; t +=ppd[23]; + t +=ppd[24]; t +=ppd[25]; t +=ppd[26]; t +=ppd[27]; + t +=ppd[28]; t +=ppd[29]; t +=ppd[30]; t +=ppd[31]; + + t +=ppd[32]; t +=ppd[33]; t +=ppd[34]; t +=ppd[35]; + t +=ppd[36]; t +=ppd[37]; t +=ppd[38]; t +=ppd[39]; + t +=ppd[40]; t +=ppd[41]; t +=ppd[42]; t +=ppd[43]; + t +=ppd[44]; t +=ppd[45]; t +=ppd[46]; t +=ppd[47]; + t +=ppd[48]; t +=ppd[49]; t +=ppd[50]; t +=ppd[51]; + t +=ppd[52]; t +=ppd[53]; t +=ppd[54]; t +=ppd[55]; + t +=ppd[56]; t +=ppd[57]; t +=ppd[58]; t +=ppd[59]; + t +=ppd[60]; t +=ppd[61]; t +=ppd[62]; t +=ppd[63]; + + if (t<=0) { + pd_init(ppd,pd_uniform(6),pd_log2dim[6]); + return t; + } + + to = t; + t = 1.0f/t; + ppd[0] *=t; ppd[1] *=t; ppd[2] *=t; ppd[3] *=t; + ppd[4] *=t; ppd[5] *=t; ppd[6] *=t; ppd[7] *=t; + ppd[8] *=t; ppd[9] *=t; ppd[10] *=t; ppd[11] *=t; + ppd[12] *=t; ppd[13] *=t; ppd[14] *=t; ppd[15] *=t; + ppd[16] *=t; ppd[17] *=t; ppd[18] *=t; ppd[19] *=t; + ppd[20] *=t; ppd[21] *=t; ppd[22] *=t; ppd[23] *=t; + ppd[24] *=t; ppd[25] *=t; ppd[26] *=t; ppd[27] *=t; + ppd[28] *=t; ppd[29] *=t; ppd[30] *=t; ppd[31] *=t; + + ppd[32] *=t; ppd[33] *=t; ppd[34] *=t; ppd[35] *=t; + ppd[36] *=t; ppd[37] *=t; ppd[38] *=t; ppd[39] *=t; + ppd[40] *=t; ppd[41] *=t; ppd[42] *=t; ppd[43] *=t; + ppd[44] *=t; ppd[45] *=t; ppd[46] *=t; ppd[47] *=t; + ppd[48] *=t; ppd[49] *=t; ppd[50] *=t; ppd[51] *=t; + ppd[52] *=t; ppd[53] *=t; ppd[54] *=t; ppd[55] *=t; + ppd[56] *=t; ppd[57] *=t; ppd[58] *=t; ppd[59] *=t; + ppd[60] *=t; ppd[61] *=t; ppd[62] *=t; ppd[63] *=t; + + return to; +} + + +static const ppd_norm pd_norm_tab[7] = { + pd_norm1, + pd_norm2, + pd_norm4, + pd_norm8, + pd_norm16, + pd_norm32, + pd_norm64 +}; + +float pd_norm(float *pd, int nlogdim) +{ + return pd_norm_tab[nlogdim](pd); +} + +void pd_memset(float *dst, const float *src, int ndim, int nitems) +{ + int size = PD_SIZE(ndim); + while(nitems--) { + memcpy(dst,src,size); + dst +=ndim; + } +} + +void pd_fwdperm(float *dst, float *src, const int *perm, int ndim) +{ + // TODO: non-loop implementation + while (ndim--) + dst[ndim] = src[perm[ndim]]; +} + +void pd_bwdperm(float *dst, float *src, const int *perm, int ndim) +{ + // TODO: non-loop implementation + while (ndim--) + dst[perm[ndim]] = src[ndim]; +} + +float pd_max(float *src, int ndim) +{ + // TODO: faster implementation + + float cmax=0; // we assume that prob distributions are always positive + float cval; + + while (ndim--) { + cval = src[ndim]; + if (cval>=cmax) { + cmax = cval; + } + } + + return cmax; +} + +int pd_argmax(float *pmax, float *src, int ndim) +{ + // TODO: faster implementation + + float cmax=0; // we assume that prob distributions are always positive + float cval; + int idxmax=-1; // indicates that all pd elements are <0 + + while (ndim--) { + cval = src[ndim]; + if (cval>=cmax) { + cmax = cval; + idxmax = ndim; + } + } + + if (pmax) + *pmax = cmax; + + return idxmax; +} diff --git a/lib/qra/qracodes/pdmath.h b/lib/qra/qracodes/pdmath.h new file mode 100644 index 00000000..bbd1210c --- /dev/null +++ b/lib/qra/qracodes/pdmath.h @@ -0,0 +1,85 @@ +// pdmath.h +// Elementary math on probability distributions +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (repeat and accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + + +#ifndef _pdmath_h_ +#define _pdmath_h_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PD_NDIM(nlogdim) ((1<<(nlogdim)) +#define PD_SIZE(ndim) ((ndim)*sizeof(float)) +#define PD_ROWADDR(fp,ndim,idx) (fp+((ndim)*(idx))) + +const float *pd_uniform(int nlogdim); +// Returns a pointer to a (constant) uniform distribution of the given log2 size + +#define pd_init(dst,src,ndim) memcpy(dst,src,PD_SIZE(ndim)) +// Distribution copy + +void pd_memset(float *dst, const float *src, int ndim, int nitems); +// Copy the distribution pointed by src to the array of distributions dst +// src is a pointer to the input distribution (a vector of size ndim) +// dst is a pointer to a linear array of distributions (a vector of size ndim*nitems) + +void pd_imul(float *dst, const float *src, int nlogdim); +// In place multiplication +// Compute dst = dst*src for any element of the distrib give their log2 size +// src and dst arguments must be pointers to array of floats of the given size + +float pd_norm(float *pd, int nlogdim); +// In place normalizazion +// Normalizes the input vector so that the sum of its components are one +// pd must be a pointer to an array of floats of the given size. +// If the norm of the input vector is non-positive the vector components +// are replaced with a uniform distribution +// Returns the norm of the distribution prior to the normalization + +void pd_fwdperm(float *dst, float *src, const int *perm, int ndim); +// Forward permutation of a distribution +// Computes dst[k] = src[perm[k]] for every element in the distribution +// perm must be a pointer to an array of integers of length ndim + +void pd_bwdperm(float *dst, float *src, const int *perm, int ndim); +// Backward permutation of a distribution +// Computes dst[perm[k]] = src[k] for every element in the distribution +// perm must be a pointer to an array of integers of length ndim + +float pd_max(float *src, int ndim); +// Return the maximum of the elements of the given distribution +// Assumes that the input vector is a probability distribution and that each element in the +// distribution is non negative + +int pd_argmax(float *pmax, float *src, int ndim); +// Return the index of the maximum element of the given distribution +// The maximum is stored in the variable pointed by pmax if pmax is not null +// Same note of pd_max applies. +// Return -1 if all the elements in the distribution are negative + +#ifdef __cplusplus +} +#endif + +#endif // _pdmath_h_ diff --git a/lib/qra/qracodes/qra12_63_64_irr_b.c b/lib/qra/qracodes/qra12_63_64_irr_b.c new file mode 100644 index 00000000..d69443b8 --- /dev/null +++ b/lib/qra/qracodes/qra12_63_64_irr_b.c @@ -0,0 +1,534 @@ +// qra12_63_64_irr_b.c +// Encoding/Decoding tables for Q-ary RA code (12,63) over GF(64) +// Code Name: qra12_63_64_irr_b +// (12,63) RA Code over GF(64) - RF=333344455567 + +// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy + +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +#include "qra12_63_64_irr_b.h" + +#define qra_K 12 // number of information symbols +#define qra_N 63 // codeword length in symbols +#define qra_m 6 // bits/symbol +#define qra_M 64 // Symbol alphabet cardinality +#define qra_a 1 // grouping factor +#define qra_NC 51 // number of check symbols (N-K) + +// Defines used by the message passing decoder -------- + +#define qra_V 63 // number of variables in the code graph (N) +#define qra_C 115 // number of factors in the code graph (N +(N-K)+1) +#define qra_NMSG 217 // number of msgs in the code graph +#define qra_MAXVDEG 8 // maximum variable degree +#define qra_MAXCDEG 3 // maximum factor degree +#define qra_R 0.19048f // code rate (K/N) +#define CODE_NAME "qra_12_63_64_irr_b" + + +// table of the systematic symbols indexes in the accumulator chain +static const int qra_acc_input_idx[qra_NC+1] = { + 3, 11, 0, 1, 7, 8, 6, 5, 10, 4, + 11, 9, 0, 2, 6, 7, 8, 4, 11, 5, + 10, 2, 1, 9, 3, 8, 4, 11, 5, 7, + 10, 9, 6, 3, 11, 5, 8, 10, 0, 7, + 9, 11, 4, 2, 10, 6, 8, 1, 9, 7, + 11, 10 +}; + +// table of the systematic symbols weight logarithms over GF(M) +static const int qra_acc_input_wlog[qra_NC+1] = { + 39, 0, 34, 16, 25, 0, 34, 48, 19, 13, + 29, 56, 0, 5, 39, 42, 31, 0, 10, 0, + 57, 62, 33, 43, 0, 14, 22, 48, 28, 20, + 5, 45, 16, 43, 17, 4, 32, 0, 31, 0, + 0, 28, 57, 0, 18, 0, 60, 0, 10, 31, + 57, 27 +}; + +// table of the logarithms of the elements of GF(M) (log(0) never used) +static const int qra_log[qra_M] = { + -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, + 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, + 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, + 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, + 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, + 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, + 20, 59, 57, 58 +}; + +// table of GF(M) elements given their logarithm +static const int qra_exp[qra_M-1] = { + 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, + 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, + 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, + 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, + 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, + 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, + 57, 49, 33 +}; + +// table of the messages weight logarithms over GF(M) +static const int qra_msgw[qra_NMSG] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 39, 0, 34, 16, 25, 0, 34, + 48, 19, 13, 29, 56, 0, 5, 39, 42, 31, + 0, 10, 0, 57, 62, 33, 43, 0, 14, 22, + 48, 28, 20, 5, 45, 16, 43, 17, 4, 32, + 0, 31, 0, 0, 28, 57, 0, 18, 0, 60, + 0, 10, 31, 57, 27, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0 +}; + +// table of the degrees of the variable nodes +static const int qra_vdeg[qra_V] = { + 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, + 7, 8, 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 +}; + +// table of the degrees of the factor nodes +static const int qra_cdeg[qra_C] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 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, 2 +}; + +// table (uncompressed) of the v->c message indexes (-1=unused entry) +static const int qra_v2cmidx[qra_V*qra_MAXVDEG] = { + 0, 65, 75, 101, -1, -1, -1, -1, + 1, 66, 85, 110, -1, -1, -1, -1, + 2, 76, 84, 106, -1, -1, -1, -1, + 3, 63, 87, 96, -1, -1, -1, -1, + 4, 72, 80, 89, 105, -1, -1, -1, + 5, 70, 82, 91, 98, -1, -1, -1, + 6, 69, 77, 95, 108, -1, -1, -1, + 7, 67, 78, 92, 102, 112, -1, -1, + 8, 68, 79, 88, 99, 109, -1, -1, + 9, 74, 86, 94, 103, 111, -1, -1, + 10, 71, 83, 93, 100, 107, 114, -1, + 11, 64, 73, 81, 90, 97, 104, 113, + 12, 115, 116, -1, -1, -1, -1, -1, + 13, 117, 118, -1, -1, -1, -1, -1, + 14, 119, 120, -1, -1, -1, -1, -1, + 15, 121, 122, -1, -1, -1, -1, -1, + 16, 123, 124, -1, -1, -1, -1, -1, + 17, 125, 126, -1, -1, -1, -1, -1, + 18, 127, 128, -1, -1, -1, -1, -1, + 19, 129, 130, -1, -1, -1, -1, -1, + 20, 131, 132, -1, -1, -1, -1, -1, + 21, 133, 134, -1, -1, -1, -1, -1, + 22, 135, 136, -1, -1, -1, -1, -1, + 23, 137, 138, -1, -1, -1, -1, -1, + 24, 139, 140, -1, -1, -1, -1, -1, + 25, 141, 142, -1, -1, -1, -1, -1, + 26, 143, 144, -1, -1, -1, -1, -1, + 27, 145, 146, -1, -1, -1, -1, -1, + 28, 147, 148, -1, -1, -1, -1, -1, + 29, 149, 150, -1, -1, -1, -1, -1, + 30, 151, 152, -1, -1, -1, -1, -1, + 31, 153, 154, -1, -1, -1, -1, -1, + 32, 155, 156, -1, -1, -1, -1, -1, + 33, 157, 158, -1, -1, -1, -1, -1, + 34, 159, 160, -1, -1, -1, -1, -1, + 35, 161, 162, -1, -1, -1, -1, -1, + 36, 163, 164, -1, -1, -1, -1, -1, + 37, 165, 166, -1, -1, -1, -1, -1, + 38, 167, 168, -1, -1, -1, -1, -1, + 39, 169, 170, -1, -1, -1, -1, -1, + 40, 171, 172, -1, -1, -1, -1, -1, + 41, 173, 174, -1, -1, -1, -1, -1, + 42, 175, 176, -1, -1, -1, -1, -1, + 43, 177, 178, -1, -1, -1, -1, -1, + 44, 179, 180, -1, -1, -1, -1, -1, + 45, 181, 182, -1, -1, -1, -1, -1, + 46, 183, 184, -1, -1, -1, -1, -1, + 47, 185, 186, -1, -1, -1, -1, -1, + 48, 187, 188, -1, -1, -1, -1, -1, + 49, 189, 190, -1, -1, -1, -1, -1, + 50, 191, 192, -1, -1, -1, -1, -1, + 51, 193, 194, -1, -1, -1, -1, -1, + 52, 195, 196, -1, -1, -1, -1, -1, + 53, 197, 198, -1, -1, -1, -1, -1, + 54, 199, 200, -1, -1, -1, -1, -1, + 55, 201, 202, -1, -1, -1, -1, -1, + 56, 203, 204, -1, -1, -1, -1, -1, + 57, 205, 206, -1, -1, -1, -1, -1, + 58, 207, 208, -1, -1, -1, -1, -1, + 59, 209, 210, -1, -1, -1, -1, -1, + 60, 211, 212, -1, -1, -1, -1, -1, + 61, 213, 214, -1, -1, -1, -1, -1, + 62, 215, 216, -1, -1, -1, -1, -1 +}; + +// table (uncompressed) of the c->v message indexes (-1=unused entry) +static const int qra_c2vmidx[qra_C*qra_MAXCDEG] = { + 0, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1, + 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1, + 8, -1, -1, 9, -1, -1, 10, -1, -1, 11, -1, -1, + 12, -1, -1, 13, -1, -1, 14, -1, -1, 15, -1, -1, + 16, -1, -1, 17, -1, -1, 18, -1, -1, 19, -1, -1, + 20, -1, -1, 21, -1, -1, 22, -1, -1, 23, -1, -1, + 24, -1, -1, 25, -1, -1, 26, -1, -1, 27, -1, -1, + 28, -1, -1, 29, -1, -1, 30, -1, -1, 31, -1, -1, + 32, -1, -1, 33, -1, -1, 34, -1, -1, 35, -1, -1, + 36, -1, -1, 37, -1, -1, 38, -1, -1, 39, -1, -1, + 40, -1, -1, 41, -1, -1, 42, -1, -1, 43, -1, -1, + 44, -1, -1, 45, -1, -1, 46, -1, -1, 47, -1, -1, + 48, -1, -1, 49, -1, -1, 50, -1, -1, 51, -1, -1, + 52, -1, -1, 53, -1, -1, 54, -1, -1, 55, -1, -1, + 56, -1, -1, 57, -1, -1, 58, -1, -1, 59, -1, -1, + 60, -1, -1, 61, -1, -1, 62, -1, -1, 63, 115, -1, + 64, 116, 117, 65, 118, 119, 66, 120, 121, 67, 122, 123, + 68, 124, 125, 69, 126, 127, 70, 128, 129, 71, 130, 131, + 72, 132, 133, 73, 134, 135, 74, 136, 137, 75, 138, 139, + 76, 140, 141, 77, 142, 143, 78, 144, 145, 79, 146, 147, + 80, 148, 149, 81, 150, 151, 82, 152, 153, 83, 154, 155, + 84, 156, 157, 85, 158, 159, 86, 160, 161, 87, 162, 163, + 88, 164, 165, 89, 166, 167, 90, 168, 169, 91, 170, 171, + 92, 172, 173, 93, 174, 175, 94, 176, 177, 95, 178, 179, + 96, 180, 181, 97, 182, 183, 98, 184, 185, 99, 186, 187, +100, 188, 189, 101, 190, 191, 102, 192, 193, 103, 194, 195, +104, 196, 197, 105, 198, 199, 106, 200, 201, 107, 202, 203, +108, 204, 205, 109, 206, 207, 110, 208, 209, 111, 210, 211, +112, 212, 213, 113, 214, 215, 114, 216, -1 +}; + +// permutation matrix to compute Prob(x*alfa^logw) +static const int qra_pmat[qra_M*qra_M] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 33, 1, 32, 2, 35, 3, 34, 4, 37, 5, 36, 6, 39, 7, 38, + 8, 41, 9, 40, 10, 43, 11, 42, 12, 45, 13, 44, 14, 47, 15, 46, + 16, 49, 17, 48, 18, 51, 19, 50, 20, 53, 21, 52, 22, 55, 23, 54, + 24, 57, 25, 56, 26, 59, 27, 58, 28, 61, 29, 60, 30, 63, 31, 62, + 0, 49, 33, 16, 1, 48, 32, 17, 2, 51, 35, 18, 3, 50, 34, 19, + 4, 53, 37, 20, 5, 52, 36, 21, 6, 55, 39, 22, 7, 54, 38, 23, + 8, 57, 41, 24, 9, 56, 40, 25, 10, 59, 43, 26, 11, 58, 42, 27, + 12, 61, 45, 28, 13, 60, 44, 29, 14, 63, 47, 30, 15, 62, 46, 31, + 0, 57, 49, 8, 33, 24, 16, 41, 1, 56, 48, 9, 32, 25, 17, 40, + 2, 59, 51, 10, 35, 26, 18, 43, 3, 58, 50, 11, 34, 27, 19, 42, + 4, 61, 53, 12, 37, 28, 20, 45, 5, 60, 52, 13, 36, 29, 21, 44, + 6, 63, 55, 14, 39, 30, 22, 47, 7, 62, 54, 15, 38, 31, 23, 46, + 0, 61, 57, 4, 49, 12, 8, 53, 33, 28, 24, 37, 16, 45, 41, 20, + 1, 60, 56, 5, 48, 13, 9, 52, 32, 29, 25, 36, 17, 44, 40, 21, + 2, 63, 59, 6, 51, 14, 10, 55, 35, 30, 26, 39, 18, 47, 43, 22, + 3, 62, 58, 7, 50, 15, 11, 54, 34, 31, 27, 38, 19, 46, 42, 23, + 0, 63, 61, 2, 57, 6, 4, 59, 49, 14, 12, 51, 8, 55, 53, 10, + 33, 30, 28, 35, 24, 39, 37, 26, 16, 47, 45, 18, 41, 22, 20, 43, + 1, 62, 60, 3, 56, 7, 5, 58, 48, 15, 13, 50, 9, 54, 52, 11, + 32, 31, 29, 34, 25, 38, 36, 27, 17, 46, 44, 19, 40, 23, 21, 42, + 0, 62, 63, 1, 61, 3, 2, 60, 57, 7, 6, 56, 4, 58, 59, 5, + 49, 15, 14, 48, 12, 50, 51, 13, 8, 54, 55, 9, 53, 11, 10, 52, + 33, 31, 30, 32, 28, 34, 35, 29, 24, 38, 39, 25, 37, 27, 26, 36, + 16, 46, 47, 17, 45, 19, 18, 44, 41, 23, 22, 40, 20, 42, 43, 21, + 0, 31, 62, 33, 63, 32, 1, 30, 61, 34, 3, 28, 2, 29, 60, 35, + 57, 38, 7, 24, 6, 25, 56, 39, 4, 27, 58, 37, 59, 36, 5, 26, + 49, 46, 15, 16, 14, 17, 48, 47, 12, 19, 50, 45, 51, 44, 13, 18, + 8, 23, 54, 41, 55, 40, 9, 22, 53, 42, 11, 20, 10, 21, 52, 43, + 0, 46, 31, 49, 62, 16, 33, 15, 63, 17, 32, 14, 1, 47, 30, 48, + 61, 19, 34, 12, 3, 45, 28, 50, 2, 44, 29, 51, 60, 18, 35, 13, + 57, 23, 38, 8, 7, 41, 24, 54, 6, 40, 25, 55, 56, 22, 39, 9, + 4, 42, 27, 53, 58, 20, 37, 11, 59, 21, 36, 10, 5, 43, 26, 52, + 0, 23, 46, 57, 31, 8, 49, 38, 62, 41, 16, 7, 33, 54, 15, 24, + 63, 40, 17, 6, 32, 55, 14, 25, 1, 22, 47, 56, 30, 9, 48, 39, + 61, 42, 19, 4, 34, 53, 12, 27, 3, 20, 45, 58, 28, 11, 50, 37, + 2, 21, 44, 59, 29, 10, 51, 36, 60, 43, 18, 5, 35, 52, 13, 26, + 0, 42, 23, 61, 46, 4, 57, 19, 31, 53, 8, 34, 49, 27, 38, 12, + 62, 20, 41, 3, 16, 58, 7, 45, 33, 11, 54, 28, 15, 37, 24, 50, + 63, 21, 40, 2, 17, 59, 6, 44, 32, 10, 55, 29, 14, 36, 25, 51, + 1, 43, 22, 60, 47, 5, 56, 18, 30, 52, 9, 35, 48, 26, 39, 13, + 0, 21, 42, 63, 23, 2, 61, 40, 46, 59, 4, 17, 57, 44, 19, 6, + 31, 10, 53, 32, 8, 29, 34, 55, 49, 36, 27, 14, 38, 51, 12, 25, + 62, 43, 20, 1, 41, 60, 3, 22, 16, 5, 58, 47, 7, 18, 45, 56, + 33, 52, 11, 30, 54, 35, 28, 9, 15, 26, 37, 48, 24, 13, 50, 39, + 0, 43, 21, 62, 42, 1, 63, 20, 23, 60, 2, 41, 61, 22, 40, 3, + 46, 5, 59, 16, 4, 47, 17, 58, 57, 18, 44, 7, 19, 56, 6, 45, + 31, 52, 10, 33, 53, 30, 32, 11, 8, 35, 29, 54, 34, 9, 55, 28, + 49, 26, 36, 15, 27, 48, 14, 37, 38, 13, 51, 24, 12, 39, 25, 50, + 0, 52, 43, 31, 21, 33, 62, 10, 42, 30, 1, 53, 63, 11, 20, 32, + 23, 35, 60, 8, 2, 54, 41, 29, 61, 9, 22, 34, 40, 28, 3, 55, + 46, 26, 5, 49, 59, 15, 16, 36, 4, 48, 47, 27, 17, 37, 58, 14, + 57, 13, 18, 38, 44, 24, 7, 51, 19, 39, 56, 12, 6, 50, 45, 25, + 0, 26, 52, 46, 43, 49, 31, 5, 21, 15, 33, 59, 62, 36, 10, 16, + 42, 48, 30, 4, 1, 27, 53, 47, 63, 37, 11, 17, 20, 14, 32, 58, + 23, 13, 35, 57, 60, 38, 8, 18, 2, 24, 54, 44, 41, 51, 29, 7, + 61, 39, 9, 19, 22, 12, 34, 56, 40, 50, 28, 6, 3, 25, 55, 45, + 0, 13, 26, 23, 52, 57, 46, 35, 43, 38, 49, 60, 31, 18, 5, 8, + 21, 24, 15, 2, 33, 44, 59, 54, 62, 51, 36, 41, 10, 7, 16, 29, + 42, 39, 48, 61, 30, 19, 4, 9, 1, 12, 27, 22, 53, 56, 47, 34, + 63, 50, 37, 40, 11, 6, 17, 28, 20, 25, 14, 3, 32, 45, 58, 55, + 0, 39, 13, 42, 26, 61, 23, 48, 52, 19, 57, 30, 46, 9, 35, 4, + 43, 12, 38, 1, 49, 22, 60, 27, 31, 56, 18, 53, 5, 34, 8, 47, + 21, 50, 24, 63, 15, 40, 2, 37, 33, 6, 44, 11, 59, 28, 54, 17, + 62, 25, 51, 20, 36, 3, 41, 14, 10, 45, 7, 32, 16, 55, 29, 58, + 0, 50, 39, 21, 13, 63, 42, 24, 26, 40, 61, 15, 23, 37, 48, 2, + 52, 6, 19, 33, 57, 11, 30, 44, 46, 28, 9, 59, 35, 17, 4, 54, + 43, 25, 12, 62, 38, 20, 1, 51, 49, 3, 22, 36, 60, 14, 27, 41, + 31, 45, 56, 10, 18, 32, 53, 7, 5, 55, 34, 16, 8, 58, 47, 29, + 0, 25, 50, 43, 39, 62, 21, 12, 13, 20, 63, 38, 42, 51, 24, 1, + 26, 3, 40, 49, 61, 36, 15, 22, 23, 14, 37, 60, 48, 41, 2, 27, + 52, 45, 6, 31, 19, 10, 33, 56, 57, 32, 11, 18, 30, 7, 44, 53, + 46, 55, 28, 5, 9, 16, 59, 34, 35, 58, 17, 8, 4, 29, 54, 47, + 0, 45, 25, 52, 50, 31, 43, 6, 39, 10, 62, 19, 21, 56, 12, 33, + 13, 32, 20, 57, 63, 18, 38, 11, 42, 7, 51, 30, 24, 53, 1, 44, + 26, 55, 3, 46, 40, 5, 49, 28, 61, 16, 36, 9, 15, 34, 22, 59, + 23, 58, 14, 35, 37, 8, 60, 17, 48, 29, 41, 4, 2, 47, 27, 54, + 0, 55, 45, 26, 25, 46, 52, 3, 50, 5, 31, 40, 43, 28, 6, 49, + 39, 16, 10, 61, 62, 9, 19, 36, 21, 34, 56, 15, 12, 59, 33, 22, + 13, 58, 32, 23, 20, 35, 57, 14, 63, 8, 18, 37, 38, 17, 11, 60, + 42, 29, 7, 48, 51, 4, 30, 41, 24, 47, 53, 2, 1, 54, 44, 27, + 0, 58, 55, 13, 45, 23, 26, 32, 25, 35, 46, 20, 52, 14, 3, 57, + 50, 8, 5, 63, 31, 37, 40, 18, 43, 17, 28, 38, 6, 60, 49, 11, + 39, 29, 16, 42, 10, 48, 61, 7, 62, 4, 9, 51, 19, 41, 36, 30, + 21, 47, 34, 24, 56, 2, 15, 53, 12, 54, 59, 1, 33, 27, 22, 44, + 0, 29, 58, 39, 55, 42, 13, 16, 45, 48, 23, 10, 26, 7, 32, 61, + 25, 4, 35, 62, 46, 51, 20, 9, 52, 41, 14, 19, 3, 30, 57, 36, + 50, 47, 8, 21, 5, 24, 63, 34, 31, 2, 37, 56, 40, 53, 18, 15, + 43, 54, 17, 12, 28, 1, 38, 59, 6, 27, 60, 33, 49, 44, 11, 22, + 0, 47, 29, 50, 58, 21, 39, 8, 55, 24, 42, 5, 13, 34, 16, 63, + 45, 2, 48, 31, 23, 56, 10, 37, 26, 53, 7, 40, 32, 15, 61, 18, + 25, 54, 4, 43, 35, 12, 62, 17, 46, 1, 51, 28, 20, 59, 9, 38, + 52, 27, 41, 6, 14, 33, 19, 60, 3, 44, 30, 49, 57, 22, 36, 11, + 0, 54, 47, 25, 29, 43, 50, 4, 58, 12, 21, 35, 39, 17, 8, 62, + 55, 1, 24, 46, 42, 28, 5, 51, 13, 59, 34, 20, 16, 38, 63, 9, + 45, 27, 2, 52, 48, 6, 31, 41, 23, 33, 56, 14, 10, 60, 37, 19, + 26, 44, 53, 3, 7, 49, 40, 30, 32, 22, 15, 57, 61, 11, 18, 36, + 0, 27, 54, 45, 47, 52, 25, 2, 29, 6, 43, 48, 50, 41, 4, 31, + 58, 33, 12, 23, 21, 14, 35, 56, 39, 60, 17, 10, 8, 19, 62, 37, + 55, 44, 1, 26, 24, 3, 46, 53, 42, 49, 28, 7, 5, 30, 51, 40, + 13, 22, 59, 32, 34, 57, 20, 15, 16, 11, 38, 61, 63, 36, 9, 18, + 0, 44, 27, 55, 54, 26, 45, 1, 47, 3, 52, 24, 25, 53, 2, 46, + 29, 49, 6, 42, 43, 7, 48, 28, 50, 30, 41, 5, 4, 40, 31, 51, + 58, 22, 33, 13, 12, 32, 23, 59, 21, 57, 14, 34, 35, 15, 56, 20, + 39, 11, 60, 16, 17, 61, 10, 38, 8, 36, 19, 63, 62, 18, 37, 9, + 0, 22, 44, 58, 27, 13, 55, 33, 54, 32, 26, 12, 45, 59, 1, 23, + 47, 57, 3, 21, 52, 34, 24, 14, 25, 15, 53, 35, 2, 20, 46, 56, + 29, 11, 49, 39, 6, 16, 42, 60, 43, 61, 7, 17, 48, 38, 28, 10, + 50, 36, 30, 8, 41, 63, 5, 19, 4, 18, 40, 62, 31, 9, 51, 37, + 0, 11, 22, 29, 44, 39, 58, 49, 27, 16, 13, 6, 55, 60, 33, 42, + 54, 61, 32, 43, 26, 17, 12, 7, 45, 38, 59, 48, 1, 10, 23, 28, + 47, 36, 57, 50, 3, 8, 21, 30, 52, 63, 34, 41, 24, 19, 14, 5, + 25, 18, 15, 4, 53, 62, 35, 40, 2, 9, 20, 31, 46, 37, 56, 51, + 0, 36, 11, 47, 22, 50, 29, 57, 44, 8, 39, 3, 58, 30, 49, 21, + 27, 63, 16, 52, 13, 41, 6, 34, 55, 19, 60, 24, 33, 5, 42, 14, + 54, 18, 61, 25, 32, 4, 43, 15, 26, 62, 17, 53, 12, 40, 7, 35, + 45, 9, 38, 2, 59, 31, 48, 20, 1, 37, 10, 46, 23, 51, 28, 56, + 0, 18, 36, 54, 11, 25, 47, 61, 22, 4, 50, 32, 29, 15, 57, 43, + 44, 62, 8, 26, 39, 53, 3, 17, 58, 40, 30, 12, 49, 35, 21, 7, + 27, 9, 63, 45, 16, 2, 52, 38, 13, 31, 41, 59, 6, 20, 34, 48, + 55, 37, 19, 1, 60, 46, 24, 10, 33, 51, 5, 23, 42, 56, 14, 28, + 0, 9, 18, 27, 36, 45, 54, 63, 11, 2, 25, 16, 47, 38, 61, 52, + 22, 31, 4, 13, 50, 59, 32, 41, 29, 20, 15, 6, 57, 48, 43, 34, + 44, 37, 62, 55, 8, 1, 26, 19, 39, 46, 53, 60, 3, 10, 17, 24, + 58, 51, 40, 33, 30, 23, 12, 5, 49, 56, 35, 42, 21, 28, 7, 14, + 0, 37, 9, 44, 18, 55, 27, 62, 36, 1, 45, 8, 54, 19, 63, 26, + 11, 46, 2, 39, 25, 60, 16, 53, 47, 10, 38, 3, 61, 24, 52, 17, + 22, 51, 31, 58, 4, 33, 13, 40, 50, 23, 59, 30, 32, 5, 41, 12, + 29, 56, 20, 49, 15, 42, 6, 35, 57, 28, 48, 21, 43, 14, 34, 7, + 0, 51, 37, 22, 9, 58, 44, 31, 18, 33, 55, 4, 27, 40, 62, 13, + 36, 23, 1, 50, 45, 30, 8, 59, 54, 5, 19, 32, 63, 12, 26, 41, + 11, 56, 46, 29, 2, 49, 39, 20, 25, 42, 60, 15, 16, 35, 53, 6, + 47, 28, 10, 57, 38, 21, 3, 48, 61, 14, 24, 43, 52, 7, 17, 34, + 0, 56, 51, 11, 37, 29, 22, 46, 9, 49, 58, 2, 44, 20, 31, 39, + 18, 42, 33, 25, 55, 15, 4, 60, 27, 35, 40, 16, 62, 6, 13, 53, + 36, 28, 23, 47, 1, 57, 50, 10, 45, 21, 30, 38, 8, 48, 59, 3, + 54, 14, 5, 61, 19, 43, 32, 24, 63, 7, 12, 52, 26, 34, 41, 17, + 0, 28, 56, 36, 51, 47, 11, 23, 37, 57, 29, 1, 22, 10, 46, 50, + 9, 21, 49, 45, 58, 38, 2, 30, 44, 48, 20, 8, 31, 3, 39, 59, + 18, 14, 42, 54, 33, 61, 25, 5, 55, 43, 15, 19, 4, 24, 60, 32, + 27, 7, 35, 63, 40, 52, 16, 12, 62, 34, 6, 26, 13, 17, 53, 41, + 0, 14, 28, 18, 56, 54, 36, 42, 51, 61, 47, 33, 11, 5, 23, 25, + 37, 43, 57, 55, 29, 19, 1, 15, 22, 24, 10, 4, 46, 32, 50, 60, + 9, 7, 21, 27, 49, 63, 45, 35, 58, 52, 38, 40, 2, 12, 30, 16, + 44, 34, 48, 62, 20, 26, 8, 6, 31, 17, 3, 13, 39, 41, 59, 53, + 0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45, + 51, 52, 61, 58, 47, 40, 33, 38, 11, 12, 5, 2, 23, 16, 25, 30, + 37, 34, 43, 44, 57, 62, 55, 48, 29, 26, 19, 20, 1, 6, 15, 8, + 22, 17, 24, 31, 10, 13, 4, 3, 46, 41, 32, 39, 50, 53, 60, 59, + 0, 34, 7, 37, 14, 44, 9, 43, 28, 62, 27, 57, 18, 48, 21, 55, + 56, 26, 63, 29, 54, 20, 49, 19, 36, 6, 35, 1, 42, 8, 45, 15, + 51, 17, 52, 22, 61, 31, 58, 24, 47, 13, 40, 10, 33, 3, 38, 4, + 11, 41, 12, 46, 5, 39, 2, 32, 23, 53, 16, 50, 25, 59, 30, 60, + 0, 17, 34, 51, 7, 22, 37, 52, 14, 31, 44, 61, 9, 24, 43, 58, + 28, 13, 62, 47, 27, 10, 57, 40, 18, 3, 48, 33, 21, 4, 55, 38, + 56, 41, 26, 11, 63, 46, 29, 12, 54, 39, 20, 5, 49, 32, 19, 2, + 36, 53, 6, 23, 35, 50, 1, 16, 42, 59, 8, 25, 45, 60, 15, 30, + 0, 41, 17, 56, 34, 11, 51, 26, 7, 46, 22, 63, 37, 12, 52, 29, + 14, 39, 31, 54, 44, 5, 61, 20, 9, 32, 24, 49, 43, 2, 58, 19, + 28, 53, 13, 36, 62, 23, 47, 6, 27, 50, 10, 35, 57, 16, 40, 1, + 18, 59, 3, 42, 48, 25, 33, 8, 21, 60, 4, 45, 55, 30, 38, 15, + 0, 53, 41, 28, 17, 36, 56, 13, 34, 23, 11, 62, 51, 6, 26, 47, + 7, 50, 46, 27, 22, 35, 63, 10, 37, 16, 12, 57, 52, 1, 29, 40, + 14, 59, 39, 18, 31, 42, 54, 3, 44, 25, 5, 48, 61, 8, 20, 33, + 9, 60, 32, 21, 24, 45, 49, 4, 43, 30, 2, 55, 58, 15, 19, 38, + 0, 59, 53, 14, 41, 18, 28, 39, 17, 42, 36, 31, 56, 3, 13, 54, + 34, 25, 23, 44, 11, 48, 62, 5, 51, 8, 6, 61, 26, 33, 47, 20, + 7, 60, 50, 9, 46, 21, 27, 32, 22, 45, 35, 24, 63, 4, 10, 49, + 37, 30, 16, 43, 12, 55, 57, 2, 52, 15, 1, 58, 29, 38, 40, 19, + 0, 60, 59, 7, 53, 9, 14, 50, 41, 21, 18, 46, 28, 32, 39, 27, + 17, 45, 42, 22, 36, 24, 31, 35, 56, 4, 3, 63, 13, 49, 54, 10, + 34, 30, 25, 37, 23, 43, 44, 16, 11, 55, 48, 12, 62, 2, 5, 57, + 51, 15, 8, 52, 6, 58, 61, 1, 26, 38, 33, 29, 47, 19, 20, 40, + 0, 30, 60, 34, 59, 37, 7, 25, 53, 43, 9, 23, 14, 16, 50, 44, + 41, 55, 21, 11, 18, 12, 46, 48, 28, 2, 32, 62, 39, 57, 27, 5, + 17, 15, 45, 51, 42, 52, 22, 8, 36, 58, 24, 6, 31, 1, 35, 61, + 56, 38, 4, 26, 3, 29, 63, 33, 13, 19, 49, 47, 54, 40, 10, 20, + 0, 15, 30, 17, 60, 51, 34, 45, 59, 52, 37, 42, 7, 8, 25, 22, + 53, 58, 43, 36, 9, 6, 23, 24, 14, 1, 16, 31, 50, 61, 44, 35, + 41, 38, 55, 56, 21, 26, 11, 4, 18, 29, 12, 3, 46, 33, 48, 63, + 28, 19, 2, 13, 32, 47, 62, 49, 39, 40, 57, 54, 27, 20, 5, 10, + 0, 38, 15, 41, 30, 56, 17, 55, 60, 26, 51, 21, 34, 4, 45, 11, + 59, 29, 52, 18, 37, 3, 42, 12, 7, 33, 8, 46, 25, 63, 22, 48, + 53, 19, 58, 28, 43, 13, 36, 2, 9, 47, 6, 32, 23, 49, 24, 62, + 14, 40, 1, 39, 16, 54, 31, 57, 50, 20, 61, 27, 44, 10, 35, 5, + 0, 19, 38, 53, 15, 28, 41, 58, 30, 13, 56, 43, 17, 2, 55, 36, + 60, 47, 26, 9, 51, 32, 21, 6, 34, 49, 4, 23, 45, 62, 11, 24, + 59, 40, 29, 14, 52, 39, 18, 1, 37, 54, 3, 16, 42, 57, 12, 31, + 7, 20, 33, 50, 8, 27, 46, 61, 25, 10, 63, 44, 22, 5, 48, 35, + 0, 40, 19, 59, 38, 14, 53, 29, 15, 39, 28, 52, 41, 1, 58, 18, + 30, 54, 13, 37, 56, 16, 43, 3, 17, 57, 2, 42, 55, 31, 36, 12, + 60, 20, 47, 7, 26, 50, 9, 33, 51, 27, 32, 8, 21, 61, 6, 46, + 34, 10, 49, 25, 4, 44, 23, 63, 45, 5, 62, 22, 11, 35, 24, 48, + 0, 20, 40, 60, 19, 7, 59, 47, 38, 50, 14, 26, 53, 33, 29, 9, + 15, 27, 39, 51, 28, 8, 52, 32, 41, 61, 1, 21, 58, 46, 18, 6, + 30, 10, 54, 34, 13, 25, 37, 49, 56, 44, 16, 4, 43, 63, 3, 23, + 17, 5, 57, 45, 2, 22, 42, 62, 55, 35, 31, 11, 36, 48, 12, 24, + 0, 10, 20, 30, 40, 34, 60, 54, 19, 25, 7, 13, 59, 49, 47, 37, + 38, 44, 50, 56, 14, 4, 26, 16, 53, 63, 33, 43, 29, 23, 9, 3, + 15, 5, 27, 17, 39, 45, 51, 57, 28, 22, 8, 2, 52, 62, 32, 42, + 41, 35, 61, 55, 1, 11, 21, 31, 58, 48, 46, 36, 18, 24, 6, 12, + 0, 5, 10, 15, 20, 17, 30, 27, 40, 45, 34, 39, 60, 57, 54, 51, + 19, 22, 25, 28, 7, 2, 13, 8, 59, 62, 49, 52, 47, 42, 37, 32, + 38, 35, 44, 41, 50, 55, 56, 61, 14, 11, 4, 1, 26, 31, 16, 21, + 53, 48, 63, 58, 33, 36, 43, 46, 29, 24, 23, 18, 9, 12, 3, 6, + 0, 35, 5, 38, 10, 41, 15, 44, 20, 55, 17, 50, 30, 61, 27, 56, + 40, 11, 45, 14, 34, 1, 39, 4, 60, 31, 57, 26, 54, 21, 51, 16, + 19, 48, 22, 53, 25, 58, 28, 63, 7, 36, 2, 33, 13, 46, 8, 43, + 59, 24, 62, 29, 49, 18, 52, 23, 47, 12, 42, 9, 37, 6, 32, 3, + 0, 48, 35, 19, 5, 53, 38, 22, 10, 58, 41, 25, 15, 63, 44, 28, + 20, 36, 55, 7, 17, 33, 50, 2, 30, 46, 61, 13, 27, 43, 56, 8, + 40, 24, 11, 59, 45, 29, 14, 62, 34, 18, 1, 49, 39, 23, 4, 52, + 60, 12, 31, 47, 57, 9, 26, 42, 54, 6, 21, 37, 51, 3, 16, 32, + 0, 24, 48, 40, 35, 59, 19, 11, 5, 29, 53, 45, 38, 62, 22, 14, + 10, 18, 58, 34, 41, 49, 25, 1, 15, 23, 63, 39, 44, 52, 28, 4, + 20, 12, 36, 60, 55, 47, 7, 31, 17, 9, 33, 57, 50, 42, 2, 26, + 30, 6, 46, 54, 61, 37, 13, 21, 27, 3, 43, 51, 56, 32, 8, 16, + 0, 12, 24, 20, 48, 60, 40, 36, 35, 47, 59, 55, 19, 31, 11, 7, + 5, 9, 29, 17, 53, 57, 45, 33, 38, 42, 62, 50, 22, 26, 14, 2, + 10, 6, 18, 30, 58, 54, 34, 46, 41, 37, 49, 61, 25, 21, 1, 13, + 15, 3, 23, 27, 63, 51, 39, 43, 44, 32, 52, 56, 28, 16, 4, 8, + 0, 6, 12, 10, 24, 30, 20, 18, 48, 54, 60, 58, 40, 46, 36, 34, + 35, 37, 47, 41, 59, 61, 55, 49, 19, 21, 31, 25, 11, 13, 7, 1, + 5, 3, 9, 15, 29, 27, 17, 23, 53, 51, 57, 63, 45, 43, 33, 39, + 38, 32, 42, 44, 62, 56, 50, 52, 22, 16, 26, 28, 14, 8, 2, 4, + 0, 3, 6, 5, 12, 15, 10, 9, 24, 27, 30, 29, 20, 23, 18, 17, + 48, 51, 54, 53, 60, 63, 58, 57, 40, 43, 46, 45, 36, 39, 34, 33, + 35, 32, 37, 38, 47, 44, 41, 42, 59, 56, 61, 62, 55, 52, 49, 50, + 19, 16, 21, 22, 31, 28, 25, 26, 11, 8, 13, 14, 7, 4, 1, 2, + 0, 32, 3, 35, 6, 38, 5, 37, 12, 44, 15, 47, 10, 42, 9, 41, + 24, 56, 27, 59, 30, 62, 29, 61, 20, 52, 23, 55, 18, 50, 17, 49, + 48, 16, 51, 19, 54, 22, 53, 21, 60, 28, 63, 31, 58, 26, 57, 25, + 40, 8, 43, 11, 46, 14, 45, 13, 36, 4, 39, 7, 34, 2, 33, 1, + 0, 16, 32, 48, 3, 19, 35, 51, 6, 22, 38, 54, 5, 21, 37, 53, + 12, 28, 44, 60, 15, 31, 47, 63, 10, 26, 42, 58, 9, 25, 41, 57, + 24, 8, 56, 40, 27, 11, 59, 43, 30, 14, 62, 46, 29, 13, 61, 45, + 20, 4, 52, 36, 23, 7, 55, 39, 18, 2, 50, 34, 17, 1, 49, 33, + 0, 8, 16, 24, 32, 40, 48, 56, 3, 11, 19, 27, 35, 43, 51, 59, + 6, 14, 22, 30, 38, 46, 54, 62, 5, 13, 21, 29, 37, 45, 53, 61, + 12, 4, 28, 20, 44, 36, 60, 52, 15, 7, 31, 23, 47, 39, 63, 55, + 10, 2, 26, 18, 42, 34, 58, 50, 9, 1, 25, 17, 41, 33, 57, 49, + 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, + 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, + 6, 2, 14, 10, 22, 18, 30, 26, 38, 34, 46, 42, 54, 50, 62, 58, + 5, 1, 13, 9, 21, 17, 29, 25, 37, 33, 45, 41, 53, 49, 61, 57, + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, + 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, + 3, 1, 7, 5, 11, 9, 15, 13, 19, 17, 23, 21, 27, 25, 31, 29, + 35, 33, 39, 37, 43, 41, 47, 45, 51, 49, 55, 53, 59, 57, 63, 61 +}; + +const qracode qra_12_63_64_irr_b = { + qra_K, + qra_N, + qra_m, + qra_M, + qra_a, + qra_NC, + qra_V, + qra_C, + qra_NMSG, + qra_MAXVDEG, + qra_MAXCDEG, + QRATYPE_NORMAL, + qra_R, + CODE_NAME, + qra_acc_input_idx, + qra_acc_input_wlog, + qra_log, + qra_exp, + qra_msgw, + qra_vdeg, + qra_cdeg, + qra_v2cmidx, + qra_c2vmidx, + qra_pmat +}; + +#undef qra_K +#undef qra_N +#undef qra_m +#undef qra_M +#undef qra_a +#undef qra_NC +#undef qra_V +#undef qra_C +#undef qra_NMSG +#undef qra_MAXVDEG +#undef qra_MAXCDEG +#undef qra_R +#undef CODE_NAME \ No newline at end of file diff --git a/lib/qra/qracodes/qra12_63_64_irr_b.h b/lib/qra/qracodes/qra12_63_64_irr_b.h new file mode 100644 index 00000000..bf70b360 --- /dev/null +++ b/lib/qra/qracodes/qra12_63_64_irr_b.h @@ -0,0 +1,39 @@ +// qra12_63_64_irr_b.h +// Code tables and defines for Q-ary RA code (12,63) over GF(64) +// Code Name: qra12_63_64_irr_b +// (12,63) RA Code over GF(64) - RF=333344455567 + +// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy + +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +#ifndef _qra12_63_64_irr_b_h +#define _qra12_63_64_irr_b_h + +#include "qracodes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const qracode qra_12_63_64_irr_b; + +#ifdef __cplusplus +} +#endif + +#endif // _qra12_63_64_irr_b_h diff --git a/lib/qra/qracodes/qra13_64_64_irr_e.c b/lib/qra/qracodes/qra13_64_64_irr_e.c new file mode 100644 index 00000000..7adf22fe --- /dev/null +++ b/lib/qra/qracodes/qra13_64_64_irr_e.c @@ -0,0 +1,534 @@ +// qra13_64_64_irr_e.c +// Encoding/Decoding tables for Q-ary RA code (13,64) over GF(64) +// Code Name: qra13_64_64_irr_e +// (13,64) RA Code over GF(64) RF=[3x4 4x4 6x1 3x2 5x1 7x1]/18 + +// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy + +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +#include "qra13_64_64_irr_e.h" + +#define qra_K 13 // number of information symbols +#define qra_N 64 // codeword length in symbols +#define qra_m 6 // bits/symbol +#define qra_M 64 // Symbol alphabet cardinality +#define qra_a 1 // grouping factor +#define qra_NC 51 // number of check symbols (N-K) + +// Defines used by the message passing decoder -------- + +#define qra_V 64 // number of variables in the code graph (N) +#define qra_C 116 // number of factors in the code graph (N +(N-K)+1) +#define qra_NMSG 218 // number of msgs in the code graph +#define qra_MAXVDEG 8 // maximum variable degree +#define qra_MAXCDEG 3 // maximum factor degree +#define qra_R 0.20313f // code rate (K/N) +#define CODE_NAME "qra_13_64_64_irr_e" + +// table of the systematic symbols indexes in the accumulator chain +static const int qra_acc_input_idx[qra_NC+1] = { + 12, 4, 3, 9, 0, 11, 6, 8, 12, 1, + 2, 7, 4, 11, 3, 5, 9, 8, 12, 7, + 2, 4, 10, 3, 5, 11, 12, 8, 9, 6, + 7, 2, 5, 4, 12, 8, 11, 1, 6, 7, + 0, 10, 12, 8, 11, 5, 6, 1, 0, 10, + 12, 8 +}; + +// table of the systematic symbols weight logarithms over GF(M) +static const int qra_acc_input_wlog[qra_NC+1] = { + 0, 27, 0, 0, 0, 31, 28, 61, 31, 0, + 0, 52, 22, 7, 19, 47, 44, 62, 32, 50, + 52, 42, 48, 56, 40, 50, 51, 37, 37, 0, + 5, 14, 0, 0, 18, 2, 0, 45, 21, 0, + 62, 8, 11, 60, 36, 32, 17, 9, 5, 0, + 53, 0 +}; + +// table of the logarithms of the elements of GF(M) (log(0) never used) +static const int qra_log[qra_M] = { + -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, + 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, + 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, + 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, + 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, + 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, + 20, 59, 57, 58 +}; + +// table of GF(M) elements given their logarithm +static const int qra_exp[qra_M-1] = { + 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, + 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, + 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, + 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, + 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, + 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, + 57, 49, 33 +}; + +// table of the messages weight logarithms over GF(M) +static const int qra_msgw[qra_NMSG] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 27, 0, 0, 0, 31, + 28, 61, 31, 0, 0, 52, 22, 7, 19, 47, + 44, 62, 32, 50, 52, 42, 48, 56, 40, 50, + 51, 37, 37, 0, 5, 14, 0, 0, 18, 2, + 0, 45, 21, 0, 62, 8, 11, 60, 36, 32, + 17, 9, 5, 0, 53, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; + +// table of the degrees of the variable nodes +static const int qra_vdeg[qra_V] = { + 4, 4, 4, 4, 5, 5, 5, 5, 7, 4, + 4, 6, 8, 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 +}; + +// table of the degrees of the factor nodes +static const int qra_cdeg[qra_C] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 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, 2 +}; + +// table (uncompressed) of the v->c message indexes (-1=unused entry) +static const int qra_v2cmidx[qra_V*qra_MAXVDEG] = { + 0, 68, 104, 112, -1, -1, -1, -1, + 1, 73, 101, 111, -1, -1, -1, -1, + 2, 74, 84, 95, -1, -1, -1, -1, + 3, 66, 78, 87, -1, -1, -1, -1, + 4, 65, 76, 85, 97, -1, -1, -1, + 5, 79, 88, 96, 109, -1, -1, -1, + 6, 70, 93, 102, 110, -1, -1, -1, + 7, 75, 83, 94, 103, -1, -1, -1, + 8, 71, 81, 91, 99, 107, 115, -1, + 9, 67, 80, 92, -1, -1, -1, -1, + 10, 86, 105, 113, -1, -1, -1, -1, + 11, 69, 77, 89, 100, 108, -1, -1, + 12, 64, 72, 82, 90, 98, 106, 114, + 13, 116, 117, -1, -1, -1, -1, -1, + 14, 118, 119, -1, -1, -1, -1, -1, + 15, 120, 121, -1, -1, -1, -1, -1, + 16, 122, 123, -1, -1, -1, -1, -1, + 17, 124, 125, -1, -1, -1, -1, -1, + 18, 126, 127, -1, -1, -1, -1, -1, + 19, 128, 129, -1, -1, -1, -1, -1, + 20, 130, 131, -1, -1, -1, -1, -1, + 21, 132, 133, -1, -1, -1, -1, -1, + 22, 134, 135, -1, -1, -1, -1, -1, + 23, 136, 137, -1, -1, -1, -1, -1, + 24, 138, 139, -1, -1, -1, -1, -1, + 25, 140, 141, -1, -1, -1, -1, -1, + 26, 142, 143, -1, -1, -1, -1, -1, + 27, 144, 145, -1, -1, -1, -1, -1, + 28, 146, 147, -1, -1, -1, -1, -1, + 29, 148, 149, -1, -1, -1, -1, -1, + 30, 150, 151, -1, -1, -1, -1, -1, + 31, 152, 153, -1, -1, -1, -1, -1, + 32, 154, 155, -1, -1, -1, -1, -1, + 33, 156, 157, -1, -1, -1, -1, -1, + 34, 158, 159, -1, -1, -1, -1, -1, + 35, 160, 161, -1, -1, -1, -1, -1, + 36, 162, 163, -1, -1, -1, -1, -1, + 37, 164, 165, -1, -1, -1, -1, -1, + 38, 166, 167, -1, -1, -1, -1, -1, + 39, 168, 169, -1, -1, -1, -1, -1, + 40, 170, 171, -1, -1, -1, -1, -1, + 41, 172, 173, -1, -1, -1, -1, -1, + 42, 174, 175, -1, -1, -1, -1, -1, + 43, 176, 177, -1, -1, -1, -1, -1, + 44, 178, 179, -1, -1, -1, -1, -1, + 45, 180, 181, -1, -1, -1, -1, -1, + 46, 182, 183, -1, -1, -1, -1, -1, + 47, 184, 185, -1, -1, -1, -1, -1, + 48, 186, 187, -1, -1, -1, -1, -1, + 49, 188, 189, -1, -1, -1, -1, -1, + 50, 190, 191, -1, -1, -1, -1, -1, + 51, 192, 193, -1, -1, -1, -1, -1, + 52, 194, 195, -1, -1, -1, -1, -1, + 53, 196, 197, -1, -1, -1, -1, -1, + 54, 198, 199, -1, -1, -1, -1, -1, + 55, 200, 201, -1, -1, -1, -1, -1, + 56, 202, 203, -1, -1, -1, -1, -1, + 57, 204, 205, -1, -1, -1, -1, -1, + 58, 206, 207, -1, -1, -1, -1, -1, + 59, 208, 209, -1, -1, -1, -1, -1, + 60, 210, 211, -1, -1, -1, -1, -1, + 61, 212, 213, -1, -1, -1, -1, -1, + 62, 214, 215, -1, -1, -1, -1, -1, + 63, 216, 217, -1, -1, -1, -1, -1 +}; + +// table (uncompressed) of the c->v message indexes (-1=unused entry) +static const int qra_c2vmidx[qra_C*qra_MAXCDEG] = { + 0, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1, + 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1, + 8, -1, -1, 9, -1, -1, 10, -1, -1, 11, -1, -1, + 12, -1, -1, 13, -1, -1, 14, -1, -1, 15, -1, -1, + 16, -1, -1, 17, -1, -1, 18, -1, -1, 19, -1, -1, + 20, -1, -1, 21, -1, -1, 22, -1, -1, 23, -1, -1, + 24, -1, -1, 25, -1, -1, 26, -1, -1, 27, -1, -1, + 28, -1, -1, 29, -1, -1, 30, -1, -1, 31, -1, -1, + 32, -1, -1, 33, -1, -1, 34, -1, -1, 35, -1, -1, + 36, -1, -1, 37, -1, -1, 38, -1, -1, 39, -1, -1, + 40, -1, -1, 41, -1, -1, 42, -1, -1, 43, -1, -1, + 44, -1, -1, 45, -1, -1, 46, -1, -1, 47, -1, -1, + 48, -1, -1, 49, -1, -1, 50, -1, -1, 51, -1, -1, + 52, -1, -1, 53, -1, -1, 54, -1, -1, 55, -1, -1, + 56, -1, -1, 57, -1, -1, 58, -1, -1, 59, -1, -1, + 60, -1, -1, 61, -1, -1, 62, -1, -1, 63, -1, -1, + 64, 116, -1, 65, 117, 118, 66, 119, 120, 67, 121, 122, + 68, 123, 124, 69, 125, 126, 70, 127, 128, 71, 129, 130, + 72, 131, 132, 73, 133, 134, 74, 135, 136, 75, 137, 138, + 76, 139, 140, 77, 141, 142, 78, 143, 144, 79, 145, 146, + 80, 147, 148, 81, 149, 150, 82, 151, 152, 83, 153, 154, + 84, 155, 156, 85, 157, 158, 86, 159, 160, 87, 161, 162, + 88, 163, 164, 89, 165, 166, 90, 167, 168, 91, 169, 170, + 92, 171, 172, 93, 173, 174, 94, 175, 176, 95, 177, 178, + 96, 179, 180, 97, 181, 182, 98, 183, 184, 99, 185, 186, +100, 187, 188, 101, 189, 190, 102, 191, 192, 103, 193, 194, +104, 195, 196, 105, 197, 198, 106, 199, 200, 107, 201, 202, +108, 203, 204, 109, 205, 206, 110, 207, 208, 111, 209, 210, +112, 211, 212, 113, 213, 214, 114, 215, 216, 115, 217, -1 +}; + +// permutation matrix to compute Prob(x*alfa^logw) +static const int qra_pmat[qra_M*qra_M] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 0, 33, 1, 32, 2, 35, 3, 34, 4, 37, 5, 36, 6, 39, 7, 38, + 8, 41, 9, 40, 10, 43, 11, 42, 12, 45, 13, 44, 14, 47, 15, 46, + 16, 49, 17, 48, 18, 51, 19, 50, 20, 53, 21, 52, 22, 55, 23, 54, + 24, 57, 25, 56, 26, 59, 27, 58, 28, 61, 29, 60, 30, 63, 31, 62, + 0, 49, 33, 16, 1, 48, 32, 17, 2, 51, 35, 18, 3, 50, 34, 19, + 4, 53, 37, 20, 5, 52, 36, 21, 6, 55, 39, 22, 7, 54, 38, 23, + 8, 57, 41, 24, 9, 56, 40, 25, 10, 59, 43, 26, 11, 58, 42, 27, + 12, 61, 45, 28, 13, 60, 44, 29, 14, 63, 47, 30, 15, 62, 46, 31, + 0, 57, 49, 8, 33, 24, 16, 41, 1, 56, 48, 9, 32, 25, 17, 40, + 2, 59, 51, 10, 35, 26, 18, 43, 3, 58, 50, 11, 34, 27, 19, 42, + 4, 61, 53, 12, 37, 28, 20, 45, 5, 60, 52, 13, 36, 29, 21, 44, + 6, 63, 55, 14, 39, 30, 22, 47, 7, 62, 54, 15, 38, 31, 23, 46, + 0, 61, 57, 4, 49, 12, 8, 53, 33, 28, 24, 37, 16, 45, 41, 20, + 1, 60, 56, 5, 48, 13, 9, 52, 32, 29, 25, 36, 17, 44, 40, 21, + 2, 63, 59, 6, 51, 14, 10, 55, 35, 30, 26, 39, 18, 47, 43, 22, + 3, 62, 58, 7, 50, 15, 11, 54, 34, 31, 27, 38, 19, 46, 42, 23, + 0, 63, 61, 2, 57, 6, 4, 59, 49, 14, 12, 51, 8, 55, 53, 10, + 33, 30, 28, 35, 24, 39, 37, 26, 16, 47, 45, 18, 41, 22, 20, 43, + 1, 62, 60, 3, 56, 7, 5, 58, 48, 15, 13, 50, 9, 54, 52, 11, + 32, 31, 29, 34, 25, 38, 36, 27, 17, 46, 44, 19, 40, 23, 21, 42, + 0, 62, 63, 1, 61, 3, 2, 60, 57, 7, 6, 56, 4, 58, 59, 5, + 49, 15, 14, 48, 12, 50, 51, 13, 8, 54, 55, 9, 53, 11, 10, 52, + 33, 31, 30, 32, 28, 34, 35, 29, 24, 38, 39, 25, 37, 27, 26, 36, + 16, 46, 47, 17, 45, 19, 18, 44, 41, 23, 22, 40, 20, 42, 43, 21, + 0, 31, 62, 33, 63, 32, 1, 30, 61, 34, 3, 28, 2, 29, 60, 35, + 57, 38, 7, 24, 6, 25, 56, 39, 4, 27, 58, 37, 59, 36, 5, 26, + 49, 46, 15, 16, 14, 17, 48, 47, 12, 19, 50, 45, 51, 44, 13, 18, + 8, 23, 54, 41, 55, 40, 9, 22, 53, 42, 11, 20, 10, 21, 52, 43, + 0, 46, 31, 49, 62, 16, 33, 15, 63, 17, 32, 14, 1, 47, 30, 48, + 61, 19, 34, 12, 3, 45, 28, 50, 2, 44, 29, 51, 60, 18, 35, 13, + 57, 23, 38, 8, 7, 41, 24, 54, 6, 40, 25, 55, 56, 22, 39, 9, + 4, 42, 27, 53, 58, 20, 37, 11, 59, 21, 36, 10, 5, 43, 26, 52, + 0, 23, 46, 57, 31, 8, 49, 38, 62, 41, 16, 7, 33, 54, 15, 24, + 63, 40, 17, 6, 32, 55, 14, 25, 1, 22, 47, 56, 30, 9, 48, 39, + 61, 42, 19, 4, 34, 53, 12, 27, 3, 20, 45, 58, 28, 11, 50, 37, + 2, 21, 44, 59, 29, 10, 51, 36, 60, 43, 18, 5, 35, 52, 13, 26, + 0, 42, 23, 61, 46, 4, 57, 19, 31, 53, 8, 34, 49, 27, 38, 12, + 62, 20, 41, 3, 16, 58, 7, 45, 33, 11, 54, 28, 15, 37, 24, 50, + 63, 21, 40, 2, 17, 59, 6, 44, 32, 10, 55, 29, 14, 36, 25, 51, + 1, 43, 22, 60, 47, 5, 56, 18, 30, 52, 9, 35, 48, 26, 39, 13, + 0, 21, 42, 63, 23, 2, 61, 40, 46, 59, 4, 17, 57, 44, 19, 6, + 31, 10, 53, 32, 8, 29, 34, 55, 49, 36, 27, 14, 38, 51, 12, 25, + 62, 43, 20, 1, 41, 60, 3, 22, 16, 5, 58, 47, 7, 18, 45, 56, + 33, 52, 11, 30, 54, 35, 28, 9, 15, 26, 37, 48, 24, 13, 50, 39, + 0, 43, 21, 62, 42, 1, 63, 20, 23, 60, 2, 41, 61, 22, 40, 3, + 46, 5, 59, 16, 4, 47, 17, 58, 57, 18, 44, 7, 19, 56, 6, 45, + 31, 52, 10, 33, 53, 30, 32, 11, 8, 35, 29, 54, 34, 9, 55, 28, + 49, 26, 36, 15, 27, 48, 14, 37, 38, 13, 51, 24, 12, 39, 25, 50, + 0, 52, 43, 31, 21, 33, 62, 10, 42, 30, 1, 53, 63, 11, 20, 32, + 23, 35, 60, 8, 2, 54, 41, 29, 61, 9, 22, 34, 40, 28, 3, 55, + 46, 26, 5, 49, 59, 15, 16, 36, 4, 48, 47, 27, 17, 37, 58, 14, + 57, 13, 18, 38, 44, 24, 7, 51, 19, 39, 56, 12, 6, 50, 45, 25, + 0, 26, 52, 46, 43, 49, 31, 5, 21, 15, 33, 59, 62, 36, 10, 16, + 42, 48, 30, 4, 1, 27, 53, 47, 63, 37, 11, 17, 20, 14, 32, 58, + 23, 13, 35, 57, 60, 38, 8, 18, 2, 24, 54, 44, 41, 51, 29, 7, + 61, 39, 9, 19, 22, 12, 34, 56, 40, 50, 28, 6, 3, 25, 55, 45, + 0, 13, 26, 23, 52, 57, 46, 35, 43, 38, 49, 60, 31, 18, 5, 8, + 21, 24, 15, 2, 33, 44, 59, 54, 62, 51, 36, 41, 10, 7, 16, 29, + 42, 39, 48, 61, 30, 19, 4, 9, 1, 12, 27, 22, 53, 56, 47, 34, + 63, 50, 37, 40, 11, 6, 17, 28, 20, 25, 14, 3, 32, 45, 58, 55, + 0, 39, 13, 42, 26, 61, 23, 48, 52, 19, 57, 30, 46, 9, 35, 4, + 43, 12, 38, 1, 49, 22, 60, 27, 31, 56, 18, 53, 5, 34, 8, 47, + 21, 50, 24, 63, 15, 40, 2, 37, 33, 6, 44, 11, 59, 28, 54, 17, + 62, 25, 51, 20, 36, 3, 41, 14, 10, 45, 7, 32, 16, 55, 29, 58, + 0, 50, 39, 21, 13, 63, 42, 24, 26, 40, 61, 15, 23, 37, 48, 2, + 52, 6, 19, 33, 57, 11, 30, 44, 46, 28, 9, 59, 35, 17, 4, 54, + 43, 25, 12, 62, 38, 20, 1, 51, 49, 3, 22, 36, 60, 14, 27, 41, + 31, 45, 56, 10, 18, 32, 53, 7, 5, 55, 34, 16, 8, 58, 47, 29, + 0, 25, 50, 43, 39, 62, 21, 12, 13, 20, 63, 38, 42, 51, 24, 1, + 26, 3, 40, 49, 61, 36, 15, 22, 23, 14, 37, 60, 48, 41, 2, 27, + 52, 45, 6, 31, 19, 10, 33, 56, 57, 32, 11, 18, 30, 7, 44, 53, + 46, 55, 28, 5, 9, 16, 59, 34, 35, 58, 17, 8, 4, 29, 54, 47, + 0, 45, 25, 52, 50, 31, 43, 6, 39, 10, 62, 19, 21, 56, 12, 33, + 13, 32, 20, 57, 63, 18, 38, 11, 42, 7, 51, 30, 24, 53, 1, 44, + 26, 55, 3, 46, 40, 5, 49, 28, 61, 16, 36, 9, 15, 34, 22, 59, + 23, 58, 14, 35, 37, 8, 60, 17, 48, 29, 41, 4, 2, 47, 27, 54, + 0, 55, 45, 26, 25, 46, 52, 3, 50, 5, 31, 40, 43, 28, 6, 49, + 39, 16, 10, 61, 62, 9, 19, 36, 21, 34, 56, 15, 12, 59, 33, 22, + 13, 58, 32, 23, 20, 35, 57, 14, 63, 8, 18, 37, 38, 17, 11, 60, + 42, 29, 7, 48, 51, 4, 30, 41, 24, 47, 53, 2, 1, 54, 44, 27, + 0, 58, 55, 13, 45, 23, 26, 32, 25, 35, 46, 20, 52, 14, 3, 57, + 50, 8, 5, 63, 31, 37, 40, 18, 43, 17, 28, 38, 6, 60, 49, 11, + 39, 29, 16, 42, 10, 48, 61, 7, 62, 4, 9, 51, 19, 41, 36, 30, + 21, 47, 34, 24, 56, 2, 15, 53, 12, 54, 59, 1, 33, 27, 22, 44, + 0, 29, 58, 39, 55, 42, 13, 16, 45, 48, 23, 10, 26, 7, 32, 61, + 25, 4, 35, 62, 46, 51, 20, 9, 52, 41, 14, 19, 3, 30, 57, 36, + 50, 47, 8, 21, 5, 24, 63, 34, 31, 2, 37, 56, 40, 53, 18, 15, + 43, 54, 17, 12, 28, 1, 38, 59, 6, 27, 60, 33, 49, 44, 11, 22, + 0, 47, 29, 50, 58, 21, 39, 8, 55, 24, 42, 5, 13, 34, 16, 63, + 45, 2, 48, 31, 23, 56, 10, 37, 26, 53, 7, 40, 32, 15, 61, 18, + 25, 54, 4, 43, 35, 12, 62, 17, 46, 1, 51, 28, 20, 59, 9, 38, + 52, 27, 41, 6, 14, 33, 19, 60, 3, 44, 30, 49, 57, 22, 36, 11, + 0, 54, 47, 25, 29, 43, 50, 4, 58, 12, 21, 35, 39, 17, 8, 62, + 55, 1, 24, 46, 42, 28, 5, 51, 13, 59, 34, 20, 16, 38, 63, 9, + 45, 27, 2, 52, 48, 6, 31, 41, 23, 33, 56, 14, 10, 60, 37, 19, + 26, 44, 53, 3, 7, 49, 40, 30, 32, 22, 15, 57, 61, 11, 18, 36, + 0, 27, 54, 45, 47, 52, 25, 2, 29, 6, 43, 48, 50, 41, 4, 31, + 58, 33, 12, 23, 21, 14, 35, 56, 39, 60, 17, 10, 8, 19, 62, 37, + 55, 44, 1, 26, 24, 3, 46, 53, 42, 49, 28, 7, 5, 30, 51, 40, + 13, 22, 59, 32, 34, 57, 20, 15, 16, 11, 38, 61, 63, 36, 9, 18, + 0, 44, 27, 55, 54, 26, 45, 1, 47, 3, 52, 24, 25, 53, 2, 46, + 29, 49, 6, 42, 43, 7, 48, 28, 50, 30, 41, 5, 4, 40, 31, 51, + 58, 22, 33, 13, 12, 32, 23, 59, 21, 57, 14, 34, 35, 15, 56, 20, + 39, 11, 60, 16, 17, 61, 10, 38, 8, 36, 19, 63, 62, 18, 37, 9, + 0, 22, 44, 58, 27, 13, 55, 33, 54, 32, 26, 12, 45, 59, 1, 23, + 47, 57, 3, 21, 52, 34, 24, 14, 25, 15, 53, 35, 2, 20, 46, 56, + 29, 11, 49, 39, 6, 16, 42, 60, 43, 61, 7, 17, 48, 38, 28, 10, + 50, 36, 30, 8, 41, 63, 5, 19, 4, 18, 40, 62, 31, 9, 51, 37, + 0, 11, 22, 29, 44, 39, 58, 49, 27, 16, 13, 6, 55, 60, 33, 42, + 54, 61, 32, 43, 26, 17, 12, 7, 45, 38, 59, 48, 1, 10, 23, 28, + 47, 36, 57, 50, 3, 8, 21, 30, 52, 63, 34, 41, 24, 19, 14, 5, + 25, 18, 15, 4, 53, 62, 35, 40, 2, 9, 20, 31, 46, 37, 56, 51, + 0, 36, 11, 47, 22, 50, 29, 57, 44, 8, 39, 3, 58, 30, 49, 21, + 27, 63, 16, 52, 13, 41, 6, 34, 55, 19, 60, 24, 33, 5, 42, 14, + 54, 18, 61, 25, 32, 4, 43, 15, 26, 62, 17, 53, 12, 40, 7, 35, + 45, 9, 38, 2, 59, 31, 48, 20, 1, 37, 10, 46, 23, 51, 28, 56, + 0, 18, 36, 54, 11, 25, 47, 61, 22, 4, 50, 32, 29, 15, 57, 43, + 44, 62, 8, 26, 39, 53, 3, 17, 58, 40, 30, 12, 49, 35, 21, 7, + 27, 9, 63, 45, 16, 2, 52, 38, 13, 31, 41, 59, 6, 20, 34, 48, + 55, 37, 19, 1, 60, 46, 24, 10, 33, 51, 5, 23, 42, 56, 14, 28, + 0, 9, 18, 27, 36, 45, 54, 63, 11, 2, 25, 16, 47, 38, 61, 52, + 22, 31, 4, 13, 50, 59, 32, 41, 29, 20, 15, 6, 57, 48, 43, 34, + 44, 37, 62, 55, 8, 1, 26, 19, 39, 46, 53, 60, 3, 10, 17, 24, + 58, 51, 40, 33, 30, 23, 12, 5, 49, 56, 35, 42, 21, 28, 7, 14, + 0, 37, 9, 44, 18, 55, 27, 62, 36, 1, 45, 8, 54, 19, 63, 26, + 11, 46, 2, 39, 25, 60, 16, 53, 47, 10, 38, 3, 61, 24, 52, 17, + 22, 51, 31, 58, 4, 33, 13, 40, 50, 23, 59, 30, 32, 5, 41, 12, + 29, 56, 20, 49, 15, 42, 6, 35, 57, 28, 48, 21, 43, 14, 34, 7, + 0, 51, 37, 22, 9, 58, 44, 31, 18, 33, 55, 4, 27, 40, 62, 13, + 36, 23, 1, 50, 45, 30, 8, 59, 54, 5, 19, 32, 63, 12, 26, 41, + 11, 56, 46, 29, 2, 49, 39, 20, 25, 42, 60, 15, 16, 35, 53, 6, + 47, 28, 10, 57, 38, 21, 3, 48, 61, 14, 24, 43, 52, 7, 17, 34, + 0, 56, 51, 11, 37, 29, 22, 46, 9, 49, 58, 2, 44, 20, 31, 39, + 18, 42, 33, 25, 55, 15, 4, 60, 27, 35, 40, 16, 62, 6, 13, 53, + 36, 28, 23, 47, 1, 57, 50, 10, 45, 21, 30, 38, 8, 48, 59, 3, + 54, 14, 5, 61, 19, 43, 32, 24, 63, 7, 12, 52, 26, 34, 41, 17, + 0, 28, 56, 36, 51, 47, 11, 23, 37, 57, 29, 1, 22, 10, 46, 50, + 9, 21, 49, 45, 58, 38, 2, 30, 44, 48, 20, 8, 31, 3, 39, 59, + 18, 14, 42, 54, 33, 61, 25, 5, 55, 43, 15, 19, 4, 24, 60, 32, + 27, 7, 35, 63, 40, 52, 16, 12, 62, 34, 6, 26, 13, 17, 53, 41, + 0, 14, 28, 18, 56, 54, 36, 42, 51, 61, 47, 33, 11, 5, 23, 25, + 37, 43, 57, 55, 29, 19, 1, 15, 22, 24, 10, 4, 46, 32, 50, 60, + 9, 7, 21, 27, 49, 63, 45, 35, 58, 52, 38, 40, 2, 12, 30, 16, + 44, 34, 48, 62, 20, 26, 8, 6, 31, 17, 3, 13, 39, 41, 59, 53, + 0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45, + 51, 52, 61, 58, 47, 40, 33, 38, 11, 12, 5, 2, 23, 16, 25, 30, + 37, 34, 43, 44, 57, 62, 55, 48, 29, 26, 19, 20, 1, 6, 15, 8, + 22, 17, 24, 31, 10, 13, 4, 3, 46, 41, 32, 39, 50, 53, 60, 59, + 0, 34, 7, 37, 14, 44, 9, 43, 28, 62, 27, 57, 18, 48, 21, 55, + 56, 26, 63, 29, 54, 20, 49, 19, 36, 6, 35, 1, 42, 8, 45, 15, + 51, 17, 52, 22, 61, 31, 58, 24, 47, 13, 40, 10, 33, 3, 38, 4, + 11, 41, 12, 46, 5, 39, 2, 32, 23, 53, 16, 50, 25, 59, 30, 60, + 0, 17, 34, 51, 7, 22, 37, 52, 14, 31, 44, 61, 9, 24, 43, 58, + 28, 13, 62, 47, 27, 10, 57, 40, 18, 3, 48, 33, 21, 4, 55, 38, + 56, 41, 26, 11, 63, 46, 29, 12, 54, 39, 20, 5, 49, 32, 19, 2, + 36, 53, 6, 23, 35, 50, 1, 16, 42, 59, 8, 25, 45, 60, 15, 30, + 0, 41, 17, 56, 34, 11, 51, 26, 7, 46, 22, 63, 37, 12, 52, 29, + 14, 39, 31, 54, 44, 5, 61, 20, 9, 32, 24, 49, 43, 2, 58, 19, + 28, 53, 13, 36, 62, 23, 47, 6, 27, 50, 10, 35, 57, 16, 40, 1, + 18, 59, 3, 42, 48, 25, 33, 8, 21, 60, 4, 45, 55, 30, 38, 15, + 0, 53, 41, 28, 17, 36, 56, 13, 34, 23, 11, 62, 51, 6, 26, 47, + 7, 50, 46, 27, 22, 35, 63, 10, 37, 16, 12, 57, 52, 1, 29, 40, + 14, 59, 39, 18, 31, 42, 54, 3, 44, 25, 5, 48, 61, 8, 20, 33, + 9, 60, 32, 21, 24, 45, 49, 4, 43, 30, 2, 55, 58, 15, 19, 38, + 0, 59, 53, 14, 41, 18, 28, 39, 17, 42, 36, 31, 56, 3, 13, 54, + 34, 25, 23, 44, 11, 48, 62, 5, 51, 8, 6, 61, 26, 33, 47, 20, + 7, 60, 50, 9, 46, 21, 27, 32, 22, 45, 35, 24, 63, 4, 10, 49, + 37, 30, 16, 43, 12, 55, 57, 2, 52, 15, 1, 58, 29, 38, 40, 19, + 0, 60, 59, 7, 53, 9, 14, 50, 41, 21, 18, 46, 28, 32, 39, 27, + 17, 45, 42, 22, 36, 24, 31, 35, 56, 4, 3, 63, 13, 49, 54, 10, + 34, 30, 25, 37, 23, 43, 44, 16, 11, 55, 48, 12, 62, 2, 5, 57, + 51, 15, 8, 52, 6, 58, 61, 1, 26, 38, 33, 29, 47, 19, 20, 40, + 0, 30, 60, 34, 59, 37, 7, 25, 53, 43, 9, 23, 14, 16, 50, 44, + 41, 55, 21, 11, 18, 12, 46, 48, 28, 2, 32, 62, 39, 57, 27, 5, + 17, 15, 45, 51, 42, 52, 22, 8, 36, 58, 24, 6, 31, 1, 35, 61, + 56, 38, 4, 26, 3, 29, 63, 33, 13, 19, 49, 47, 54, 40, 10, 20, + 0, 15, 30, 17, 60, 51, 34, 45, 59, 52, 37, 42, 7, 8, 25, 22, + 53, 58, 43, 36, 9, 6, 23, 24, 14, 1, 16, 31, 50, 61, 44, 35, + 41, 38, 55, 56, 21, 26, 11, 4, 18, 29, 12, 3, 46, 33, 48, 63, + 28, 19, 2, 13, 32, 47, 62, 49, 39, 40, 57, 54, 27, 20, 5, 10, + 0, 38, 15, 41, 30, 56, 17, 55, 60, 26, 51, 21, 34, 4, 45, 11, + 59, 29, 52, 18, 37, 3, 42, 12, 7, 33, 8, 46, 25, 63, 22, 48, + 53, 19, 58, 28, 43, 13, 36, 2, 9, 47, 6, 32, 23, 49, 24, 62, + 14, 40, 1, 39, 16, 54, 31, 57, 50, 20, 61, 27, 44, 10, 35, 5, + 0, 19, 38, 53, 15, 28, 41, 58, 30, 13, 56, 43, 17, 2, 55, 36, + 60, 47, 26, 9, 51, 32, 21, 6, 34, 49, 4, 23, 45, 62, 11, 24, + 59, 40, 29, 14, 52, 39, 18, 1, 37, 54, 3, 16, 42, 57, 12, 31, + 7, 20, 33, 50, 8, 27, 46, 61, 25, 10, 63, 44, 22, 5, 48, 35, + 0, 40, 19, 59, 38, 14, 53, 29, 15, 39, 28, 52, 41, 1, 58, 18, + 30, 54, 13, 37, 56, 16, 43, 3, 17, 57, 2, 42, 55, 31, 36, 12, + 60, 20, 47, 7, 26, 50, 9, 33, 51, 27, 32, 8, 21, 61, 6, 46, + 34, 10, 49, 25, 4, 44, 23, 63, 45, 5, 62, 22, 11, 35, 24, 48, + 0, 20, 40, 60, 19, 7, 59, 47, 38, 50, 14, 26, 53, 33, 29, 9, + 15, 27, 39, 51, 28, 8, 52, 32, 41, 61, 1, 21, 58, 46, 18, 6, + 30, 10, 54, 34, 13, 25, 37, 49, 56, 44, 16, 4, 43, 63, 3, 23, + 17, 5, 57, 45, 2, 22, 42, 62, 55, 35, 31, 11, 36, 48, 12, 24, + 0, 10, 20, 30, 40, 34, 60, 54, 19, 25, 7, 13, 59, 49, 47, 37, + 38, 44, 50, 56, 14, 4, 26, 16, 53, 63, 33, 43, 29, 23, 9, 3, + 15, 5, 27, 17, 39, 45, 51, 57, 28, 22, 8, 2, 52, 62, 32, 42, + 41, 35, 61, 55, 1, 11, 21, 31, 58, 48, 46, 36, 18, 24, 6, 12, + 0, 5, 10, 15, 20, 17, 30, 27, 40, 45, 34, 39, 60, 57, 54, 51, + 19, 22, 25, 28, 7, 2, 13, 8, 59, 62, 49, 52, 47, 42, 37, 32, + 38, 35, 44, 41, 50, 55, 56, 61, 14, 11, 4, 1, 26, 31, 16, 21, + 53, 48, 63, 58, 33, 36, 43, 46, 29, 24, 23, 18, 9, 12, 3, 6, + 0, 35, 5, 38, 10, 41, 15, 44, 20, 55, 17, 50, 30, 61, 27, 56, + 40, 11, 45, 14, 34, 1, 39, 4, 60, 31, 57, 26, 54, 21, 51, 16, + 19, 48, 22, 53, 25, 58, 28, 63, 7, 36, 2, 33, 13, 46, 8, 43, + 59, 24, 62, 29, 49, 18, 52, 23, 47, 12, 42, 9, 37, 6, 32, 3, + 0, 48, 35, 19, 5, 53, 38, 22, 10, 58, 41, 25, 15, 63, 44, 28, + 20, 36, 55, 7, 17, 33, 50, 2, 30, 46, 61, 13, 27, 43, 56, 8, + 40, 24, 11, 59, 45, 29, 14, 62, 34, 18, 1, 49, 39, 23, 4, 52, + 60, 12, 31, 47, 57, 9, 26, 42, 54, 6, 21, 37, 51, 3, 16, 32, + 0, 24, 48, 40, 35, 59, 19, 11, 5, 29, 53, 45, 38, 62, 22, 14, + 10, 18, 58, 34, 41, 49, 25, 1, 15, 23, 63, 39, 44, 52, 28, 4, + 20, 12, 36, 60, 55, 47, 7, 31, 17, 9, 33, 57, 50, 42, 2, 26, + 30, 6, 46, 54, 61, 37, 13, 21, 27, 3, 43, 51, 56, 32, 8, 16, + 0, 12, 24, 20, 48, 60, 40, 36, 35, 47, 59, 55, 19, 31, 11, 7, + 5, 9, 29, 17, 53, 57, 45, 33, 38, 42, 62, 50, 22, 26, 14, 2, + 10, 6, 18, 30, 58, 54, 34, 46, 41, 37, 49, 61, 25, 21, 1, 13, + 15, 3, 23, 27, 63, 51, 39, 43, 44, 32, 52, 56, 28, 16, 4, 8, + 0, 6, 12, 10, 24, 30, 20, 18, 48, 54, 60, 58, 40, 46, 36, 34, + 35, 37, 47, 41, 59, 61, 55, 49, 19, 21, 31, 25, 11, 13, 7, 1, + 5, 3, 9, 15, 29, 27, 17, 23, 53, 51, 57, 63, 45, 43, 33, 39, + 38, 32, 42, 44, 62, 56, 50, 52, 22, 16, 26, 28, 14, 8, 2, 4, + 0, 3, 6, 5, 12, 15, 10, 9, 24, 27, 30, 29, 20, 23, 18, 17, + 48, 51, 54, 53, 60, 63, 58, 57, 40, 43, 46, 45, 36, 39, 34, 33, + 35, 32, 37, 38, 47, 44, 41, 42, 59, 56, 61, 62, 55, 52, 49, 50, + 19, 16, 21, 22, 31, 28, 25, 26, 11, 8, 13, 14, 7, 4, 1, 2, + 0, 32, 3, 35, 6, 38, 5, 37, 12, 44, 15, 47, 10, 42, 9, 41, + 24, 56, 27, 59, 30, 62, 29, 61, 20, 52, 23, 55, 18, 50, 17, 49, + 48, 16, 51, 19, 54, 22, 53, 21, 60, 28, 63, 31, 58, 26, 57, 25, + 40, 8, 43, 11, 46, 14, 45, 13, 36, 4, 39, 7, 34, 2, 33, 1, + 0, 16, 32, 48, 3, 19, 35, 51, 6, 22, 38, 54, 5, 21, 37, 53, + 12, 28, 44, 60, 15, 31, 47, 63, 10, 26, 42, 58, 9, 25, 41, 57, + 24, 8, 56, 40, 27, 11, 59, 43, 30, 14, 62, 46, 29, 13, 61, 45, + 20, 4, 52, 36, 23, 7, 55, 39, 18, 2, 50, 34, 17, 1, 49, 33, + 0, 8, 16, 24, 32, 40, 48, 56, 3, 11, 19, 27, 35, 43, 51, 59, + 6, 14, 22, 30, 38, 46, 54, 62, 5, 13, 21, 29, 37, 45, 53, 61, + 12, 4, 28, 20, 44, 36, 60, 52, 15, 7, 31, 23, 47, 39, 63, 55, + 10, 2, 26, 18, 42, 34, 58, 50, 9, 1, 25, 17, 41, 33, 57, 49, + 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, + 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, + 6, 2, 14, 10, 22, 18, 30, 26, 38, 34, 46, 42, 54, 50, 62, 58, + 5, 1, 13, 9, 21, 17, 29, 25, 37, 33, 45, 41, 53, 49, 61, 57, + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, + 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, + 3, 1, 7, 5, 11, 9, 15, 13, 19, 17, 23, 21, 27, 25, 31, 29, + 35, 33, 39, 37, 43, 41, 47, 45, 51, 49, 55, 53, 59, 57, 63, 61 +}; + +const qracode qra_13_64_64_irr_e = { + qra_K, + qra_N, + qra_m, + qra_M, + qra_a, + qra_NC, + qra_V, + qra_C, + qra_NMSG, + qra_MAXVDEG, + qra_MAXCDEG, + QRATYPE_CRCPUNCTURED, + qra_R, + CODE_NAME, + qra_acc_input_idx, + qra_acc_input_wlog, + qra_log, + qra_exp, + qra_msgw, + qra_vdeg, + qra_cdeg, + qra_v2cmidx, + qra_c2vmidx, + qra_pmat +}; + +#undef qra_K +#undef qra_N +#undef qra_m +#undef qra_M +#undef qra_a +#undef qra_NC +#undef qra_V +#undef qra_C +#undef qra_NMSG +#undef qra_MAXVDEG +#undef qra_MAXCDEG +#undef qra_R +#undef CODE_NAME \ No newline at end of file diff --git a/lib/qra/qracodes/qra13_64_64_irr_e.h b/lib/qra/qracodes/qra13_64_64_irr_e.h new file mode 100644 index 00000000..d24421d2 --- /dev/null +++ b/lib/qra/qracodes/qra13_64_64_irr_e.h @@ -0,0 +1,39 @@ +// qra13_64_64_irr_e.h +// Code tables and defines for Q-ary RA code (13,64) over GF(64) +// Code Name: qra13_64_64_irr_e +// (13,64) RA Code over GF(64) RF=[3x4 4x4 6x1 3x2 5x1 7x1]/18 + +// (c) 2016 - Nico Palermo - IV3NWV - Microtelecom Srl, Italy + +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +#ifndef _qra13_64_64_irr_e_h +#define _qra13_64_64_irr_e_h + +#include "qracodes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const qracode qra_13_64_64_irr_e; + +#ifdef __cplusplus +} +#endif + +#endif // _qra13_64_64_irr_e_h diff --git a/lib/qra/qracodes/qracodes.c b/lib/qra/qracodes/qracodes.c new file mode 100644 index 00000000..748a9c9c --- /dev/null +++ b/lib/qra/qracodes/qracodes.c @@ -0,0 +1,474 @@ +// qracodes.c +// Q-ary RA codes encoding/decoding functions +// +// (c) 2016 - Nico Palermo, IV3NWV - Microtelecom Srl, Italy +// ------------------------------------------------------------------------------ +// This file is part of the qracodes project, a Forward Error Control +// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. +// +// qracodes 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 of the License, or +// (at your option) any later version. +// qracodes 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 qracodes source distribution. +// If not, see . + +#include +#include + +#include "npfwht.h" +#include "pdmath.h" + +#include "qracodes.h" + +int qra_encode(const qracode *pcode, int *y, const int *x) +{ + int k,j,kk,jj; + int t, chk = 0; + + const int K = pcode->K; + const int M = pcode->M; + const int NC= pcode->NC; + const int a = pcode->a; + const int *acc_input_idx = pcode->acc_input_idx; + const int *acc_input_wlog = pcode->acc_input_wlog; + const int *gflog = pcode->gflog; + const int *gfexp = pcode->gfexp; + + // copy the systematic symbols to destination + memcpy(y,x,K*sizeof(int)); + + y = y+K; // point to check symbols + + // compute the code check symbols as a weighted accumulation of a permutated + // sequence of the (repeated) systematic input symbols: + // chk(k+1) = x(idx(k))*alfa^(logw(k)) + chk(k) + // (all operations performed over GF(M)) + + if (a==1) { // grouping factor = 1 + for (k=0;k 1 + for (k=0;k80.f) // avoid floating point exp() overflows + v=80.f; + + src[nitems] = (float)exp(v); + } +} + + +float qra_mfskbesselmetric(float *pix, const float *rsq, const int m, const int N, float EsNoMetric) +{ + // Computes the codeword symbols intrinsic probabilities + // given the square of the received input amplitudes. + + // The input vector rqs must be a linear array of size M*N, where M=2^m, + // containing the squared amplitudes (rp*rp+rq*rq) of the input samples + + // First symbol amplitudes should be stored in the first M positions, + // second symbol amplitudes stored at positions [M ... 2*M-1], and so on. + + // Output vector is the intrinsic symbol metric (the probability distribution) + // assuming that symbols are transmitted using a M-FSK modulation + // and incoherent demodulation. + + // As the input Es/No is generally unknown (as it cannot be exstimated accurately + // when the codeword length is few tens symbols) but an exact metric requires it + // we simply fix it to a predefined EsNoMetric value so that the metric is what + // expected at that specific value. + // The metric computed in this way is optimal only at this predefined Es/No value, + // nevertheless it is usually better than a generic parameter-free metric which + // makes no assumptions on the input Es/No. + + // returns the estimated noise standard deviation + + int k; + float rsum = 0.f; + float sigmaest, cmetric; + + const int M = 1<M; + const int qra_m = pcode->m; + const int qra_V = pcode->V; + const int qra_MAXVDEG = pcode->MAXVDEG; + const int *qra_vdeg = pcode->vdeg; + const int qra_C = pcode->C; + const int qra_MAXCDEG = pcode->MAXCDEG; + const int *qra_cdeg = pcode->cdeg; + const int *qra_v2cmidx = pcode->v2cmidx; + const int *qra_c2vmidx = pcode->c2vmidx; + const int *qra_pmat = pcode->gfpmat; + const int *qra_msgw = pcode->msgw; + +// float msgout[qra_M]; // buffer to store temporary results + float msgout[QRACODE_MAX_M]; // we use a fixed size in order to avoid mallocs + + float totex; // total extrinsic information + int nit; // current iteration + int nv; // current variable + int nc; // current check + int k,kk; // loop indexes + + int ndeg; // current node degree + int msgbase; // current offset in the table of msg indexes + int imsg; // current message index + int wmsg; // current message weight + + int rc = -1; // rc>=0 extrinsic converged to 1 at iteration rc (rc=0..maxiter-1) + // rc=-1 no convergence in the given number of iterations + // rc=-2 error in the code tables (code checks degrees must be >1) + // rc=-3 M is larger than QRACODE_MAX_M + + + + if (qra_M>QRACODE_MAX_M) + return -3; + + // message initialization ------------------------------------------------------- + + // init c->v variable intrinsic msgs + pd_init(C2VMSG(0),pix,qra_M*qra_V); + + // init the v->c messages directed to code factors (k=1..ndeg) with the intrinsic info + for (nv=0;nvc + for (k=1;kv step ----------------------------------------------------- + // Computes messages from code checks to code variables. + // As the first qra_V checks are associated with intrinsic information + // (the code tables have been constructed in this way) + // we need to do this step only for code checks in the range [qra_V..qra_C) + + // The convolutions of probability distributions over the alphabet of a finite field GF(qra_M) + // are performed with a fast convolution algorithm over the given field. + // + // I.e. given the code check x1+x2+x3 = 0 (with x1,x2,x3 in GF(2^m)) + // and given Prob(x2) and Prob(x3), we have that: + // Prob(x1=X1) = Prob((x2+x3)=X1) = sum((Prob(x2=X2)*Prob(x3=(X1+X2))) for all the X2s in the field + // This translates to Prob(x1) = IWHT(WHT(Prob(x2))*WHT(Prob(x3))) + // where WHT and IWHT are the direct and inverse Walsh-Hadamard transforms of the argument. + // Note that the WHT and the IWHF differs only by a multiplicative coefficent and since in this step + // we don't need that the output distribution is normalized we use the relationship + // Prob(x1) =(proportional to) WH(WH(Prob(x2))*WH(Prob(x3))) + + // In general given the check code x1+x2+x3+..+xm = 0 + // the output distribution of a variable given the distributions of the other m-1 variables + // is the inverse WHT of the product of the WHTs of the distribution of the other m-1 variables + // The complexity of this algorithm scales with M*log2(M) instead of the M^2 complexity of + // the brute force approach (M=size of the alphabet) + + for (nc=qra_V;nc1) + return -2; // bad code tables + + msgbase = nc*qra_MAXCDEG; // base to msg index row for the current node + + // transforms inputs in the Walsh-Hadamard "frequency" domain + // v->c -> fwht(v->c) + for (k=0;kv = prod(fwht(v->c)) + // TODO: we assume that checks degrees are not larger than three but + // if they are larger the products can be computed more efficiently + for (kk=0;kkc steps when multipling + // small fp numbers + msgout[0]+=1E-7f; // TODO: define the bias accordingly to the field size + + np_fwht(qra_m,msgout,msgout); + + // inverse weight and output + imsg = qra_c2vmidx[msgbase+k]; // current output msg index + wmsg = qra_msgw[imsg]; // current msg weight + + if (wmsg==0) + pd_init(C2VMSG(imsg),msgout,qra_M); + else + // output p(alfa^(-w)*x) + pd_bwdperm(C2VMSG(imsg),msgout, MSGPERM(wmsg), qra_M); + + } // for (k=0;kc step ----------------------------------------------------- + for (nv=0;nvc msg = prod(c->v) + // TODO: factor factors to reduce the number of computations for high degree nodes + for (kk=0;kkc are null + // normalize output to a probability distribution + if (pd_norm(msgout,qra_m)<=0) { + // dump msgin; + printf("warning: v->c pd with invalid norm. nit=%d nv=%d k=%d\n",nit,nv,k); + for (kk=0;kk(1.*(qra_V)-0.01)) { + // the total maximum extrinsic information of each symbol in the codeword + // is very close to one. This means that we have reached the (1,1) point in the + // code EXIT chart(s) and we have successfully decoded the input. + rc = nit; + break; // remove the break to evaluate the decoder speed performance as a function of the max iterations number) + } + + } // for (nit=0;nitM; + const int qra_m = pcode->m; + const int qra_K = pcode->K; + + int k; + + for (k=0;k. + +#ifndef _qracodes_h_ +#define _qracodes_h_ + +// type of codes +#define QRATYPE_NORMAL 0x00 // normal code +#define QRATYPE_CRC 0x01 // code with crc - last information symbol is a CRC +#define QRATYPE_CRCPUNCTURED 0x02 // the CRC symbol is punctured (not sent along the channel) + + +typedef struct { + // code parameters + const int K; // number of information symbols + const int N; // codeword length in symbols + const int m; // bits/symbol + const int M; // Symbol alphabet cardinality (2^m) + const int a; // code grouping factor + const int NC; // number of check symbols (N-K) + const int V; // number of variables in the code graph (N) + const int C; // number of factors in the code graph (N +(N-K)+1) + const int NMSG; // number of msgs in the code graph + const int MAXVDEG; // maximum variable degree + const int MAXCDEG; // maximum factor degree + const int type; // see QRATYPE_xx defines + const float R; // code rate (K/N) + const char name[64]; // code name + // tables used by the encoder + const int *acc_input_idx; + const int *acc_input_wlog; + const int *gflog; + const int *gfexp; + // tables used by the decoder ------------------------- + const int *msgw; + const int *vdeg; + const int *cdeg; + const int *v2cmidx; + const int *c2vmidx; + const int *gfpmat; +} qracode; +// Uncomment the header file of the code which needs to be tested + +//#include "qra12_63_64_irr_b.h" // irregular code (12,63) over GF(64) +//#include "qra13_64_64_irr_e.h" // irregular code with good performance and best UER protection at AP56 +//#include "qra13_64_64_reg_a.h" // regular code with good UER but perf. inferior to that of code qra12_63_64_irr_b + +#ifdef __cplusplus +extern "C" { +#endif + +int qra_encode(const qracode *pcode, int *y, const int *x); +float qra_mfskbesselmetric(float *pix, const float *rsq, const int m, const int N, float EsNoMetric); +int qra_extrinsic(const qracode *pcode, float *pex, const float *pix, int maxiter,float *qra_v2cmsg,float *qra_c2vmsg); +void qra_mapdecode(const qracode *pcode, int *xdec, float *pex, const float *pix); + +#ifdef __cplusplus +} +#endif + +#endif // _qracodes_h_ diff --git a/lib/qra64a.f90 b/lib/qra64a.f90 new file mode 100644 index 00000000..2f128ac0 --- /dev/null +++ b/lib/qra64a.f90 @@ -0,0 +1,158 @@ +subroutine qra64a(dd,npts,nutc,nf1,nf2,nfqso,ntol,mode64,minsync,ndepth, & + emedelay,mycall_12,hiscall_12,hisgrid_6,sync,nsnr,dtx,nfreq,decoded,nft) + + use packjt + use timer_module, only: timer + + parameter (NMAX=60*12000,LN=1152*63) + character decoded*22 + character*12 mycall_12,hiscall_12 + character*6 mycall,hiscall,hisgrid_6 + character*4 hisgrid + logical ltext + complex c00(0:720000) !Complex spectrum of dd() + complex c0(0:720000) !Complex data for dd() + real a(3) + real dd(NMAX) !Raw data sampled at 12000 Hz + real s3(LN) !Symbol spectra + real s3a(LN) !Symbol spectra + integer dat4(12) !Decoded message (as 12 integers) + integer dat4x(12) + integer nap(0:11) + data nap/0,2,3,2,3,4,2,3,6,4,6,6/ + data nc1z/-1/,nc2z/-1/,ng2z/-1/,maxaptypez/-1/ + save + + call timer('qra64a ',0) + irc=-1 + decoded=' ' + nft=99 + if(nfqso.lt.nf1 .or. nfqso.gt.nf2) go to 900 + + mycall=mycall_12(1:6) !### May need fixing ### + hiscall=hiscall_12(1:6) + hisgrid=hisgrid_6(1:4) + call packcall(mycall,nc1,ltext) + call packcall(hiscall,nc2,ltext) + call packgrid(hisgrid,ng2,ltext) + nSubmode=0 + if(mode64.eq.2) nSubmode=1 + if(mode64.eq.4) nSubmode=2 + if(mode64.eq.8) nSubmode=3 + if(mode64.eq.16) nSubmode=4 + b90=1.0 + nFadingModel=1 + maxaptype=4 + if(iand(ndepth,64).ne.0) maxaptype=5 + if(nc1.ne.nc1z .or. nc2.ne.nc2z .or. ng2.ne.ng2z .or. & + maxaptype.ne.maxaptypez) then + do naptype=0,maxaptype + if(naptype.eq.2 .and. maxaptype.eq.4) cycle + call qra64_dec(s3,nc1,nc2,ng2,naptype,1,nSubmode,b90, & + nFadingModel,dat4,snr2,irc) + enddo + nc1z=nc1 + nc2z=nc2 + ng2z=ng2 + maxaptypez=maxaptype + endif + naptype=maxaptype + + call ana64(dd,npts,c00) + npts2=npts/2 + + call timer('sync64 ',0) + call sync64(c00,nf1,nf2,nfqso,ntol,mode64,emedelay,dtx,f0,jpk0,sync, & + sync2,width) + call timer('sync64 ',1) + nfreq=nint(f0) + if(mode64.eq.1 .and. minsync.ge.0 .and. (sync-7.0).lt.minsync) go to 900 +! if((sync-3.4).lt.float(minsync) .or.width.gt.340.0) go to 900 + a=0. + a(1)=-f0 + call twkfreq(c00,c0,npts2,6000.0,a) + + irc=-99 + s3lim=20. + itz=11 + if(mode64.eq.4) itz=9 + if(mode64.eq.2) itz=7 + if(mode64.eq.1) itz=5 + + LL=64*(mode64+2) + NN=63 + napmin=99 + do itry0=1,5 + idt=itry0/2 + if(mod(itry0,2).eq.0) idt=-idt + jpk=jpk0 + 750*idt + call spec64(c0,npts2,mode64,jpk,s3a,LL,NN) + call pctile(s3a,LL*NN,40,base) + s3a=s3a/base + where(s3a(1:LL*NN)>s3lim) s3a(1:LL*NN)=s3lim + do iter=itz,0,-2 + b90=1.728**iter + if(b90.gt.230.0) cycle + if(b90.lt.0.15*width) exit + s3(1:LL*NN)=s3a(1:LL*NN) + call timer('qra64_de',0) + call qra64_dec(s3,nc1,nc2,ng2,naptype,0,nSubmode,b90, & + nFadingModel,dat4,snr2,irc) + call timer('qra64_de',1) + if(irc.eq.0) go to 10 + if(irc.gt.0) call badmsg(irc,dat4,nc1,nc2,ng2) + iirc=max(0,min(irc,11)) + if(irc.gt.0 .and. nap(iirc).lt.napmin) then + dat4x=dat4 + b90x=b90 + snr2x=snr2 + napmin=nap(iirc) + irckeep=irc + dtxkeep=jpk/6000.0 - 1.0 + itry0keep=itry0 + iterkeep=iter + endif + enddo + if(irc.eq.0) exit + enddo + + if(napmin.ne.99) then + dat4=dat4x + b90=b90x + snr2=snr2x + irc=irckeep + dtx=dtxkeep + itry0=itry0keep + iter=iterkeep + endif +10 decoded=' ' + + if(irc.ge.0) then + call unpackmsg(dat4,decoded,.false.,' ') !Unpack the user message + call fmtmsg(decoded,iz) + if(index(decoded,"000AAA ").ge.1) then + ! Suppress a certain type of garbage decode. + decoded=' ' + irc=-1 + endif + nft=100 + irc + nsnr=nint(snr2) + else + snr2=0. + endif + +900 if(irc.lt.0) then + sy=max(1.0,sync) + if(nSubmode.eq.0) nsnr=nint(10.0*log10(sy)-35.0) !A + if(nSubmode.eq.1) nsnr=nint(10.0*log10(sy)-34.0) !B + if(nSubmode.eq.2) nsnr=nint(10.0*log10(sy)-29.0) !C + if(nSubmode.eq.3) nsnr=nint(10.0*log10(sy)-29.0) !D + if(nSubmode.eq.4) nsnr=nint(10.0*log10(sy)-24.0) !E + endif + call timer('qra64a ',1) + +! write(71,3001) nutc,dtx,f0,sync,sync2,width,minsync,decoded +!3001 format(i4.4,f7.2,4f8.1,i3,2x,a22) + + return +end subroutine qra64a diff --git a/lib/qra64code.f90 b/lib/qra64code.f90 new file mode 100644 index 00000000..0f9c16bf --- /dev/null +++ b/lib/qra64code.f90 @@ -0,0 +1,66 @@ +program QRA64code + +! Provides examples of message packing, bit and symbol ordering, +! QRA (63,12) encoding, and other necessary details of the QRA64 +! protocol. + + use packjt + character*22 msg,msg0,msg1,decoded,cok*3,msgtype*10,arg*12 + character*6 mycall + logical ltext + integer dgen(12),sent(63),dec(12) + integer icos7(0:6) + data icos7/2,5,6,0,4,1,3/ !Defines a 7x7 Costas array + + include 'testmsg.f90' + + nargs=iargc() + if(nargs.lt.1) then + print*,'Usage: qra64code "message"' + print*,' qra64code -t' + go to 999 + endif + + call getarg(1,msg) !Get message from command line + nmsg=1 + if(msg(1:2).eq."-t") nmsg=NTEST + + write(*,1010) +1010 format(" Message Decoded Err? Type"/74("-")) + + do imsg=1,nmsg + if(nmsg.gt.1) msg=testmsg(imsg) + call fmtmsg(msg,iz) !To upper, collapse mult blanks + msg0=msg !Input message + call chkmsg(msg,cok,nspecial,flip) !See if it includes "OOO" report + msg1=msg !Message without "OOO" + call packmsg(msg1,dgen,itype,.false.) !Pack message into 12 six-bit bytes + msgtype="" + if(itype.eq.1) msgtype="Std Msg" + if(itype.eq.2) msgtype="Type 1 pfx" + if(itype.eq.3) msgtype="Type 1 sfx" + if(itype.eq.4) msgtype="Type 2 pfx" + if(itype.eq.5) msgtype="Type 2 sfx" + if(itype.eq.6) msgtype="Free text" + + call qra64_enc(dgen,sent) !Encode using QRA64 + + call unpackmsg(dgen,decoded,.false.,' ') !Unpack the user message + call fmtmsg(decoded,iz) + ii=imsg + write(*,1020) ii,msg0,decoded,itype,msgtype +1020 format(i4,1x,a22,2x,a22,4x,i3,": ",a13) + enddo + + if(nmsg.eq.1) then + write(*,1030) dgen +1030 format(/'Packed message, 6-bit symbols ',12i3) !Display packed symbols + + write(*,1040) sent +1040 format(/'Information-carrying channel symbols'/(i5,29i3)) + + write(*,1050) 10*icos7,sent(1:32),10*icos7,sent(33:63),10*icos7 +1050 format(/'Channel symbols including sync'/(i5,29i3)) + endif + +999 end program QRA64code diff --git a/lib/qratest.f90 b/lib/qratest.f90 new file mode 100644 index 00000000..2b5de8c1 --- /dev/null +++ b/lib/qratest.f90 @@ -0,0 +1,54 @@ +program qratest + + parameter (NMAX=60*12000) + real dd(NMAX) + character arg*8,mycall*12,hiscall*12,hisgrid*6,decoded*22 + character c*1 + logical loop + + nargs=iargc() + if(nargs.lt.1 .or. nargs.gt.4) then + print*,'Usage: qratest nfile [sync f0 fTol]' + go to 999 + endif + call getarg(1,arg) + read(arg,*) nfile + loop=arg(1:1).eq.'+' + minsync0=-1 + nfqso0=-1 + ntol0=-1 + if(nargs.gt.1) then + call getarg(2,arg) + read(arg,*) minsync0 + call getarg(3,arg) + read(arg,*) nfqso0 + call getarg(4,arg) + read(arg,*) ntol0 + endif + ndepth=3 + nft=99 + + open(60,file='qra64_data.bin',access='stream') + + do ifile=1,999 + read(60,end=999) dd,npts,nutc,nf1,nf2,nfqso,ntol,mode64,minsync,ndepth, & + mycall,hiscall,hisgrid + if(ifile.lt.nfile) cycle + + if(minsync0.ne.-1) minsync=minsync0 + if(nfqso0.ne.-1) nfqso=nfqso0 + if(ntol0.ne.-1) ntol=ntol0 + + call qra64a(dd,npts,nutc,nf1,nf2,nfqso,ntol,mode64,minsync,ndepth, & + mycall,hiscall,hisgrid,sync,nsnr,dtx,nfreq,decoded,nft) + c='a' + if(mode64.eq.2) c='b' + if(mode64.eq.4) c='c' + if(mode64.eq.8) c='d' + if(mode64.eq.16) c='e' + write(*,1000) ifile,c,nutc,nsnr,dtx,nfreq,decoded,nft-100,sync-3.4 +1000 format(i4,1x,a1,1x,i4.4,i4,f6.2,i5,1x,a22,i3,f6.2) + if(ifile.eq.nfile .and. (.not.loop)) exit + enddo + +999 end program qratest diff --git a/lib/readwav.f90 b/lib/readwav.f90 new file mode 100644 index 00000000..ebc30c9a --- /dev/null +++ b/lib/readwav.f90 @@ -0,0 +1,71 @@ +! +! readwav - open and read the header of a WAV format file +! +! On successful exit the file is left positioned at the start of the +! data. +! +! Example of usage: +! +! use readwav +! integer*2 sample +! type(wav_header) wav +! call wav%read ('file.wav') +! write (*,*) 'Sample rate is: ', wav%audio_format%sample_rate +! do i=0,wav%data_size +! read (unit=wav%lun) sample +! ! process sample +! end do +! +module readwav + implicit none + + type format_chunk + integer*2 audio_format + integer*2 num_channels + integer sample_rate + integer byte_rate + integer*2 block_align + integer*2 bits_per_sample + end type format_chunk + + type, public :: wav_header + integer :: lun + type(format_chunk) :: audio_format + integer :: data_size + contains + procedure :: read + end type wav_header + + private +contains + subroutine read (this, filename) + implicit none + + type riff_descriptor + character(len=4) :: id + integer :: size + end type riff_descriptor + + class(wav_header), intent(inout) :: this + character(len=*), intent(in) :: filename + + integer :: filepos + type(riff_descriptor) :: desc + character(len=4) :: riff_type + + open (newunit=this%lun, file=filename, access='stream', form='unformatted', status='old') + read (unit=this%lun) desc,riff_type + inquire (unit=this%lun, pos=filepos) + do + read (unit=this%lun, pos=filepos) desc + inquire (unit=this%lun, pos=filepos) + if (desc%id .eq. 'fmt ') then + read (unit=this%lun) this%audio_format + else if (desc%id .eq. 'data') then + this%data_size = desc%size + exit + end if + filepos = filepos + (desc%size + 1) / 2 * 2 ! pad to even alignment + end do + end subroutine read +end module readwav diff --git a/lib/rectify_msk.f90 b/lib/rectify_msk.f90 new file mode 100644 index 00000000..ff5ee497 --- /dev/null +++ b/lib/rectify_msk.f90 @@ -0,0 +1,64 @@ +subroutine rectify_msk(c,msg0,imsg,freq2) + + parameter (NSPM=1404) + complex c(0:NSPM-1) !Received data + complex cmsg(0:NSPM-1) !Message waveform + complex c1(0:NSPM-1) !Rectified signal + complex c2(0:NSPM-1) !Integral of rectified signal + complex c3(0:2*NSPM-1) !FFT of rectified signal + complex cfac + character*22 msg0,msg,msgsent + integer i4tone(234) + + ichk=0 + msg=msg0 + nsym=234 + if(imsg.ge.0) then + ichk=10000+imsg + msg=" 73" + nsym=35 + endif + call genmsk(msg,ichk,msgsent,i4tone,itype) !Get tone sequence for msg + + twopi=8.0*atan(1.0) + dt=1.0/12000.0 + f0=1000.0 + f1=2000.0 + phi=0. + dphi=0. + k=-1 + c2=0. + do j=1,nsym !Generate Tx waveform for msg + if(i4tone(j).eq.0) dphi=twopi*f0*dt + if(i4tone(j).eq.1) dphi=twopi*f1*dt + do i=1,6 + k=k+1 + phi=phi+dphi + cmsg(k)=cmplx(cos(phi),sin(phi)) + c1(k)=conjg(cmsg(k))*c(k) + if(k.ge.1) c2(k)=c2(k-1) + c1(k) + enddo + enddo + c2(0)=c2(1) + pha=atan2(aimag(c2(NSPM-1)),real(c2(NSPM-1))) + cfac=cmplx(cos(pha),-sin(pha)) + c1=cfac*c1 + c2=cfac*c2 + nfft=2*NSPM + c3(0:NSPM-1)=c2 + c3(NSPM:nfft-1)=0. + df=12000.0/nfft + call four2a(c3,nfft,1,-1,1) + smax=0. + do i=0,nfft-1 + f=i*df + if(i.gt.nfft/2) f=f-12000.0 + s=1.e-10*(real(c3(i))**2 + aimag(c3(i))**2) + if(s.gt.smax) then + smax=s + freq2=1500.0 + f + endif + enddo + + return +end subroutine rectify_msk diff --git a/lib/refspectrum.f90 b/lib/refspectrum.f90 new file mode 100644 index 00000000..bc5bede3 --- /dev/null +++ b/lib/refspectrum.f90 @@ -0,0 +1,159 @@ +subroutine refspectrum(id2,bclear,brefspec,buseref,fname) + +! Input: +! id2 i*2 Raw 16-bit integer data, 12000 Hz sample rate +! brefspec logical True when accumulating a reference spectrum + + parameter (NFFT=6912,NH=NFFT/2,NPOLYLOW=400,NPOLYHIGH=2600) + integer*2 id2(NFFT) + logical*1 bclear,brefspec,buseref,blastuse + + real xs(0:NH-1) !Saved upper half of input chunk convolved with h(t) + real x(0:NFFT-1) !Work array + real*4 w(0:NFFT-1) !Window function + real*4 s(0:NH) !Average spectrum + real*4 fil(0:NH) + real*8 xfit(1500),yfit(1500),sigmay(1500),a(5),chisqr !Polyfit arrays + logical first + complex cx(0:NH) !Complex frequency-domain work array + complex cfil(0:NH) + character*(*) fname + common/spectra/syellow(6827),ref(0:NH),filter(0:NH) + equivalence(x,cx) + data first/.true./,blastuse/.false./ + save + + if(first) then + pi=4.0*atan(1.0) + do i=0,NFFT-1 + ww=sin(i*pi/NFFT) + w(i)=ww*ww/NFFT + enddo + nsave=0 + s=0.0 + filter=1.0 + xs=0. + first=.false. + endif + if(bclear) s=0. + + if(brefspec) then + x(0:NH-1)=0.001*id2(1:NH) + x(NH:NFFT-1)=0.0 + call four2a(x,NFFT,1,-1,0) !r2c FFT + + do i=1,NH + s(i)=s(i) + real(cx(i))**2 + aimag(cx(i))**2 + enddo + nsave=nsave+1 + + fac0=0.9 + if(mod(nsave,4).eq.0) then + df=12000.0/NFFT + ia=nint(1000.0/df) + ib=nint(2000.0/df) + avemid=sum(s(ia:ib))/(ib-ia+1) + do i=0,NH + fil(i)=0. + if(s(i).gt.0.0) then + fil(i)=sqrt(avemid/s(i)) + endif + enddo + +! Default range is 240 - 4000 Hz. For narrower filters, use frequencies +! at which gain is -20 dB relative to 1500 Hz. + ia=nint(240.0/df) + ib=nint(4000.0/df) + i0=nint(1500.0/df) + do i=i0,ia,-1 + if(s(i)/s(i0).lt.0.01) exit + enddo + ia=i + do i=i0,ib,1 + if(s(i)/s(i0).lt.0.01) exit + enddo + ib=i + + fac=fac0 + do i=ia,1,-1 + fac=fac*fac0 + fil(i)=fac*fil(i) + enddo + + fac=fac0 + do i=ib,NH + fac=fac*fac0 + fil(i)=fac*fil(i) + enddo + + do iter=1,100 !### ??? ### + call smo121(fil,NH) + enddo + + do i=0,NH + filter(i)=-60.0 + if(s(i).gt.0.0) filter(i)=20.0*log10(fil(i)) + enddo + + il=nint(NPOLYLOW/df) + ih=nint(NPOLYHIGH/df) + nfit=ih-il+1 + mode=0 + nterms=5 + do i=1,nfit + xfit(i)=((i+il-1)*df-1500.0)/1000.0 + yfit(i)=fil(i+il-1) + sigmay(i)=1.0 + enddo + call polyfit(xfit,yfit,sigmay,nfit,nterms,mode,a,chisqr) + + open(16,file=fname,status='unknown') + write(16,1003) NPOLYLOW,NPOLYHIGH,nterms,a +1003 format(3i5,5e25.16) + do i=1,NH + freq=i*df + ref(i)=db(s(i)/avemid) + write(16,1005) freq,s(i),ref(i),fil(i),filter(i) +1005 format(f10.3,e12.3,f12.6,e12.3,f12.6) + enddo + close(16) + endif + return + endif + + if(buseref) then + if(blastuse.neqv.buseref) then !just enabled so read filter + fil=1.0 + open(16,file=fname,status='old',err=110) + read(16,1003,err=20,end=100) ndummy,ndummy,nterms,a + goto 30 +20 rewind(16) !allow for old style refspec.dat with no header +30 do i=1,NH + read(16,1005,err=100,end=100) freq,s(i),ref(i),fil(i),filter(i) + enddo +! Make the filter causal for overlap and add. + cx(0)=0.0 + cx(1:NH)=fil(1:NH)/NFFT + call four2a(x,NFFT,1,1,-1) + x=cshift(x,-400) + x(800:NH)=0.0 + call four2a(cx,NFFT,1,-1,0) + cfil=cx +100 close(16) +110 continue + endif +! Use overlap and add method to apply causal reference filter. + x(0:NH-1)=id2(1:NH) + x(NH:NFFT-1)=0.0 + x=x/NFFT + call four2a(x,NFFT,1,-1,0) + cx=cfil*cx + call four2a(cx,NFFT,1,1,-1) + x(0:NH-1)=x(0:NH-1)+xs + xs=x(NH:NFFT-1) + id2(1:NH)=nint(x(0:NH-1)) + endif + blastuse=buseref + + return +end subroutine refspectrum diff --git a/lib/s3avg.f90 b/lib/s3avg.f90 deleted file mode 100644 index f8f68ac5..00000000 --- a/lib/s3avg.f90 +++ /dev/null @@ -1,60 +0,0 @@ -subroutine s3avg(nsave,mode65,nutc,nhz,xdt,npol,ntol,s3,nsum,nkv,decoded) - -! Save the current synchronized spectra, s3(64,63), for possible -! decoding of average. - - real s3(64,63) !Synchronized spectra for 63 symbols - real s3a(64,63,64) !Saved spectra - real s3b(64,63) !Average spectra - integer iutc(64),ihz(64),ipol(64) - real dt(64) - character*22 decoded - logical ltext,first - data first/.true./ - save - - if(first) then - iutc=-1 - ihz=0 - ipol=0 - first=.false. - ihzdiff=min(100,ntol) - dtdiff=0.2 - endif - - do i=1,64 - if(nutc.eq.iutc(i) .and. abs(nhz-ihz(i)).lt.ihzdiff) then - nsave=mod(nsave-1+64,64)+1 - go to 10 - endif - enddo - - iutc(nsave)=nutc !Save UTC - ihz(nsave)=nhz !Save freq in Hz - ipol(nsave)=npol !Save pol - dt(nsave)=xdt !Save DT - s3a(1:64,1:63,nsave)=s3 !Save the spectra - -10 s3b=0. - do i=1,64 !Accumulate avg spectra - if(iutc(i).lt.0) cycle - if(mod(iutc(i),2).ne.mod(nutc,2)) cycle !Use only same sequence - if(abs(nhz-ihz(i)).gt.ihzdiff) cycle !Freq must match - if(abs(xdt-dt(i)).gt.dtdiff) cycle !DT must match - s3b=s3b + s3a(1:64,1:63,i) - nsum=nsum+1 - enddo - - decoded=' ' - if(nsum.ge.2) then !Try decoding the sverage - nadd=mode65*nsum - call extract(s3b,nadd,ncount,nhist,decoded,ltext) !Extract the message - nkv=nsum - if(ncount.lt.0) then - nkv=0 - decoded=' ' - endif - endif - - return -end subroutine s3avg diff --git a/lib/savec2.f90 b/lib/savec2.f90 new file mode 100644 index 00000000..6435a215 --- /dev/null +++ b/lib/savec2.f90 @@ -0,0 +1,55 @@ +integer function savec2(c2name,ntrseconds,f0m1500) + +! Array c0() has complex samples at 1500 Hz sample rate. +! WSPR-2: downsample by 1/4 to produce c2, centered at 1500 Hz +! WSPR-15: downsample by 1/32 to produce c2, centered at 1612.5 Hz + + parameter (NDMAX=120*1500) !Sample intervals at 1500 Hz rate + parameter (MAXFFT=256*1024) + + character*(*) c2name + character*14 outfile + real*8 f0m1500 + complex c0 + complex c1(0:MAXFFT-1) + complex c2(0:65535) + common/c0com/c0(0:NDMAX-1) + + ntrminutes=ntrseconds/60 + npts=114*1500 + nfft1=262144 + if(ntrminutes.eq.15) then + npts=890*1500 + nfft1=MAXFFT + endif + df1=1500.0/nfft1 + fac=1.0/nfft1 + c1(0:npts-1)=fac*c0(0:npts-1) + c1(npts:nfft1-1)=0. + + call four2a(c1,nfft1,1,1,1) !Complex FFT to frequency domain + +! Select the desired frequency range + nfft2=65536 + nh2=nfft2/2 + if(ntrminutes.eq.2) then + c2(0:nh2)=c1(0:nh2) + c2(nh2+1:nfft2-1)=c1(nfft1-nh2+1:nfft1-1) + else + i0=nint(112.5/df1) + c2(0:nh2)=c1(i0:i0+nh2) + c2(nh2+1:nfft2-1)=c1(i0-nh2+1:i0-1) + endif + + call four2a(c2,nfft2,1,-1,1) !Shorter complex FFT, back to time domain + +! Write complex time-domain data to disk. + i1=index(c2name,'.c2') + outfile=c2name(i1-11:i1+2) + open(18,file=c2name,status='unknown',access='stream', iostat=ioerr) + if (ioerr.eq.0) then + write(18) outfile,ntrminutes,f0m1500,c2(0:45000-1) + close(18) + endif + savec2 = ioerr +end function savec2 diff --git a/lib/setup65.f90 b/lib/setup65.f90 index 608b41b9..42274ce0 100644 --- a/lib/setup65.f90 +++ b/lib/setup65.f90 @@ -3,8 +3,8 @@ subroutine setup65 ! Defines arrays related to the JT65 pseudo-random synchronizing pattern. ! Executed at program start. + use jt65_mod integer nprc(126) - common/prcom/pr(126),mdat(126),mref(126,2),mdat2(126),mref2(126,2) ! JT65 data nprc/ & diff --git a/lib/sfrsd.f90 b/lib/sfrsd.f90 new file mode 100644 index 00000000..49dc7bca --- /dev/null +++ b/lib/sfrsd.f90 @@ -0,0 +1,121 @@ +subroutine sfrsd(mrsym,mrprob,mr2sym,mr2prob,ntrials,correct,indexes, & + param,ntry) + + integer mrsym(0:62),mrprob(0:62),mr2sym(0:62),mr2prob(0:62) + integer correct(0:62),indexes(0:62),probs(0:62),thresh0(0:62) + integer rxdat(0:62),rxdat2(0:62),rxprob(0:62),rxprob2(0:62) + integer workdat(0:62),era_pos(0:50) + integer perr(0:7,0:7) + integer param(0:7) + real ratio0(0:62) + + call init_rs_int() + do i=0,62 + rxdat(i)=mrsym(62-i) + rxdat2(i)=mr2sym(62-i) + rxprob(i)=mrprob(62-i) + rxprob2(i)=mr2prob(62-i) + enddo + + do i=0,62 + indexes(i)=i + probs(i)=rxprob(i) + enddo + + do ip=1,62 + do k=0,63-ip + if(probs(k).lt.probs(k+1)) then + ntmp=probs(k) + probs(k)=probs(k+1) + probs(k+1)=ntmp + ntmp=indexes(k) + indexes(k)=indexes(k+1) + indexes(k+1)=ntmp + endif + enddo + enddo + + era_pos=0 + numera=0 + workdat=rxdat + call decode_rs_int() + if(nerr.ge.0) then + correct=workdat + param=0 + return + endif + + call random_seed() + + ncandidates=0 + nsum=0 + do i=0,62 + nsum=nsum+rxprob(i) + j=indexes(62-i) + ratio0(i)=float(rxprob2(j))/(float(rxprob(j))+0.01) + ii=int(7.999*ratio0(i)) + jj=(62-i)/8 + thresh0(i)=nint(1.3*perr(jj,ii)) + enddo + if(nsum.eq.0) return + + do k=0,ntrials + era_pos=0 + workdat=rxdat + numera=0 + do i=0,62 + j=indexes(62-i) + thresh=thresh0(i) + ir=rand() + if(...) then + era_pos(numera)=j + numera=numera+1 + endif + enddo + + call decode_rs_int() + if(nerr.ge.0) then + ncandidates=ncandidates+1 + nhard=0 + nsoft=0 + nsofter=0 + do i=0,62 + if(workdat(i).ne.rxdat(i)) then + nhard=nhard+1 + nsofter=nsofter+rxprob(i) + if(workdat(i).ne.rxdat2(i)) nsoft=nsoft+rxprob(i) + else + nsofter=nsofter-rxprob(i) + endif + enddo + nsoft=63*nsoft/nsum + nsofter=63*nsofter/nsum + ntotal=nsoft+nhard + if(ntotal.lt.ntotal_min) then + nsoft_min=nsoft + nhard_min=nhard + nsofter_min=nsofter + ntotal_min=ntotal + correct=workdat + nera_best=numera + ntry=k + endif + if(ntotal_min.lt.72 .and. nhard_min.lt.42) exit + endif + if(k.eq.ntrials-1) ntry=k+1 + enddo + + if(ntotal_min.ge.76 .or. nhard.ge.44) nhard_min=-1 + + param(0)=ncandidates + param(1)=nhard_min + param(2)=nsoft_min + param(3)=nera_best + param(4)=nsofter_min + if(param(0).eq.0) param(2)=-1 + + return +end subroutine sfrsd + + + diff --git a/lib/sgran.c b/lib/sgran.c new file mode 100644 index 00000000..b48222e9 --- /dev/null +++ b/lib/sgran.c @@ -0,0 +1,7 @@ +#include "init_random_seed.h" + +/* Fortran wrapper to seed the C library rand */ +void sgran_(void) +{ + init_random_seed(); +} diff --git a/lib/sh65.f90 b/lib/sh65.f90 new file mode 100644 index 00000000..8f13fdc3 --- /dev/null +++ b/lib/sh65.f90 @@ -0,0 +1,89 @@ +subroutine sh65(cx,n5,mode65,ntol,xdf,nspecial,snrdb) + parameter(NFFT=2048,NH=NFFT/2,MAXSTEPS=150) + complex cx(90000) + complex c(0:NFFT-1) + real s(-NH+1:NH) + real s2(-NH+1:NH,MAXSTEPS) + real ss(-NH+1:NH,8) + real sigmax(8) + integer ipk(8) + + s=0. + ss=0. + + jstep=NFFT/4 + nblks=n5/jstep - 3 + ia=-jstep+1 + do iblk=1,nblks + ia=ia+jstep + ib=ia+NFFT-1 + c=cx(ia:ib) + call four2a(c,nfft,1,1,1) !c2c FFT + do i=0,NFFT-1 + j=i + if(j.gt.NH) j=j-NFFT + p=real(c(i))**2 + aimag(c(i))**2 + s(j)=s(j) + p + s2(j,iblk)=p + enddo + n=mod(iblk-1,8) +1 + ss(-NH+1:NH,n)=ss(-NH+1:NH,n) + s2(-NH+1:NH,iblk) + enddo + + s=1.e-6*s + ss=1.e-6*ss + df=1378.1285/NFFT + nfac=40*mode65 + dtstep=0.25/df + +! Define range of frequencies to be searched + fa=-ntol + fb=ntol + ia2=max(-NH+1,nint(fa/df)) +! Upper tone is above sync tone by 4*nfac*df Hz + ib2=min(NH,nint(fb/df + 4.1*nfac)) + +! Find strongest line in each of the 4 phases, repeating for each drift rate. + sbest=0. + snrbest=0. + nbest=1 + ipk=0 + + do n=1,8 + sigmax(n)=0. + do i=ia2,ib2 + sig=ss(i,n) + if(sig.ge.sigmax(n)) then + ipk(n)=i + sigmax(n)=sig + if(sig.ge.sbest) then + sbest=sig + nbest=n + endif + endif + enddo + enddo + n2best=nbest+4 + if(n2best.gt.8) n2best=nbest-4 + xdf=min(ipk(nbest),ipk(n2best))*df + nspecial=0 + if(abs(xdf).le.ntol) then + idiff=abs(ipk(nbest)-ipk(n2best)) + xk=float(idiff)/nfac + k=nint(xk) + iderr=nint((xk-k)*nfac) +! maxerr=nint(0.008*abs(idiff) + 0.51) + maxerr=nint(0.02*abs(idiff) + 0.51) !### Better test ??? ### + if(abs(iderr).le.maxerr .and. k.ge.2 .and. k.le.4) nspecial=k + snrdb=-30.0 + if(nspecial.gt.0) then + call sh65snr(ss(ia2,nbest),ib2-ia2+1,snr1) + call sh65snr(ss(ia2,n2best),ib2-ia2+1,snr2) + snr=0.5*(snr1+snr2) + snrdb=db(snr) - db(2500.0/df) - db(sqrt(nblks/4.0)) + 8.0 + endif + if(snr1.lt.4.0 .or. snr2.lt.4.0 .or. snr.lt.5.0) nspecial=0 + endif + + return +end subroutine sh65 diff --git a/lib/sh65snr.f90 b/lib/sh65snr.f90 new file mode 100644 index 00000000..3d449010 --- /dev/null +++ b/lib/sh65snr.f90 @@ -0,0 +1,36 @@ +subroutine sh65snr(x,nz,snr) + + real x(nz) + + ipk=0 !Shut up compiler warnings. -db + smax=-1.e30 + do i=1,nz + if(x(i).gt.smax) then + ipk=i + smax=x(i) + endif + s=s+x(i) + enddo + + s=0. + ns=0 + do i=1,nz + if(abs(i-ipk).ge.3) then + s=s+x(i) + ns=ns+1 + endif + enddo + ave=s/ns + + sq=0. + do i=1,nz + if(abs(i-ipk).ge.3) then + sq=sq+(x(i)-ave)**2 + ns=ns+1 + endif + enddo + rms=sqrt(sq/(nz-2)) + snr=(smax-ave)/rms + + return +end subroutine sh65snr diff --git a/lib/shell.f90 b/lib/shell.f90 new file mode 100644 index 00000000..d7365bfc --- /dev/null +++ b/lib/shell.f90 @@ -0,0 +1,27 @@ +subroutine shell(n,a) + integer n + real a(n) + integer i,j,inc + real v + + inc=1 +1 inc=3*inc+1 + if(inc.le.n) go to 1 +2 inc=inc/3 + + do i=inc+1,n + v=a(i) + j=i +3 if(a(j-inc).gt.v) then + a(j)=a(j-inc) + j=j-inc + if(j.le.inc) go to 4 + go to 3 + endif +4 a(j)=v + enddo + + if(inc.gt.1) go to 2 + + return +end subroutine shell diff --git a/lib/slasubs.f b/lib/slasubs.f new file mode 100644 index 00000000..16081f28 --- /dev/null +++ b/lib/slasubs.f @@ -0,0 +1,3396 @@ + SUBROUTINE sla_CLDJ (IY, IM, ID, DJM, J) +*+ +* - - - - - +* C L D J +* - - - - - +* +* Gregorian Calendar to Modified Julian Date +* +* Given: +* IY,IM,ID int year, month, day in Gregorian calendar +* +* Returned: +* DJM dp modified Julian Date (JD-2400000.5) for 0 hrs +* J int status: +* 0 = OK +* 1 = bad year (MJD not computed) +* 2 = bad month (MJD not computed) +* 3 = bad day (MJD computed) +* +* The year must be -4699 (i.e. 4700BC) or later. +* +* The algorithm is adapted from Hatcher 1984 (QJRAS 25, 53-55). +* +* Last revision: 27 July 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + INTEGER IY,IM,ID + DOUBLE PRECISION DJM + INTEGER J + +* Month lengths in days + INTEGER MTAB(12) + DATA MTAB / 31,28,31,30,31,30,31,31,30,31,30,31 / + + + +* Preset status. + J = 0 + +* Validate year. + IF ( IY .LT. -4699 ) THEN + J = 1 + ELSE + +* Validate month. + IF ( IM.GE.1 .AND. IM.LE.12 ) THEN + +* Allow for leap year. + IF ( MOD(IY,4) .EQ. 0 ) THEN + MTAB(2) = 29 + ELSE + MTAB(2) = 28 + END IF + IF ( MOD(IY,100).EQ.0 .AND. MOD(IY,400).NE.0 ) + : MTAB(2) = 28 + +* Validate day. + IF ( ID.LT.1 .OR. ID.GT.MTAB(IM) ) J=3 + +* Modified Julian Date. + DJM = DBLE ( ( 1461 * ( IY - (12-IM)/10 + 4712 ) ) / 4 + : + ( 306 * MOD ( IM+9, 12 ) + 5 ) / 10 + : - ( 3 * ( ( IY - (12-IM)/10 + 4900 ) / 100 ) ) / 4 + : + ID - 2399904 ) + +* Bad month. + ELSE + J=2 + END IF + + END IF + + END + DOUBLE PRECISION FUNCTION sla_DAT (UTC) +*+ +* - - - - +* D A T +* - - - - +* +* Increment to be applied to Coordinated Universal Time UTC to give +* International Atomic Time TAI (double precision) +* +* Given: +* UTC d UTC date as a modified JD (JD-2400000.5) +* +* Result: TAI-UTC in seconds +* +* Notes: +* +* 1 The UTC is specified to be a date rather than a time to indicate +* that care needs to be taken not to specify an instant which lies +* within a leap second. Though in most cases UTC can include the +* fractional part, correct behaviour on the day of a leap second +* can only be guaranteed up to the end of the second 23:59:59. +* +* 2 For epochs from 1961 January 1 onwards, the expressions from the +* file ftp://maia.usno.navy.mil/ser7/tai-utc.dat are used. +* +* 3 The 5ms time step at 1961 January 1 is taken from 2.58.1 (p87) of +* the 1992 Explanatory Supplement. +* +* 4 UTC began at 1960 January 1.0 (JD 2436934.5) and it is improper +* to call the routine with an earlier epoch. However, if this +* is attempted, the TAI-UTC expression for the year 1960 is used. +* +* +* :-----------------------------------------: +* : : +* : IMPORTANT : +* : : +* : This routine must be updated on each : +* : occasion that a leap second is : +* : announced : +* : : +* : Latest leap second: 2015 July 1 : +* : : +* :-----------------------------------------: +* +* Last revision: 5 July 2008 +* +* Copyright P.T.Wallace. All rights reserved. +*- + + IMPLICIT NONE + + DOUBLE PRECISION UTC + + DOUBLE PRECISION DT + + + + IF (.FALSE.) THEN + +* - - - - - - - - - - - - - - - - - - - - - - * +* Add new code here on each occasion that a * +* leap second is announced, and update the * +* preamble comments appropriately. * +* - - - - - - - - - - - - - - - - - - - - - - * + +* 2015 July 1 + ELSE IF (UTC.GE.57204D0) THEN + DT=36D0 + +* 2012 July 1 + ELSE IF (UTC.GE.56109D0) THEN + DT=35D0 + +* 2009 January 1 + ELSE IF (UTC.GE.54832D0) THEN + DT=34D0 + +* 2006 January 1 + ELSE IF (UTC.GE.53736D0) THEN + DT=33D0 + +* 1999 January 1 + ELSE IF (UTC.GE.51179D0) THEN + DT=32D0 + +* 1997 July 1 + ELSE IF (UTC.GE.50630D0) THEN + DT=31D0 + +* 1996 January 1 + ELSE IF (UTC.GE.50083D0) THEN + DT=30D0 + +* 1994 July 1 + ELSE IF (UTC.GE.49534D0) THEN + DT=29D0 + +* 1993 July 1 + ELSE IF (UTC.GE.49169D0) THEN + DT=28D0 + +* 1992 July 1 + ELSE IF (UTC.GE.48804D0) THEN + DT=27D0 + +* 1991 January 1 + ELSE IF (UTC.GE.48257D0) THEN + DT=26D0 + +* 1990 January 1 + ELSE IF (UTC.GE.47892D0) THEN + DT=25D0 + +* 1988 January 1 + ELSE IF (UTC.GE.47161D0) THEN + DT=24D0 + +* 1985 July 1 + ELSE IF (UTC.GE.46247D0) THEN + DT=23D0 + +* 1983 July 1 + ELSE IF (UTC.GE.45516D0) THEN + DT=22D0 + +* 1982 July 1 + ELSE IF (UTC.GE.45151D0) THEN + DT=21D0 + +* 1981 July 1 + ELSE IF (UTC.GE.44786D0) THEN + DT=20D0 + +* 1980 January 1 + ELSE IF (UTC.GE.44239D0) THEN + DT=19D0 + +* 1979 January 1 + ELSE IF (UTC.GE.43874D0) THEN + DT=18D0 + +* 1978 January 1 + ELSE IF (UTC.GE.43509D0) THEN + DT=17D0 + +* 1977 January 1 + ELSE IF (UTC.GE.43144D0) THEN + DT=16D0 + +* 1976 January 1 + ELSE IF (UTC.GE.42778D0) THEN + DT=15D0 + +* 1975 January 1 + ELSE IF (UTC.GE.42413D0) THEN + DT=14D0 + +* 1974 January 1 + ELSE IF (UTC.GE.42048D0) THEN + DT=13D0 + +* 1973 January 1 + ELSE IF (UTC.GE.41683D0) THEN + DT=12D0 + +* 1972 July 1 + ELSE IF (UTC.GE.41499D0) THEN + DT=11D0 + +* 1972 January 1 + ELSE IF (UTC.GE.41317D0) THEN + DT=10D0 + +* 1968 February 1 + ELSE IF (UTC.GE.39887D0) THEN + DT=4.2131700D0+(UTC-39126D0)*0.002592D0 + +* 1966 January 1 + ELSE IF (UTC.GE.39126D0) THEN + DT=4.3131700D0+(UTC-39126D0)*0.002592D0 + +* 1965 September 1 + ELSE IF (UTC.GE.39004D0) THEN + DT=3.8401300D0+(UTC-38761D0)*0.001296D0 + +* 1965 July 1 + ELSE IF (UTC.GE.38942D0) THEN + DT=3.7401300D0+(UTC-38761D0)*0.001296D0 + +* 1965 March 1 + ELSE IF (UTC.GE.38820D0) THEN + DT=3.6401300D0+(UTC-38761D0)*0.001296D0 + +* 1965 January 1 + ELSE IF (UTC.GE.38761D0) THEN + DT=3.5401300D0+(UTC-38761D0)*0.001296D0 + +* 1964 September 1 + ELSE IF (UTC.GE.38639D0) THEN + DT=3.4401300D0+(UTC-38761D0)*0.001296D0 + +* 1964 April 1 + ELSE IF (UTC.GE.38486D0) THEN + DT=3.3401300D0+(UTC-38761D0)*0.001296D0 + +* 1964 January 1 + ELSE IF (UTC.GE.38395D0) THEN + DT=3.2401300D0+(UTC-38761D0)*0.001296D0 + +* 1963 November 1 + ELSE IF (UTC.GE.38334D0) THEN + DT=1.9458580D0+(UTC-37665D0)*0.0011232D0 + +* 1962 January 1 + ELSE IF (UTC.GE.37665D0) THEN + DT=1.8458580D0+(UTC-37665D0)*0.0011232D0 + +* 1961 August 1 + ELSE IF (UTC.GE.37512D0) THEN + DT=1.3728180D0+(UTC-37300D0)*0.001296D0 + +* 1961 January 1 + ELSE IF (UTC.GE.37300D0) THEN + DT=1.4228180D0+(UTC-37300D0)*0.001296D0 + +* Before that + ELSE + DT=1.4178180D0+(UTC-37300D0)*0.001296D0 + + END IF + + sla_DAT=DT + + END + SUBROUTINE sla_DC62S (V, A, B, R, AD, BD, RD) +*+ +* - - - - - - +* D C 6 2 S +* - - - - - - +* +* Conversion of position & velocity in Cartesian coordinates +* to spherical coordinates (double precision) +* +* Given: +* V d(6) Cartesian position & velocity vector +* +* Returned: +* A d longitude (radians) +* B d latitude (radians) +* R d radial coordinate +* AD d longitude derivative (radians per unit time) +* BD d latitude derivative (radians per unit time) +* RD d radial derivative +* +* P.T.Wallace Starlink 28 April 1996 +* +* Copyright (C) 1996 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION V(6),A,B,R,AD,BD,RD + + DOUBLE PRECISION X,Y,Z,XD,YD,ZD,RXY2,RXY,R2,XYP + + + +* Components of position/velocity vector + X=V(1) + Y=V(2) + Z=V(3) + XD=V(4) + YD=V(5) + ZD=V(6) + +* Component of R in XY plane squared + RXY2=X*X+Y*Y + +* Modulus squared + R2=RXY2+Z*Z + +* Protection against null vector + IF (R2.EQ.0D0) THEN + X=XD + Y=YD + Z=ZD + RXY2=X*X+Y*Y + R2=RXY2+Z*Z + END IF + +* Position and velocity in spherical coordinates + RXY=SQRT(RXY2) + XYP=X*XD+Y*YD + IF (RXY2.NE.0D0) THEN + A=ATAN2(Y,X) + B=ATAN2(Z,RXY) + AD=(X*YD-Y*XD)/RXY2 + BD=(ZD*RXY2-Z*XYP)/(R2*RXY) + ELSE + A=0D0 + IF (Z.NE.0D0) THEN + B=ATAN2(Z,RXY) + ELSE + B=0D0 + END IF + AD=0D0 + BD=0D0 + END IF + R=SQRT(R2) + IF (R.NE.0D0) THEN + RD=(XYP+Z*ZD)/R + ELSE + RD=0D0 + END IF + + END + SUBROUTINE sla_DCC2S (V, A, B) +*+ +* - - - - - - +* D C C 2 S +* - - - - - - +* +* Cartesian to spherical coordinates (double precision) +* +* Given: +* V d(3) x,y,z vector +* +* Returned: +* A,B d spherical coordinates in radians +* +* The spherical coordinates are longitude (+ve anticlockwise looking +* from the +ve latitude pole) and latitude. The Cartesian coordinates +* are right handed, with the x axis at zero longitude and latitude, and +* the z axis at the +ve latitude pole. +* +* If V is null, zero A and B are returned. At either pole, zero A is +* returned. +* +* Last revision: 22 July 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION V(3),A,B + + DOUBLE PRECISION X,Y,Z,R + + + X = V(1) + Y = V(2) + Z = V(3) + R = SQRT(X*X+Y*Y) + + IF (R.EQ.0D0) THEN + A = 0D0 + ELSE + A = ATAN2(Y,X) + END IF + + IF (Z.EQ.0D0) THEN + B = 0D0 + ELSE + B = ATAN2(Z,R) + END IF + + END + SUBROUTINE sla_DCS2C (A, B, V) +*+ +* - - - - - - +* D C S 2 C +* - - - - - - +* +* Spherical coordinates to direction cosines (double precision) +* +* Given: +* A,B d spherical coordinates in radians +* (RA,Dec), (long,lat) etc. +* +* Returned: +* V d(3) x,y,z unit vector +* +* The spherical coordinates are longitude (+ve anticlockwise looking +* from the +ve latitude pole) and latitude. The Cartesian coordinates +* are right handed, with the x axis at zero longitude and latitude, and +* the z axis at the +ve latitude pole. +* +* Last revision: 26 December 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION A,B,V(3) + + DOUBLE PRECISION COSB + + + COSB = COS(B) + + V(1) = COS(A)*COSB + V(2) = SIN(A)*COSB + V(3) = SIN(B) + + END + SUBROUTINE sla_DE2H (HA, DEC, PHI, AZ, EL) +*+ +* - - - - - +* D E 2 H +* - - - - - +* +* Equatorial to horizon coordinates: HA,Dec to Az,El +* +* (double precision) +* +* Given: +* HA d hour angle +* DEC d declination +* PHI d observatory latitude +* +* Returned: +* AZ d azimuth +* EL d elevation +* +* Notes: +* +* 1) All the arguments are angles in radians. +* +* 2) Azimuth is returned in the range 0-2pi; north is zero, +* and east is +pi/2. Elevation is returned in the range +* +/-pi/2. +* +* 3) The latitude must be geodetic. In critical applications, +* corrections for polar motion should be applied. +* +* 4) In some applications it will be important to specify the +* correct type of hour angle and declination in order to +* produce the required type of azimuth and elevation. In +* particular, it may be important to distinguish between +* elevation as affected by refraction, which would +* require the "observed" HA,Dec, and the elevation +* in vacuo, which would require the "topocentric" HA,Dec. +* If the effects of diurnal aberration can be neglected, the +* "apparent" HA,Dec may be used instead of the topocentric +* HA,Dec. +* +* 5) No range checking of arguments is carried out. +* +* 6) In applications which involve many such calculations, rather +* than calling the present routine it will be more efficient to +* use inline code, having previously computed fixed terms such +* as sine and cosine of latitude, and (for tracking a star) +* sine and cosine of declination. +* +* P.T.Wallace Starlink 9 July 1994 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION HA,DEC,PHI,AZ,EL + + DOUBLE PRECISION D2PI + PARAMETER (D2PI=6.283185307179586476925286766559D0) + + DOUBLE PRECISION SH,CH,SD,CD,SP,CP,X,Y,Z,R,A + + +* Useful trig functions + SH=SIN(HA) + CH=COS(HA) + SD=SIN(DEC) + CD=COS(DEC) + SP=SIN(PHI) + CP=COS(PHI) + +* Az,El as x,y,z + X=-CH*CD*SP+SD*CP + Y=-SH*CD + Z=CH*CD*CP+SD*SP + +* To spherical + R=SQRT(X*X+Y*Y) + IF (R.EQ.0D0) THEN + A=0D0 + ELSE + A=ATAN2(Y,X) + END IF + IF (A.LT.0D0) A=A+D2PI + AZ=A + EL=ATAN2(Z,R) + + END + SUBROUTINE sla_DEULER (ORDER, PHI, THETA, PSI, RMAT) +*+ +* - - - - - - - +* D E U L E R +* - - - - - - - +* +* Form a rotation matrix from the Euler angles - three successive +* rotations about specified Cartesian axes (double precision) +* +* Given: +* ORDER c*(*) specifies about which axes the rotations occur +* PHI d 1st rotation (radians) +* THETA d 2nd rotation ( " ) +* PSI d 3rd rotation ( " ) +* +* Returned: +* RMAT d(3,3) rotation matrix +* +* A rotation is positive when the reference frame rotates +* anticlockwise as seen looking towards the origin from the +* positive region of the specified axis. +* +* The characters of ORDER define which axes the three successive +* rotations are about. A typical value is 'ZXZ', indicating that +* RMAT is to become the direction cosine matrix corresponding to +* rotations of the reference frame through PHI radians about the +* old Z-axis, followed by THETA radians about the resulting X-axis, +* then PSI radians about the resulting Z-axis. +* +* The axis names can be any of the following, in any order or +* combination: X, Y, Z, uppercase or lowercase, 1, 2, 3. Normal +* axis labelling/numbering conventions apply; the xyz (=123) +* triad is right-handed. Thus, the 'ZXZ' example given above +* could be written 'zxz' or '313' (or even 'ZxZ' or '3xZ'). ORDER +* is terminated by length or by the first unrecognized character. +* +* Fewer than three rotations are acceptable, in which case the later +* angle arguments are ignored. If all rotations are zero, the +* identity matrix is produced. +* +* P.T.Wallace Starlink 23 May 1997 +* +* Copyright (C) 1997 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + CHARACTER*(*) ORDER + DOUBLE PRECISION PHI,THETA,PSI,RMAT(3,3) + + INTEGER J,I,L,N,K + DOUBLE PRECISION RESULT(3,3),ROTN(3,3),ANGLE,S,C,W,WM(3,3) + CHARACTER AXIS + + + +* Initialize result matrix + DO J=1,3 + DO I=1,3 + IF (I.NE.J) THEN + RESULT(I,J) = 0D0 + ELSE + RESULT(I,J) = 1D0 + END IF + END DO + END DO + +* Establish length of axis string + L = LEN(ORDER) + +* Look at each character of axis string until finished + DO N=1,3 + IF (N.LE.L) THEN + +* Initialize rotation matrix for the current rotation + DO J=1,3 + DO I=1,3 + IF (I.NE.J) THEN + ROTN(I,J) = 0D0 + ELSE + ROTN(I,J) = 1D0 + END IF + END DO + END DO + +* Pick up the appropriate Euler angle and take sine & cosine + IF (N.EQ.1) THEN + ANGLE = PHI + ELSE IF (N.EQ.2) THEN + ANGLE = THETA + ELSE + ANGLE = PSI + END IF + S = SIN(ANGLE) + C = COS(ANGLE) + +* Identify the axis + AXIS = ORDER(N:N) + IF (AXIS.EQ.'X'.OR. + : AXIS.EQ.'x'.OR. + : AXIS.EQ.'1') THEN + +* Matrix for x-rotation + ROTN(2,2) = C + ROTN(2,3) = S + ROTN(3,2) = -S + ROTN(3,3) = C + + ELSE IF (AXIS.EQ.'Y'.OR. + : AXIS.EQ.'y'.OR. + : AXIS.EQ.'2') THEN + +* Matrix for y-rotation + ROTN(1,1) = C + ROTN(1,3) = -S + ROTN(3,1) = S + ROTN(3,3) = C + + ELSE IF (AXIS.EQ.'Z'.OR. + : AXIS.EQ.'z'.OR. + : AXIS.EQ.'3') THEN + +* Matrix for z-rotation + ROTN(1,1) = C + ROTN(1,2) = S + ROTN(2,1) = -S + ROTN(2,2) = C + + ELSE + +* Unrecognized character - fake end of string + L = 0 + + END IF + +* Apply the current rotation (matrix ROTN x matrix RESULT) + DO I=1,3 + DO J=1,3 + W = 0D0 + DO K=1,3 + W = W+ROTN(I,K)*RESULT(K,J) + END DO + WM(I,J) = W + END DO + END DO + DO J=1,3 + DO I=1,3 + RESULT(I,J) = WM(I,J) + END DO + END DO + + END IF + + END DO + +* Copy the result + DO J=1,3 + DO I=1,3 + RMAT(I,J) = RESULT(I,J) + END DO + END DO + + END + SUBROUTINE sla_DMOON (DATE, PV) +*+ +* - - - - - - +* D M O O N +* - - - - - - +* +* Approximate geocentric position and velocity of the Moon +* (double precision) +* +* Given: +* DATE D TDB (loosely ET) as a Modified Julian Date +* (JD-2400000.5) +* +* Returned: +* PV D(6) Moon x,y,z,xdot,ydot,zdot, mean equator and +* equinox of date (AU, AU/s) +* +* Notes: +* +* 1 This routine is a full implementation of the algorithm +* published by Meeus (see reference). +* +* 2 Meeus quotes accuracies of 10 arcsec in longitude, 3 arcsec in +* latitude and 0.2 arcsec in HP (equivalent to about 20 km in +* distance). Comparison with JPL DE200 over the interval +* 1960-2025 gives RMS errors of 3.7 arcsec and 83 mas/hour in +* longitude, 2.3 arcsec and 48 mas/hour in latitude, 11 km +* and 81 mm/s in distance. The maximum errors over the same +* interval are 18 arcsec and 0.50 arcsec/hour in longitude, +* 11 arcsec and 0.24 arcsec/hour in latitude, 40 km and 0.29 m/s +* in distance. +* +* 3 The original algorithm is expressed in terms of the obsolete +* timescale Ephemeris Time. Either TDB or TT can be used, but +* not UT without incurring significant errors (30 arcsec at +* the present time) due to the Moon's 0.5 arcsec/sec movement. +* +* 4 The algorithm is based on pre IAU 1976 standards. However, +* the result has been moved onto the new (FK5) equinox, an +* adjustment which is in any case much smaller than the +* intrinsic accuracy of the procedure. +* +* 5 Velocity is obtained by a complete analytical differentiation +* of the Meeus model. +* +* Reference: +* Meeus, l'Astronomie, June 1984, p348. +* +* P.T.Wallace Starlink 22 January 1998 +* +* Copyright (C) 1998 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE,PV(6) + +* Degrees, arcseconds and seconds of time to radians + DOUBLE PRECISION D2R,DAS2R,DS2R + PARAMETER (D2R=0.0174532925199432957692369D0, + : DAS2R=4.848136811095359935899141D-6, + : DS2R=7.272205216643039903848712D-5) + +* Seconds per Julian century (86400*36525) + DOUBLE PRECISION CJ + PARAMETER (CJ=3155760000D0) + +* Julian epoch of B1950 + DOUBLE PRECISION B1950 + PARAMETER (B1950=1949.9997904423D0) + +* Earth equatorial radius in AU ( = 6378.137 / 149597870 ) + DOUBLE PRECISION ERADAU + PARAMETER (ERADAU=4.2635212653763D-5) + + DOUBLE PRECISION T,THETA,SINOM,COSOM,DOMCOM,WA,DWA,WB,DWB,WOM, + : DWOM,SINWOM,COSWOM,V,DV,COEFF,EMN,EMPN,DN,FN,EN, + : DEN,DTHETA,FTHETA,EL,DEL,B,DB,BF,DBF,P,DP,SP,R, + : DR,X,Y,Z,XD,YD,ZD,SEL,CEL,SB,CB,RCB,RBD,W,EPJ, + : EQCOR,EPS,SINEPS,COSEPS,ES,EC + INTEGER N,I + +* +* Coefficients for fundamental arguments +* +* at J1900: T**0, T**1, T**2, T**3 +* at epoch: T**0, T**1 +* +* Units are degrees for position and Julian centuries for time +* + +* Moon's mean longitude + DOUBLE PRECISION ELP0,ELP1,ELP2,ELP3,ELP,DELP + PARAMETER (ELP0=270.434164D0, + : ELP1=481267.8831D0, + : ELP2=-0.001133D0, + : ELP3=0.0000019D0) + +* Sun's mean anomaly + DOUBLE PRECISION EM0,EM1,EM2,EM3,EM,DEM + PARAMETER (EM0=358.475833D0, + : EM1=35999.0498D0, + : EM2=-0.000150D0, + : EM3=-0.0000033D0) + +* Moon's mean anomaly + DOUBLE PRECISION EMP0,EMP1,EMP2,EMP3,EMP,DEMP + PARAMETER (EMP0=296.104608D0, + : EMP1=477198.8491D0, + : EMP2=0.009192D0, + : EMP3=0.0000144D0) + +* Moon's mean elongation + DOUBLE PRECISION D0,D1,D2,D3,D,DD + PARAMETER (D0=350.737486D0, + : D1=445267.1142D0, + : D2=-0.001436D0, + : D3=0.0000019D0) + +* Mean distance of the Moon from its ascending node + DOUBLE PRECISION F0,F1,F2,F3,F,DF + PARAMETER (F0=11.250889D0, + : F1=483202.0251D0, + : F2=-0.003211D0, + : F3=-0.0000003D0) + +* Longitude of the Moon's ascending node + DOUBLE PRECISION OM0,OM1,OM2,OM3,OM,DOM + PARAMETER (OM0=259.183275D0, + : OM1=-1934.1420D0, + : OM2=0.002078D0, + : OM3=0.0000022D0) + +* Coefficients for (dimensionless) E factor + DOUBLE PRECISION E1,E2,E,DE,ESQ,DESQ + PARAMETER (E1=-0.002495D0,E2=-0.00000752D0) + +* Coefficients for periodic variations etc + DOUBLE PRECISION PAC,PA0,PA1 + PARAMETER (PAC=0.000233D0,PA0=51.2D0,PA1=20.2D0) + DOUBLE PRECISION PBC + PARAMETER (PBC=-0.001778D0) + DOUBLE PRECISION PCC + PARAMETER (PCC=0.000817D0) + DOUBLE PRECISION PDC + PARAMETER (PDC=0.002011D0) + DOUBLE PRECISION PEC,PE0,PE1,PE2 + PARAMETER (PEC=0.003964D0, + : PE0=346.560D0,PE1=132.870D0,PE2=-0.0091731D0) + DOUBLE PRECISION PFC + PARAMETER (PFC=0.001964D0) + DOUBLE PRECISION PGC + PARAMETER (PGC=0.002541D0) + DOUBLE PRECISION PHC + PARAMETER (PHC=0.001964D0) + DOUBLE PRECISION PIC + PARAMETER (PIC=-0.024691D0) + DOUBLE PRECISION PJC,PJ0,PJ1 + PARAMETER (PJC=-0.004328D0,PJ0=275.05D0,PJ1=-2.30D0) + DOUBLE PRECISION CW1 + PARAMETER (CW1=0.0004664D0) + DOUBLE PRECISION CW2 + PARAMETER (CW2=0.0000754D0) + +* +* Coefficients for Moon position +* +* Tx(N) = coefficient of L, B or P term (deg) +* ITx(N,1-5) = coefficients of M, M', D, F, E**n in argument +* + INTEGER NL,NB,NP + PARAMETER (NL=50,NB=45,NP=31) + DOUBLE PRECISION TL(NL),TB(NB),TP(NP) + INTEGER ITL(5,NL),ITB(5,NB),ITP(5,NP) +* +* Longitude +* M M' D F n + DATA TL( 1)/ +6.288750D0 /, + : (ITL(I, 1),I=1,5)/ +0, +1, +0, +0, 0 / + DATA TL( 2)/ +1.274018D0 /, + : (ITL(I, 2),I=1,5)/ +0, -1, +2, +0, 0 / + DATA TL( 3)/ +0.658309D0 /, + : (ITL(I, 3),I=1,5)/ +0, +0, +2, +0, 0 / + DATA TL( 4)/ +0.213616D0 /, + : (ITL(I, 4),I=1,5)/ +0, +2, +0, +0, 0 / + DATA TL( 5)/ -0.185596D0 /, + : (ITL(I, 5),I=1,5)/ +1, +0, +0, +0, 1 / + DATA TL( 6)/ -0.114336D0 /, + : (ITL(I, 6),I=1,5)/ +0, +0, +0, +2, 0 / + DATA TL( 7)/ +0.058793D0 /, + : (ITL(I, 7),I=1,5)/ +0, -2, +2, +0, 0 / + DATA TL( 8)/ +0.057212D0 /, + : (ITL(I, 8),I=1,5)/ -1, -1, +2, +0, 1 / + DATA TL( 9)/ +0.053320D0 /, + : (ITL(I, 9),I=1,5)/ +0, +1, +2, +0, 0 / + DATA TL(10)/ +0.045874D0 /, + : (ITL(I,10),I=1,5)/ -1, +0, +2, +0, 1 / + DATA TL(11)/ +0.041024D0 /, + : (ITL(I,11),I=1,5)/ -1, +1, +0, +0, 1 / + DATA TL(12)/ -0.034718D0 /, + : (ITL(I,12),I=1,5)/ +0, +0, +1, +0, 0 / + DATA TL(13)/ -0.030465D0 /, + : (ITL(I,13),I=1,5)/ +1, +1, +0, +0, 1 / + DATA TL(14)/ +0.015326D0 /, + : (ITL(I,14),I=1,5)/ +0, +0, +2, -2, 0 / + DATA TL(15)/ -0.012528D0 /, + : (ITL(I,15),I=1,5)/ +0, +1, +0, +2, 0 / + DATA TL(16)/ -0.010980D0 /, + : (ITL(I,16),I=1,5)/ +0, -1, +0, +2, 0 / + DATA TL(17)/ +0.010674D0 /, + : (ITL(I,17),I=1,5)/ +0, -1, +4, +0, 0 / + DATA TL(18)/ +0.010034D0 /, + : (ITL(I,18),I=1,5)/ +0, +3, +0, +0, 0 / + DATA TL(19)/ +0.008548D0 /, + : (ITL(I,19),I=1,5)/ +0, -2, +4, +0, 0 / + DATA TL(20)/ -0.007910D0 /, + : (ITL(I,20),I=1,5)/ +1, -1, +2, +0, 1 / + DATA TL(21)/ -0.006783D0 /, + : (ITL(I,21),I=1,5)/ +1, +0, +2, +0, 1 / + DATA TL(22)/ +0.005162D0 /, + : (ITL(I,22),I=1,5)/ +0, +1, -1, +0, 0 / + DATA TL(23)/ +0.005000D0 /, + : (ITL(I,23),I=1,5)/ +1, +0, +1, +0, 1 / + DATA TL(24)/ +0.004049D0 /, + : (ITL(I,24),I=1,5)/ -1, +1, +2, +0, 1 / + DATA TL(25)/ +0.003996D0 /, + : (ITL(I,25),I=1,5)/ +0, +2, +2, +0, 0 / + DATA TL(26)/ +0.003862D0 /, + : (ITL(I,26),I=1,5)/ +0, +0, +4, +0, 0 / + DATA TL(27)/ +0.003665D0 /, + : (ITL(I,27),I=1,5)/ +0, -3, +2, +0, 0 / + DATA TL(28)/ +0.002695D0 /, + : (ITL(I,28),I=1,5)/ -1, +2, +0, +0, 1 / + DATA TL(29)/ +0.002602D0 /, + : (ITL(I,29),I=1,5)/ +0, +1, -2, -2, 0 / + DATA TL(30)/ +0.002396D0 /, + : (ITL(I,30),I=1,5)/ -1, -2, +2, +0, 1 / + DATA TL(31)/ -0.002349D0 /, + : (ITL(I,31),I=1,5)/ +0, +1, +1, +0, 0 / + DATA TL(32)/ +0.002249D0 /, + : (ITL(I,32),I=1,5)/ -2, +0, +2, +0, 2 / + DATA TL(33)/ -0.002125D0 /, + : (ITL(I,33),I=1,5)/ +1, +2, +0, +0, 1 / + DATA TL(34)/ -0.002079D0 /, + : (ITL(I,34),I=1,5)/ +2, +0, +0, +0, 2 / + DATA TL(35)/ +0.002059D0 /, + : (ITL(I,35),I=1,5)/ -2, -1, +2, +0, 2 / + DATA TL(36)/ -0.001773D0 /, + : (ITL(I,36),I=1,5)/ +0, +1, +2, -2, 0 / + DATA TL(37)/ -0.001595D0 /, + : (ITL(I,37),I=1,5)/ +0, +0, +2, +2, 0 / + DATA TL(38)/ +0.001220D0 /, + : (ITL(I,38),I=1,5)/ -1, -1, +4, +0, 1 / + DATA TL(39)/ -0.001110D0 /, + : (ITL(I,39),I=1,5)/ +0, +2, +0, +2, 0 / + DATA TL(40)/ +0.000892D0 /, + : (ITL(I,40),I=1,5)/ +0, +1, -3, +0, 0 / + DATA TL(41)/ -0.000811D0 /, + : (ITL(I,41),I=1,5)/ +1, +1, +2, +0, 1 / + DATA TL(42)/ +0.000761D0 /, + : (ITL(I,42),I=1,5)/ -1, -2, +4, +0, 1 / + DATA TL(43)/ +0.000717D0 /, + : (ITL(I,43),I=1,5)/ -2, +1, +0, +0, 2 / + DATA TL(44)/ +0.000704D0 /, + : (ITL(I,44),I=1,5)/ -2, +1, -2, +0, 2 / + DATA TL(45)/ +0.000693D0 /, + : (ITL(I,45),I=1,5)/ +1, -2, +2, +0, 1 / + DATA TL(46)/ +0.000598D0 /, + : (ITL(I,46),I=1,5)/ -1, +0, +2, -2, 1 / + DATA TL(47)/ +0.000550D0 /, + : (ITL(I,47),I=1,5)/ +0, +1, +4, +0, 0 / + DATA TL(48)/ +0.000538D0 /, + : (ITL(I,48),I=1,5)/ +0, +4, +0, +0, 0 / + DATA TL(49)/ +0.000521D0 /, + : (ITL(I,49),I=1,5)/ -1, +0, +4, +0, 1 / + DATA TL(50)/ +0.000486D0 /, + : (ITL(I,50),I=1,5)/ +0, +2, -1, +0, 0 / +* +* Latitude +* M M' D F n + DATA TB( 1)/ +5.128189D0 /, + : (ITB(I, 1),I=1,5)/ +0, +0, +0, +1, 0 / + DATA TB( 2)/ +0.280606D0 /, + : (ITB(I, 2),I=1,5)/ +0, +1, +0, +1, 0 / + DATA TB( 3)/ +0.277693D0 /, + : (ITB(I, 3),I=1,5)/ +0, +1, +0, -1, 0 / + DATA TB( 4)/ +0.173238D0 /, + : (ITB(I, 4),I=1,5)/ +0, +0, +2, -1, 0 / + DATA TB( 5)/ +0.055413D0 /, + : (ITB(I, 5),I=1,5)/ +0, -1, +2, +1, 0 / + DATA TB( 6)/ +0.046272D0 /, + : (ITB(I, 6),I=1,5)/ +0, -1, +2, -1, 0 / + DATA TB( 7)/ +0.032573D0 /, + : (ITB(I, 7),I=1,5)/ +0, +0, +2, +1, 0 / + DATA TB( 8)/ +0.017198D0 /, + : (ITB(I, 8),I=1,5)/ +0, +2, +0, +1, 0 / + DATA TB( 9)/ +0.009267D0 /, + : (ITB(I, 9),I=1,5)/ +0, +1, +2, -1, 0 / + DATA TB(10)/ +0.008823D0 /, + : (ITB(I,10),I=1,5)/ +0, +2, +0, -1, 0 / + DATA TB(11)/ +0.008247D0 /, + : (ITB(I,11),I=1,5)/ -1, +0, +2, -1, 1 / + DATA TB(12)/ +0.004323D0 /, + : (ITB(I,12),I=1,5)/ +0, -2, +2, -1, 0 / + DATA TB(13)/ +0.004200D0 /, + : (ITB(I,13),I=1,5)/ +0, +1, +2, +1, 0 / + DATA TB(14)/ +0.003372D0 /, + : (ITB(I,14),I=1,5)/ -1, +0, -2, +1, 1 / + DATA TB(15)/ +0.002472D0 /, + : (ITB(I,15),I=1,5)/ -1, -1, +2, +1, 1 / + DATA TB(16)/ +0.002222D0 /, + : (ITB(I,16),I=1,5)/ -1, +0, +2, +1, 1 / + DATA TB(17)/ +0.002072D0 /, + : (ITB(I,17),I=1,5)/ -1, -1, +2, -1, 1 / + DATA TB(18)/ +0.001877D0 /, + : (ITB(I,18),I=1,5)/ -1, +1, +0, +1, 1 / + DATA TB(19)/ +0.001828D0 /, + : (ITB(I,19),I=1,5)/ +0, -1, +4, -1, 0 / + DATA TB(20)/ -0.001803D0 /, + : (ITB(I,20),I=1,5)/ +1, +0, +0, +1, 1 / + DATA TB(21)/ -0.001750D0 /, + : (ITB(I,21),I=1,5)/ +0, +0, +0, +3, 0 / + DATA TB(22)/ +0.001570D0 /, + : (ITB(I,22),I=1,5)/ -1, +1, +0, -1, 1 / + DATA TB(23)/ -0.001487D0 /, + : (ITB(I,23),I=1,5)/ +0, +0, +1, +1, 0 / + DATA TB(24)/ -0.001481D0 /, + : (ITB(I,24),I=1,5)/ +1, +1, +0, +1, 1 / + DATA TB(25)/ +0.001417D0 /, + : (ITB(I,25),I=1,5)/ -1, -1, +0, +1, 1 / + DATA TB(26)/ +0.001350D0 /, + : (ITB(I,26),I=1,5)/ -1, +0, +0, +1, 1 / + DATA TB(27)/ +0.001330D0 /, + : (ITB(I,27),I=1,5)/ +0, +0, -1, +1, 0 / + DATA TB(28)/ +0.001106D0 /, + : (ITB(I,28),I=1,5)/ +0, +3, +0, +1, 0 / + DATA TB(29)/ +0.001020D0 /, + : (ITB(I,29),I=1,5)/ +0, +0, +4, -1, 0 / + DATA TB(30)/ +0.000833D0 /, + : (ITB(I,30),I=1,5)/ +0, -1, +4, +1, 0 / + DATA TB(31)/ +0.000781D0 /, + : (ITB(I,31),I=1,5)/ +0, +1, +0, -3, 0 / + DATA TB(32)/ +0.000670D0 /, + : (ITB(I,32),I=1,5)/ +0, -2, +4, +1, 0 / + DATA TB(33)/ +0.000606D0 /, + : (ITB(I,33),I=1,5)/ +0, +0, +2, -3, 0 / + DATA TB(34)/ +0.000597D0 /, + : (ITB(I,34),I=1,5)/ +0, +2, +2, -1, 0 / + DATA TB(35)/ +0.000492D0 /, + : (ITB(I,35),I=1,5)/ -1, +1, +2, -1, 1 / + DATA TB(36)/ +0.000450D0 /, + : (ITB(I,36),I=1,5)/ +0, +2, -2, -1, 0 / + DATA TB(37)/ +0.000439D0 /, + : (ITB(I,37),I=1,5)/ +0, +3, +0, -1, 0 / + DATA TB(38)/ +0.000423D0 /, + : (ITB(I,38),I=1,5)/ +0, +2, +2, +1, 0 / + DATA TB(39)/ +0.000422D0 /, + : (ITB(I,39),I=1,5)/ +0, -3, +2, -1, 0 / + DATA TB(40)/ -0.000367D0 /, + : (ITB(I,40),I=1,5)/ +1, -1, +2, +1, 1 / + DATA TB(41)/ -0.000353D0 /, + : (ITB(I,41),I=1,5)/ +1, +0, +2, +1, 1 / + DATA TB(42)/ +0.000331D0 /, + : (ITB(I,42),I=1,5)/ +0, +0, +4, +1, 0 / + DATA TB(43)/ +0.000317D0 /, + : (ITB(I,43),I=1,5)/ -1, +1, +2, +1, 1 / + DATA TB(44)/ +0.000306D0 /, + : (ITB(I,44),I=1,5)/ -2, +0, +2, -1, 2 / + DATA TB(45)/ -0.000283D0 /, + : (ITB(I,45),I=1,5)/ +0, +1, +0, +3, 0 / +* +* Parallax +* M M' D F n + DATA TP( 1)/ +0.950724D0 /, + : (ITP(I, 1),I=1,5)/ +0, +0, +0, +0, 0 / + DATA TP( 2)/ +0.051818D0 /, + : (ITP(I, 2),I=1,5)/ +0, +1, +0, +0, 0 / + DATA TP( 3)/ +0.009531D0 /, + : (ITP(I, 3),I=1,5)/ +0, -1, +2, +0, 0 / + DATA TP( 4)/ +0.007843D0 /, + : (ITP(I, 4),I=1,5)/ +0, +0, +2, +0, 0 / + DATA TP( 5)/ +0.002824D0 /, + : (ITP(I, 5),I=1,5)/ +0, +2, +0, +0, 0 / + DATA TP( 6)/ +0.000857D0 /, + : (ITP(I, 6),I=1,5)/ +0, +1, +2, +0, 0 / + DATA TP( 7)/ +0.000533D0 /, + : (ITP(I, 7),I=1,5)/ -1, +0, +2, +0, 1 / + DATA TP( 8)/ +0.000401D0 /, + : (ITP(I, 8),I=1,5)/ -1, -1, +2, +0, 1 / + DATA TP( 9)/ +0.000320D0 /, + : (ITP(I, 9),I=1,5)/ -1, +1, +0, +0, 1 / + DATA TP(10)/ -0.000271D0 /, + : (ITP(I,10),I=1,5)/ +0, +0, +1, +0, 0 / + DATA TP(11)/ -0.000264D0 /, + : (ITP(I,11),I=1,5)/ +1, +1, +0, +0, 1 / + DATA TP(12)/ -0.000198D0 /, + : (ITP(I,12),I=1,5)/ +0, -1, +0, +2, 0 / + DATA TP(13)/ +0.000173D0 /, + : (ITP(I,13),I=1,5)/ +0, +3, +0, +0, 0 / + DATA TP(14)/ +0.000167D0 /, + : (ITP(I,14),I=1,5)/ +0, -1, +4, +0, 0 / + DATA TP(15)/ -0.000111D0 /, + : (ITP(I,15),I=1,5)/ +1, +0, +0, +0, 1 / + DATA TP(16)/ +0.000103D0 /, + : (ITP(I,16),I=1,5)/ +0, -2, +4, +0, 0 / + DATA TP(17)/ -0.000084D0 /, + : (ITP(I,17),I=1,5)/ +0, +2, -2, +0, 0 / + DATA TP(18)/ -0.000083D0 /, + : (ITP(I,18),I=1,5)/ +1, +0, +2, +0, 1 / + DATA TP(19)/ +0.000079D0 /, + : (ITP(I,19),I=1,5)/ +0, +2, +2, +0, 0 / + DATA TP(20)/ +0.000072D0 /, + : (ITP(I,20),I=1,5)/ +0, +0, +4, +0, 0 / + DATA TP(21)/ +0.000064D0 /, + : (ITP(I,21),I=1,5)/ -1, +1, +2, +0, 1 / + DATA TP(22)/ -0.000063D0 /, + : (ITP(I,22),I=1,5)/ +1, -1, +2, +0, 1 / + DATA TP(23)/ +0.000041D0 /, + : (ITP(I,23),I=1,5)/ +1, +0, +1, +0, 1 / + DATA TP(24)/ +0.000035D0 /, + : (ITP(I,24),I=1,5)/ -1, +2, +0, +0, 1 / + DATA TP(25)/ -0.000033D0 /, + : (ITP(I,25),I=1,5)/ +0, +3, -2, +0, 0 / + DATA TP(26)/ -0.000030D0 /, + : (ITP(I,26),I=1,5)/ +0, +1, +1, +0, 0 / + DATA TP(27)/ -0.000029D0 /, + : (ITP(I,27),I=1,5)/ +0, +0, -2, +2, 0 / + DATA TP(28)/ -0.000029D0 /, + : (ITP(I,28),I=1,5)/ +1, +2, +0, +0, 1 / + DATA TP(29)/ +0.000026D0 /, + : (ITP(I,29),I=1,5)/ -2, +0, +2, +0, 2 / + DATA TP(30)/ -0.000023D0 /, + : (ITP(I,30),I=1,5)/ +0, +1, -2, +2, 0 / + DATA TP(31)/ +0.000019D0 /, + : (ITP(I,31),I=1,5)/ -1, -1, +4, +0, 1 / + + + +* Centuries since J1900 + T=(DATE-15019.5D0)/36525D0 + +* +* Fundamental arguments (radians) and derivatives (radians per +* Julian century) for the current epoch +* + +* Moon's mean longitude + ELP=D2R*MOD(ELP0+(ELP1+(ELP2+ELP3*T)*T)*T,360D0) + DELP=D2R*(ELP1+(2D0*ELP2+3D0*ELP3*T)*T) + +* Sun's mean anomaly + EM=D2R*MOD(EM0+(EM1+(EM2+EM3*T)*T)*T,360D0) + DEM=D2R*(EM1+(2D0*EM2+3D0*EM3*T)*T) + +* Moon's mean anomaly + EMP=D2R*MOD(EMP0+(EMP1+(EMP2+EMP3*T)*T)*T,360D0) + DEMP=D2R*(EMP1+(2D0*EMP2+3D0*EMP3*T)*T) + +* Moon's mean elongation + D=D2R*MOD(D0+(D1+(D2+D3*T)*T)*T,360D0) + DD=D2R*(D1+(2D0*D2+3D0*D3*T)*T) + +* Mean distance of the Moon from its ascending node + F=D2R*MOD(F0+(F1+(F2+F3*T)*T)*T,360D0) + DF=D2R*(F1+(2D0*F2+3D0*F3*T)*T) + +* Longitude of the Moon's ascending node + OM=D2R*MOD(OM0+(OM1+(OM2+OM3*T)*T)*T,360D0) + DOM=D2R*(OM1+(2D0*OM2+3D0*OM3*T)*T) + SINOM=SIN(OM) + COSOM=COS(OM) + DOMCOM=DOM*COSOM + +* Add the periodic variations + THETA=D2R*(PA0+PA1*T) + WA=SIN(THETA) + DWA=D2R*PA1*COS(THETA) + THETA=D2R*(PE0+(PE1+PE2*T)*T) + WB=PEC*SIN(THETA) + DWB=D2R*PEC*(PE1+2D0*PE2*T)*COS(THETA) + ELP=ELP+D2R*(PAC*WA+WB+PFC*SINOM) + DELP=DELP+D2R*(PAC*DWA+DWB+PFC*DOMCOM) + EM=EM+D2R*PBC*WA + DEM=DEM+D2R*PBC*DWA + EMP=EMP+D2R*(PCC*WA+WB+PGC*SINOM) + DEMP=DEMP+D2R*(PCC*DWA+DWB+PGC*DOMCOM) + D=D+D2R*(PDC*WA+WB+PHC*SINOM) + DD=DD+D2R*(PDC*DWA+DWB+PHC*DOMCOM) + WOM=OM+D2R*(PJ0+PJ1*T) + DWOM=DOM+D2R*PJ1 + SINWOM=SIN(WOM) + COSWOM=COS(WOM) + F=F+D2R*(WB+PIC*SINOM+PJC*SINWOM) + DF=DF+D2R*(DWB+PIC*DOMCOM+PJC*DWOM*COSWOM) + +* E-factor, and square + E=1D0+(E1+E2*T)*T + DE=E1+2D0*E2*T + ESQ=E*E + DESQ=2D0*E*DE + +* +* Series expansions +* + +* Longitude + V=0D0 + DV=0D0 + DO N=NL,1,-1 + COEFF=TL(N) + EMN=DBLE(ITL(1,N)) + EMPN=DBLE(ITL(2,N)) + DN=DBLE(ITL(3,N)) + FN=DBLE(ITL(4,N)) + I=ITL(5,N) + IF (I.EQ.0) THEN + EN=1D0 + DEN=0D0 + ELSE IF (I.EQ.1) THEN + EN=E + DEN=DE + ELSE + EN=ESQ + DEN=DESQ + END IF + THETA=EMN*EM+EMPN*EMP+DN*D+FN*F + DTHETA=EMN*DEM+EMPN*DEMP+DN*DD+FN*DF + FTHETA=SIN(THETA) + V=V+COEFF*FTHETA*EN + DV=DV+COEFF*(COS(THETA)*DTHETA*EN+FTHETA*DEN) + END DO + EL=ELP+D2R*V + DEL=(DELP+D2R*DV)/CJ + +* Latitude + V=0D0 + DV=0D0 + DO N=NB,1,-1 + COEFF=TB(N) + EMN=DBLE(ITB(1,N)) + EMPN=DBLE(ITB(2,N)) + DN=DBLE(ITB(3,N)) + FN=DBLE(ITB(4,N)) + I=ITB(5,N) + IF (I.EQ.0) THEN + EN=1D0 + DEN=0D0 + ELSE IF (I.EQ.1) THEN + EN=E + DEN=DE + ELSE + EN=ESQ + DEN=DESQ + END IF + THETA=EMN*EM+EMPN*EMP+DN*D+FN*F + DTHETA=EMN*DEM+EMPN*DEMP+DN*DD+FN*DF + FTHETA=SIN(THETA) + V=V+COEFF*FTHETA*EN + DV=DV+COEFF*(COS(THETA)*DTHETA*EN+FTHETA*DEN) + END DO + BF=1D0-CW1*COSOM-CW2*COSWOM + DBF=CW1*DOM*SINOM+CW2*DWOM*SINWOM + B=D2R*V*BF + DB=D2R*(DV*BF+V*DBF)/CJ + +* Parallax + V=0D0 + DV=0D0 + DO N=NP,1,-1 + COEFF=TP(N) + EMN=DBLE(ITP(1,N)) + EMPN=DBLE(ITP(2,N)) + DN=DBLE(ITP(3,N)) + FN=DBLE(ITP(4,N)) + I=ITP(5,N) + IF (I.EQ.0) THEN + EN=1D0 + DEN=0D0 + ELSE IF (I.EQ.1) THEN + EN=E + DEN=DE + ELSE + EN=ESQ + DEN=DESQ + END IF + THETA=EMN*EM+EMPN*EMP+DN*D+FN*F + DTHETA=EMN*DEM+EMPN*DEMP+DN*DD+FN*DF + FTHETA=COS(THETA) + V=V+COEFF*FTHETA*EN + DV=DV+COEFF*(-SIN(THETA)*DTHETA*EN+FTHETA*DEN) + END DO + P=D2R*V + DP=D2R*DV/CJ + +* +* Transformation into final form +* + +* Parallax to distance (AU, AU/sec) + SP=SIN(P) + R=ERADAU/SP + DR=-R*DP*COS(P)/SP + +* Longitude, latitude to x,y,z (AU) + SEL=SIN(EL) + CEL=COS(EL) + SB=SIN(B) + CB=COS(B) + RCB=R*CB + RBD=R*DB + W=RBD*SB-CB*DR + X=RCB*CEL + Y=RCB*SEL + Z=R*SB + XD=-Y*DEL-W*CEL + YD=X*DEL-W*SEL + ZD=RBD*CB+SB*DR + +* Julian centuries since J2000 + T=(DATE-51544.5D0)/36525D0 + +* Fricke equinox correction + EPJ=2000D0+T*100D0 + EQCOR=DS2R*(0.035D0+0.00085D0*(EPJ-B1950)) + +* Mean obliquity (IAU 1976) + EPS=DAS2R*(84381.448D0+(-46.8150D0+(-0.00059D0+0.001813D0*T)*T)*T) + +* To the equatorial system, mean of date, FK5 system + SINEPS=SIN(EPS) + COSEPS=COS(EPS) + ES=EQCOR*SINEPS + EC=EQCOR*COSEPS + PV(1)=X-EC*Y+ES*Z + PV(2)=EQCOR*X+Y*COSEPS-Z*SINEPS + PV(3)=Y*SINEPS+Z*COSEPS + PV(4)=XD-EC*YD+ES*ZD + PV(5)=EQCOR*XD+YD*COSEPS-ZD*SINEPS + PV(6)=YD*SINEPS+ZD*COSEPS + + END + SUBROUTINE sla_DMXV (DM, VA, VB) +*+ +* - - - - - +* D M X V +* - - - - - +* +* Performs the 3-D forward unitary transformation: +* +* vector VB = matrix DM * vector VA +* +* (double precision) +* +* Given: +* DM dp(3,3) matrix +* VA dp(3) vector +* +* Returned: +* VB dp(3) result vector +* +* To comply with the ANSI Fortran 77 standard, VA and VB must be +* different arrays. However, the routine is coded so as to work +* properly on many platforms even if this rule is violated. +* +* Last revision: 26 December 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DM(3,3),VA(3),VB(3) + + INTEGER I,J + DOUBLE PRECISION W,VW(3) + + +* Matrix DM * vector VA -> vector VW + DO J=1,3 + W=0D0 + DO I=1,3 + W=W+DM(J,I)*VA(I) + END DO + VW(J)=W + END DO + +* Vector VW -> vector VB + DO J=1,3 + VB(J)=VW(J) + END DO + + END + DOUBLE PRECISION FUNCTION sla_DRANGE (ANGLE) +*+ +* - - - - - - - +* D R A N G E +* - - - - - - - +* +* Normalize angle into range +/- pi (double precision) +* +* Given: +* ANGLE dp the angle in radians +* +* The result (double precision) is ANGLE expressed in the range +/- pi. +* +* P.T.Wallace Starlink 23 November 1995 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION ANGLE + + DOUBLE PRECISION DPI,D2PI + PARAMETER (DPI=3.141592653589793238462643D0) + PARAMETER (D2PI=6.283185307179586476925287D0) + + + sla_DRANGE=MOD(ANGLE,D2PI) + IF (ABS(sla_DRANGE).GE.DPI) + : sla_DRANGE=sla_DRANGE-SIGN(D2PI,ANGLE) + + END + DOUBLE PRECISION FUNCTION sla_DRANRM (ANGLE) +*+ +* - - - - - - - +* D R A N R M +* - - - - - - - +* +* Normalize angle into range 0-2 pi (double precision) +* +* Given: +* ANGLE dp the angle in radians +* +* The result is ANGLE expressed in the range 0-2 pi. +* +* Last revision: 22 July 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION ANGLE + + DOUBLE PRECISION D2PI + PARAMETER (D2PI=6.283185307179586476925286766559D0) + + + sla_DRANRM = MOD(ANGLE,D2PI) + IF (sla_DRANRM.LT.0D0) sla_DRANRM = sla_DRANRM+D2PI + + END + DOUBLE PRECISION FUNCTION sla_DTT (UTC) +*+ +* - - - - +* D T T +* - - - - +* +* Increment to be applied to Coordinated Universal Time UTC to give +* Terrestrial Time TT (formerly Ephemeris Time ET) +* +* (double precision) +* +* Given: +* UTC d UTC date as a modified JD (JD-2400000.5) +* +* Result: TT-UTC in seconds +* +* Notes: +* +* 1 The UTC is specified to be a date rather than a time to indicate +* that care needs to be taken not to specify an instant which lies +* within a leap second. Though in most cases UTC can include the +* fractional part, correct behaviour on the day of a leap second +* can only be guaranteed up to the end of the second 23:59:59. +* +* 2 Pre 1972 January 1 a fixed value of 10 + ET-TAI is returned. +* +* 3 See also the routine sla_DT, which roughly estimates ET-UT for +* historical epochs. +* +* Called: sla_DAT +* +* P.T.Wallace Starlink 6 December 1994 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION UTC + + DOUBLE PRECISION sla_DAT + + + sla_DTT=32.184D0+sla_DAT(UTC) + + END + SUBROUTINE sla_ECMAT (DATE, RMAT) +*+ +* - - - - - - +* E C M A T +* - - - - - - +* +* Form the equatorial to ecliptic rotation matrix - IAU 1980 theory +* (double precision) +* +* Given: +* DATE dp TDB (loosely ET) as Modified Julian Date +* (JD-2400000.5) +* Returned: +* RMAT dp(3,3) matrix +* +* Reference: +* Murray,C.A., Vectorial Astrometry, section 4.3. +* +* Note: +* The matrix is in the sense V(ecl) = RMAT * V(equ); the +* equator, equinox and ecliptic are mean of date. +* +* Called: sla_DEULER +* +* P.T.Wallace Starlink 23 August 1996 +* +* Copyright (C) 1996 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE,RMAT(3,3) + +* Arc seconds to radians + DOUBLE PRECISION AS2R + PARAMETER (AS2R=0.484813681109535994D-5) + + DOUBLE PRECISION T,EPS0 + + + +* Interval between basic epoch J2000.0 and current epoch (JC) + T = (DATE-51544.5D0)/36525D0 + +* Mean obliquity + EPS0 = AS2R* + : (84381.448D0+(-46.8150D0+(-0.00059D0+0.001813D0*T)*T)*T) + +* Matrix + CALL sla_DEULER('X',EPS0,0D0,0D0,RMAT) + + END + DOUBLE PRECISION FUNCTION sla_EPJ (DATE) +*+ +* - - - - +* E P J +* - - - - +* +* Conversion of Modified Julian Date to Julian Epoch (double precision) +* +* Given: +* DATE dp Modified Julian Date (JD - 2400000.5) +* +* The result is the Julian Epoch. +* +* Reference: +* Lieske,J.H., 1979. Astron.Astrophys.,73,282. +* +* P.T.Wallace Starlink February 1984 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE + + + sla_EPJ = 2000D0 + (DATE-51544.5D0)/365.25D0 + + END + SUBROUTINE sla_EQECL (DR, DD, DATE, DL, DB) +*+ +* - - - - - - +* E Q E C L +* - - - - - - +* +* Transformation from J2000.0 equatorial coordinates to +* ecliptic coordinates (double precision) +* +* Given: +* DR,DD dp J2000.0 mean RA,Dec (radians) +* DATE dp TDB (loosely ET) as Modified Julian Date +* (JD-2400000.5) +* Returned: +* DL,DB dp ecliptic longitude and latitude +* (mean of date, IAU 1980 theory, radians) +* +* Called: +* sla_DCS2C, sla_PREC, sla_EPJ, sla_DMXV, sla_ECMAT, sla_DCC2S, +* sla_DRANRM, sla_DRANGE +* +* P.T.Wallace Starlink March 1986 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DR,DD,DATE,DL,DB + + DOUBLE PRECISION sla_EPJ,sla_DRANRM,sla_DRANGE + + DOUBLE PRECISION RMAT(3,3),V1(3),V2(3) + + + +* Spherical to Cartesian + CALL sla_DCS2C(DR,DD,V1) + +* Mean J2000 to mean of date + CALL sla_PREC(2000D0,sla_EPJ(DATE),RMAT) + CALL sla_DMXV(RMAT,V1,V2) + +* Equatorial to ecliptic + CALL sla_ECMAT(DATE,RMAT) + CALL sla_DMXV(RMAT,V2,V1) + +* Cartesian to spherical + CALL sla_DCC2S(V1,DL,DB) + +* Express in conventional ranges + DL=sla_DRANRM(DL) + DB=sla_DRANGE(DB) + + END + DOUBLE PRECISION FUNCTION sla_EQEQX (DATE) +*+ +* - - - - - - +* E Q E Q X +* - - - - - - +* +* Equation of the equinoxes (IAU 1994, double precision) +* +* Given: +* DATE dp TDB (loosely ET) as Modified Julian Date +* (JD-2400000.5) +* +* The result is the equation of the equinoxes (double precision) +* in radians: +* +* Greenwich apparent ST = GMST + sla_EQEQX +* +* References: IAU Resolution C7, Recommendation 3 (1994) +* Capitaine, N. & Gontier, A.-M., Astron. Astrophys., +* 275, 645-650 (1993) +* +* Called: sla_NUTC +* +* Patrick Wallace Starlink 23 August 1996 +* +* Copyright (C) 1996 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE + +* Turns to arc seconds and arc seconds to radians + DOUBLE PRECISION T2AS,AS2R + PARAMETER (T2AS=1296000D0, + : AS2R=0.484813681109535994D-5) + + DOUBLE PRECISION T,OM,DPSI,DEPS,EPS0 + + + +* Interval between basic epoch J2000.0 and current epoch (JC) + T=(DATE-51544.5D0)/36525D0 + +* Longitude of the mean ascending node of the lunar orbit on the +* ecliptic, measured from the mean equinox of date + OM=AS2R*(450160.280D0+(-5D0*T2AS-482890.539D0 + : +(7.455D0+0.008D0*T)*T)*T) + +* Nutation + CALL sla_NUTC(DATE,DPSI,DEPS,EPS0) + +* Equation of the equinoxes + sla_EQEQX=DPSI*COS(EPS0)+AS2R*(0.00264D0*SIN(OM)+ + : 0.000063D0*SIN(OM+OM)) + + END + SUBROUTINE sla_GEOC (P, H, R, Z) +*+ +* - - - - - +* G E O C +* - - - - - +* +* Convert geodetic position to geocentric (double precision) +* +* Given: +* P dp latitude (geodetic, radians) +* H dp height above reference spheroid (geodetic, metres) +* +* Returned: +* R dp distance from Earth axis (AU) +* Z dp distance from plane of Earth equator (AU) +* +* Notes: +* +* 1 Geocentric latitude can be obtained by evaluating ATAN2(Z,R). +* +* 2 IAU 1976 constants are used. +* +* Reference: +* +* Green,R.M., Spherical Astronomy, CUP 1985, p98. +* +* Last revision: 22 July 2004 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION P,H,R,Z + +* Earth equatorial radius (metres) + DOUBLE PRECISION A0 + PARAMETER (A0=6378140D0) + +* Reference spheroid flattening factor and useful function + DOUBLE PRECISION F,B + PARAMETER (F=1D0/298.257D0,B=(1D0-F)**2) + +* Astronomical unit in metres + DOUBLE PRECISION AU + PARAMETER (AU=1.49597870D11) + + DOUBLE PRECISION SP,CP,C,S + + + +* Geodetic to geocentric conversion + SP = SIN(P) + CP = COS(P) + C = 1D0/SQRT(CP*CP+B*SP*SP) + S = B*C + R = (A0*C+H)*CP/AU + Z = (A0*S+H)*SP/AU + + END + DOUBLE PRECISION FUNCTION sla_GMST (UT1) +*+ +* - - - - - +* G M S T +* - - - - - +* +* Conversion from universal time to sidereal time (double precision) +* +* Given: +* UT1 dp universal time (strictly UT1) expressed as +* modified Julian Date (JD-2400000.5) +* +* The result is the Greenwich mean sidereal time (double +* precision, radians). +* +* The IAU 1982 expression (see page S15 of 1984 Astronomical Almanac) +* is used, but rearranged to reduce rounding errors. This expression +* is always described as giving the GMST at 0 hours UT. In fact, it +* gives the difference between the GMST and the UT, which happens to +* equal the GMST (modulo 24 hours) at 0 hours UT each day. In this +* routine, the entire UT is used directly as the argument for the +* standard formula, and the fractional part of the UT is added +* separately. Note that the factor 1.0027379... does not appear in the +* IAU 1982 expression explicitly but in the form of the coefficient +* 8640184.812866, which is 86400x36525x0.0027379... +* +* See also the routine sla_GMSTA, which delivers better numerical +* precision by accepting the UT date and time as separate arguments. +* +* Called: sla_DRANRM +* +* P.T.Wallace Starlink 14 October 2001 +* +* Copyright (C) 2001 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION UT1 + + DOUBLE PRECISION sla_DRANRM + + DOUBLE PRECISION D2PI,S2R + PARAMETER (D2PI=6.283185307179586476925286766559D0, + : S2R=7.272205216643039903848711535369D-5) + + DOUBLE PRECISION TU + + + +* Julian centuries from fundamental epoch J2000 to this UT + TU=(UT1-51544.5D0)/36525D0 + +* GMST at this UT + sla_GMST=sla_DRANRM(MOD(UT1,1D0)*D2PI+ + : (24110.54841D0+ + : (8640184.812866D0+ + : (0.093104D0-6.2D-6*TU)*TU)*TU)*S2R) + + END + SUBROUTINE sla_NUTC (DATE, DPSI, DEPS, EPS0) +*+ +* - - - - - +* N U T C +* - - - - - +* +* Nutation: longitude & obliquity components and mean obliquity, +* using the Shirai & Fukushima (2001) theory. +* +* Given: +* DATE d TDB (loosely ET) as Modified Julian Date +* (JD-2400000.5) +* Returned: +* DPSI,DEPS d nutation in longitude,obliquity +* EPS0 d mean obliquity +* +* Notes: +* +* 1 The routine predicts forced nutation (but not free core nutation) +* plus corrections to the IAU 1976 precession model. +* +* 2 Earth attitude predictions made by combining the present nutation +* model with IAU 1976 precession are accurate to 1 mas (with respect +* to the ICRF) for a few decades around 2000. +* +* 3 The sla_NUTC80 routine is the equivalent of the present routine +* but using the IAU 1980 nutation theory. The older theory is less +* accurate, leading to errors as large as 350 mas over the interval +* 1900-2100, mainly because of the error in the IAU 1976 precession. +* +* References: +* +* Shirai, T. & Fukushima, T., Astron.J. 121, 3270-3283 (2001). +* +* Fukushima, T., Astron.Astrophys. 244, L11 (1991). +* +* Simon, J. L., Bretagnon, P., Chapront, J., Chapront-Touze, M., +* Francou, G. & Laskar, J., Astron.Astrophys. 282, 663 (1994). +* +* This revision: 24 November 2005 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE,DPSI,DEPS,EPS0 + +* Degrees to radians + DOUBLE PRECISION DD2R + PARAMETER (DD2R=1.745329251994329576923691D-2) + +* Arc seconds to radians + DOUBLE PRECISION DAS2R + PARAMETER (DAS2R=4.848136811095359935899141D-6) + +* Arc seconds in a full circle + DOUBLE PRECISION TURNAS + PARAMETER (TURNAS=1296000D0) + +* Reference epoch (J2000), MJD + DOUBLE PRECISION DJM0 + PARAMETER (DJM0=51544.5D0 ) + +* Days per Julian century + DOUBLE PRECISION DJC + PARAMETER (DJC=36525D0) + + INTEGER I,J + DOUBLE PRECISION T,EL,ELP,F,D,OM,VE,MA,JU,SA,THETA,C,S,DP,DE + +* Number of terms in the nutation model + INTEGER NTERMS + PARAMETER (NTERMS=194) + +* The SF2001 forced nutation model + INTEGER NA(9,NTERMS) + DOUBLE PRECISION PSI(4,NTERMS), EPS(4,NTERMS) + +* Coefficients of fundamental angles + DATA ( ( NA(I,J), I=1,9 ), J=1,10 ) / + : 0, 0, 0, 0, -1, 0, 0, 0, 0, + : 0, 0, 2, -2, 2, 0, 0, 0, 0, + : 0, 0, 2, 0, 2, 0, 0, 0, 0, + : 0, 0, 0, 0, -2, 0, 0, 0, 0, + : 0, 1, 0, 0, 0, 0, 0, 0, 0, + : 0, 1, 2, -2, 2, 0, 0, 0, 0, + : 1, 0, 0, 0, 0, 0, 0, 0, 0, + : 0, 0, 2, 0, 1, 0, 0, 0, 0, + : 1, 0, 2, 0, 2, 0, 0, 0, 0, + : 0, -1, 2, -2, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=11,20 ) / + : 0, 0, 2, -2, 1, 0, 0, 0, 0, + : -1, 0, 2, 0, 2, 0, 0, 0, 0, + : -1, 0, 0, 2, 0, 0, 0, 0, 0, + : 1, 0, 0, 0, 1, 0, 0, 0, 0, + : 1, 0, 0, 0, -1, 0, 0, 0, 0, + : -1, 0, 2, 2, 2, 0, 0, 0, 0, + : 1, 0, 2, 0, 1, 0, 0, 0, 0, + : -2, 0, 2, 0, 1, 0, 0, 0, 0, + : 0, 0, 0, 2, 0, 0, 0, 0, 0, + : 0, 0, 2, 2, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=21,30 ) / + : 2, 0, 0, -2, 0, 0, 0, 0, 0, + : 2, 0, 2, 0, 2, 0, 0, 0, 0, + : 1, 0, 2, -2, 2, 0, 0, 0, 0, + : -1, 0, 2, 0, 1, 0, 0, 0, 0, + : 2, 0, 0, 0, 0, 0, 0, 0, 0, + : 0, 0, 2, 0, 0, 0, 0, 0, 0, + : 0, 1, 0, 0, 1, 0, 0, 0, 0, + : -1, 0, 0, 2, 1, 0, 0, 0, 0, + : 0, 2, 2, -2, 2, 0, 0, 0, 0, + : 0, 0, 2, -2, 0, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=31,40 ) / + : -1, 0, 0, 2, -1, 0, 0, 0, 0, + : 0, 1, 0, 0, -1, 0, 0, 0, 0, + : 0, 2, 0, 0, 0, 0, 0, 0, 0, + : -1, 0, 2, 2, 1, 0, 0, 0, 0, + : 1, 0, 2, 2, 2, 0, 0, 0, 0, + : 0, 1, 2, 0, 2, 0, 0, 0, 0, + : -2, 0, 2, 0, 0, 0, 0, 0, 0, + : 0, 0, 2, 2, 1, 0, 0, 0, 0, + : 0, -1, 2, 0, 2, 0, 0, 0, 0, + : 0, 0, 0, 2, 1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=41,50 ) / + : 1, 0, 2, -2, 1, 0, 0, 0, 0, + : 2, 0, 0, -2, -1, 0, 0, 0, 0, + : 2, 0, 2, -2, 2, 0, 0, 0, 0, + : 2, 0, 2, 0, 1, 0, 0, 0, 0, + : 0, 0, 0, 2, -1, 0, 0, 0, 0, + : 0, -1, 2, -2, 1, 0, 0, 0, 0, + : -1, -1, 0, 2, 0, 0, 0, 0, 0, + : 2, 0, 0, -2, 1, 0, 0, 0, 0, + : 1, 0, 0, 2, 0, 0, 0, 0, 0, + : 0, 1, 2, -2, 1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=51,60 ) / + : 1, -1, 0, 0, 0, 0, 0, 0, 0, + : -2, 0, 2, 0, 2, 0, 0, 0, 0, + : 0, -1, 0, 2, 0, 0, 0, 0, 0, + : 3, 0, 2, 0, 2, 0, 0, 0, 0, + : 0, 0, 0, 1, 0, 0, 0, 0, 0, + : 1, -1, 2, 0, 2, 0, 0, 0, 0, + : 1, 0, 0, -1, 0, 0, 0, 0, 0, + : -1, -1, 2, 2, 2, 0, 0, 0, 0, + : -1, 0, 2, 0, 0, 0, 0, 0, 0, + : 2, 0, 0, 0, -1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=61,70 ) / + : 0, -1, 2, 2, 2, 0, 0, 0, 0, + : 1, 1, 2, 0, 2, 0, 0, 0, 0, + : 2, 0, 0, 0, 1, 0, 0, 0, 0, + : 1, 1, 0, 0, 0, 0, 0, 0, 0, + : 1, 0, -2, 2, -1, 0, 0, 0, 0, + : 1, 0, 2, 0, 0, 0, 0, 0, 0, + : -1, 1, 0, 1, 0, 0, 0, 0, 0, + : 1, 0, 0, 0, 2, 0, 0, 0, 0, + : -1, 0, 1, 0, 1, 0, 0, 0, 0, + : 0, 0, 2, 1, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=71,80 ) / + : -1, 1, 0, 1, 1, 0, 0, 0, 0, + : -1, 0, 2, 4, 2, 0, 0, 0, 0, + : 0, -2, 2, -2, 1, 0, 0, 0, 0, + : 1, 0, 2, 2, 1, 0, 0, 0, 0, + : 1, 0, 0, 0, -2, 0, 0, 0, 0, + : -2, 0, 2, 2, 2, 0, 0, 0, 0, + : 1, 1, 2, -2, 2, 0, 0, 0, 0, + : -2, 0, 2, 4, 2, 0, 0, 0, 0, + : -1, 0, 4, 0, 2, 0, 0, 0, 0, + : 2, 0, 2, -2, 1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=81,90 ) / + : 1, 0, 0, -1, -1, 0, 0, 0, 0, + : 2, 0, 2, 2, 2, 0, 0, 0, 0, + : 1, 0, 0, 2, 1, 0, 0, 0, 0, + : 3, 0, 0, 0, 0, 0, 0, 0, 0, + : 0, 0, 2, -2, -1, 0, 0, 0, 0, + : 3, 0, 2, -2, 2, 0, 0, 0, 0, + : 0, 0, 4, -2, 2, 0, 0, 0, 0, + : -1, 0, 0, 4, 0, 0, 0, 0, 0, + : 0, 1, 2, 0, 1, 0, 0, 0, 0, + : 0, 0, 2, -2, 3, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=91,100 ) / + : -2, 0, 0, 4, 0, 0, 0, 0, 0, + : -1, -1, 0, 2, 1, 0, 0, 0, 0, + : -2, 0, 2, 0, -1, 0, 0, 0, 0, + : 0, 0, 2, 0, -1, 0, 0, 0, 0, + : 0, -1, 2, 0, 1, 0, 0, 0, 0, + : 0, 1, 0, 0, 2, 0, 0, 0, 0, + : 0, 0, 2, -1, 2, 0, 0, 0, 0, + : 2, 1, 0, -2, 0, 0, 0, 0, 0, + : 0, 0, 2, 4, 2, 0, 0, 0, 0, + : -1, -1, 0, 2, -1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=101,110 ) / + : -1, 1, 0, 2, 0, 0, 0, 0, 0, + : 1, -1, 0, 0, 1, 0, 0, 0, 0, + : 0, -1, 2, -2, 0, 0, 0, 0, 0, + : 0, 1, 0, 0, -2, 0, 0, 0, 0, + : 1, -1, 2, 2, 2, 0, 0, 0, 0, + : 1, 0, 0, 2, -1, 0, 0, 0, 0, + : -1, 1, 2, 2, 2, 0, 0, 0, 0, + : 3, 0, 2, 0, 1, 0, 0, 0, 0, + : 0, 1, 2, 2, 2, 0, 0, 0, 0, + : 1, 0, 2, -2, 0, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=111,120 ) / + : -1, 0, -2, 4, -1, 0, 0, 0, 0, + : -1, -1, 2, 2, 1, 0, 0, 0, 0, + : 0, -1, 2, 2, 1, 0, 0, 0, 0, + : 2, -1, 2, 0, 2, 0, 0, 0, 0, + : 0, 0, 0, 2, 2, 0, 0, 0, 0, + : 1, -1, 2, 0, 1, 0, 0, 0, 0, + : -1, 1, 2, 0, 2, 0, 0, 0, 0, + : 0, 1, 0, 2, 0, 0, 0, 0, 0, + : 0, 1, 2, -2, 0, 0, 0, 0, 0, + : 0, 3, 2, -2, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=121,130 ) / + : 0, 0, 0, 1, 1, 0, 0, 0, 0, + : -1, 0, 2, 2, 0, 0, 0, 0, 0, + : 2, 1, 2, 0, 2, 0, 0, 0, 0, + : 1, 1, 0, 0, 1, 0, 0, 0, 0, + : 2, 0, 0, 2, 0, 0, 0, 0, 0, + : 1, 1, 2, 0, 1, 0, 0, 0, 0, + : -1, 0, 0, 2, 2, 0, 0, 0, 0, + : 1, 0, -2, 2, 0, 0, 0, 0, 0, + : 0, -1, 0, 2, -1, 0, 0, 0, 0, + : -1, 0, 1, 0, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=131,140 ) / + : 0, 1, 0, 1, 0, 0, 0, 0, 0, + : 1, 0, -2, 2, -2, 0, 0, 0, 0, + : 0, 0, 0, 1, -1, 0, 0, 0, 0, + : 1, -1, 0, 0, -1, 0, 0, 0, 0, + : 0, 0, 0, 4, 0, 0, 0, 0, 0, + : 1, -1, 0, 2, 0, 0, 0, 0, 0, + : 1, 0, 2, 1, 2, 0, 0, 0, 0, + : 1, 0, 2, -1, 2, 0, 0, 0, 0, + : -1, 0, 0, 2, -2, 0, 0, 0, 0, + : 0, 0, 2, 1, 1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=141,150 ) / + : -1, 0, 2, 0, -1, 0, 0, 0, 0, + : -1, 0, 2, 4, 1, 0, 0, 0, 0, + : 0, 0, 2, 2, 0, 0, 0, 0, 0, + : 1, 1, 2, -2, 1, 0, 0, 0, 0, + : 0, 0, 1, 0, 1, 0, 0, 0, 0, + : -1, 0, 2, -1, 1, 0, 0, 0, 0, + : -2, 0, 2, 2, 1, 0, 0, 0, 0, + : 2, -1, 0, 0, 0, 0, 0, 0, 0, + : 4, 0, 2, 0, 2, 0, 0, 0, 0, + : 2, 1, 2, -2, 2, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=151,160 ) / + : 0, 1, 2, 1, 2, 0, 0, 0, 0, + : 1, 0, 4, -2, 2, 0, 0, 0, 0, + : 1, 1, 0, 0, -1, 0, 0, 0, 0, + : -2, 0, 2, 4, 1, 0, 0, 0, 0, + : 2, 0, 2, 0, 0, 0, 0, 0, 0, + : -1, 0, 1, 0, 0, 0, 0, 0, 0, + : 1, 0, 0, 1, 0, 0, 0, 0, 0, + : 0, 1, 0, 2, 1, 0, 0, 0, 0, + : -1, 0, 4, 0, 1, 0, 0, 0, 0, + : -1, 0, 0, 4, 1, 0, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=161,170 ) / + : 2, 0, 2, 2, 1, 0, 0, 0, 0, + : 2, 1, 0, 0, 0, 0, 0, 0, 0, + : 0, 0, 5, -5, 5, -3, 0, 0, 0, + : 0, 0, 0, 0, 0, 0, 0, 2, 0, + : 0, 0, 1, -1, 1, 0, 0, -1, 0, + : 0, 0, -1, 1, -1, 1, 0, 0, 0, + : 0, 0, -1, 1, 0, 0, 2, 0, 0, + : 0, 0, 3, -3, 3, 0, 0, -1, 0, + : 0, 0, -8, 8, -7, 5, 0, 0, 0, + : 0, 0, -1, 1, -1, 0, 2, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=171,180 ) / + : 0, 0, -2, 2, -2, 2, 0, 0, 0, + : 0, 0, -6, 6, -6, 4, 0, 0, 0, + : 0, 0, -2, 2, -2, 0, 8, -3, 0, + : 0, 0, 6, -6, 6, 0, -8, 3, 0, + : 0, 0, 4, -4, 4, -2, 0, 0, 0, + : 0, 0, -3, 3, -3, 2, 0, 0, 0, + : 0, 0, 4, -4, 3, 0, -8, 3, 0, + : 0, 0, -4, 4, -5, 0, 8, -3, 0, + : 0, 0, 0, 0, 0, 2, 0, 0, 0, + : 0, 0, -4, 4, -4, 3, 0, 0, 0 / + DATA ( ( NA(I,J), I=1,9 ), J=181,190 ) / + : 0, 1, -1, 1, -1, 0, 0, 1, 0, + : 0, 0, 0, 0, 0, 0, 0, 1, 0, + : 0, 0, 1, -1, 1, 1, 0, 0, 0, + : 0, 0, 2, -2, 2, 0, -2, 0, 0, + : 0, -1, -7, 7, -7, 5, 0, 0, 0, + : -2, 0, 2, 0, 2, 0, 0, -2, 0, + : -2, 0, 2, 0, 1, 0, 0, -3, 0, + : 0, 0, 2, -2, 2, 0, 0, -2, 0, + : 0, 0, 1, -1, 1, 0, 0, 1, 0, + : 0, 0, 0, 0, 0, 0, 0, 0, 2 / + DATA ( ( NA(I,J), I=1,9 ), J=191,NTERMS ) / + : 0, 0, 0, 0, 0, 0, 0, 0, 1, + : 2, 0, -2, 0, -2, 0, 0, 3, 0, + : 0, 0, 1, -1, 1, 0, 0, -2, 0, + : 0, 0, -7, 7, -7, 5, 0, 0, 0 / + +* Nutation series: longitude + DATA ( ( PSI(I,J), I=1,4 ), J=1,10 ) / + : 3341.5D0, 17206241.8D0, 3.1D0, 17409.5D0, + : -1716.8D0, -1317185.3D0, 1.4D0, -156.8D0, + : 285.7D0, -227667.0D0, 0.3D0, -23.5D0, + : -68.6D0, -207448.0D0, 0.0D0, -21.4D0, + : 950.3D0, 147607.9D0, -2.3D0, -355.0D0, + : -66.7D0, -51689.1D0, 0.2D0, 122.6D0, + : -108.6D0, 71117.6D0, 0.0D0, 7.0D0, + : 35.6D0, -38740.2D0, 0.1D0, -36.2D0, + : 85.4D0, -30127.6D0, 0.0D0, -3.1D0, + : 9.0D0, 21583.0D0, 0.1D0, -50.3D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=11,20 ) / + : 22.1D0, 12822.8D0, 0.0D0, 13.3D0, + : 3.4D0, 12350.8D0, 0.0D0, 1.3D0, + : -21.1D0, 15699.4D0, 0.0D0, 1.6D0, + : 4.2D0, 6313.8D0, 0.0D0, 6.2D0, + : -22.8D0, 5796.9D0, 0.0D0, 6.1D0, + : 15.7D0, -5961.1D0, 0.0D0, -0.6D0, + : 13.1D0, -5159.1D0, 0.0D0, -4.6D0, + : 1.8D0, 4592.7D0, 0.0D0, 4.5D0, + : -17.5D0, 6336.0D0, 0.0D0, 0.7D0, + : 16.3D0, -3851.1D0, 0.0D0, -0.4D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=21,30 ) / + : -2.8D0, 4771.7D0, 0.0D0, 0.5D0, + : 13.8D0, -3099.3D0, 0.0D0, -0.3D0, + : 0.2D0, 2860.3D0, 0.0D0, 0.3D0, + : 1.4D0, 2045.3D0, 0.0D0, 2.0D0, + : -8.6D0, 2922.6D0, 0.0D0, 0.3D0, + : -7.7D0, 2587.9D0, 0.0D0, 0.2D0, + : 8.8D0, -1408.1D0, 0.0D0, 3.7D0, + : 1.4D0, 1517.5D0, 0.0D0, 1.5D0, + : -1.9D0, -1579.7D0, 0.0D0, 7.7D0, + : 1.3D0, -2178.6D0, 0.0D0, -0.2D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=31,40 ) / + : -4.8D0, 1286.8D0, 0.0D0, 1.3D0, + : 6.3D0, 1267.2D0, 0.0D0, -4.0D0, + : -1.0D0, 1669.3D0, 0.0D0, -8.3D0, + : 2.4D0, -1020.0D0, 0.0D0, -0.9D0, + : 4.5D0, -766.9D0, 0.0D0, 0.0D0, + : -1.1D0, 756.5D0, 0.0D0, -1.7D0, + : -1.4D0, -1097.3D0, 0.0D0, -0.5D0, + : 2.6D0, -663.0D0, 0.0D0, -0.6D0, + : 0.8D0, -714.1D0, 0.0D0, 1.6D0, + : 0.4D0, -629.9D0, 0.0D0, -0.6D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=41,50 ) / + : 0.3D0, 580.4D0, 0.0D0, 0.6D0, + : -1.6D0, 577.3D0, 0.0D0, 0.5D0, + : -0.9D0, 644.4D0, 0.0D0, 0.0D0, + : 2.2D0, -534.0D0, 0.0D0, -0.5D0, + : -2.5D0, 493.3D0, 0.0D0, 0.5D0, + : -0.1D0, -477.3D0, 0.0D0, -2.4D0, + : -0.9D0, 735.0D0, 0.0D0, -1.7D0, + : 0.7D0, 406.2D0, 0.0D0, 0.4D0, + : -2.8D0, 656.9D0, 0.0D0, 0.0D0, + : 0.6D0, 358.0D0, 0.0D0, 2.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=51,60 ) / + : -0.7D0, 472.5D0, 0.0D0, -1.1D0, + : -0.1D0, -300.5D0, 0.0D0, 0.0D0, + : -1.2D0, 435.1D0, 0.0D0, -1.0D0, + : 1.8D0, -289.4D0, 0.0D0, 0.0D0, + : 0.6D0, -422.6D0, 0.0D0, 0.0D0, + : 0.8D0, -287.6D0, 0.0D0, 0.6D0, + : -38.6D0, -392.3D0, 0.0D0, 0.0D0, + : 0.7D0, -281.8D0, 0.0D0, 0.6D0, + : 0.6D0, -405.7D0, 0.0D0, 0.0D0, + : -1.2D0, 229.0D0, 0.0D0, 0.2D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=61,70 ) / + : 1.1D0, -264.3D0, 0.0D0, 0.5D0, + : -0.7D0, 247.9D0, 0.0D0, -0.5D0, + : -0.2D0, 218.0D0, 0.0D0, 0.2D0, + : 0.6D0, -339.0D0, 0.0D0, 0.8D0, + : -0.7D0, 198.7D0, 0.0D0, 0.2D0, + : -1.5D0, 334.0D0, 0.0D0, 0.0D0, + : 0.1D0, 334.0D0, 0.0D0, 0.0D0, + : -0.1D0, -198.1D0, 0.0D0, 0.0D0, + : -106.6D0, 0.0D0, 0.0D0, 0.0D0, + : -0.5D0, 165.8D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=71,80 ) / + : 0.0D0, 134.8D0, 0.0D0, 0.0D0, + : 0.9D0, -151.6D0, 0.0D0, 0.0D0, + : 0.0D0, -129.7D0, 0.0D0, 0.0D0, + : 0.8D0, -132.8D0, 0.0D0, -0.1D0, + : 0.5D0, -140.7D0, 0.0D0, 0.0D0, + : -0.1D0, 138.4D0, 0.0D0, 0.0D0, + : 0.0D0, 129.0D0, 0.0D0, -0.3D0, + : 0.5D0, -121.2D0, 0.0D0, 0.0D0, + : -0.3D0, 114.5D0, 0.0D0, 0.0D0, + : -0.1D0, 101.8D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=81,90 ) / + : -3.6D0, -101.9D0, 0.0D0, 0.0D0, + : 0.8D0, -109.4D0, 0.0D0, 0.0D0, + : 0.2D0, -97.0D0, 0.0D0, 0.0D0, + : -0.7D0, 157.3D0, 0.0D0, 0.0D0, + : 0.2D0, -83.3D0, 0.0D0, 0.0D0, + : -0.3D0, 93.3D0, 0.0D0, 0.0D0, + : -0.1D0, 92.1D0, 0.0D0, 0.0D0, + : -0.5D0, 133.6D0, 0.0D0, 0.0D0, + : -0.1D0, 81.5D0, 0.0D0, 0.0D0, + : 0.0D0, 123.9D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=91,100 ) / + : -0.3D0, 128.1D0, 0.0D0, 0.0D0, + : 0.1D0, 74.1D0, 0.0D0, -0.3D0, + : -0.2D0, -70.3D0, 0.0D0, 0.0D0, + : -0.4D0, 66.6D0, 0.0D0, 0.0D0, + : 0.1D0, -66.7D0, 0.0D0, 0.0D0, + : -0.7D0, 69.3D0, 0.0D0, -0.3D0, + : 0.0D0, -70.4D0, 0.0D0, 0.0D0, + : -0.1D0, 101.5D0, 0.0D0, 0.0D0, + : 0.5D0, -69.1D0, 0.0D0, 0.0D0, + : -0.2D0, 58.5D0, 0.0D0, 0.2D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=101,110 ) / + : 0.1D0, -94.9D0, 0.0D0, 0.2D0, + : 0.0D0, 52.9D0, 0.0D0, -0.2D0, + : 0.1D0, 86.7D0, 0.0D0, -0.2D0, + : -0.1D0, -59.2D0, 0.0D0, 0.2D0, + : 0.3D0, -58.8D0, 0.0D0, 0.1D0, + : -0.3D0, 49.0D0, 0.0D0, 0.0D0, + : -0.2D0, 56.9D0, 0.0D0, -0.1D0, + : 0.3D0, -50.2D0, 0.0D0, 0.0D0, + : -0.2D0, 53.4D0, 0.0D0, -0.1D0, + : 0.1D0, -76.5D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=111,120 ) / + : -0.2D0, 45.3D0, 0.0D0, 0.0D0, + : 0.1D0, -46.8D0, 0.0D0, 0.0D0, + : 0.2D0, -44.6D0, 0.0D0, 0.0D0, + : 0.2D0, -48.7D0, 0.0D0, 0.0D0, + : 0.1D0, -46.8D0, 0.0D0, 0.0D0, + : 0.1D0, -42.0D0, 0.0D0, 0.0D0, + : 0.0D0, 46.4D0, 0.0D0, -0.1D0, + : 0.2D0, -67.3D0, 0.0D0, 0.1D0, + : 0.0D0, -65.8D0, 0.0D0, 0.2D0, + : -0.1D0, -43.9D0, 0.0D0, 0.3D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=121,130 ) / + : 0.0D0, -38.9D0, 0.0D0, 0.0D0, + : -0.3D0, 63.9D0, 0.0D0, 0.0D0, + : -0.2D0, 41.2D0, 0.0D0, 0.0D0, + : 0.0D0, -36.1D0, 0.0D0, 0.2D0, + : -0.3D0, 58.5D0, 0.0D0, 0.0D0, + : -0.1D0, 36.1D0, 0.0D0, 0.0D0, + : 0.0D0, -39.7D0, 0.0D0, 0.0D0, + : 0.1D0, -57.7D0, 0.0D0, 0.0D0, + : -0.2D0, 33.4D0, 0.0D0, 0.0D0, + : 36.4D0, 0.0D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=131,140 ) / + : -0.1D0, 55.7D0, 0.0D0, -0.1D0, + : 0.1D0, -35.4D0, 0.0D0, 0.0D0, + : 0.1D0, -31.0D0, 0.0D0, 0.0D0, + : -0.1D0, 30.1D0, 0.0D0, 0.0D0, + : -0.3D0, 49.2D0, 0.0D0, 0.0D0, + : -0.2D0, 49.1D0, 0.0D0, 0.0D0, + : -0.1D0, 33.6D0, 0.0D0, 0.0D0, + : 0.1D0, -33.5D0, 0.0D0, 0.0D0, + : 0.1D0, -31.0D0, 0.0D0, 0.0D0, + : -0.1D0, 28.0D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=141,150 ) / + : 0.1D0, -25.2D0, 0.0D0, 0.0D0, + : 0.1D0, -26.2D0, 0.0D0, 0.0D0, + : -0.2D0, 41.5D0, 0.0D0, 0.0D0, + : 0.0D0, 24.5D0, 0.0D0, 0.1D0, + : -16.2D0, 0.0D0, 0.0D0, 0.0D0, + : 0.0D0, -22.3D0, 0.0D0, 0.0D0, + : 0.0D0, 23.1D0, 0.0D0, 0.0D0, + : -0.1D0, 37.5D0, 0.0D0, 0.0D0, + : 0.2D0, -25.7D0, 0.0D0, 0.0D0, + : 0.0D0, 25.2D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=151,160 ) / + : 0.1D0, -24.5D0, 0.0D0, 0.0D0, + : -0.1D0, 24.3D0, 0.0D0, 0.0D0, + : 0.1D0, -20.7D0, 0.0D0, 0.0D0, + : 0.1D0, -20.8D0, 0.0D0, 0.0D0, + : -0.2D0, 33.4D0, 0.0D0, 0.0D0, + : 32.9D0, 0.0D0, 0.0D0, 0.0D0, + : 0.1D0, -32.6D0, 0.0D0, 0.0D0, + : 0.0D0, 19.9D0, 0.0D0, 0.0D0, + : -0.1D0, 19.6D0, 0.0D0, 0.0D0, + : 0.0D0, -18.7D0, 0.0D0, 0.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=161,170 ) / + : 0.1D0, -19.0D0, 0.0D0, 0.0D0, + : 0.1D0, -28.6D0, 0.0D0, 0.0D0, + : 4.0D0, 178.8D0,-11.8D0, 0.3D0, + : 39.8D0, -107.3D0, -5.6D0, -1.0D0, + : 9.9D0, 164.0D0, -4.1D0, 0.1D0, + : -4.8D0, -135.3D0, -3.4D0, -0.1D0, + : 50.5D0, 75.0D0, 1.4D0, -1.2D0, + : -1.1D0, -53.5D0, 1.3D0, 0.0D0, + : -45.0D0, -2.4D0, -0.4D0, 6.6D0, + : -11.5D0, -61.0D0, -0.9D0, 0.4D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=171,180 ) / + : 4.4D0, -68.4D0, -3.4D0, 0.0D0, + : 7.7D0, -47.1D0, -4.7D0, -1.0D0, + : -42.9D0, -12.6D0, -1.2D0, 4.2D0, + : -42.8D0, 12.7D0, -1.2D0, -4.2D0, + : -7.6D0, -44.1D0, 2.1D0, -0.5D0, + : -64.1D0, 1.7D0, 0.2D0, 4.5D0, + : 36.4D0, -10.4D0, 1.0D0, 3.5D0, + : 35.6D0, 10.2D0, 1.0D0, -3.5D0, + : -1.7D0, 39.5D0, 2.0D0, 0.0D0, + : 50.9D0, -8.2D0, -0.8D0, -5.0D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=181,190 ) / + : 0.0D0, 52.3D0, 1.2D0, 0.0D0, + : -42.9D0, -17.8D0, 0.4D0, 0.0D0, + : 2.6D0, 34.3D0, 0.8D0, 0.0D0, + : -0.8D0, -48.6D0, 2.4D0, -0.1D0, + : -4.9D0, 30.5D0, 3.7D0, 0.7D0, + : 0.0D0, -43.6D0, 2.1D0, 0.0D0, + : 0.0D0, -25.4D0, 1.2D0, 0.0D0, + : 2.0D0, 40.9D0, -2.0D0, 0.0D0, + : -2.1D0, 26.1D0, 0.6D0, 0.0D0, + : 22.6D0, -3.2D0, -0.5D0, -0.5D0 / + DATA ( ( PSI(I,J), I=1,4 ), J=191,NTERMS ) / + : -7.6D0, 24.9D0, -0.4D0, -0.2D0, + : -6.2D0, 34.9D0, 1.7D0, 0.3D0, + : 2.0D0, 17.4D0, -0.4D0, 0.1D0, + : -3.9D0, 20.5D0, 2.4D0, 0.6D0 / + +* Nutation series: obliquity + DATA ( ( EPS(I,J), I=1,4 ), J=1,10 ) / + : 9205365.8D0, -1506.2D0, 885.7D0, -0.2D0, + : 573095.9D0, -570.2D0, -305.0D0, -0.3D0, + : 97845.5D0, 147.8D0, -48.8D0, -0.2D0, + : -89753.6D0, 28.0D0, 46.9D0, 0.0D0, + : 7406.7D0, -327.1D0, -18.2D0, 0.8D0, + : 22442.3D0, -22.3D0, -67.6D0, 0.0D0, + : -683.6D0, 46.8D0, 0.0D0, 0.0D0, + : 20070.7D0, 36.0D0, 1.6D0, 0.0D0, + : 12893.8D0, 39.5D0, -6.2D0, 0.0D0, + : -9593.2D0, 14.4D0, 30.2D0, -0.1D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=11,20 ) / + : -6899.5D0, 4.8D0, -0.6D0, 0.0D0, + : -5332.5D0, -0.1D0, 2.7D0, 0.0D0, + : -125.2D0, 10.5D0, 0.0D0, 0.0D0, + : -3323.4D0, -0.9D0, -0.3D0, 0.0D0, + : 3142.3D0, 8.9D0, 0.3D0, 0.0D0, + : 2552.5D0, 7.3D0, -1.2D0, 0.0D0, + : 2634.4D0, 8.8D0, 0.2D0, 0.0D0, + : -2424.4D0, 1.6D0, -0.4D0, 0.0D0, + : -123.3D0, 3.9D0, 0.0D0, 0.0D0, + : 1642.4D0, 7.3D0, -0.8D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=21,30 ) / + : 47.9D0, 3.2D0, 0.0D0, 0.0D0, + : 1321.2D0, 6.2D0, -0.6D0, 0.0D0, + : -1234.1D0, -0.3D0, 0.6D0, 0.0D0, + : -1076.5D0, -0.3D0, 0.0D0, 0.0D0, + : -61.6D0, 1.8D0, 0.0D0, 0.0D0, + : -55.4D0, 1.6D0, 0.0D0, 0.0D0, + : 856.9D0, -4.9D0, -2.1D0, 0.0D0, + : -800.7D0, -0.1D0, 0.0D0, 0.0D0, + : 685.1D0, -0.6D0, -3.8D0, 0.0D0, + : -16.9D0, -1.5D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=31,40 ) / + : 695.7D0, 1.8D0, 0.0D0, 0.0D0, + : 642.2D0, -2.6D0, -1.6D0, 0.0D0, + : 13.3D0, 1.1D0, -0.1D0, 0.0D0, + : 521.9D0, 1.6D0, 0.0D0, 0.0D0, + : 325.8D0, 2.0D0, -0.1D0, 0.0D0, + : -325.1D0, -0.5D0, 0.9D0, 0.0D0, + : 10.1D0, 0.3D0, 0.0D0, 0.0D0, + : 334.5D0, 1.6D0, 0.0D0, 0.0D0, + : 307.1D0, 0.4D0, -0.9D0, 0.0D0, + : 327.2D0, 0.5D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=41,50 ) / + : -304.6D0, -0.1D0, 0.0D0, 0.0D0, + : 304.0D0, 0.6D0, 0.0D0, 0.0D0, + : -276.8D0, -0.5D0, 0.1D0, 0.0D0, + : 268.9D0, 1.3D0, 0.0D0, 0.0D0, + : 271.8D0, 1.1D0, 0.0D0, 0.0D0, + : 271.5D0, -0.4D0, -0.8D0, 0.0D0, + : -5.2D0, 0.5D0, 0.0D0, 0.0D0, + : -220.5D0, 0.1D0, 0.0D0, 0.0D0, + : -20.1D0, 0.3D0, 0.0D0, 0.0D0, + : -191.0D0, 0.1D0, 0.5D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=51,60 ) / + : -4.1D0, 0.3D0, 0.0D0, 0.0D0, + : 130.6D0, -0.1D0, 0.0D0, 0.0D0, + : 3.0D0, 0.3D0, 0.0D0, 0.0D0, + : 122.9D0, 0.8D0, 0.0D0, 0.0D0, + : 3.7D0, -0.3D0, 0.0D0, 0.0D0, + : 123.1D0, 0.4D0, -0.3D0, 0.0D0, + : -52.7D0, 15.3D0, 0.0D0, 0.0D0, + : 120.7D0, 0.3D0, -0.3D0, 0.0D0, + : 4.0D0, -0.3D0, 0.0D0, 0.0D0, + : 126.5D0, 0.5D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=61,70 ) / + : 112.7D0, 0.5D0, -0.3D0, 0.0D0, + : -106.1D0, -0.3D0, 0.3D0, 0.0D0, + : -112.9D0, -0.2D0, 0.0D0, 0.0D0, + : 3.6D0, -0.2D0, 0.0D0, 0.0D0, + : 107.4D0, 0.3D0, 0.0D0, 0.0D0, + : -10.9D0, 0.2D0, 0.0D0, 0.0D0, + : -0.9D0, 0.0D0, 0.0D0, 0.0D0, + : 85.4D0, 0.0D0, 0.0D0, 0.0D0, + : 0.0D0, -88.8D0, 0.0D0, 0.0D0, + : -71.0D0, -0.2D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=71,80 ) / + : -70.3D0, 0.0D0, 0.0D0, 0.0D0, + : 64.5D0, 0.4D0, 0.0D0, 0.0D0, + : 69.8D0, 0.0D0, 0.0D0, 0.0D0, + : 66.1D0, 0.4D0, 0.0D0, 0.0D0, + : -61.0D0, -0.2D0, 0.0D0, 0.0D0, + : -59.5D0, -0.1D0, 0.0D0, 0.0D0, + : -55.6D0, 0.0D0, 0.2D0, 0.0D0, + : 51.7D0, 0.2D0, 0.0D0, 0.0D0, + : -49.0D0, -0.1D0, 0.0D0, 0.0D0, + : -52.7D0, -0.1D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=81,90 ) / + : -49.6D0, 1.4D0, 0.0D0, 0.0D0, + : 46.3D0, 0.4D0, 0.0D0, 0.0D0, + : 49.6D0, 0.1D0, 0.0D0, 0.0D0, + : -5.1D0, 0.1D0, 0.0D0, 0.0D0, + : -44.0D0, -0.1D0, 0.0D0, 0.0D0, + : -39.9D0, -0.1D0, 0.0D0, 0.0D0, + : -39.5D0, -0.1D0, 0.0D0, 0.0D0, + : -3.9D0, 0.1D0, 0.0D0, 0.0D0, + : -42.1D0, -0.1D0, 0.0D0, 0.0D0, + : -17.2D0, 0.1D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=91,100 ) / + : -2.3D0, 0.1D0, 0.0D0, 0.0D0, + : -39.2D0, 0.0D0, 0.0D0, 0.0D0, + : -38.4D0, 0.1D0, 0.0D0, 0.0D0, + : 36.8D0, 0.2D0, 0.0D0, 0.0D0, + : 34.6D0, 0.1D0, 0.0D0, 0.0D0, + : -32.7D0, 0.3D0, 0.0D0, 0.0D0, + : 30.4D0, 0.0D0, 0.0D0, 0.0D0, + : 0.4D0, 0.1D0, 0.0D0, 0.0D0, + : 29.3D0, 0.2D0, 0.0D0, 0.0D0, + : 31.6D0, 0.1D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=101,110 ) / + : 0.8D0, -0.1D0, 0.0D0, 0.0D0, + : -27.9D0, 0.0D0, 0.0D0, 0.0D0, + : 2.9D0, 0.0D0, 0.0D0, 0.0D0, + : -25.3D0, 0.0D0, 0.0D0, 0.0D0, + : 25.0D0, 0.1D0, 0.0D0, 0.0D0, + : 27.5D0, 0.1D0, 0.0D0, 0.0D0, + : -24.4D0, -0.1D0, 0.0D0, 0.0D0, + : 24.9D0, 0.2D0, 0.0D0, 0.0D0, + : -22.8D0, -0.1D0, 0.0D0, 0.0D0, + : 0.9D0, -0.1D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=111,120 ) / + : 24.4D0, 0.1D0, 0.0D0, 0.0D0, + : 23.9D0, 0.1D0, 0.0D0, 0.0D0, + : 22.5D0, 0.1D0, 0.0D0, 0.0D0, + : 20.8D0, 0.1D0, 0.0D0, 0.0D0, + : 20.1D0, 0.0D0, 0.0D0, 0.0D0, + : 21.5D0, 0.1D0, 0.0D0, 0.0D0, + : -20.0D0, 0.0D0, 0.0D0, 0.0D0, + : 1.4D0, 0.0D0, 0.0D0, 0.0D0, + : -0.2D0, -0.1D0, 0.0D0, 0.0D0, + : 19.0D0, 0.0D0, -0.1D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=121,130 ) / + : 20.5D0, 0.0D0, 0.0D0, 0.0D0, + : -2.0D0, 0.0D0, 0.0D0, 0.0D0, + : -17.6D0, -0.1D0, 0.0D0, 0.0D0, + : 19.0D0, 0.0D0, 0.0D0, 0.0D0, + : -2.4D0, 0.0D0, 0.0D0, 0.0D0, + : -18.4D0, -0.1D0, 0.0D0, 0.0D0, + : 17.1D0, 0.0D0, 0.0D0, 0.0D0, + : 0.4D0, 0.0D0, 0.0D0, 0.0D0, + : 18.4D0, 0.1D0, 0.0D0, 0.0D0, + : 0.0D0, 17.4D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=131,140 ) / + : -0.6D0, 0.0D0, 0.0D0, 0.0D0, + : -15.4D0, 0.0D0, 0.0D0, 0.0D0, + : -16.8D0, -0.1D0, 0.0D0, 0.0D0, + : 16.3D0, 0.0D0, 0.0D0, 0.0D0, + : -2.0D0, 0.0D0, 0.0D0, 0.0D0, + : -1.5D0, 0.0D0, 0.0D0, 0.0D0, + : -14.3D0, -0.1D0, 0.0D0, 0.0D0, + : 14.4D0, 0.0D0, 0.0D0, 0.0D0, + : -13.4D0, 0.0D0, 0.0D0, 0.0D0, + : -14.3D0, -0.1D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=141,150 ) / + : -13.7D0, 0.0D0, 0.0D0, 0.0D0, + : 13.1D0, 0.1D0, 0.0D0, 0.0D0, + : -1.7D0, 0.0D0, 0.0D0, 0.0D0, + : -12.8D0, 0.0D0, 0.0D0, 0.0D0, + : 0.0D0, -14.4D0, 0.0D0, 0.0D0, + : 12.4D0, 0.0D0, 0.0D0, 0.0D0, + : -12.0D0, 0.0D0, 0.0D0, 0.0D0, + : -0.8D0, 0.0D0, 0.0D0, 0.0D0, + : 10.9D0, 0.1D0, 0.0D0, 0.0D0, + : -10.8D0, 0.0D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=151,160 ) / + : 10.5D0, 0.0D0, 0.0D0, 0.0D0, + : -10.4D0, 0.0D0, 0.0D0, 0.0D0, + : -11.2D0, 0.0D0, 0.0D0, 0.0D0, + : 10.5D0, 0.1D0, 0.0D0, 0.0D0, + : -1.4D0, 0.0D0, 0.0D0, 0.0D0, + : 0.0D0, 0.1D0, 0.0D0, 0.0D0, + : 0.7D0, 0.0D0, 0.0D0, 0.0D0, + : -10.3D0, 0.0D0, 0.0D0, 0.0D0, + : -10.0D0, 0.0D0, 0.0D0, 0.0D0, + : 9.6D0, 0.0D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=161,170 ) / + : 9.4D0, 0.1D0, 0.0D0, 0.0D0, + : 0.6D0, 0.0D0, 0.0D0, 0.0D0, + : -87.7D0, 4.4D0, -0.4D0, -6.3D0, + : 46.3D0, 22.4D0, 0.5D0, -2.4D0, + : 15.6D0, -3.4D0, 0.1D0, 0.4D0, + : 5.2D0, 5.8D0, 0.2D0, -0.1D0, + : -30.1D0, 26.9D0, 0.7D0, 0.0D0, + : 23.2D0, -0.5D0, 0.0D0, 0.6D0, + : 1.0D0, 23.2D0, 3.4D0, 0.0D0, + : -12.2D0, -4.3D0, 0.0D0, 0.0D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=171,180 ) / + : -2.1D0, -3.7D0, -0.2D0, 0.1D0, + : -18.6D0, -3.8D0, -0.4D0, 1.8D0, + : 5.5D0, -18.7D0, -1.8D0, -0.5D0, + : -5.5D0, -18.7D0, 1.8D0, -0.5D0, + : 18.4D0, -3.6D0, 0.3D0, 0.9D0, + : -0.6D0, 1.3D0, 0.0D0, 0.0D0, + : -5.6D0, -19.5D0, 1.9D0, 0.0D0, + : 5.5D0, -19.1D0, -1.9D0, 0.0D0, + : -17.3D0, -0.8D0, 0.0D0, 0.9D0, + : -3.2D0, -8.3D0, -0.8D0, 0.3D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=181,190 ) / + : -0.1D0, 0.0D0, 0.0D0, 0.0D0, + : -5.4D0, 7.8D0, -0.3D0, 0.0D0, + : -14.8D0, 1.4D0, 0.0D0, 0.3D0, + : -3.8D0, 0.4D0, 0.0D0, -0.2D0, + : 12.6D0, 3.2D0, 0.5D0, -1.5D0, + : 0.1D0, 0.0D0, 0.0D0, 0.0D0, + : -13.6D0, 2.4D0, -0.1D0, 0.0D0, + : 0.9D0, 1.2D0, 0.0D0, 0.0D0, + : -11.9D0, -0.5D0, 0.0D0, 0.3D0, + : 0.4D0, 12.0D0, 0.3D0, -0.2D0 / + DATA ( ( EPS(I,J), I=1,4 ), J=191,NTERMS ) / + : 8.3D0, 6.1D0, -0.1D0, 0.1D0, + : 0.0D0, 0.0D0, 0.0D0, 0.0D0, + : 0.4D0, -10.8D0, 0.3D0, 0.0D0, + : 9.6D0, 2.2D0, 0.3D0, -1.2D0 / + + + +* Interval between fundamental epoch J2000.0 and given epoch (JC). + T = (DATE-DJM0)/DJC + +* Mean anomaly of the Moon. + EL = 134.96340251D0*DD2R+ + : MOD(T*(1717915923.2178D0+ + : T*( 31.8792D0+ + : T*( 0.051635D0+ + : T*( - 0.00024470D0)))),TURNAS)*DAS2R + +* Mean anomaly of the Sun. + ELP = 357.52910918D0*DD2R+ + : MOD(T*( 129596581.0481D0+ + : T*( - 0.5532D0+ + : T*( 0.000136D0+ + : T*( - 0.00001149D0)))),TURNAS)*DAS2R + +* Mean argument of the latitude of the Moon. + F = 93.27209062D0*DD2R+ + : MOD(T*(1739527262.8478D0+ + : T*( - 12.7512D0+ + : T*( - 0.001037D0+ + : T*( 0.00000417D0)))),TURNAS)*DAS2R + +* Mean elongation of the Moon from the Sun. + D = 297.85019547D0*DD2R+ + : MOD(T*(1602961601.2090D0+ + : T*( - 6.3706D0+ + : T*( 0.006539D0+ + : T*( - 0.00003169D0)))),TURNAS)*DAS2R + +* Mean longitude of the ascending node of the Moon. + OM = 125.04455501D0*DD2R+ + : MOD(T*( - 6962890.5431D0+ + : T*( 7.4722D0+ + : T*( 0.007702D0+ + : T*( - 0.00005939D0)))),TURNAS)*DAS2R + +* Mean longitude of Venus. + VE = 181.97980085D0*DD2R+MOD(210664136.433548D0*T,TURNAS)*DAS2R + +* Mean longitude of Mars. + MA = 355.43299958D0*DD2R+MOD( 68905077.493988D0*T,TURNAS)*DAS2R + +* Mean longitude of Jupiter. + JU = 34.35151874D0*DD2R+MOD( 10925660.377991D0*T,TURNAS)*DAS2R + +* Mean longitude of Saturn. + SA = 50.07744430D0*DD2R+MOD( 4399609.855732D0*T,TURNAS)*DAS2R + +* Geodesic nutation (Fukushima 1991) in microarcsec. + DP = -153.1D0*SIN(ELP)-1.9D0*SIN(2D0*ELP) + DE = 0D0 + +* Shirai & Fukushima (2001) nutation series. + DO J=NTERMS,1,-1 + THETA = DBLE(NA(1,J))*EL+ + : DBLE(NA(2,J))*ELP+ + : DBLE(NA(3,J))*F+ + : DBLE(NA(4,J))*D+ + : DBLE(NA(5,J))*OM+ + : DBLE(NA(6,J))*VE+ + : DBLE(NA(7,J))*MA+ + : DBLE(NA(8,J))*JU+ + : DBLE(NA(9,J))*SA + C = COS(THETA) + S = SIN(THETA) + DP = DP+(PSI(1,J)+PSI(3,J)*T)*C+(PSI(2,J)+PSI(4,J)*T)*S + DE = DE+(EPS(1,J)+EPS(3,J)*T)*C+(EPS(2,J)+EPS(4,J)*T)*S + END DO + +* Change of units, and addition of the precession correction. + DPSI = (DP*1D-6-0.042888D0-0.29856D0*T)*DAS2R + DEPS = (DE*1D-6-0.005171D0-0.02408D0*T)*DAS2R + +* Mean obliquity of date (Simon et al. 1994). + EPS0 = (84381.412D0+ + : (-46.80927D0+ + : (-0.000152D0+ + : (0.0019989D0+ + : (-0.00000051D0+ + : (-0.000000025D0)*T)*T)*T)*T)*T)*DAS2R + + END + SUBROUTINE sla_NUT (DATE, RMATN) +*+ +* - - - - +* N U T +* - - - - +* +* Form the matrix of nutation for a given date - Shirai & Fukushima +* 2001 theory (double precision) +* +* Reference: +* Shirai, T. & Fukushima, T., Astron.J. 121, 3270-3283 (2001). +* +* Given: +* DATE d TDB (loosely ET) as Modified Julian Date +* (=JD-2400000.5) +* Returned: +* RMATN d(3,3) nutation matrix +* +* Notes: +* +* 1 The matrix is in the sense v(true) = rmatn * v(mean) . +* where v(true) is the star vector relative to the true equator and +* equinox of date and v(mean) is the star vector relative to the +* mean equator and equinox of date. +* +* 2 The matrix represents forced nutation (but not free core +* nutation) plus corrections to the IAU~1976 precession model. +* +* 3 Earth attitude predictions made by combining the present nutation +* matrix with IAU~1976 precession are accurate to 1~mas (with +* respect to the ICRS) for a few decades around 2000. +* +* 4 The distinction between the required TDB and TT is always +* negligible. Moreover, for all but the most critical applications +* UTC is adequate. +* +* Called: sla_NUTC, sla_DEULER +* +* Last revision: 1 December 2005 +* +* Copyright P.T.Wallace. All rights reserved. +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION DATE,RMATN(3,3) + + DOUBLE PRECISION DPSI,DEPS,EPS0 + + + +* Nutation components and mean obliquity + CALL sla_NUTC(DATE,DPSI,DEPS,EPS0) + +* Rotation matrix + CALL sla_DEULER('XZX',EPS0,-DPSI,-(EPS0+DEPS),RMATN) + + END + SUBROUTINE sla_PREBN (BEP0, BEP1, RMATP) +*+ +* - - - - - - +* P R E B N +* - - - - - - +* +* Generate the matrix of precession between two epochs, +* using the old, pre-IAU1976, Bessel-Newcomb model, using +* Kinoshita's formulation (double precision) +* +* Given: +* BEP0 dp beginning Besselian epoch +* BEP1 dp ending Besselian epoch +* +* Returned: +* RMATP dp(3,3) precession matrix +* +* The matrix is in the sense V(BEP1) = RMATP * V(BEP0) +* +* Reference: +* Kinoshita, H. (1975) 'Formulas for precession', SAO Special +* Report No. 364, Smithsonian Institution Astrophysical +* Observatory, Cambridge, Massachusetts. +* +* Called: sla_DEULER +* +* P.T.Wallace Starlink 23 August 1996 +* +* Copyright (C) 1996 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION BEP0,BEP1,RMATP(3,3) + +* Arc seconds to radians + DOUBLE PRECISION AS2R + PARAMETER (AS2R=0.484813681109535994D-5) + + DOUBLE PRECISION BIGT,T,TAS2R,W,ZETA,Z,THETA + + + +* Interval between basic epoch B1850.0 and beginning epoch in TC + BIGT = (BEP0-1850D0)/100D0 + +* Interval over which precession required, in tropical centuries + T = (BEP1-BEP0)/100D0 + +* Euler angles + TAS2R = T*AS2R + W = 2303.5548D0+(1.39720D0+0.000059D0*BIGT)*BIGT + + ZETA = (W+(0.30242D0-0.000269D0*BIGT+0.017996D0*T)*T)*TAS2R + Z = (W+(1.09478D0+0.000387D0*BIGT+0.018324D0*T)*T)*TAS2R + THETA = (2005.1125D0+(-0.85294D0-0.000365D0*BIGT)*BIGT+ + : (-0.42647D0-0.000365D0*BIGT-0.041802D0*T)*T)*TAS2R + +* Rotation matrix + CALL sla_DEULER('ZYZ',-ZETA,THETA,-Z,RMATP) + + END + SUBROUTINE sla_PRECES (SYSTEM, EP0, EP1, RA, DC) +*+ +* - - - - - - - +* P R E C E S +* - - - - - - - +* +* Precession - either FK4 (Bessel-Newcomb, pre IAU 1976) or +* FK5 (Fricke, post IAU 1976) as required. +* +* Given: +* SYSTEM char precession to be applied: 'FK4' or 'FK5' +* EP0,EP1 dp starting and ending epoch +* RA,DC dp RA,Dec, mean equator & equinox of epoch EP0 +* +* Returned: +* RA,DC dp RA,Dec, mean equator & equinox of epoch EP1 +* +* Called: sla_DRANRM, sla_PREBN, sla_PREC, sla_DCS2C, +* sla_DMXV, sla_DCC2S +* +* Notes: +* +* 1) Lowercase characters in SYSTEM are acceptable. +* +* 2) The epochs are Besselian if SYSTEM='FK4' and Julian if 'FK5'. +* For example, to precess coordinates in the old system from +* equinox 1900.0 to 1950.0 the call would be: +* CALL sla_PRECES ('FK4', 1900D0, 1950D0, RA, DC) +* +* 3) This routine will NOT correctly convert between the old and +* the new systems - for example conversion from B1950 to J2000. +* For these purposes see sla_FK425, sla_FK524, sla_FK45Z and +* sla_FK54Z. +* +* 4) If an invalid SYSTEM is supplied, values of -99D0,-99D0 will +* be returned for both RA and DC. +* +* P.T.Wallace Starlink 20 April 1990 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + CHARACTER SYSTEM*(*) + DOUBLE PRECISION EP0,EP1,RA,DC + + DOUBLE PRECISION PM(3,3),V1(3),V2(3) + CHARACTER SYSUC*3 + + DOUBLE PRECISION sla_DRANRM + + + + +* Convert to uppercase and validate SYSTEM + SYSUC=SYSTEM + IF (SYSUC(1:1).EQ.'f') SYSUC(1:1)='F' + IF (SYSUC(2:2).EQ.'k') SYSUC(2:2)='K' + IF (SYSUC.NE.'FK4'.AND.SYSUC.NE.'FK5') THEN + RA=-99D0 + DC=-99D0 + ELSE + +* Generate appropriate precession matrix + IF (SYSUC.EQ.'FK4') THEN + CALL sla_PREBN(EP0,EP1,PM) + ELSE + CALL sla_PREC(EP0,EP1,PM) + END IF + +* Convert RA,Dec to x,y,z + CALL sla_DCS2C(RA,DC,V1) + +* Precess + CALL sla_DMXV(PM,V1,V2) + +* Back to RA,Dec + CALL sla_DCC2S(V2,RA,DC) + RA=sla_DRANRM(RA) + + END IF + + END + SUBROUTINE sla_PREC (EP0, EP1, RMATP) +*+ +* - - - - - +* P R E C +* - - - - - +* +* Form the matrix of precession between two epochs (IAU 1976, FK5) +* (double precision) +* +* Given: +* EP0 dp beginning epoch +* EP1 dp ending epoch +* +* Returned: +* RMATP dp(3,3) precession matrix +* +* Notes: +* +* 1) The epochs are TDB (loosely ET) Julian epochs. +* +* 2) The matrix is in the sense V(EP1) = RMATP * V(EP0) +* +* 3) Though the matrix method itself is rigorous, the precession +* angles are expressed through canonical polynomials which are +* valid only for a limited time span. There are also known +* errors in the IAU precession rate. The absolute accuracy +* of the present formulation is better than 0.1 arcsec from +* 1960AD to 2040AD, better than 1 arcsec from 1640AD to 2360AD, +* and remains below 3 arcsec for the whole of the period +* 500BC to 3000AD. The errors exceed 10 arcsec outside the +* range 1200BC to 3900AD, exceed 100 arcsec outside 4200BC to +* 5600AD and exceed 1000 arcsec outside 6800BC to 8200AD. +* The SLALIB routine sla_PRECL implements a more elaborate +* model which is suitable for problems spanning several +* thousand years. +* +* References: +* Lieske,J.H., 1979. Astron.Astrophys.,73,282. +* equations (6) & (7), p283. +* Kaplan,G.H., 1981. USNO circular no. 163, pA2. +* +* Called: sla_DEULER +* +* P.T.Wallace Starlink 23 August 1996 +* +* Copyright (C) 1996 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION EP0,EP1,RMATP(3,3) + +* Arc seconds to radians + DOUBLE PRECISION AS2R + PARAMETER (AS2R=0.484813681109535994D-5) + + DOUBLE PRECISION T0,T,TAS2R,W,ZETA,Z,THETA + + + +* Interval between basic epoch J2000.0 and beginning epoch (JC) + T0 = (EP0-2000D0)/100D0 + +* Interval over which precession required (JC) + T = (EP1-EP0)/100D0 + +* Euler angles + TAS2R = T*AS2R + W = 2306.2181D0+(1.39656D0-0.000139D0*T0)*T0 + + ZETA = (W+((0.30188D0-0.000344D0*T0)+0.017998D0*T)*T)*TAS2R + Z = (W+((1.09468D0+0.000066D0*T0)+0.018203D0*T)*T)*TAS2R + THETA = ((2004.3109D0+(-0.85330D0-0.000217D0*T0)*T0) + : +((-0.42665D0-0.000217D0*T0)-0.041833D0*T)*T)*TAS2R + +* Rotation matrix + CALL sla_DEULER('ZYZ',-ZETA,THETA,-Z,RMATP) + + END + SUBROUTINE sla_PVOBS (P, H, STL, PV) +*+ +* - - - - - - +* P V O B S +* - - - - - - +* +* Position and velocity of an observing station (double precision) +* +* Given: +* P dp latitude (geodetic, radians) +* H dp height above reference spheroid (geodetic, metres) +* STL dp local apparent sidereal time (radians) +* +* Returned: +* PV dp(6) position/velocity 6-vector (AU, AU/s, true equator +* and equinox of date) +* +* Called: sla_GEOC +* +* IAU 1976 constants are used. +* +* P.T.Wallace Starlink 14 November 1994 +* +* Copyright (C) 1995 Rutherford Appleton Laboratory +* +* License: +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program (see SLA_CONDITIONS); if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +*- + + IMPLICIT NONE + + DOUBLE PRECISION P,H,STL,PV(6) + + DOUBLE PRECISION R,Z,S,C,V + +* Mean sidereal rate (at J2000) in radians per (UT1) second + DOUBLE PRECISION SR + PARAMETER (SR=7.292115855306589D-5) + + + +* Geodetic to geocentric conversion + CALL sla_GEOC(P,H,R,Z) + +* Functions of ST + S=SIN(STL) + C=COS(STL) + +* Speed + V=SR*R + +* Position + PV(1)=R*C + PV(2)=R*S + PV(3)=Z + +* Velocity + PV(4)=-V*S + PV(5)=V*C + PV(6)=0D0 + + END diff --git a/lib/slope.f90 b/lib/slope.f90 index 5581ade1..0b2b98da 100644 --- a/lib/slope.f90 +++ b/lib/slope.f90 @@ -1,40 +1,40 @@ -subroutine slope(y,npts,xpk) - -! Remove best-fit slope from data in y(i). When fitting the straight line, -! ignore the peak around xpk +/- 2. - - real y(npts) - real x(100) - - do i=1,npts - x(i)=i - enddo - - sumw=0. - sumx=0. - sumy=0. - sumx2=0. - sumxy=0. - sumy2=0. - - do i=1,npts - if(abs(i-xpk).gt.2.0) then - sumw=sumw + 1.0 - sumx=sumx + x(i) - sumy=sumy + y(i) - sumx2=sumx2 + x(i)**2 - sumxy=sumxy + x(i)*y(i) - sumy2=sumy2 + y(i)**2 - endif - enddo - - delta=sumw*sumx2 - sumx**2 - a=(sumx2*sumy - sumx*sumxy) / delta - b=(sumw*sumxy - sumx*sumy) / delta - - do i=1,npts - y(i)=y(i)-(a + b*x(i)) - enddo - - return -end subroutine slope +subroutine slope(y,npts,xpk) + +! Remove best-fit slope from data in y(i). When fitting the straight line, +! ignore the peak around xpk +/- 2 bins + + real y(npts) + + sumw=0. + sumx=0. + sumy=0. + sumx2=0. + sumxy=0. + sumy2=0. + do i=1,npts + if(abs(i-xpk).gt.2.0) then + sumw=sumw + 1.0 + x=i + sumx=sumx + x + sumy=sumy + y(i) + sumx2=sumx2 + x*x + sumxy=sumxy + x*y(i) + sumy2=sumy2 + y(i)**2 + endif + enddo + + delta=sumw*sumx2 - sumx**2 + a=(sumx2*sumy - sumx*sumxy) / delta + b=(sumw*sumxy - sumx*sumy) / delta + + sq=0. + do i=1,npts + y(i)=y(i)-(a + b*i) + if(abs(i-xpk).gt.2.0) sq=sq + y(i)**2 + enddo + rms=sqrt(sq/(sumw-2.0)) + y=y/rms + + return +end subroutine slope + diff --git a/lib/smo.f90 b/lib/smo.f90 index 94a33784..c42de7c6 100644 --- a/lib/smo.f90 +++ b/lib/smo.f90 @@ -11,13 +11,9 @@ subroutine smo(x,npts,y,nadd) enddo y(i)=sum enddo - y(:nh)=0. - y(npts-nh+1:)=0. - - fac=1.0/nadd - do i=1,npts - x(i)=fac*y(i) - enddo + x=y + x(:nh)=0. + x(npts-nh+1:)=0. return end subroutine smo diff --git a/lib/smolorentz.f90 b/lib/smolorentz.f90 new file mode 100644 index 00000000..70132f59 --- /dev/null +++ b/lib/smolorentz.f90 @@ -0,0 +1,42 @@ +!program smolorentz +subroutine smolorentz(s1,nz,w,s2) + +! parameter (nz=512) + real s1(nz),s2(nz) + real y(-50:50) +! character*8 arg + +! s1=0. +! s1(256)=1. + +! call getarg(1,arg) +! read(arg,*) w + + do i=-50,50 + x=i + z=x/(0.5*w) + y(i)=0. + if(abs(z).lt.3.0) then + d=1.0 + z*z + y(i)=(1.0/d - 0.1)*10.0/9.0 + endif + enddo + + jz=nint(1.5*w) + if(jz.gt.50) jz=50 + do i=1,nz + s=0. + sy=0. + do j=-jz,jz + k=i+j + if(k.ge.1 .and. k.le.nz) then + s=s + s1(k)*y(j) + sy=sy+y(j) + endif + enddo + s2(i)=s/sy +! write(52,3002) i-256,s1(i),s2(i) +!3002 format(i5,2f10.4) + enddo + +end subroutine smolorentz diff --git a/lib/softsym.f90 b/lib/softsym.f90 index 5bb6265f..6475b0e4 100644 --- a/lib/softsym.f90 +++ b/lib/softsym.f90 @@ -3,9 +3,13 @@ subroutine softsym(id2,npts8,nsps8,newdat,fpk,syncpk,snrdb,xdt, & ! Compute the soft symbols - complex c2(0:1440-1) - complex c3(0:1440-1) - complex c5(0:1440-1) + use timer_module, only: timer + + parameter (NZ2=1512,NZ3=1360) + logical, intent(inout) :: newdat + complex c2(0:NZ2-1) + complex c3(0:NZ3-1) + complex c5(0:NZ3-1) real a(3) integer*1 i1SoftSymbolsScrambled(207) integer*1 i1SoftSymbols(207) @@ -16,18 +20,20 @@ subroutine softsym(id2,npts8,nsps8,newdat,fpk,syncpk,snrdb,xdt, & ! Mix, low-pass filter, and downsample to 16 samples per symbol call timer('downsam9',0) - call downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2,nz2) + call downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2) call timer('downsam9',1) - call peakdt9(c2,nz2,nsps8,nspsd,c3,nz3,xdt) !Find DT + call peakdt9(c2,nsps8,nspsd,c3,xdt) !Find DT fsample=1500.0/ndown a=0. call timer('afc9 ',0) - call afc9(c3,nz3,fsample,a,syncpk) !Find deltaF, fDot, fDDot + call afc9(c3,nz3,fsample,a,syncpk) !Find deltaF, fDot, extra DT call timer('afc9 ',1) freq=fpk - a(1) drift=-2.0*a(2) +! write(*,3301) fpk,freq,a +!3301 format(2f9.3,3f10.4) a3=a(3) a(3)=0. diff --git a/lib/softsym9f.f90 b/lib/softsym9f.f90 new file mode 100644 index 00000000..bb505f0e --- /dev/null +++ b/lib/softsym9f.f90 @@ -0,0 +1,55 @@ +subroutine softsym9f(ss2,ss3,i1SoftSymbols) + +! Compute soft symbols and S/N + + real ss2(0:8,85) + real ss3(0:7,69) + integer*1 i1SoftSymbolsScrambled(207) + integer*1 i1SoftSymbols(207) + + ss=0. + sig=0. + if(ss2(0,1).eq.-999.0) return !Silence compiler warning + do j=1,69 + smax=0. + do i=0,7 + smax=max(smax,ss3(i,j)) + ss=ss+ss3(i,j) + enddo + sig=sig+smax + ss=ss-smax + enddo + ave=ss/(69*7) !Baseline +! call pctile(ss2,9*85,35,xmed) !### better? ### + ss3=ss3/ave + sig=sig/69. !Signal + + m0=3 + k=0 + scale=10.0 + do j=1,69 + do m=m0-1,0,-1 !Get bit-wise soft symbols + if(m.eq.2) then + r1=max(ss3(4,j),ss3(5,j),ss3(6,j),ss3(7,j)) + r0=max(ss3(0,j),ss3(1,j),ss3(2,j),ss3(3,j)) + else if(m.eq.1) then + r1=max(ss3(2,j),ss3(3,j),ss3(4,j),ss3(5,j)) + r0=max(ss3(0,j),ss3(1,j),ss3(6,j),ss3(7,j)) + else + r1=max(ss3(1,j),ss3(2,j),ss3(4,j),ss3(7,j)) + r0=max(ss3(0,j),ss3(3,j),ss3(5,j),ss3(6,j)) + endif + + k=k+1 + i4=nint(scale*(r1-r0)) + if(i4.lt.-127) i4=-127 + if(i4.gt.127) i4=127 + i1SoftSymbolsScrambled(k)=i4 + enddo + enddo + + + call interleave9(i1SoftSymbolsScrambled,-1,i1SoftSymbols) + + return +end subroutine softsym9f diff --git a/lib/softsym9w.f90 b/lib/softsym9w.f90 new file mode 100644 index 00000000..4465e0ea --- /dev/null +++ b/lib/softsym9w.f90 @@ -0,0 +1,126 @@ +subroutine softsym9w(id2,npts,xdt0,f0,width,nsubmode,xdt1,i1softsymbols) + + parameter (NFFT=6912,NH=NFFT/2,NQ=NH/2) + real s(NQ) + real s2(0:8,85) + real s3(0:7,69) + real x(NFFT) + complex cx(0:NH) + integer*2 id2(60*12000) + integer*1 i1SoftSymbolsScrambled(207) + integer*1 i1softsymbols(207) + include 'jt9sync.f90' + equivalence (x,cx) + + if(npts.eq.-99) stop !Silence compiler warning + df=12000.0/NFFT + i0a=max(1.0,(xdt0-1.0)*12000.0) + i0b=(xdt0+1.0)*12000.0 + k1=max(1,nint((f0-0.5*width)/df)) + k2=min(NQ,nint((f0+0.5*width)/df)) + smax=0. + i0pk=1 + i1softsymbols=0 + + do i0=i0a,i0b,432 + s=0. + ssum=0. + do j=1,16 + ia=i0 + (ii(j)-1)*nfft + ib=ia+NFFT-1 + x=1.e-6*id2(ia:ib) + call four2a(x,nfft,1,-1,0) !r2c FFT + do k=1,NQ + s(k)=s(k) + real(cx(k))**2 + aimag(cx(k))**2 + enddo + enddo + ssum=ssum + sum(s(k1:k2)) + if(ssum.gt.smax) then + smax=ssum + i0pk=i0 + else + if(ssum.lt.0.7*smax) exit + endif + end do + xdt1=(i0pk-1)/12000.0 + + if(i0pk.le.0) go to 999 + + m=0 + do j=1,85 + ia=i0pk + (j-1)*nfft + ib=ia+NFFT-1 + x=1.e-6*id2(ia:ib) + call four2a(x,nfft,1,-1,0) !r2c FFT + do k=1,NQ + s(k)=real(cx(k))**2 + aimag(cx(k))**2 + enddo + + dtone=df*(2**nsubmode) + do i=0,8 + f=f0 + i*dtone + k1=max(1,nint((f-0.5*width)/df)) + k2=min(NQ,nint((f+0.5*width)/df)) + s2(i,j)=sum(s(k1:k2)) !Symbol spectra, including sync + enddo + + if(isync(j).eq.0) then + m=m+1 + s3(0:7,m)=s2(1:8,j) !Symbol spectra, data only + endif + +! write(19,3101) j,s2(0:8,j) +!3101 format(i2,9f8.2) + enddo + + ss=0. + sig=0. + do j=1,69 + smax=0. + do i=0,7 + smax=max(smax,s3(i,j)) + ss=ss+s3(i,j) + enddo + sig=sig+smax + ss=ss-smax + enddo + ave=ss/(69*7) !Baseline + call pctile(s2,9*85,35,xmed) + s3=s3/ave + sig=sig/69. !Signal + t=max(1.0,sig - 1.0) + snrdb=db(t) + + m0=3 + k=0 + do j=1,69 + smax=0. + do i=0,7 + if(s3(i,j).gt.smax) smax=s3(i,j) + enddo + + do m=m0-1,0,-1 !Get bit-wise soft symbols + if(m.eq.2) then + r1=max(s3(4,j),s3(5,j),s3(6,j),s3(7,j)) + r0=max(s3(0,j),s3(1,j),s3(2,j),s3(3,j)) + else if(m.eq.1) then + r1=max(s3(2,j),s3(3,j),s3(4,j),s3(5,j)) + r0=max(s3(0,j),s3(1,j),s3(6,j),s3(7,j)) + else + r1=max(s3(1,j),s3(2,j),s3(4,j),s3(7,j)) + r0=max(s3(0,j),s3(3,j),s3(5,j),s3(6,j)) + endif + + k=k+1 + i4=nint(10.0*(r1-r0)) + if(i4.lt.-127) i4=-127 + if(i4.gt.127) i4=127 + i1SoftSymbolsScrambled(k)=i4 + enddo + enddo + +! Remove interleaving + call interleave9(i1SoftSymbolsScrambled,-1,i1SoftSymbols) + +999 return +end subroutine softsym9w diff --git a/lib/sort.f90 b/lib/sort.f90 index 993dafd7..0a90a6b3 100644 --- a/lib/sort.f90 +++ b/lib/sort.f90 @@ -9,6 +9,7 @@ subroutine sort(n,arr) jstack=0 l=1 ir=n + n0=n 1 if(ir-l.lt.m) then do j=l+1,ir @@ -55,6 +56,14 @@ subroutine sort(n,arr) j=ir a=arr(l) 3 i=i+1 + if(i.gt.n0) then + do jj=1,n0 + write(99,3001) jj,arr(jj),i,n,ir +3001 format(i10,e12.3,3i10) + enddo + close(99) + stop 'Bounds error in sort.f90' + endif if(arr(i).lt.a) goto 3 4 j=j-1 diff --git a/lib/spec64.f90 b/lib/spec64.f90 new file mode 100644 index 00000000..a0c0a04c --- /dev/null +++ b/lib/spec64.f90 @@ -0,0 +1,42 @@ +subroutine spec64(c0,npts2,mode64,jpk,s3,LL,NN) + + parameter (NSPS=3456) !Samples per symbol at 6000 Hz + complex c0(0:360000) !Complex spectrum of dd() + complex cs(0:NSPS-1) !Complex symbol spectrum + real s3(LL,NN) !Synchronized symbol spectra + real xbase0(LL),xbase(LL) + + nfft=nsps + fac=1.0/nfft + do j=1,NN + jj=j+7 !Skip first Costas array + if(j.ge.33) jj=j+14 !Skip middle Costas array + ja=jpk + (jj-1)*nfft + jb=ja+nfft-1 + cs(0:nfft-1)=fac*c0(ja:jb) + call four2a(cs,nfft,1,-1,1) + do ii=1,LL + i=ii-65 + if(i.lt.0) i=i+nfft + s3(ii,j)=real(cs(i))**2 + aimag(cs(i))**2 + enddo + enddo + + df=6000.0/nfft + do i=1,LL + call pctile(s3(i,1:NN),NN,45,xbase0(i)) !Get baseline for passband shape + enddo + + nh=25 + xbase(1:nh-1)=sum(xbase0(1:nh-1))/(nh-1.0) + xbase(LL-nh+1:LL)=sum(xbase0(LL-nh+1:LL))/(nh-1.0) + do i=nh,LL-nh + xbase(i)=sum(xbase0(i-nh+1:i+nh))/(2*nh+1) !Smoothed passband shape + enddo + + do i=1,LL + s3(i,1:NN)=s3(i,1:NN)/(xbase(i)+0.001) !Apply frequency equalization + enddo + + return +end subroutine spec64 diff --git a/lib/spec9f.f90 b/lib/spec9f.f90 new file mode 100644 index 00000000..96dac29c --- /dev/null +++ b/lib/spec9f.f90 @@ -0,0 +1,30 @@ +subroutine spec9f(id2,npts,nsps,s1,jz,nq) + +! Compute symbol spectra at quarter-symbol steps. + + integer*2 id2(0:npts) + real s1(nq,jz) + real x(960) + complex c(0:480) + equivalence (x,c) + + nfft=2*nsps !FFTs at twice the symbol length + nh=nfft/2 + do j=1,jz + ia=(j-1)*nsps/4 + ib=ia+nsps-1 + if(ib.gt.npts) exit + x(1:nh)=id2(ia:ib) + x(nh+1:)=0. + call four2a(x,nfft,1,-1,0) !r2c + k=mod(j-1,340)+1 + do i=1,NQ + s1(i,j)=1.e-10*(real(c(i))**2 + aimag(c(i))**2) + enddo + enddo + +!### Reference spectrum should be applied here (or possibly earlier?) ### +!### Normalize so that rms (or level?) is 1.0 ? ### + + return +end subroutine spec9f diff --git a/lib/stats.f90 b/lib/stats.f90 new file mode 100644 index 00000000..a864f6a1 --- /dev/null +++ b/lib/stats.f90 @@ -0,0 +1,66 @@ +program stats + + character*8 arg + character*40 infile + character decoded*22 + + nargs=iargc() + if(nargs.lt.1) then + print*,'Usage: stats file1 ...' + go to 999 + endif + + ttol=0.1 + nftol=1 + write(*,1000) +1000 format(' SNR Files Sync BM FT Hint Total False BadSync'/ & + 56('-')) + + do ifile=1,nargs + call getarg(ifile,infile) + open(10,file=infile,status='old') + i1=index(infile,".")+1 + i2=40 + if(index(infile,"_").gt.1) i2=index(infile,"_") - 1 + snrgen=0. + read(infile(i1:i2),*,err=1) snrgen +1 snrgen=-snrgen + nsynced=0 + nbm=0 + nftok=0 + nhint=0 + ngood=0 + nbad=0 + nbadsync=0 + + do iline=1,999999 + read(10,1010,end=100) nutc,sync,nsnr,dt,nfreq,ncandidates,nhard, & + ntotal,rtt,ntry,nft,nqual,decoded +1010 format(i4.4,f5.1,i4,f5.1,i5,i6,i3,i4,f6.3,i8,i2,i3,1x,a22) + + ndfreq=abs(nfreq-1500) + if(sync.ge.1.0 .and. abs(dt).le.ttol .and. ndfreq.le.nftol) then + nsynced=nsynced+1 + else + nbadsync=nbadsync+1 + endif + + if(decoded.eq.' ') cycle + if(nft.eq.2 .or. (ntotal.le.81 .and. rtt.le.0.87)) then !nag=0 + if(decoded(1:11).eq.'K1ABC W9XYZ') then + ngood=ngood+1 + if(nft.eq.1 .and. ncandidates.eq.0) nbm=nbm+1 + if(nft.eq.1) nftok=nftok+1 + if(nft.ge.2) nhint=nhint+1 + else + nbad=nbad+1 + endif + endif + enddo + +100 write(*,1100) snrgen,nutc,nsynced,nbm,nftok,nhint,ngood,nbad, & + nbadsync +1100 format(f5.1,8i6) + enddo + +999 end program stats diff --git a/lib/stdmsg.f90 b/lib/stdmsg.f90 index 7670ff0f..599287bb 100644 --- a/lib/stdmsg.f90 +++ b/lib/stdmsg.f90 @@ -1,11 +1,21 @@ -logical*1 function stdmsg(msg0) +function stdmsg(msg0,bcontest,mygrid) - character*22 msg0,msg + ! Is msg0 a standard "JT-style" message? + + use iso_c_binding, only: c_bool + use packjt + character*22 msg0,msg1,msg + character*6 mygrid integer dat(12) + logical(c_bool), value :: bcontest + logical(c_bool) :: stdmsg - call packmsg(msg0,dat,itype) - call unpackmsg(dat,msg) - stdmsg=(msg.eq.msg0) .and. (itype.ge.0) + msg1=msg0 + i0=index(msg1,' OOO ') + if(i0.gt.10) msg1=msg0(1:i0) + call packmsg(msg0,dat,itype,logical(bcontest)) + call unpackmsg(dat,msg,logical(bcontest),mygrid) + stdmsg=(msg.eq.msg1) .and. (itype.ge.0) .and. itype.ne.6 return end function stdmsg diff --git a/lib/subtract65.f90 b/lib/subtract65.f90 new file mode 100644 index 00000000..88b35506 --- /dev/null +++ b/lib/subtract65.f90 @@ -0,0 +1,112 @@ +subroutine subtract65(dd,npts,f0,dt) + +! Subtract a jt65 signal +! +! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t)) +! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) ) +! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ] +! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt} + + use packjt + use timer_module, only: timer + + integer correct(63) + parameter (NMAX=60*12000) !Samples per 60 s + parameter (NFILT=1600) + real*4 dd(NMAX), window(-NFILT/2:NFILT/2) + complex cref,camp,cfilt,cw + integer nprc(126) + real*8 dphi,phi + logical first + data nprc/ & + 1,0,0,1,1,0,0,0,1,1,1,1,1,1,0,1,0,1,0,0, & + 0,1,0,1,1,0,0,1,0,0,0,1,1,1,0,0,1,1,1,1, & + 0,1,1,0,1,1,1,1,0,0,0,1,1,0,1,0,1,0,1,1, & + 0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,0,0,0,0,1, & + 1,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,1,1,0,1, & + 0,1,0,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,1, & + 1,1,1,1,1,1/ + data first/.true./ + common/chansyms65/correct + common/heap1/cref(NMAX),camp(NMAX),cfilt(NMAX),cw(NMAX) + save first + + pi=4.0*atan(1.0) + +! Symbol duration is 4096/11025 s. +! Sample rate is 12000/s, so 12000*(4096/11025)=4458.23 samples/symbol. +! For now, call it 4458 samples/symbol. Over the message duration, we'll be off +! by about (4458.23-4458)*126=28.98 samples; 29 samples, or 0.7% of 1 symbol. +! Could eliminate accumulated error by injecting one extra sample every +! 5 or so symbols... Maybe try this later. + + nstart=dt*12000+1; + nsym=126 + ns=4458 + nref=nsym*ns + nend=nstart+nref-1 + phi=0.0 + iref=1 + ind=1 + isym=1 + call timer('subtr_1 ',0) + do k=1,nsym + if( nprc(k) .eq. 1 ) then + omega=2*pi*f0 + else + omega=2*pi*(f0+2.6917*(correct(isym)+2)) + isym=isym+1 + endif + dphi=omega/12000.0 + do i=1,ns + cref(ind)=cexp(cmplx(0.0,phi)) + phi=modulo(phi+dphi,2*pi) + id=nstart-1+ind + if(id.ge.1) camp(ind)=dd(id)*conjg(cref(ind)) + ind=ind+1 + enddo + enddo + call timer('subtr_1 ',1) + + call timer('subtr_2 ',0) +! Smoothing filter: do the convolution by means of FFTs. Ignore end-around +! cyclic effects for now. + + nfft=564480 + + if(first) then +! Create and normalize the filter + sum=0.0 + do j=-NFILT/2,NFILT/2 + window(j)=cos(pi*j/NFILT)**2 + sum=sum+window(j) + enddo + cw=0. + do i=-NFILT/2,NFILT/2 + j=i+1 + if(j.lt.1) j=j+nfft + cw(j)=window(i)/sum + enddo + call four2a(cw,nfft,1,-1,1) + first=.false. + endif + + nz=561708 + cfilt(1:nz)=camp(1:nz) + cfilt(nz+1:nfft)=0. + call four2a(cfilt,nfft,1,-1,1) + fac=1.0/float(nfft) + cfilt(1:nfft)=fac*cfilt(1:nfft)*cw(1:nfft) + call four2a(cfilt,nfft,1,1,1) + call timer('subtr_2 ',1) + +! Subtract the reconstructed signal + call timer('subtr_3 ',0) + do i=1,nref + j=nstart+i-1 + if(j.ge.1 .and. j.le.npts) dd(j)=dd(j)-2*REAL(cfilt(i)*cref(i)) + enddo + call timer('subtr_3 ',1) + + return +end subroutine subtract65 diff --git a/lib/symspec.f90 b/lib/symspec.f90 index 8a9c1d7a..8135a812 100644 --- a/lib/symspec.f90 +++ b/lib/symspec.f90 @@ -1,4 +1,5 @@ -subroutine symspec(k,ntrperiod,nsps,ingain,nflatten,pxdb,s,df3,ihsym,npts8) +subroutine symspec(shared_data,k,ntrperiod,nsps,ingain,nminw,pxdb,s, & + df3,ihsym,npts8,pxdbmax) ! Input: ! k pointer to the most recent new data @@ -9,27 +10,29 @@ subroutine symspec(k,ntrperiod,nsps,ingain,nflatten,pxdb,s,df3,ihsym,npts8) ! nbslider NB setting, 0-100 ! Output: -! pxdb power (0-60 dB) +! pxdb raw power (0-90 dB) ! s() current spectrum for waterfall display -! ihsym index number of this half-symbol (1-184) +! ihsym index number of this half-symbol (1-184) for 60 s modes ! jt9com ! ss() JT9 symbol spectra at half-symbol steps ! savg() average spectra for waterfall display - include 'constants.f90' + use, intrinsic :: iso_c_binding, only: c_int, c_short, c_float, c_char + include 'jt9com.f90' + + type(dec_data) :: shared_data real*4 w3(MAXFFT3) real*4 s(NSMAX) real*4 ssum(NSMAX) real*4 xc(0:MAXFFT3-1) real*4 tmp(NSMAX) complex cx(0:MAXFFT3/2) - integer*2 id2 - common/jt9com/ss(184,NSMAX),savg(NSMAX),id2(NMAX),nutc,ndiskdat, & - ntr,mousefqso,newdat,npts8a,nfa,nfsplit,nfb,ntol,kin,nzhsym, & - nsave,nagain,ndepth,ntxmode,nmode,junk(5) - common/jt9w/syellow(NSMAX) - data rms/999.0/,k0/99999999/,nfft3z/0/ + integer nch(7) + + common/spectra/syellow(NSMAX),ref(0:3456),filter(0:3456) + data k0/99999999/,nfft3z/0/ + data nch/1,2,4,9,18,36,72/ equivalence (xc,cx) save @@ -57,19 +60,20 @@ subroutine symspec(k,ntrperiod,nsps,ingain,nflatten,pxdb,s,df3,ihsym,npts8) ja=0 ssum=0. ihsym=0 - if(ndiskdat.eq.0) id2(k+1:)=0 !Needed to prevent "ghosts". Not sure why. + if(.not. shared_data%params%ndiskdat) shared_data%id2(k+1:)=0 !Needed to prevent "ghosts". Not sure why. endif gain=10.0**(0.1*ingain) sq=0. + pxmax=0.; do i=k0+1,k - x1=id2(i) + x1=shared_data%id2(i) + if (abs(x1).gt.pxmax) pxmax = abs(x1); sq=sq + x1*x1 enddo - sq=sq * gain - rms=sqrt(sq/(k-k0)) - pxdb=0. - if(rms.gt.0.0) pxdb=20.0*log10(rms) - if(pxdb.gt.60.0) pxdb=60.0 + pxdb = 0. + if(sq.gt.0.0) pxdb=10*log10(sq/(k-k0)) + pxdbmax=0. + if(pxmax.gt.0) pxdbmax = 20*log10(pxmax) k0=k ja=ja+jstep !Index of first sample @@ -78,37 +82,35 @@ subroutine symspec(k,ntrperiod,nsps,ingain,nflatten,pxdb,s,df3,ihsym,npts8) do i=0,nfft3-1 !Copy data into cx j=ja+i-(nfft3-1) xc(i)=0. - if(j.ge.1) xc(i)=fac0*id2(j) + if(j.ge.1 .and.j.le.NMAX) xc(i)=fac0*shared_data%id2(j) enddo - - if(ihsym.lt.184) ihsym=ihsym+1 + ihsym=ihsym+1 xc(0:nfft3-1)=w3(1:nfft3)*xc(0:nfft3-1) !Apply window w3 call four2a(xc,nfft3,1,-1,0) !Real-to-complex FFT - n=min(184,ihsym) df3=12000.0/nfft3 !JT9-1: 0.732 Hz = 0.42 * tone spacing -! i0=nint(1000.0/df3) - i0=0 iz=min(NSMAX,nint(5000.0/df3)) fac=(1.0/nfft3)**2 do i=1,iz - j=i0+i-1 + j=i-1 if(j.lt.0) j=j+nfft3 sx=fac*(real(cx(j))**2 + aimag(cx(j))**2) - ss(n,i)=sx + if(ihsym.le.184) shared_data%ss(ihsym,i)=sx ssum(i)=ssum(i) + sx s(i)=1000.0*gain*sx enddo - savg=ssum/ihsym + shared_data%savg=ssum/ihsym - if(mod(n,10).eq.0) then - mode4=36 + if(mod(ihsym,10).eq.0) then + mode4=nch(nminw+1) nsmo=min(10*mode4,150) nsmo=4*nsmo - call flat1(savg,iz,nsmo,syellow) - if(mode4.ge.9) call smo(syellow,iz,tmp,mode4) + call flat1(shared_data%savg,iz,nsmo,syellow) + if(mode4.ge.2) call smo(syellow,iz,tmp,mode4) + if(mode4.ge.2) call smo(syellow,iz,tmp,mode4) + syellow(1:250)=0. ia=500./df3 ib=2700.0/df3 smin=minval(syellow(ia:ib)) diff --git a/lib/sync24.f90 b/lib/sync24.f90 deleted file mode 100644 index cf6bf5af..00000000 --- a/lib/sync24.f90 +++ /dev/null @@ -1,179 +0,0 @@ -subroutine sync24(dat,jz,DFTolerance,NFreeze,MouseDF,mode,mode4, & - dtx,dfx,snrx,snrsync,ccfblue,ccfred1,flip,width) - -! Synchronizes JT4 data, finding the best-fit DT and DF. - - parameter (NFFTMAX=2520) !Max length of FFTs - parameter (NHMAX=NFFTMAX/2) !Max length of power spectra - parameter (NSMAX=525) !Max number of half-symbol steps - integer DFTolerance !Range of DF search - real dat(jz) - real psavg(NHMAX) !Average spectrum of whole record - real s2(NHMAX,NSMAX) !2d spectrum, stepped by half-symbols - real ccfblue(-5:540) !CCF with pseudorandom sequence - real ccfred(-450:450) !Peak of ccfblue, as function of freq - real ccfred1(-224:224) !Peak of ccfblue, as function of freq - real tmp(1260) - save - -! Do FFTs of twice symbol length, stepped by half symbols. Note that -! we have already downsampled the data by factor of 2. - - nsym=207 - nfft=2520 - nh=nfft/2 - nq=nfft/4 - nsteps=jz/nq - 1 - df=0.5*11025.0/nfft - psavg(1:nh)=0. - - do j=1,nsteps !Compute spectrum for each step, get average - k=(j-1)*nq + 1 - call ps24(dat(k),nfft,s2(1,j)) - psavg(1:nh)=psavg(1:nh) + s2(1:nh,j) - enddo - - call flat1(psavg,s2,nh,nsteps,NHMAX,NSMAX) !Flatten spectra - -! Set freq and lag ranges - famin=200. - fbmax=2700. - fa=famin - fb=fbmax - if(NFreeze.eq.1) then - fa=max(famin,1270.46+MouseDF-DFTolerance) - fb=min(fbmax,1270.46+MouseDF+DFTolerance) - else - fa=max(famin,1270.46+MouseDF-600) - fb=min(fbmax,1270.46+MouseDF+600) - endif - ia=fa/df - ib=fb/df - if(mode.eq.7) then - ia=ia - 3*mode4 - ib=ib - 3*mode4 - endif - i0=nint(1270.46/df) - lag1=-5 - lag2=59 - syncbest=-1.e30 - syncbest2=-1.e30 - ccfred=0. - - do i=ia,ib !Find best frequency channel for CCF - - call xcor24(s2,i,nsteps,nsym,lag1,lag2,mode4,ccfblue,ccf0,lagpk0,flip) - j=i-i0 - if(mode.eq.7) j=j + 3*mode4 - if(j.ge.-372 .and. j.le.372) ccfred(j)=ccf0 - -! Find rms of the CCF, without main peak - call slope(ccfblue(lag1),lag2-lag1+1,lagpk0-lag1+1.0) - sync=abs(ccfblue(lagpk0)) - ppmax=psavg(i)-1.0 - -! Find best sync value - if(sync.gt.syncbest2) then - ipk2=i - lagpk2=lagpk0 - syncbest2=sync - endif - -! We are most interested if snrx will be more than -30 dB. - if(ppmax.gt.0.2938) then !Corresponds to snrx.gt.-30.0 - if(sync.gt.syncbest) then - ipk=i - lagpk=lagpk0 - syncbest=sync - endif - endif - enddo - -! If we found nothing with snrx > -30 dB, take the best sync that *was* found. - if(syncbest.lt.-10.) then - ipk=ipk2 - lagpk=lagpk2 - syncbest=syncbest2 - endif - - dfx=(ipk-i0)*df - if(mode.eq.7) dfx=dfx + 3*mode4*df - -! Peak up in time, at best whole-channel frequency - call xcor24(s2,ipk,nsteps,nsym,lag1,lag2,mode4,ccfblue,ccfmax,lagpk,flip) - xlag=lagpk - if(lagpk.gt.lag1 .and. lagpk.lt.lag2) then - call peakup(ccfblue(lagpk-1),ccfmax,ccfblue(lagpk+1),dx2) - xlag=lagpk+dx2 - endif - -! Find rms of the CCF, without the main peak - call slope(ccfblue(lag1),lag2-lag1+1,xlag-lag1+1.0) - sq=0. - nsq=0 - do lag=lag1,lag2 - if(abs(lag-xlag).gt.2.0) then - sq=sq+ccfblue(lag)**2 - nsq=nsq+1 - endif - enddo - rms=sqrt(sq/nsq) - snrsync=abs(ccfblue(lagpk))/rms - 1.1 !Empirical - - dt=2.0/11025.0 - istart=xlag*nq - dtx=istart*dt - snrx=-99.0 - ppmax=psavg(ipk)-1.0 - - if(ppmax.gt.0.0001) then - snrx=db(ppmax*df/2500.0) + 7.5 !Empirical - if(mode.eq.7) snrx=snrx + 3.0 !Empirical - endif - if(snrx.lt.-33.0) snrx=-33.0 - -! Compute width of sync tone to outermost -3 dB points - i1=max(-450,ia-i0) - i2=min(450,ib-i0) - call pctile(ccfred(i1),i2-i1+1,45,base) - - jpk=ipk-i0 - if(abs(jpk).gt.450) then - print*,'sync24 a:',jpk,ipk,i0 - snrsync=0. - go to 999 - else - stest=base + 0.5*(ccfred(jpk)-base) ! -3 dB - endif - do i=-10,0 - if(jpk+i.ge.-371) then - if(ccfred(jpk+i).gt.stest) go to 30 - endif - enddo - i=0 -30 continue - if(abs(jpk+i-1).gt.450 .or. abs(jpk+i).gt.450) then - print*,'sync24 b:',jpk,i - else - x1=i-0.5 - endif - - do i=10,0,-1 - if(jpk+i.le.371) then - if(ccfred(jpk+i).gt.stest) go to 32 - endif - enddo - i=0 -32 x2=i+0.5 - width=x2-x1 - if(width.gt.1.2) width=sqrt(width**2 - 1.44) - width=df*width - width=max(0.0,min(99.0,width)) - - do i=-224,224 - ccfred1(i)=ccfred(i) - enddo - -999 return -end subroutine sync24 - diff --git a/lib/sync4.f90 b/lib/sync4.f90 new file mode 100644 index 00000000..c7f33b47 --- /dev/null +++ b/lib/sync4.f90 @@ -0,0 +1,179 @@ +subroutine sync4(dat,jz,ntol,NFreeze,MouseDF,mode,mode4,minwidth, & + dtx,dfx,snrx,snrsync,ccfblue,ccfred1,flip,width,ps0) + +! Synchronizes JT4 data, finding the best-fit DT and DF. + + parameter (NFFTMAX=2520) !Max length of FFTs + parameter (NHMAX=NFFTMAX/2) !Max length of power spectra + parameter (NSMAX=525) !Max number of half-symbol steps + integer ntol !Range of DF search + real dat(jz) + real psavg(NHMAX) !Average spectrum of whole record + real ps0(450) !Avg spectrum for plotting + real s2(NHMAX,NSMAX) !2d spectrum, stepped by half-symbols + real ccfblue(-5:540) !CCF with pseudorandom sequence + real ccfred(-450:450) !Peak of ccfblue, as function of freq + real red(-450:450) !Peak of ccfblue, as function of freq + real ccfred1(-224:224) !Peak of ccfblue, as function of freq + real tmp(1260) + integer ipk1(1) + integer nch(7) + logical savered + equivalence (ipk1,ipk1a) + data nch/1,2,4,9,18,36,72/ + save + +! write(*,3001) 'A',ntol,nfreeze,mousedf,mode,mode4,minwidth +!3001 format(a1,6i6) + +! Do FFTs of twice symbol length, stepped by half symbols. Note that +! we have already downsampled the data by factor of 2. + nsym=207 + nfft=2520 + nh=nfft/2 + nq=nfft/4 + nsteps=jz/nq - 1 + df=0.5*11025.0/nfft + psavg(1:nh)=0. + if(mode.eq.-999) width=0. !Silence compiler warning + + do j=1,nsteps !Compute spectrum for each step, get average + k=(j-1)*nq + 1 + call ps4(dat(k),nfft,s2(1,j)) + psavg(1:nh)=psavg(1:nh) + s2(1:nh,j) + enddo + + nsmo=min(10*mode4,150) + call flat1b(psavg,nsmo,s2,nh,nsteps,NHMAX,NSMAX) !Flatten spectra + + if(mode4.ge.9) call smo(psavg,nh,tmp,mode4/4) + + i0=132 + do i=1,450 + ps0(i)=5.0*(psavg(i0+2*i) + psavg(i0+2*i+1) - 2.0) + enddo + +! Set freq and lag ranges + famin=200.0 + 3*mode4*df + fbmax=2700.0 - 3*mode4*df + fa=famin + fb=fbmax + if(NFreeze.eq.1) then + fa=max(famin,1270.46+MouseDF-ntol) + fb=min(fbmax,1270.46+MouseDF+ntol) + else + fa=max(famin,1270.46+MouseDF-600) + fb=min(fbmax,1270.46+MouseDF+600) + endif + ia=fa/df - 3*mode4 !Index of lowest tone, bottom of range + ib=fb/df - 3*mode4 !Index of lowest tone, top of range + i0=nint(1270.46/df) + irange=450 + if(ia-i0.lt.-irange) ia=i0-irange + if(ib-i0.gt.irange) ib=i0+irange + lag1=-5 + lag2=59 + syncbest=-1.e30 + ccfred=0. + jmax=-1000 + jmin=1000 + + do ich=minwidth,7 !Find best width + kz=nch(ich)/2 + savered=.false. + do i=ia+kz,ib-kz !Find best frequency channel for CCF + call xcor4(s2,i,nsteps,nsym,lag1,lag2,ich,mode4,ccfblue,ccf0, & + lagpk0,flip) + j=i-i0 + 3*mode4 + if(j.ge.-372 .and. j.le.372) then + ccfred(j)=ccf0 + jmax=max(j,jmax) + jmin=min(j,jmin) + endif + +! Find rms of the CCF, without main peak + call slope(ccfblue(lag1),lag2-lag1+1,lagpk0-lag1+1.0) + sync=abs(ccfblue(lagpk0)) + +! Find best sync value + if(sync.gt.syncbest) then + ipk=i + lagpk=lagpk0 + ichpk=ich + syncbest=sync + savered=.true. + endif + enddo + if(savered) red=ccfred + enddo + + ccfred=red +! width=df*nch(ichpk) + dfx=(ipk-i0 + 3*mode4)*df + +! Peak up in time, at best whole-channel frequency + call xcor4(s2,ipk,nsteps,nsym,lag1,lag2,ichpk,mode4,ccfblue,ccfmax, & + lagpk,flip) + xlag=lagpk + if(lagpk.gt.lag1 .and. lagpk.lt.lag2) then + call peakup(ccfblue(lagpk-1),ccfmax,ccfblue(lagpk+1),dx2) + xlag=lagpk+dx2 + endif + +! Find rms of the CCF, without the main peak + call slope(ccfblue(lag1),lag2-lag1+1,xlag-lag1+1.0) + sq=0. + nsq=0 + do lag=lag1,lag2 + if(abs(lag-xlag).gt.2.0) then + sq=sq+ccfblue(lag)**2 + nsq=nsq+1 + endif + enddo + rms=sqrt(sq/nsq) + snrsync=max(0.0,db(abs(ccfblue(lagpk)/rms - 1.0)) - 4.5) + snrx=-26. + if(mode4.eq.2) snrx=-25. + if(mode4.eq.4) snrx=-24. + if(mode4.eq.9) snrx=-23. + if(mode4.eq.18) snrx=-22. + if(mode4.eq.36) snrx=-21. + if(mode4.eq.72) snrx=-20. + snrx=snrx + snrsync + + dt=2.0/11025.0 + istart=xlag*nq + dtx=istart*dt + ccfred1=0. + jmin=max(jmin,-224) + jmax=min(jmax,224) + do i=jmin,jmax + ccfred1(i)=ccfred(i) + enddo + + ipk1=maxloc(ccfred1) - 225 + ns=0 + s=0. + iw=min(mode4,(ib-ia)/4) + do i=jmin,jmax + if(abs(i-ipk1a).gt.iw) then + s=s+ccfred1(i) + ns=ns+1 + endif + enddo + base=s/ns + ccfred1=ccfred1-base + ccf10=0.5*maxval(ccfred1) + do i=ipk1a,jmin,-1 + if(ccfred1(i).le.ccf10) exit + enddo + i1=i + do i=ipk1a,jmax + if(ccfred1(i).le.ccf10) exit + enddo + width=(i-i1)*df + + return +end subroutine sync4 + +include 'flat1b.f90' diff --git a/lib/sync64.f90 b/lib/sync64.f90 new file mode 100644 index 00000000..d927af9c --- /dev/null +++ b/lib/sync64.f90 @@ -0,0 +1,165 @@ +subroutine sync64(c0,nf1,nf2,nfqso,ntol,mode64,emedelay,dtx,f0,jpk,sync, & + sync2,width) + + use timer_module, only: timer + + parameter (NMAX=60*12000) !Max size of raw data at 12000 Hz + parameter (NSPS=3456) !Samples per symbol at 6000 Hz + parameter (NSPC=7*NSPS) !Samples per Costas array + real s1(0:NSPC-1) !Power spectrum of Costas 1 + real s2(0:NSPC-1) !Power spectrum of Costas 2 + real s3(0:NSPC-1) !Power spectrum of Costas 3 + real s0(0:NSPC-1) !Sum of s1+s2+s3 + real s0a(0:NSPC-1) !Best synchromized spectrum (saved) + real s0b(0:NSPC-1) !tmp + real a(5) + integer icos7(0:6) !Costas 7x7 tones + integer ipk0(1) + complex cc(0:NSPC-1) !Costas waveform + complex c0(0:720000) !Complex spectrum of dd() + complex c1(0:NSPC-1) !Complex spectrum of Costas 1 + complex c2(0:NSPC-1) !Complex spectrum of Costas 2 + complex c3(0:NSPC-1) !Complex spectrum of Costas 3 + data icos7/2,5,6,0,4,1,3/ !Costas 7x7 tone pattern + data mode64z/-1/ + save + + if(mode64.ne.mode64z) then + twopi=8.0*atan(1.0) + dfgen=mode64*12000.0/6912.0 + k=-1 + phi=0. + do j=0,6 !Compute complex Costas waveform + dphi=twopi*10.0*icos7(j)*dfgen/6000.0 + do i=1,NSPS + phi=phi + dphi + if(phi.gt.twopi) phi=phi-twopi + k=k+1 + cc(k)=cmplx(cos(phi),sin(phi)) + enddo + enddo + mode64z=mode64 + endif + + nfft3=NSPC + nh3=nfft3/2 + df3=6000.0/nfft3 + + fa=max(nf1,nfqso-ntol) + fb=min(nf2,nfqso+ntol) + iaa=max(0,nint(fa/df3)) + ibb=min(NSPC-1,nint(fb/df3)) + + maxtol=max(ntol,500) + fa=max(nf1,nfqso-maxtol) + fb=min(nf2,nfqso+maxtol) + ia=max(0,nint(fa/df3)) + ib=min(NSPC-1,nint(fb/df3)) + id=0.1*(ib-ia) + iz=ib-ia+1 + sync=-1.e30 + smaxall=0. + jpk=0 + ja=0 + jb=(5.0+emedelay)*6000 + jstep=100 + ipk=0 + kpk=0 + nadd=10*mode64 + if(mod(nadd,2).eq.0) nadd=nadd+1 !Make nadd odd + nskip=max(49,nadd) + + do j1=ja,jb,jstep + call timer('sync64_1',0) + j2=j1 + 39*NSPS + j3=j1 + 77*NSPS + c1=1.e-4*c0(j1:j1+NSPC-1) * conjg(cc) + c2=1.e-4*c0(j2:j2+NSPC-1) * conjg(cc) + c3=1.e-4*c0(j3:j3+NSPC-1) * conjg(cc) + call four2a(c1,nfft3,1,-1,1) + call four2a(c2,nfft3,1,-1,1) + call four2a(c3,nfft3,1,-1,1) + s1=0. + s2=0. + s3=0. + s0b=0. + do i=ia,ib + freq=i*df3 + s1(i)=real(c1(i))**2 + aimag(c1(i))**2 + s2(i)=real(c2(i))**2 + aimag(c2(i))**2 + s3(i)=real(c3(i))**2 + aimag(c3(i))**2 + enddo + call timer('sync64_1',1) + + call timer('sync64_2',0) + s0(ia:ib)=s1(ia:ib) + s2(ia:ib) + s3(ia:ib) + s0(:ia-1)=0. + s0(ib+1:)=0. + if(nadd.ge.3) then + do ii=1,3 + s0b(ia:ib)=s0(ia:ib) + call smo(s0b(ia:ib),iz,s0(ia:ib),nadd) + enddo + endif + call averms(s0(ia+id:ib-id),iz-2*id,nskip,ave,rms) + s=(maxval(s0(iaa:ibb))-ave)/rms + ipk0=maxloc(s0(iaa:ibb)) + ip=ipk0(1) + iaa - 1 + if(s.gt.sync) then + jpk=j1 + s0a=(s0-ave)/rms + sync=s + dtx=jpk/6000.0 - 1.0 + ipk=ip + f0=ip*df3 + endif + call timer('sync64_2',1) + enddo + + s0a=s0a+2.0 +! write(17) ia,ib,s0a(ia:ib) !Save data for red curve +! close(17) + + nskip=50 + call lorentzian(s0a(ia+nskip:ib-nskip),iz-2*nskip,a) + f0a=(a(3)+ia+49)*df3 + w1=df3*a(4) + w2=2*nadd*df3 + width=w1 + if(w1.gt.1.2*w2) width=sqrt(w1**2 - w2**2) + + sq=0. + do i=1,20 + j=ia+nskip+1 + k=ib-nskip-21+i + sq=sq + (s0a(j)-a(1))**2 + (s0a(k)-a(1))**2 + enddo + rms2=sqrt(sq/40.0) + sync2=10.0*log10(a(2)/rms2) + + slimit=6.0 + rewind 17 + write(17,1110) 0.0,0.0 + rewind 17 +! rewind 76 + do i=2,iz-2*nskip-1,3 + x=i + z=(x-a(3))/(0.5*a(4)) + yfit=a(1) + if(abs(z).lt.3.0) then + d=1.0 + z*z + yfit=a(1) + a(2)*(1.0/d - 0.1) + endif + j=i+ia+49 + freq=j*df3 + ss=(s0a(j-1)+s0a(j)+s0a(j+1))/3.0 + if(ss.gt.slimit) write(17,1110) freq,ss +1110 format(3f10.3) +! write(76,1110) freq,ss,yfit + enddo + flush(17) + close(17) +! flush(76) + + return +end subroutine sync64 diff --git a/lib/sync65.f90 b/lib/sync65.f90 new file mode 100644 index 00000000..794d5593 --- /dev/null +++ b/lib/sync65.f90 @@ -0,0 +1,92 @@ +subroutine sync65(ss,nfa,nfb,naggressive,ntol,nhsym,ca,ncand,nrobust, & + bVHF) + + parameter (NSZ=3413,NFFT=8192,MAXCAND=300) + real ss(322,NSZ) + real ccfblue(-11:540) !CCF with pseudorandom sequence + real ccfred(NSZ) !Peak of ccfblue, as function of freq + logical bVHF + + type candidate + real freq + real dt + real sync + real flip + end type candidate + type(candidate) ca(MAXCAND) + + common/steve/thresh0 + + if(ntol.eq.-99) stop !Silence compiler warning + call setup65 + df=12000.0/NFFT !df = 12000.0/8192 = 1.465 Hz + ia=max(2,nint(nfa/df)) + ib=min(NSZ-1,nint(nfb/df)) + lag1=-11 + lag2=59 + nsym=126 + ncand=0 + fdot=0. + ccfred=0. + ccfblue=0. + ccfmax=0. + ipk=0 + + do i=ia,ib + call xcor(ss,i,nhsym,nsym,lag1,lag2,ccfblue,ccf0,lagpk0,flip,fdot,nrobust) +! Remove best-fit slope from ccfblue and normalize so baseline rms=1.0 + if(.not.bVHF) call slope(ccfblue(lag1),lag2-lag1+1, & + lagpk0-lag1+1.0) + ccfred(i)=ccfblue(lagpk0) + if(ccfred(i).gt.ccfmax) then + ccfmax=ccfred(i) + ipk=i + endif + enddo + call pctile(ccfred(ia:ib),ib-ia+1,35,xmed) + ccfred(ia:ib)=ccfred(ia:ib)-xmed + ccfred(ia-1)=ccfred(ia) + ccfred(ib+1)=ccfred(ib) + + do i=ia,ib + freq=i*df + itry=0 +! if(naggressive.gt.0 .and. ntol.lt.1000 .and. ccfmax.ge.thresh0) then + if(naggressive.gt.0 .and. ccfmax.ge.thresh0) then + if(i.ne.ipk) cycle + itry=1 + ncand=ncand+1 + else + if(ccfred(i).ge.thresh0 .and. ccfred(i).gt.ccfred(i-1) .and. & + ccfred(i).gt.ccfred(i+1)) then + itry=1 + ncand=ncand+1 + endif + endif + if(itry.ne.0) then + call xcor(ss,i,nhsym,nsym,lag1,lag2,ccfblue,ccf0,lagpk,flip,fdot, & + nrobust) + if(.not.bVHF) call slope(ccfblue(lag1),lag2-lag1+1, & + lagpk-lag1+1.0) + xlag=lagpk + if(lagpk.gt.lag1 .and. lagpk.lt.lag2) then + call peakup(ccfblue(lagpk-1),ccfmax,ccfblue(lagpk+1),dx2) + xlag=lagpk+dx2 + endif + dtx=xlag*2048.0/11025.0 + ccfblue(lag1)=0. + ccfblue(lag2)=0. + ca(ncand)%freq=freq + ca(ncand)%dt=dtx + ca(ncand)%flip=flip + if(bVHF) then + ca(ncand)%sync=db(ccfred(i)) - 16.0 + else + ca(ncand)%sync=ccfred(i) + endif + endif + if(ncand.eq.MAXCAND) exit + enddo + + return +end subroutine sync65 diff --git a/lib/sync9.f90 b/lib/sync9.f90 index a757d8c7..635c1b56 100644 --- a/lib/sync9.f90 +++ b/lib/sync9.f90 @@ -9,6 +9,8 @@ subroutine sync9(ss,nzhsym,lag1,lag2,ia,ib,ccfred,red2,ipkbest) real smo(-5:25) real sq(NSMAX) real red2(NSMAX) + character*27 cr + data cr/'(C) 2016, Joe Taylor - K1JT'/ include 'jt9sync.f90' ipk=0 diff --git a/lib/sync9f.f90 b/lib/sync9f.f90 new file mode 100644 index 00000000..8aca06bb --- /dev/null +++ b/lib/sync9f.f90 @@ -0,0 +1,55 @@ +subroutine sync9f(s2,nq,nfa,nfb,ss2,ss3,lagpk,ipk,ccfbest) + +! Look for JT9 sync pattern in the folded symbol spectra, s2. +! Frequency search extends from nfa to nfb. Synchronized symbol +! spectra are put into ss2() and ss3(). + + integer ii4(16) + real s2(240,340) + real ss2(0:8,85) + real ss3(0:7,69) + include 'jt9sync.f90' + + ii4=4*ii-3 + ccf=0. + ccfbest=0. + nfft=4*nq + df=12000.0/nfft + ia=nfa/df + ib=nfb/df + 0.9999 + + do i=ia,ib + do lag=0,339 + t=0. + do n=1,16 + j=ii4(n)+lag + if(j.gt.340) j=j-340 + t=t + s2(i,j) + enddo + if(t.gt.ccfbest) then + lagpk=lag + ipk=i + ccfbest=t + endif + enddo + enddo + + do i=0,8 + j4=lagpk-4 + i2=2*i + ipk + if(i2.lt.1) i2=1 + m=0 + do j=1,85 + j4=j4+4 + if(j4.gt.340) j4=j4-340 + if(j4.lt.1) j4=j4+340 + ss2(i,j)=s2(i2,j4) + if(i.ge.1 .and. isync(j).eq.0) then + m=m+1 + ss3(i-1,m)=ss2(i,j) + endif + enddo + enddo + + return +end subroutine sync9f diff --git a/lib/sync9w.f90 b/lib/sync9w.f90 new file mode 100644 index 00000000..f69720d7 --- /dev/null +++ b/lib/sync9w.f90 @@ -0,0 +1,81 @@ +subroutine sync9w(ss,nzhsym,lag1,lag2,ia,ib,ccfred,ccfblue,ipkbest,lagpk,nadd) + + include 'constants.f90' + real ss(184,NSMAX) + real ss1(184),ss1save(184) + real ccfred(NSMAX) + real ccfblue(-9:18) + real sa(NSMAX),sb(NSMAX) + include 'jt9sync.f90' + +! Smooth the symbol spectra (by an amount consistent with measured width??) + do j=1,nzhsym + sa=ss(j,1:NSMAX) + call smo(sa,NSMAX,sb,nadd) + call smo(sb,NSMAX,sa,nadd) + ss(j,1:NSMAX)=sa + enddo + + ipk=0 + ipkbest=0 + sbest=0. + ccfred=0. + df=12000.0/16384.0 + + do i=ia,ib !Loop over specified freq range + ss1=ss(1:184,i) !Symbol amplitudes at this freq + call pctile(ss1,nzhsym,50,xmed) !Median level at this freq + ss1=ss1/xmed - 1.0 + + smax=0. !Find DT in specified range + do lag=lag1,lag2 + sum1=0. + nsum=nzhsym + do j=1,16 !Sum over 16 sync symbols + k=ii2(j) + lag + if(k.ge.1 .and. k.le.nzhsym) then + sum1=sum1 + ss1(k) + nsum=nsum-1 + endif + enddo + if(sum1.gt.smax) then + smax=sum1 + ipk=i + endif + enddo + + ccfred(i)=smax !Best at this freq, over all lags + if(smax.gt.sbest) then + sbest=smax + ipkbest=ipk + ss1save=ss1 + endif + enddo + + call pctile(ccfred(ia),ib-ia+1,50,xmed) + if(xmed.le.0.0) xmed=1.0 + ccfred=ccfred/xmed + + ss1=ss1save + smax=0. !Find DT in specified range + do lag=lag1,lag2 + sum1=0. + nsum=nzhsym + do j=1,16 !Sum over 16 sync symbols + k=ii2(j) + lag + if(k.ge.1 .and. k.le.nzhsym) then + sum1=sum1 + ss1(k) + nsum=nsum-1 + endif + enddo + ccfblue(lag)=sum1 + if(sum1.gt.smax) then + smax=sum1 + lagpk=lag + endif + enddo + if(lagpk.eq.-9) lagpk=-8 !Protect the ends of ccfblue() + if(lagpk.eq.18) lagpk=17 + + return +end subroutine sync9w diff --git a/lib/synciscat.f90 b/lib/synciscat.f90 new file mode 100644 index 00000000..5ce27acf --- /dev/null +++ b/lib/synciscat.f90 @@ -0,0 +1,185 @@ +subroutine synciscat(cdat,npts,nh,npct,s0,jsym,df,ntol,NFreeze, & + MouseDF,mousebutton,mode4,nafc,psavg,xsync,sig,ndf0,msglen, & + ipk,jpk,idf,df1) + +! Synchronize an ISCAT signal +! cdat() is the downsampled analytic signal. +! Sample rate = fsample = BW = 11025 * (9/32) = 3100.78125 Hz +! npts, nsps, etc., are all reduced by 9/32 + + parameter (NMAX=30*3101) + parameter (NSZ=4*1400) + complex cdat(NMAX) + complex c(288) + real s0(288,NSZ) + real fs0(288,96) !108 = 96 + 3*4 + real savg(288) + real sref(288) + real psavg(72) !Average spectrum of whole file + integer icos(4) + data icos/0,1,3,2/ + data nsync/4/,nlen/2/,ndat/18/ + +! Silence compiler warnings: + sigbest=-20.0 + ndf0best=0 + msglenbest=0 + ipkbest=0 + jpkbest=0 + ipk2=0 + idfbest=mousebutton + + fsample=3100.78125 !New sample rate + nsps=144/mode4 + nsym=npts/nsps - 1 + nblk=nsync+nlen+ndat + nfft=2*nsps !FFTs at twice the symbol length, + + kstep=nsps/4 ! stepped by 1/4 symbol + df=fsample/nfft + fac=1.0/1000.0 !Somewhat arbitrary + savg=0. + s0=0. + + ia=1-kstep + do j=1,4*nsym !Compute symbol spectra + ia=ia+kstep + ib=ia+nsps-1 + if(ib.gt.npts) exit + c(1:nsps)=fac*cdat(ia:ib) + c(nsps+1:nfft)=0. + call four2a(c,nfft,1,-1,1) + do i=1,nfft + s0(i,j)=real(c(i))**2 + aimag(c(i))**2 + savg(i)=savg(i) + s0(i,j) !Accumulate avg spectrum + enddo + i0=40 + enddo + + jsym=4*nsym + savg=savg/jsym + + do i=1,71 !Compute spectrum in dB, for plot + if(mode4.eq.1) then + psavg(i)=2*db(savg(4*i)+savg(4*i-1)+savg(4*i-2)+savg(4*i-3)) + 1.0 + else + psavg(i)=2*db(savg(2*i)+savg(2*i-1)) + 7.0 + endif + enddo + + do i=nh+1,nfft-nh + call pctile(savg(i-nh),2*nh+1,npct,sref(i)) + enddo + sref(1:nh)=sref(nh+11) + sref(nfft-nh+1:nfft)=sref(nfft-nh) + + do i=1,nfft !Normalize the symbol spectra + fac=1.0/sref(i) + if(i.lt.11) fac=1.0/savg(11) + do j=1,jsym + s0(i,j)=fac*s0(i,j) + enddo + enddo + + nfold=jsym/96 + jb=96*nfold + + ttot=npts/fsample !Length of record (s) + df1=df/ttot !Step size for f1=fdot + idf1=-25.0/df1 + idf2=5.0/df1 + if(nafc.eq.0) then + idf1=0 + idf2=0 + else if(mod(-idf1,2).eq.1) then + idf1=idf1-1 + endif + + xsyncbest=0. + do idf=idf1,idf2 !Loop over fdot + fs0=0. + do j=1,jb !Fold s0 into fs0, modulo 4*nblk + k=mod(j-1,4*nblk)+1 + ii=nint(idf*float(j-jb/2)/float(jb)) + ia=max(1-ii,1) + ib=min(nfft-ii,nfft) + do i=ia,ib + fs0(i,k)=fs0(i,k) + s0(i+ii,j) + enddo + enddo + ref=nfold*4 + + i0=27 + if(mode4.eq.1) i0=95 + ia=i0-nint(ntol/df) + ib=i0+nint(ntol/df) + if(ia.lt.1) ia=1 + if(ib.gt.nfft-3) ib=nfft-3 + + smax=0. + ipk=1 + jpk=1 + do j=0,4*nblk-1 !Find sync pattern: lags 0-95 + do i=ia,ib !Search specified freq range + ss=0. + do n=1,4 !Sum over 4 sync tones + k=j+4*n-3 + if(k.gt.96) k=k-96 + ss=ss + fs0(i+2*icos(n),k) + enddo + if(ss.gt.smax) then + smax=ss + ipk=i !Frequency offset, DF + jpk=j+1 !Time offset, DT + endif + enddo + enddo + + xsync=smax/ref - 1.0 + if(nfold.lt.26) xsync=xsync * sqrt(nfold/26.0) + xsync=xsync-0.5 !Empirical + + sig=db(smax/ref - 1.0) - 15.0 + if(mode4.eq.1) sig=sig-5.0 +! if(sig.lt.-20 .or. xsync.lt.1.0) sig=-20.0 +! if(sig.lt.-20) sig=-20.0 + ndf0=nint(df*(ipk-i0)) + + smax=0. + ja=jpk+16 + if(ja.gt.4*nblk) ja=ja-4*nblk + jj=jpk+20 + if(jj.gt.4*nblk) jj=jj-4*nblk + do i=ipk,ipk+60,2 !Find User's message length + ss=fs0(i,ja) + fs0(i+10,jj) + if(ss.gt.smax) then + smax=ss + ipk2=i + endif + enddo + + msglen=(ipk2-ipk)/2 + if(msglen.lt.2 .or. msglen.gt.29) cycle + + if(xsync.ge.xsyncbest) then + xsyncbest=xsync + sigbest=sig + ndf0best=ndf0 + msglenbest=msglen + ipkbest=ipk + jpkbest=jpk + idfbest=idf + endif + enddo + + xsync=xsyncbest + sig=sigbest + ndf0=ndf0best + msglen=msglenbest + ipk=ipkbest + jpk=jpkbest + idf=idfbest + if(nafc.eq.0) idf=0 + + return +end subroutine synciscat diff --git a/lib/syncmsk.f90 b/lib/syncmsk.f90 new file mode 100644 index 00000000..be28a3bb --- /dev/null +++ b/lib/syncmsk.f90 @@ -0,0 +1,304 @@ +subroutine syncmsk(cdat,npts,jpk,ipk,idf,rmax,snr,metric,decoded) + +! Attempt synchronization, and if successful decode using Viterbi algorithm. + + use iso_c_binding, only: c_loc,c_size_t + use packjt + use hashing + use timer_module, only: timer + + parameter (NSPM=1404,NSAVE=2000) + complex cdat(npts) !Analytic signal + complex cb(66) !Complex waveform for Barker-11 code + complex cd(0:11,0:3) + complex c(0:NSPM-1) !Complex data for one message length + complex c2(0:NSPM-1) + complex cb3(1:NSPM,3) + real r(12000) + real rdat(12000) + real ss1(12000) + real symbol(234) + real rdata(198) + real rd2(198) + real rsave(NSAVE) + real xp(29) + complex z,z0,z1,z2,z3,cfac + integer*1 e1(198) + integer*1, target :: d8(13) + integer*1 i1hash(4) + integer*1 i1 + integer*4 i4Msg6BitWords(12) !72-bit message as 6-bit words + integer mettab(0:255,0:1) !Metric table for BPSK modulation + integer ipksave(NSAVE) + integer jpksave(NSAVE) + integer indx(NSAVE) + integer b11(11) !Barker-11 code + character*22 decoded + character*72 c72 + logical first + equivalence (i1,i4) + equivalence (ihash,i1hash) + data xp/0.500000, 0.401241, 0.309897, 0.231832, 0.168095, & + 0.119704, 0.083523, 0.057387, 0.039215, 0.026890, & + 0.018084, 0.012184, 0.008196, 0.005475, 0.003808, & + 0.002481, 0.001710, 0.001052, 0.000789, 0.000469, & + 0.000329, 0.000225, 0.000187, 0.000086, 0.000063, & + 0.000017, 0.000091, 0.000032, 0.000045/ + data first/.true./ + data b11/1,1,1,0,0,0,1,0,0,1,0/ + save first,cb,cd,twopi,dt,f0,f1,mettab + + phi=0. + if(first) then +! Get the metric table + bias=0.0 + scale=20.0 + xln2=log(2.0) + mettab=0 + do i=128,156 + x0=log(max(0.001,2.0*xp(i-127)))/xln2 + x1=log(max(0.001,2.0*(1.0-xp(i-127))))/xln2 + mettab(i,0)=nint(scale*(x0-bias)) + mettab(i,1)=nint(scale*(x1-bias)) + mettab(256-i,0)=mettab(i,1) + mettab(256-i,1)=mettab(i,0) + enddo + do i=157,255 + mettab(i,0)=mettab(156,0) + mettab(i,1)=mettab(156,1) + mettab(256-i,0)=mettab(i,1) + mettab(256-i,1)=mettab(i,0) + enddo + j=0 + twopi=8.0*atan(1.0) + dt=1.0/12000.0 + f0=1000.0 + f1=2000.0 + dphi=0 + do i=1,11 + if(b11(i).eq.0) dphi=twopi*f0*dt + if(b11(i).eq.1) dphi=twopi*f1*dt + do n=1,6 + j=j+1 + phi=phi+dphi + cb(j)=cmplx(cos(phi),sin(phi)) + enddo + enddo + cb3=0. + cb3(1:66,1)=cb + cb3(283:348,1)=cb + cb3(769:834,1)=cb + + cb3(1:66,2)=cb + cb3(487:552,2)=cb + cb3(1123:1188,2)=cb + + cb3(1:66,3)=cb + cb3(637:702,3)=cb + cb3(919:984,3)=cb + + phi=0. + do n=0,3 + k=-1 + dphi=twopi*f0*dt + if(n.ge.2) dphi=twopi*f1*dt + do i=0,5 + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + cd(k,n)=cmplx(cos(phi),sin(phi)) + enddo + + dphi=twopi*f0*dt + if(mod(n,2).eq.1) dphi=twopi*f1*dt + do i=6,11 + k=k+1 + phi=phi+dphi + if(phi.gt.twopi) phi=phi-twopi + cd(k,n)=cmplx(cos(phi),sin(phi)) + enddo + enddo + + first=.false. + endif + + nfft=NSPM + jz=npts-nfft + decoded=" " + ipk=0 + jpk=0 + metric=-9999 + r=0. + + call timer('sync1 ',0) + do j=1,jz !Find the Barker-11 sync vectors + z=0. + ss=0. + do i=1,66 + ss=ss + real(cdat(j+i-1))**2 + aimag(cdat(j+i-1))**2 + z=z + cdat(j+i-1)*conjg(cb(i)) !Signal matching Barker 11 + enddo + ss=sqrt(ss/66.0)*66.0 + r(j)=abs(z)/(0.908*ss) !Goodness-of-fit to Barker 11 + ss1(j)=ss + enddo + call timer('sync1 ',1) + + call timer('sync2 ',0) + jz=npts-nfft + rmax=0. +! n1=35, n2=69, n3=94 + k=0 + do j=1,jz !Find best full-message sync + if(ss1(j).lt.85.0) cycle + r1=r(j) + r(j+282) + r(j+768) ! 6*(12+n1) 6*(24+n1+n2) + r2=r(j) + r(j+486) + r(j+1122) ! 6*(12+n2) 6*(24+n2+n3) + r3=r(j) + r(j+636) + r(j+918) ! 6*(12+n3) 6*(24+n3+n1) + if(r1.gt.rmax) then + rmax=r1 + jpk=j + ipk=1 + endif + if(r2.gt.rmax) then + rmax=r2 + jpk=j + ipk=2 + endif + if(r3.gt.rmax) then + rmax=r3 + jpk=j + ipk=3 + endif + rrmax=max(r1,r2,r3) + if(rrmax.gt.1.9) then + k=min(k+1,NSAVE) + if(r1.eq.rrmax) ipksave(k)=1 + if(r2.eq.rrmax) ipksave(k)=2 + if(r3.eq.rrmax) ipksave(k)=3 + jpksave(k)=j + rsave(k)=rrmax + endif + enddo + call timer('sync2 ',1) + kmax=k + + call indexx(rsave,kmax,indx) + + call timer('sync3 ',0) + do kk=1,kmax + k=indx(kmax+1-kk) + ipk=ipksave(k) + jpk=jpksave(k) + rmax=rsave(k) + + c=conjg(cb3(1:NSPM,ipk))*cdat(jpk:jpk+nfft-1) + smax=0. + dfx=0. + idfbest=0 + do itry=1,25 + idf=itry/2 + if(mod(itry,2).eq.0) idf=-idf + idf=4*idf + twk=idf + call tweak1(c,NSPM,-twk,c2) + z=sum(c2) + if(abs(z).gt.smax) then + dfx=twk + smax=abs(z) + phi=atan2(aimag(z),real(z)) !Carrier phase offset + idfbest=idf + endif + enddo + idf=idfbest + call tweak1(cdat,npts,-dfx,cdat) + cfac=cmplx(cos(phi),-sin(phi)) + cdat=cfac*cdat + + sig=0. + ref=0. + rdat(1:npts)=cdat + iz=11 + do k=1,234 !Compute soft symbols + j=jpk+6*(k-1) + + z0=2.0*dot_product(cdat(j:j+iz),cd(0:iz,0)) + z1=2.0*dot_product(cdat(j:j+iz),cd(0:iz,1)) + z2=2.0*dot_product(cdat(j:j+iz),cd(0:iz,2)) + z3=2.0*dot_product(cdat(j:j+iz),cd(0:iz,3)) + +!### Maybe these should be weighted by yellow() ? + if(j+1404+iz.lt.npts) then + z0=z0 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,0)) + z1=z1 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,1)) + z2=z2 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,2)) + z3=z3 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,3)) + endif + + if(j-1404.ge.1) then + z0=z0 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,0)) + z1=z1 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,1)) + z2=z2 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,2)) + z3=z3 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,3)) + endif + + sym=max(abs(real(z2)),abs(real(z3))) - max(abs(real(z0)),abs(real(z1))) + + if(sym.lt.0.0) then + phi=atan2(aimag(z0),real(z0)) + sig=sig + real(z0)**2 + ref=ref + aimag(z0)**2 + else + phi=atan2(aimag(z1),real(z1)) + sig=sig + real(z1)**2 + ref=ref + aimag(z1)**2 + endif + n=k + if(ipk.eq.2) n=k+47 + if(ipk.eq.3) n=k+128 + if(n.gt.234) n=n-234 + ibit=0 + if(sym.ge.0) ibit=1 + symbol(n)=sym + enddo + snr=db(sig/ref-1.0) + + rdata(1:35)=symbol(12:46) + rdata(36:104)=symbol(59:127) + rdata(105:198)=symbol(140:233) + +! Re-order the symbols and make them i*1 + j=0 + do i=1,99 + i4=128+rdata(i) !### Should be nint() ??? ### + if(i4.gt.255) i4=255 + if(i4.lt.0) i4=0 + j=j+1 + e1(j)=i1 + rd2(j)=rdata(i) + i4=128+rdata(i+99) + if(i4.gt.255) i4=255 + if(i4.lt.0) i4=0 + j=j+1 + e1(j)=i1 + rd2(j)=rdata(i+99) + enddo + +! Decode the message + nb1=87 + call vit213(e1,nb1,mettab,d8,metric) + ihash=nhash(c_loc(d8),int(9,c_size_t),146) + ihash=2*iand(ihash,32767) + decoded=' ' + if(d8(10).eq.i1hash(2) .and. d8(11).eq.i1hash(1)) then + write(c72,1012) d8(1:9) +1012 format(9b8.8) + read(c72,1014) i4Msg6BitWords +1014 format(12b6.6) + call unpackmsg(i4Msg6BitWords,decoded,.false.,' ') !Unpack to get msgsent + endif + if(decoded.ne.' ') exit + enddo + call timer('sync3 ',1) + + return +end subroutine syncmsk diff --git a/lib/t6.f90 b/lib/t6.f90 new file mode 100644 index 00000000..fd08f01f --- /dev/null +++ b/lib/t6.f90 @@ -0,0 +1,56 @@ +program t6 + + parameter (MAXFFT=1404) + complex c(0:MAXFFT-1) + real s(0:MAXFFT-1) + + m1=45 + m2=67 + m3=89 + nsym=3*11 + m1 + m2 + m3 + nfft=6*nsym + nh=nfft/2 + + best=9999. +! do m1=22,67 +! do m2=37,97 + do m1=30,67 + do m2=26,100 + m3=201-m2-m1 + if(m3.lt.13) cycle + c=0. + n1=6*(11+m1) + n2=n1+6*(11+m2) + c(1:66)=1. + c(1+n1:66+n1)=1. + c(1+n2:66+n2)=1. + + call four2a(c,nfft,1,-1,1) !c2c FFT + + df=12000.0/nfft + smax=0. + do i=0,nfft-1 + s(i)=real(c(i))**2 + aimag(c(i))**2 + if(i.ne.0) smax=max(s(i),smax) + enddo + sidelobe=db(smax/s(0)) + + if(sidelobe.lt.best) then + write(*,1000) m1,m2,m3,sidelobe +1000 format(3i5,f8.2) + best=sidelobe + s=s/s(0) + rewind 13 + do j=0,nfft-1 + i=mod(j+nh,nfft) + f=i*df + if(i.gt.nh) f=f-12000.0 + write(13,1020) f,s(i) +1020 format(2f12.4) + enddo + endif + enddo + enddo + +end program t6 + diff --git a/lib/test_init_random_seed.f90 b/lib/test_init_random_seed.f90 new file mode 100644 index 00000000..3b9dad1f --- /dev/null +++ b/lib/test_init_random_seed.f90 @@ -0,0 +1,8 @@ +program test_init_random_seed + real :: r(10,4) + call init_random_seed() + call random_number(r) + do i =1,10 + write (*, *) (r(i,j),j=1,4) + end do +end program test_init_random_seed diff --git a/lib/testfast9.f90 b/lib/testfast9.f90 new file mode 100644 index 00000000..391d88e5 --- /dev/null +++ b/lib/testfast9.f90 @@ -0,0 +1,42 @@ +program testfast9 + + parameter (NMAX=359424) + integer*2 id2(NMAX) + integer narg(0:11) + character*80 line(100) + character submode*1,infile*80 + + nargs=iargc() + if(nargs.ne.2) then + print*,'Usage: testfast9 submode infile' + print*,'Example: testfast9 E /data/VE1SKY/K1JT/JT9E/150806_123300.wav' + go to 999 + endif + call getarg(1,submode) + call getarg(2,infile) + + open(10,file=infile,access='stream',status='old') + read(10) id2(1:22) !Skip 44 header bytes + npts=NMAX + read(10,end=1) id2(1:npts) !Read the raw data + +1 i1=index(infile,'.wav') + read(infile(i1-6:i1-1),*) narg(0) + narg(1)=NMAX + n=ichar(submode) + narg(2)=n-ichar('A') + if(n.ge.97 .and. n.le.104) narg(2)=n-ichar('a') + narg(3)=1 + narg(4)=0 + narg(5)=0 + narg(6)=0 + narg(7)=29951 + narg(8)=1 + narg(9)=102 + narg(10)=700 + narg(11)=500 + + call fast9(id2,narg,line) + print*,line(1) + +999 end program testfast9 diff --git a/lib/testmsg.f90 b/lib/testmsg.f90 new file mode 100644 index 00000000..661c390a --- /dev/null +++ b/lib/testmsg.f90 @@ -0,0 +1,145 @@ + parameter (MAXTEST=75,NTEST=68) + character*22 testmsg(MAXTEST) + character*22 testmsgchk(MAXTEST) + ! Test msgs should include the extremes for the different types + ! See pfx.f90 + ! Type 1 P & A + ! Type 1 1A & E5 + data testmsg(1:NTEST)/ & + "CQ WB9XYZ EN34", & + "CQ DX WB9XYZ EN34", & + "QRZ WB9XYZ EN34", & + "KA1ABC WB9XYZ EN34", & + "KA1ABC WB9XYZ RO", & + "KA1ABC WB9XYZ -21", & + "KA1ABC WB9XYZ R-19", & + "KA1ABC WB9XYZ RRR", & + "KA1ABC WB9XYZ 73", & + "KA1ABC WB9XYZ", & + "CQ 000 WB9XYZ EN34", & + "CQ 999 WB9XYZ EN34", & + "CQ EU WB9XYZ EN34", & + "CQ WY WB9XYZ EN34", & + "1A/KA1ABC WB9XYZ", & + "E5/KA1ABC WB9XYZ", & + "KA1ABC 1A/WB9XYZ", & + "KA1ABC E5/WB9XYZ", & + "KA1ABC/P WB9XYZ", & + "KA1ABC/A WB9XYZ", & + "KA1ABC WB9XYZ/P", & + "KA1ABC WB9XYZ/A", & + "CQ KA1ABC/P", & + "CQ WB9XYZ/A", & + "QRZ KA1ABC/P", & + "QRZ WB9XYZ/A", & + "DE KA1ABC/P", & + "DE WB9XYZ/A", & + "CQ 1A/KA1ABC", & + "CQ E5/KA1ABC", & + "DE 1A/KA1ABC", & + "DE E5/KA1ABC", & + "QRZ 1A/KA1ABC", & + "QRZ E5/KA1ABC", & + "CQ WB9XYZ/1A", & + "CQ WB9XYZ/E5", & + "QRZ WB9XYZ/1A", & + "QRZ WB9XYZ/E5", & + "DE WB9XYZ/1A", & + "DE WB9XYZ/E5", & + "CQ A000/KA1ABC FM07", & + "CQ ZZZZ/KA1ABC FM07", & + "QRZ W4/KA1ABC FM07", & + "DE W4/KA1ABC FM07", & + "CQ W4/KA1ABC -22", & + "DE W4/KA1ABC -22", & + "QRZ W4/KA1ABC -22", & + "CQ W4/KA1ABC R-22", & + "DE W4/KA1ABC R-22", & + "QRZ W4/KA1ABC R-22", & + "DE W4/KA1ABC 73", & + "CQ KA1ABC FM07", & + "QRZ KA1ABC FM07", & + "DE KA1ABC/VE6 FM07", & + "CQ KA1ABC/VE6 -22", & + "DE KA1ABC/VE6 -22", & + "QRZ KA1ABC/VE6 -22", & + "CQ KA1ABC/VE6 R-22", & + "DE KA1ABC/VE6 R-22", & + "QRZ KA1ABC/VE6 R-22", & + "DE KA1ABC 73", & + "HELLO WORLD", & + "ZL4/KA1ABC 73", & + "KA1ABC XL/WB9XYZ", & + "KA1ABC WB9XYZ/W4", & + "DE KA1ABC/QRP 2W", & + "KA1ABC/1 WB9XYZ/1", & + "123456789ABCDEFGH"/ + data testmsgchk(1:NTEST)/ & + "CQ WB9XYZ EN34", & + "CQ DX WB9XYZ EN34", & + "QRZ WB9XYZ EN34", & + "KA1ABC WB9XYZ EN34", & + "KA1ABC WB9XYZ RO", & + "KA1ABC WB9XYZ -21", & + "KA1ABC WB9XYZ R-19", & + "KA1ABC WB9XYZ RRR", & + "KA1ABC WB9XYZ 73", & + "KA1ABC WB9XYZ", & + "CQ 000 WB9XYZ EN34", & + "CQ 999 WB9XYZ EN34", & + "CQ EU WB9XYZ EN34", & + "CQ WY WB9XYZ EN34", & + "1A/KA1ABC WB9XYZ", & + "E5/KA1ABC WB9XYZ", & + "KA1ABC 1A/WB9XYZ", & + "KA1ABC E5/WB9XYZ", & + "KA1ABC/P WB9XYZ", & + "KA1ABC/A WB9XYZ", & + "KA1ABC WB9XYZ/P", & + "KA1ABC WB9XYZ/A", & + "CQ KA1ABC/P", & + "CQ WB9XYZ/A", & + "QRZ KA1ABC/P", & + "QRZ WB9XYZ/A", & + "DE KA1ABC/P", & + "DE WB9XYZ/A", & + "CQ 1A/KA1ABC", & + "CQ E5/KA1ABC", & + "DE 1A/KA1ABC", & + "DE E5/KA1ABC", & + "QRZ 1A/KA1ABC", & + "QRZ E5/KA1ABC", & + "CQ WB9XYZ/1A", & + "CQ WB9XYZ/E5", & + "QRZ WB9XYZ/1A", & + "QRZ WB9XYZ/E5", & + "DE WB9XYZ/1A", & + "DE WB9XYZ/E5", & + "CQ A000/KA1ABC FM07", & + "CQ ZZZZ/KA1ABC FM07", & + "QRZ W4/KA1ABC FM07", & + "DE W4/KA1ABC FM07", & + "CQ W4/KA1ABC -22", & + "DE W4/KA1ABC -22", & + "QRZ W4/KA1ABC -22", & + "CQ W4/KA1ABC R-22", & + "DE W4/KA1ABC R-22", & + "QRZ W4/KA1ABC R-22", & + "DE W4/KA1ABC 73", & + "CQ KA1ABC FM07", & + "QRZ KA1ABC FM07", & + "DE KA1ABC/VE6 FM07", & + "CQ KA1ABC/VE6 -22", & + "DE KA1ABC/VE6 -22", & + "QRZ KA1ABC/VE6 -22", & + "CQ KA1ABC/VE6 R-22", & + "DE KA1ABC/VE6 R-22", & + "QRZ KA1ABC/VE6 R-22", & + "DE KA1ABC 73", & + "HELLO WORLD", & + "ZL4/KA1ABC 73", & + "KA1ABC XL/WB9", & + "KA1ABC WB9XYZ", & + "DE KA1ABC/QRP", & + "KA1ABC/1 WB9X", & + "123456789ABCD"/ diff --git a/lib/timefft.f90 b/lib/timefft.f90 index 4e00838d..72ab41b2 100644 --- a/lib/timefft.f90 +++ b/lib/timefft.f90 @@ -19,6 +19,8 @@ program timefft lthreading=maxthreads.ge.1 maxthreads=max(1,maxthreads) + call sgran() ! see C rand generator (used in gran) + ! Allocate data arrays pa=fftwf_alloc_complex(int(nfft,C_SIZE_T)) call c_f_pointer(pa,a,[nfft]) diff --git a/lib/timer.f90 b/lib/timer.f90 deleted file mode 100644 index 5293a573..00000000 --- a/lib/timer.f90 +++ /dev/null @@ -1,200 +0,0 @@ -subroutine timer(dname,k) - -! Times procedure number n between a call with k=0 (tstart) and with -! k=1 (tstop). Accumulates sums of these times in array ut (user time). -! Also traces all calls (for debugging purposes) if limtrace.gt.0 -! -! If this is used with OpenMP than the /tracer_priv/ common block must -! be copyed into each thread of a thread team by using the copyin() -! clause on the !$omp parallel directive that creates the team. - - !$ use omp_lib - - character*8 dname - !$ integer tid - integer onlevel(0:10) - common/tracer/ limtrace,lu - common/tracer_priv/level,onlevel - - parameter (MAXCALL=100) - character*8 name(MAXCALL),space - logical on(MAXCALL) - real ut(MAXCALL),ut0(MAXCALL) - !$ integer ntid(MAXCALL) - integer nmax,ncall(MAXCALL),nlevel(MAXCALL),nparent(MAXCALL) - common/data/nmax,name,on,ut,ut0,dut, & - !$ ntid, & - ncall,nlevel,nparent,total,sum,sumf,space - - data eps/0.000001/,ntrace/0/ - data level/0/,nmax/0/,space/' '/ - data limtrace/0/,lu/-1/ - - !$omp threadprivate(/tracer_priv/) - - !$omp critical(timer) - if(limtrace.lt.0) go to 999 - if(lu.lt.1) lu=6 - if(k.gt.1) go to 40 !Check for "all done" (k>1) - onlevel(0)=0 - - !$ tid=omp_get_thread_num() - do n=1,nmax !Check for existing name/parent[/thread] - if(name(n).eq.dname & - !$ .and.ntid(n).eq.tid & - ) then - if (on(n)) then - if (nparent(n).eq.onlevel(level-1)) goto 20 - else - if (nparent(n).eq.onlevel(level)) goto 20 - end if - end if - enddo - - nmax=nmax+1 !This is a new one - n=nmax - !$ ntid(n)=tid - ncall(n)=0 - on(n)=.false. - ut(n)=eps - name(n)=dname - -20 if(k.eq.0) then !Get start times (k=0) - if(on(n)) then - print*,'Error in timer: ',dname,' already on.' - end if - level=level+1 !Increment the level - on(n)=.true. -! call system_clock(icount,irate) -! ut0(n)=float(icount)/irate -! call cpu_time(ut0(n)) - ut0(n)=secnds(0.0) - - ncall(n)=ncall(n)+1 - if(ncall(n).gt.1.and.nlevel(n).ne.level) then - !recursion is happening - ! - !TODO: somehow need to account for this deeper call at the - !shallowest instance in the call chain and this needs to be - !done without incrementing anything here other than counters - !and timers - ! - nlevel(n)=-1 - else - nlevel(n)=level - endif - nparent(n)=onlevel(level-1) - onlevel(level)=n - - else if(k.eq.1) then !Get stop times and accumulate sums. (k=1) - if(on(n)) then - on(n)=.false. -! call system_clock(icount,irate) -! ut1=float(icount)/irate -! call cpu_time(ut1) - ut1=secnds(0.0) - - ut(n)=ut(n)+ut1-ut0(n) - endif - level=level-1 - endif - - ntrace=ntrace+1 - if(ntrace.lt.limtrace) write(lu,1020) ntrace,tname,k,level,nparent(n) -1020 format(i8,': ',a8,3i5) - go to 998 - -! Write out the timer statistics - -40 write(lu,1040) -1040 format(/' Name Time Frac dTime', & - ' dFrac Calls'/58('-')) - - !$ !walk backwards through the database rolling up thread data by call chain - !$ do i=nmax,1,-1 - !$ do j=1,i-1 - !$ l=j - !$ m=i - !$ do while (name(l).eq.name(m)) - !$ l=nparent(l) - !$ m=nparent(m) - !$ if (l.eq.0.or.m.eq.0) exit - !$ end do - !$ if (l.eq.0.and.m.eq.0) then - !$ !same call chain so roll up data - !$ ncall(j)=ncall(j)+ncall(i) - !$ ut(j)=ut(j)+ut(i) - !$ do n=1,nmax - !$ if (nparent(n).eq.i) nparent(n)=j - !$ end do - !$ name(i)=space - !$ exit - !$ end if - !$ end do - !$ end do - - if(k.gt.100) then - ndiv=k-100 - do i=1,nmax - ncall(i)=ncall(i)/ndiv - ut(i)=ut(i)/ndiv - enddo - endif - - total=ut(1) - sum=0. - sumf=0. - call print_root(1) - write(lu,1070) sum,sumf -1070 format(58('-')/32x,f10.3,f6.2) - nmax=0 - eps=0.000001 - ntrace=0 - level=0 - onlevel(0)=0 - -998 flush(lu) - -999 continue - - !$omp end critical(timer) - return -end subroutine timer - -recursive subroutine print_root(i) - character*16 sname - - common/tracer/ limtrace,lu - - parameter (MAXCALL=100) - character*8 name(MAXCALL),space - logical on(MAXCALL) - real ut(MAXCALL),ut0(MAXCALL) - !$ integer ntid(MAXCALL) - integer nmax,ncall(MAXCALL),nlevel(MAXCALL),nparent(MAXCALL) - common/data/nmax,name,on,ut,ut0,dut, & - !$ ntid, & - ncall,nlevel,nparent,total,sum,sumf,space - - if (i.le.nmax) then - if (name(i).ne.space) then - dut=ut(i) - do j=i,nmax - if (name(j).ne.space.and.nparent(j).eq.i) dut=dut-ut(j) - enddo - if(dut.lt.0.0) dut=0.0 - utf=ut(i)/total - dutf=dut/total - sum=sum+dut - sumf=sumf+dutf - kk=nlevel(i) - sname=space(1:kk)//name(i)//space(1:8-kk) - write(lu,2000) sname,ut(i),utf,dut,dutf,ncall(i) -2000 format(a16,2(f10.3,f6.2),i9) - do j=i,nmax - if(nparent(j).eq.i) call print_root(j) - enddo - end if - end if - return -end subroutine print_root diff --git a/lib/timer_C_wrapper.f90 b/lib/timer_C_wrapper.f90 new file mode 100644 index 00000000..866a8508 --- /dev/null +++ b/lib/timer_C_wrapper.f90 @@ -0,0 +1,57 @@ +module timer_c_wrapper + use :: iso_c_binding, only: c_ptr + use timer_module, only: timer, null_timer + implicit none + + ! + ! C interoperable callback setup + ! + abstract interface + subroutine c_timer_callback (context, dname, k) + use, intrinsic :: iso_c_binding, only: c_ptr, c_char + implicit none + type(c_ptr), value, intent(in) :: context + character(c_char), intent(in) :: dname(*) + integer, intent(in), value :: k + end subroutine c_timer_callback + end interface + + public :: init, fini + + private + + ! + ! the following are singleton items which assumes that any timer + ! implementation should only assume one global instance, probably a + ! struct or class object whose address is stored the context below + ! + type(c_ptr), private :: the_context + procedure(C_timer_callback), pointer, private :: the_callback + +contains + subroutine timer_callback_wrapper (dname, k) + use, intrinsic :: iso_c_binding, only: c_null_char + implicit none + character(len=8), intent(in) :: dname + integer, intent(in) :: k + call the_callback (the_context, trim (dname) // c_null_char, k) + end subroutine timer_callback_wrapper + + subroutine init (context, callback) + use, intrinsic :: iso_c_binding, only: c_ptr, c_funptr, c_f_procpointer + use iso_c_utilities, only: c_to_f_string + use timer_module, only: timer + implicit none + type(c_ptr), value, intent(in) :: context + type(c_funptr), value, intent(in) :: callback + the_context=context + call c_f_procpointer (callback, the_callback) + timer => timer_callback_wrapper + end subroutine init + + subroutine fini () + implicit none + timer => null_timer + end subroutine fini + +end module timer_c_wrapper diff --git a/lib/timer_common.inc b/lib/timer_common.inc new file mode 100644 index 00000000..1e7f32a9 --- /dev/null +++ b/lib/timer_common.inc @@ -0,0 +1,3 @@ + integer :: level, onlevel(0:10) + common/timer_private/ level, onlevel + !$omp threadprivate(/timer_private/) diff --git a/lib/timer_impl.f90 b/lib/timer_impl.f90 new file mode 100644 index 00000000..4e35162c --- /dev/null +++ b/lib/timer_impl.f90 @@ -0,0 +1,262 @@ +module timer_impl + !$ use omp_lib + use :: iso_c_binding, only: c_ptr + use timer_module, only: timer_callback + implicit none + + public :: init_timer, fini_timer + integer, public :: limtrace=0 + + private + + integer, parameter :: MAXCALL=100 + integer :: lu=6 + real :: dut + integer :: i,nmax=0,ncall(MAXCALL),nlevel(MAXCALL),nparent(MAXCALL) + character(len=8) :: name(MAXCALL),space=' ' + logical :: on(MAXCALL) + real :: total,sum,sumf,ut(MAXCALL),ut0(MAXCALL) + !$ integer :: j,l,m,ntid(MAXCALL) + + ! + ! C interoperable callback setup + ! + public :: C_init_timer + abstract interface + subroutine C_timer_callback (context, dname, k) + use, intrinsic :: iso_c_binding, only: c_ptr + implicit none + type(c_ptr), intent(in) :: context + character(len=8), intent(in) :: dname + integer, intent(in) :: k + end subroutine C_timer_callback + end interface + type(c_ptr), private :: the_context + procedure(C_timer_callback), pointer, private :: the_C_callback + +contains + subroutine timer_callback_wrapper (dname, k) + implicit none + character(len=8), intent(in) :: dname + integer, intent(in) :: k + call the_C_callback (the_context, dname, k) + end subroutine timer_callback_wrapper + + subroutine C_init_timer (context, callback) bind(C) + use, intrinsic :: iso_c_binding, only: c_ptr, c_funptr, c_f_procpointer + use iso_c_utilities, only: c_to_f_string + use timer_module, only: timer + implicit none + type(c_ptr), intent(in) :: context + type(c_funptr), intent(in) :: callback + the_context=context + call c_f_procpointer (callback, the_C_callback) + timer => timer_callback_wrapper + end subroutine C_init_timer + + ! + ! default Fortran implementation which is thread safe using OpenMP + ! + subroutine default_timer (dname, k) + + ! Times procedure number n between a call with k=0 (tstart) and with + ! k=1 (tstop). Accumulates sums of these times in array ut (user time). + ! Also traces all calls (for debugging purposes) if limtrace.gt.0 + ! + ! If this is used with OpenMP than the /timer_private/ common + ! block must be copyed into each thread of a thread team by using + ! the copyin() clause on the !$omp parallel directive that creates + ! the team. + + implicit none + + character(len=8), intent(in) :: dname + integer, intent(in) :: k + + real :: ut1,eps=0.000001 + integer :: n,ndiv,ntrace=0 + !$ integer :: tid + character(len=8) :: tname + include 'timer_common.inc' + + !$omp critical(timer) + if(limtrace.lt.0) go to 999 + if(k.gt.1) go to 40 !Check for "all done" (k>1) + onlevel(0)=0 + + !$ tid=omp_get_thread_num() + do n=1,nmax !Check for existing name/parent[/thread] + if(name(n).eq.dname & + !$ .and.ntid(n).eq.tid & + ) then + if (on(n)) then + if (nparent(n).eq.onlevel(level-1)) goto 20 + else + if (nparent(n).eq.onlevel(level)) goto 20 + end if + end if + enddo + + nmax=nmax+1 !This is a new one + n=nmax + !$ ntid(n)=tid + ncall(n)=0 + on(n)=.false. + ut(n)=eps + name(n)=dname + +20 if(k.eq.0) then !Get start times (k=0) + if(on(n)) then + print*,'Error in timer: ',dname,' already on.' + end if + level=level+1 !Increment the level + on(n)=.true. + ! call system_clock(icount,irate) + ! ut0(n)=float(icount)/irate + ! call cpu_time(ut0(n)) + ut0(n)=secnds(0.0) + + ncall(n)=ncall(n)+1 + if(ncall(n).gt.1.and.nlevel(n).ne.level) then + !recursion is happening + ! + !TODO: somehow need to account for this deeper call at the + !shallowest instance in the call chain and this needs to be + !done without incrementing anything here other than counters + !and timers + ! + nlevel(n)=-1 + else + nlevel(n)=level + endif + nparent(n)=onlevel(level-1) + onlevel(level)=n + + else if(k.eq.1) then !Get stop times and accumulate sums. (k=1) + if(on(n)) then + on(n)=.false. + ! call system_clock(icount,irate) + ! ut1=float(icount)/irate + ! call cpu_time(ut1) + ut1=secnds(0.0) + + ut(n)=ut(n)+ut1-ut0(n) + endif + level=level-1 + endif + + ntrace=ntrace+1 + if(ntrace.lt.limtrace) write(lu,1020) ntrace,tname,k,level,nparent(n) +1020 format(i8,': ',a8,3i5) + go to 998 + + ! Write out the timer statistics + +40 write(lu,1040) +1040 format(/' Name Time Frac dTime', & + ' dFrac Calls'/58('-')) + + !$ !walk backwards through the database rolling up thread data by call chain + !$ do i=nmax,1,-1 + !$ do j=1,i-1 + !$ l=j + !$ m=i + !$ do while (name(l).eq.name(m)) + !$ l=nparent(l) + !$ m=nparent(m) + !$ if (l.eq.0.or.m.eq.0) exit + !$ end do + !$ if (l.eq.0.and.m.eq.0) then + !$ !same call chain so roll up data + !$ ncall(j)=ncall(j)+ncall(i) + !$ ut(j)=ut(j)+ut(i) + !$ do n=1,nmax + !$ if (nparent(n).eq.i) nparent(n)=j + !$ end do + !$ name(i)=space + !$ exit + !$ end if + !$ end do + !$ end do + + if(k.gt.100) then + ndiv=k-100 + do i=1,nmax + ncall(i)=ncall(i)/ndiv + ut(i)=ut(i)/ndiv + enddo + endif + + total=ut(1) + sum=0. + sumf=0. + call print_root(1) + write(lu,1070) sum,sumf +1070 format(58('-')/32x,f10.3,f6.2) + nmax=0 + eps=0.000001 + ntrace=0 + level=0 + onlevel(0)=0 + +998 flush(lu) + +999 continue + + !$omp end critical(timer) + return + end subroutine default_timer + + recursive subroutine print_root(i) + implicit none + integer, intent(in) :: i + character(len=16) :: sname + real :: dutf, utf + integer :: j, kk + + if (i.le.nmax) then + if (name(i).ne.space) then + dut=ut(i) + do j=i,nmax + if (name(j).ne.space.and.nparent(j).eq.i) dut=dut-ut(j) + enddo + if(dut.lt.0.0) dut=0.0 + utf=ut(i)/total + dutf=dut/total + sum=sum+dut + sumf=sumf+dutf + kk=nlevel(i) + sname=space(1:kk)//name(i)//space(1:8-kk) + write(lu,2000) sname,ut(i),utf,dut,dutf,ncall(i) +2000 format(a16,2(f10.3,f6.2),i9) + do j=i,nmax + if(nparent(j).eq.i) call print_root(j) + enddo + end if + end if + return + end subroutine print_root + + subroutine init_timer (filename) + use, intrinsic :: iso_c_binding, only: c_char + use timer_module, only: timer + implicit none + character(len=*), optional, intent(in) :: filename + include 'timer_common.inc' + data level/0/, onlevel/11 * 0/ + if (present (filename)) then + open (newunit=lu, file=filename, status='unknown') + else + open (newunit=lu, file='timer.out', status='unknown') + end if + timer => default_timer + end subroutine init_timer + + subroutine fini_timer () + use timer_module, only: timer, null_timer + implicit none + timer => null_timer + close (lu) + end subroutine fini_timer + +end module timer_impl diff --git a/lib/timer_module.f90 b/lib/timer_module.f90 new file mode 100644 index 00000000..59675c16 --- /dev/null +++ b/lib/timer_module.f90 @@ -0,0 +1,24 @@ +module timer_module + implicit none + + abstract interface + subroutine timer_callback (dname, k) + character(len=8), intent(in) :: dname + integer, intent(in) :: k + end subroutine timer_callback + end interface + + public :: null_timer + procedure(timer_callback), pointer :: timer => null_timer + +contains + ! + ! default Fortran implementation which does nothing + ! + subroutine null_timer (dname, k) + implicit none + character(len=8), intent(in) :: dname + integer, intent(in) :: k + if(dname.eq.'99999999' .and. k.eq.9999) stop !Silence compiler warnings + end subroutine null_timer +end module timer_module diff --git a/lib/timf2.f90 b/lib/timf2.f90 new file mode 100644 index 00000000..07f50983 --- /dev/null +++ b/lib/timf2.f90 @@ -0,0 +1,142 @@ +subroutine timf2(x0,k,nfft,nwindow,nb,peaklimit,x1, & + slimit,lstrong,px,nzap) + +! Sequential processing of time-domain I/Q data, using Linrad-like +! "first FFT" and "first backward FFT", treating frequencies with +! strong signals differently. Noise blanking is applied to weak +! signals only. + +! x0 - real input data +! nfft - length of FFTs +! nwindow - 0 for no window, 2 for sin^2 window +! x1 - real output data + +! Non-windowed processing means no overlap, so kstep=nfft. +! Sin^2 window has 50% overlap, kstep=nfft/2. + +! Frequencies with strong signals are identified and separated. Back +! transforms are done separately for weak and strong signals, so that +! noise blanking can be applied to the weak-signal portion. Strong and +! weak are finally re-combined, in the time domain. + + parameter (MAXFFT=1024,MAXNH=MAXFFT/2) + parameter (MAXSIGS=100) + real x0(0:nfft-1),x1(0:nfft-1) + real x(0:MAXFFT-1),xw(0:MAXFFT-1),xs(0:MAXFFT-1) + real xwov(0:MAXNH-1),xsov(0:MAXNH-1) + complex cx(0:MAXFFT-1),cxt(0:MAXFFT-1) + complex cxs(0:MAXFFT-1) !Strong signals + complex cxw(0:MAXFFT-1) !Weak signals + real*4 w(0:MAXFFT-1) + real*4 s(0:MAXNH) + logical*1 lstrong(0:MAXNH),lprev + integer ia(MAXSIGS),ib(MAXSIGS) + logical first + equivalence (x,cx),(xw,cxw),(xs,cxs) + data first/.true./ + data k0/99999999/ + save + + if(first) then + pi=4.0*atan(1.0) + do i=0,nfft-1 + w(i)=(sin(i*pi/nfft))**2 + enddo + s=0. + nh=nfft/2 + kstep=nfft + if(nwindow.eq.2) kstep=nh + fac=1.0/nfft + slimit=1.e30 + first=.false. + endif + + if(k.lt.k0) then + xsov=0. + xwov=0. + endif + k0=k + + x(0:nfft-1)=x0 + if(nwindow.eq.2) x(0:nfft-1)=w(0:nfft-1)*x(0:nfft-1) + call four2a(x,nfft,1,-1,0) !First forward FFT, r2c + cxt(0:nh)=cx(0:nh) + +! Identify frequencies with strong signals. + do i=0,nh + p=real(cxt(i))**2 + aimag(cxt(i))**2 + s(i)=p + enddo + ave=sum(s(0:nh))/nh + lstrong(0:nh)=s(0:nh).gt.10.0*ave + + nsigs=0 + lprev=.false. + iwid=1 + ib=-99 + do i=0,nh + if(lstrong(i) .and. (.not.lprev)) then + if(nsigs.lt.MAXSIGS) nsigs=nsigs+1 + ia(nsigs)=i-iwid + if(ia(nsigs).lt.0) ia(nsigs)=0 + endif + if(.not.lstrong(i) .and. lprev) then + ib(nsigs)=i-1+iwid + if(ib(nsigs).gt.nh) ib(nsigs)=nh + endif + lprev=lstrong(i) + enddo + + if(nsigs.gt.0) then + do i=1,nsigs + ja=ia(i) + jb=ib(i) + if(ja.lt.0 .or. ja.gt.nh .or. jb.lt.0 .or. jb.gt.nh) then + cycle + endif + if(jb.eq.-99) jb=ja + min(2*iwid,nh) + lstrong(ja:jb)=.true. + enddo + endif + +! Copy frequency-domain data into array cs (strong) or cw (weak). + do i=0,nh + if(lstrong(i)) then + cxs(i)=fac*cxt(i) + cxw(i)=0. + else + cxw(i)=fac*cxt(i) + cxs(i)=0. + endif + enddo + + call four2a(cxw,nfft,1,1,-1) !Transform weak and strong back + call four2a(cxs,nfft,1,1,-1) !to time domain, separately (c2r) + + if(nwindow.eq.2) then + xw(0:nh-1)=xw(0:nh-1)+xwov(0:nh-1) !Add previous segment's 2nd half + xwov(0:nh-1)=xw(nh:nfft-1) !Save 2nd half + xs(0:nh-1)=xs(0:nh-1)+xsov(0:nh-1) !Ditto for strong signals + xsov(0:nh-1)=xs(nh:nfft-1) + endif + +! Apply noise blanking to weak data + if(nb.ne.0) then + do i=0,kstep-1 + peak=abs(xw(i)) + if(peak.gt.peaklimit) then + xw(i)=0. + nzap=nzap+1 + endif + enddo + endif + +! Compute power levels from weak data only + do i=0,kstep-1 + px=px + xw(i)**2 + enddo + + x1(0:kstep-1)=xw(0:kstep-1) + xs(0:kstep-1) !Recombine weak + strong + + return +end subroutine timf2 diff --git a/lib/tm2.f90 b/lib/tm2.f90 deleted file mode 100644 index cf110783..00000000 --- a/lib/tm2.f90 +++ /dev/null @@ -1,14 +0,0 @@ -subroutine tm2(day,xlat4,xlon4,xl4,b4) - - implicit real*8 (a-h,o-z) - parameter (RADS=0.0174532925199433d0) - - real*4 xlat4,xlon4,xl4,b4 - - glat=xlat4*RADS - glong=xlon4*RADS - call tmoonsub(day,glat,glong,el,rv,xl,b,pax) - xl4=xl - b4=b - -end subroutine tm2 diff --git a/lib/to_contest_msg.f90 b/lib/to_contest_msg.f90 new file mode 100644 index 00000000..42691951 --- /dev/null +++ b/lib/to_contest_msg.f90 @@ -0,0 +1,27 @@ +subroutine to_contest_msg(msg0,msg) + +! If the message has "R grid4" istead of "grid4", remove the "R " +! and substitute the diametrically opposite grid. + + character*6 g1,g2 + character*22 msg0,msg + logical isgrid + isgrid(g1)=g1(1:1).ge.'A' .and. g1(1:1).le.'R' .and. g1(2:2).ge.'A' .and. & + g1(2:2).le.'R' .and. g1(3:3).ge.'0' .and. g1(3:3).le.'9' .and. & + g1(4:4).ge.'0' .and. g1(4:4).le.'9' .and. g1(1:4).ne.'RR73' + + i0=index(msg0,' R ') + 3 !Check for ' R ' in message + g1=msg0(i0:i0+3)//' ' + if(isgrid(g1)) then !Check for ' R grid' + call grid2deg(g1,dlong,dlat) + dlong=dlong+180.0 + if(dlong.gt.180.0) dlong=dlong-360.0 + dlat=-dlat + call deg2grid(dlong,dlat,g2) !g2=antipodes grid + msg=msg0(1:i0-3)//g2(1:4) !Send message with g2 + else + msg=msg0 + endif + + return +end subroutine to_contest_msg diff --git a/lib/toxyz.f90 b/lib/toxyz.f90 deleted file mode 100644 index 646dd7a2..00000000 --- a/lib/toxyz.f90 +++ /dev/null @@ -1,25 +0,0 @@ -subroutine toxyz(alpha,delta,r,vec) - - implicit real*8 (a-h,o-z) - real*8 vec(3) - - vec(1)=r*cos(delta)*cos(alpha) - vec(2)=r*cos(delta)*sin(alpha) - vec(3)=r*sin(delta) - - return -end subroutine toxyz - -subroutine fromxyz(vec,alpha,delta,r) - - implicit real*8 (a-h,o-z) - real*8 vec(3) - data twopi/6.283185307d0/ - - r=sqrt(vec(1)**2 + vec(2)**2 + vec(3)**2) - alpha=atan2(vec(2),vec(1)) - if(alpha.lt.0.d0) alpha=alpha+twopi - delta=asin(vec(3)/r) - - return -end subroutine fromxyz diff --git a/lib/tweak1.f90 b/lib/tweak1.f90 new file mode 100644 index 00000000..c62c4087 --- /dev/null +++ b/lib/tweak1.f90 @@ -0,0 +1,23 @@ +subroutine tweak1(ca,jz,f0,cb) + +! Shift frequency of analytic signal ca, with output to cb + + complex ca(jz),cb(jz) + real*8 twopi + complex*16 w,wstep + complex w4 + data twopi/0.d0/ + save twopi + + if(twopi.eq.0.d0) twopi=8.d0*atan(1.d0) + w=1.d0 + dphi=twopi*f0/12000.d0 + wstep=cmplx(cos(dphi),sin(dphi)) + do i=1,jz + w=w*wstep + w4=w + cb(i)=w4*ca(i) + enddo + + return +end subroutine tweak1 diff --git a/lib/unpackbits.f90 b/lib/unpackbits.f90 deleted file mode 100644 index a3ff15f1..00000000 --- a/lib/unpackbits.f90 +++ /dev/null @@ -1,22 +0,0 @@ -subroutine unpackbits(sym,nsymd,m0,dbits) - -! Unpack bits from sym() into dbits(), one bit per byte. -! NB: nsymd is the number of input words, and m0 their length. -! there will be m0*nsymd output bytes, each 0 or 1. - - integer sym(nsymd) - integer*1 dbits(*) - - k=0 - do i=1,nsymd - mask=ishft(1,m0-1) - do j=1,m0 - k=k+1 - dbits(k)=0 - if(iand(mask,sym(i)).ne.0) dbits(k)=1 - mask=ishft(mask,-1) - enddo - enddo - - return -end subroutine unpackbits diff --git a/lib/unpackcall.f90 b/lib/unpackcall.f90 deleted file mode 100644 index 3b009b27..00000000 --- a/lib/unpackcall.f90 +++ /dev/null @@ -1,138 +0,0 @@ -subroutine unpackcall(ncall,word,iv2,psfx) - - parameter (NBASE=37*36*10*27*27*27) - character word*12,c*37,psfx*4 - - data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ '/ - - word='......' - psfx=' ' - n=ncall - iv2=0 - if(n.ge.262177560) go to 20 - word='......' -! if(n.ge.262177560) go to 999 !Plain text message ... - i=mod(n,27)+11 - word(6:6)=c(i:i) - n=n/27 - i=mod(n,27)+11 - word(5:5)=c(i:i) - n=n/27 - i=mod(n,27)+11 - word(4:4)=c(i:i) - n=n/27 - i=mod(n,10)+1 - word(3:3)=c(i:i) - n=n/10 - i=mod(n,36)+1 - word(2:2)=c(i:i) - n=n/36 - i=n+1 - word(1:1)=c(i:i) - do i=1,4 - if(word(i:i).ne.' ') go to 10 - enddo - go to 999 -10 word=word(i:) - go to 999 - -20 if(n.ge.267796946) go to 999 - -! We have a JT65v2 message - if((n.ge.262178563) .and. (n.le.264002071)) then -! CQ with prefix - iv2=1 - n=n-262178563 - i=mod(n,37)+1 - psfx(4:4)=c(i:i) - n=n/37 - i=mod(n,37)+1 - psfx(3:3)=c(i:i) - n=n/37 - i=mod(n,37)+1 - psfx(2:2)=c(i:i) - n=n/37 - i=n+1 - psfx(1:1)=c(i:i) - - else if((n.ge.264002072) .and. (n.le.265825580)) then -! QRZ with prefix - iv2=2 - n=n-264002072 - i=mod(n,37)+1 - psfx(4:4)=c(i:i) - n=n/37 - i=mod(n,37)+1 - psfx(3:3)=c(i:i) - n=n/37 - i=mod(n,37)+1 - psfx(2:2)=c(i:i) - n=n/37 - i=n+1 - psfx(1:1)=c(i:i) - - else if((n.ge.265825581) .and. (n.le.267649089)) then -! DE with prefix - iv2=3 - n=n-265825581 - i=mod(n,37)+1 - psfx(4:4)=c(i:i) - n=n/37 - i=mod(n,37)+1 - psfx(3:3)=c(i:i) - n=n/37 - i=mod(n,37)+1 - psfx(2:2)=c(i:i) - n=n/37 - i=n+1 - psfx(1:1)=c(i:i) - - else if((n.ge.267649090) .and. (n.le.267698374)) then -! CQ with suffix - iv2=4 - n=n-267649090 - i=mod(n,37)+1 - psfx(3:3)=c(i:i) - n=n/37 - i=mod(n,37)+1 - psfx(2:2)=c(i:i) - n=n/37 - i=n+1 - psfx(1:1)=c(i:i) - - else if((n.ge.267698375) .and. (n.le.267747659)) then -! QRZ with suffix - iv2=5 - n=n-267698375 - i=mod(n,37)+1 - psfx(3:3)=c(i:i) - n=n/37 - i=mod(n,37)+1 - psfx(2:2)=c(i:i) - n=n/37 - i=n+1 - psfx(1:1)=c(i:i) - - else if((n.ge.267747660) .and. (n.le.267796944)) then -! DE with suffix - iv2=6 - n=n-267747660 - i=mod(n,37)+1 - psfx(3:3)=c(i:i) - n=n/37 - i=mod(n,37)+1 - psfx(2:2)=c(i:i) - n=n/37 - i=n+1 - psfx(1:1)=c(i:i) - - else if(n.eq.267796945) then -! DE with no prefix or suffix - iv2=7 - psfx = ' ' - endif - -999 if(word(1:3).eq.'3D0') word='3DA0'//word(4:) - - return -end subroutine unpackcall diff --git a/lib/unpackgrid.f90 b/lib/unpackgrid.f90 deleted file mode 100644 index 84dc7441..00000000 --- a/lib/unpackgrid.f90 +++ /dev/null @@ -1,45 +0,0 @@ -subroutine unpackgrid(ng,grid) - - parameter (NGBASE=180*180) - character grid*4,grid6*6 - - grid=' ' - if(ng.ge.32400) go to 10 - dlat=mod(ng,180)-90 - dlong=(ng/180)*2 - 180 + 2 - call deg2grid(dlong,dlat,grid6) - grid=grid6(:4) - if(grid(1:2).eq.'KA') then - read(grid(3:4),*) n - n=n-50 - write(grid,1001) n -1001 format(i3.2) - if(grid(1:1).eq.' ') grid(1:1)='+' - else if(grid(1:2).eq.'LA') then - read(grid(3:4),*) n - n=n-50 - write(grid,1002) n -1002 format('R',i3.2) - if(grid(2:2).eq.' ') grid(2:2)='+' - endif - go to 900 - -10 n=ng-NGBASE-1 - if(n.ge.1 .and.n.le.30) then - write(grid,1012) -n -1012 format(i3.2) - else if(n.ge.31 .and.n.le.60) then - n=n-30 - write(grid,1022) -n -1022 format('R',i3.2) - else if(n.eq.61) then - grid='RO' - else if(n.eq.62) then - grid='RRR' - else if(n.eq.63) then - grid='73' - endif - -900 return -end subroutine unpackgrid - diff --git a/lib/unpackmsg.f90 b/lib/unpackmsg.f90 deleted file mode 100644 index 531bb300..00000000 --- a/lib/unpackmsg.f90 +++ /dev/null @@ -1,108 +0,0 @@ -subroutine unpackmsg(dat,msg) - - parameter (NBASE=37*36*10*27*27*27) - parameter (NGBASE=180*180) - integer dat(12) - character c1*12,c2*12,grid*4,msg*22,grid6*6,psfx*4,junk2*4 - logical cqnnn - - cqnnn=.false. - nc1=ishft(dat(1),22) + ishft(dat(2),16) + ishft(dat(3),10)+ & - ishft(dat(4),4) + iand(ishft(dat(5),-2),15) - - nc2=ishft(iand(dat(5),3),26) + ishft(dat(6),20) + & - ishft(dat(7),14) + ishft(dat(8),8) + ishft(dat(9),2) + & - iand(ishft(dat(10),-4),3) - - ng=ishft(iand(dat(10),15),12) + ishft(dat(11),6) + dat(12) - - if(ng.ge.32768) then - call unpacktext(nc1,nc2,ng,msg) - go to 100 - endif - - call unpackcall(nc1,c1,iv2,psfx) - if(iv2.eq.0) then -! This is an "original JT65" message - if(nc1.eq.NBASE+1) c1='CQ ' - if(nc1.eq.NBASE+2) c1='QRZ ' - nfreq=nc1-NBASE-3 - if(nfreq.ge.0 .and. nfreq.le.999) then - write(c1,1002) nfreq -1002 format('CQ ',i3.3) - cqnnn=.true. - endif - endif - - call unpackcall(nc2,c2,junk1,junk2) - call unpackgrid(ng,grid) - - if(iv2.gt.0) then -! This is a JT65v2 message - do i=1,4 - if(ichar(psfx(i:i)).eq.0) psfx(i:i)=' ' - enddo - - n1=len_trim(psfx) - n2=len_trim(c2) - if(iv2.eq.1) msg='CQ '//psfx(:n1)//'/'//c2(:n2)//' '//grid - if(iv2.eq.2) msg='QRZ '//psfx(:n1)//'/'//c2(:n2)//' '//grid - if(iv2.eq.3) msg='DE '//psfx(:n1)//'/'//c2(:n2)//' '//grid - if(iv2.eq.4) msg='CQ '//c2(:n2)//'/'//psfx(:n1)//' '//grid - if(iv2.eq.5) msg='QRZ '//c2(:n2)//'/'//psfx(:n1)//' '//grid - if(iv2.eq.6) msg='DE '//c2(:n2)//'/'//psfx(:n1)//' '//grid - if(iv2.eq.7) msg='DE '//c2(:n2)//' '//grid - if(iv2.eq.8) msg=' ' - go to 100 - else - - endif - - grid6=grid//'ma' - call grid2k(grid6,k) - if(k.ge.1 .and. k.le.450) call getpfx2(k,c1) - if(k.ge.451 .and. k.le.900) call getpfx2(k,c2) - - i=index(c1,char(0)) - if(i.ge.3) c1=c1(1:i-1)//' ' - i=index(c2,char(0)) - if(i.ge.3) c2=c2(1:i-1)//' ' - - msg=' ' - j=0 - if(cqnnn) then - msg=c1//' ' - j=7 !### ??? ### - go to 10 - endif - - do i=1,12 - j=j+1 - msg(j:j)=c1(i:i) - if(c1(i:i).eq.' ') go to 10 - enddo - j=j+1 - msg(j:j)=' ' - -10 do i=1,12 - if(j.le.21) j=j+1 - msg(j:j)=c2(i:i) - if(c2(i:i).eq.' ') go to 20 - enddo - if(j.le.21) j=j+1 - msg(j:j)=' ' - -20 if(k.eq.0) then - do i=1,4 - if(j.le.21) j=j+1 - msg(j:j)=grid(i:i) - enddo - if(j.le.21) j=j+1 - msg(j:j)=' ' - endif - -100 continue - if(msg(1:6).eq.'CQ9DX ') msg(3:3)=' ' - - return -end subroutine unpackmsg diff --git a/lib/unpackmsg144.f90 b/lib/unpackmsg144.f90 new file mode 100644 index 00000000..96423ff6 --- /dev/null +++ b/lib/unpackmsg144.f90 @@ -0,0 +1,117 @@ + subroutine unpackmsg144(dat,msg,c1,c2) +! special unpackmsg for MSK144 - returns call1 and call2 to enable +! maintenance of a recent-calls-heard list + + use packjt + parameter (NBASE=37*36*10*27*27*27) + parameter (NGBASE=180*180) + integer dat(12) + character c1*12,c2*12,grid*4,msg*22,grid6*6,psfx*4,junk2*4 + logical cqnnn + + cqnnn=.false. + nc1=ishft(dat(1),22) + ishft(dat(2),16) + ishft(dat(3),10)+ & + ishft(dat(4),4) + iand(ishft(dat(5),-2),15) + + nc2=ishft(iand(dat(5),3),26) + ishft(dat(6),20) + & + ishft(dat(7),14) + ishft(dat(8),8) + ishft(dat(9),2) + & + iand(ishft(dat(10),-4),3) + + ng=ishft(iand(dat(10),15),12) + ishft(dat(11),6) + dat(12) + + if(ng.ge.32768) then + call unpacktext(nc1,nc2,ng,msg) + c1(1:12)=' ' + c2(1:12)=' ' + go to 100 + endif + + call unpackcall(nc1,c1,iv2,psfx) + if(iv2.eq.0) then + ! This is an "original JT65" message + if(nc1.eq.NBASE+1) c1='CQ ' + if(nc1.eq.NBASE+2) c1='QRZ ' + nfreq=nc1-NBASE-3 + if(nfreq.ge.0 .and. nfreq.le.999) then + write(c1,1002) nfreq + 1002 format('CQ ',i3.3) + cqnnn=.true. + endif + endif + + call unpackcall(nc2,c2,junk1,junk2) + call unpackgrid(ng,grid) + + if(iv2.gt.0) then + ! This is a JT65v2 message + do i=1,4 + if(ichar(psfx(i:i)).eq.0) psfx(i:i)=' ' + enddo + + n1=len_trim(psfx) + n2=len_trim(c2) + if(iv2.eq.1) msg='CQ '//psfx(:n1)//'/'//c2(:n2)//' '//grid + if(iv2.eq.2) msg='QRZ '//psfx(:n1)//'/'//c2(:n2)//' '//grid + if(iv2.eq.3) msg='DE '//psfx(:n1)//'/'//c2(:n2)//' '//grid + if(iv2.eq.4) msg='CQ '//c2(:n2)//'/'//psfx(:n1)//' '//grid + if(iv2.eq.5) msg='QRZ '//c2(:n2)//'/'//psfx(:n1)//' '//grid + if(iv2.eq.6) msg='DE '//c2(:n2)//'/'//psfx(:n1)//' '//grid + if(iv2.eq.7) msg='DE '//c2(:n2)//' '//grid + if(iv2.eq.8) msg=' ' + go to 100 + else + + endif + + grid6=grid//'ma' + call grid2k(grid6,k) + if(k.ge.1 .and. k.le.450) call getpfx2(k,c1) + if(k.ge.451 .and. k.le.900) call getpfx2(k,c2) + + i=index(c1,char(0)) + if(i.ge.3) c1=c1(1:i-1)//' ' + i=index(c2,char(0)) + if(i.ge.3) c2=c2(1:i-1)//' ' + + msg=' ' + j=0 + if(cqnnn) then + msg=c1//' ' + j=7 !### ??? ### + go to 10 + endif + + do i=1,12 + j=j+1 + msg(j:j)=c1(i:i) + if(c1(i:i).eq.' ') go to 10 + enddo + j=j+1 + msg(j:j)=' ' + + 10 do i=1,12 + if(j.le.21) j=j+1 + msg(j:j)=c2(i:i) + if(c2(i:i).eq.' ') go to 20 + enddo + if(j.le.21) j=j+1 + msg(j:j)=' ' + + 20 if(k.eq.0) then + do i=1,4 + if(j.le.21) j=j+1 + msg(j:j)=grid(i:i) + enddo + if(j.le.21) j=j+1 + msg(j:j)=' ' + endif + + 100 continue + if(msg(1:6).eq.'CQ9DX ') msg(3:3)=' ' + if(msg(1:2).eq.'E9' .and. & + msg(3:3).ge.'A' .and. msg(3:3).le.'Z' .and. & + msg(4:4).ge.'A' .and. msg(4:4).le.'Z' .and. & + msg(5:5).eq.' ') msg='CQ '//msg(3:) + + return + end subroutine unpackmsg144 diff --git a/lib/unpacktext.f90 b/lib/unpacktext.f90 deleted file mode 100644 index 62451f97..00000000 --- a/lib/unpacktext.f90 +++ /dev/null @@ -1,35 +0,0 @@ -subroutine unpacktext(nc1,nc2,nc3,msg) - - character*22 msg - character*44 c - data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ +-./?'/ - - nc3=iand(nc3,32767) !Remove the "plain text" bit - if(iand(nc1,1).ne.0) nc3=nc3+32768 - nc1=nc1/2 - if(iand(nc2,1).ne.0) nc3=nc3+65536 - nc2=nc2/2 - - do i=5,1,-1 - j=mod(nc1,42)+1 - msg(i:i)=c(j:j) - nc1=nc1/42 - enddo - - do i=10,6,-1 - j=mod(nc2,42)+1 - msg(i:i)=c(j:j) - nc2=nc2/42 - enddo - - do i=13,11,-1 - j=mod(nc3,42)+1 - msg(i:i)=c(j:j) - nc3=nc3/42 - enddo - msg(14:22) = ' ' - - return -end subroutine unpacktext - - diff --git a/lib/update_hasharray.f90 b/lib/update_hasharray.f90 new file mode 100644 index 00000000..0f9c872e --- /dev/null +++ b/lib/update_hasharray.f90 @@ -0,0 +1,25 @@ +subroutine update_hasharray(recent_calls,nrecent,nhasharray) + + character*12 recent_calls(nrecent) + character*22 hashmsg + integer nhasharray(nrecent,nrecent) + + nhasharray=-1 + do i=1,nrecent + do j=i+1,nrecent + if( recent_calls(i)(1:1) .ne. ' ' .and. recent_calls(j)(1:1) .ne. ' ' ) then + hashmsg=trim(recent_calls(i))//' '//trim(recent_calls(j)) + call fmtmsg(hashmsg,iz) + call hash(hashmsg,22,ihash) + ihash=iand(ihash,4095) + nhasharray(i,j)=ihash + hashmsg=trim(recent_calls(j))//' '//trim(recent_calls(i)) + call fmtmsg(hashmsg,iz) + call hash(hashmsg,22,ihash) + ihash=iand(ihash,4095) + nhasharray(j,i)=ihash + endif + enddo + enddo + +end subroutine update_hasharray diff --git a/lib/update_recent_calls.f90 b/lib/update_recent_calls.f90 new file mode 100644 index 00000000..e67ff385 --- /dev/null +++ b/lib/update_recent_calls.f90 @@ -0,0 +1,19 @@ +subroutine update_recent_calls(call,calls_hrd,nsize) +character*12 call,calls_hrd(nsize) + + new=1 + do ic=1,nsize + if( calls_hrd(ic).eq.call ) then + new=0 + endif + enddo + + if( new.eq.1 ) then + do ic=nsize-1,1,-1 + calls_hrd(ic+1)(1:12)=calls_hrd(ic)(1:12) + enddo + calls_hrd(1)(1:12)=call(1:12) + endif + + return + end subroutine update_recent_calls diff --git a/lib/vit213.c b/lib/vit213.c new file mode 100644 index 00000000..93f803ab --- /dev/null +++ b/lib/vit213.c @@ -0,0 +1,221 @@ +/* Viterbi decoder for arbitrary convolutional code + * viterbi27 and viterbi37 for the r=1/2 and r=1/3 K=7 codes are faster + * Copyright 1999 Phil Karn, KA9Q + * Modifications by Joe Taylor, K1JT + * May be used under the terms of the GNU Public License + */ + +#include + +/* Select code here */ + +#define V213 + +#ifdef V213 +#define K 13 /* Constraint length */ +#define N 2 /* Number of symbols per data bit */ +#define Polys Poly213 /* Select polynomials here */ +#endif + +/* Rate 1/2 codes */ +unsigned int Poly213[] = {012767,016461}; /* k = 13 */ + +#include + +#define LONGBITS 32 +#define LOGLONGBITS 5 + +#undef max +#define max(x,y) ((x) > (y) ? (x) : (y)) +#define D (1 << max(0,K-LOGLONGBITS-1)) +#define MAXNBITS 200 /* Maximum frame size (user bits) */ + +extern unsigned char Partab[]; /* Parity lookup table */ + +int Syms[1 << K]; + + +int parity(int x) +{ + x ^= (x >> 16); + x ^= (x >> 8); + return Partab[x & 0xff]; +} + +/* Convolutionally encode data into binary symbols */ +int enc213(unsigned char symbols[], unsigned char data[], + unsigned int nbytes, unsigned int startstate, + unsigned int endstate) +{ + unsigned int i,j,k; + int l,n=-1; + unsigned int encstate = startstate; + + for(k=0; k=0;l--){ + encstate = (encstate + encstate) + ((data[k] >> l) & 1); + for(j=0;j> i) & 1); + for(j=0;j> (N-j-1)) & 1][symbols[j]]; + } + } + symbols += N; + /* Run the add-compare-select operations */ + mask = 1; + for(i=0;i< 1 << (K-1);i+=2){ + int b1,b2; + + b1 = mets[Syms[i]]; + nmetric[i] = m0 = cmetric[i/2] + b1; + b2 = mets[Syms[i+1]]; + b1 -= b2; + m1 = cmetric[(i/2) + (1<<(K-2))] + b2; + + if(m1 > m0){ + nmetric[i] = m1; + *pp |= mask; + } + + m0 -= b1; + nmetric[i+1] = m0; + m1 += b1; + + if(m1 > m0){ + nmetric[i+1] = m1; + *pp |= mask << 1; + } + + mask <<= 2; + if(mask == 0){ + mask = 1; + pp++; + ipp++; + } + } + if(mask != 1){ + pp++; + ipp++; + } + if(++bitcnt == (int)nbits){ + *metric = nmetric[endstate]; + break; + } + memcpy(cmetric,nmetric,sizeof(cmetric)); + } + + /* Chain back from terminal state to produce decoded data */ + if(data == NULL) + return 0;/* Discard output */ + memset(data,0,(nbits+7)/8); /* round up in case nbits % 8 != 0 */ + + for(i=nbits-1;i >= 0;i--){ + // int a0,a1; + pp -= D; + ipp -= D; + m0=endstate >> LOGLONGBITS; + m1=1L << (endstate & (LONGBITS-1)); + if(pp[m0] & m1) { + // a0=nmetric[endstate]; + endstate |= (1 << (K-1)); + // a1=nmetric[endstate]; + data[i>>3] |= 0x80 >> (i&7); + // printf("B %d %d %d %d\n",*metric,i,a0,a1); + } + endstate >>= 1; + } + return 0; +} + +// Wrapper for calling "encode" from Fortran: +void enc213_( +unsigned char data[], // User data, 8 bits per byte +int *nbits, // Number of user bits +unsigned char symbols[], // Encoded one-bit symbols, 8 per byte +int *nsymbols, // Number of symbols +int *kk, // K +int *nn) // N +{ + int nbytes; + nbytes=(*nbits+7)/8; // Always encode multiple of 8 information bits + enc213(symbols,data,nbytes,0,0); // Do the encoding + *nsymbols=(*nbits+K-1)*N; // Return number of encoded symbols + *kk=K; + *nn=N; +} + +// Wrapper for calling "viterbi" from Fortran: +void vit213_( +unsigned char symbols[], /* Raw deinterleaved input symbols */ +unsigned int *Nbits, /* Number of decoded information bits */ +int mettab[2][256], /* Metric table, [sent sym][rx symbol] */ +unsigned char ddec[], /* Decoded output data */ +int *Metric /* Final path metric (bigger is better) */ +){ + int metric; + vit213(&metric,ddec,symbols,*Nbits,mettab,0,0); + *Metric=metric; +} + diff --git a/lib/vit216.c b/lib/vit216.c index 38984d2f..fc0c5a76 100644 --- a/lib/vit216.c +++ b/lib/vit216.c @@ -18,8 +18,8 @@ /* Rate 1/2 codes */ unsigned int Poly216[] = {0126723, 0152711}; /* k = 16 */ +#include #include -#define NULL ((void *)0) #define LONGBITS 32 #define LOGLONGBITS 5 diff --git a/lib/wav11.f90 b/lib/wav11.f90 new file mode 100644 index 00000000..3bba0bf8 --- /dev/null +++ b/lib/wav11.f90 @@ -0,0 +1,27 @@ +subroutine wav11(d2,npts,dd) + +! Convert i*2 data sampled at 12000 Hz to r*4 sampled at 11025 Hz. + + parameter (NZ11=60*11025,NZ12=60*12000) + parameter (NFFT1=64*12000,NFFT2=64*11025) + integer*2 d2(NZ12) + real*4 dd(NZ11) + real x(NFFT2) + complex cx(0:NFFT1/2) + equivalence (x,cx) + save x,cx + + jz=min(NZ12,npts) + x(1:jz)=d2(1:jz) + x(jz+1:)=0.0 + call four2a(x,nfft1,1,-1,0) !Forward FFT, r2c + df=12000.0/NFFT1 + ia=5000.0/df + cx(ia:)=0.0 + call four2a(cx,nfft2,1,1,-1) !Inverse FFT, c2r + npts=jz*11025.0/12000.0 + fac=1.e-6 + dd(1:npts)=fac*x(1:npts) + + return +end subroutine wav11 diff --git a/lib/wav12.f90 b/lib/wav12.f90 new file mode 100644 index 00000000..31fe1d59 --- /dev/null +++ b/lib/wav12.f90 @@ -0,0 +1,49 @@ +subroutine wav12(d2,d1,npts,nbitsam2) + +! Convert i*2 or i*1 data at 11025 Hz (from WSJT *.wav files) +! to i*2 data at 12000 Hz. + +! Input: i*2 d2(npts) or i*1 d1(npts) +! i*2 nbitsam2 = 8 or 16 (bits per sample) + +! Output: npts = (12000*npts)/11025 +! i*2 d2(npts) + + parameter (NZ11=60*11025,NZ12=60*12000) + parameter (NFFT1=64*11025,NFFT2=64*12000) + integer*1 d1(NZ11) + integer*1 d1a(NZ11) + integer*1 i1 + integer*2 i2 + integer*2 d2(NZ12) + real x(NFFT2) + complex cx(0:NFFT2/2) + integer*2 nbitsam2 + equivalence (x,cx),(i1,i2) + + jz=min(NZ11,npts) + if(nbitsam2.eq.8) then + jz=min(NZ11,npts) + d1a(1:jz)=d1(1:jz) !d1 and d2 may be same array in calling prog + do i=1,jz !Move data from d1a into d2 + i2=0 + i1=d1a(i) + d2(i)=10*(i2-128) + enddo + endif + + x(1:jz)=d2(1:jz) + x(jz+1:)=0.0 + call four2a(x,nfft1,1,-1,0) !Forwarxd FFT, r2c + cx(nfft1/2:)=0.0 + call four2a(cx,nfft2,1,1,-1) !Inverse FFT, c2r + + npts=jz*12000.0/11025.0 + fac=1.e-6 +! if(nbitsam2.eq.16) fac=3.e-6 + x=fac*x + d2(1:npts)=nint(x(1:npts)) + if(npts.lt.NZ12) d2(npts+1:NZ12)=0 + + return +end subroutine wav12 diff --git a/lib/wavhdr.f90 b/lib/wavhdr.f90 index b42d5e86..b54fba78 100644 --- a/lib/wavhdr.f90 +++ b/lib/wavhdr.f90 @@ -35,4 +35,76 @@ module wavhdr default_header=h end function default_header + subroutine set_wsjtx_wav_params(fMHz,mode,nsubmode,ntrperiod,id2) + + parameter (NBANDS=23,NMODES=11) + character*8 mode,modes(NMODES) + integer*2 id2(4) + integer iperiod(7) + real fband(NBANDS) + data fband/0.137,0.474,1.8,3.5,5.1,7.0,10.14,14.0,18.1,21.0,24.9, & + 28.0,50.0,144.0,222.0,432.0,902.0,1296.0,2304.0,3400.0, & + 5760.0,10368.0,24048.0/ + data modes/'Echo','FSK441','ISCAT','JT4','JT65','JT6M','JT9', & + 'JT9+JT65','JTMS','JTMSK','WSPR'/ + data iperiod/5,10,15,30,60,120,900/ + + dmin=1.e30 + iband=0 + do i=1,NBANDS + if(abs(fMHz-fband(i)).lt.dmin) then + dmin=abs(fMHz-fband(i)) + iband=i + endif + enddo + + imode=0 + do i=1,NMODES + if(mode.eq.modes(i)) imode=i + enddo + + ip=0 + do i=1,7 + if(ntrperiod.eq.iperiod(i)) ip=i + enddo + + id2(1)=iband + id2(2)=imode + id2(3)=nsubmode + id2(4)=ip + + return + end subroutine set_wsjtx_wav_params + + subroutine get_wsjtx_wav_params(id2,band,mode,nsubmode,ntrperiod,ok) + + parameter (NBANDS=23,NMODES=11) + character*8 mode,modes(NMODES) + character*6 band,bands(NBANDS) + integer*2 id2(4) + integer iperiod(7) + logical ok + data modes/'Echo','FSK441','ISCAT','JT4','JT65','JT6M','JT9', & + 'JT9+JT65','JTMS','JTMSK','WSPR'/ + data iperiod/5,10,15,30,60,120,900/ + data bands/'2190m','630m','160m','80m','60m','40m','30m','20m', & + '17m','15m','12m','10m','6m','2m','1.25m','70cm','33cm', & + '23cm','13cm','9cm','6cm','3cm','1.25cm'/ + + ok=.true. + if(id2(1).lt.1 .or. id2(1).gt.NBANDS) ok=.false. + if(id2(2).lt.1 .or. id2(2).gt.NMODES) ok=.false. + if(id2(3).lt.1 .or. id2(3).gt.8) ok=.false. + if(id2(4).lt.1 .or. id2(4).gt.7) ok=.false. + + if(ok) then + band=bands(id2(1)) + mode=modes(id2(2)) + nsubmode=id2(3) + ntrperiod=iperiod(id2(4)) + endif + + return + end subroutine get_wsjtx_wav_params + end module wavhdr diff --git a/lib/wqdecode.f90 b/lib/wqdecode.f90 new file mode 100644 index 00000000..baa68cb1 --- /dev/null +++ b/lib/wqdecode.f90 @@ -0,0 +1,338 @@ +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +! File Name: wqdecode.f90 +! Description: +! +! Copyright (C) 2001-2014 Joseph Taylor, K1JT +! License: GPL-3 +! +! This program 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 of the License, or (at your option) any later +! version. +! +! This program 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 +! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +! Street, Fifth Floor, Boston, MA 02110-1301, USA. +! +!------------------------------------------------------------------------------- +subroutine wqdecode(data0,message,ntype) + + parameter (N15=32768) + integer*1 data0(11) + character*22 message + character*12 callsign + character*3 cdbm + character grid4*4,grid6*6 + logical first + character*12 dcall(0:N15-1) + data first/.true./ + save first,dcall + +! May want to have a timeout (say, one hour?) on calls fetched +! from the hash table. + + if(first) then + dcall=' ' + first=.false. + endif + + message=' ' + call unpack50(data0,n1,n2) +! print*,data0,n1,n2 + call unpackcall(n1,callsign) + i1=index(callsign,' ') + call unpackgrid(n2/128,grid4) + ntype=iand(n2,127) -64 + +! Standard WSPR message (types 0 3 7 10 13 17 ... 60) + if(ntype.ge.0 .and. ntype.le.62) then + nu=mod(ntype,10) + if(nu.eq.0 .or. nu.eq.3 .or. nu.eq.7) then + write(cdbm,'(i3)'),ntype + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + message=callsign(1:i1)//grid4//' '//cdbm + call hash(callsign,i1-1,ih) + dcall(ih)=callsign(:i1) + else + nadd=nu + if(nu.gt.3) nadd=nu-3 + if(nu.gt.7) nadd=nu-7 + ng=n2/128 + 32768*(nadd-1) + call unpackpfx(ng,callsign) + ndbm=ntype-nadd + write(cdbm,'(i3)'),ndbm + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + i2=index(callsign,' ') + message=callsign(:i2)//cdbm + call hash(callsign,i2-1,ih) + dcall(ih)=callsign(:i2) + endif + else if(ntype.lt.0) then + ndbm=-(ntype+1) + grid6=callsign(6:6)//callsign(1:5) + ih=(n2-ntype-64)/128 + callsign=dcall(ih) + write(cdbm,'(i3)'),ndbm + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + i2=index(callsign,' ') + if(dcall(ih)(1:1).ne.' ') then + message='<'//callsign(:i2-1)//'> '//grid6//' '//cdbm + else + message='<...> '//grid6//' '//cdbm + endif + endif + + return +end subroutine wqdecode + +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +! File Name: unpack50.f90 +! Description: +! +! Copyright (C) 2001-2014 Joseph Taylor, K1JT +! License: GPL-3 +! +! This program 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 of the License, or (at your option) any later +! version. +! +! This program 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 +! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +! Street, Fifth Floor, Boston, MA 02110-1301, USA. +! +!------------------------------------------------------------------------------- +subroutine unpack50(dat,n1,n2) + + integer*1 dat(11) + + i=dat(1) + i4=iand(i,255) + n1=ishft(i4,20) + i=dat(2) + i4=iand(i,255) + n1=n1 + ishft(i4,12) + i=dat(3) + i4=iand(i,255) + n1=n1 + ishft(i4,4) + i=dat(4) + i4=iand(i,255) + n1=n1 + iand(ishft(i4,-4),15) + n2=ishft(iand(i4,15),18) + i=dat(5) + i4=iand(i,255) + n2=n2 + ishft(i4,10) + i=dat(6) + i4=iand(i,255) + n2=n2 + ishft(i4,2) + i=dat(7) + i4=iand(i,255) + n2=n2 + iand(ishft(i4,-6),3) + + return +end subroutine unpack50 + +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +! File Name: unpackcall.f90 +! Description: +! +! Copyright (C) 2001-2014 Joseph Taylor, K1JT +! License: GPL-3 +! +! This program 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 of the License, or (at your option) any later +! version. +! +! This program 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 +! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +! Street, Fifth Floor, Boston, MA 02110-1301, USA. +! +!------------------------------------------------------------------------------- +subroutine unpackcall(ncall,word) + + character word*12,c*37 + + data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ '/ + + n=ncall + word='......' + if(n.ge.262177560) go to 999 !Plain text message ... + i=mod(n,27)+11 + word(6:6)=c(i:i) + n=n/27 + i=mod(n,27)+11 + word(5:5)=c(i:i) + n=n/27 + i=mod(n,27)+11 + word(4:4)=c(i:i) + n=n/27 + i=mod(n,10)+1 + word(3:3)=c(i:i) + n=n/10 + i=mod(n,36)+1 + word(2:2)=c(i:i) + n=n/36 + i=n+1 + word(1:1)=c(i:i) + do i=1,4 + if(word(i:i).ne.' ') go to 10 + enddo + go to 999 +10 word=word(i:) + +999 if(word(1:3).eq.'3D0') word='3DA0'//word(4:) + return +end subroutine unpackcall + +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +! File Name: unpackgrid.f90 +! Description: +! +! Copyright (C) 2001-2014 Joseph Taylor, K1JT +! License: GPL-3 +! +! This program 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 of the License, or (at your option) any later +! version. +! +! This program 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 +! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +! Street, Fifth Floor, Boston, MA 02110-1301, USA. +! +!------------------------------------------------------------------------------- +subroutine unpackgrid(ng,grid) + + parameter (NGBASE=180*180) + character grid*4,grid6*6,digit*10 + data digit/'0123456789'/ + + grid=' ' + if(ng.ge.32400) go to 10 + dlat=mod(ng,180)-90 + dlong=(ng/180)*2 - 180 + 2 + call deg2grid(dlong,dlat,grid6) + grid=grid6(1:4) !XXX explicitly truncate this -db + go to 100 + +10 n=ng-NGBASE-1 + if(n.ge.1 .and.n.le.30) then + grid(1:1)='-' + grid(2:2)=char(48+n/10) + grid(3:3)=char(48+mod(n,10)) + else if(n.ge.31 .and.n.le.60) then + n=n-30 + grid(1:2)='R-' + grid(3:3)=char(48+n/10) + grid(4:4)=char(48+mod(n,10)) + else if(n.eq.61) then + grid='RO' + else if(n.eq.62) then + grid='RRR' + else if(n.eq.63) then + grid='73' + endif + +100 return +end subroutine unpackgrid + +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +! File Name: unpackpfx.f90 +! Description: +! +! Copyright (C) 2001-2014 Joseph Taylor, K1JT +! License: GPL-3 +! +! This program 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 of the License, or (at your option) any later +! version. +! +! This program 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 +! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +! Street, Fifth Floor, Boston, MA 02110-1301, USA. +! +!------------------------------------------------------------------------------- +subroutine unpackpfx(ng,call1) + + character*12 call1 + character*3 pfx + + if(ng.lt.60000) then +! Add-on prefix of 1 to 3 characters + n=ng + do i=3,1,-1 + nc=mod(n,37) + if(nc.ge.0 .and. nc.le.9) then + pfx(i:i)=char(nc+48) + else if(nc.ge.10 .and. nc.le.35) then + pfx(i:i)=char(nc+55) + else + pfx(i:i)=' ' + endif + n=n/37 + enddo + call1=pfx//'/'//call1 + if(call1(1:1).eq.' ') call1=call1(2:) + if(call1(1:1).eq.' ') call1=call1(2:) + else +! Add-on suffix, one or teo characters + i1=index(call1,' ') + nc=ng-60000 + if(nc.ge.0 .and. nc.le.9) then + call1=call1(:i1-1)//'/'//char(nc+48) + else if(nc.ge.10 .and. nc.le.35) then + call1=call1(:i1-1)//'/'//char(nc+55) + else if(nc.ge.36 .and. nc.le.125) then + nc1=(nc-26)/10 + nc2=mod(nc-26,10) + call1=call1(:i1-1)//'/'//char(nc1+48)//char(nc2+48) + endif + endif + + return +end subroutine unpackpfx diff --git a/lib/wqencode.f90 b/lib/wqencode.f90 new file mode 100644 index 00000000..3ca87f31 --- /dev/null +++ b/lib/wqencode.f90 @@ -0,0 +1,66 @@ +subroutine wqencode(msg,ntype,data0) + +! Parse and encode a WSPR message. + + use packjt + parameter (MASK15=32767) + character*22 msg + character*12 call1,call2 + character grid4*4 + logical lbad1,lbad2 + integer*1 data0(11) + integer nu(0:9) + data nu/0,-1,1,0,-1,2,1,0,-1,1/ + +! Standard WSPR message (types 0 3 7 10 13 17 ... 60) + i1=index(msg,' ') + i2=index(msg,'/') + i3=index(msg,'<') + call1=msg(:i1-1) + if(i1.lt.3 .or. i1.gt.7 .or. i2.gt.0 .or. i3.gt.0) go to 10 + grid4=msg(i1+1:i1+4) + call packcall(call1,n1,lbad1) + call packgrid(grid4,ng,lbad2) + if(lbad1 .or. lbad2) go to 10 + ndbm=0 + read(msg(i1+5:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + n2=128*ng + (ndbm+64) + call pack50(n1,n2,data0) + ntype=ndbm + go to 900 + +10 if(i2.ge.2 .and. i3.lt.1) then + call packpfx(call1,n1,ng,nadd) + ndbm=0 + read(msg(i1+1:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + ntype=ndbm + 1 + nadd + n2=128*ng + ntype + 64 + call pack50(n1,n2,data0) + else if(i3.eq.1) then + i4=index(msg,'>') + call1=msg(2:i4-1) + call hash(call1,i4-2,ih) + i5=index(trim(msg(i1+1:)),' ') +! Convert grid to valid callsign format - first character moved to end + call2=msg(i1+2:i1+i5-1)//msg(i1+1:i1+1)//' ' + call packcall(call2,n1,lbad1) + ndbm=0 + read(msg(i1+i5+1:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + ntype=-(ndbm+1) + n2=128*ih + ntype + 64 + call pack50(n1,n2,data0) + endif + go to 900 + +900 continue + return +end subroutine wqencode diff --git a/lib/wsjt24.f90 b/lib/wsjt24.f90 deleted file mode 100644 index 574f1dd9..00000000 --- a/lib/wsjt24.f90 +++ /dev/null @@ -1,181 +0,0 @@ -subroutine wsjt24(dat,npts,cfile6,NClearAve,MinSigdB, & - DFTolerance,NFreeze,mode,mode4,Nseg,MouseDF,NAgain, & - idf,lumsg,lcum,nspecial,ndf,NSyncOK,ccfblue,ccfred,ndiag) - -! Orchestrates the process of decoding JT4 messages, using data that -! have been 2x downsampled. -! No message averaging and no deep search, at present. - - parameter (MAXAVE=120) - real dat(npts) !Raw data - real*4 ccfblue(-5:540) !CCF in time - real*4 ccfred(-224:224) !CCF in frequency - integer DFTolerance - logical first - logical lcum - character decoded*22,cfile6*6,special*5,cooo*3 - character*22 avemsg1,avemsg2,deepmsg - character*77 line,ave1,ave2 - character*1 csync,c1 - character*12 mycall - character*12 hiscall - character*6 hisgrid - character submode*1 - real*4 ccfbluesum(-5:540),ccfredsum(-224:224) - common/ave/ppsave(207,7,MAXAVE),nflag(MAXAVE),nsave,iseg(MAXAVE) - data first/.true./,ns10/0/,ns20/0/ - save - - if(first) then - nsave=0 - first=.false. - ave1=' ' - ave2=' ' - ccfblue=0. - ccfred=0. - if(nspecial.eq.999) go to 900 !Silence compiler warning - endif - - ndepth=3 !### - naggressive=0 - if(ndepth.ge.2) naggressive=1 - nq1=3 - nq2=6 - if(naggressive.eq.1) nq1=1 - - if(NClearAve.ne.0) then - nsave=0 !Clear the averaging accumulators - ns10=0 - ns20=0 - ave1=' ' - ave2=' ' - endif - if(MinSigdB.eq.99 .or. MinSigdB.eq.-99) then - ns10=0 !For Include/Exclude ? - ns20=0 - endif - -! Attempt to synchronize: look for sync pattern, get DF and DT. - call sync24(dat,npts,DFTolerance,NFreeze,MouseDF,mode, & - mode4,dtx,dfx,snrx,snrsync,ccfblue,ccfred,flip,width) - - csync=' ' - decoded=' ' - deepmsg=' ' - special=' ' - cooo=' ' - ncount=-1 !Flag for RS decode of current record - ncount1=-1 !Flag for RS Decode of ave1 - ncount2=-1 !Flag for RS Decode of ave2 - NSyncOK=0 - nqual1=0 - nqual2=0 - - if(nsave.lt.MAXAVE .and. (NAgain.eq.0 .or. NClearAve.eq.1)) nsave=nsave+1 - if(nsave.le.0) go to 900 !Prevent bounds error - - nflag(nsave)=0 !Clear the "good sync" flag - iseg(nsave)=Nseg !Set the RX segment to 1 or 2 - nsync=nint(snrsync-3.0) - nsnr=nint(snrx) - if(nsnr.lt.-30 .or. nsync.lt.0) nsync=0 - nsnrlim=-33 - if(nsync.lt.MinSigdB .or. nsnr.lt.nsnrlim) go to 200 - -! If we get here, we have achieved sync! - NSyncOK=1 - nflag(nsave)=1 !Mark this RX file as good - csync='*' - if(flip.lt.0.0) then - csync='#' - cooo='O ?' - endif - - call decode24(dat,npts,dtx,dfx,flip,mode,mode4,decoded, & - ncount,deepmsg,qual,submode) - -200 kvqual=0 - if(ncount.ge.0) kvqual=1 - nqual=qual - if(ndiag.eq.0 .and. nqual.gt.10) nqual=10 - if(nqual.ge.nq1 .and.kvqual.eq.0) decoded=deepmsg - - ndf=nint(dfx) - if(flip.lt.0.0 .and. (kvqual.eq.1 .or. nqual.ge.nq2)) cooo='OOO' - if(kvqual.eq.0.and.nqual.ge.nq1.and.nqual.lt.nq2) cooo(2:3)=' ?' - if(decoded.eq.' ') cooo=' ' - do i=1,22 - c1=decoded(i:i) - if(c1.ge.'a' .and. c1.le.'z') decoded(i:i)=char(ichar(c1)-32) - enddo - jdf=ndf+idf - -! call cs_lock('wsjt24') - write(line,1010) cfile6,nsync,nsnr,dtx-1.0,jdf,nint(width), & - csync,special,decoded(1:19),cooo,kvqual,nqual,submode -1010 format(a6,i3,i5,f5.1,i5,i3,1x,a1,1x,a5,a19,1x,a3,i3,i5,1x,a1) - -! Blank all end-of-line stuff if no decode - if(line(31:40).eq.' ') line=line(:30) - - if(lcum) write(21,1011) line - -! Write decoded msg unless this is an "Exclude" request: - if(MinSigdB.lt.99) write(*,1011) line -1011 format(a77) - - if(nsave.ge.1) call avemsg4(1,mode4,ndepth, & - avemsg1,nused1,nq1,nq2,neme,mycall,hiscall,hisgrid,qual1, & - ns1,ncount1) - if(nsave.ge.1) call avemsg4(2,mode4,ndepth, & - avemsg2,nused2,nq1,nq2,neme,mycall,hiscall,hisgrid,qual2, & - ns2,ncount2) - nqual1=qual1 - nqual2=qual2 - if(ndiag.eq.0 .and. nqual1.gt.10) nqual1=10 - if(ndiag.eq.0 .and. nqual2.gt.10) nqual2=10 - nc1=0 - nc2=0 - if(ncount1.ge.0) nc1=1 - if(ncount2.ge.0) nc2=1 - -! Write the average line - if(ns1.ge.1) then - if(ns1.lt.10) write(ave1,1021) cfile6,1,nused1,ns1,avemsg1,nc1,nqual1 -1021 format(a6,i3,i4,'/',i1,20x,a19,i7,i5) - if(ns1.ge.10 .and. nsave.le.99) write(ave1,1022) cfile6, & - 1,nused1,ns1,avemsg1,nc1,nqual1 -1022 format(a6,i3,i4,'/',i2,19x,a19,i7,i5) - if(ns1.ge.100) write(ave1,1023) cfile6,1,nused1,ns1, & - avemsg1,nc1,nqual1 -1023 format(a6,i3,i4,'/',i3,18x,a19,i7,i5) - if(lcum .and. (avemsg1.ne.' ')) & - write(21,1011) ave1 - ns10=ns1 - endif - -! If Monitor segment #2 is available, write that line also - if(ns2.ge.1) then - if(ns2.lt.10) write(ave2,1021) cfile6,2,nused2,ns2,avemsg2,nc2,nqual2 - if(ns2.ge.10 .and. nsave.le.99) write(ave2,1022) cfile6, & - 2,nused2,ns2,avemsg2,nc2,nqual2 - if(ns2.ge.100) write(ave2,1023) cfile6,2,nused2,ns2,avemsg2,nc2,nqual2 - if(lcum .and. (avemsg2.ne.' ')) & - write(21,1011) ave2 - ns20=ns2 - endif - - if(ave1(31:40).eq.' ') ave1=ave1(:30) - if(ave2(31:40).eq.' ') ave2=ave2(:30) - write(12,1011) ave1 - write(12,1011) ave2 - call flush(12) -! call cs_unlock - -900 continue - - ccfbluesum=ccfbluesum + ccfblue - ccfredsum=ccfredsum + ccfred - - return -end subroutine wsjt24 diff --git a/lib/wsjt24d.f90 b/lib/wsjt24d.f90 deleted file mode 100644 index 005e809f..00000000 --- a/lib/wsjt24d.f90 +++ /dev/null @@ -1,43 +0,0 @@ -program wsjt24d - - real*4 dat(60*11025/2) - character*6 cfile6 - character*12 arg - real ccfblue(-5:540) !X-cor function in JT65 mode (blue line) - real ccfred(450) !Average spectrum of the whole file - integer dftolerance - - nargs=iargc() - if(nargs.ne.2) then - print*,'Usage: wspr24d ifile1 ifile2' - go to 999 - endif - call getarg(1,arg) - read(arg,*) ifile1 - call getarg(2,arg) - read(arg,*) ifile2 - - open(23,file='CALL3.TXT',status='old') - open(50,file='vk7mo.dat',form='unformatted',status='old') - - do ifile=1,ifile2 - read(50,end=999) jz,cfile6,NClearAve,MinSigdB,DFTolerance,NFreeze, & - mode,mode4,Nseg,MouseDF2,NAgain,idf,lumsg,lcum,nspecial,ndf, & - NSyncOK,dat(1:jz) - if(ifile.lt.ifile1) cycle - -! write(*,3000) ifile,cfile6,jz,mode,mode4,idf -!3000 format(i3,2x,a6,i10,3i5) - - dftolerance=100 - nfreeze=1 - neme=0 - -! call wsjt24(dat(4097),jz-4096,cfile6,NClearAve,MinSigdB,DFTolerance, & - call wsjt24(dat,jz,cfile6,NClearAve,MinSigdB,DFTolerance, & - NFreeze,mode,mode4,Nseg,MouseDF2,NAgain,idf,lumsg,lcum,nspecial, & - ndf,NSyncOK,ccfblue,ccfred,ndiag) - if(ifile.ge.ifile2) exit - enddo - -999 end program wsjt24d diff --git a/lib/wsjt_modes.txt b/lib/wsjt_modes.txt new file mode 100644 index 00000000..8e1a98e3 --- /dev/null +++ b/lib/wsjt_modes.txt @@ -0,0 +1,68 @@ + WSJT modes: Modulation Parameters + --------------------------------- + +------------------------------------------------------------------------ +Mode nsps Rate B t_sym t_msg Suggested + (baud) (Hz) (ms) (s) applications +------------------------------------------------------------------------ +Fast modes, sample Rate 11025 Hz: +------------------------------------------------------------------------ +JTMS 8 689 1378 0.7 0.097 MS on 144+ + +FSK441 25 441 1764 2.3 0.129 MS + +ISCAT-A 512 21.5 905 46.4 1.11 Aircraft Scatter +ISCAT-B 256 43.1 1809 23.2 0.56 Ionoscatter (6m) + +JT6M 512 21.5 947 46.4 1.32 Ionoscatter (6m) + +Slow modes, sample Rate 11025 Hz: +------------------------------------------------------------------------ +JT65A 4096 2.69 178 372 46.81 EME 50 MHz +JT65B 4096 2.69 355 372 46.81 EME 144, 432 +JT65C 4096 2.69 711 372 46.81 EME 1296-and-up + +JT4A 2520 4.375 17.5 229 47.09 QRP HF dxing +JT4B 2520 4.375 35 229 47.09 +JT4C 2520 4.375 70 229 47.09 +JT4D 2520 4.375 158 229 47.09 +JT4E 2520 4.375 315 229 47.09 +JT4F 2520 4.375 630 229 47.09 Microwave EME +JT4G 2520 4.375 1260 229 47.09 Microwave EME + +------------------------------------------------------------------------ +Mode nsps Rate B t_sym t_msg Suggested + (baud) (Hz) (ms) (s) applications +------------------------------------------------------------------------ +Slow modes, sample Rate 12000 Hz: +------------------------------------------------------------------------ +JT9A 6912 1.736 15.625 576 48.96 QRP HF dxing +JT9B 6912 1.736 28.125 576 48.96 +JT9C 6912 1.736 56.25 576 48.96 +JT9D 6912 1.736 112.5 576 48.96 +JT9E 6912 1.736 225 576 48.96 +JT9F 6912 1.736 450 576 48.96 +JT9G 6912 1.736 900 576 48.96 Microwave EME? +JT9H 6912 1.736 1800 576 48.96 Microwave EME? + +WSPR 8192 1.465 5.86 683 110.59 Propagation probe + +------------------------------------------------------------------------ +Fast modes, sample Rate 12000 Hz: +------------------------------------------------------------------------ +JT9B 3840 3.125 28.125 320 27.20 Not yet... +JT9C 1920 6.25 56.25 160 13.60 Not yet... +JT9D 960 12.5 112.5 80 6.80 Ionoscatter +JT9E 480 25 225 40 3.40 Ionoscatter +JT9F 240 50 450 20 1.70 Ionoscatter +JT9G 120 100 900 10 0.85 Ionoscatter +JT9H 60 200 1800 5 0.43 Ionoscat (no 10m) + +JTMSK 6 2000 2000 0.5 0.117 MS +------------------------------------------------------------------------ + +nsps - Samples per symbol, at stated sample rate +Rate - Keying rate (baud) +B - Bandwidth (Hz) +t_sym - Symbol duration (ms) +t_msg - Time (s) to transmit typical 18-character message diff --git a/lib/wspr_downsample.f90 b/lib/wspr_downsample.f90 new file mode 100644 index 00000000..22cc4788 --- /dev/null +++ b/lib/wspr_downsample.f90 @@ -0,0 +1,76 @@ +subroutine wspr_downsample(id2,k) + +! Input: +! id2 raw 16-bit integer data, 12000 Hz sample rate +! k pointer to the most recent new data + +! Output (in common/c0com) +! c0 complex data downsampled to 1500 Hz + + parameter (NMAX=120*12000) !Total sample intervals per 30 minutes + parameter (NDMAX=120*1500) !Sample intervals at 1500 Hz rate + parameter (NSMAX=1366) !Max length of saved spectra + parameter (NFFT1=1024) + parameter (MAXFFT3=32768) + real*4 w3(MAXFFT3) + real*4 x0(NFFT1) + real*4 x2(NFFT1+105) + real*4 ssum(NSMAX) + integer*2 id2(NMAX) + complex c0 + common/c0com/c0(NDMAX) + data rms/999.0/,k0/99999999/,nfft3z/0/,nsps/8192/,nbfo/1500/ + save + + nfft3=nsps/4 + jstep=nsps/16 + if(k.gt.NMAX) go to 999 + if(k.lt.nfft3) go to 999 !Wait for enough samples to start + if(nfft3.ne.nfft3z) then + pi=4.0*atan(1.0) + do i=1,nfft3 + w3(i)=2.0*(sin(i*pi/nfft3))**2 !Window for nfft3 + enddo + nfft3z=nfft3 + endif + + if(k.lt.k0) then + ja=0 + ssum=0. + k1=0 + k8=0 + x2=0. +! if(ndiskdat.eq.0) then +! id2(k+1:)=0 +! c0=0. !This is necessary to prevent "ghosts". Not sure why. +! endif + endif + k0=k + + nzap=0 + nbslider=0 + sigmas=1.0*(10.0**(0.01*nbslider)) + 0.7 + peaklimit=sigmas*max(10.0,rms) + px=0. + + nwindow=2 + kstep1=NFFT1 + if(nwindow.ne.0) kstep1=NFFT1/2 + fac=2.0/NFFT1 + nblks=(k-k1)/kstep1 + gain=1.0 + nb=0 + do nblk=1,nblks + do i=1,NFFT1 + x0(i)=gain*id2(k1+i) + enddo +! call timf2(x0,k,NFFT1,nwindow,nb,peaklimit,x1, & +! slimit,lstrong,px,nzap) +! Mix at nbfo Hz, lowpass at +/-750 Hz, and downsample to 1500 Hz complex. + call mixlpf(x0,nbfo,c0(k8+1)) + k1=k1+kstep1 + k8=k8+kstep1/8 + enddo + +999 return +end subroutine wspr_downsample diff --git a/lib/wsprcode/go.sh b/lib/wsprcode/go.sh new file mode 100644 index 00000000..dfce99ea --- /dev/null +++ b/lib/wsprcode/go.sh @@ -0,0 +1 @@ + gfortran -o wsprcode -fbounds-check wsprcode.f90 nhash.c diff --git a/lib/wsprcode/nhash.c b/lib/wsprcode/nhash.c new file mode 100644 index 00000000..675022b4 --- /dev/null +++ b/lib/wsprcode/nhash.c @@ -0,0 +1,384 @@ +/* + *------------------------------------------------------------------------------- + * + * This file is part of the WSPR application, Weak Signal Propagation Reporter + * + * File Name: nhash.c + * Description: Functions to produce 32-bit hashes for hash table lookup + * + * Copyright (C) 2008-2014 Joseph Taylor, K1JT + * License: GPL-3 + * + * This program 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 of the License, or (at your option) any later + * version. + * + * This program 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 + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Files: lookup3.c + * Copyright: Copyright (C) 2006 Bob Jenkins + * License: public-domain + * You may use this code any way you wish, private, educational, or commercial. + * It's free. + * + *------------------------------------------------------------------------------- +*/ + +/* +These are functions for producing 32-bit hashes for hash table lookup. +hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() +are externally useful functions. Routines to test the hash are included +if SELF_TEST is defined. You can use this free for any purpose. It's in +the public domain. It has no warranty. + +You probably want to use hashlittle(). hashlittle() and hashbig() +hash byte arrays. hashlittle() is is faster than hashbig() on +little-endian machines. Intel and AMD are little-endian machines. +On second thought, you probably want hashlittle2(), which is identical to +hashlittle() except it returns two 32-bit hashes for the price of one. +You could implement hashbig2() if you wanted but I haven't bothered here. + +If you want to find a hash of, say, exactly 7 integers, do + a = i1; b = i2; c = i3; + mix(a,b,c); + a += i4; b += i5; c += i6; + mix(a,b,c); + a += i7; + final(a,b,c); +then use c as the hash value. If you have a variable length array of +4-byte integers to hash, use hashword(). If you have a byte array (like +a character string), use hashlittle(). If you have several byte arrays, or +a mix of things, see the comments above hashlittle(). + +Why is this so big? I read 12 bytes at a time into 3 4-byte integers, +then mix those integers. This is fast (you can do a lot more thorough +mixing with 12*3 instructions on 3 integers than you can with 3 instructions +on 1 byte), but shoehorning those bytes into integers efficiently is messy. +*/ + +#define SELF_TEST 1 + +#include /* defines printf for tests */ +#include /* defines time_t for timings in the test */ +#ifdef Win32 +#include "win_stdint.h" /* defines uint32_t etc */ +#else +#include /* defines uint32_t etc */ +#endif +//#include /* attempt to define endianness */ +//#ifdef linux +//# include /* attempt to define endianness */ +//#endif + +#define HASH_LITTLE_ENDIAN 1 + +#define hashsize(n) ((uint32_t)1<<(n)) +#define hashmask(n) (hashsize(n)-1) +#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) + +/* +------------------------------------------------------------------------------- +mix -- mix 3 32-bit values reversibly. + +This is reversible, so any information in (a,b,c) before mix() is +still in (a,b,c) after mix(). + +If four pairs of (a,b,c) inputs are run through mix(), or through +mix() in reverse, there are at least 32 bits of the output that +are sometimes the same for one pair and different for another pair. +This was tested for: +* pairs that differed by one bit, by two bits, in any combination + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). +* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. +* the base values were pseudorandom, all zero but one bit set, or + all zero plus a counter that starts at zero. + +Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that +satisfy this are + 4 6 8 16 19 4 + 9 15 3 18 27 15 + 14 9 3 7 17 3 +Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing +for "differ" defined as + with a one-bit base and a two-bit delta. I +used http://burtleburtle.net/bob/hash/avalanche.html to choose +the operations, constants, and arrangements of the variables. + +This does not achieve avalanche. There are input bits of (a,b,c) +that fail to affect some output bits of (a,b,c), especially of a. The +most thoroughly mixed value is c, but it doesn't really even achieve +avalanche in c. + +This allows some parallelism. Read-after-writes are good at doubling +the number of bits affected, so the goal of mixing pulls in the opposite +direction as the goal of parallelism. I did what I could. Rotates +seem to cost as much as shifts on every machine I could lay my hands +on, and rotates are much kinder to the top and bottom bits, so I used +rotates. +------------------------------------------------------------------------------- +*/ +#define mix(a,b,c) \ +{ \ + a -= c; a ^= rot(c, 4); c += b; \ + b -= a; b ^= rot(a, 6); a += c; \ + c -= b; c ^= rot(b, 8); b += a; \ + a -= c; a ^= rot(c,16); c += b; \ + b -= a; b ^= rot(a,19); a += c; \ + c -= b; c ^= rot(b, 4); b += a; \ +} + +/* +------------------------------------------------------------------------------- +final -- final mixing of 3 32-bit values (a,b,c) into c + +Pairs of (a,b,c) values differing in only a few bits will usually +produce values of c that look totally different. This was tested for +* pairs that differed by one bit, by two bits, in any combination + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). +* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. +* the base values were pseudorandom, all zero but one bit set, or + all zero plus a counter that starts at zero. + +These constants passed: + 14 11 25 16 4 14 24 + 12 14 25 16 4 14 24 +and these came close: + 4 8 15 26 3 22 24 + 10 8 15 26 3 22 24 + 11 8 15 26 3 22 24 +------------------------------------------------------------------------------- +*/ +#define final(a,b,c) \ +{ \ + c ^= b; c -= rot(b,14); \ + a ^= c; a -= rot(c,11); \ + b ^= a; b -= rot(a,25); \ + c ^= b; c -= rot(b,16); \ + a ^= c; a -= rot(c,4); \ + b ^= a; b -= rot(a,14); \ + c ^= b; c -= rot(b,24); \ +} + +/* +------------------------------------------------------------------------------- +hashlittle() -- hash a variable-length key into a 32-bit value + k : the key (the unaligned variable-length array of bytes) + length : the length of the key, counting by bytes + initval : can be any 4-byte value +Returns a 32-bit value. Every bit of the key affects every bit of +the return value. Two keys differing by one or two bits will have +totally different hash values. + +The best hash table sizes are powers of 2. There is no need to do +mod a prime (mod is sooo slow!). If you need less than 32 bits, +use a bitmask. For example, if you need only 10 bits, do + h = (h & hashmask(10)); +In which case, the hash table should have hashsize(10) elements. + +If you are hashing n strings (uint8_t **)k, do it like this: + for (i=0, h=0; i 12) + { + a += k[0]; + b += k[1]; + c += k[2]; + mix(a,b,c); + length -= 12; + k += 3; + } + + /*----------------------------- handle the last (probably partial) block */ + /* + * "k[2]&0xffffff" actually reads beyond the end of the string, but + * then masks off the part it's not allowed to read. Because the + * string is aligned, the masked-off tail is in the same word as the + * rest of the string. Every machine with memory protection I've seen + * does it on word boundaries, so is OK with this. But VALGRIND will + * still catch it and complain. The masking trick does make the hash + * noticably faster for short strings (like English words). + */ +#ifndef VALGRIND + + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; + case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; + case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=k[1]&0xffffff; a+=k[0]; break; + case 6 : b+=k[1]&0xffff; a+=k[0]; break; + case 5 : b+=k[1]&0xff; a+=k[0]; break; + case 4 : a+=k[0]; break; + case 3 : a+=k[0]&0xffffff; break; + case 2 : a+=k[0]&0xffff; break; + case 1 : a+=k[0]&0xff; break; + case 0 : return c; /* zero length strings require no mixing */ + } + +#else /* make valgrind happy */ + + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]; break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ + case 1 : a+=k8[0]; break; + case 0 : return c; + } + +#endif /* !valgrind */ + + } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { + const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ + const uint8_t *k8; + + /*--------------- all but last block: aligned reads and different mixing */ + while (length > 12) + { + a += k[0] + (((uint32_t)k[1])<<16); + b += k[2] + (((uint32_t)k[3])<<16); + c += k[4] + (((uint32_t)k[5])<<16); + mix(a,b,c); + length -= 12; + k += 6; + } + + /*----------------------------- handle the last (probably partial) block */ + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[4]+(((uint32_t)k[5])<<16); + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=k[4]; + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=k[2]; + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=k[0]; + break; + case 1 : a+=k8[0]; + break; + case 0 : return c; /* zero length requires no mixing */ + } + + } else { /* need to read the key one byte at a time */ + const uint8_t *k = (const uint8_t *)key; + + /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + a += ((uint32_t)k[1])<<8; + a += ((uint32_t)k[2])<<16; + a += ((uint32_t)k[3])<<24; + b += k[4]; + b += ((uint32_t)k[5])<<8; + b += ((uint32_t)k[6])<<16; + b += ((uint32_t)k[7])<<24; + c += k[8]; + c += ((uint32_t)k[9])<<8; + c += ((uint32_t)k[10])<<16; + c += ((uint32_t)k[11])<<24; + mix(a,b,c); + length -= 12; + k += 12; + } + + /*-------------------------------- last block: affect all 32 bits of (c) */ + switch(length) /* all the case statements fall through */ + { + case 12: c+=((uint32_t)k[11])<<24; + case 11: c+=((uint32_t)k[10])<<16; + case 10: c+=((uint32_t)k[9])<<8; + case 9 : c+=k[8]; + case 8 : b+=((uint32_t)k[7])<<24; + case 7 : b+=((uint32_t)k[6])<<16; + case 6 : b+=((uint32_t)k[5])<<8; + case 5 : b+=k[4]; + case 4 : a+=((uint32_t)k[3])<<24; + case 3 : a+=((uint32_t)k[2])<<16; + case 2 : a+=((uint32_t)k[1])<<8; + case 1 : a+=k[0]; + break; + case 0 : return c; + } + } + + final(a,b,c); + return c; +} + +//uint32_t __stdcall NHASH(const void *key, size_t length, uint32_t initval) diff --git a/lib/wsprcode/wspr_old_subs.f90 b/lib/wsprcode/wspr_old_subs.f90 new file mode 100644 index 00000000..b1bbb7e1 --- /dev/null +++ b/lib/wsprcode/wspr_old_subs.f90 @@ -0,0 +1,937 @@ +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +! File Name: wspr_old_subs.f90 +! Description: Utility subroutines from WSPR 2.0 +! +! Copyright (C) 2001-2014 Joseph Taylor, K1JT +! License: GPL-3 +! +! This program 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 of the License, or (at your option) any later +! version. +! +! This program 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 +! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +! Street, Fifth Floor, Boston, MA 02110-1301, USA. +! +!------------------------------------------------------------------------------- + +subroutine deg2grid(dlong0,dlat,grid) + + real dlong !West longitude (deg) + real dlat !Latitude (deg) + character grid*6 + + dlong=dlong0 + if(dlong.lt.-180.0) dlong=dlong+360.0 + if(dlong.gt.180.0) dlong=dlong-360.0 + +! Convert to units of 5 min of longitude, working east from 180 deg. + nlong=60.0*(180.0-dlong)/5.0 + n1=nlong/240 !20-degree field + n2=(nlong-240*n1)/24 !2 degree square + n3=nlong-240*n1-24*n2 !5 minute subsquare + grid(1:1)=char(ichar('A')+n1) + grid(3:3)=char(ichar('0')+n2) + grid(5:5)=char(ichar('a')+n3) + +! Convert to units of 2.5 min of latitude, working north from -90 deg. + nlat=60.0*(dlat+90)/2.5 + n1=nlat/240 !10-degree field + n2=(nlat-240*n1)/24 !1 degree square + n3=nlat-240*n1-24*n2 !2.5 minuts subsquare + grid(2:2)=char(ichar('A')+n1) + grid(4:4)=char(ichar('0')+n2) + grid(6:6)=char(ichar('a')+n3) + + return +end subroutine deg2grid + +subroutine encode232(dat,nbytes,symbol,maxsym) + +! Convolutional encoder for a K=32, r=1/2 code. + + integer*1 dat(nbytes) !User data, packed 8 bits per byte + integer*1 symbol(maxsym) !Channel symbols, one bit per byte + integer*1 i1 + +! Layland-Lushbaugh polynomials for a K=32, r=1/2 convolutional code, +! and 8-bit parity lookup table. + + data npoly1/-221228207/,npoly2/-463389625/ + integer*1 partab(0:255) + data partab/ & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0/ + + nstate=0 + k=0 + do j=1,nbytes + do i=7,0,-1 + i1=dat(j) + i4=i1 + if (i4.lt.0) i4=i4+256 + nstate=ior(ishft(nstate,1),iand(ishft(i4,-i),1)) + n=iand(nstate,npoly1) + n=ieor(n,ishft(n,-16)) + k=k+1 + symbol(k)=partab(iand(ieor(n,ishft(n,-8)),255)) + n=iand(nstate,npoly2) + n=ieor(n,ishft(n,-16)) + k=k+1 + symbol(k)=partab(iand(ieor(n,ishft(n,-8)),255)) + enddo + enddo + + return +end subroutine encode232 + +subroutine fano232(symbol,nbits,mettab,ndelta,maxcycles,dat,ncycles,metric,ierr) + +! Sequential decoder for K=32, r=1/2 convolutional code using +! the Fano algorithm. Translated from C routine for same purpose +! written by Phil Karn, KA9Q. + + parameter (MAXBITS=103) + parameter (MAXDAT=(MAXBITS+7)/8) + integer*1 symbol(0:2*MAXBITS-1) + integer*1 dat(MAXDAT) !Decoded user data, 8 bits per byte + integer mettab(0:255,0:1) !Metric table + +! These were the "node" structure in Karn's C code: + integer nstate(0:MAXBITS-1) !Encoder state of next node + integer gamma(0:MAXBITS-1) !Cumulative metric to this node + integer metrics(0:3,0:MAXBITS-1) !Metrics indexed by all possible Tx syms + integer tm(0:1,0:MAXBITS-1) !Sorted metrics for current hypotheses + integer ii(0:MAXBITS-1) !Current branch being tested + + logical noback + +! Layland-Lushbaugh polynomials for a K=32, r=1/2 convolutional code, +! and 8-bit parity lookup table. + + data npoly1/-221228207/,npoly2/-463389625/ + integer*1 partab(0:255) + data partab/ & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 0, 1, 1, 0, 1, 0, 0, 1, & + 1, 0, 0, 1, 0, 1, 1, 0/ + + ntail=nbits-31 + +! Compute all possible branch metrics for each symbol pair. +! This is the only place we actually look at the raw input symbols + i4a=0 + i4b=0 + do np=0,nbits-1 + j=2*np + i4a=symbol(j) + i4b=symbol(j+1) + if (i4a.lt.0) i4a=i4a+256 + if (i4b.lt.0) i4b=i4b+256 + metrics(0,np) = mettab(i4a,0) + mettab(i4b,0) + metrics(1,np) = mettab(i4a,0) + mettab(i4b,1) + metrics(2,np) = mettab(i4a,1) + mettab(i4b,0) + metrics(3,np) = mettab(i4a,1) + mettab(i4b,1) + enddo + + np=0 + nstate(np)=0 + +! Compute and sort branch metrics from the root node + n=iand(nstate(np),npoly1) + n=ieor(n,ishft(n,-16)) + lsym=partab(iand(ieor(n,ishft(n,-8)),255)) + n=iand(nstate(np),npoly2) + n=ieor(n,ishft(n,-16)) + lsym=lsym+lsym+partab(iand(ieor(n,ishft(n,-8)),255)) + m0=metrics(lsym,np) + m1=metrics(ieor(3,lsym),np) + if(m0.gt.m1) then + tm(0,np)=m0 !0-branch has better metric + tm(1,np)=m1 + else + tm(0,np)=m1 !1-branch is better + tm(1,np)=m0 + nstate(np)=nstate(np) + 1 !Set low bit + endif + +! Start with best branch + ii(np)=0 + gamma(np)=0 + nt=0 + +! Start the Fano decoder + do i=1,nbits*maxcycles +! Look forward + ngamma=gamma(np) + tm(ii(np),np) + if(ngamma.ge.nt) then + +! Node is acceptable. If first time visiting this node, tighten threshold: + if(gamma(np).lt.(nt+ndelta)) nt=nt + & + ndelta * ((ngamma-nt)/ndelta) + +! Move forward + gamma(np+1)=ngamma + nstate(np+1)=ishft(nstate(np),1) + np=np+1 + if(np.eq.nbits-1) go to 100 !We're done! + + n=iand(nstate(np),npoly1) + n=ieor(n,ishft(n,-16)) + lsym=partab(iand(ieor(n,ishft(n,-8)),255)) + n=iand(nstate(np),npoly2) + n=ieor(n,ishft(n,-16)) + lsym=lsym+lsym+partab(iand(ieor(n,ishft(n,-8)),255)) + + if(np.ge.ntail) then + tm(0,np)=metrics(lsym,np) !We're in the tail, all zeros + else + m0=metrics(lsym,np) + m1=metrics(ieor(3,lsym),np) + if(m0.gt.m1) then + tm(0,np)=m0 !0-branch has better metric + tm(1,np)=m1 + else + tm(0,np)=m1 !1-branch is better + tm(1,np)=m0 + nstate(np)=nstate(np) + 1 !Set low bit + endif + endif + + ii(np)=0 !Start with best branch + go to 99 + endif + +! Threshold violated, can't go forward +10 noback=.false. + if(np.eq.0) noback=.true. + if(np.gt.0) then + if(gamma(np-1).lt.nt) noback=.true. + endif + + if(noback) then +! Can't back up, either. Relax threshold and look forward again +! to a better branch. + nt=nt-ndelta + if(ii(np).ne.0) then + ii(np)=0 + nstate(np)=ieor(nstate(np),1) + endif + go to 99 + endif + +! Back up + np=np-1 + if(np.lt.ntail .and. ii(np).ne.1) then +! Search the next best branch + ii(np)=ii(np)+1 + nstate(np)=ieor(nstate(np),1) + go to 99 + endif + go to 10 +99 continue + enddo + i=nbits*maxcycles + +100 metric=gamma(np) !Final path metric + +! Copy decoded data to user's buffer + nbytes=(nbits+7)/8 + np=7 + do j=1,nbytes-1 + i4a=nstate(np) + dat(j)=i4a + np=np+8 + enddo + dat(nbytes)=0 + + ncycles=i+1 + ierr=0 + if(i.ge.maxcycles*nbits) ierr=-1 + + return +end subroutine fano232 + +subroutine grid2deg(grid0,dlong,dlat) + +! Converts Maidenhead grid locator to degrees of West longitude +! and North latitude. + + character*6 grid0,grid + character*1 g1,g2,g3,g4,g5,g6 + + grid=grid0 + i=ichar(grid(5:5)) + if(grid(5:5).eq.' ' .or. i.le.64 .or. i.ge.128) grid(5:6)='mm' + + if(grid(1:1).ge.'a' .and. grid(1:1).le.'z') grid(1:1)= & + char(ichar(grid(1:1))+ichar('A')-ichar('a')) + if(grid(2:2).ge.'a' .and. grid(2:2).le.'z') grid(2:2)= & + char(ichar(grid(2:2))+ichar('A')-ichar('a')) + if(grid(5:5).ge.'A' .and. grid(5:5).le.'Z') grid(5:5)= & + char(ichar(grid(5:5))-ichar('A')+ichar('a')) + if(grid(6:6).ge.'A' .and. grid(6:6).le.'Z') grid(6:6)= & + char(ichar(grid(6:6))-ichar('A')+ichar('a')) + + g1=grid(1:1) + g2=grid(2:2) + g3=grid(3:3) + g4=grid(4:4) + g5=grid(5:5) + g6=grid(6:6) + + nlong = 180 - 20*(ichar(g1)-ichar('A')) + n20d = 2*(ichar(g3)-ichar('0')) + xminlong = 5*(ichar(g5)-ichar('a')+0.5) + dlong = nlong - n20d - xminlong/60.0 + nlat = -90+10*(ichar(g2)-ichar('A')) + ichar(g4)-ichar('0') + xminlat = 2.5*(ichar(g6)-ichar('a')+0.5) + dlat = nlat + xminlat/60.0 + + return +end subroutine grid2deg + +subroutine hash(string,len,ihash) + + parameter (MASK15=32767) + character*(*) string + integer*1 ic(12) + + do i=1,len + ic(i)=ichar(string(i:i)) + enddo + i=nhash(ic,len,146) + ihash=iand(i,MASK15) + +! print*,'C',ihash,len,string + return +end subroutine hash + +subroutine inter_mept(id,ndir) + +! Interleave (ndir=1) or de-interleave (ndir=-1) the array id. + + integer*1 id(0:161),itmp(0:161) + integer j0(0:161) + logical first + data first/.true./ + save + + if(first) then +! Compute the interleave table using bit reversal. + k=-1 + do i=0,255 + n=0 + ii=i + do j=0,7 + n=n+n + if(iand(ii,1).ne.0) n=n+1 + ii=ii/2 + enddo + if(n.le.161) then + k=k+1 + j0(k)=n + endif + enddo + first=.false. + endif + + if(ndir.eq.1) then + do i=0,161 + itmp(j0(i))=id(i) + enddo + else + do i=0,161 + itmp(i)=id(j0(i)) + enddo + endif + + do i=0,161 + id(i)=itmp(i) + enddo + + return +end subroutine inter_mept + +function nchar(c) + +! Convert ASCII number, letter, or space to 0-36 for callsign packing. + + character c*1 + data n/0/ !Silence compiler warning + + if(c.ge.'0' .and. c.le.'9') then + n=ichar(c)-ichar('0') + else if(c.ge.'A' .and. c.le.'Z') then + n=ichar(c)-ichar('A') + 10 + else if(c.ge.'a' .and. c.le.'z') then + n=ichar(c)-ichar('a') + 10 + else if(c.ge.' ') then + n=36 + else + Print*,'Invalid character in callsign ',c,' ',ichar(c) + stop + endif + nchar=n + + return +end function nchar + +subroutine pack50(n1,n2,dat) + + integer*1 dat(11),i1 + + i1=iand(ishft(n1,-20),255) !8 bits + dat(1)=i1 + i1=iand(ishft(n1,-12),255) !8 bits + dat(2)=i1 + i1=iand(ishft(n1, -4),255) !8 bits + dat(3)=i1 + i1=16*iand(n1,15)+iand(ishft(n2,-18),15) !4+4 bits + dat(4)=i1 + i1=iand(ishft(n2,-10),255) !8 bits + dat(5)=i1 + i1=iand(ishft(n2, -2),255) !8 bits + dat(6)=i1 + i1=64*iand(n2,3) !2 bits + dat(7)=i1 + dat(8)=0 + dat(9)=0 + dat(10)=0 + dat(11)=0 + + return +end subroutine pack50 + +subroutine packcall(callsign,ncall,text) + +! Pack a valid callsign into a 28-bit integer. + + parameter (NBASE=37*36*10*27*27*27) + character callsign*6,c*1,tmp*6,digit*10 + logical text + data digit/'0123456789'/ + + text=.false. + +! Work-around for Swaziland prefix: + if(callsign(1:4).eq.'3DA0') callsign='3D0'//callsign(5:6) + + if(callsign(1:3).eq.'CQ ') then + ncall=NBASE + 1 + if(callsign(4:4).ge.'0' .and. callsign(4:4).le.'9' .and. & + callsign(5:5).ge.'0' .and. callsign(5:5).le.'9' .and. & + callsign(6:6).ge.'0' .and. callsign(6:6).le.'9') then + nfreq=100*(ichar(callsign(4:4))-48) + & + 10*(ichar(callsign(5:5))-48) + & + ichar(callsign(6:6))-48 + ncall=NBASE + 3 + nfreq + endif + return + else if(callsign(1:4).eq.'QRZ ') then + ncall=NBASE + 2 + return + endif + + tmp=' ' + if(callsign(3:3).ge.'0' .and. callsign(3:3).le.'9') then + tmp=callsign + else if(callsign(2:2).ge.'0' .and. callsign(2:2).le.'9') then + if(callsign(6:6).ne.' ') then + text=.true. + return + endif + tmp=' '//callsign + else + text=.true. + return + endif + + do i=1,6 + c=tmp(i:i) + if(c.ge.'a' .and. c.le.'z') & + tmp(i:i)=char(ichar(c)-ichar('a')+ichar('A')) + enddo + + n1=0 + if((tmp(1:1).ge.'A'.and.tmp(1:1).le.'Z').or.tmp(1:1).eq.' ') n1=1 + if(tmp(1:1).ge.'0' .and. tmp(1:1).le.'9') n1=1 + n2=0 + if(tmp(2:2).ge.'A' .and. tmp(2:2).le.'Z') n2=1 + if(tmp(2:2).ge.'0' .and. tmp(2:2).le.'9') n2=1 + n3=0 + if(tmp(3:3).ge.'0' .and. tmp(3:3).le.'9') n3=1 + n4=0 + if((tmp(4:4).ge.'A'.and.tmp(4:4).le.'Z').or.tmp(4:4).eq.' ') n4=1 + n5=0 + if((tmp(5:5).ge.'A'.and.tmp(5:5).le.'Z').or.tmp(5:5).eq.' ') n5=1 + n6=0 + if((tmp(6:6).ge.'A'.and.tmp(6:6).le.'Z').or.tmp(6:6).eq.' ') n6=1 + + if(n1+n2+n3+n4+n5+n6 .ne. 6) then + text=.true. + return + endif + + ncall=nchar(tmp(1:1)) + ncall=36*ncall+nchar(tmp(2:2)) + ncall=10*ncall+nchar(tmp(3:3)) + ncall=27*ncall+nchar(tmp(4:4))-10 + ncall=27*ncall+nchar(tmp(5:5))-10 + ncall=27*ncall+nchar(tmp(6:6))-10 + + return +end subroutine packcall + +subroutine packgrid(grid,ng,text) + + parameter (NGBASE=180*180) + character*4 grid + logical text + + text=.false. + if(grid.eq.' ') go to 90 !Blank grid is OK + +! Test for numerical signal report, etc. + if(grid(1:1).eq.'-') then + n=10*(ichar(grid(2:2))-48) + ichar(grid(3:3)) - 48 + ng=NGBASE+1+n + go to 100 + else if(grid(1:2).eq.'R-') then + n=10*(ichar(grid(3:3))-48) + ichar(grid(4:4)) - 48 + if(n.eq.0) go to 90 + ng=NGBASE+31+n + go to 100 + else if(grid(1:2).eq.'RO') then + ng=NGBASE+62 + go to 100 + else if(grid(1:3).eq.'RRR') then + ng=NGBASE+63 + go to 100 + else if(grid(1:2).eq.'73') then + ng=NGBASE+64 + go to 100 + endif + + if(grid(1:1).lt.'A' .or. grid(1:1).gt.'R') text=.true. + if(grid(2:2).lt.'A' .or. grid(2:2).gt.'R') text=.true. + if(grid(3:3).lt.'0' .or. grid(3:3).gt.'9') text=.true. + if(grid(4:4).lt.'0' .or. grid(4:4).gt.'9') text=.true. + if(text) go to 100 + + call grid2deg(grid//'mm',dlong,dlat) + long=dlong + lat=dlat+ 90.0 + ng=((long+180)/2)*180 + lat + go to 100 + +90 ng=NGBASE + 1 + +100 return +end subroutine packgrid + +subroutine packpfx(call1,n1,ng,nadd) + + character*12 call1,call0 + character*3 pfx + logical text + + i1=index(call1,'/') + if(call1(i1+2:i1+2).eq.' ') then +! Single-character add-on suffix (maybe also fourth suffix letter?) + call0=call1(:i1-1) + call packcall(call0,n1,text) + nadd=1 + nc=ichar(call1(i1+1:i1+1)) + if(nc.ge.48 .and. nc.le.57) then + n=nc-48 + else if(nc.ge.65 .and. nc.le.90) then + n=nc-65+10 + else + n=38 + endif + nadd=1 + ng=60000-32768+n + else if(call1(i1+3:i1+3).eq.' ') then +! Two-character numerical suffix, /10 to /99 + call0=call1(:i1-1) + call packcall(call0,n1,text) + nadd=1 + n=10*(ichar(call1(i1+1:i1+1))-48) + ichar(call1(i1+2:i1+2)) - 48 + nadd=1 + ng=60000 + 26 + n + else +! Prefix of 1 to 3 characters + pfx=call1(:i1-1) + if(pfx(3:3).eq.' ') pfx=' '//pfx + if(pfx(3:3).eq.' ') pfx=' '//pfx + call0=call1(i1+1:) + call packcall(call0,n1,text) + + ng=0 + do i=1,3 + nc=ichar(pfx(i:i)) + if(nc.ge.48 .and. nc.le.57) then + n=nc-48 + else if(nc.ge.65 .and. nc.le.90) then + n=nc-65+10 + else + n=36 + endif + ng=37*ng + n + enddo + nadd=0 + if(ng.ge.32768) then + ng=ng-32768 + nadd=1 + endif + endif + + return +end subroutine packpfx + +subroutine unpack50(dat,n1,n2) + + integer*1 dat(11) + + i=dat(1) + i4=iand(i,255) + n1=ishft(i4,20) + i=dat(2) + i4=iand(i,255) + n1=n1 + ishft(i4,12) + i=dat(3) + i4=iand(i,255) + n1=n1 + ishft(i4,4) + i=dat(4) + i4=iand(i,255) + n1=n1 + iand(ishft(i4,-4),15) + n2=ishft(iand(i4,15),18) + i=dat(5) + i4=iand(i,255) + n2=n2 + ishft(i4,10) + i=dat(6) + i4=iand(i,255) + n2=n2 + ishft(i4,2) + i=dat(7) + i4=iand(i,255) + n2=n2 + iand(ishft(i4,-6),3) + + return +end subroutine unpack50 + +subroutine unpackcall(ncall,word) + + character word*12,c*37 + + data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ '/ + + n=ncall + word='......' + if(n.ge.262177560) go to 999 !Plain text message ... + i=mod(n,27)+11 + word(6:6)=c(i:i) + n=n/27 + i=mod(n,27)+11 + word(5:5)=c(i:i) + n=n/27 + i=mod(n,27)+11 + word(4:4)=c(i:i) + n=n/27 + i=mod(n,10)+1 + word(3:3)=c(i:i) + n=n/10 + i=mod(n,36)+1 + word(2:2)=c(i:i) + n=n/36 + i=n+1 + word(1:1)=c(i:i) + do i=1,4 + if(word(i:i).ne.' ') go to 10 + enddo + go to 999 +10 word=word(i:) + +999 if(word(1:3).eq.'3D0') word='3DA0'//word(4:) + return +end subroutine unpackcall + +subroutine unpackgrid(ng,grid) + + parameter (NGBASE=180*180) + character grid*4,grid6*6,digit*10 + data digit/'0123456789'/ + + grid=' ' + if(ng.ge.32400) go to 10 + dlat=mod(ng,180)-90 + dlong=(ng/180)*2 - 180 + 2 + call deg2grid(dlong,dlat,grid6) + grid=grid6(1:4) !XXX explicitly truncate this -db + go to 100 + +10 n=ng-NGBASE-1 + if(n.ge.1 .and.n.le.30) then + grid(1:1)='-' + grid(2:2)=char(48+n/10) + grid(3:3)=char(48+mod(n,10)) + else if(n.ge.31 .and.n.le.60) then + n=n-30 + grid(1:2)='R-' + grid(3:3)=char(48+n/10) + grid(4:4)=char(48+mod(n,10)) + else if(n.eq.61) then + grid='RO' + else if(n.eq.62) then + grid='RRR' + else if(n.eq.63) then + grid='73' + endif + +100 return +end subroutine unpackgrid + +subroutine unpackpfx(ng,call1) + + character*12 call1 + character*3 pfx + + if(ng.lt.60000) then +! Add-on prefix of 1 to 3 characters + n=ng + do i=3,1,-1 + nc=mod(n,37) + if(nc.ge.0 .and. nc.le.9) then + pfx(i:i)=char(nc+48) + else if(nc.ge.10 .and. nc.le.35) then + pfx(i:i)=char(nc+55) + else + pfx(i:i)=' ' + endif + n=n/37 + enddo + call1=pfx//'/'//call1 + if(call1(1:1).eq.' ') call1=call1(2:) + if(call1(1:1).eq.' ') call1=call1(2:) + else +! Add-on suffix, one or teo characters + i1=index(call1,' ') + nc=ng-60000 + if(nc.ge.0 .and. nc.le.9) then + call1=call1(:i1-1)//'/'//char(nc+48) + else if(nc.ge.10 .and. nc.le.35) then + call1=call1(:i1-1)//'/'//char(nc+55) + else if(nc.ge.36 .and. nc.le.125) then + nc1=(nc-26)/10 + nc2=mod(nc-26,10) + call1=call1(:i1-1)//'/'//char(nc1+48)//char(nc2+48) + endif + endif + + return +end subroutine unpackpfx + +subroutine wqdecode(data0,message,ntype) + + parameter (N15=32768) + integer*1 data0(11) + character*22 message + character*12 callsign + character*3 cdbm + character grid4*4,grid6*6 + logical first + character*12 dcall(0:N15-1) + data first/.true./ + save first,dcall + +! May want to have a timeout (say, one hour?) on calls fetched +! from the hash table. + + if(first) then + dcall=' ' + first=.false. + endif + + message=' ' + call unpack50(data0,n1,n2) + call unpackcall(n1,callsign) + i1=index(callsign,' ') + call unpackgrid(n2/128,grid4) + ntype=iand(n2,127) -64 + +! Standard WSPR message (types 0 3 7 10 13 17 ... 60) + if(ntype.ge.0 .and. ntype.le.62) then + nu=mod(ntype,10) + if(nu.eq.0 .or. nu.eq.3 .or. nu.eq.7) then + write(cdbm,'(i3)'),ntype + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + message=callsign(1:i1)//grid4//' '//cdbm + call hash(callsign,i1-1,ih) + dcall(ih)=callsign(:i1) + else + nadd=nu + if(nu.gt.3) nadd=nu-3 + if(nu.gt.7) nadd=nu-7 + ng=n2/128 + 32768*(nadd-1) + call unpackpfx(ng,callsign) + ndbm=ntype-nadd + write(cdbm,'(i3)'),ndbm + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + i2=index(callsign,' ') + message=callsign(:i2)//cdbm + call hash(callsign,i2-1,ih) + dcall(ih)=callsign(:i2) + endif + else if(ntype.lt.0) then + ndbm=-(ntype+1) + grid6=callsign(6:6)//callsign(1:5) + ih=(n2-ntype-64)/128 + callsign=dcall(ih) + write(cdbm,'(i3)'),ndbm + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + if(cdbm(1:1).eq.' ') cdbm=cdbm(2:) + i2=index(callsign,' ') + if(dcall(ih)(1:1).ne.' ') then + message='<'//callsign(:i2-1)//'> '//grid6//' '//cdbm + else + message='<...> '//grid6//' '//cdbm + endif + endif + + return +end subroutine wqdecode + +subroutine wqencode(msg,ntype,data0) + +! Parse and encode a WSPR message. + + parameter (MASK15=32767) + character*22 msg + character*12 call1,call2 + character grid4*4,grid6*6 + logical lbad1,lbad2 + integer*1 data0(11) + integer nu(0:9) + data nu/0,-1,1,0,-1,2,1,0,-1,1/ + +! Standard WSPR message (types 0 3 7 10 13 17 ... 60) + i1=index(msg,' ') + i2=index(msg,'/') + i3=index(msg,'<') + call1=msg(:i1-1) + if(i1.lt.3 .or. i1.gt.7 .or. i2.gt.0 .or. i3.gt.0) go to 10 + grid4=msg(i1+1:i1+4) + call packcall(call1,n1,lbad1) + call packgrid(grid4,ng,lbad2) + if(lbad1 .or. lbad2) go to 10 + ndbm=0 + read(msg(i1+5:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + n2=128*ng + (ndbm+64) + call pack50(n1,n2,data0) + ntype=ndbm + go to 900 + +10 if(i2.ge.2 .and. i3.lt.1) then + call packpfx(call1,n1,ng,nadd) + ndbm=0 + read(msg(i1+1:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + ntype=ndbm + 1 + nadd + n2=128*ng + ntype + 64 + call pack50(n1,n2,data0) + else if(i3.eq.1) then + i4=index(msg,'>') + call1=msg(2:i4-1) + call hash(call1,i4-2,ih) + grid6=msg(i1+1:i1+6) + call2=grid6(2:6)//grid6(1:1)//' ' + call packcall(call2,n1,lbad1) + ndbm=0 + read(msg(i1+8:),*) ndbm + if(ndbm.lt.0) ndbm=0 + if(ndbm.gt.60) ndbm=60 + ndbm=ndbm+nu(mod(ndbm,10)) + ntype=-(ndbm+1) + n2=128*ih + ntype + 64 + call pack50(n1,n2,data0) + endif + go to 900 + +900 continue + return +end subroutine wqencode diff --git a/lib/wsprcode/wsprcode.f90 b/lib/wsprcode/wsprcode.f90 new file mode 100644 index 00000000..88b55901 --- /dev/null +++ b/lib/wsprcode/wsprcode.f90 @@ -0,0 +1,158 @@ +!------------------------------------------------------------------------------- +! +! This file is part of the WSPR application, Weak Signal Propagation Reporter +! +! File Name: wsprcode.f90 +! Description: This program provides examples of the source encoding, +! convulsional error-control coding, bit and symbol ordering, +! and synchronizing information contained in WSPR messages. +! +! Copyright (C) 2001-2014 Joseph Taylor, K1JT +! License: GPL-3 +! +! This program 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 of the License, or (at your option) any later +! version. +! +! This program 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 +! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +! Street, Fifth Floor, Boston, MA 02110-1301, USA. +! +!------------------------------------------------------------------------------- + +program wsprcode + + parameter (NSYM=162) + parameter (MAXSYM=176) + character*22 msg,msg2 + integer*1 data0(13) + integer*1 data1(13) + integer*1 dat(206) + integer*1 softsym(206) + +! Define the sync vector: + integer*1 sync(NSYM) + data sync/ & + 1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, & + 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, & + 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, & + 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, & + 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, & + 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, & + 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, & + 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, & + 0,0/ + +! Metric table for decoding from soft symbols + integer mettab(0:255,0:1) + data mettab/ & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, & + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & + 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, & + 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, & + -1, -1, -1, -2, -2, -3, -4, -4, -5, -6, & + -7, -7, -8, -9, -10, -11, -12, -12, -13, -14, & + -15, -16, -17, -17, -18, -19, -20, -21, -22, -22, & + -23, -24, -25, -26, -26, -27, -28, -29, -30, -30, & + -31, -32, -33, -33, -34, -35, -36, -36, -37, -38, & + -38, -39, -40, -41, -41, -42, -43, -43, -44, -45, & + -45, -46, -47, -47, -48, -49, -49, -50, -51, -51, & + -52, -53, -53, -54, -54, -55, -56, -56, -57, -57, & + -58, -59, -59, -60, -60, -61, -62, -62, -62, -63, & + -64, -64, -65, -65, -66, -67, -67, -67, -68, -69, & + -69, -70, -70, -71, -72, -72, -72, -72, -73, -74, & + -75, -75, -75, -77, -76, -76, -78, -78, -80, -81, & + -80, -79, -83, -82, -81, -82, -82, -83, -84, -84, & + -84, -87, -86, -87, -88, -89, -89, -89, -88, -87, & + -86, -87, -84, -84, -84, -83, -82, -82, -81, -82, & + -83, -79, -80, -81, -80, -78, -78, -76, -76, -77, & + -75, -75, -75, -74, -73, -72, -72, -72, -72, -71, & + -70, -70, -69, -69, -68, -67, -67, -67, -66, -65, & + -65, -64, -64, -63, -62, -62, -62, -61, -60, -60, & + -59, -59, -58, -57, -57, -56, -56, -55, -54, -54, & + -53, -53, -52, -51, -51, -50, -49, -49, -48, -47, & + -47, -46, -45, -45, -44, -43, -43, -42, -41, -41, & + -40, -39, -38, -38, -37, -36, -36, -35, -34, -33, & + -33, -32, -31, -30, -30, -29, -28, -27, -26, -26, & + -25, -24, -23, -22, -22, -21, -20, -19, -18, -17, & + -17, -16, -15, -14, -13, -12, -12, -11, -10, -9, & + -8, -7, -7, -6, -5, -4, -4, -3, -2, -2, & + -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, & + 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, & + 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, & + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & + 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5/ + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: WSPRcode "message"' + go to 999 + endif + call getarg(1,msg) !Get message from command line + write(*,1000) msg +1000 format('Message: ',a22) + + nbits=50+31 !User bits=50, constraint length=32 + nbytes=(nbits+7)/8 + ndelta=50 + limit=20000 + + data0=0 + call wqencode(msg,ntype0,data0) !Source encoding + write(*,1002) data0(1:7),data0(1:6),data0(7)/64 +1002 format(/'Source-encoded message, 50 bits:'/'Hex: ',7z3.2/ & + 'Binary: ',6b9.8,b3.2) + + call encode232(data0,nbytes,dat,MAXSYM) !Convolutional encoding + call inter_mept(dat,1) !Interleaving + + write(*,1004) +1004 format(/'Data symbols:') + write(*,1006) (dat(i),i=1,NSYM) +1006 format(5x,30i2) + + write(*,1008) +1008 format(/'Sync symbols:') + write(*,1006) (sync(i),i=1,NSYM) + + write(*,1010) +1010 format(/'Channel symbols:') + write(*,1006) (2*dat(i)+sync(i),i=1,NSYM) + + call inter_mept(dat,-1) !Remove interleaving + softsym=-dat !Simulate soft symbols + +! Call the sequential (Fano algorithm) decoder + call fano232(softsym,nbits,mettab,ndelta,limit,data1,ncycles,metric,nerr) + call wqdecode(data1,msg2,ntype1) + + write(*,1020) msg2,ntype1 +1020 format(/'Decoded message: ',a22,' ntype:',i3) + +999 end program wsprcode + +include 'wspr_old_subs.f90' + diff --git a/lib/wsprd/Makefile b/lib/wsprd/Makefile new file mode 100644 index 00000000..92040734 --- /dev/null +++ b/lib/wsprd/Makefile @@ -0,0 +1,34 @@ +CC = gcc +#CC = clang-3.5 +FC = gfortran + +CFLAGS= -I/usr/include -Wall -Wno-missing-braces -O3 -ffast-math +LDFLAGS = -L/usr/lib +FFLAGS = -O2 -Wall -Wno-conversion +LIBS = -lfftw3f -lm + +# Default rules +%.o: %.c $(DEPS) + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: wsprd wsprsim wsprd_exp + +DEPS = wsprsim_utils.h wsprd_utils.h fano.h jelinek.h nhash.h +OBJS1 = wsprd.o wsprsim_utils.o wsprd_utils.o tab.o fano.o jelinek.o nhash.o +wsprd: $(OBJS1) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +OBJS2 = wsprsim.o wsprsim_utils.o wsprd_utils.o tab.o fano.o nhash.o +wsprsim: $(OBJS2) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +clean: + rm *.o wsprd wsprsim diff --git a/lib/wsprd/Makefile.MinGW b/lib/wsprd/Makefile.MinGW new file mode 100644 index 00000000..d9fd6b83 --- /dev/null +++ b/lib/wsprd/Makefile.MinGW @@ -0,0 +1,30 @@ +CC = gcc +#CC = clang +FC = gfortran + +FFLAGS = -O2 -Wall -Wno-conversion +CFLAGS= -Wall -Wno-missing-braces -O2 +#LDFLAGS = -L/JTSDK/fftw3f +LIBS = c:/JTSDK/fftw3f/libfftw3-3.dll -lm + +# Default rules +%.o: %.c $(DEPS) + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: wsprd + +DEPS = fano.h +OBJS1 = wsprd.o wsprd_utils.o fano.o tab.o nhash.o +wsprd: $(OBJS1) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +clean: + rm *.o wsprd diff --git a/lib/wsprd/Makefile.win32 b/lib/wsprd/Makefile.win32 new file mode 100644 index 00000000..8d600d71 --- /dev/null +++ b/lib/wsprd/Makefile.win32 @@ -0,0 +1,40 @@ +CC = gcc +FC = gfortran + +FFLAGS = -O2 -Wall -Wno-conversion +CFLAGS= -I/JTSDK/fftw3f -Wall -Wno-missing-braces -O2 +#LDFLAGS = -L/JTSDK/fftw3f -Wl,--stack,4000000 +LDFLAGS = -L/JTSDK/fftw3f +LIBS = c:/JTSDK/fftw3f/libfftw3-3.dll -lm + +# Default rules +%.o: %.c $(DEPS) + ${CC} ${CFLAGS} -c $< +%.o: %.f + ${FC} ${FFLAGS} -c $< +%.o: %.F + ${FC} ${FFLAGS} -c $< +%.o: %.f90 + ${FC} ${FFLAGS} -c $< +%.o: %.F90 + ${FC} ${FFLAGS} -c $< + +all: wsprd.exe wsprsim.exe wsprd_exp.exe + +DEPS = wsprsim_utils.h wsprd_utils.h fano.h jelinek.h nhash.h + +OBJS1 = wsprd.o wsprsim_utils.o wsprd_utils.o tab.o fano.o jelinek.o nhash.o +wsprd.exe: $(OBJS1) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +OBJS2 = wsprsim.o wsprsim_utils.o wsprd_utils.o tab.o fano.o nhash.o +wsprsim.exe: $(OBJS2) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +OBJS3 = wsprd_exp.o wsprsim_utils.o wsprd_utils.o tab.o fano.o jelinek.o \ + nhash.o +wsprd_exp.exe: $(OBJS3) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) + +clean: + rm *.o wsprd.exe wsprsim.exe wsprd_exp.exe diff --git a/lib/wsprd/README b/lib/wsprd/README new file mode 100755 index 00000000..4579d2d3 --- /dev/null +++ b/lib/wsprd/README @@ -0,0 +1,54 @@ +wsprd is a decoder for K1JT's Weak Signal Propagation Reporter (WSPR) mode. + +The program is written in C and is a command-line program that reads from a +.c2 file or .wav file and writes output to the console. It is used by WSJT-X +for wspr-mode decoding. + +USAGE: + wsprd [options...] infile + +OPTIONS: + -a path to writeable data files, default="." + -c write .c2 file at the end of the first pass + -e x (x is transceiver dial frequency error in Hz) + -f x (x is transceiver dial frequency in MHz) + -H do not use (or update) the hash table + -m decode wspr-15 .wav file + -q quick mode - doesn't dig deep for weak signals + -s single pass mode, no subtraction (same as original wsprd) + -v verbose mode (shows dupes) + -w wideband mode - decode signals within +/- 150 Hz of center + -z x (x is fano metric table bias, default is 0.42) + +infile can be either .wav or .c2 + +e.g. +./wsprd -wf 14.0956 140709_2258.wav + +Note that for .c2 files, the frequency within the file overrides the command +line value. + +FEATURES: +By default, wsprd reports signals that are within +/- 110 Hz of the +subband center frequency. The wideband option (-w) extends this to +/- 150 Hz. + +wsprd maintains a hashtable and will decode all three types of wspr +messages. An option (-H) is available to turn off use of the hashtable. + +The symbols are decoded using Phil Karn's sequential decoder routine, +fano.c. + +NOTES: +This program attempts to maximize the number of successful decodes per transmit +interval by trying to decode virtually every peak in the averaged spectrum. +The program also implements two-pass decoding, whereby signals that are successfully +decoded are subtracted one-by-one during the first decoding pass. Then, the +decoder is run again. In many cases the subtraction process will uncover signals +that can then be successfully decoded on the second pass. + +There will be occasional duplicate decodes when two closely spaced +peaks come from the same signal. The program removes dupes based on callsign +and frequency. Two decodes that have the same callsign and estimated frequencies +that are within 1 Hz will be treated as decodes of the same signal. This +dupechecking is turned off with the -v flag. + diff --git a/lib/wsprd/WSPRcode.f90 b/lib/wsprd/WSPRcode.f90 new file mode 100644 index 00000000..1ec91712 --- /dev/null +++ b/lib/wsprd/WSPRcode.f90 @@ -0,0 +1,132 @@ +program wsprcode + +! This program provides examples of the source encoding, convolutional +! error-control coding, bit and symbol ordering, and synchronizing +! information contained in WSPR messages. + + parameter (NSYM=162) + parameter (MAXSYM=176) + character*22 msg,msg2 + integer*1 data0(7) + integer*1 data1(7) + integer*1 dat(NSYM) + integer*1 softsym(NSYM) + +! Define the sync vector: + integer*1 sync(NSYM) + data sync/ & + 1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, & + 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, & + 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, & + 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, & + 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, & + 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, & + 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, & + 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, & + 0,0/ + +! Metric table for decoding from soft symbols + integer mettab(0:255,0:1) + data mettab/ & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, & + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & + 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, & + 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, & + -1, -1, -1, -2, -2, -3, -4, -4, -5, -6, & + -7, -7, -8, -9, -10, -11, -12, -12, -13, -14, & + -15, -16, -17, -17, -18, -19, -20, -21, -22, -22, & + -23, -24, -25, -26, -26, -27, -28, -29, -30, -30, & + -31, -32, -33, -33, -34, -35, -36, -36, -37, -38, & + -38, -39, -40, -41, -41, -42, -43, -43, -44, -45, & + -45, -46, -47, -47, -48, -49, -49, -50, -51, -51, & + -52, -53, -53, -54, -54, -55, -56, -56, -57, -57, & + -58, -59, -59, -60, -60, -61, -62, -62, -62, -63, & + -64, -64, -65, -65, -66, -67, -67, -67, -68, -69, & + -69, -70, -70, -71, -72, -72, -72, -72, -73, -74, & + -75, -75, -75, -77, -76, -76, -78, -78, -80, -81, & + -80, -79, -83, -82, -81, -82, -82, -83, -84, -84, & + -84, -87, -86, -87, -88, -89, -89, -89, -88, -87, & + -86, -87, -84, -84, -84, -83, -82, -82, -81, -82, & + -83, -79, -80, -81, -80, -78, -78, -76, -76, -77, & + -75, -75, -75, -74, -73, -72, -72, -72, -72, -71, & + -70, -70, -69, -69, -68, -67, -67, -67, -66, -65, & + -65, -64, -64, -63, -62, -62, -62, -61, -60, -60, & + -59, -59, -58, -57, -57, -56, -56, -55, -54, -54, & + -53, -53, -52, -51, -51, -50, -49, -49, -48, -47, & + -47, -46, -45, -45, -44, -43, -43, -42, -41, -41, & + -40, -39, -38, -38, -37, -36, -36, -35, -34, -33, & + -33, -32, -31, -30, -30, -29, -28, -27, -26, -26, & + -25, -24, -23, -22, -22, -21, -20, -19, -18, -17, & + -17, -16, -15, -14, -13, -12, -12, -11, -10, -9, & + -8, -7, -7, -6, -5, -4, -4, -3, -2, -2, & + -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, & + 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, & + 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, & + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, & + 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, & + 5, 5/ + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: WSPRcode "message"' + go to 999 + endif + call getarg(1,msg) !Get message from command line + write(*,1000) msg +1000 format('Message: ',a22) + + nbits=50+31 !User bits=50, constraint length=32 + nbytes=(nbits+7)/8 + ndelta=50 + limit=20000 + + data0=0 + call wqencode(msg,ntype0,data0) !Source encoding + write(*,1002) data0 +1002 format(/'Source-encoded message (50 bits, hex):',7z3.2) + + call encode232(data0,nbytes,dat,MAXSYM) !Convolutional encoding + call inter_mept(dat,1) !Interleaving + + write(*,1004) +1004 format(/'Data symbols:') + write(*,1006) (dat(i),i=1,NSYM) +1006 format(5x,30i2) + + write(*,1008) +1008 format(/'Sync symbols:') + write(*,1006) (sync(i),i=1,NSYM) + + write(*,1010) +1010 format(/'Channel symbols:') + write(*,1006) (2*dat(i)+sync(i),i=1,NSYM) + + call inter_mept(dat,-1) !Remove interleaving + softsym=-dat !Simulate soft symbols + +! Call the sequential (Fano algorithm) decoder + call fano232(softsym,nbits,mettab,ndelta,limit,data1,ncycles,metric,nerr) + call wqdecode(data1,msg2,ntype1) + + write(*,1020) ntype1 +1020 format(/'Message type: ',i7) + write(*,1030) msg2 +1030 format('Decoded message: ',a22) + +999 end program wsprcode diff --git a/lib/wsprd/fano.c b/lib/wsprd/fano.c new file mode 100644 index 00000000..8fe1a649 --- /dev/null +++ b/lib/wsprd/fano.c @@ -0,0 +1,239 @@ +/* + This file is part of wsprd. + + File name: fano.c + + Description: Soft decision Fano sequential decoder for K=32 r=1/2 + convolutional code. + + Copyright 1994, Phil Karn, KA9Q + Minor modifications by Joe Taylor, K1JT +*/ + +#define LL 1 // Select Layland-Lushbaugh code +#include +#include +#include +#include "fano.h" + +struct node { + unsigned long encstate; // Encoder state of next node + long gamma; // Cumulative metric to this node + int metrics[4]; // Metrics indexed by all possible tx syms + int tm[2]; // Sorted metrics for current hypotheses + int i; // Current branch being tested +}; + +// Convolutional coding polynomials. All are rate 1/2, K=32 +#ifdef NASA_STANDARD +/* "NASA standard" code by Massey & Costello + * Nonsystematic, quick look-in, dmin=11, dfree=23 + * used on Pioneer 10-12, Helios A,B + */ +#define POLY1 0xbbef6bb7 +#define POLY2 0xbbef6bb5 +#endif + +#ifdef MJ +/* Massey-Johannesson code + * Nonsystematic, quick look-in, dmin=13, dfree>=23 + * Purported to be more computationally efficient than Massey-Costello + */ +#define POLY1 0xb840a20f +#define POLY2 0xb840a20d +#endif + +#ifdef LL +/* Layland-Lushbaugh code + * Nonsystematic, non-quick look-in, dmin=?, dfree=? + */ +#define POLY1 0xf2d05351 +#define POLY2 0xe4613c47 +#endif + +/* Convolutionally encode a packet. The input data bytes are read + * high bit first and the encoded packet is written into 'symbols', + * one symbol per byte. The first symbol is generated from POLY1, + * the second from POLY2. + * + * Storing only one symbol per byte uses more space, but it is faster + * and easier than trying to pack them more compactly. + */ +int encode( + unsigned char *symbols, // Output buffer, 2*nbytes*8 + unsigned char *data, // Input buffer, nbytes + unsigned int nbytes) // Number of bytes in data +{ + unsigned long encstate; + int sym; + int i; + + encstate = 0; + while(nbytes-- != 0) { + for(i=7;i>=0;i--) { + encstate = (encstate << 1) | ((*data >> i) & 1); + ENCODE(sym,encstate); + *symbols++ = sym >> 1; + *symbols++ = sym & 1; + } + data++; + } + return 0; +} + +/* Decode packet with the Fano algorithm. + * Return 0 on success, -1 on timeout + */ +int fano( + unsigned int *metric, // Final path metric (returned value) + unsigned int *cycles, // Cycle count (returned value) + unsigned int *maxnp, // Progress before timeout (returned value) + unsigned char *data, // Decoded output data + unsigned char *symbols, // Raw deinterleaved input symbols + unsigned int nbits, // Number of output bits + int mettab[2][256], // Metric table, [sent sym][rx symbol] + int delta, // Threshold adjust parameter + unsigned int maxcycles) // Decoding timeout in cycles per bit +{ + struct node *nodes; // First node + struct node *np; // Current node + struct node *lastnode; // Last node + struct node *tail; // First node of tail + int t; // Threshold + int m0,m1; + int ngamma; + unsigned int lsym; + unsigned int i; + + if((nodes = (struct node *)malloc((nbits+1)*sizeof(struct node))) == NULL) { + printf("malloc failed\n"); + return 0; + } + lastnode = &nodes[nbits-1]; + tail = &nodes[nbits-31]; + *maxnp = 0; + +/* Compute all possible branch metrics for each symbol pair + * This is the only place we actually look at the raw input symbols + */ + for(np=nodes;np <= lastnode;np++) { + np->metrics[0] = mettab[0][symbols[0]] + mettab[0][symbols[1]]; + np->metrics[1] = mettab[0][symbols[0]] + mettab[1][symbols[1]]; + np->metrics[2] = mettab[1][symbols[0]] + mettab[0][symbols[1]]; + np->metrics[3] = mettab[1][symbols[0]] + mettab[1][symbols[1]]; + symbols += 2; + } + np = nodes; + np->encstate = 0; + +// Compute and sort branch metrics from root node */ + ENCODE(lsym,np->encstate); // 0-branch (LSB is 0) + m0 = np->metrics[lsym]; + +/* Now do the 1-branch. To save another ENCODE call here and + * inside the loop, we assume that both polynomials are odd, + * providing complementary pairs of branch symbols. + + * This code should be modified if a systematic code were used. + */ + + m1 = np->metrics[3^lsym]; + if(m0 > m1) { + np->tm[0] = m0; // 0-branch has better metric + np->tm[1] = m1; + } else { + np->tm[0] = m1; // 1-branch is better + np->tm[1] = m0; + np->encstate++; // Set low bit + } + np->i = 0; // Start with best branch + maxcycles *= nbits; + np->gamma = t = 0; + + // Start the Fano decoder + for(i=1;i <= maxcycles;i++) { + if((int)(np-nodes) > (int)*maxnp) *maxnp=(int)(np-nodes); +#ifdef debug + printf("k=%ld, g=%ld, t=%d, m[%d]=%d, maxnp=%d, encstate=%lx\n", + np-nodes,np->gamma,t,np->i,np->tm[np->i],*maxnp,np->encstate); +#endif +// Look forward */ + ngamma = np->gamma + np->tm[np->i]; + if(ngamma >= t) { + if(np->gamma < t + delta) { // Node is acceptable + /* First time we've visited this node; + * Tighten threshold. + * + * This loop could be replaced with + * t += delta * ((ngamma - t)/delta); + * but the multiply and divide are slower. + */ + while(ngamma >= t + delta) t += delta; + } + np[1].gamma = ngamma; // Move forward + np[1].encstate = np->encstate << 1; + if( ++np == (lastnode+1) ) { + break; // Done! + } + + /* Compute and sort metrics, starting with the + * zero branch + */ + ENCODE(lsym,np->encstate); + if(np >= tail) { + /* The tail must be all zeroes, so don't + * bother computing the 1-branches here. + */ + np->tm[0] = np->metrics[lsym]; + } else { + m0 = np->metrics[lsym]; + m1 = np->metrics[3^lsym]; + if(m0 > m1) { + np->tm[0] = m0; // 0-branch is better + np->tm[1] = m1; + } else { + np->tm[0] = m1; // 1-branch is better + np->tm[1] = m0; + np->encstate++; // Set low bit + } + } + np->i = 0; // Start with best branch + continue; + } + // Threshold violated, can't go forward + for(;;) { // Look backward + if(np == nodes || np[-1].gamma < t) { + /* Can't back up either. + * Relax threshold and and look + * forward again to better branch. + */ + t -= delta; + if(np->i != 0) { + np->i = 0; + np->encstate ^= 1; + } + break; + } + // Back up + if(--np < tail && np->i != 1) { + np->i++; // Search next best branch + np->encstate ^= 1; + break; + } // else keep looking back + } + } + *metric = np->gamma; // Return the final path metric + + // Copy decoded data to user's buffer + nbits >>= 3; + np = &nodes[7]; + while(nbits-- != 0) { + *data++ = np->encstate; + np += 8; + } + *cycles = i+1; + + free(nodes); + if(i >= maxcycles) return -1; // Decoder timed out + return 0; // Successful completion +} diff --git a/lib/wsprd/fano.h b/lib/wsprd/fano.h new file mode 100644 index 00000000..3290a094 --- /dev/null +++ b/lib/wsprd/fano.h @@ -0,0 +1,39 @@ +/* + This file is part of wsprd. + + File name: fano.h + + Description: Header file for sequential Fano decoder. + + Copyright 1994, Phil Karn, KA9Q + Minor modifications by Joe Taylor, K1JT +*/ + +#ifndef FANO_H +#define FANO_H + +int fano(unsigned int *metric, unsigned int *cycles, unsigned int *maxnp, + unsigned char *data,unsigned char *symbols, unsigned int nbits, + int mettab[2][256],int delta,unsigned int maxcycles); + +int encode(unsigned char *symbols,unsigned char *data,unsigned int nbytes); + +extern unsigned char Partab[]; + +/* Convolutional encoder macro. Takes the encoder state, generates + * a rate 1/2 symbol pair and stores it in 'sym'. The symbol generated from + * POLY1 goes into the 2-bit of sym, and the symbol generated from POLY2 + * goes into the 1-bit. + */ +#define ENCODE(sym,encstate){\ +unsigned long _tmp;\ +\ +_tmp = (encstate) & POLY1;\ +_tmp ^= _tmp >> 16;\ +(sym) = Partab[(_tmp ^ (_tmp >> 8)) & 0xff] << 1;\ +_tmp = (encstate) & POLY2;\ +_tmp ^= _tmp >> 16;\ +(sym) |= Partab[(_tmp ^ (_tmp >> 8)) & 0xff];\ +} + +#endif diff --git a/lib/wsprd/fftw3.h b/lib/wsprd/fftw3.h new file mode 100644 index 00000000..58a2c73d --- /dev/null +++ b/lib/wsprd/fftw3.h @@ -0,0 +1,410 @@ +/* + * Copyright (c) 2003, 2007-11 Matteo Frigo + * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology + * + * The following statement of license applies *only* to this header file, + * and *not* to the other files distributed with FFTW or derived therefrom: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/***************************** NOTE TO USERS ********************************* + * + * THIS IS A HEADER FILE, NOT A MANUAL + * + * If you want to know how to use FFTW, please read the manual, + * online at http://www.fftw.org/doc/ and also included with FFTW. + * For a quick start, see the manual's tutorial section. + * + * (Reading header files to learn how to use a library is a habit + * stemming from code lacking a proper manual. Arguably, it's a + * *bad* habit in most cases, because header files can contain + * interfaces that are not part of the public, stable API.) + * + ****************************************************************************/ + +#ifndef FFTW3_H +#define FFTW3_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/* If is included, use the C99 complex type. Otherwise + define a type bit-compatible with C99 complex */ +#if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) +# define FFTW_DEFINE_COMPLEX(R, C) typedef R _Complex C +#else +# define FFTW_DEFINE_COMPLEX(R, C) typedef R C[2] +#endif + +#define FFTW_CONCAT(prefix, name) prefix ## name +#define FFTW_MANGLE_DOUBLE(name) FFTW_CONCAT(fftw_, name) +#define FFTW_MANGLE_FLOAT(name) FFTW_CONCAT(fftwf_, name) +#define FFTW_MANGLE_LONG_DOUBLE(name) FFTW_CONCAT(fftwl_, name) +#define FFTW_MANGLE_QUAD(name) FFTW_CONCAT(fftwq_, name) + +/* IMPORTANT: for Windows compilers, you should add a line + #define FFTW_DLL + here and in kernel/ifftw.h if you are compiling/using FFTW as a + DLL, in order to do the proper importing/exporting, or + alternatively compile with -DFFTW_DLL or the equivalent + command-line flag. This is not necessary under MinGW/Cygwin, where + libtool does the imports/exports automatically. */ +#if defined(FFTW_DLL) && (defined(_WIN32) || defined(__WIN32__)) + /* annoying Windows syntax for shared-library declarations */ +# if defined(COMPILING_FFTW) /* defined in api.h when compiling FFTW */ +# define FFTW_EXTERN extern __declspec(dllexport) +# else /* user is calling FFTW; import symbol */ +# define FFTW_EXTERN extern __declspec(dllimport) +# endif +#else +# define FFTW_EXTERN extern +#endif + +enum fftw_r2r_kind_do_not_use_me { + FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2, + FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6, + FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10 +}; + +struct fftw_iodim_do_not_use_me { + int n; /* dimension size */ + int is; /* input stride */ + int os; /* output stride */ +}; + +#include /* for ptrdiff_t */ +struct fftw_iodim64_do_not_use_me { + ptrdiff_t n; /* dimension size */ + ptrdiff_t is; /* input stride */ + ptrdiff_t os; /* output stride */ +}; + +typedef void (*fftw_write_char_func_do_not_use_me)(char c, void *); +typedef int (*fftw_read_char_func_do_not_use_me)(void *); + +/* + huge second-order macro that defines prototypes for all API + functions. We expand this macro for each supported precision + + X: name-mangling macro + R: real data type + C: complex data type +*/ + +#define FFTW_DEFINE_API(X, R, C) \ + \ +FFTW_DEFINE_COMPLEX(R, C); \ + \ +typedef struct X(plan_s) *X(plan); \ + \ +typedef struct fftw_iodim_do_not_use_me X(iodim); \ +typedef struct fftw_iodim64_do_not_use_me X(iodim64); \ + \ +typedef enum fftw_r2r_kind_do_not_use_me X(r2r_kind); \ + \ +typedef fftw_write_char_func_do_not_use_me X(write_char_func); \ +typedef fftw_read_char_func_do_not_use_me X(read_char_func); \ + \ +FFTW_EXTERN void X(execute)(const X(plan) p); \ + \ +FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \ + C *in, C *out, int sign, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_dft_1d)(int n, C *in, C *out, int sign, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_2d)(int n0, int n1, \ + C *in, C *out, int sign, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_3d)(int n0, int n1, int n2, \ + C *in, C *out, int sign, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_many_dft)(int rank, const int *n, \ + int howmany, \ + C *in, const int *inembed, \ + int istride, int idist, \ + C *out, const int *onembed, \ + int ostride, int odist, \ + int sign, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru_dft)(int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + C *in, C *out, \ + int sign, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru_split_dft)(int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + R *ri, R *ii, R *ro, R *io, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru64_dft)(int rank, \ + const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + C *in, C *out, \ + int sign, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru64_split_dft)(int rank, \ + const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + R *ri, R *ii, R *ro, R *io, \ + unsigned flags); \ + \ +FFTW_EXTERN void X(execute_dft)(const X(plan) p, C *in, C *out); \ +FFTW_EXTERN void X(execute_split_dft)(const X(plan) p, R *ri, R *ii, \ + R *ro, R *io); \ + \ +FFTW_EXTERN X(plan) X(plan_many_dft_r2c)(int rank, const int *n, \ + int howmany, \ + R *in, const int *inembed, \ + int istride, int idist, \ + C *out, const int *onembed, \ + int ostride, int odist, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_dft_r2c)(int rank, const int *n, \ + R *in, C *out, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_dft_r2c_1d)(int n,R *in,C *out,unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_r2c_2d)(int n0, int n1, \ + R *in, C *out, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_r2c_3d)(int n0, int n1, \ + int n2, \ + R *in, C *out, unsigned flags); \ + \ + \ +FFTW_EXTERN X(plan) X(plan_many_dft_c2r)(int rank, const int *n, \ + int howmany, \ + C *in, const int *inembed, \ + int istride, int idist, \ + R *out, const int *onembed, \ + int ostride, int odist, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_dft_c2r)(int rank, const int *n, \ + C *in, R *out, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_dft_c2r_1d)(int n,C *in,R *out,unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_c2r_2d)(int n0, int n1, \ + C *in, R *out, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_dft_c2r_3d)(int n0, int n1, \ + int n2, \ + C *in, R *out, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru_dft_r2c)(int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + R *in, C *out, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru_dft_c2r)(int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + C *in, R *out, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru_split_dft_r2c)( \ + int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + R *in, R *ro, R *io, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru_split_dft_c2r)( \ + int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + R *ri, R *ii, R *out, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru64_dft_r2c)(int rank, \ + const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + R *in, C *out, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru64_dft_c2r)(int rank, \ + const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + C *in, R *out, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru64_split_dft_r2c)( \ + int rank, const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + R *in, R *ro, R *io, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_guru64_split_dft_c2r)( \ + int rank, const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + R *ri, R *ii, R *out, \ + unsigned flags); \ + \ +FFTW_EXTERN void X(execute_dft_r2c)(const X(plan) p, R *in, C *out); \ +FFTW_EXTERN void X(execute_dft_c2r)(const X(plan) p, C *in, R *out); \ + \ +FFTW_EXTERN void X(execute_split_dft_r2c)(const X(plan) p, \ + R *in, R *ro, R *io); \ +FFTW_EXTERN void X(execute_split_dft_c2r)(const X(plan) p, \ + R *ri, R *ii, R *out); \ + \ +FFTW_EXTERN X(plan) X(plan_many_r2r)(int rank, const int *n, \ + int howmany, \ + R *in, const int *inembed, \ + int istride, int idist, \ + R *out, const int *onembed, \ + int ostride, int odist, \ + const X(r2r_kind) *kind, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_r2r)(int rank, const int *n, R *in, R *out, \ + const X(r2r_kind) *kind, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_r2r_1d)(int n, R *in, R *out, \ + X(r2r_kind) kind, unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_r2r_2d)(int n0, int n1, R *in, R *out, \ + X(r2r_kind) kind0, X(r2r_kind) kind1, \ + unsigned flags); \ +FFTW_EXTERN X(plan) X(plan_r2r_3d)(int n0, int n1, int n2, \ + R *in, R *out, X(r2r_kind) kind0, \ + X(r2r_kind) kind1, X(r2r_kind) kind2, \ + unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru_r2r)(int rank, const X(iodim) *dims, \ + int howmany_rank, \ + const X(iodim) *howmany_dims, \ + R *in, R *out, \ + const X(r2r_kind) *kind, unsigned flags); \ + \ +FFTW_EXTERN X(plan) X(plan_guru64_r2r)(int rank, const X(iodim64) *dims, \ + int howmany_rank, \ + const X(iodim64) *howmany_dims, \ + R *in, R *out, \ + const X(r2r_kind) *kind, unsigned flags); \ + \ +FFTW_EXTERN void X(execute_r2r)(const X(plan) p, R *in, R *out); \ + \ +FFTW_EXTERN void X(destroy_plan)(X(plan) p); \ +FFTW_EXTERN void X(forget_wisdom)(void); \ +FFTW_EXTERN void X(cleanup)(void); \ + \ +FFTW_EXTERN void X(set_timelimit)(double t); \ + \ +FFTW_EXTERN void X(plan_with_nthreads)(int nthreads); \ +FFTW_EXTERN int X(init_threads)(void); \ +FFTW_EXTERN void X(cleanup_threads)(void); \ + \ +FFTW_EXTERN int X(export_wisdom_to_filename)(const char *filename); \ +FFTW_EXTERN void X(export_wisdom_to_file)(FILE *output_file); \ +FFTW_EXTERN char *X(export_wisdom_to_string)(void); \ +FFTW_EXTERN void X(export_wisdom)(X(write_char_func) write_char, \ + void *data); \ +FFTW_EXTERN int X(import_system_wisdom)(void); \ +FFTW_EXTERN int X(import_wisdom_from_filename)(const char *filename); \ +FFTW_EXTERN int X(import_wisdom_from_file)(FILE *input_file); \ +FFTW_EXTERN int X(import_wisdom_from_string)(const char *input_string); \ +FFTW_EXTERN int X(import_wisdom)(X(read_char_func) read_char, void *data); \ + \ +FFTW_EXTERN void X(fprint_plan)(const X(plan) p, FILE *output_file); \ +FFTW_EXTERN void X(print_plan)(const X(plan) p); \ + \ +FFTW_EXTERN void *X(malloc)(size_t n); \ +FFTW_EXTERN R *X(alloc_real)(size_t n); \ +FFTW_EXTERN C *X(alloc_complex)(size_t n); \ +FFTW_EXTERN void X(free)(void *p); \ + \ +FFTW_EXTERN void X(flops)(const X(plan) p, \ + double *add, double *mul, double *fmas); \ +FFTW_EXTERN double X(estimate_cost)(const X(plan) p); \ +FFTW_EXTERN double X(cost)(const X(plan) p); \ + \ +FFTW_EXTERN const char X(version)[]; \ +FFTW_EXTERN const char X(cc)[]; \ +FFTW_EXTERN const char X(codelet_optim)[]; + + +/* end of FFTW_DEFINE_API macro */ + +FFTW_DEFINE_API(FFTW_MANGLE_DOUBLE, double, fftw_complex) +FFTW_DEFINE_API(FFTW_MANGLE_FLOAT, float, fftwf_complex) +FFTW_DEFINE_API(FFTW_MANGLE_LONG_DOUBLE, long double, fftwl_complex) + +/* __float128 (quad precision) is a gcc extension on i386, x86_64, and ia64 + for gcc >= 4.6 (compiled in FFTW with --enable-quad-precision) */ +#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \ + && !(defined(__ICC) || defined(__INTEL_COMPILER)) \ + && (defined(__i386__) || defined(__x86_64__) || defined(__ia64__)) +# if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) +/* note: __float128 is a typedef, which is not supported with the _Complex + keyword in gcc, so instead we use this ugly __attribute__ version. + However, we can't simply pass the __attribute__ version to + FFTW_DEFINE_API because the __attribute__ confuses gcc in pointer + types. Hence redefining FFTW_DEFINE_COMPLEX. Ugh. */ +# undef FFTW_DEFINE_COMPLEX +# define FFTW_DEFINE_COMPLEX(R, C) typedef _Complex float __attribute__((mode(TC))) C +# endif +FFTW_DEFINE_API(FFTW_MANGLE_QUAD, __float128, fftwq_complex) +#endif + +#define FFTW_FORWARD (-1) +#define FFTW_BACKWARD (+1) + +#define FFTW_NO_TIMELIMIT (-1.0) + +/* documented flags */ +#define FFTW_MEASURE (0U) +#define FFTW_DESTROY_INPUT (1U << 0) +#define FFTW_UNALIGNED (1U << 1) +#define FFTW_CONSERVE_MEMORY (1U << 2) +#define FFTW_EXHAUSTIVE (1U << 3) /* NO_EXHAUSTIVE is default */ +#define FFTW_PRESERVE_INPUT (1U << 4) /* cancels FFTW_DESTROY_INPUT */ +#define FFTW_PATIENT (1U << 5) /* IMPATIENT is default */ +#define FFTW_ESTIMATE (1U << 6) +#define FFTW_WISDOM_ONLY (1U << 21) + +/* undocumented beyond-guru flags */ +#define FFTW_ESTIMATE_PATIENT (1U << 7) +#define FFTW_BELIEVE_PCOST (1U << 8) +#define FFTW_NO_DFT_R2HC (1U << 9) +#define FFTW_NO_NONTHREADED (1U << 10) +#define FFTW_NO_BUFFERING (1U << 11) +#define FFTW_NO_INDIRECT_OP (1U << 12) +#define FFTW_ALLOW_LARGE_GENERIC (1U << 13) /* NO_LARGE_GENERIC is default */ +#define FFTW_NO_RANK_SPLITS (1U << 14) +#define FFTW_NO_VRANK_SPLITS (1U << 15) +#define FFTW_NO_VRECURSE (1U << 16) +#define FFTW_NO_SIMD (1U << 17) +#define FFTW_NO_SLOW (1U << 18) +#define FFTW_NO_FIXED_RADIX_LARGE_N (1U << 19) +#define FFTW_ALLOW_PRUNING (1U << 20) + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* FFTW3_H */ diff --git a/lib/wsprd/genmet.f90 b/lib/wsprd/genmet.f90 new file mode 100644 index 00000000..e5dcdaba --- /dev/null +++ b/lib/wsprd/genmet.f90 @@ -0,0 +1,50 @@ +program genmet + + character*12 arg + integer hist(-128:128) + lim(x)=min(127,max(-128,nint(scale*x))) + + nargs=iargc() + if(nargs.ne.4) then + print*,'Usage: genmet bw scale snr iters' + print*,'Example: genmet 1.46 20 -24 1000000' + go to 999 + endif + call getarg(1,arg) + read(arg,*) bw + call getarg(2,arg) + read(arg,*) scale + call getarg(3,arg) + read(arg,*) snr + call getarg(4,arg) + read(arg,*) iters + + hist=0 + s=sqrt(2500.0/bw) * 10.0**(0.05*snr) + fac=1.0/sqrt(2.0) + do iter=1,iters + x1=fac*gran() + y1=fac*gran() + x0=fac*gran() + y0=fac*gran() + r=(x1+s)**2 + y1*y1 - x0*x0 - y0*y0 + hist(lim(r))=hist(lim(r))+1 + enddo + + xln2=log(2.0) + do i=-128,127 + p1=hist(i)/dfloat(iters) + j=-i + if(j.gt.127) j=127 + p0=hist(j)/dfloat(iters) + xlhd0=log(max(0.001,2.0*p0/(p0+p1)))/xln2 + xlhd1=log(max(0.001,2.0*p1/(p0+p1)))/xln2 + write(13,1010) i/scale,hist(i)/dfloat(iters) +1010 format(f8.3,f12.9) + write(14,1012) i+128,xlhd0,xlhd1 +1012 format(i4,2f8.3) + enddo + +999 end program genmet + + diff --git a/lib/wsprd/gran.c b/lib/wsprd/gran.c new file mode 100644 index 00000000..24b98650 --- /dev/null +++ b/lib/wsprd/gran.c @@ -0,0 +1,28 @@ +#include +#include + +/* Generate gaussian random float with mean=0 and std_dev=1 */ +float gran_() +{ + float fac,rsq,v1,v2; + static float gset; + static int iset; + + if(iset){ + /* Already got one */ + iset = 0; + return gset; + } + /* Generate two evenly distributed numbers between -1 and +1 + * that are inside the unit circle + */ + do { + v1 = 2.0 * (float)rand() / RAND_MAX - 1; + v2 = 2.0 * (float)rand() / RAND_MAX - 1; + rsq = v1*v1 + v2*v2; + } while(rsq >= 1.0 || rsq == 0.0); + fac = sqrt(-2.0*log(rsq)/rsq); + gset = v1*fac; + iset++; + return v2*fac; +} diff --git a/lib/wsprd/jelinek.c b/lib/wsprd/jelinek.c new file mode 100644 index 00000000..8fe0d2f7 --- /dev/null +++ b/lib/wsprd/jelinek.c @@ -0,0 +1,163 @@ +/* + Soft-decision stack-based sequential decoder for K=32 r=1/2 + convolutional code. This code implements the "stack-bucket" algorithm + described in: + "Fast Sequential Decoding Algorithm Using a Stack", F. Jelinek + + The ENCODE macro from Phil Karn's (KA9Q) Fano decoder is used. + + Written by Steve Franke, K9AN for WSJT-X (July 2015) + */ + +#include "jelinek.h" + +#include +#include +#include +#include /* memset */ + +#include "fano.h" + +/* WSPR uses the Layland-Lushbaugh code + * Nonsystematic, non-quick look-in, dmin=?, dfree=? + */ +#define POLY1 0xf2d05351 +#define POLY2 0xe4613c47 + +//Decoder - returns 0 on success, -1 on timeout +int jelinek( + unsigned int *metric, /* Final path metric (returned value) */ + unsigned int *cycles, /* Cycle count (returned value) */ + unsigned char *data, /* Decoded output data */ + unsigned char *symbols, /* Raw deinterleaved input symbols */ + unsigned int nbits, /* Number of output bits */ + unsigned int stacksize, + struct snode *stack, + int mettab[2][256], /* Metric table, [sent sym][rx symbol] */ + unsigned int maxcycles)/* Decoding timeout in cycles per bit */ +{ + + // Compute branch metrics for each symbol pair + // The sequential decoding algorithm only uses the metrics, not the + // symbol values. + unsigned int i; + long int metrics[81][4]; + for(i=0; i>5)+200; //fast, but not particularly safe - totmet can be negative + if( bucket > high_bucket ) high_bucket=bucket; + if( bucket < low_bucket ) low_bucket=bucket; + + // place the 0 node on the stack, overwriting the parent (current) node + stack[ptr].encstate=encstate; + stack[ptr].gamma=totmet0; + stack[ptr].depth=depth; + stack[ptr].jpointer=buckets[bucket]; + buckets[bucket]=ptr; + + // if in the tail, only need to evaluate the "0" branch. + // Otherwise, enter this "if" and place the 1 node on the stack, + if( depth <= nbits_minus_ntail ) { + if( stackptr < stacksize_minus_1 ) { + stackptr++; + ptr=stackptr; + } else { // stack full + while( buckets[low_bucket] == 0 ) { //write latest to where the top of the lowest bucket points + low_bucket++; + } + ptr=buckets[low_bucket]; + buckets[low_bucket]=stack[ptr].jpointer; //make bucket point to next older entry + } + + bucket=(totmet1>>5)+200; //this may not be safe on all compilers + if( bucket > high_bucket ) high_bucket=bucket; + if( bucket < low_bucket ) low_bucket=bucket; + + stack[ptr].encstate=encstate+1; + stack[ptr].gamma=totmet1; + stack[ptr].depth=depth; + stack[ptr].jpointer=buckets[bucket]; + buckets[bucket]=ptr; + } + + // pick off the latest entry from the high bucket + while( buckets[high_bucket] == 0 ) { + high_bucket--; + } + ptr=buckets[high_bucket]; + buckets[high_bucket]=stack[ptr].jpointer; + depth=stack[ptr].depth; + gamma=stack[ptr].gamma; + encstate=stack[ptr].encstate; + + // we are done if the top entry on the stack is at depth nbits + if (depth == nbits) { + break; + } + } + + *cycles = i+1; + *metric = gamma; /* Return final path metric */ + + // printf("cycles %d stackptr=%d, depth=%d, gamma=%d, encstate=%lx\n", + // *cycles, stackptr, depth, *metric, encstate); + + for (i=0; i<7; i++) { + data[i]=(encstate>>(48-i*8))&(0x00000000000000ff); + } + for (i=7; i<11; i++) { + data[i]=0; + } + + if(*cycles/nbits >= maxcycles) //timed out + { + return -1; + } + return 0; //success +} diff --git a/lib/wsprd/jelinek.h b/lib/wsprd/jelinek.h new file mode 100644 index 00000000..64ecdb96 --- /dev/null +++ b/lib/wsprd/jelinek.h @@ -0,0 +1,26 @@ +#ifndef JELINEK_H +#define JELINEK_H + +#include + +struct snode { + uint64_t encstate; // Encoder state + int gamma; // Cumulative metric to this node + unsigned int depth; // depth of this node + unsigned int jpointer; +}; + +struct snode *stack; + +int jelinek(unsigned int *metric, + unsigned int *cycles, + unsigned char *data, + unsigned char *symbols, + unsigned int nbits, + unsigned int stacksize, + struct snode *stack, + int mettab[2][256], + unsigned int maxcycles); + +#endif + diff --git a/lib/wsprd/metric_tables.c b/lib/wsprd/metric_tables.c new file mode 100644 index 00000000..973651d7 --- /dev/null +++ b/lib/wsprd/metric_tables.c @@ -0,0 +1,138 @@ +/******************************************************************************* +* 4 metric tables calculated via simulation for 2-FSK with Es/No=0,3,6,9 dB +* tables were calculated for constant rms noise level of 50. The symbol vector +* should be normalized to have rms amplitude equal to "symbol_scale". +********************************************************************************/ +//float symbol_scale[5]={42.6, 53.3, 72.7, 100.2, 125.4}; +float metric_tables[5][256]={ + {0.9782, 0.9695, 0.9689, 0.9669, 0.9666, 0.9653, 0.9638, 0.9618, 0.9599, 0.9601, + 0.9592, 0.9570, 0.9556, 0.9540, 0.9525, 0.9527, 0.9486, 0.9477, 0.9450, 0.9436, + 0.9424, 0.9400, 0.9381, 0.9360, 0.9340, 0.9316, 0.9301, 0.9272, 0.9254, 0.9224, + 0.9196, 0.9171, 0.9154, 0.9123, 0.9076, 0.9061, 0.9030, 0.9000, 0.8965, 0.8934, + 0.8903, 0.8874, 0.8834, 0.8792, 0.8760, 0.8726, 0.8685, 0.8639, 0.8599, 0.8550, + 0.8504, 0.8459, 0.8422, 0.8364, 0.8320, 0.8262, 0.8215, 0.8159, 0.8111, 0.8052, + 0.7996, 0.7932, 0.7878, 0.7812, 0.7745, 0.7685, 0.7616, 0.7550, 0.7479, 0.7405, + 0.7336, 0.7255, 0.7184, 0.7102, 0.7016, 0.6946, 0.6860, 0.6769, 0.6687, 0.6598, + 0.6503, 0.6416, 0.6325, 0.6219, 0.6122, 0.6016, 0.5920, 0.5818, 0.5711, 0.5606, + 0.5487, 0.5374, 0.5266, 0.5142, 0.5020, 0.4908, 0.4784, 0.4663, 0.4532, 0.4405, + 0.4271, 0.4144, 0.4006, 0.3865, 0.3731, 0.3594, 0.3455, 0.3304, 0.3158, 0.3009, + 0.2858, 0.2708, 0.2560, 0.2399, 0.2233, 0.2074, 0.1919, 0.1756, 0.1590, 0.1427, + 0.1251, 0.1074, 0.0905, 0.0722, 0.0550, 0.0381, 0.0183, 0.0000, -0.0185, -0.0391, + -0.0571, -0.0760, -0.0966, -0.1160, -0.1370, -0.1584, -0.1787, -0.1999, -0.2214, -0.2423, + -0.2643, -0.2879, -0.3114, -0.3336, -0.3568, -0.3806, -0.4050, -0.4293, -0.4552, -0.4798, + -0.5046, -0.5296, -0.5564, -0.5836, -0.6093, -0.6372, -0.6645, -0.6933, -0.7208, -0.7495, + -0.7763, -0.8065, -0.8378, -0.8660, -0.8964, -0.9293, -0.9592, -0.9907, -1.0214, -1.0509, + -1.0850, -1.1168, -1.1528, -1.1847, -1.2157, -1.2511, -1.2850, -1.3174, -1.3540, -1.3900, + -1.4201, -1.4580, -1.4956, -1.5292, -1.5683, -1.6030, -1.6411, -1.6789, -1.7147, -1.7539, + -1.7887, -1.8289, -1.8699, -1.9043, -1.9469, -1.9849, -2.0267, -2.0610, -2.1028, -2.1391, + -2.1855, -2.2215, -2.2712, -2.3033, -2.3440, -2.3870, -2.4342, -2.4738, -2.5209, -2.5646, + -2.6016, -2.6385, -2.6868, -2.7356, -2.7723, -2.8111, -2.8524, -2.9009, -2.9428, -2.9879, + -3.0103, -3.0832, -3.1340, -3.1628, -3.2049, -3.2557, -3.3101, -3.3453, -3.4025, -3.4317, + -3.4828, -3.5270, -3.5745, -3.6181, -3.6765, -3.7044, -3.7410, -3.8118, -3.8368, -3.9549, + -3.9488, -3.9941, -4.0428, -4.0892, -4.1648, -4.1965, -4.1892, -4.2565, -4.3356, -4.3948, + -4.4481, -4.4607, -4.5533, -4.5809, -4.5927, -5.1047}, + {0.9978, 0.9962, 0.9961, 0.9959, 0.9958, 0.9954, 0.9949, 0.9950, 0.9947, 0.9942, + 0.9940, 0.9939, 0.9933, 0.9931, 0.9928, 0.9924, 0.9921, 0.9916, 0.9911, 0.9909, + 0.9903, 0.9900, 0.9892, 0.9887, 0.9883, 0.9877, 0.9869, 0.9863, 0.9857, 0.9848, + 0.9842, 0.9835, 0.9825, 0.9817, 0.9808, 0.9799, 0.9791, 0.9777, 0.9767, 0.9757, + 0.9744, 0.9729, 0.9716, 0.9704, 0.9690, 0.9674, 0.9656, 0.9641, 0.9625, 0.9609, + 0.9587, 0.9567, 0.9548, 0.9524, 0.9501, 0.9478, 0.9453, 0.9426, 0.9398, 0.9371, + 0.9339, 0.9311, 0.9277, 0.9242, 0.9206, 0.9168, 0.9131, 0.9087, 0.9043, 0.8999, + 0.8953, 0.8907, 0.8857, 0.8803, 0.8747, 0.8690, 0.8632, 0.8572, 0.8507, 0.8439, + 0.8368, 0.8295, 0.8217, 0.8138, 0.8058, 0.7972, 0.7883, 0.7784, 0.7694, 0.7597, + 0.7489, 0.7378, 0.7269, 0.7152, 0.7030, 0.6911, 0.6782, 0.6643, 0.6506, 0.6371, + 0.6211, 0.6054, 0.5897, 0.5740, 0.5565, 0.5393, 0.5214, 0.5027, 0.4838, 0.4643, + 0.4436, 0.4225, 0.4004, 0.3787, 0.3562, 0.3324, 0.3089, 0.2839, 0.2584, 0.2321, + 0.2047, 0.1784, 0.1499, 0.1213, 0.0915, 0.0628, 0.0314, 0.0000, -0.0321, -0.0657, + -0.0977, -0.1324, -0.1673, -0.2036, -0.2387, -0.2768, -0.3150, -0.3538, -0.3936, -0.4327, + -0.4739, -0.5148, -0.5561, -0.6000, -0.6438, -0.6889, -0.7331, -0.7781, -0.8247, -0.8712, + -0.9177, -0.9677, -1.0142, -1.0631, -1.1143, -1.1686, -1.2169, -1.2680, -1.3223, -1.3752, + -1.4261, -1.4806, -1.5356, -1.5890, -1.6462, -1.7041, -1.7591, -1.8124, -1.8735, -1.9311, + -1.9891, -2.0459, -2.1048, -2.1653, -2.2248, -2.2855, -2.3466, -2.4079, -2.4668, -2.5263, + -2.5876, -2.6507, -2.7142, -2.7761, -2.8366, -2.8995, -2.9620, -3.0279, -3.0973, -3.1576, + -3.2238, -3.2890, -3.3554, -3.4215, -3.4805, -3.5518, -3.6133, -3.6812, -3.7473, -3.8140, + -3.8781, -3.9450, -4.0184, -4.0794, -4.1478, -4.2241, -4.2853, -4.3473, -4.4062, -4.4839, + -4.5539, -4.6202, -4.6794, -4.7478, -4.8309, -4.9048, -4.9669, -5.0294, -5.1194, -5.1732, + -5.2378, -5.3094, -5.3742, -5.4573, -5.5190, -5.5728, -5.6637, -5.7259, -5.7843, -5.8854, + -5.9553, -6.0054, -6.0656, -6.1707, -6.2241, -6.3139, -6.3393, -6.4356, -6.5153, -6.5758, + -6.6506, -6.7193, -6.7542, -6.8942, -6.9219, -6.9605, -7.1013, -7.1895, -7.1549, -7.2799, + -7.4119, -7.4608, -7.5256, -7.5879, -7.7598, -8.4120}, + {0.9999, 0.9998, 0.9998, 0.9998, 0.9998, 0.9998, 0.9997, 0.9997, 0.9997, 0.9997, + 0.9997, 0.9996, 0.9996, 0.9996, 0.9995, 0.9995, 0.9994, 0.9994, 0.9994, 0.9993, + 0.9993, 0.9992, 0.9991, 0.9991, 0.9990, 0.9989, 0.9988, 0.9988, 0.9988, 0.9986, + 0.9985, 0.9984, 0.9983, 0.9982, 0.9980, 0.9979, 0.9977, 0.9976, 0.9974, 0.9971, + 0.9969, 0.9968, 0.9965, 0.9962, 0.9960, 0.9957, 0.9953, 0.9950, 0.9947, 0.9941, + 0.9937, 0.9933, 0.9928, 0.9922, 0.9917, 0.9911, 0.9904, 0.9897, 0.9890, 0.9882, + 0.9874, 0.9863, 0.9855, 0.9843, 0.9832, 0.9819, 0.9806, 0.9792, 0.9777, 0.9760, + 0.9743, 0.9724, 0.9704, 0.9683, 0.9659, 0.9634, 0.9609, 0.9581, 0.9550, 0.9516, + 0.9481, 0.9446, 0.9406, 0.9363, 0.9317, 0.9270, 0.9218, 0.9160, 0.9103, 0.9038, + 0.8972, 0.8898, 0.8822, 0.8739, 0.8647, 0.8554, 0.8457, 0.8357, 0.8231, 0.8115, + 0.7984, 0.7854, 0.7704, 0.7556, 0.7391, 0.7210, 0.7038, 0.6840, 0.6633, 0.6408, + 0.6174, 0.5939, 0.5678, 0.5410, 0.5137, 0.4836, 0.4524, 0.4193, 0.3850, 0.3482, + 0.3132, 0.2733, 0.2315, 0.1891, 0.1435, 0.0980, 0.0493, 0.0000, -0.0510, -0.1052, + -0.1593, -0.2177, -0.2759, -0.3374, -0.4005, -0.4599, -0.5266, -0.5935, -0.6626, -0.7328, + -0.8051, -0.8757, -0.9498, -1.0271, -1.1019, -1.1816, -1.2642, -1.3459, -1.4295, -1.5077, + -1.5958, -1.6818, -1.7647, -1.8548, -1.9387, -2.0295, -2.1152, -2.2154, -2.3011, -2.3904, + -2.4820, -2.5786, -2.6730, -2.7652, -2.8616, -2.9546, -3.0526, -3.1445, -3.2445, -3.3416, + -3.4357, -3.5325, -3.6324, -3.7313, -3.8225, -3.9209, -4.0248, -4.1278, -4.2261, -4.3193, + -4.4220, -4.5262, -4.6214, -4.7242, -4.8234, -4.9245, -5.0298, -5.1250, -5.2232, -5.3267, + -5.4332, -5.5342, -5.6431, -5.7270, -5.8401, -5.9350, -6.0407, -6.1418, -6.2363, -6.3384, + -6.4536, -6.5429, -6.6582, -6.7433, -6.8438, -6.9478, -7.0789, -7.1894, -7.2714, -7.3815, + -7.4810, -7.5575, -7.6852, -7.8071, -7.8580, -7.9724, -8.1000, -8.2207, -8.2867, -8.4017, + -8.5287, -8.6347, -8.7082, -8.8319, -8.9448, -9.0355, -9.1885, -9.2095, -9.2863, -9.4186, + -9.5064, -9.6386, -9.7207, -9.8286, -9.9453, -10.0701, -10.1735, -10.3001, -10.2858, -10.5427, + -10.5982, -10.7361, -10.7042, -10.9212, -11.0097, -11.0469, -11.1155, -11.2812, -11.3472, -11.4988, + -11.5327, -11.6692, -11.9376, -11.8606, -12.1372, -13.2539}, + {1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, + 0.9999, 0.9998, 0.9998, 0.9998, 0.9998, 0.9997, 0.9997, 0.9997, 0.9997, 0.9996, + 0.9996, 0.9995, 0.9995, 0.9994, 0.9994, 0.9993, 0.9992, 0.9991, 0.9991, 0.9989, + 0.9988, 0.9986, 0.9985, 0.9983, 0.9981, 0.9980, 0.9977, 0.9974, 0.9971, 0.9968, + 0.9965, 0.9962, 0.9956, 0.9950, 0.9948, 0.9941, 0.9933, 0.9926, 0.9919, 0.9910, + 0.9899, 0.9889, 0.9877, 0.9863, 0.9845, 0.9829, 0.9811, 0.9791, 0.9769, 0.9741, + 0.9716, 0.9684, 0.9645, 0.9611, 0.9563, 0.9519, 0.9463, 0.9406, 0.9344, 0.9272, + 0.9197, 0.9107, 0.9016, 0.8903, 0.8791, 0.8653, 0.8523, 0.8357, 0.8179, 0.7988, + 0.7779, 0.7562, 0.7318, 0.7024, 0.6753, 0.6435, 0.6089, 0.5700, 0.5296, 0.4860, + 0.4366, 0.3855, 0.3301, 0.2735, 0.2114, 0.1443, 0.0682, 0.0000, -0.0715, -0.1604, + -0.2478, -0.3377, -0.4287, -0.5277, -0.6291, -0.7384, -0.8457, -0.9559, -1.0742, -1.1913, + -1.3110, -1.4238, -1.5594, -1.6854, -1.8093, -1.9414, -2.0763, -2.2160, -2.3611, -2.4876, + -2.6374, -2.7710, -2.9225, -3.0591, -3.2077, -3.3452, -3.4916, -3.6316, -3.7735, -3.9296, + -4.0682, -4.2334, -4.3607, -4.5270, -4.6807, -4.8108, -4.9753, -5.1212, -5.2631, -5.4042, + -5.5510, -5.7227, -5.8794, -6.0244, -6.1677, -6.3271, -6.4862, -6.6130, -6.7449, -6.9250, + -7.1232, -7.1736, -7.3628, -7.5596, -7.6906, -7.8129, -7.9817, -8.1440, -8.3016, -8.4797, + -8.5734, -8.7692, -8.9198, -9.0610, -9.1746, -9.3536, -9.5939, -9.6957, -9.8475, -9.9639, + -10.1730, -10.2427, -10.4573, -10.5413, -10.7303, -10.9339, -11.0215, -11.2047, -11.2894, -11.4572, + -11.6256, -11.7794, -11.8801, -12.1717, -12.2354, -12.3686, -12.6195, -12.6527, -12.8247, -12.9560, + -13.3265, -13.1667, -13.4274, -13.6064, -13.5515, -13.9501, -13.9926, -14.4049, -14.1653, -14.4348, + -14.7983, -14.7807, -15.2349, -15.3536, -15.3026, -15.2739, -15.7170, -16.2161, -15.9185, -15.9490, + -16.6258, -16.5568, -16.4318, -16.7999, -16.4101, -17.6393, -17.7643, -17.2644, -17.5973, -17.0403, + -17.7039, -18.0073, -18.1840, -18.3848, -18.6286, -20.7063}, + {1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, + 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, + 0.9999, 0.9998, 0.9998, 0.9998, 0.9998, 0.9997, 0.9997, 0.9997, 0.9997, 0.9996, + 0.9996, 0.9995, 0.9995, 0.9994, 0.9994, 0.9993, 0.9992, 0.9991, 0.9991, 0.9989, + 0.9988, 0.9986, 0.9985, 0.9983, 0.9981, 0.9980, 0.9977, 0.9974, 0.9971, 0.9968, + 0.9965, 0.9962, 0.9956, 0.9950, 0.9948, 0.9941, 0.9933, 0.9926, 0.9919, 0.9910, + 0.9899, 0.9889, 0.9877, 0.9863, 0.9845, 0.9829, 0.9811, 0.9791, 0.9769, 0.9741, + 0.9716, 0.9684, 0.9645, 0.9611, 0.9563, 0.9519, 0.9463, 0.9406, 0.9344, 0.9272, + 0.9197, 0.9107, 0.9016, 0.8903, 0.8791, 0.8653, 0.8523, 0.8357, 0.8179, 0.7988, + 0.7779, 0.7562, 0.7318, 0.7024, 0.6753, 0.6435, 0.6089, 0.5700, 0.5296, 0.4860, + 0.4366, 0.3855, 0.3301, 0.2735, 0.2114, 0.1443, 0.0682, 0.0000, -0.0715, -0.1604, + -0.2478, -0.3377, -0.4287, -0.5277, -0.6291, -0.7384, -0.8457, -0.9559, -1.0742, -1.1913, + -1.3110, -1.4238, -1.5594, -1.6854, -1.8093, -1.9414, -2.0763, -2.2160, -2.3611, -2.4876, + -2.6374, -2.7710, -2.9225, -3.0591, -3.2077, -3.3452, -3.4916, -3.6316, -3.7735, -3.9296, + -4.0682, -4.2334, -4.3607, -4.5270, -4.6807, -4.8108, -4.9753, -5.1212, -5.2631, -5.4042, + -5.5510, -5.7227, -5.8794, -6.0244, -6.1677, -6.3271, -6.4862, -6.6130, -6.7449, -6.9250, + -7.1232, -7.1736, -7.3628, -7.5596, -7.6906, -7.8129, -7.9817, -8.1440, -8.3016, -8.4797, + -8.5734, -8.7692, -8.9198, -9.0610, -9.1746, -9.3536, -9.5939, -9.6957, -9.8475, -9.9639, + -10.1730, -10.2427, -10.4573, -11.7794, -11.8801, -12.1717, -12.2354, -12.3686, -12.6195, -12.6527, + -12.8247, -12.9560, -13.3265, -13.1667, -13.4274, -13.6064, -13.5515, -13.9501, -13.9926, -14.4049, + -14.1653, -14.4348, -14.7983, -14.7807, -15.2349, -15.3536, -15.3026, -15.2739, -15.7170, -16.2161, + -15.9185, -15.9490, -16.6258, -16.5568, -16.4318, -16.7999, -16.4101, -17.6393, -17.7643, -17.2644, + -17.5973, -17.0403, -17.7039, -18.0073, -18.1840, -18.3848, -18.6286, -20.7063, 1.43370769e-019, + 2.64031087e-006, 6.6908396e+031, 1.77537994e+028, 2.79322819e+020, 1.94326e-019, + 0.00019371575, 2.80722121e-041}}; diff --git a/lib/wsprd/mettab.c b/lib/wsprd/mettab.c new file mode 100644 index 00000000..f188c0cc --- /dev/null +++ b/lib/wsprd/mettab.c @@ -0,0 +1,76 @@ +/* + This file is part of wsprd. + + File name: mettab.c + Description: Metric table for sequential Fano decoder. + + Copyright 2008-2015, Joseph Taylor, K1JT + License: GNU GPL v3 + + This program 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 of the License, or + (at your option) any later version. + + This program 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 this program. If not, see . +*/ + +int mettab[2][256]={ + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, + 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, + -1, -1, -1, -2, -2, -3, -4, -4, -5, -6, + -7, -7, -8, -9, -10, -11, -12, -12, -13, -14, + -15, -16, -17, -17, -18, -19, -20, -21, -22, -22, + -23, -24, -25, -26, -26, -27, -28, -29, -30, -30, + -31, -32, -33, -33, -34, -35, -36, -36, -37, -38, + -38, -39, -40, -41, -41, -42, -43, -43, -44, -45, + -45, -46, -47, -47, -48, -49, -49, -50, -51, -51, + -52, -53, -53, -54, -54, -55, -56, -56, -57, -57, + -58, -59, -59, -60, -60, -61, -62, -62, -62, -63, + -64, -64, -65, -65, -66, -67, -67, -67, -68, -69, + -69, -70, -70, -71, -72, -72, -72, -72, -73, -74, + -75, -75, -75, -77, -76, -76, -78, -78, -80, -81, + -80, -79, -83, -82, -81, -82, -82, -83, -84, -84, + -84, -87, -86, -87, -88,-105, -94,-105, -88, -87, + -86, -87, -84, -84, -84, -83, -82, -82, -81, -82, + -83, -79, -80, -81, -80, -78, -78, -76, -76, -77, + -75, -75, -75, -74, -73, -72, -72, -72, -72, -71, + -70, -70, -69, -69, -68, -67, -67, -67, -66, -65, + -65, -64, -64, -63, -62, -62, -62, -61, -60, -60, + -59, -59, -58, -57, -57, -56, -56, -55, -54, -54, + -53, -53, -52, -51, -51, -50, -49, -49, -48, -47, + -47, -46, -45, -45, -44, -43, -43, -42, -41, -41, + -40, -39, -38, -38, -37, -36, -36, -35, -34, -33, + -33, -32, -31, -30, -30, -29, -28, -27, -26, -26, + -25, -24, -23, -22, -22, -21, -20, -19, -18, -17, + -17, -16, -15, -14, -13, -12, -12, -11, -10, -9, + -8, -7, -7, -6, -5, -4, -4, -3, -2, -2, + -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5 }; diff --git a/lib/wsprd/nhash.c b/lib/wsprd/nhash.c new file mode 100644 index 00000000..9376954f --- /dev/null +++ b/lib/wsprd/nhash.c @@ -0,0 +1,372 @@ +/* + This file is part of wsprd. + + File name: nhash.c + + *------------------------------------------------------------------------------ + * + * This file is part of the WSPR application, Weak Signal Propogation Reporter + * + * File Name: nhash.c + * Description: Functions to produce 32-bit hashes for hash table lookup + * + * Copyright (C) 2008-2014 Joseph Taylor, K1JT + * License: GNU GPL v3+ + * + * This program 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 of the License, or (at your option) any later + * version. + * + * This program 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 + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Files: lookup3.c + * Copyright: Copyright (C) 2006 Bob Jenkins + * License: public-domain + * You may use this code any way you wish, private, educational, or commercial. + * It's free. + * + *------------------------------------------------------------------------------- +*/ + +/* +These are functions for producing 32-bit hashes for hash table lookup. +hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() +are externally useful functions. Routines to test the hash are included +if SELF_TEST is defined. You can use this free for any purpose. It's in +the public domain. It has no warranty. + +You probably want to use hashlittle(). hashlittle() and hashbig() +hash byte arrays. hashlittle() is is faster than hashbig() on +little-endian machines. Intel and AMD are little-endian machines. +On second thought, you probably want hashlittle2(), which is identical to +hashlittle() except it returns two 32-bit hashes for the price of one. +You could implement hashbig2() if you wanted but I haven't bothered here. + +If you want to find a hash of, say, exactly 7 integers, do + a = i1; b = i2; c = i3; + mix(a,b,c); + a += i4; b += i5; c += i6; + mix(a,b,c); + a += i7; + final(a,b,c); +then use c as the hash value. If you have a variable length array of +4-byte integers to hash, use hashword(). If you have a byte array (like +a character string), use hashlittle(). If you have several byte arrays, or +a mix of things, see the comments above hashlittle(). + +Why is this so big? I read 12 bytes at a time into 3 4-byte integers, +then mix those integers. This is fast (you can do a lot more thorough +mixing with 12*3 instructions on 3 integers than you can with 3 instructions +on 1 byte), but shoehorning those bytes into integers efficiently is messy. +*/ + +#define SELF_TEST 1 + +#include /* defines printf for tests */ +#include /* defines time_t for timings in the test */ +#include "nhash.h" +//#include /* attempt to define endianness */ +//#ifdef linux +//# include /* attempt to define endianness */ +//#endif + +#define HASH_LITTLE_ENDIAN 1 + +#define hashsize(n) ((uint32_t)1<<(n)) +#define hashmask(n) (hashsize(n)-1) +#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) + +/* +------------------------------------------------------------------------------- +mix -- mix 3 32-bit values reversibly. + +This is reversible, so any information in (a,b,c) before mix() is +still in (a,b,c) after mix(). + +If four pairs of (a,b,c) inputs are run through mix(), or through +mix() in reverse, there are at least 32 bits of the output that +are sometimes the same for one pair and different for another pair. +This was tested for: +* pairs that differed by one bit, by two bits, in any combination + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). +* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. +* the base values were pseudorandom, all zero but one bit set, or + all zero plus a counter that starts at zero. + +Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that +satisfy this are + 4 6 8 16 19 4 + 9 15 3 18 27 15 + 14 9 3 7 17 3 +Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing +for "differ" defined as + with a one-bit base and a two-bit delta. I +used http://burtleburtle.net/bob/hash/avalanche.html to choose +the operations, constants, and arrangements of the variables. + +This does not achieve avalanche. There are input bits of (a,b,c) +that fail to affect some output bits of (a,b,c), especially of a. The +most thoroughly mixed value is c, but it doesn't really even achieve +avalanche in c. + +This allows some parallelism. Read-after-writes are good at doubling +the number of bits affected, so the goal of mixing pulls in the opposite +direction as the goal of parallelism. I did what I could. Rotates +seem to cost as much as shifts on every machine I could lay my hands +on, and rotates are much kinder to the top and bottom bits, so I used +rotates. +------------------------------------------------------------------------------- +*/ +#define mix(a,b,c) \ +{ \ + a -= c; a ^= rot(c, 4); c += b; \ + b -= a; b ^= rot(a, 6); a += c; \ + c -= b; c ^= rot(b, 8); b += a; \ + a -= c; a ^= rot(c,16); c += b; \ + b -= a; b ^= rot(a,19); a += c; \ + c -= b; c ^= rot(b, 4); b += a; \ +} + +/* +------------------------------------------------------------------------------- +final -- final mixing of 3 32-bit values (a,b,c) into c + +Pairs of (a,b,c) values differing in only a few bits will usually +produce values of c that look totally different. This was tested for +* pairs that differed by one bit, by two bits, in any combination + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). +* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. +* the base values were pseudorandom, all zero but one bit set, or + all zero plus a counter that starts at zero. + +These constants passed: + 14 11 25 16 4 14 24 + 12 14 25 16 4 14 24 +and these came close: + 4 8 15 26 3 22 24 + 10 8 15 26 3 22 24 + 11 8 15 26 3 22 24 +------------------------------------------------------------------------------- +*/ +#define final(a,b,c) \ +{ \ + c ^= b; c -= rot(b,14); \ + a ^= c; a -= rot(c,11); \ + b ^= a; b -= rot(a,25); \ + c ^= b; c -= rot(b,16); \ + a ^= c; a -= rot(c,4); \ + b ^= a; b -= rot(a,14); \ + c ^= b; c -= rot(b,24); \ +} + +/* +------------------------------------------------------------------------------- +hashlittle() -- hash a variable-length key into a 32-bit value + k : the key (the unaligned variable-length array of bytes) + length : the length of the key, counting by bytes + initval : can be any 4-byte value +Returns a 32-bit value. Every bit of the key affects every bit of +the return value. Two keys differing by one or two bits will have +totally different hash values. + +The best hash table sizes are powers of 2. There is no need to do +mod a prime (mod is sooo slow!). If you need less than 32 bits, +use a bitmask. For example, if you need only 10 bits, do + h = (h & hashmask(10)); +In which case, the hash table should have hashsize(10) elements. + +If you are hashing n strings (uint8_t **)k, do it like this: + for (i=0, h=0; i 12) + { + a += k[0]; + b += k[1]; + c += k[2]; + mix(a,b,c); + length -= 12; + k += 3; + } + + /*----------------------------- handle the last (probably partial) block */ + /* + * "k[2]&0xffffff" actually reads beyond the end of the string, but + * then masks off the part it's not allowed to read. Because the + * string is aligned, the masked-off tail is in the same word as the + * rest of the string. Every machine with memory protection I've seen + * does it on word boundaries, so is OK with this. But VALGRIND will + * still catch it and complain. The masking trick does make the hash + * noticably faster for short strings (like English words). + */ +#ifndef VALGRIND + + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; + case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; + case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=k[1]&0xffffff; a+=k[0]; break; + case 6 : b+=k[1]&0xffff; a+=k[0]; break; + case 5 : b+=k[1]&0xff; a+=k[0]; break; + case 4 : a+=k[0]; break; + case 3 : a+=k[0]&0xffffff; break; + case 2 : a+=k[0]&0xffff; break; + case 1 : a+=k[0]&0xff; break; + case 0 : return c; /* zero length strings require no mixing */ + } + +#else /* make valgrind happy */ + + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]; break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ + case 1 : a+=k8[0]; break; + case 0 : return c; + } + +#endif /* !valgrind */ + + } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { + const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ + const uint8_t *k8; + + /*--------------- all but last block: aligned reads and different mixing */ + while (length > 12) + { + a += k[0] + (((uint32_t)k[1])<<16); + b += k[2] + (((uint32_t)k[3])<<16); + c += k[4] + (((uint32_t)k[5])<<16); + mix(a,b,c); + length -= 12; + k += 6; + } + + /*----------------------------- handle the last (probably partial) block */ + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[4]+(((uint32_t)k[5])<<16); + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=k[4]; + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=k[2]; + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=k[0]; + break; + case 1 : a+=k8[0]; + break; + case 0 : return c; /* zero length requires no mixing */ + } + + } else { /* need to read the key one byte at a time */ + const uint8_t *k = (const uint8_t *)key; + + /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + a += ((uint32_t)k[1])<<8; + a += ((uint32_t)k[2])<<16; + a += ((uint32_t)k[3])<<24; + b += k[4]; + b += ((uint32_t)k[5])<<8; + b += ((uint32_t)k[6])<<16; + b += ((uint32_t)k[7])<<24; + c += k[8]; + c += ((uint32_t)k[9])<<8; + c += ((uint32_t)k[10])<<16; + c += ((uint32_t)k[11])<<24; + mix(a,b,c); + length -= 12; + k += 12; + } + + /*-------------------------------- last block: affect all 32 bits of (c) */ + switch(length) /* all the case statements fall through */ + { + case 12: c+=((uint32_t)k[11])<<24; + case 11: c+=((uint32_t)k[10])<<16; + case 10: c+=((uint32_t)k[9])<<8; + case 9 : c+=k[8]; + case 8 : b+=((uint32_t)k[7])<<24; + case 7 : b+=((uint32_t)k[6])<<16; + case 6 : b+=((uint32_t)k[5])<<8; + case 5 : b+=k[4]; + case 4 : a+=((uint32_t)k[3])<<24; + case 3 : a+=((uint32_t)k[2])<<16; + case 2 : a+=((uint32_t)k[1])<<8; + case 1 : a+=k[0]; + break; + case 0 : return c; + } + } + + final(a,b,c); + c=(32767&c); + + return c; +} diff --git a/lib/wsprd/nhash.h b/lib/wsprd/nhash.h new file mode 100644 index 00000000..a111916b --- /dev/null +++ b/lib/wsprd/nhash.h @@ -0,0 +1,21 @@ +#ifndef NHASH_H_ +#define NHASH_H_ + +#ifdef Win32 +#include "win_stdint.h" /* defines uint32_t etc */ +#else +#include +#include /* defines uint32_t etc */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t nhash( const void * key, size_t length, uint32_t initval); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wsprd/t2.f90 b/lib/wsprd/t2.f90 new file mode 100644 index 00000000..0f214db4 --- /dev/null +++ b/lib/wsprd/t2.f90 @@ -0,0 +1,11 @@ +program t2 + + df=375.0/65536.0 + do i=1,65536 + w=1.0/(1.0 + ((i-32768)/26214.0)**20) + f=(i-32768)*df + write(13,1010) f,w +1010 format(2f15.6) + enddo + +end program t2 diff --git a/lib/wsprd/tab.c b/lib/wsprd/tab.c new file mode 100644 index 00000000..e330c757 --- /dev/null +++ b/lib/wsprd/tab.c @@ -0,0 +1,41 @@ +/* + This file is part of wsprd. + + File name: tab.c + Description: 8-bit parity lookup table. +*/ +unsigned char Partab[] = { + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1, + 0, 1, 1, 0, 1, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, +}; + diff --git a/lib/wsprd/test_wspr.f90 b/lib/wsprd/test_wspr.f90 new file mode 100644 index 00000000..86e29186 --- /dev/null +++ b/lib/wsprd/test_wspr.f90 @@ -0,0 +1,61 @@ +program test_wspr + +! This program provides examples of the source encoding, convolutional +! error-control coding, bit and symbol ordering, and synchronizing +! information contained in WSPR messages. + + character*22 msg,msg2 + character*23 msg3 + character*1 err2,err3 + integer*1 data0(11) + logical lfile + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.1) then + print*,'Usage: test_wspr "message"' + go to 999 + endif + call getarg(1,msg) !Get message from command line + call unpk(data0,1,msg3) !Read the C hashtable + lfile=msg(1:2).eq."-t" + if(lfile) open(10,file="messages.txt",status="old") + + do imsg=1,999 + if(lfile) read(10,1001,end=900) msg +1001 format(a22) + + data0=0 + call wqencode(msg,ntype0,data0) !Source encoding +! write(*,1002) data0(1:7) +!1002 format('Source-encoded message (50 bits, hex):',7z3.2) +! data0(8:11)=0 + + call wqdecode(data0,msg2,ntype1) + +! write(*,1020) ntype1 +!1020 format('Message type: ',i7) +! write(*,1030) msg2 +!1030 format('Decoded message: ',a22) + + call unpk(data0,0,msg3) + do i=1,23 + if(ichar(msg3(i:i)).eq.0) then + msg3(i:)=" " + exit + endif + enddo + + err2=' ' + err3=' ' + if(msg2.ne.msg) err2='*' + if(msg3.ne.msg) err3='*' + + write(*,1040) msg,err2,msg2,err3,msg3 +1040 format(a22,1x,a1,1x,a22,1x,a1,1x,a22) + if(.not.lfile) exit + enddo +900 call unpk(data0,2,msg3) + + +999 end program test_wspr diff --git a/lib/wsprd/unpk.c.obsolete b/lib/wsprd/unpk.c.obsolete new file mode 100644 index 00000000..fae2bcf8 --- /dev/null +++ b/lib/wsprd/unpk.c.obsolete @@ -0,0 +1,124 @@ +/* the routine unpk() is not in wsprd_utils.c */ +#include +#include +#include +#include +#include +#include +#include + +#include "wsprd_utils.h" + +unsigned int nhash_( const void *key, size_t length, uint32_t initval); + +void unpk_(signed char message[], int *nhashtab, char call_loc_pow[]) +{ + int i,n1,n2,n3,ndbm,ihash,nadd,noprint,nh; + char callsign[13],grid[5],grid6[7],cdbm[3]; + static char hashtab[32768][13]; + FILE *fhash; + + if(*nhashtab==1) { + char line[80], hcall[12]; + if( (fhash=fopen("hashtable.txt","r+")) ) { + while (fgets(line, sizeof(line), fhash) != NULL) { + sscanf(line,"%d %s",&nh,hcall); + strcpy(*hashtab+nh*13,hcall); + } + } else { + fhash=fopen("hashtable.txt","w+"); + } + fclose(fhash); + return; + } + + if(*nhashtab==2) { + fhash=fopen("hashtable.txt","w"); + for (i=0; i<32768; i++) { + if( strncmp(hashtab[i],"\0",1) != 0 ) { + fprintf(fhash,"%5d %s\n",i,*hashtab+i*13); + } + } + fclose(fhash); + return; + } + + unpack50(message,&n1,&n2); + unpackcall(n1,callsign); + unpackgrid(n2, grid); + int ntype = (n2&127) - 64; + callsign[12]=0; + grid[4]=0; + +/* + Based on the value of ntype, decide whether this is a Type 1, 2, or + 3 message. + + * Type 1: 6 digit call, grid, power - ntype is positive and is a member + of the set {0,3,7,10,13,17,20...60} + + * Type 2: extended callsign, power - ntype is positive but not + a member of the set of allowed powers + + * Type 3: hash, 6 digit grid, power - ntype is negative. +*/ + + if( (ntype >= 0) && (ntype <= 62) ) { + int nu=ntype%10; + if( nu == 0 || nu == 3 || nu == 7 ) { + ndbm=ntype; + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,grid,4); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); + strcpy(*hashtab+ihash*13,callsign); + } else { + nadd=nu; + if( nu > 3 ) nadd=nu-3; + if( nu > 7 ) nadd=nu-7; + n3=n2/128+32768*(nadd-1); + unpackpfx(n3,callsign); + ndbm=ntype-nadd; + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); + strcpy(*hashtab+ihash*13,callsign); + noprint=0; + } + } else if ( ntype < 0 ) { + ndbm=-(ntype+1); + memset(grid6,0,sizeof(char)*7); + strncat(grid6,callsign+5,1); + strncat(grid6,callsign,5); + ihash=(n2-ntype-64)/128; + if( strncmp(hashtab[ihash],"\0",1) != 0 ) { + sprintf(callsign,"<%s>",hashtab[ihash]); + } else { + sprintf(callsign,"%5s","<...>"); + } + + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,grid6,strlen(grid6)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + + noprint=0; + +// I don't know what to do with these... They show up as "A000AA" grids. + if( ntype == -64 ) noprint=1; + } + // printf("\nUnpacked in C: %s\n",call_loc_pow); +} diff --git a/lib/wsprd/wsprd.c b/lib/wsprd/wsprd.c new file mode 100644 index 00000000..09cd599b --- /dev/null +++ b/lib/wsprd/wsprd.c @@ -0,0 +1,1290 @@ +/* + This file is part of program wsprd, a detector/demodulator/decoder + for the Weak Signal Propagation Reporter (WSPR) mode. + + File name: wsprd.c + + Copyright 2001-2015, Joe Taylor, K1JT + + Much of the present code is based on work by Steven Franke, K9AN, + which in turn was based on earlier work by K1JT. + + Copyright 2014-2015, Steven Franke, K9AN + + License: GNU GPL v3 + + This program 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 of the License, or + (at your option) any later version. + + This program 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 this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fano.h" +#include "jelinek.h" +#include "nhash.h" +#include "wsprd_utils.h" +#include "wsprsim_utils.h" + +#define max(x,y) ((x) > (y) ? (x) : (y)) +// Possible PATIENCE options: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT, +// FFTW_MEASURE, FFTW_PATIENT, FFTW_EXHAUSTIVE +#define PATIENCE FFTW_ESTIMATE +fftwf_plan PLAN1,PLAN2,PLAN3; + +unsigned char pr3[162]= +{1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, + 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, + 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, + 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, + 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, + 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, + 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, + 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, + 0,0}; + +unsigned long nr; + +int printdata=0; + +//*************************************************************************** +unsigned long readc2file(char *ptr_to_infile, float *idat, float *qdat, + double *freq, int *wspr_type) +{ + float *buffer; + double dfreq; + int i,ntrmin; + char *c2file[15]; + FILE* fp; + + buffer=malloc(sizeof(float)*2*65536); + memset(buffer,0,sizeof(float)*2*65536); + + fp = fopen(ptr_to_infile,"rb"); + if (fp == NULL) { + fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile); + return 1; + } + unsigned long nread=fread(c2file,sizeof(char),14,fp); + nread=fread(&ntrmin,sizeof(int),1,fp); + nread=fread(&dfreq,sizeof(double),1,fp); + *freq=dfreq; + nread=fread(buffer,sizeof(float),2*45000,fp); + fclose(fp); + + *wspr_type=ntrmin; + + for(i=0; i<45000; i++) { + idat[i]=buffer[2*i]; + qdat[i]=-buffer[2*i+1]; + } + + if( nread == 2*45000 ) { + return nread/2; + } else { + return 1; + } + free(buffer); +} + +//*************************************************************************** +unsigned long readwavfile(char *ptr_to_infile, int ntrmin, float *idat, float *qdat ) +{ + size_t i, j, npoints; + int nfft1, nfft2, nh2, i0; + double df; + + nfft2=46080; //this is the number of downsampled points that will be returned + nh2=nfft2/2; + + if( ntrmin == 2 ) { + nfft1=nfft2*32; //need to downsample by a factor of 32 + df=12000.0/nfft1; + i0=1500.0/df+0.5; + npoints=114*12000; + } else if ( ntrmin == 15 ) { + nfft1=nfft2*8*32; + df=12000.0/nfft1; + i0=(1500.0+112.5)/df+0.5; + npoints=8*114*12000; + } else { + fprintf(stderr,"This should not happen\n"); + return 1; + } + + float *realin; + fftwf_complex *fftin, *fftout; + + FILE *fp; + short int *buf2; + buf2 = malloc(npoints*sizeof(short int)); + + fp = fopen(ptr_to_infile,"rb"); + if (fp == NULL) { + fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile); + return 1; + } + nr=fread(buf2,2,22,fp); //Read and ignore header + nr=fread(buf2,2,npoints,fp); //Read raw data + fclose(fp); + + realin=(float*) fftwf_malloc(sizeof(float)*nfft1); + fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*nfft1); + PLAN1 = fftwf_plan_dft_r2c_1d(nfft1, realin, fftout, PATIENCE); + + for (i=0; i(size_t)nh2 ) j=j-nfft2; + fftin[i][0]=fftout[j][0]; + fftin[i][1]=fftout[j][1]; + } + + fftwf_free(fftout); + fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*nfft2); + PLAN2 = fftwf_plan_dft_1d(nfft2, fftin, fftout, FFTW_BACKWARD, PATIENCE); + fftwf_execute(PLAN2); + + for (i=0; i<(size_t)nfft2; i++) { + idat[i]=fftout[i][0]/1000.0; + qdat[i]=fftout[i][1]/1000.0; + } + + fftwf_free(fftin); + fftwf_free(fftout); + return nfft2; +} + +//*************************************************************************** +void sync_and_demodulate(float *id, float *qd, long np, + unsigned char *symbols, float *f1, int ifmin, int ifmax, float fstep, + int *shift1, int lagmin, int lagmax, int lagstep, + float *drift1, int symfac, float *sync, int mode) +{ + /*********************************************************************** + * mode = 0: no frequency or drift search. find best time lag. * + * 1: no time lag or drift search. find best frequency. * + * 2: no frequency or time lag search. calculate soft-decision * + * symbols using passed frequency and shift. * + ************************************************************************/ + + static float fplast=-10000.0; + static float dt=1.0/375.0, df=375.0/256.0; + static float pi=3.14159265358979323846; + float twopidt, df15=df*1.5, df05=df*0.5; + + int i, j, k, lag; + float i0[162],q0[162],i1[162],q1[162],i2[162],q2[162],i3[162],q3[162]; + float p0,p1,p2,p3,cmet,totp,syncmax,fac; + float c0[256],s0[256],c1[256],s1[256],c2[256],s2[256],c3[256],s3[256]; + float dphi0, cdphi0, sdphi0, dphi1, cdphi1, sdphi1, dphi2, cdphi2, sdphi2, + dphi3, cdphi3, sdphi3; + float f0=0.0, fp, ss, fbest=0.0, fsum=0.0, f2sum=0.0, fsymb[162]; + int best_shift = 0, ifreq; + + syncmax=-1e30; + if( mode == 0 ) {ifmin=0; ifmax=0; fstep=0.0; f0=*f1;} + if( mode == 1 ) {lagmin=*shift1;lagmax=*shift1;f0=*f1;} + if( mode == 2 ) {lagmin=*shift1;lagmax=*shift1;ifmin=0;ifmax=0;f0=*f1;} + + twopidt=2*pi*dt; + for(ifreq=ifmin; ifreq<=ifmax; ifreq++) { + f0=*f1+ifreq*fstep; + for(lag=lagmin; lag<=lagmax; lag=lag+lagstep) { + ss=0.0; + totp=0.0; + for (i=0; i<162; i++) { + fp = f0 + (*drift1/2.0)*((float)i-81.0)/81.0; + if( i==0 || (fp != fplast) ) { // only calculate sin/cos if necessary + dphi0=twopidt*(fp-df15); + cdphi0=cos(dphi0); + sdphi0=sin(dphi0); + + dphi1=twopidt*(fp-df05); + cdphi1=cos(dphi1); + sdphi1=sin(dphi1); + + dphi2=twopidt*(fp+df05); + cdphi2=cos(dphi2); + sdphi2=sin(dphi2); + + dphi3=twopidt*(fp+df15); + cdphi3=cos(dphi3); + sdphi3=sin(dphi3); + + c0[0]=1; s0[0]=0; + c1[0]=1; s1[0]=0; + c2[0]=1; s2[0]=0; + c3[0]=1; s3[0]=0; + + for (j=1; j<256; j++) { + c0[j]=c0[j-1]*cdphi0 - s0[j-1]*sdphi0; + s0[j]=c0[j-1]*sdphi0 + s0[j-1]*cdphi0; + c1[j]=c1[j-1]*cdphi1 - s1[j-1]*sdphi1; + s1[j]=c1[j-1]*sdphi1 + s1[j-1]*cdphi1; + c2[j]=c2[j-1]*cdphi2 - s2[j-1]*sdphi2; + s2[j]=c2[j-1]*sdphi2 + s2[j-1]*cdphi2; + c3[j]=c3[j-1]*cdphi3 - s3[j-1]*sdphi3; + s3[j]=c3[j-1]*sdphi3 + s3[j-1]*cdphi3; + } + fplast = fp; + } + + i0[i]=0.0; q0[i]=0.0; + i1[i]=0.0; q1[i]=0.0; + i2[i]=0.0; q2[i]=0.0; + i3[i]=0.0; q3[i]=0.0; + + for (j=0; j<256; j++) { + k=lag+i*256+j; + if( (k>0) && (k syncmax ) { //Save best parameters + syncmax=ss; + best_shift=lag; + fbest=f0; + } + } // lag loop + } //freq loop + + if( mode <=1 ) { //Send best params back to caller + *sync=syncmax; + *shift1=best_shift; + *f1=fbest; + return; + } + + if( mode == 2 ) { + *sync=syncmax; + for (i=0; i<162; i++) { //Normalize the soft symbols + fsum=fsum+fsymb[i]/162.0; + f2sum=f2sum+fsymb[i]*fsymb[i]/162.0; + } + fac=sqrt(f2sum-fsum*fsum); + for (i=0; i<162; i++) { + fsymb[i]=symfac*fsymb[i]/fac; + if( fsymb[i] > 127) fsymb[i]=127.0; + if( fsymb[i] < -128 ) fsymb[i]=-128.0; + symbols[i]=fsymb[i] + 128; + } + return; + } + return; +} +/*************************************************************************** + symbol-by-symbol signal subtraction + ****************************************************************************/ +void subtract_signal(float *id, float *qd, long np, + float f0, int shift0, float drift0, unsigned char* channel_symbols) +{ + float dt=1.0/375.0, df=375.0/256.0; + int i, j, k; + float pi=4.*atan(1.0),twopidt, fp; + + float i0,q0; + float c0[256],s0[256]; + float dphi, cdphi, sdphi; + + twopidt=2*pi*dt; + + for (i=0; i<162; i++) { + fp = f0 + ((float)drift0/2.0)*((float)i-81.0)/81.0; + + dphi=twopidt*(fp+((float)channel_symbols[i]-1.5)*df); + cdphi=cos(dphi); + sdphi=sin(dphi); + + c0[0]=1; s0[0]=0; + + for (j=1; j<256; j++) { + c0[j]=c0[j-1]*cdphi - s0[j-1]*sdphi; + s0[j]=c0[j-1]*sdphi + s0[j-1]*cdphi; + } + + i0=0.0; q0=0.0; + + for (j=0; j<256; j++) { + k=shift0+i*256+j; + if( (k>0) & (k0) & (k0) && (k(nsig-1-nfilt/2) ) { + norm=partialsum[nfilt/2+nsig-1-i]; + } else { + norm=1.0; + } + k=shift0+i; + j=i+nfilt; + if( (k>0) && (k path to writeable data files, default=\".\"\n"); + printf(" -c write .c2 file at the end of the first pass\n"); + printf(" -C maximum number of decoder cycles per bit, default 10000\n"); + printf(" -d deeper search. Slower, a few more decodes\n"); + printf(" -e x (x is transceiver dial frequency error in Hz)\n"); + printf(" -f x (x is transceiver dial frequency in MHz)\n"); + printf(" -H do not use (or update) the hash table\n"); + printf(" -J use the stack decoder instead of Fano decoder\n"); + printf(" -m decode wspr-15 .wav file\n"); + printf(" -q quick mode - doesn't dig deep for weak signals\n"); + printf(" -s single pass mode, no subtraction (same as original wsprd)\n"); + printf(" -v verbose mode (shows dupes)\n"); + printf(" -w wideband mode - decode signals within +/- 150 Hz of center\n"); + printf(" -z x (x is fano metric table bias, default is 0.45)\n"); +} + +//*************************************************************************** +int main(int argc, char *argv[]) +{ + char cr[] = "(C) 2016, Steven Franke - K9AN"; + (void)cr; + extern char *optarg; + extern int optind; + int i,j,k; + unsigned char *symbols, *decdata, *channel_symbols; + signed char message[]={-9,13,-35,123,57,-39,64,0,0,0,0}; + char *callsign, *call_loc_pow; + char *ptr_to_infile,*ptr_to_infile_suffix; + char *data_dir=NULL; + char wisdom_fname[200],all_fname[200],spots_fname[200]; + char timer_fname[200],hash_fname[200]; + char uttime[5],date[7]; + int c,delta,maxpts=65536,verbose=0,quickmode=0,more_candidates=0, stackdecoder=0; + int writenoise=0,usehashtable=1,wspr_type=2, ipass; + int writec2=0, npasses=2, subtraction=1; + int shift1, lagmin, lagmax, lagstep, ifmin, ifmax, worth_a_try, not_decoded; + unsigned int nbits=81, stacksize=200000; + unsigned int npoints, metric, cycles, maxnp; + float df=375.0/256.0/2; + float freq0[200],snr0[200],drift0[200],sync0[200]; + int shift0[200]; + float dt=1.0/375.0, dt_print; + double dialfreq_cmdline=0.0, dialfreq, freq_print; + double dialfreq_error=0.0; + float fmin=-110, fmax=110; + float f1, fstep, sync1, drift1; + float psavg[512]; + float *idat, *qdat; + clock_t t0,t00; + float tfano=0.0,treadwav=0.0,tcandidates=0.0,tsync0=0.0; + float tsync1=0.0,tsync2=0.0,ttotal=0.0; + + struct result { char date[7]; char time[5]; float sync; float snr; + float dt; double freq; char message[23]; float drift; + unsigned int cycles; int jitter; }; + struct result decodes[50]; + + char *hashtab; + hashtab=malloc(sizeof(char)*32768*13); + memset(hashtab,0,sizeof(char)*32768*13); + int nh; + symbols=malloc(sizeof(char)*nbits*2); + decdata=malloc(sizeof(char)*11); + channel_symbols=malloc(sizeof(char)*nbits*2); + + callsign=malloc(sizeof(char)*13); + call_loc_pow=malloc(sizeof(char)*23); + float allfreqs[100]; + char allcalls[100][13]; + memset(allfreqs,0,sizeof(float)*100); + memset(allcalls,0,sizeof(char)*100*13); + + int uniques=0, noprint=0, ndecodes_pass=0; + + // Parameters used for performance-tuning: + unsigned int maxcycles=10000; //Decoder timeout limit + float minsync1=0.10; //First sync limit + float minsync2=0.12; //Second sync limit + int iifac=8; //Step size in final DT peakup + int symfac=50; //Soft-symbol normalizing factor + int maxdrift=4; //Maximum (+/-) drift + float minrms=52.0 * (symfac/64.0); //Final test for plausible decoding + delta=60; //Fano threshold step + float bias=0.45; //Fano metric bias (used for both Fano and stack algorithms) + + t00=clock(); + fftwf_complex *fftin, *fftout; +#include "./metric_tables.c" + + int mettab[2][256]; + + idat=malloc(sizeof(float)*maxpts); + qdat=malloc(sizeof(float)*maxpts); + + while ( (c = getopt(argc, argv, "a:cC:de:f:HJmqstwvz:")) !=-1 ) { + switch (c) { + case 'a': + data_dir = optarg; + break; + case 'c': + writec2=1; + break; + case 'C': + maxcycles=(unsigned int) strtoul(optarg,NULL,10); + break; + case 'd': + more_candidates=1; + break; + case 'e': + dialfreq_error = strtod(optarg,NULL); // units of Hz + // dialfreq_error = dial reading - actual, correct frequency + break; + case 'f': + dialfreq_cmdline = strtod(optarg,NULL); // units of MHz + break; + case 'H': + usehashtable = 0; + break; + case 'J': //Stack (Jelinek) decoder, Fano decoder is the default + stackdecoder = 1; + break; + case 'm': //15-minute wspr mode + wspr_type = 15; + break; + case 'q': //no shift jittering + quickmode = 1; + break; + case 's': //single pass mode (same as original wsprd) + subtraction = 0; + npasses = 1; + break; + case 'v': + verbose = 1; + break; + case 'w': + fmin=-150.0; + fmax=150.0; + break; + case 'z': + bias=strtod(optarg,NULL); //fano metric bias (default is 0.45) + break; + case '?': + usage(); + return 1; + } + } + + if( stackdecoder ) { + stack=malloc(stacksize*sizeof(struct snode)); + } + + if( optind+1 > argc) { + usage(); + return 1; + } else { + ptr_to_infile=argv[optind]; + } + + // setup metric table + for(i=0; i<256; i++) { + mettab[0][i]=round( 10*(metric_tables[2][i]-bias) ); + mettab[1][i]=round( 10*(metric_tables[2][255-i]-bias) ); + } + + FILE *fp_fftwf_wisdom_file, *fall_wspr, *fwsprd, *fhash, *ftimer; + strcpy(wisdom_fname,"."); + strcpy(all_fname,"."); + strcpy(spots_fname,"."); + strcpy(timer_fname,"."); + strcpy(hash_fname,"."); + if(data_dir != NULL) { + strcpy(wisdom_fname,data_dir); + strcpy(all_fname,data_dir); + strcpy(spots_fname,data_dir); + strcpy(timer_fname,data_dir); + strcpy(hash_fname,data_dir); + } + strncat(wisdom_fname,"/wspr_wisdom.dat",20); + strncat(all_fname,"/ALL_WSPR.TXT",20); + strncat(spots_fname,"/wspr_spots.txt",20); + strncat(timer_fname,"/wspr_timer.out",20); + strncat(hash_fname,"/hashtable.txt",20); + if ((fp_fftwf_wisdom_file = fopen(wisdom_fname, "r"))) { //Open FFTW wisdom + fftwf_import_wisdom_from_file(fp_fftwf_wisdom_file); + fclose(fp_fftwf_wisdom_file); + } + + fall_wspr=fopen(all_fname,"a"); + fwsprd=fopen(spots_fname,"w"); + // FILE *fdiag; + // fdiag=fopen("wsprd_diag","a"); + + if((ftimer=fopen(timer_fname,"r"))) { + //Accumulate timing data + nr=fscanf(ftimer,"%f %f %f %f %f %f %f", + &treadwav,&tcandidates,&tsync0,&tsync1,&tsync2,&tfano,&ttotal); + fclose(ftimer); + } + ftimer=fopen(timer_fname,"w"); + + if( strstr(ptr_to_infile,".wav") ) { + ptr_to_infile_suffix=strstr(ptr_to_infile,".wav"); + + t0 = clock(); + npoints=readwavfile(ptr_to_infile, wspr_type, idat, qdat); + treadwav += (float)(clock()-t0)/CLOCKS_PER_SEC; + + if( npoints == 1 ) { + return 1; + } + dialfreq=dialfreq_cmdline - (dialfreq_error*1.0e-06); + } else if ( strstr(ptr_to_infile,".c2") !=0 ) { + ptr_to_infile_suffix=strstr(ptr_to_infile,".c2"); + npoints=readc2file(ptr_to_infile, idat, qdat, &dialfreq, &wspr_type); + if( npoints == 1 ) { + return 1; + } + dialfreq -= (dialfreq_error*1.0e-06); + } else { + printf("Error: Failed to open %s\n",ptr_to_infile); + printf("WSPR file must have suffix .wav or .c2\n"); + return 1; + } + + // Parse date and time from given filename + strncpy(date,ptr_to_infile_suffix-11,6); + strncpy(uttime,ptr_to_infile_suffix-4,4); + date[6]='\0'; + uttime[4]='\0'; + + // Do windowed ffts over 2 symbols, stepped by half symbols + int nffts=4*floor(npoints/512)-1; + fftin=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*512); + fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*512); + PLAN3 = fftwf_plan_dft_1d(512, fftin, fftout, FFTW_FORWARD, PATIENCE); + + float ps[512][nffts]; + float w[512]; + for(i=0; i<512; i++) { + w[i]=sin(0.006147931*i); + } + + if( usehashtable ) { + char line[80], hcall[12]; + if( (fhash=fopen(hash_fname,"r+")) ) { + while (fgets(line, sizeof(line), fhash) != NULL) { + sscanf(line,"%d %s",&nh,hcall); + strcpy(hashtab+nh*13,hcall); + } + } else { + fhash=fopen(hash_fname,"w+"); + } + fclose(fhash); + } + + //*************** main loop starts here ***************** + for (ipass=0; ipass 0 && ndecodes_pass == 0 ) break; + ndecodes_pass=0; + + memset(ps,0.0, sizeof(float)*512*nffts); + for (i=0; i511 ) + k=k-512; + ps[j][i]=fftout[k][0]*fftout[k][0]+fftout[k][1]*fftout[k][1]; + } + } + + // Compute average spectrum + memset(psavg,0.0, sizeof(float)*512); + for (i=0; imin_snr) && (npk<200); + if ( candidate ) { + freq0[npk]=(j-205)*df; + snr0[npk]=10*log10(smspec[j])-snr_scaling_factor; + npk++; + } + } + } else { + for(j=1; j<410; j++) { + candidate = (smspec[j]>smspec[j-1]) && + (smspec[j]>smspec[j+1]) && + (npk<200); + if ( candidate ) { + freq0[npk]=(j-205)*df; + snr0[npk]=10*log10(smspec[j])-snr_scaling_factor; + npk++; + } + } + } + + // Compute corrected fmin, fmax, accounting for dial frequency error + fmin += dialfreq_error; // dialfreq_error is in units of Hz + fmax += dialfreq_error; + + // Don't waste time on signals outside of the range [fmin,fmax]. + i=0; + for( j=0; j= fmin && freq0[j] <= fmax ) { + freq0[i]=freq0[j]; + snr0[i]=snr0[j]; + i++; + } + } + npk=i; + + // bubble sort on snr, bringing freq along for the ride + int pass; + float tmp; + for (pass = 1; pass <= npk - 1; pass++) { + for (k = 0; k < npk - pass ; k++) { + if (snr0[k] < snr0[k+1]) { + tmp = snr0[k]; + snr0[k] = snr0[k+1]; + snr0[k+1] = tmp; + tmp = freq0[k]; + freq0[k] = freq0[k+1]; + freq0[k+1] = tmp; + } + } + } + + t0=clock(); + + /* Make coarse estimates of shift (DT), freq, and drift + + * Look for time offsets up to +/- 8 symbols (about +/- 5.4 s) relative + to nominal start time, which is 2 seconds into the file + + * Calculates shift relative to the beginning of the file + + * Negative shifts mean that signal started before start of file + + * The program prints DT = shift-2 s + + * Shifts that cause sync vector to fall off of either end of the data + vector are accommodated by "partial decoding", such that missing + symbols produce a soft-decision symbol value of 128 + + * The frequency drift model is linear, deviation of +/- drift/2 over the + span of 162 symbols, with deviation equal to 0 at the center of the + signal vector. + */ + + int idrift,ifr,if0,ifd,k0; + int kindex; + float smax,ss,pow,p0,p1,p2,p3; + for(j=0; j smax ) { //Save coarse parameters + smax=sync1; + shift0[j]=128*(k0+1); + drift0[j]=idrift; + freq0[j]=(ifr-256)*df; + sync0[j]=sync1; + } + } + } + } + } + tcandidates += (float)(clock()-t0)/CLOCKS_PER_SEC; + + /* + Refine the estimates of freq, shift using sync as a metric. + Sync is calculated such that it is a float taking values in the range + [0.0,1.0]. + + Function sync_and_demodulate has three modes of operation + mode is the last argument: + + 0 = no frequency or drift search. find best time lag. + 1 = no time lag or drift search. find best frequency. + 2 = no frequency or time lag search. Calculate soft-decision + symbols using passed frequency and shift. + + NB: best possibility for OpenMP may be here: several worker threads + could each work on one candidate at a time. + */ + for (j=0; jminsync1 continue + fstep=0.0; ifmin=0; ifmax=0; + lagmin=shift1-128; + lagmax=shift1+128; + lagstep=64; + t0 = clock(); + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0); + tsync0 += (float)(clock()-t0)/CLOCKS_PER_SEC; + + fstep=0.25; ifmin=-2; ifmax=2; + t0 = clock(); + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1); + + // refine drift estimate + fstep=0.0; ifmin=0; ifmax=0; + float driftp,driftm,syncp,syncm; + driftp=drift1+0.5; + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &driftp, symfac, &syncp, 1); + + driftm=drift1-0.5; + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &driftm, symfac, &syncm, 1); + + if(syncp>sync1) { + drift1=driftp; + sync1=syncp; + } else if (syncm>sync1) { + drift1=driftm; + sync1=syncm; + } + + tsync1 += (float)(clock()-t0)/CLOCKS_PER_SEC; + + // fine-grid lag and freq search + if( sync1 > minsync1 ) { + + lagmin=shift1-32; lagmax=shift1+32; lagstep=16; + t0 = clock(); + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0); + tsync0 += (float)(clock()-t0)/CLOCKS_PER_SEC; + + // fine search over frequency + fstep=0.05; ifmin=-2; ifmax=2; + t0 = clock(); + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1, + lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1); + tsync1 += (float)(clock()-t0)/CLOCKS_PER_SEC; + + worth_a_try = 1; + } else { + worth_a_try = 0; + } + + int idt=0, ii=0, jiggered_shift; + float y,sq,rms; + not_decoded=1; + + while ( worth_a_try && not_decoded && idt<=(128/iifac)) { + ii=(idt+1)/2; + if( idt%2 == 1 ) ii=-ii; + ii=iifac*ii; + jiggered_shift=shift1+ii; + + // Use mode 2 to get soft-decision symbols + t0 = clock(); + sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, + &jiggered_shift, lagmin, lagmax, lagstep, &drift1, symfac, + &sync1, 2); + tsync2 += (float)(clock()-t0)/CLOCKS_PER_SEC; + + sq=0.0; + for(i=0; i<162; i++) { + y=(float)symbols[i] - 128.0; + sq += y*y; + } + rms=sqrt(sq/162.0); + + if((sync1 > minsync2) && (rms > minrms)) { + deinterleave(symbols); + t0 = clock(); + + if ( stackdecoder ) { + not_decoded = jelinek(&metric, &cycles, decdata, symbols, nbits, + stacksize, stack, mettab,maxcycles); + } else { + not_decoded = fano(&metric,&cycles,&maxnp,decdata,symbols,nbits, + mettab,delta,maxcycles); + } + + tfano += (float)(clock()-t0)/CLOCKS_PER_SEC; + + } + idt++; + if( quickmode ) break; + } + + if( worth_a_try && !not_decoded ) { + ndecodes_pass++; + + for(i=0; i<11; i++) { + + if( decdata[i]>127 ) { + message[i]=decdata[i]-256; + } else { + message[i]=decdata[i]; + } + + } + + // Unpack the decoded message, update the hashtable, apply + // sanity checks on grid and power, and return + // call_loc_pow string and also callsign (for de-duping). + noprint=unpk_(message,hashtab,call_loc_pow,callsign); + + // subtract even on last pass + if( subtraction && (ipass < npasses ) && !noprint ) { + if( get_wspr_channel_symbols(call_loc_pow, hashtab, channel_symbols) ) { + subtract_signal2(idat, qdat, npoints, f1, shift1, drift1, channel_symbols); + } else { + break; + } + + } + + // Remove dupes (same callsign and freq within 3 Hz) + int dupe=0; + for (i=0; i decodes[k+1].freq) { + temp = decodes[k]; + decodes[k]=decodes[k+1];; + decodes[k+1] = temp; + } + } + } + + for (i=0; i\n"); + + fftwf_free(fftin); + fftwf_free(fftout); + + if ((fp_fftwf_wisdom_file = fopen(wisdom_fname, "w"))) { + fftwf_export_wisdom_to_file(fp_fftwf_wisdom_file); + fclose(fp_fftwf_wisdom_file); + } + + ttotal += (float)(clock()-t00)/CLOCKS_PER_SEC; + + fprintf(ftimer,"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n\n", + treadwav,tcandidates,tsync0,tsync1,tsync2,tfano,ttotal); + + fprintf(ftimer,"Code segment Seconds Frac\n"); + fprintf(ftimer,"-----------------------------------\n"); + fprintf(ftimer,"readwavfile %7.2f %7.2f\n",treadwav,treadwav/ttotal); + fprintf(ftimer,"Coarse DT f0 f1 %7.2f %7.2f\n",tcandidates, + tcandidates/ttotal); + fprintf(ftimer,"sync_and_demod(0) %7.2f %7.2f\n",tsync0,tsync0/ttotal); + fprintf(ftimer,"sync_and_demod(1) %7.2f %7.2f\n",tsync1,tsync1/ttotal); + fprintf(ftimer,"sync_and_demod(2) %7.2f %7.2f\n",tsync2,tsync2/ttotal); + fprintf(ftimer,"Stack/Fano decoder %7.2f %7.2f\n",tfano,tfano/ttotal); + fprintf(ftimer,"-----------------------------------\n"); + fprintf(ftimer,"Total %7.2f %7.2f\n",ttotal,1.0); + + fclose(fall_wspr); + fclose(fwsprd); + // fclose(fdiag); + fclose(ftimer); + fftwf_destroy_plan(PLAN1); + fftwf_destroy_plan(PLAN2); + fftwf_destroy_plan(PLAN3); + + if( usehashtable ) { + fhash=fopen(hash_fname,"w"); + for (i=0; i<32768; i++) { + if( strncmp(hashtab+i*13,"\0",1) != 0 ) { + fprintf(fhash,"%5d %s\n",i,hashtab+i*13); + } + } + fclose(fhash); + } + + if( stackdecoder ) { + free(stack); + } + + if(writenoise == 999) return -1; //Silence compiler warning + return 0; +} diff --git a/lib/wsprd/wsprd_stats.txt b/lib/wsprd/wsprd_stats.txt new file mode 100644 index 00000000..0d925aa6 --- /dev/null +++ b/lib/wsprd/wsprd_stats.txt @@ -0,0 +1,24 @@ + Linux Windows +Program Time Decodes Time Decodes +------------------------------------------------- +wsprd (Mar 2013) 2413 1451 2718 1451 + +k9an-wsprd 1800 2122 +k9an_wsprd -q 354 1939 + +wsprd 399 2190 356 2190 +wsprd -q 214 2034 192 2034 + +wsprd* 1240 2215 +wsprd# 1599 2220 + +------------------------------------------------- +* maxcycles=30000 +# maxcycles=20000, iifac=1 +------------------------------------------------- +Test data: 638 *.wav files (recorded by WSJT-X) +------------------------------------------------- +Linux machine: Core 2 Duo, E6750 CPU +Windows machine: 4-Core i5-2500 CPU +wsprd git commit: eecc274 +------------------------------------------------- diff --git a/lib/wsprd/wsprd_utils.c b/lib/wsprd/wsprd_utils.c new file mode 100644 index 00000000..65485d4b --- /dev/null +++ b/lib/wsprd/wsprd_utils.c @@ -0,0 +1,339 @@ +/* + This file is part of program wsprd, a detector/demodulator/decoder + for the Weak Signal Propagation Reporter (WSPR) mode. + + File name: wsprd_utils.c + + Copyright 2001-2015, Joe Taylor, K1JT + + Most of the code is based on work by Steven Franke, K9AN, which + in turn was based on earlier work by K1JT. + + Copyright 2014-2015, Steven Franke, K9AN + + License: GNU GPL v3 + + This program 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 of the License, or + (at your option) any later version. + + This program 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 this program. If not, see . + */ +#include "wsprd_utils.h" + +#ifndef int32_t +#define int32_t int +#endif + +void unpack50( signed char *dat, int32_t *n1, int32_t *n2 ) +{ + int32_t i,i4; + + i=dat[0]; + i4=i&255; + *n1=i4<<20; + + i=dat[1]; + i4=i&255; + *n1=*n1+(i4<<12); + + i=dat[2]; + i4=i&255; + *n1=*n1+(i4<<4); + + i=dat[3]; + i4=i&255; + *n1=*n1+((i4>>4)&15); + *n2=(i4&15)<<18; + + i=dat[4]; + i4=i&255; + *n2=*n2+(i4<<10); + + i=dat[5]; + i4=i&255; + *n2=*n2+(i4<<2); + + i=dat[6]; + i4=i&255; + *n2=*n2+((i4>>6)&3); +} + +int unpackcall( int32_t ncall, char *call ) +{ + char c[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E', + 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', + 'U','V','W','X','Y','Z',' '}; + int32_t n; + int i; + char tmp[7]; + + n=ncall; + strcpy(call,"......"); + if (n < 262177560 ) { + i=n%27+10; + tmp[5]=c[i]; + n=n/27; + i=n%27+10; + tmp[4]=c[i]; + n=n/27; + i=n%27+10; + tmp[3]=c[i]; + n=n/27; + i=n%10; + tmp[2]=c[i]; + n=n/10; + i=n%36; + tmp[1]=c[i]; + n=n/36; + i=n; + tmp[0]=c[i]; + tmp[6]='\0'; + // remove leading whitespace + for(i=0; i<5; i++) { + if( tmp[i] != c[36] ) + break; + } + sprintf(call,"%-6s",&tmp[i]); + // remove trailing whitespace + for(i=0; i<6; i++) { + if( call[i] == c[36] ) { + call[i]='\0'; + } + } + } else { + return 0; + } + return 1; +} + +int unpackgrid( int32_t ngrid, char *grid) +{ + char c[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E', + 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', + 'U','V','W','X','Y','Z',' '}; + int dlat, dlong; + + ngrid=ngrid>>7; + if( ngrid < 32400 ) { + dlat=(ngrid%180)-90; + dlong=(ngrid/180)*2 - 180 + 2; + if( dlong < -180 ) + dlong=dlong+360; + if( dlong > 180 ) + dlong=dlong+360; + int nlong = 60.0*(180.0-dlong)/5.0; + int n1 = nlong/240; + int n2 = (nlong - 240*n1)/24; + grid[0] = c[10+n1]; + grid[2]= c[n2]; + + int nlat = 60.0*(dlat+90)/2.5; + n1 = nlat/240; + n2 = (nlat-240*n1)/24; + grid[1]=c[10+n1]; + grid[3]=c[n2]; + } else { + strcpy(grid,"XXXX"); + return 0; + } + return 1; +} + +int unpackpfx( int32_t nprefix, char *call) +{ + char nc, pfx[4]={'\0'}, tmpcall[7]; + int i; + int32_t n; + + strcpy(tmpcall,call); + if( nprefix < 60000 ) { + // add a prefix of 1 to 3 characters + n=nprefix; + for (i=2; i>=0; i--) { + nc=n%37; + if( (nc >= 0) & (nc <= 9) ) { + pfx[i]=nc+48; + } + else if( (nc >= 10) & (nc <= 35) ) { + pfx[i]=nc+55; + } + else { + pfx[i]=' '; + } + n=n/37; + } + + char * p = strrchr(pfx,' '); + strcpy(call, p ? p + 1 : pfx); + strncat(call,"/",1); + strncat(call,tmpcall,strlen(tmpcall)); + + } else { + // add a suffix of 1 or 2 characters + nc=nprefix-60000; + if( (nc >= 0) & (nc <= 9) ) { + pfx[0]=nc+48; + strcpy(call,tmpcall); + strncat(call,"/",1); + strncat(call,pfx,1); + } + else if( (nc >= 10) & (nc <= 35) ) { + pfx[0]=nc+55; + strcpy(call,tmpcall); + strncat(call,"/",1); + strncat(call,pfx,1); + } + else if( (nc >= 36) & (nc <= 125) ) { + pfx[0]=(nc-26)/10+48; + pfx[1]=(nc-26)%10+48; + strcpy(call,tmpcall); + strncat(call,"/",1); + strncat(call,pfx,2); + } + else { + return 0; + } + } + return 1; +} + +void deinterleave(unsigned char *sym) +{ + unsigned char tmp[162]; + unsigned char p, i, j; + + p=0; + i=0; + while (p<162) { + j=((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32; + if (j < 162 ) { + tmp[p]=sym[j]; + p=p+1; + } + i=i+1; + } + for (i=0; i<162; i++) { + sym[i]=tmp[i]; + } +} + +// used by qsort +int doublecomp(const void* elem1, const void* elem2) +{ + if(*(const double*)elem1 < *(const double*)elem2) + return -1; + return *(const double*)elem1 > *(const double*)elem2; +} + +int floatcomp(const void* elem1, const void* elem2) +{ + if(*(const float*)elem1 < *(const float*)elem2) + return -1; + return *(const float*)elem1 > *(const float*)elem2; +} + +int unpk_(signed char *message, char *hashtab, char *call_loc_pow, char *callsign) +{ + int n1,n2,n3,ndbm,ihash,nadd,noprint=0; + char grid[5],grid6[7],cdbm[3]; + + unpack50(message,&n1,&n2); + if( !unpackcall(n1,callsign) ) return 1; + if( !unpackgrid(n2, grid) ) return 1; + int ntype = (n2&127) - 64; + callsign[12]=0; + grid[4]=0; + + /* + Based on the value of ntype, decide whether this is a Type 1, 2, or + 3 message. + + * Type 1: 6 digit call, grid, power - ntype is positive and is a member + of the set {0,3,7,10,13,17,20...60} + + * Type 2: extended callsign, power - ntype is positive but not + a member of the set of allowed powers + + * Type 3: hash, 6 digit grid, power - ntype is negative. + */ + + if( (ntype >= 0) && (ntype <= 62) ) { + int nu=ntype%10; + if( nu == 0 || nu == 3 || nu == 7 ) { + ndbm=ntype; + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,grid,4); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); + strcpy(hashtab+ihash*13,callsign); + } else { + nadd=nu; + if( nu > 3 ) nadd=nu-3; + if( nu > 7 ) nadd=nu-7; + n3=n2/128+32768*(nadd-1); + if( !unpackpfx(n3,callsign) ) return 1; + ndbm=ntype-nadd; + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + int nu=ndbm%10; + if( nu == 0 || nu == 3 || nu == 7 || nu == 10 ) { //make sure power is OK + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); + strcpy(hashtab+ihash*13,callsign); + } else noprint=1; + } + } else if ( ntype < 0 ) { + ndbm=-(ntype+1); + memset(grid6,0,sizeof(char)*7); +// size_t len=strlen(callsign); + size_t len=6; + strncat(grid6,callsign+len-1,1); + strncat(grid6,callsign,len-1); + int nu=ndbm%10; + if ((nu != 0 && nu != 3 && nu != 7 && nu != 10) || + !isalpha(grid6[0]) || !isalpha(grid6[1]) || + !isdigit(grid6[2]) || !isdigit(grid6[3])) { + // not testing 4'th and 5'th chars because of this case: JO33 40 + // grid is only 4 chars even though this is a hashed callsign... + // isalpha(grid6[4]) && isalpha(grid6[5]) ) ) { + noprint=1; + } + + ihash=(n2-ntype-64)/128; + if( strncmp(hashtab+ihash*13,"\0",1) != 0 ) { + sprintf(callsign,"<%s>",hashtab+ihash*13); + } else { + sprintf(callsign,"%5s","<...>"); + } + + memset(call_loc_pow,0,sizeof(char)*23); + sprintf(cdbm,"%2d",ndbm); + strncat(call_loc_pow,callsign,strlen(callsign)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,grid6,strlen(grid6)); + strncat(call_loc_pow," ",1); + strncat(call_loc_pow,cdbm,2); + strncat(call_loc_pow,"\0",1); + + + // I don't know what to do with these... They show up as "A000AA" grids. + if( ntype == -64 ) noprint=1; + } + return noprint; +} diff --git a/lib/wsprd/wsprd_utils.h b/lib/wsprd/wsprd_utils.h new file mode 100644 index 00000000..d6708363 --- /dev/null +++ b/lib/wsprd/wsprd_utils.h @@ -0,0 +1,29 @@ +#ifndef WSPRD_UTILS_H +#define WSPRD_UTILS_H + +#include +#include +#include +#include +#include +#include +#include +#include "nhash.h" + +void unpack50( signed char *dat, int32_t *n1, int32_t *n2 ); + +int unpackcall( int32_t ncall, char *call ); + +int unpackgrid( int32_t ngrid, char *grid); + +int unpackpfx( int32_t nprefix, char *call); + +void deinterleave(unsigned char *sym); + +// used by qsort +int doublecomp(const void* elem1, const void* elem2); +int floatcomp(const void* elem1, const void* elem2); + +int unpk_( signed char *message, char* hashtab, char *call_loc_pow, char *callsign); + +#endif diff --git a/lib/wsprd/wsprsim.c b/lib/wsprd/wsprsim.c new file mode 100644 index 00000000..f368b209 --- /dev/null +++ b/lib/wsprd/wsprsim.c @@ -0,0 +1,207 @@ +/* + File name: wsprsim.c (first committed to wsjtx June 13, 2015) + */ +#include +#include +#include +#include + +#include "wsprsim_utils.h" +#include "wsprd_utils.h" +#include "fano.h" + +int printdata=0; + +void usage() { + printf("Usage: wsprsim [options] message\n"); + printf(" message format: \"K1ABC FN42 33\"\n"); + printf(" \"PJ4/K1ABC 33\"\n"); + printf(" \" FK52UD 33\"\n"); + printf("Options:\n"); + printf(" -c (print channel symbols)\n"); + printf(" -d (print packed data with zero tail - 11 bytes)\n"); + printf(" -o filename (write a c2 file with this name)\n"); + printf(" -s x (x is snr of signal that is written to .c2 file)\n"); + printf("\n"); + printf(" e.g. ./wsprsim -cds -28 -o 150613_1920.c2 \"K1ABC FN42 33\"\n"); + printf(" then ./wsprd 150613_1920.c2\n"); +} + +int add_signal_vector(float f0, float t0, float amp, unsigned char* symbols + , double* isig, double* qsig) +{ + int i, j, ii, idelay; + double phi=0.0, twopidt, df, dt, dphi; + twopidt=8.0*atan(1.0)/375.0; + df=375.0/256.0; + dt=1/375.0; + idelay=t0/dt; + + for (i=0; i<162; i++) { + dphi=twopidt*(f0 + ( (double)symbols[i]-1.5)*df ); + for ( j=0; j<256; j++ ) { + ii=idelay+256*i+j; + isig[ii]=isig[ii]+amp*cos(phi); + qsig[ii]=qsig[ii]+amp*sin(phi); + phi=phi+dphi; + } + } + return 1; +} + +char* tobinary(int x) +{ + static char b[33]; + b[0] = '\0'; + + long unsigned int z; + for (z = 0x80000000; z > 0; z >>= 1) + { + strcat(b, ((x & z) == z) ? "1" : "0"); + } + + return b; +} + +double gaussrand() +{ + static double V1, V2, S; + static int phase = 0; + double X; + + if(phase == 0) { + do { + double U1 = (double)rand() / RAND_MAX; + double U2 = (double)rand() / RAND_MAX; + + V1 = 2 * U1 - 1; + V2 = 2 * U2 - 1; + S = V1 * V1 + V2 * V2; + } while(S >= 1 || S == 0); + + X = V1 * sqrt(-2 * log(S) / S); + } else + X = V2 * sqrt(-2 * log(S) / S); + + phase = 1 - phase; + + return X; +} + +unsigned long writec2file(char *c2filename, int trmin, double freq + , double *idat, double *qdat) +{ + int i; + float buffer[2*45000]; + memset(buffer,0,sizeof(float)*2*45000); + FILE *fp; + + fp = fopen(c2filename,"wb"); + if( fp == NULL ) { + fprintf(stderr, "Could not open c2 file '%s'\n", c2filename); + return 0; + } + unsigned long nwrite = fwrite(c2filename,sizeof(char),14,fp); + nwrite = fwrite(&trmin, sizeof(int), 1, fp); + nwrite = fwrite(&freq, sizeof(double), 1, fp); + + for(i=0; i<45000; i++) { + buffer[2*i]=idat[i]; + buffer[2*i+1]=-qdat[i]; + } + + nwrite = fwrite(buffer, sizeof(float), 2*45000, fp); + if( nwrite == 2*45000 ) { + return nwrite; + } else { + return 0; + } +} + + +//******************************************************************** +int main(int argc, char *argv[]) +{ + extern char *optarg; + extern int optind; + int i, c, printchannel=0, writec2=0; + float snr=50.0; + char *message, *c2filename, *hashtab; + c2filename=malloc(sizeof(char)*15); + hashtab=malloc(sizeof(char)*32768*13); + memset(hashtab,0,sizeof(char)*32768*13); + + // message length is 22 characters + message=malloc(sizeof(char)*23); + + strcpy(c2filename,"000000_0001.c2"); + + srand(getpid()); + + while ( (c = getopt(argc, argv, "cdo:s:")) !=-1 ) { + switch (c) { + case 'c': + printchannel=1; + break; + case 'd': + printdata=1; + break; + case 'o': + c2filename = optarg; + writec2=1; + break; + case 's': + snr = (float)atoi(optarg); + break; + } + } + + if( optind+1 > argc ) { + usage(); + return 0; + } else { + message=argv[optind]; + } + + unsigned char channel_symbols[162]; + get_wspr_channel_symbols(message, hashtab, channel_symbols); + + if( printchannel ) { + printf("Channel symbols:\n"); + for (i=0; i<162; i++) { + printf("%d ",channel_symbols[i]); + } + printf("\n"); + } + + // add noise, then signal + double isig[45000], qsig[45000]; + memset(isig,0,sizeof(double)*45000); + memset(qsig,0,sizeof(double)*45000); + + if( snr < 40 ) { + // snr in 375Hz is 8.2 dB higher than in 2500 Hz. + snr=snr+8.2; + snr=pow(10,snr/20.0)*pow(2,0.5); + + for (i = 0; i<45000; i++) { + isig[i]=isig[i]+gaussrand(); + qsig[i]=qsig[i]+gaussrand(); + } + } else { + snr=1.0; + } + + float f0, t0; + f0=0.0; + t0=1.0; + add_signal_vector(f0, t0, snr, channel_symbols, isig, qsig); + if( writec2) { + // write a .c2 file + double carrierfreq=10.1387; + int wsprtype=2; + printf("Writing %s\n",c2filename); + writec2file(c2filename, wsprtype, carrierfreq, isig, qsig); + } + return 1; +} diff --git a/lib/wsprd/wsprsim_utils.c b/lib/wsprd/wsprsim_utils.c new file mode 100644 index 00000000..d4a53c8b --- /dev/null +++ b/lib/wsprd/wsprsim_utils.c @@ -0,0 +1,311 @@ +/* + Functions used by wsprsim + */ +#include "wsprsim_utils.h" +#include "wsprd_utils.h" +#include "nhash.h" +#include "fano.h" + +char get_locator_character_code(char ch) { + if( ch >=48 && ch <=57 ) { //0-9 + return ch-48; + } + if( ch == 32 ) { //space + return 36; + } + if( ch >= 65 && ch <= 82 ) { //A-Z + return ch-65; + } + return -1; +} + +char get_callsign_character_code(char ch) { + if( ch >=48 && ch <=57 ) { //0-9 + return ch-48; + } + if( ch == 32 ) { //space + return 36; + } + if( ch >= 65 && ch <= 90 ) { //A-Z + return ch-55; + } + return -1; +} + +long unsigned int pack_grid4_power(char *grid4, int power) { + long unsigned int m; + + m=(179-10*grid4[0]-grid4[2])*180+10*grid4[1]+grid4[3]; + m=m*128+power+64; + return m; +} + +long unsigned int pack_call(char *callsign) { + unsigned int i; + long unsigned int n; + char call6[6]; + memset(call6,32,sizeof(char)*6); + // callsign is 6 characters in length. Exactly. + size_t call_len = strlen(callsign); + if( call_len > 6 ) { + return 0; + } + if( isdigit(*(callsign+2)) ) { + for (i=0; i= 48 && nc <= 57 ) { + *m=nc-48; + } else if ( nc >= 65 && nc <= 90 ) { + *m=nc-65+10; + } else { + *m=38; + } + *m=60000-32768+*m; + } else if( callsign[i1+3]==0 ) { + //two char suffix + for (i=0; i= 48 && nc <= 57 ) { + nc=nc-48; + } else if ( nc >= 65 && nc <= 90 ) { + nc=nc-65+10; + } else { + nc=36; + } + *m=37*(*m)+nc; + } + *nadd=0; + if( *m > 32768 ) { + *m=*m-32768; + *nadd=1; + } + } +} + +void interleave(unsigned char *sym) +{ + unsigned char tmp[162]; + unsigned char p, i, j; + + p=0; + i=0; + while (p<162) { + j=((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32; + if (j < 162 ) { + tmp[j]=sym[p]; + p=p+1; + } + i=i+1; + } + for (i=0; i<162; i++) { + sym[i]=tmp[i]; + } +} + +int get_wspr_channel_symbols(char* rawmessage, char* hashtab, unsigned char* symbols) { + int m=0, n=0, ntype=0; + int i, j, ihash; + unsigned char pr3[162]= + {1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, + 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, + 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, + 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, + 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, + 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, + 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, + 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, + 0,0}; + int nu[10]={0,-1,1,0,-1,2,1,0,-1,1}; + char *callsign, *grid, *powstr; + char grid4[5], message[23]; + + memset(message,0,sizeof(char)*23); + i=0; + while ( rawmessage[i] != 0 && i<23 ) { + message[i]=rawmessage[i]; + i++; + } + + size_t i1=strcspn(message," "); + size_t i2=strcspn(message,"/"); + size_t i3=strcspn(message,"<"); + size_t i4=strcspn(message,">"); + size_t mlen=strlen(message); + + // Use the presence and/or absence of "<" and "/" to decide what + // type of message. No sanity checks! Beware! + + if( (i1>3) & (i1<7) & (i2==mlen) & (i3==mlen) ) { + // Type 1 message: K9AN EN50 33 + // xxnxxxx xxnn nn + callsign = strtok(message," "); + grid = strtok(NULL," "); + powstr = strtok(NULL," "); + int power = atoi(powstr); + n = pack_call(callsign); + + for (i=0; i<4; i++) { + grid4[i]=get_locator_character_code(*(grid+i)); + } + m = pack_grid4_power(grid4,power); + + } else if ( i3 == 0 && i4 < mlen ) { + // Type 3: EN50WC 33 + // FK52UD 37 + // send hash instead of callsign to make room for 6 char grid. + // if 4-digit locator is specified, 2 spaces are added to the end. + callsign=strtok(message,"<> "); + grid=strtok(NULL," "); + powstr=strtok(NULL," "); + int power = atoi(powstr); + if( power < 0 ) power=0; + if( power > 60 ) power=60; + power=power+nu[power%10]; + ntype=-(power+1); + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); + m=128*ihash + ntype + 64; + + char grid6[6]; + memset(grid6,32,sizeof(char)*6); + j=strlen(grid); + for(i=0; i 60 ) power=60; + power=power+nu[power%10]; + int n1, ng, nadd; + pack_prefix(callsign, &n1, &ng, &nadd); + ntype=power + 1 + nadd; + m=128*ng+ntype+64; + n=n1; + } else { + return 0; + } + + // pack 50 bits + 31 (0) tail bits into 11 bytes + unsigned char it, data[11]; + memset(data,0,sizeof(char)*11); + it=0xFF & (n>>20); + data[0]=it; + it=0xFF & (n>>12); + data[1]=it; + it=0xFF & (n>>4); + data[2]=it; + it= ((n&(0x0F))<<4) + ((m>>18)&(0x0F)); + data[3]=it; + it=0xFF & (m>>10); + data[4]=it; + it=0xFF & (m>>2); + data[5]=it; + it=(m & 0x03)<<6 ; + data[6]=it; + data[7]=0; + data[8]=0; + data[9]=0; + data[10]=0; + + if( printdata ) { + printf("Data is :"); + for (i=0; i<11; i++) { + printf("%02X ",data[i]); + } + printf("\n"); + } + + // make sure that the 11-byte data vector is unpackable + // unpack it with the routine that the decoder will use and display + // the result. let the operator decide whether it worked. + + char *check_call_loc_pow, *check_callsign; + check_call_loc_pow=malloc(sizeof(char)*23); + check_callsign=malloc(sizeof(char)*13); + signed char check_data[11]; + memcpy(check_data,data,sizeof(char)*11); + unpk_(check_data,hashtab,check_call_loc_pow,check_callsign); +// printf("Will decode as: %s\n",check_call_loc_pow); + + unsigned int nbytes=11; // The message with tail is packed into almost 11 bytes. + unsigned char channelbits[nbytes*8*2]; /* 162 rounded up */ + memset(channelbits,0,sizeof channelbits); + + encode(channelbits,data,nbytes); + + interleave(channelbits); + + for (i=0; i<162; i++) { + symbols[i]=2*channelbits[i]+pr3[i]; + } + + return 1; +} diff --git a/lib/wsprd/wsprsim_utils.h b/lib/wsprd/wsprsim_utils.h new file mode 100644 index 00000000..2f4151a5 --- /dev/null +++ b/lib/wsprd/wsprsim_utils.h @@ -0,0 +1,28 @@ +#ifndef WSPRSIM_UTILS_H +#define WSPRSIM_UTILS_H + +#include +#include +#include +#include +#include +#include +#include + +extern int printdata; + +char get_locator_character_code(char ch); + +char get_callsign_character_code(char ch); + +long unsigned int pack_grid4_power(char *grid4, int power); + +long unsigned int pack_call(char *callsign); + +void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd ); + +void interleave(unsigned char *sym); + +int get_wspr_channel_symbols(char* message, char* hashtab, unsigned char* symbols); + +#endif diff --git a/lib/xcor.f90 b/lib/xcor.f90 new file mode 100644 index 00000000..3f95f768 --- /dev/null +++ b/lib/xcor.f90 @@ -0,0 +1,73 @@ +subroutine xcor(ss,ipk,nsteps,nsym,lag1,lag2,ccf,ccf0,lagpk,flip,fdot,nrobust) + +! Computes ccf of a row of ss and the pseudo-random array pr. Returns +! peak of the CCF and the lag at which peak occurs. For JT65, the +! CCF peak may be either positive or negative, with negative implying +! the "OOO" message. + + use jt65_mod + parameter (NHMAX=3413) !Max length of power spectra + parameter (NSMAX=322) !Max number of half-symbol steps + real ss(NSMAX,NHMAX) !2d spectrum, stepped by half-symbols + real a(NSMAX) + real ccf(-11:540) + data lagmin/0/ !Silence g77 warning + save + + df=12000.0/8192. + dtstep=0.5/df + fac=dtstep/(60.0*df) + + do j=1,nsteps + ii=nint((j-nsteps/2)*fdot*fac)+ipk + if( (ii.ge.1) .and. (ii.le.NHMAX) ) then + a(j)=ss(j,ii) + endif + enddo + + if(nrobust.eq.1) then +! use robust correlation estimator to mitigate AGC attack spikes at beginning +! this reduces the number of spurious candidates overall + call pctile(a,nsteps,50,xmed) + do j=1,nsteps + if( a(j).ge.xmed ) then + a(j)=1 + else + a(j)=-1 + endif + enddo + endif + + ccfmax=0. + ccfmin=0. + do lag=lag1,lag2 + x=0. + do i=1,nsym + j=2*i-1+lag + if(j.ge.1 .and. j.le.nsteps) x=x+a(j)*pr(i) + enddo + ccf(lag)=2*x !The 2 is for plotting scale + if(ccf(lag).gt.ccfmax) then + ccfmax=ccf(lag) + lagpk=lag + endif + + if(ccf(lag).lt.ccfmin) then + ccfmin=ccf(lag) + lagmin=lag + endif + enddo + + ccf0=ccfmax + flip=1.0 + if(-ccfmin.gt.ccfmax) then + do lag=lag1,lag2 + ccf(lag)=-ccf(lag) + enddo + lagpk=lagmin + ccf0=-ccfmin + flip=-1.0 + endif + + return +end subroutine xcor diff --git a/lib/xcor24.f90 b/lib/xcor24.f90 deleted file mode 100644 index b76093b2..00000000 --- a/lib/xcor24.f90 +++ /dev/null @@ -1,94 +0,0 @@ -subroutine xcor24(s2,ipk,nsteps,nsym,lag1,lag2,mode4,ccf,ccf0,lagpk,flip) - -! Computes ccf of a row of s2 and the pseudo-random array pr2. Returns -! peak of the CCF and the lag at which peak occurs. For JT65, the -! CCF peak may be either positive or negative, with negative implying -! the "OOO" message. - - parameter (NHMAX=1260) !Max length of power spectra - parameter (NSMAX=525) !Max number of half-symbol steps - real s2(NHMAX,NSMAX) !2d spectrum, stepped by half-symbols - real a(NSMAX) - real ccf(-5:540) - integer npr2(207) - real pr2(207) - logical first - data lagmin/0/ !Silence g77 warning - data first/.true./ - data npr2/ & - 0,0,0,0,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0, & - 0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,0,0, & - 1,0,0,1,0,0,1,1,1,1,1,0,0,0,1,0,1,0,0,0,1,1,1,1,0,1,1,0,0,1, & - 0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1,0,1,0,1, & - 0,1,1,1,0,0,1,0,1,1,0,1,1,1,1,0,0,0,0,1,1,0,1,1,0,0,0,1,1,1, & - 0,1,1,1,0,1,1,1,0,0,1,0,0,0,1,1,0,1,1,0,0,1,0,0,0,1,1,1,1,1, & - 1,0,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,1,0,1,1,1,1,0,1,0,1/ - save - - if(first) then - do i=1,207 - pr2(i)=2*npr2(i)-1 - enddo - first=.false. - endif - - do j=1,nsteps - n=2*mode4 - if(mode4.eq.1) then - a(j)=max(s2(ipk+n,j),s2(ipk+3*n,j)) - max(s2(ipk ,j),s2(ipk+2*n,j)) - else - kz=mode4/2 - ss0=0. - ss1=0. - ss2=0. - ss3=0. - wsum=0. - do k=-kz+1,kz-1 - w=float(kz-iabs(k))/mode4 - wsum=wsum+w - if(ipk+k.lt.1 .or. ipk+3*n+k.gt.1260) then - print*,'xcor24:',ipk,n,k - else - ss0=ss0 + w*s2(ipk +k,j) - ss1=ss1 + w*s2(ipk+ n+k,j) - ss2=ss2 + w*s2(ipk+2*n+k,j) - ss3=ss3 + w*s2(ipk+3*n+k,j) - endif - enddo - a(j)=(max(ss1,ss3) - max(ss0,ss2))/sqrt(wsum) - endif - enddo - - ccfmax=0. - ccfmin=0. - do lag=lag1,lag2 - x=0. - do i=1,nsym - j=2*i-1+lag - if(j.ge.1 .and. j.le.nsteps) x=x+a(j)*pr2(i) - enddo - ccf(lag)=2*x !The 2 is for plotting scale - if(ccf(lag).gt.ccfmax) then - ccfmax=ccf(lag) - lagpk=lag - endif - - if(ccf(lag).lt.ccfmin) then - ccfmin=ccf(lag) - lagmin=lag - endif - enddo - - ccf0=ccfmax - flip=1.0 - if(-ccfmin.gt.ccfmax) then - do lag=lag1,lag2 - ccf(lag)=-ccf(lag) - enddo - lagpk=lagmin - ccf0=-ccfmin - flip=-1.0 - endif - - return -end subroutine xcor24 diff --git a/lib/xcor4.f90 b/lib/xcor4.f90 new file mode 100644 index 00000000..9e1f5a52 --- /dev/null +++ b/lib/xcor4.f90 @@ -0,0 +1,95 @@ +subroutine xcor4(s2,ipk,nsteps,nsym,lag1,lag2,ich,mode4,ccf,ccf0, & + lagpk,flip) + +! Computes ccf of the 4_FSK spectral array s2 and the pseudo-random +! array pr2. Returns peak of CCF and the lag at which peak occurs. +! The CCF peak may be either positive or negative, with negative +! implying the "OOO" message. + + parameter (NHMAX=1260) !Max length of power spectra + parameter (NSMAX=525) !Max number of half-symbol steps + real s2(NHMAX,NSMAX) !2d spectrum, stepped by half-symbols + real a(NSMAX) + real ccf(-5:540) + integer nch(7) + integer npr2(207) + real pr2(207) + logical first + data lagmin/0/ !Silence compiler warning + data first/.true./ + data npr2/ & + 0,0,0,0,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0, & + 0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,0,0, & + 1,0,0,1,0,0,1,1,1,1,1,0,0,0,1,0,1,0,0,0,1,1,1,1,0,1,1,0,0,1, & + 0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1,0,1,0,1, & + 0,1,1,1,0,0,1,0,1,1,0,1,1,1,1,0,0,0,0,1,1,0,1,1,0,0,0,1,1,1, & + 0,1,1,1,0,1,1,1,0,0,1,0,0,0,1,1,0,1,1,0,0,1,0,0,0,1,1,1,1,1, & + 1,0,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,1,0,1,1,1,1,0,1,0,1/ + data nch/1,2,4,9,18,36,72/ + save + + if(first) then + do i=1,207 + pr2(i)=2*npr2(i)-1 + enddo + first=.false. + endif + + ccfmax=0. + ccfmin=0. + nw=nch(ich) + + do j=1,nsteps + n=2*mode4 + if(mode4.eq.1) then + a(j)=max(s2(ipk+n,j),s2(ipk+3*n,j)) - max(s2(ipk ,j),s2(ipk+2*n,j)) + else + kz=max(1,nw/2) + ss0=0. + ss1=0. + ss2=0. + ss3=0. + wsum=0. + do k=-kz+1,kz-1 + w=float(kz-iabs(k))/nw + wsum=wsum+w + ss0=ss0 + w*s2(ipk +k,j) + ss1=ss1 + w*s2(ipk+ n+k,j) + ss2=ss2 + w*s2(ipk+2*n+k,j) + ss3=ss3 + w*s2(ipk+3*n+k,j) + enddo + a(j)=(max(ss1,ss3) - max(ss0,ss2))/sqrt(wsum) + endif + enddo + + do lag=lag1,lag2 + x=0. + do i=1,nsym + j=2*i-1+lag + if(j.ge.1 .and. j.le.nsteps) x=x+a(j)*pr2(i) + enddo + ccf(lag)=2*x !The 2 is for plotting scale + if(ccf(lag).gt.ccfmax) then + ccfmax=ccf(lag) + lagpk=lag + endif + + if(ccf(lag).lt.ccfmin) then + ccfmin=ccf(lag) + lagmin=lag + endif + enddo + + ccf0=ccfmax + flip=1.0 + if(-ccfmin.gt.ccfmax) then + do lag=lag1,lag2 + ccf(lag)=-ccf(lag) + enddo + lagpk=lagmin + ccf0=-ccfmin + flip=-1.0 + endif + + return +end subroutine xcor4 diff --git a/lib/zplt.f90 b/lib/zplt.f90 new file mode 100644 index 00000000..a7f6e571 --- /dev/null +++ b/lib/zplt.f90 @@ -0,0 +1,112 @@ +subroutine zplt(z,iplt,sync,dtx,nfreq,flip,sync2,nplot,emedelay,dttol, & + nfqso,ntol) + + real z(458,65) + real zz(458,65) + integer ij(2) + character*4 lab + + call pctile(z,458*65,84,rms) + fac=0.05/rms + z=fac*z + dtq=0.114286 + df=11025.0/(2.0*2520.0) + + ia=nint((nfqso-ntol)/df) - 273 + if(ia.lt.1) ia=1 + ib=nint((nfqso+ntol)/df) - 273 + if(ib.gt.458) ib=458 + ja=(emedelay+0.8-dttol)/dtq + if(ja.lt.1) ja=1 + jb=(emedelay+0.8+dttol)/dtq + if(jb.gt.65) jb=65 + + zz=0. + zz(ia:ib,ja:jb)=z(ia:ib,ja:jb) + + zmin=minval(zz) + zmax=maxval(zz) + flip=1.0 + if(abs(zmin).gt.abs(zmax)) flip=-1.0 + + ij=maxloc(zz) + if(flip.lt.0.0) ij=minloc(zz) + i0=ij(1) + j0=ij(2) + nfreq=nint((i0+273)*df) + dtx=j0*dtq-0.8 +! write(69,3101) ia,ib,ja,jb,ij,dtx,nfreq +!3101 format(6i5,f8.2,i6) + + ia=max(1,i0-72) + ib=min(458,i0+72) + sync=16.33*flip*(z(i0,j0) - 0.5*(z(ia,j0)+z(ib,j0))) + sync2=20.0*flip*z(i0,j0) + + if(nplot.eq.0) go to 900 + + zmax=max(abs(zmin),abs(zmax),1.0) + zmin=-zmax + + do j=1,65 + write(61,1100) j*dtq-0.8,z(i0,j) +1100 format(2f10.3) + enddo + + do i=1,458 + write(62,1100) (i+273)*df,flip*z(i,j0) + enddo + + xx=1.5 + yy=7.5 - 3.0*iplt + width=6.0 + height=2.0 + IP=458 + JP=65 + imax=IP + jmax=JP + + if(iplt.eq.0) then + call imopen("testjt4.ps") + call imfont("Helvetica",16) + call impalette("BlueRed.pal") + endif + + call imr4mat_color(z,IP,JP,imax,jmax,zmin,zmax,xx,yy, & + width,height,1) + call imstring("Frequency (Hz)",xx+0.5*width,yy-0.5,2,0) + dy=0.1 + do i=1,9 + x=xx + 0.1*i*width + call imyline(x,yy,dy) + call imyline(x,yy+height,-dy) + enddo + do i=1,6 + nf=(i-1)*200 + 600 + write(lab,1020) nf +1020 format(i4) + x=xx + (i-1)*0.2*width + call imstring(lab,x,yy-0.25,2,0) + enddo + + dx=0.1 + do i=0,6 + y=yy + height*(0.8+i)/(65.0*0.114286) + call imxline(xx,y,dx) + call imxline(xx+width,y,-dx) + enddo + + do i=0,6,2 + y=yy + height*(0.8+i)/(65.0*0.114286) + write(lab,1020) i + call imstring(lab(4:4),xx-0.15,y-0.08,2,0) + enddo + + y=yy + height*(3.8)/(65.0*0.114286) + call imstring("DT", xx-0.5,y ,2,0) + call imstring("(s)",xx-0.5,y-0.25,2,0) + + if(iplt.eq.2) call imclose + +900 return +end subroutine zplt -- cgit v1.2.3