mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-26 14:18:38 -05:00
Add code needed to unpack decoded message.
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6645 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
e68674214c
commit
45ba25f6ed
@ -7,8 +7,8 @@ use, intrinsic :: iso_c_binding
|
|||||||
use hashing
|
use hashing
|
||||||
use packjt
|
use packjt
|
||||||
|
|
||||||
character*22 msg,msgsent
|
character*22 msg,msgsent,msgreceived
|
||||||
integer*4 i4Msg6BitWords(12)
|
integer*4 i4Msg6BitWords(12),i4Dec6BitWords(12)
|
||||||
integer*1, target:: i1Msg8BitBytes(10) ! 72 bit msg + 8 bit hash
|
integer*1, target:: i1Msg8BitBytes(10) ! 72 bit msg + 8 bit hash
|
||||||
integer*1, target:: i1Dec8BitBytes(10) ! 72 bit msg + 8 bit hash
|
integer*1, target:: i1Dec8BitBytes(10) ! 72 bit msg + 8 bit hash
|
||||||
integer*1 i1hashdec
|
integer*1 i1hashdec
|
||||||
@ -22,8 +22,8 @@ equivalence (ihash,i1hash)
|
|||||||
|
|
||||||
nargs=iargc()
|
nargs=iargc()
|
||||||
if(nargs.ne.7) then
|
if(nargs.ne.7) then
|
||||||
print*,'Usage: ldpcsim pchk/gen file prefix N K niter ndither #trials s '
|
print*,'Usage: ldpcsim <pchk file prefix > N K niter ndither #trials s '
|
||||||
print*,'eg: ldpcsim "128-80-peg-reg3" 128 80 10 1 1000 0.75'
|
print*,'eg: ldpcsim "/pathto/128-80-peg-reg3" 128 80 10 1 1000 0.75'
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
call getarg(1,prefix)
|
call getarg(1,prefix)
|
||||||
@ -43,7 +43,7 @@ read(arg,*) s
|
|||||||
pchk_file=trim(prefix)//".pchk"
|
pchk_file=trim(prefix)//".pchk"
|
||||||
gen_file=trim(prefix)//".gen"
|
gen_file=trim(prefix)//".gen"
|
||||||
|
|
||||||
!rate=real(K)/real(N)
|
! rate=real(K)/real(N)
|
||||||
! don't count hash bits as data bits
|
! don't count hash bits as data bits
|
||||||
rate=72.0/real(N)
|
rate=72.0/real(N)
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ allocate ( codeword(N), decoded(K), message(K) )
|
|||||||
allocate ( lratio(N), rxdata(N) )
|
allocate ( lratio(N), rxdata(N) )
|
||||||
call init_ldpc(trim(pchk_file)//char(0),trim(gen_file)//char(0))
|
call init_ldpc(trim(pchk_file)//char(0),trim(gen_file)//char(0))
|
||||||
|
|
||||||
msg="K1JT K9AN EN50"
|
msg="123"
|
||||||
call fmtmsg(msg,iz)
|
call fmtmsg(msg,iz)
|
||||||
call packmsg(msg,i4Msg6BitWords,itype)
|
call packmsg(msg,i4Msg6BitWords,itype)
|
||||||
call unpackmsg(i4Msg6BitWords,msgsent)
|
call unpackmsg(i4Msg6BitWords,msgsent)
|
||||||
@ -104,19 +104,19 @@ do idb = 0, 11
|
|||||||
|
|
||||||
do itrial=1, ntrials
|
do itrial=1, ntrials
|
||||||
|
|
||||||
! create a realization of a noisy received word
|
! Create a realization of a noisy received word
|
||||||
do i=1,N
|
do i=1,N
|
||||||
rxdata(i) = 2.0*(codeword(i)-0.5) + sigma*gran()
|
rxdata(i) = 2.0*(codeword(i)-0.5) + sigma*gran()
|
||||||
enddo
|
enddo
|
||||||
|
|
||||||
! correct signal normalization is important for this decoder.
|
! Correct signal normalization is important for this decoder.
|
||||||
rxav=sum(rxdata)/N
|
rxav=sum(rxdata)/N
|
||||||
rx2av=sum(rxdata*rxdata)/N
|
rx2av=sum(rxdata*rxdata)/N
|
||||||
rxsig=sqrt(rx2av-rxav*rxav)
|
rxsig=sqrt(rx2av-rxav*rxav)
|
||||||
rxdata=rxdata/rxsig
|
rxdata=rxdata/rxsig
|
||||||
|
|
||||||
! To match the metric to the channel, s should be set to the noise standard deviation.
|
! To match the metric to the channel, s should be set to the noise standard deviation.
|
||||||
! For now we just set s to the value that optimizes decode probability near threshold.
|
! 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
|
! The s parameter can be tuned to trade a few tenth's dB of threshold for an order of
|
||||||
! magnitude in UER
|
! magnitude in UER
|
||||||
do i=1,N
|
do i=1,N
|
||||||
@ -128,18 +128,16 @@ do idb = 0, 11
|
|||||||
lratio(i)=exp(2.0*rxdata(i)/(ss*ss))
|
lratio(i)=exp(2.0*rxdata(i)/(ss*ss))
|
||||||
enddo
|
enddo
|
||||||
|
|
||||||
! call interface to Radford Neal implementation of binary belief propagation.
|
|
||||||
! max_iterations is max number of belief propagation iterations
|
! max_iterations is max number of belief propagation iterations
|
||||||
! max_dither is the number of tries - try number 2 and beyond start with dithered likelihood ratios.
|
|
||||||
call ldpc_decode(lratio, decoded, max_iterations, niterations, max_dither, ndither)
|
call ldpc_decode(lratio, decoded, max_iterations, niterations, max_dither, ndither)
|
||||||
|
|
||||||
! if the decoder finds a valid codeword, niterations will be .ge. 0
|
! If the decoder finds a valid codeword, niterations will be .ge. 0.
|
||||||
if( niterations .ge. 0 ) then
|
if( niterations .ge. 0 ) then
|
||||||
nueflag=0
|
nueflag=0
|
||||||
nhashflag=0
|
nhashflag=0
|
||||||
! the decoder produced a codeword --- compare hash part of message (byte 10) with computed hash
|
|
||||||
! first collapse 80 decoded bits to 10 bytes
|
! The decoder found a codeword. Compare received hash (byte 10) with computed hash.
|
||||||
! the first 9 bytes are the message, 10'th byte is the hash.
|
! Collapse 80 decoded bits to 10 bytes. Bytes 1-9 are the message, byte 10 is the hash.
|
||||||
do ibyte=1,10
|
do ibyte=1,10
|
||||||
itmp=0
|
itmp=0
|
||||||
do ibit=1,8
|
do ibit=1,8
|
||||||
@ -147,17 +145,19 @@ do idb = 0, 11
|
|||||||
enddo
|
enddo
|
||||||
i1Dec8BitBytes(ibyte)=itmp
|
i1Dec8BitBytes(ibyte)=itmp
|
||||||
enddo
|
enddo
|
||||||
! calculate the hash using the first 9 bytes
|
|
||||||
|
! Calculate the hash using the first 9 bytes.
|
||||||
ihashdec=nhash(c_loc(i1Dec8BitBytes),int(9,c_size_t),146)
|
ihashdec=nhash(c_loc(i1Dec8BitBytes),int(9,c_size_t),146)
|
||||||
ihashdec=2*iand(ihashdec,255)
|
ihashdec=2*iand(ihashdec,255)
|
||||||
! compare calculated hash with received byte 10 - if they agree, keep the message
|
|
||||||
|
! Compare calculated hash with received byte 10 - if they agree, keep the message.
|
||||||
i1hashdec=ihashdec
|
i1hashdec=ihashdec
|
||||||
if( i1hashdec .ne. i1Dec8BitBytes(10) ) then
|
if( i1hashdec .ne. i1Dec8BitBytes(10) ) then
|
||||||
nbadhash=nbadhash+1
|
nbadhash=nbadhash+1
|
||||||
nhashflag=1
|
nhashflag=1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
! check the message plus hash against what was sent
|
! Check the message plus hash against what was sent.
|
||||||
do i=1,K
|
do i=1,K
|
||||||
if( message(i) .ne. decoded(i) ) then
|
if( message(i) .ne. decoded(i) ) then
|
||||||
nueflag=1
|
nueflag=1
|
||||||
@ -166,11 +166,25 @@ do idb = 0, 11
|
|||||||
|
|
||||||
if( nhashflag .eq. 0 .and. nueflag .eq. 0 ) then
|
if( nhashflag .eq. 0 .and. nueflag .eq. 0 ) then
|
||||||
ngood=ngood+1
|
ngood=ngood+1
|
||||||
|
|
||||||
|
! don't bother to unpack while testing
|
||||||
|
if( .false. ) then
|
||||||
|
! 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 unpackmsg(i4Dec6BitWords,msgreceived)
|
||||||
|
print*,"Received ",msgreceived
|
||||||
|
endif
|
||||||
|
|
||||||
else if( nhashflag .eq. 0 .and. nueflag .eq. 1 ) then
|
else if( nhashflag .eq. 0 .and. nueflag .eq. 1 ) then
|
||||||
nue=nue+1;
|
nue=nue+1;
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
enddo
|
enddo
|
||||||
|
|
||||||
write(*,"(f4.1,1x,i8,1x,i8,1x,i8)") db,ngood,nue,nbadhash
|
write(*,"(f4.1,1x,i8,1x,i8,1x,i8)") db,ngood,nue,nbadhash
|
||||||
|
Loading…
Reference in New Issue
Block a user