js8call/lib/js8/ldpcsim174js8b.f90
Jordan Sherer c24e931f09 Squashed commit of the following:
commit 0d6833b23da2519155ee93b98b4144240b356730
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Sep 5 14:06:47 2019 -0400

    Bump version

commit 17705fcff6a22529f3dec45aa95cad90feb78c63
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Sep 5 10:36:03 2019 -0400

    Updated configration labeling for idle timeout

commit a9f8aa9549c1c6b62201a6c102d91649ee17b9a5
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Sep 5 10:07:11 2019 -0400

    Decoder params tests

commit 94e524741020fd8b3925233a189cedf0a8a282cc
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Sep 4 21:24:23 2019 -0400

    Fixed decoder bug that crashed the software

commit 4fdbfc8d9082e0f52513a5c215489b13558972f9
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Sep 4 21:02:52 2019 -0400

    Decoder params tweak

commit 1e25ac41d442372f09b254d957e0d9e31773254e
Merge: 97a0fb5 552cd7f
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Sep 4 18:17:40 2019 -0400

    Merge branch 'fortran-cleanup' of bitbucket.org:widefido/js8call-private into fortran-cleanup

commit 97a0fb51b37c24e2638400dc5694fc4e988ae4f2
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Sep 4 18:15:25 2019 -0400

    Heartbeat as a mode does not work if slow mode does not work. Tabling this idea for now.

commit 552cd7fe5fc81c712b57b5f3ea79599177e53f69
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 23:35:14 2019 +0000

    js8_params.f90 edited online with Bitbucket

commit 7c9e960b863148a4ecbca4f61584536471623ea2
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 16:28:52 2019 -0400

    Do not randomize offset at startup

commit cff7b90dbb9aada2944e668a9bcf078470af4608
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 16:20:19 2019 -0400

    Slow label for button

commit 977145dee89ccd7da4d43ce0bc2f9b79243aa200
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 16:17:36 2019 -0400

    Experimental slow mode

commit 27c128e0b327e1c077a9b49e11750bef2f3c26eb
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 15:26:01 2019 -0400

    HBs are Normal

commit 89792f91abf22dcd7c512bf7362f5e2e1cb36374
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 14:16:27 2019 -0400

    Update heartbeat UI for more clarity

commit f5cebbcdabe37d90b75ca7e8d1675a553e107c83
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 11:58:53 2019 -0400

    Optimize decode params

commit b14003bb34d93f9e93d7d4ad4241d619963c3a65
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 11:30:00 2019 -0400

    Shrink speed column for Joe ;)

commit 35f4446146efc9fd7044af3b56b0b93664238b24
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 10:54:28 2019 -0400

    Fixed fast mode decoder for directed messages

commit 64212acc30dd360348a72b354899a5b0de28aa83
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 10:05:11 2019 -0400

    Simplified decoder callbacks

commit a026766517d282a3fda0258356f6f22fee2a916f
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Sep 3 09:50:33 2019 -0400

    Commentary

commit 9d28b1ff5bd5cda7a04028218a01639e3902bf7b
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Sep 2 23:33:22 2019 -0400

    Let's experiment with a new UI for HB

commit a013d66d8b8d16cc941a14eb76af2ce23b7bb6d5
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Sep 2 21:44:26 2019 -0400

    31.25 baud experiment

commit 0671458bf588dd94710c5ba34f20695e13a28d31
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Sep 2 15:31:43 2019 -0400

    Added basic foundation for slow mode, coming soon.

commit 8b9aed6e29b093e8fb736ebdbdf0fbe12a820e8e
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Sep 2 09:59:08 2019 -0400

    Display SPEED+AUTO

commit 5f5af250c1c5b610e8969b32c01654d3467f0973
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sun Sep 1 09:45:39 2019 -0400

    Added mode speed option to the activity tables

commit 82fa0335fdd41f0a578149e0211d6307293c739d
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 23:14:07 2019 -0400

    Remember mode speed setting

commit 79ec805b223099bb4d552dc612a6c97a8982525e
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 21:14:04 2019 -0400

    Remove unused sync vars

commit fc52dfcc320e59f6c7ca58ba277cb70469419587
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 21:12:11 2019 -0400

    Timing delta max

commit 62b8fc5054d3611d40d7441d57d695df594b8446
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 17:14:08 2019 -0400

    Fast modes optionally can use huff encoding for data... we'll see which is best

commit 44c357aff3e1c6687e93fb843917bd420888b397
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 17:03:21 2019 -0400

    Added ability to use a different message packing algorithm for fast modes

commit e075a078eb75509ef690e6c78c0e797ada569b94
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 16:18:14 2019 -0400

    Fixed symbol offset in sync code for turbo mode

commit a130b5d4a594e9bceece003be0ba72abb05a9f90
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 31 16:09:27 2019 -0400

    Added WPM to menu

