Add hash test. Add phase0 loop. Implement hash test in msk144d.f90 test program. Have not yet tested short messages with hash test.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6890 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Steven Franke 2016-07-07 22:41:35 +00:00
parent 807d5e595b
commit b0108d59be
3 changed files with 112 additions and 92 deletions

View File

@ -214,7 +214,7 @@ subroutine detectmsk144(cbig,n,pchk_file,lines,nmessages,nutc)
if( crmax .gt. cmax ) ishort=1 if( crmax .gt. cmax ) ishort=1
! Find 6 largest peaks ! Find 6 largest peaks
do ipk=1,6 do ipk=1, 6
iloc=maxloc(abs(cc)) iloc=maxloc(abs(cc))
ic1=iloc(1) ic1=iloc(1)
iloc=maxloc(dd) iloc=maxloc(dd)
@ -246,7 +246,7 @@ subroutine detectmsk144(cbig,n,pchk_file,lines,nmessages,nutc)
if( ibb .le. 3 ) ibb=ibb-1 if( ibb .le. 3 ) ibb=ibb-1
if( ibb .gt. 3 ) ibb=ibb-7 if( ibb .gt. 3 ) ibb=ibb-7
do id=1,3 ! slicer dither. bb is very good - may be able to remove this. do id=1,1 ! slicer dither. bb is very good - may be able to remove this.
if( id .eq. 1 ) is=0 if( id .eq. 1 ) is=0
if( id .eq. 2 ) is=-1 if( id .eq. 2 ) is=-1
if( id .eq. 3 ) is=1 if( id .eq. 3 ) is=1
@ -314,80 +314,86 @@ subroutine detectmsk144(cbig,n,pchk_file,lines,nmessages,nutc)
ffin=atan2(imag(cfac),real(cfac))/(twopi*56*6*dt) ffin=atan2(imag(cfac),real(cfac))/(twopi*56*6*dt)
phase0=atan2(imag(cca+ccb),real(cca+ccb)) phase0=atan2(imag(cca+ccb),real(cca+ccb))
! Remove phase error - want constellation rotated so that sample points lie on I/Q axes do ipha=1,3
cfac=cmplx(cos(phase0),sin(phase0)) if( ipha.eq.2 ) phase0=phase0+20*pi/180.0
c=c*conjg(cfac) if( ipha.eq.3 ) phase0=phase0-20*pi/180.0
if( nmatchedfilter .eq. 0 ) then ! Remove phase error - want constellation rotated so that sample points lie on I/Q axes
cfac=cmplx(cos(phase0),sin(phase0))
c=c*conjg(cfac)
if( nmatchedfilter .eq. 0 ) then
! sample to get softsamples ! sample to get softsamples
do i=1,72 do i=1,72
softbits(2*i-1)=imag(c(1+(i-1)*12)) softbits(2*i-1)=imag(c(1+(i-1)*12))
softbits(2*i)=real(c(7+(i-1)*12)) softbits(2*i)=real(c(7+(i-1)*12))
enddo enddo
else else
! matched filter - ! matched filter -
! how much mismatch does the RX/TX/analytic filter cause?, how rig (pair) dependent is this loss? ! how much mismatch does the RX/TX/analytic filter cause?, how rig (pair) dependent is this loss?
softbits(1)=sum(imag(c(1:6))*pp(7:12))+sum(imag(c(864-5:864))*pp(1:6)) softbits(1)=sum(imag(c(1:6))*pp(7:12))+sum(imag(c(864-5:864))*pp(1:6))
softbits(2)=sum(real(c(1:12))*pp) softbits(2)=sum(real(c(1:12))*pp)
do i=2,72 do i=2,72
softbits(2*i-1)=sum(imag(c(1+(i-1)*12-6:1+(i-1)*12+5))*pp) softbits(2*i-1)=sum(imag(c(1+(i-1)*12-6:1+(i-1)*12+5))*pp)
softbits(2*i)=sum(real(c(7+(i-1)*12-6:7+(i-1)*12+5))*pp) softbits(2*i)=sum(real(c(7+(i-1)*12-6:7+(i-1)*12+5))*pp)
enddo enddo
endif endif
! sync word hard error weight is a good discriminator for ! sync word hard error weight is a good discriminator for
! frames that have reasonable probability of decoding ! frames that have reasonable probability of decoding
hardbits=0 hardbits=0
do i=1,144 do i=1,144
if( softbits(i) .ge. 0.0 ) then if( softbits(i) .ge. 0.0 ) then
hardbits(i)=1 hardbits(i)=1
endif endif
enddo enddo
nbadsync1=(8-sum( (2*hardbits(1:8)-1)*s8 ) )/2 nbadsync1=(8-sum( (2*hardbits(1:8)-1)*s8 ) )/2
nbadsync2=(8-sum( (2*hardbits(1+56:8+56)-1)*s8 ) )/2 nbadsync2=(8-sum( (2*hardbits(1+56:8+56)-1)*s8 ) )/2
nbadsync=nbadsync1+nbadsync2 nbadsync=nbadsync1+nbadsync2
if( nbadsync .gt. 4 ) cycle if( nbadsync .gt. 4 ) cycle
! normalize the softsymbols before submitting to decoder ! normalize the softsymbols before submitting to decoder
sav=sum(softbits)/144 sav=sum(softbits)/144
s2av=sum(softbits*softbits)/144 s2av=sum(softbits*softbits)/144
ssig=sqrt(s2av-sav*sav) ssig=sqrt(s2av-sav*sav)
softbits=softbits/ssig softbits=softbits/ssig
sigma=0.75 sigma=0.75
lratio(1:48)=softbits(9:9+47) lratio(1:48)=softbits(9:9+47)
lratio(49:128)=softbits(65:65+80-1) lratio(49:128)=softbits(65:65+80-1)
lratio=exp(2.0*lratio/(sigma*sigma)) lratio=exp(2.0*lratio/(sigma*sigma))
unscrambledsoftbits(1:127:2)=lratio(1:64) unscrambledsoftbits(1:127:2)=lratio(1:64)
unscrambledsoftbits(2:128:2)=lratio(65:128) unscrambledsoftbits(2:128:2)=lratio(65:128)
max_iterations=10 max_iterations=10
max_dither=1 max_dither=1
call ldpc_decode(unscrambledsoftbits, decoded, & call ldpc_decode(unscrambledsoftbits, decoded, &
max_iterations, niterations, max_dither, ndither) max_iterations, niterations, max_dither, ndither)
if( niterations .ge. 0.0 ) then if( niterations .ge. 0.0 ) then
call extractmessage144(decoded,msgreceived,nhashflag) call extractmessage144(decoded,msgreceived,nhashflag)
if( nhashflag .gt. 0 ) then ! CRCs match, so print it if( nhashflag .gt. 0 ) then ! CRCs match, so print it
ndupe=0 ndupe=0
do im=1,nmessages do im=1,nmessages
if( allmessages(im) .eq. msgreceived ) ndupe=1 if( allmessages(im) .eq. msgreceived ) ndupe=1
enddo enddo
if( ndupe .eq. 0 ) then if( ndupe .eq. 0 ) then
nmessages=nmessages+1 nmessages=nmessages+1
allmessages(nmessages)=msgreceived allmessages(nmessages)=msgreceived
write(lines(nmessages),1020) nutc,nsnr,t0,nint(fest),msgreceived write(lines(nmessages),1020) nutc,nsnr,t0,nint(fest),msgreceived
1020 format(i6.6,i4,f5.1,i5,' & ',a22) 1020 format(i6.6,i4,f5.1,i5,' & ',a22)
endif
goto 999
else
msgreceived=' '
ndither=-99 ! -99 is bad hash flag
! write(78,1001) nutc,t0,nsnr,ic,ipk,is,idf,iav,ipha,deltaf,fest,ferr,ferr2, &
! ffin,bba,bbp,nbadsync1,nbadsync2, &
! phase0,niterations,ndither,msgreceived
endif endif
goto 999
else
msgreceived=' '
ndither=-99 ! -99 is bad hash flag
! write(78,1001) nutc,t0,nsnr,ic,ipk,is,idf,iav,deltaf,fest,ferr,ferr2,ffin,bba,bbp,nbadsync1,nbadsync2, &
! phase0,niterations,ndither,msgreceived
endif endif
endif enddo ! phase dither
enddo ! frame averaging loop enddo ! frame averaging loop
enddo ! frequency dithering loop enddo ! frequency dithering loop
enddo ! sample-time dither loop enddo ! sample-time dither loop
@ -397,10 +403,11 @@ subroutine detectmsk144(cbig,n,pchk_file,lines,nmessages,nutc)
ndither=-98 ndither=-98
999 continue 999 continue
if( nmessages .ge. 1 ) then if( nmessages .ge. 1 ) then
! write(78,1001) nutc,t0,nsnr,ic,ipk,is,idf,iav,deltaf,fest,ferr,ferr2,ffin,bba,bbp,nbadsync1,nbadsync2, & ! write(78,1001) nutc,t0,nsnr,ic,ipk,is,idf,iav,ipha,deltaf,fest,ferr,ferr2, &
! phase0,niterations,ndither,msgreceived ! ffin,bba,bbp,nbadsync1,nbadsync2, &
call flush(78) ! phase0,niterations,ndither,msgreceived
!1001 format(i6.6,f8.2,i5,i5,i5,i5,i5,i5,f8.2,f8.2,f8.2,f8.2,f8.2,f10.2,f8.2,i5,i5,f8.2,i5,i5,2x,a22) ! call flush(78)
!1001 format(i6.6,f8.2,i5,i5,i5,i5,i5,i5,i5,f8.2,f8.2,f8.2,f8.2,f8.2,f10.2,f8.2,i5,i5,f8.2,i5,i5,2x,a22)
exit exit
endif endif
enddo enddo

