Implement coupled BP->OSD decoding for FT8/FT4.

This commit is contained in:
Steven Franke 2020-05-04 13:13:49 -05:00
parent 160a8c896c
commit 093c403063
8 changed files with 465 additions and 348 deletions

View File

@ -428,6 +428,7 @@ set (wsjt_FSRCS
lib/encode_128_90.f90 lib/encode_128_90.f90
lib/ft8/encode174.f90 lib/ft8/encode174.f90
lib/ft8/encode174_91.f90 lib/ft8/encode174_91.f90
lib/ft8/encode174_91_nocrc.f90
lib/entail.f90 lib/entail.f90
lib/ephem.f90 lib/ephem.f90
lib/extract.f90 lib/extract.f90
@ -603,12 +604,14 @@ set (wsjt_FSRCS
lib/fsk4hf/genwsprcpm.f90 lib/fsk4hf/genwsprcpm.f90
lib/fsk4hf/encode204.f90 lib/fsk4hf/encode204.f90
lib/fsk4hf/decode174_74.f90 lib/fsk4hf/decode174_74.f90
lib/ft8/decode174_91.f90
lib/fsk4hf/decode240_101.f90 lib/fsk4hf/decode240_101.f90
lib/fsk4hf/decode280_101.f90 lib/fsk4hf/decode280_101.f90
lib/fsk4hf/ldpcsim174_91.f90 lib/fsk4hf/ldpcsim174_91.f90
lib/fsk4hf/ldpcsim174_74.f90 lib/fsk4hf/ldpcsim174_74.f90
lib/fsk4hf/ldpcsim240_101.f90 lib/fsk4hf/ldpcsim240_101.f90
lib/fsk4hf/ldpcsim280_101.f90 lib/fsk4hf/ldpcsim280_101.f90
lib/fsk4hf/get_crc14.f90
lib/fsk4hf/get_crc24.f90 lib/fsk4hf/get_crc24.f90
lib/fsk4hf/encode174_74.f90 lib/fsk4hf/encode174_74.f90
lib/fsk4hf/encode240_101.f90 lib/fsk4hf/encode240_101.f90

View File

@ -1,15 +1,19 @@
subroutine get_crc14(mc,ncrc) subroutine get_crc14(mc,len,ncrc)
!
! 1. To calculate 14-bit CRC, mc(1:len-14) is the message and mc(len-13:len) are zero.
! 2. To check a received CRC, mc(1:len is the received message plus CRC.
! ncrc will be zero if the received message/CRC are consistent
!
character c14*14 character c14*14
integer*1 mc(len)
integer*1 mc(68),r(15),p(15) integer*1 r(15),p(15)
integer ncrc integer ncrc
! polynomial for 14-bit CRC 0x6757 ! polynomial for 14-bit CRC 0x6757
data p/1,1,0,0,1,1,1,0,1,0,1,0,1,1,1/ data p/1,1,0,0,1,1,1,0,1,0,1,0,1,1,1/
! divide by polynomial ! divide by polynomial
r=mc(1:15) r=mc(1:15)
do i=0,53 do i=0,len-15
r(15)=mc(i+15) r(15)=mc(i+15)
r=mod(r+r(1)*p,2) r=mod(r+r(1)*p,2)
r=cshift(r,1) r=cshift(r,1)
@ -17,6 +21,5 @@ subroutine get_crc14(mc,ncrc)
write(c14,'(14b1)') r(1:14) write(c14,'(14b1)') r(1:14)
read(c14,'(b14.14)') ncrc read(c14,'(b14.14)') ncrc
! mc(55:68)=r(1:14)
end subroutine get_crc14 end subroutine get_crc14

View File

@ -10,7 +10,7 @@ character*6 grid
character*96 tmpchar character*96 tmpchar
integer*1, allocatable :: codeword(:), decoded(:), message(:) integer*1, allocatable :: codeword(:), decoded(:), message(:)
integer*1 msgbits(77) integer*1 msgbits(77)
integer*1 message77(77) integer*1 message77(77),message91(91)
integer*1 apmask(N), cw(N) integer*1 apmask(N), cw(N)
integer nerrtot(0:N),nerrdec(0:N) integer nerrtot(0:N),nerrdec(0:N)
logical unpk77_success logical unpk77_success
@ -21,11 +21,12 @@ nerrtot=0
nerrdec=0 nerrdec=0
nargs=iargc() nargs=iargc()
if(nargs.ne.4) then if(nargs.ne.6) then
print*,'Usage: ldpcsim niter ndepth #trials s ' print*,'Usage: ldpcsim niter ndepth #trials s Keff BPOSD'
print*,'eg: ldpcsim 10 2 1000 0.84' print*,'eg: ldpcsim 10 2 1000 0.84 91 1'
print*,'belief propagation iterations: niter, ordered-statistics depth: ndepth' print*,'belief propagation iterations: niter, ordered-statistics depth: ndepth'
print*,'If s is negative, then value is ignored and sigma is calculated from SNR.' print*,'If s is negative, then value is ignored and sigma is calculated from SNR.'
print*,'If BPOSD=0, no coupling. BPOSD=1, BP output to OSD input.'
return return
endif endif
call getarg(1,arg) call getarg(1,arg)
@ -36,9 +37,13 @@ call getarg(3,arg)
read(arg,*) ntrials read(arg,*) ntrials
call getarg(4,arg) call getarg(4,arg)
read(arg,*) s read(arg,*) s
call getarg(5,arg)
read(arg,*) Keff
call getarg(6,arg)
read(arg,*) nbposd
! scale Eb/No for a (174,91) code ! scale Eb/No for a (174,91) code
rate=real(K)/real(N) rate=real(Keff)/real(N)
write(*,*) "rate: ",rate write(*,*) "rate: ",rate
write(*,*) "niter= ",max_iterations," s= ",s write(*,*) "niter= ",max_iterations," s= ",s
@ -46,8 +51,7 @@ write(*,*) "niter= ",max_iterations," s= ",s
allocate ( codeword(N), decoded(K), message(K) ) allocate ( codeword(N), decoded(K), message(K) )
allocate ( rxdata(N), llr(N) ) allocate ( rxdata(N), llr(N) )
! msg="K1JT K9AN EN50" msg="K9ABC K1ABC FN20"
msg="G4WJS K9AN EN50"
i3=0 i3=0
n3=1 n3=1
call pack77(msg,i3,n3,c77) !Pack into 12 6-bit bytes call pack77(msg,i3,n3,c77) !Pack into 12 6-bit bytes
@ -55,20 +59,19 @@ allocate ( rxdata(N), llr(N) )
write(*,*) "message sent ",msgsent write(*,*) "message sent ",msgsent
read(c77,'(77i1)') msgbits(1:77) read(c77,'(77i1)') msgbits(1:77)
write(*,*) 'message' write(*,*) 'message'
write(*,'(a71,1x,a3,1x,a3)') c77(1:71),c77(72:74),c77(75:77) write(*,'(a71,1x,a3,1x,a3)') c77(1:71),c77(72:74),c77(75:77)
call encode174_91(msgbits,codeword)
call init_random_seed() call init_random_seed()
call encode174_91(msgbits,codeword)
write(*,*) 'crc14'
write(*,'(14i1)') codeword(78:91)
write(*,*) 'codeword' write(*,*) 'codeword'
write(*,'(22(8i1,1x))') codeword write(*,'(22(8i1,1x))') codeword
write(*,*) "Eb/N0 SNR2500 ngood nundetected sigma psymerr" write(*,*) "Eb/N0 SNR2500 ngood nundetected sigma psymerr"
do idb = 20,-10,-1 do idb = 10,-4,-1
!do idb = 0,0,-1
db=idb/2.0-1.0 db=idb/2.0-1.0
sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) sigma=1/sqrt( 2*rate*(10**(db/10.0)) )
ngood=0 ngood=0
@ -101,14 +104,19 @@ do idb = 20,-10,-1
llr(1:nap)=5*(2.0*msgbits(1:nap)-1.0) llr(1:nap)=5*(2.0*msgbits(1:nap)-1.0)
apmask=0 apmask=0
apmask(1:nap)=1 apmask(1:nap)=1
! max_iterations is max number of belief propagation iterations ! max_iterations is max number of belief propagation iterations
call bpdecode174_91(llr, apmask, max_iterations, message77, cw, nharderrors,niterations,ncheck) call bpdecode174_91(llr, apmask, max_iterations, message77, cw, nhardbp,niterations,ncheck)
if( ndepth .ge. 0 .and. nharderrors .lt. 0 ) call osd174_91(llr, apmask, ndepth, message77, cw, nharderrors, dmin) if( ndepth .ge. 0 .and. nhardbp .lt. 0 ) then
!call decode174_91(llr, apmask, max_iterations, message77, cw, nharderrors,niterations,ncheck,dmin,nsuper) dmin=0.0
if(nbposd.eq.0) then
call osd174_91(llr,Keff,apmask,ndepth,message91,cw,nhardosd,dmin)
else
maxsuper=2
call decode174_91(llr,Keff,ndepth,apmask,maxsuper,message91,cw,nhardosd,niterations,ncheck,dmin)
endif
! If the decoder finds a valid codeword, nharderrors will be .ge. 0. ! If the decoder finds a valid codeword, nharderrors will be .ge. 0.
if( nharderrors .ge. 0 ) then endif
call extractmessage77(message77,msgreceived) if( nhardbp .ge. 0 .or. nhardosd.ge.0 ) then
nhw=count(cw.ne.codeword) nhw=count(cw.ne.codeword)
if(nhw.eq.0) then ! this is a good decode if(nhw.eq.0) then ! this is a good decode
ngood=ngood+1 ngood=ngood+1

View File

@ -56,6 +56,7 @@ contains
integer apmy_ru(28),aphis_fd(28) integer apmy_ru(28),aphis_fd(28)
integer*2 iwave(NMAX) !Raw received data integer*2 iwave(NMAX) !Raw received data
integer*1 message77(77),rvec(77),apmask(2*ND),cw(2*ND) integer*1 message77(77),rvec(77),apmask(2*ND),cw(2*ND)
integer*1 message91(91)
integer*1 hbits(2*NN) integer*1 hbits(2*NN)
integer i4tone(103) integer i4tone(103)
integer nappasses(0:5) ! # of decoding passes for QSO States 0-5 integer nappasses(0:5) ! # of decoding passes for QSO States 0-5
@ -412,12 +413,19 @@ contains
call timer('bpdec174',1) call timer('bpdec174',1)
if(doosd .and. nharderror.lt.0) then if(doosd .and. nharderror.lt.0) then
ndeep=3 ! ndeep=3
ndeep=2
if(abs(nfqso-f1).le.napwid) then if(abs(nfqso-f1).le.napwid) then
ndeep=4 ! ndeep=4
ndeep=3
endif endif
call timer('osd174_91 ',0) call timer('osd174_91 ',0)
call osd174_91(llr,apmask,ndeep,message77,cw,nharderror,dmin) Keff=91
maxsuper=2
! call osd174_91(llr,Keff,apmask,ndeep,message91,cw,nharderror,dmin)
call decode174_91(llr,Keff,ndeep,apmask,maxsuper,message91,cw,nharderror, &
niterations,ncheck,dmin)
message77=message91(1:77)
call timer('osd174_91 ',1) call timer('osd174_91 ',1)
endif endif

View File

@ -1,13 +1,12 @@
subroutine decode174_91(llr,apmask,maxiterations,message77,cw,nharderror,iter,ncheck,dmin,isuper) subroutine decode174_91(llr,Keff,ndeep,apmask,maxsuper,message91,cw,nharderror,iter,ncheck,dmin)
! !
! A hybrid bp/osd decoder for the (174,91) code. ! A hybrid bp/osd decoder for the (174,91) code.
! !
use iso_c_binding, only: c_loc,c_size_t
use crc
integer, parameter:: N=174, K=91, M=N-K integer, parameter:: N=174, K=91, M=N-K
integer*1 cw(N),apmask(N) integer*1 cw(N),apmask(N)
integer*1 decoded(K) integer*1 decoded(K)
integer*1 message77(77) integer*1 nxor(N),hdec(N)
integer*1 message91(91)
integer nrw(M),ncw integer nrw(M),ncw
integer Nm(7,M) integer Nm(7,M)
integer Mn(3,N) ! 3 checks per bit integer Mn(3,N) ! 3 checks per bit
@ -35,7 +34,6 @@ enddo
ncnt=0 ncnt=0
nclast=0 nclast=0
maxsuper=5
maxiterations=1 maxiterations=1
zsum=0.0 zsum=0.0
@ -63,10 +61,12 @@ zsum=zsum+zn
! write(*,*) 'number of unsatisfied parity checks ',ncheck ! write(*,*) 'number of unsatisfied parity checks ',ncheck
if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it
decoded=cw(1:K) decoded=cw(1:K)
call chkcrc14a(decoded,nbadcrc) call get_crc14(decoded,91,nbadcrc)
write(*,*) nbadcrc
write(*,'(91i1)') decoded
nharderror=count( (2*cw-1)*llr .lt. 0.0 ) nharderror=count( (2*cw-1)*llr .lt. 0.0 )
if(nbadcrc.eq.0) then if(nbadcrc.eq.0) then
message77=decoded(1:77) message91=decoded(1:91)
dmin=0.0 dmin=0.0
return return
endif endif
@ -118,13 +118,18 @@ dmin=0.0
enddo enddo
enddo ! bp iterations enddo ! bp iterations
ndeep=1
llr=zsum call osd174_91(zsum,Keff,apmask,ndeep,message91,cw,nharderror,dminosd)
call osd174_91(llr,apmask,ndeep,message77,cw,nharderror,dmin)
if(nharderror.gt.0) then if(nharderror.gt.0) then
hdec=0
where(llr .ge. 0) hdec=1
nxor=ieor(hdec,cw)
dmin=sum(nxor*abs(llr))
return return
endif endif
enddo ! super iterations enddo ! super iterations
nharderror=-1 nharderror=-1
return return
end subroutine decode174_91 end subroutine decode174_91

View File

@ -0,0 +1,49 @@
subroutine encode174_91_nocrc(message,codeword)
!
! Add a 14-bit CRC to a 77-bit message and return a 174-bit codeword
!
use, intrinsic :: iso_c_binding
use iso_c_binding, only: c_loc,c_size_t
use crc
integer, parameter:: N=174, K=91, M=N-K
character*91 tmpchar
integer*1 codeword(N)
integer*1 gen(M,K)
integer*1 message(K)
integer*1 pchecks(M)
integer*1, target :: i1MsgBytes(12)
include "ldpc_174_91_c_generator.f90"
logical first
data first/.true./
save first,gen
if( first ) then ! fill the generator matrix
gen=0
do i=1,M
do j=1,23
read(g(i)(j:j),"(Z1)") istr
ibmax=4
if(j.eq.23) ibmax=3
do jj=1, ibmax
icol=(j-1)*4+jj
if( btest(istr,4-jj) ) gen(i,icol)=1
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
codeword(1:K)=message
codeword(K+1:N)=pchecks
return
end subroutine encode174_91_nocrc

View File

@ -18,7 +18,7 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, &
real llra(174),llrb(174),llrc(174),llrd(174),llrz(174) !Soft symbols real llra(174),llrb(174),llrc(174),llrd(174),llrz(174) !Soft symbols
real dd0(15*12000) real dd0(15*12000)
real ss(9) real ss(9)
integer*1 message77(77),apmask(174),cw(174) integer*1 message77(77),message91(91),apmask(174),cw(174)
integer apsym(58),aph10(10) integer apsym(58),aph10(10)
integer mcq(29),mcqru(29),mcqfd(29),mcqtest(29),mcqww(29) integer mcq(29),mcqru(29),mcqfd(29),mcqtest(29),mcqww(29)
integer mrrr(19),m73(19),mrr73(19) integer mrrr(19),m73(19),mrr73(19)
@ -407,12 +407,19 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, &
dmin=0.0 dmin=0.0
if(nharderrors.lt.0 .and. ncheck.le.30 .and. ndepth.ge.2) then if(nharderrors.lt.0 .and. ncheck.le.30 .and. ndepth.ge.2) then
ndeep=ndepth ndeep=ndepth
!ndeep=ndepth-1
if(abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid .or. ncontest.eq.7) then if(abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid .or. ncontest.eq.7) then
ndeep=4 ndeep=4
!ndeep=3
endif endif
if(nagain) ndeep=5 if(nagain) ndeep=5
!if(nagain) ndeep=4
call timer('osd174_91 ',0) call timer('osd174_91 ',0)
call osd174_91(llrz,apmask,ndeep,message77,cw,nharderrors,dmin) Keff=91
! call osd174_91(llrz,Keff,apmask,ndeep,message91,cw,nharderrors,dmin)
maxsuper=2
call decode174_91(llrz,Keff,ndeep,apmask,maxsuper,message91,cw,nharderrors,niterations,ncheck,dmin)
if(nharderrors.ge.0) message77=message91(1:77)
call timer('osd174_91 ',1) call timer('osd174_91 ',1)
endif endif

View File

@ -1,78 +1,102 @@
subroutine osd174_91(llr,apmask,ndeep,message77,cw,nhardmin,dmin) subroutine osd174_91(llr,k,apmask,ndeep,message91,cw,nhardmin,dmin)
! !
! An ordered-statistics decoder for the (174,91) code. ! An ordered-statistics decoder for the (174,91) code.
! Message payload is 77 bits. Any or all of a 14-bit CRC can be
! used for detecting incorrect codewords. The remaining CRC bits are
! cascaded with the LDPC code for the purpose of improving the
! distance spectrum of the code.
! !
integer, parameter:: N=174, K=91, M=N-K ! If p1 (0.le.p1.le.14) is the number of CRC14 bits that are
integer*1 apmask(N),apmaskr(N) ! to be used for bad codeword detection, then the argument k should
integer*1 gen(K,N) ! be set to 77+p1.
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) ! Valid values for k are in the range [77,91].
integer*1 r2pat(N-K) !
integer indices(N),nxor(N) character*14 c14
integer*1 cw(N),ce(N),c0(N),hdec(N) integer, parameter:: N=174
integer*1 decoded(K) integer*1 apmask(N),apmaskr(N)
integer*1 message77(77) integer*1, allocatable, save :: gen(:,:)
integer indx(N) integer*1, allocatable :: genmrb(:,:),g2(:,:)
real llr(N),rx(N),absrx(N) integer*1, allocatable :: temp(:),m0(:),me(:),mi(:),misub(:),e2sub(:),e2(:),ui(:)
integer*1, allocatable :: r2pat(:)
integer indices(N),nxor(N)
integer*1 cw(N),ce(N),c0(N),hdec(N)
integer*1, allocatable :: decoded(:)
integer*1 message91(91),m96(96)
integer indx(N)
real llr(N),rx(N),absrx(N)
include "ldpc_174_91_c_generator.f90" logical first,reset
data first/.true./
save first
logical first,reset allocate( genmrb(k,N), g2(N,k) )
data first/.true./ allocate( temp(k), m0(k), me(k), mi(k), misub(k), e2sub(N-k), e2(N-k), ui(N-k) )
save first,gen allocate( r2pat(N-k), decoded(k) )
if( first ) then ! fill the generator matrix if( first ) then ! fill the generator matrix
!
! Create generator matrix for partial CRC cascaded with LDPC code.
!
! Let p2=91-k and p1+p2=14.
!
! The last p2 bits of the CRC14 are cascaded with the LDPC code.
!
! The first p1=k-77 CRC14 bits will be used for error detection.
!
allocate( gen(k,N) )
gen=0 gen=0
do i=1,M do i=1,k
do j=1,23 message91=0
read(g(i)(j:j),"(Z1)") istr message91(i)=1
ibmax=4 if(i.le.77) then
if(j.eq.23) ibmax=3 m96=0
do jj=1, ibmax m96(1:91)=message91
irow=(j-1)*4+jj call get_crc14(m96,96,ncrc14)
if( btest(istr,4-jj) ) gen(irow,K+i)=1 write(c14,'(b14.14)') ncrc14
read(c14,'(14i1)') message91(78:91)
message91(78:k)=0
endif
call encode174_91_nocrc(message91,cw)
gen(i,:)=cw
enddo enddo
enddo
enddo
do irow=1,K
gen(irow,irow)=1
enddo
first=.false.
endif
rx=llr first=.false.
apmaskr=apmask endif
rx=llr
apmaskr=apmask
! Hard decisions on the received word. ! Hard decisions on the received word.
hdec=0 hdec=0
where(rx .ge. 0) hdec=1 where(rx .ge. 0) hdec=1
! Use magnitude of received symbols as a measure of reliability. ! Use magnitude of received symbols as a measure of reliability.
absrx=abs(rx) absrx=abs(rx)
call indexx(absrx,N,indx) call indexx(absrx,N,indx)
! Re-order the columns of the generator matrix in order of decreasing reliability. ! Re-order the columns of the generator matrix in order of decreasing reliability.
do i=1,N do i=1,N
genmrb(1:K,i)=gen(1:K,indx(N+1-i)) genmrb(1:k,i)=gen(1:k,indx(N+1-i))
indices(i)=indx(N+1-i) indices(i)=indx(N+1-i)
enddo enddo
! Do gaussian elimination to create a generator matrix with the most reliable ! 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). ! received bits in positions 1:k in order of decreasing reliability (more or less).
do id=1,K ! diagonal element indices do id=1,k ! diagonal element indices
do icol=id,K+20 ! The 20 is ad hoc - beware do icol=id,k+20 ! The 20 is ad hoc - beware
iflag=0 iflag=0
if( genmrb(id,icol) .eq. 1 ) then if( genmrb(id,icol) .eq. 1 ) then
iflag=1 iflag=1
if( icol .ne. id ) then ! reorder column if( icol .ne. id ) then ! reorder column
temp(1:K)=genmrb(1:K,id) temp(1:k)=genmrb(1:k,id)
genmrb(1:K,id)=genmrb(1:K,icol) genmrb(1:k,id)=genmrb(1:k,icol)
genmrb(1:K,icol)=temp(1:K) genmrb(1:k,icol)=temp(1:k)
itmp=indices(id) itmp=indices(id)
indices(id)=indices(icol) indices(id)=indices(icol)
indices(icol)=itmp indices(icol)=itmp
endif endif
do ii=1,K do ii=1,k
if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then
genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N))
endif endif
@ -80,74 +104,82 @@ do id=1,K ! diagonal element indices
exit exit
endif endif
enddo enddo
enddo enddo
g2=transpose(genmrb) g2=transpose(genmrb)
! The hard decisions for the K MRB bits define the order 0 message, m0. ! 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. ! 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 ! 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 ! codewords. Return the member of the list that has the smallest Euclidean
! distance to the received word. ! distance to the received word.
hdec=hdec(indices) ! hard decisions from received symbols hdec=hdec(indices) ! hard decisions from received symbols
m0=hdec(1:K) ! zero'th order message m0=hdec(1:k) ! zero'th order message
absrx=absrx(indices) absrx=absrx(indices)
rx=rx(indices) rx=rx(indices)
apmaskr=apmaskr(indices) apmaskr=apmaskr(indices)
call mrbencode91(m0,c0,g2,N,K) call mrbencode91(m0,c0,g2,N,k)
nxor=ieor(c0,hdec) nxor=ieor(c0,hdec)
nhardmin=sum(nxor) nhardmin=sum(nxor)
dmin=sum(nxor*absrx) dmin=sum(nxor*absrx)
cw=c0 cw=c0
ntotal=0 ntotal=0
nrejected=0 nrejected=0
npre1=0 npre1=0
npre2=0 npre2=0
if(ndeep.eq.0) goto 998 ! norder=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 if( ndeep.eq. 1) then
nord=1 nord=1
npre1=0 npre1=0
npre2=0 npre2=0
nt=40 nt=40
ntheta=12 ntheta=12
elseif(ndeep.eq.2) then elseif(ndeep.eq.2) then
nord=1 nord=1
npre1=1 npre1=1
npre2=0 npre2=0
nt=40 nt=40
ntheta=12 ! ntheta=12
elseif(ndeep.eq.3) then ntheta=10
elseif(ndeep.eq.3) then
nord=1 nord=1
npre1=1 npre1=1
npre2=1 npre2=1
nt=40 nt=40
ntheta=12 ntheta=12
ntau=14 ntau=14
elseif(ndeep.eq.4) then elseif(ndeep.eq.4) then
nord=2
npre1=1
npre2=0
nt=40
ntheta=12
ntau=19
elseif(ndeep.eq.5) then
nord=2 nord=2
npre1=1 npre1=1
npre2=1 npre2=1
nt=40 nt=40
ntheta=12 ntheta=12
ntau=19 ntau=17
endif elseif(ndeep.eq.5) then
nord=3
npre1=1
npre2=1
nt=40
ntheta=12
ntau=15
elseif(ndeep.eq.6) then
nord=4
npre1=1
npre2=1
nt=95
ntheta=12
ntau=15
endif
do iorder=1,nord do iorder=1,nord
misub(1:K-iorder)=0 misub(1:k-iorder)=0
misub(K-iorder+1:K)=1 misub(k-iorder+1:k)=1
iflag=K-iorder+1 iflag=k-iorder+1
do while(iflag .ge.0) do while(iflag .ge.0)
if(iorder.eq.nord .and. npre1.eq.0) then if(iorder.eq.nord .and. npre1.eq.0) then
iend=iflag iend=iflag
@ -158,32 +190,32 @@ do iorder=1,nord
do n1=iflag,iend,-1 do n1=iflag,iend,-1
mi=misub mi=misub
mi(n1)=1 mi(n1)=1
if(any(iand(apmaskr(1:K),mi).eq.1)) cycle if(any(iand(apmaskr(1:k),mi).eq.1)) cycle
ntotal=ntotal+1 ntotal=ntotal+1
me=ieor(m0,mi) me=ieor(m0,mi)
if(n1.eq.iflag) then if(n1.eq.iflag) then
call mrbencode91(me,ce,g2,N,K) call mrbencode91(me,ce,g2,N,k)
e2sub=ieor(ce(K+1:N),hdec(K+1:N)) e2sub=ieor(ce(k+1:N),hdec(k+1:N))
e2=e2sub e2=e2sub
nd1Kpt=sum(e2sub(1:nt))+1 nd1kpt=sum(e2sub(1:nt))+1
d1=sum(ieor(me(1:K),hdec(1:K))*absrx(1:K)) d1=sum(ieor(me(1:k),hdec(1:k))*absrx(1:k))
else else
e2=ieor(e2sub,g2(K+1:N,n1)) e2=ieor(e2sub,g2(k+1:N,n1))
nd1Kpt=sum(e2(1:nt))+2 nd1kpt=sum(e2(1:nt))+2
endif endif
if(nd1Kpt .le. ntheta) then if(nd1kpt .le. ntheta) then
call mrbencode91(me,ce,g2,N,K) call mrbencode91(me,ce,g2,N,k)
nxor=ieor(ce,hdec) nxor=ieor(ce,hdec)
if(n1.eq.iflag) then if(n1.eq.iflag) then
dd=d1+sum(e2sub*absrx(K+1:N)) dd=d1+sum(e2sub*absrx(k+1:N))
else else
dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(K+1:N)) dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(k+1:N))
endif endif
if( dd .lt. dmin ) then if( dd .lt. dmin ) then
dmin=dd dmin=dd
cw=ce cw=ce
nhardmin=sum(nxor) nhardmin=sum(nxor)
nd1Kptbest=nd1Kpt nd1kptbest=nd1kpt
endif endif
else else
nrejected=nrejected+1 nrejected=nrejected+1
@ -193,15 +225,15 @@ do iorder=1,nord
! when the last pattern with weight iorder has been generated. ! when the last pattern with weight iorder has been generated.
call nextpat91(misub,k,iorder,iflag) call nextpat91(misub,k,iorder,iflag)
enddo enddo
enddo enddo
if(npre2.eq.1) then if(npre2.eq.1) then
reset=.true. reset=.true.
ntotal=0 ntotal=0
do i1=K,1,-1 do i1=k,1,-1
do i2=i1-1,1,-1 do i2=i1-1,1,-1
ntotal=ntotal+1 ntotal=ntotal+1
mi(1:ntau)=ieor(g2(K+1:K+ntau,i1),g2(K+1:K+ntau,i2)) mi(1:ntau)=ieor(g2(k+1:k+ntau,i1),g2(k+1:k+ntau,i2))
call boxit91(reset,mi(1:ntau),ntau,ntotal,i1,i2) call boxit91(reset,mi(1:ntau),ntau,ntotal,i1,i2)
enddo enddo
enddo enddo
@ -210,13 +242,13 @@ if(npre2.eq.1) then
ntotal2=0 ntotal2=0
reset=.true. reset=.true.
! Now run through again and do the second pre-processing rule ! Now run through again and do the second pre-processing rule
misub(1:K-nord)=0 misub(1:k-nord)=0
misub(K-nord+1:K)=1 misub(k-nord+1:k)=1
iflag=K-nord+1 iflag=k-nord+1
do while(iflag .ge.0) do while(iflag .ge.0)
me=ieor(m0,misub) me=ieor(m0,misub)
call mrbencode91(me,ce,g2,N,K) call mrbencode91(me,ce,g2,N,k)
e2sub=ieor(ce(K+1:N),hdec(K+1:N)) e2sub=ieor(ce(k+1:N),hdec(k+1:N))
do i2=0,ntau do i2=0,ntau
ntotal2=ntotal2+1 ntotal2=ntotal2+1
ui=0 ui=0
@ -229,9 +261,9 @@ if(npre2.eq.1) then
mi=misub mi=misub
mi(in1)=1 mi(in1)=1
mi(in2)=1 mi(in2)=1
if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:K),mi).eq.1)) cycle if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:k),mi).eq.1)) cycle
me=ieor(m0,mi) me=ieor(m0,mi)
call mrbencode91(me,ce,g2,N,K) call mrbencode91(me,ce,g2,N,k)
nxor=ieor(ce,hdec) nxor=ieor(ce,hdec)
dd=sum(nxor*absrx) dd=sum(nxor*absrx)
if( dd .lt. dmin ) then if( dd .lt. dmin ) then
@ -242,24 +274,26 @@ if(npre2.eq.1) then
goto 778 goto 778
endif endif
enddo enddo
call nextpat91(misub,K,nord,iflag) call nextpat91(misub,k,nord,iflag)
enddo enddo
endif endif
998 continue 998 continue
! Re-order the codeword to [message bits][parity bits] format. ! Re-order the codeword to [message bits][parity bits] format.
cw(indices)=cw cw(indices)=cw
hdec(indices)=hdec hdec(indices)=hdec
decoded=cw(1:K) message91=cw(1:91)
call chkcrc14a(decoded,nbadcrc) m96=0
message77=decoded(1:77) m96(1:77)=cw(1:77)
if(nbadcrc.eq.1) nhardmin=-nhardmin m96(83:96)=cw(78:91)
call get_crc14(m96,96,nbadcrc)
if(nbadcrc.ne.0) nhardmin=-nhardmin
return return
end subroutine osd174_91 end subroutine osd174_91
subroutine mrbencode91(me,codeword,g2,N,K) subroutine mrbencode91(me,codeword,g2,N,K)
integer*1 me(K),codeword(N),g2(N,K) integer*1 me(K),codeword(N),g2(N,K)
! fast encoding for low-weight test patterns ! fast encoding for low-weight test patterns
codeword=0 codeword=0
do i=1,K do i=1,K
@ -267,7 +301,7 @@ integer*1 me(K),codeword(N),g2(N,K)
codeword=ieor(codeword,g2(1:N,i)) codeword=ieor(codeword,g2(1:N,i))
endif endif
enddo enddo
return return
end subroutine mrbencode91 end subroutine mrbencode91
subroutine nextpat91(mi,k,iorder,iflag) subroutine nextpat91(mi,k,iorder,iflag)