Some repairs and tweaks to development-related programs in fsk4hf directory.

This commit is contained in:
Steven Franke 2020-02-09 16:13:52 -06:00
parent e9160f3c2f
commit cf07d478ac
4 changed files with 55 additions and 70 deletions

22
lib/fsk4hf/get_crc14.f90 Normal file
View File

@ -0,0 +1,22 @@
subroutine get_crc14(mc,ncrc)
character c14*14
integer*1 mc(68),r(15),p(15)
integer ncrc
! polynomial for 14-bit CRC 0x6757
data p/1,1,0,0,1,1,1,0,1,0,1,0,1,1,1/
! divide by polynomial
r=mc(1:15)
do i=0,53
r(15)=mc(i+15)
r=mod(r+r(1)*p,2)
r=cshift(r,1)
enddo
write(c14,'(14b1)') r(1:14)
read(c14,'(b14.14)') ncrc
! mc(55:68)=r(1:14)
end subroutine get_crc14

View File

@ -8,13 +8,15 @@ use packjt
parameter(NRECENT=10)
character*12 recent_calls(NRECENT)
character*8 arg
character*68 cmsg
character*14 c14
integer*1, allocatable :: codeword(:), decoded(:), message(:)
integer*1, target:: i1Msg8BitBytes(9)
integer*1, target:: i1Dec8BitBytes(9)
integer*1 msgbits(68)
integer*1 apmask(204)
integer*1 cw(204)
integer*2 checksum
integer*2 ncrc14,nrcrc14
integer colorder(204)
integer nerrtot(204),nerrdec(204),nmpcbad(68)
logical checksumok,fsk,bpsk
@ -36,6 +38,8 @@ data colorder/ &
170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186, &
187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203/
data cmsg/'11111111000000001111111100000000111111110000000011000000000000000000'/
do i=1,NRECENT
recent_calls(i)=' '
enddo
@ -66,41 +70,17 @@ N=204
K=68
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) )
! 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
read(cmsg,'(68i1)') msgbits
call get_crc14(msgbits,ncrcsf)
write(c14,'(b14.14)') ncrcsf
read(c14,'(14i1)') msgbits(55:68)
write(*,*) 'message'
write(*,'(9(8i1,1x))') msgbits
@ -112,12 +92,12 @@ write(*,*) i1Msg8BitBytes(1:9)
write(*,*) 'codeword'
write(*,'(204i1)') codeword
write(*,*) "Es/N0 SNR2500 ngood nundetected nbadcrc sigma"
do idb = 20,-18,-1
!do idb = -16, -16, -1
write(*,*) "Eb/N0 SNR2500 ngood nundetected nbadcrc sigma"
do idb = 10,-10,-1
!do idb = 2, 2, -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
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
@ -147,7 +127,6 @@ do idb = 20,-18,-1
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)
@ -166,58 +145,35 @@ do idb = 20,-18,-1
apmask=0
! max_iterations is max number of belief propagation iterations
call bpdecode204(llr,apmask,max_iterations,decoded,cw,nharderror,niterations)
if(nharderror.lt.0) niterations=-1
if( (nharderror .lt. 0) .and. (ndeep .ge. 0) ) then
call osd204(llr, apmask, ndeep, decoded, cw, nhardmin, dmin)
niterations=nhardmin
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, cw, nharderror, niterations)
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
call get_crc14(decoded,ncheck)
ncrcflag=0
if( crc10_check( c_loc( i1Dec8BitBytes ), 9 ) ) ncrcflag=1
if(ncheck.eq.0) ncrcflag=1
if( ncrcflag .ne. 1 ) then
nbadcrc=nbadcrc+1
endif
nueflag=0
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
if(ncrcflag.eq.1) nueflag=1
nerrmpc=nerrmpc+1
endif
enddo
if(nerrmpc.ge.1) 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

View File

@ -117,12 +117,12 @@ write(*,*) i1Msg8BitBytes(1:9)
write(*,*) 'codeword'
write(*,'(38(8i1,1x))') codeword
write(*,*) "Es/N0 SNR2500 ngood nundetected nbadcrc sigma"
write(*,*) "Eb/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
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

View File

@ -102,7 +102,7 @@ ntotal=0
nrejected=0
if(ndeep.eq.0) goto 998 ! norder=0
if(ndeep.gt.5) ndeep=5
if(ndeep.gt.6) ndeep=6
if( ndeep.eq. 1) then
nord=1
npre1=0
@ -136,6 +136,13 @@ elseif(ndeep.eq.5) then
nt=40
ntheta=12
ntau=19
elseif(ndeep.eq.6) then
nord=3
npre1=1
npre2=1
nt=60
ntheta=22
ntau=16
endif
do iorder=1,nord