View File

@ -99,7 +99,7 @@ subroutine detectmsk32(cbig,n,mycall,partnercall,lines,nmessages,nutc)
! Define the 32 likely messages ! Define the 32 likely messages
do irpt=0,31 do irpt=0,31
hashmsg=mycall//' '//partnercall//' '//rpt(irpt) hashmsg=trim(mycall)//' '//trim(partnercall)//' '//rpt(irpt)
call fmtmsg(hashmsg,iz) call fmtmsg(hashmsg,iz)
call hash(hashmsg,22,ihash) call hash(hashmsg,22,ihash)
ihash=iand(ihash,127) ihash=iand(ihash,127)
@ -107,7 +107,7 @@ subroutine detectmsk32(cbig,n,mycall,partnercall,lines,nmessages,nutc)
likelymessages(irpt)=ig likelymessages(irpt)=ig
! write(*,*) irpt,hashmsg,ig,ig24(ig) ! write(*,*) irpt,hashmsg,ig,ig24(ig)
enddo enddo
qsocontext=.false. qsocontext=.true.
! Fill the detmet, detferr arrays ! Fill the detmet, detferr arrays
nstepsize=48 ! 4ms steps nstepsize=48 ! 4ms steps
@ -196,6 +196,7 @@ subroutine detectmsk32(cbig,n,mycall,partnercall,lines,nmessages,nutc)
lines=char(0) lines=char(0)
imsgbest=-99 imsgbest=-99
nbadsyncbest=99
cdbest=1e32 cdbest=1e32
cdratbest=0.0 cdratbest=0.0
@ -414,36 +415,42 @@ subroutine detectmsk32(cbig,n,mycall,partnercall,lines,nmessages,nutc)
nbadsyncbest = nbadsync nbadsyncbest = nbadsync
if( ( ihammd(imsgbest)+nbadsyncbest .le. 4 ) .and. ( (cdratbest .gt. 100.0) .and. (cdbest .le. 0.05) ) ) goto 999 if( ( ihammd(imsgbest)+nbadsyncbest .le. 4 ) .and. ( (cdratbest .gt. 100.0) .and. (cdbest .le. 0.05) ) ) goto 999
endif endif
enddo ! phase loop enddo ! phase loop
enddo ! frame averaging loop enddo ! frame averaging loop
enddo ! frequency dithering loop enddo ! frequency dithering loop
enddo ! sample-time dither loop enddo ! sample-time dither loop
enddo ! peak loop - could be made more efficient by working harder to find good peaks enddo ! peak loop
msgreceived=' '
! write(78,1001) nutc,t0,nsnr,ic,ipk,is,idf,iav,deltaf,fest,ferr,ferr2,ffin,bba,bbp,nbadsync, & ! write(78,1001) nutc,t0,nsnr,ic,ipk,is,idf,iav,deltaf,fest,ferr,ferr2,ffin,bba,bbp,nbadsync, &
! phase0,msgreceived ! phase0,msgreceived
! call flush(78) ! call flush(78)
!1001 format(i6.6,f8.2,i5,i5,i5,i5,i5,i5,f8.2,f8.2,f8.2,f8.2,f8.2,f10.2,f8.2,i5,f8.2,2x,a22) !1001 format(i6.6,f8.2,i5,i5,i5,i5,i5,i5,f8.2,f8.2,f8.2,f8.2,f8.2,f10.2,f8.2,i5,f8.2,2x,a22)
enddo enddo
999 continue 999 continue
if( imsgbest .ge. 0 ) then msgreceived=' '
if( ( ihammd(imsgbest)+nbadsyncbest .le. 4 ) .and. ( (cdratbest .gt. 50.0) .and. (cdbest .le. 0.05) ) ) then if( ( ihammd(imsgbest)+nbadsyncbest .le. 4 ) .and. ( (cdratbest .gt. 50.0) .and. (cdbest .le. 0.05) ) ) then
if( qsocontext ) then if( qsocontext ) then
nrxrpt=iand(likelymessages(imsgbest),31) nrxrpt=iand(likelymessages(imsgbest),31)
nrxhash=(likelymessages(imsgbest)-nrxrpt)/32 nrxhash=(likelymessages(imsgbest)-nrxrpt)/32
imessage=likelymessages(imsgbest) imessage=likelymessages(imsgbest)
else else
nrxrpt=iand(imsgbest,31) nrxrpt=iand(imsgbest,31)
nrxhash=(imsgbest-nrxrpt)/32 nrxhash=(imsgbest-nrxrpt)/32
imessage=imsgbest imessage=imsgbest
endif endif
nmessages=1
write(msgreceived,'(a1,i3,a1,1x,a4)') "<",nrxhash,">",rpt(nrxrpt)
write(lines(nmessages),1020) nutc,nsnr,t0,nint(fest),msgreceived
1020 format(i6.6,i4,f5.1,i5,' & ',a22)
! write(*,1022) nutc,ipbest,times(ipbest),snrs(ipbest),fest,nrxrpt,nrxhash, & ! See if this message has a hash that is expected for a message sent to mycall by partnercall
hashmsg=trim(mycall)//' '//trim(partnercall)//' '//rpt(nrxrpt)
call fmtmsg(hashmsg,iz)
call hash(hashmsg,22,ihash)
ihash=iand(ihash,127)
if( nrxhash .eq. ihash ) then
nmessages=1
write(msgreceived,'(a1,a,1x,a,a1,1x,a4)') "<",trim(mycall),trim(partnercall),">",rpt(nrxrpt)
write(lines(nmessages),1020) nutc,nsnr,t0,nint(fest),msgreceived
1020 format(i6.6,i4,f5.1,i5,' & ',a22)
! write(*,1022) nutc,ipbest,times(ipbest),snrs(ipbest),fest,nrxrpt,nrxhash, &
! rpt(nrxrpt),imessage,ig24(imessage),ihammd(imsgbest), & ! rpt(nrxrpt),imessage,ig24(imessage),ihammd(imsgbest), &
! cdbest,cdratbest,nbadsyncbest,ipkbest,idbest,idfbest,iavbest,iphabest ! cdbest,cdratbest,nbadsyncbest,ipkbest,idbest,idfbest,iavbest,iphabest
endif endif