commit 98cacab7bfc243492b6dec703d216d378cc3d34d
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 30 23:18:58 2019 -0400

    Key eater

commit eef58e2c88d010c7f3917a111243eae744a425c3
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 30 16:07:31 2019 -0400

    Reorganizing js8dec for better understanding and less confusion between it and JS8b

commit 08c14f966e1cda836ca90a8bd1ccd5ae68ec8dd7
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 30 14:20:52 2019 -0400

    Do no expose relay and messaging to fast and turbo modes

commit c605a31c266866f78eb043812af837ead6442ede
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 30 12:02:41 2019 -0400

    Do not allow mode speed changes if transmitting

commit add062e657a5215f9a4a1ae3ee82063aa85cf0e4
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Aug 29 23:02:31 2019 -0400

    Fixed bug where tones were not generated with the correct costas arrays...causing really poor synchronization and failed decodes. I'm surprised it worked at all :P

commit cd492b5dd9fd62b5518a5711a1ef8ec522ea08fe
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Aug 29 21:56:45 2019 -0400

    Back to 20 baud. It has the best decodability, imho

commit a2266cd00b8bd14c77bdbc8fc18818689e969858
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Aug 29 14:27:29 2019 -0400

    Back to 20 baud with some decoder optimizations

commit 86413042e75873585bcb40236da67f2d64870859
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 23:04:47 2019 -0400

    Try 24 baud

commit a6704162b37d1c0704f43a64ab6b8a0a6e3c1cba
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 17:09:12 2019 -0400

    Fixed legacy compiler issue with mode text

commit 2fdbcc12e5f0c8cc8062c745af0930db4472cd9c
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 10:17:23 2019 -0400

    Function for determining current mode

commit 82e70345baa665418a51307f0309f2b7dcb3d3b7
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 09:59:26 2019 -0400

    Don't write the log

commit d3380e01676537f4bab9a05932cb5a59de3cf45f
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 09:59:03 2019 -0400

    Fixed issues with turbo decode with partial sync code

commit c2a8ebb8f305e67fcb2597d25e062663722a0d73
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 28 03:30:02 2019 -0400

    Working through better decoding of fast modes

commit 7ca93f8c6a7970559577c9dfd833eb92a1b91a0c
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 23:23:34 2019 -0400

    Trying for better TX/RX delays

commit b99271b4feaa7e41c7b88219cb3c7d43dbe7b48d
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 22:57:02 2019 -0400

    Added flags to easily enable/disable the faster modes

commit 32d913a7f7d3deb6a8d66651d51673ec451d2500
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 22:43:20 2019 -0400

    Added mode button

commit c7cc90548591638bfc5a4a8895036dd67b155aaa
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 22:17:42 2019 -0400

    Updated start delay for the modes

commit b91dc63f92101cd8b6adbf9de588c4ffd10bfc10
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 21:55:57 2019 -0400

    Late threshold for turbo mode is 1/2 the delay

commit 09ec95fab1307e65aa9bd462d60525afd2a770fe
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 21:52:55 2019 -0400

    Renamed mode menu items

commit a4e5a9ed9bce66c625e4df1182cd3c91a6ba44dd
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 21:50:45 2019 -0400

    Only enable networking and autoreply for normal JS8

commit fc558d5823c46fc5d3dc651610b7af43e7519165
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 21:14:12 2019 -0400

    Fixed spot button tooltip

commit 9a9965d543540a2d215bcbfff34934846afe507a
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 27 10:04:31 2019 -0400

    Working selectable decoder

commit 4a9cdbc52dae1d857c102d8777f1aded4fac87bb
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Aug 26 20:53:30 2019 -0400

    Mode menu selection of the submodes. Turbo decoder disabled right now. Naming to be determined

commit a3acbf7c243f7aa740c229ae178fffa528e68933
Merge: 8ea554d daa8cc2
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Aug 26 13:29:14 2019 -0400

    Merge branch 'ft8call-develop' into fortran-cleanup

commit 8ea554d79904c9b2f3ccf1027bf4d41fb25e6fe3
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Aug 26 09:53:21 2019 -0400

    Use indx variable instead of computed

commit 067e65500328133f921b172e515babbcc0df831b
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sun Aug 25 22:41:00 2019 -0400

    Make it easier to flip between modes

commit a544a7635201072f3ea20483353edf2e79dc813d
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sun Aug 25 21:18:46 2019 -0400

    Fixed sync issues with multi costas. Added log statements for future debugging

commit a8f3ead932017ae7d98fdb9a779bf3bb44bd395d
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sun Aug 25 15:54:59 2019 -0400

    Playing around with different costas arrays

commit fa89fe11a15d26abadd5102c8980620cfeffccd9
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sun Aug 25 15:51:45 2019 -0400

    Added reference to 7x7 costas arrays

