2017-05-07 11:00:50 -04:00
|
|
|
subroutine osd300(llr,norder,decoded,niterations,cw)
|
2017-05-05 22:35:38 -04:00
|
|
|
!
|
2017-05-07 11:00:50 -04:00
|
|
|
! An ordered-statistics decoder based on ideas from:
|
2017-05-05 22:35:38 -04:00
|
|
|
! "Soft-decision decoding of linear block codes based on ordered statistics,"
|
|
|
|
! by Marc P. C. Fossorier and Shu Lin,
|
|
|
|
! IEEE Trans Inf Theory, Vol 41, No 5, Sep 1995
|
|
|
|
!
|
2017-05-07 11:00:50 -04:00
|
|
|
|
|
|
|
include "ldpc_300_60_params.f90"
|
|
|
|
|
|
|
|
integer*1 gen(K,N)
|
|
|
|
integer*1 genmrb(K,N)
|
2017-05-11 18:55:31 -04:00
|
|
|
integer*1 temp(K),m0(K),me(0:K)
|
2017-05-07 11:00:50 -04:00
|
|
|
integer indices(N)
|
2017-05-05 22:49:15 -04:00
|
|
|
integer*1 codeword(N),cw(N),hdec(N)
|
2017-05-05 22:35:38 -04:00
|
|
|
integer*1 decoded(K)
|
2017-05-05 22:49:15 -04:00
|
|
|
integer indx(N)
|
|
|
|
real llr(N),rx(N),absrx(N)
|
2017-05-05 22:35:38 -04:00
|
|
|
logical first
|
|
|
|
data first/.true./
|
|
|
|
|
|
|
|
save first,gen
|
|
|
|
|
|
|
|
if( first ) then ! fill the generator matrix
|
|
|
|
gen=0
|
2017-05-07 11:00:50 -04:00
|
|
|
do i=1,M
|
2017-05-05 22:35:38 -04:00
|
|
|
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
|
2017-05-07 11:00:50 -04:00
|
|
|
do irow=1,K
|
|
|
|
gen(irow,M+irow)=1
|
2017-05-05 22:35:38 -04:00
|
|
|
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)
|
2017-05-11 18:55:31 -04:00
|
|
|
|
|
|
|
! re-order the columns of the generator matrix in order of decreasing reliability.
|
2017-05-05 22:35:38 -04:00
|
|
|
do i=1,N
|
2017-05-11 18:55:31 -04:00
|
|
|
genmrb(1:K,i)=gen(1:K,indx(N+1-i))
|
|
|
|
indices(i)=indx(N+1-i)
|
2017-05-05 22:35:38 -04:00
|
|
|
enddo
|
|
|
|
|
|
|
|
! do gaussian elimination to create a generator matrix with the most reliable
|
2017-05-11 18:55:31 -04:00
|
|
|
! 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.
|
2017-05-05 22:35:38 -04:00
|
|
|
do id=1,K ! diagonal element indices
|
2017-05-11 18:55:31 -04:00
|
|
|
do icol=id,K+20 ! The 20 is ad hoc - beware
|
2017-05-05 22:35:38 -04:00
|
|
|
iflag=0
|
|
|
|
if( genmrb(id,icol) .eq. 1 ) then
|
|
|
|
iflag=1
|
2017-05-11 18:55:31 -04:00
|
|
|
if( icol .ne. id ) then ! reorder column
|
|
|
|
temp(1:K)=genmrb(1:K,id)
|
|
|
|
genmrb(1:K,id)=genmrb(1:K,icol)
|
2017-05-07 11:00:50 -04:00
|
|
|
genmrb(1:K,icol)=temp(1:K)
|
2017-05-11 18:55:31 -04:00
|
|
|
itmp=indices(id)
|
|
|
|
indices(id)=indices(icol)
|
2017-05-05 22:35:38 -04:00
|
|
|
indices(icol)=itmp
|
|
|
|
endif
|
|
|
|
do ii=1,K
|
2017-05-11 18:55:31 -04:00
|
|
|
if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then
|
2017-05-05 22:35:38 -04:00
|
|
|
genmrb(ii,1:N)=mod(genmrb(ii,1:N)+genmrb(id,1:N),2)
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
exit
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
|
2017-05-11 18:55:31 -04:00
|
|
|
! 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)
|
|
|
|
m0=hdec(1:K)
|
2017-05-05 22:35:38 -04:00
|
|
|
|
2017-05-07 11:00:50 -04:00
|
|
|
nhardmin=N
|
|
|
|
j0=0
|
|
|
|
j1=0
|
|
|
|
j2=0
|
|
|
|
j3=0
|
|
|
|
if( norder.ge.4 ) j0=K
|
|
|
|
if( norder.ge.3 ) j1=K
|
|
|
|
if( norder.ge.2 ) j2=K
|
|
|
|
if( norder.ge.1 ) j3=K
|
2017-05-11 18:55:31 -04:00
|
|
|
! me(0) is a dummy position --- only me(1:K) are actually used. This is done
|
|
|
|
! to avoid "if" statements within the inner loop.
|
2017-05-07 11:00:50 -04:00
|
|
|
do i1=0,j0
|
|
|
|
do i2=i1,j1
|
|
|
|
do i3=i2,j2
|
|
|
|
do i4=i3,j3
|
2017-05-11 18:55:31 -04:00
|
|
|
me(1:K)=m0
|
|
|
|
me(i1)=1-me(i1)
|
|
|
|
me(i2)=1-me(i2)
|
|
|
|
me(i3)=1-me(i3)
|
|
|
|
me(i4)=1-me(i4)
|
2017-05-05 22:35:38 -04:00
|
|
|
|
2017-05-11 18:55:31 -04:00
|
|
|
! me is the m0 + error pattern. encode this message using genmrb to
|
|
|
|
! produce a codeword. test the codeword against the received vector
|
|
|
|
! and save it if it's the best that we've seen so far.
|
2017-05-07 11:00:50 -04:00
|
|
|
do i=1,N
|
2017-05-11 18:55:31 -04:00
|
|
|
nsum=sum(iand(me(1:K),genmrb(1:K,i)))
|
2017-05-05 22:35:38 -04:00
|
|
|
codeword(i)=mod(nsum,2)
|
|
|
|
enddo
|
|
|
|
nhard=count(codeword .ne. hdec)
|
|
|
|
if( nhard .lt. nhardmin ) then
|
|
|
|
cw=codeword
|
|
|
|
nhardmin=nhard
|
|
|
|
i1min=i1
|
|
|
|
i2min=i2
|
|
|
|
i3min=i3
|
|
|
|
i4min=i4
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
enddo
|
2017-05-11 18:55:31 -04:00
|
|
|
! re-order the codeword to place message bits at the end
|
|
|
|
cw(indices)=cw
|
|
|
|
decoded=cw(M+1:N)
|
|
|
|
niterations=1
|
2017-05-05 22:35:38 -04:00
|
|
|
return
|
|
|
|
end subroutine osd300
|