View File

@ -14,14 +14,16 @@ program msk144d
type(wav_header) :: wav type(wav_header) :: wav
integer*2 id2(30*12000) integer*2 id2(30*12000)
character*500 infile character*500 infile
character*12 mycall,hiscall
character(len=500) optarg character(len=500) optarg
type (option) :: long_options(2) = [ & type (option) :: long_options(3) = [ &
option ('help',.false.,'h','Display this help message',''), & option ('help',.false.,'h','Display this help message',''), &
option ('ntrials',.true.,'n','number of trials, default TRIALS=10000','TRIALS') & option ('mycall',.true.,'c','mycall',''), &
option ('hiscall',.true.,'x','hiscall','') &
] ]
do do
call getopt('hn:',long_options,c,optarg,narglen,nstat,noffset,nremain,.true.) call getopt('c:hx:',long_options,c,optarg,narglen,nstat,noffset,nremain,.true.)
if( nstat .ne. 0 ) then if( nstat .ne. 0 ) then
exit exit
end if end if
@ -30,6 +32,10 @@ program msk144d
display_help = .true. display_help = .true.
case ('n') case ('n')
read (optarg(:narglen), *) ntrials read (optarg(:narglen), *) ntrials
case ('c')
read (optarg(:narglen), *) mycall
case ('x')
read (optarg(:narglen), *) hiscall
end select end select
end do end do
@ -65,7 +71,7 @@ program msk144d
read(unit=wav%lun) id2(1:npts) read(unit=wav%lun) id2(1:npts)
close(unit=wav%lun) close(unit=wav%lun)
call timer('read ',1) call timer('read ',1)
call msk144_decode(id2,npts,nutc,1,pchk_file,line) call msk144_decode(id2,npts,nutc,1,pchk_file,mycall,hiscall,line)
enddo enddo
call timer('msk144 ',1) call timer('msk144 ',1)