commit 2417ebed6139534214f76ce94bdf1f54a966760a
Merge: 6011f1e 32fcabd
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 24 23:41:39 2019 -0400

    Merge branch 'ft8call-develop' into fortran-cleanup

commit 6011f1e807b1814399477d3c172db46831a090c6
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 24 23:35:42 2019 -0400

    Back to 10 baud. Update late threshold to be computed to 3/4 dead air time.

commit 41d3995861226f7208b2773430010a48abc125c1
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 24 15:36:12 2019 -0400

    Trying out 20 baud

commit a8d77e9e5b98f3f0bf19f68b53199b5952e8aaad
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 24 15:23:36 2019 -0400

    Fixed up sync quarter symbol constant

commit 7050722436b9c629ea00649e6b3c81d7af7be82a
Author: Jordan Sherer <jordan@widefido.com>
Date:   Sat Aug 24 14:43:48 2019 -0400

    Computed symbol stop

commit f130fe87abdccbabd2e71f2771b789c7f46d57ca
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 23 20:56:59 2019 -0400

    Added reference to 7x7 costas arrays

commit 53e91858f5a4e9ce78c38ef65c77e87f1903c058
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 23 16:34:51 2019 -0400

    Back to 10 baud

commit 1ae79d566ebd9a40ad3cf4a07977ef0e09615d91
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 23 15:14:41 2019 -0400

    Testing 31.25 baud

commit 7e033c28ae090d6c3f5a63fa651ee51c3243d61c
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 23 15:14:17 2019 -0400

    Experimenting with a few different baudrates

commit 050e24ad3a040924ded6d641004ae63da47e4251
Author: Jordan Sherer <jordan@widefido.com>
Date:   Fri Aug 23 12:25:50 2019 -0400

    Added ldpcsim for js8

commit d309a75d860e39737dec732560432a191290b258
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Aug 22 22:42:11 2019 -0400

    Experimental submode switching

commit 74f72bb24a22631b8b69942ea0633bb0564b8aa3
Author: Jordan Sherer <jordan@widefido.com>
Date:   Thu Aug 22 22:41:53 2019 -0400

    Allow switching decoders based on submode

commit f8740a23b27e80fa53350e140d4638a27cd6e975
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 23:43:18 2019 -0400

    Initial spike of js8 fortran code

commit 31625316639f79246b4a2e3d0cea4507bf0547f9
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 23:09:00 2019 -0400

    Remove fix contest message

commit c0e0862afa8ae2d47e9577562399b8c9bc929c6a
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 21:05:05 2019 -0400

    Cleanup unused text files and batch files

commit 1b3aa55869f0c310e6c911a7cbb3fe269bc7421a
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 21:00:38 2019 -0400

    Removed fast_decode and dx

commit 49e5cabff25c13620a9d2c6fc6ddd4988f1be217
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 20:54:39 2019 -0400

    Cleaning up msk stuff

commit 8bde6f391f4b23d2a2e9d55685d96bc647a462f6
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 21 20:44:39 2019 -0400

    Initial cleanup pass of qra, ftrsd, and wsprd
2019-09-05 14:07:24 -04:00

239 lines
7.0 KiB
Fortran

program ldpcsim174js8
! End to end test of the (174,75)/crc12 encoder and decoder.
use crc
use packjt
include 'js8_params.f90'
include 'js8b_params.f90'
character*22 msg,msgsent,msgreceived
character*8 arg
character*6 grid
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/
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="0123456789012"
! msg="G4WJS K9AN EN50"
call packmsg(msg,i4Msg6BitWords,itype,.false.) !Pack into 12 6-bit bytes
call unpackmsg(i4Msg6BitWords,msgsent,.false.,grid) !Unpack to get msgsent
write(*,*) "message sent ",msgsent
i4=0
ik=0
im=0
do i=1,12
nna=i4Msg6BitWords(i)
do j=1, 6
ik=ik+1
i4=i4+i4+iand(1,ishft(nna,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)
checksum = xor(checksum, 42) ! TODO: jsherer - could change the crc here
! For reference, the next 3 lines show how to check the CRC
i1Msg8BitBytes(10)=checksum/256
i1Msg8BitBytes(11)=iand(checksum,transfer(255,0_2))
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
if(nerr.ge.1) 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)
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
if(nerrmpc.ge.1) nmpcbad(nerrmpc)=nmpcbad(nerrmpc)+1
if( ncrcflag .eq. 1 ) then
if( nueflag .eq. 0 ) then
ngood=ngood+1
if(nerr.ge.1) nerrdec(nerr)=nerrdec(nerr)+1
else if( nueflag .eq. 1 ) then
nue=nue+1;
endif
endif
endif
enddo
baud=12000.0/NSPS
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 ldpcsim174js8