diff options
| author | Christoph Berg <myon@debian.org> | 2020-05-11 22:17:58 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2020-05-11 22:17:58 +0200 |
| commit | 32a41b1abe1a4aab0892c9c2051be6ba5b379f1e (patch) | |
| tree | c6e107c1ee4d70610e43a7912e57c720334a08c7 /lib/ft8 | |
| parent | 08299e8b2bf50ba90daf570f57def529dd29d6e7 (diff) | |
New upstream version 2.2.0~rc1+repackupstream/2.2.0_rc1+repack
Diffstat (limited to 'lib/ft8')
| -rw-r--r-- | lib/ft8/baseline.f90 | 1 | ||||
| -rw-r--r-- | lib/ft8/bpdecode174_91.f90 | 6 | ||||
| -rw-r--r-- | lib/ft8/decode174_91.f90 | 155 | ||||
| -rw-r--r-- | lib/ft8/encode174_91.f90 | 92 | ||||
| -rw-r--r-- | lib/ft8/encode174_91_nocrc.f90 | 49 | ||||
| -rw-r--r-- | lib/ft8/extractmessage174.f90 | 40 | ||||
| -rw-r--r-- | lib/ft8/extractmessage174_91.f90 | 40 | ||||
| -rw-r--r-- | lib/ft8/filt8.f90 | 4 | ||||
| -rw-r--r-- | lib/ft8/foxfilt.f90 | 2 | ||||
| -rw-r--r-- | lib/ft8/ft8_testmsg.f90 | 96 | ||||
| -rw-r--r-- | lib/ft8/ft8apset.f90 | 36 | ||||
| -rw-r--r-- | lib/ft8/ft8b.f90 | 261 | ||||
| -rw-r--r-- | lib/ft8/ft8code.f90 | 47 | ||||
| -rw-r--r-- | lib/ft8/ft8sim.f90 | 45 | ||||
| -rw-r--r-- | lib/ft8/ft8sim_gfsk.f90 | 131 | ||||
| -rw-r--r-- | lib/ft8/gen_ft8wave.f90 | 24 | ||||
| -rw-r--r-- | lib/ft8/get_crc14.f90 | 25 | ||||
| -rw-r--r-- | lib/ft8/get_spectrum_baseline.f90 | 43 | ||||
| -rw-r--r-- | lib/ft8/ldpc_174_91_c_parity.f90 | 351 | ||||
| -rw-r--r-- | lib/ft8/ldpc_174_91_c_reordered_parity.f90 | 270 | ||||
| -rw-r--r-- | lib/ft8/ldpcsim174_91.f90 | 134 | ||||
| -rw-r--r-- | lib/ft8/osd174_91.f90 | 627 | ||||
| -rw-r--r-- | lib/ft8/subtractft8.f90 | 116 | ||||
| -rw-r--r-- | lib/ft8/sync8.f90 | 32 | ||||
| -rw-r--r-- | lib/ft8/sync8d.f90 | 8 |
25 files changed, 1362 insertions, 1273 deletions
diff --git a/lib/ft8/baseline.f90 b/lib/ft8/baseline.f90 index 035f9ab4..49679510 100644 --- a/lib/ft8/baseline.f90 +++ b/lib/ft8/baseline.f90 @@ -37,6 +37,7 @@ subroutine baseline(s,nfa,nfb,sbase) kz=k
a=0.
call polyfit(x,y,y,kz,nterms,0,a,chisqr) !Fit a low-order polynomial
+ sbase=0.0
do i=ia,ib
t=i-i0
sbase(i)=a(1)+t*(a(2)+t*(a(3)+t*(a(4)+t*(a(5))))) + 0.65
diff --git a/lib/ft8/bpdecode174_91.f90 b/lib/ft8/bpdecode174_91.f90 index 78809f19..a7c6f95b 100644 --- a/lib/ft8/bpdecode174_91.f90 +++ b/lib/ft8/bpdecode174_91.f90 @@ -1,4 +1,4 @@ -subroutine bpdecode174_91(llr,apmask,maxiterations,message77,cw,nharderror,iter) +subroutine bpdecode174_91(llr,apmask,maxiterations,message77,cw,nharderror,iter,ncheck) ! ! A log-domain belief propagation decoder for the (174,91) code. ! @@ -19,7 +19,7 @@ real zn(N) real llr(N) real Tmn -include "ldpc_174_91_c_reordered_parity.f90" +include "ldpc_174_91_c_parity.f90" decoded=0 toc=0 @@ -33,6 +33,7 @@ do j=1,M enddo ncnt=0 +nclast=0 do iter=0,maxiterations @@ -76,6 +77,7 @@ do iter=0,maxiterations ! write(*,*) iter,ncheck,nd,ncnt if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then nharderror=-1 + return endif endif diff --git a/lib/ft8/decode174_91.f90 b/lib/ft8/decode174_91.f90 new file mode 100644 index 00000000..134864d9 --- /dev/null +++ b/lib/ft8/decode174_91.f90 @@ -0,0 +1,155 @@ +subroutine decode174_91(llr,Keff,maxosd,norder,apmask,message91,cw,ntype,nharderror,dmin) +! +! A hybrid bp/osd decoder for the (174,91) code. +! +! maxosd<0: do bp only +! maxosd=0: do bp and then call osd once with channel llrs +! maxosd>1: do bp and then call osd maxosd times with saved bp outputs +! norder : osd decoding depth +! + integer, parameter:: N=174, K=91, M=N-K + integer*1 cw(N),apmask(N) + integer*1 nxor(N),hdec(N) + integer*1 message91(91),m96(96) + integer nrw(M),ncw + integer Nm(7,M) + integer Mn(3,N) ! 3 checks per bit + integer synd(M) + real tov(3,N) + real toc(7,M) + real tanhtoc(7,M) + real zn(N),zsum(N),zsave(N,3) + real llr(N) + real Tmn + + include "ldpc_174_91_c_parity.f90" + + maxiterations=30 + nosd=0 + if(maxosd.gt.3) maxosd=3 + if(maxosd.eq.0) then ! osd with channel llrs + nosd=1 + zsave(:,1)=llr + elseif(maxosd.gt.0) then ! + nosd=maxosd + elseif(maxosd.lt.0) then ! just bp + nosd=0 + endif + + toc=0 + tov=0 + tanhtoc=0 +! initialize messages to checks + do j=1,M + do i=1,nrw(j) + toc(i,j)=llr((Nm(i,j))) + enddo + enddo + + ncnt=0 + nclast=0 + zsum=0.0 + do iter=0,maxiterations +! Update bit log likelihood ratios (tov=0 in iteration 0). + do i=1,N + if( apmask(i) .ne. 1 ) then + zn(i)=llr(i)+sum(tov(1:ncw,i)) + else + zn(i)=llr(i) + endif + enddo + zsum=zsum+zn + if(iter.gt.0 .and. iter.le.maxosd) then + zsave(:,iter)=zsum + endif + +! Check to see if we have a codeword (check before we do any iteration). + cw=0 + where( zn .gt. 0. ) cw=1 + ncheck=0 + do i=1,M + synd(i)=sum(cw(Nm(1:nrw(i),i))) + if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1 + enddo + if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it + m96=0 + m96(1:77)=cw(1:77) + m96(83:96)=cw(78:91) + call get_crc14(m96,96,nbadcrc) + nharderror=count( (2*cw-1)*llr .lt. 0.0 ) + if(nbadcrc.eq.0) then + message91=cw(1:91) + hdec=0 + where(llr .ge. 0) hdec=1 + nxor=ieor(hdec,cw) + dmin=sum(nxor*abs(llr)) + ntype=1 + return + endif + endif + + if( iter.gt.0 ) then ! this code block implements an early stopping criterion +! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion + nd=ncheck-nclast + if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased + ncnt=0 ! reset counter + else + ncnt=ncnt+1 + endif +! write(*,*) iter,ncheck,nd,ncnt + if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then + nharderror=-1 + exit + endif + endif + nclast=ncheck + +! Send messages from bits to check nodes + do j=1,M + do i=1,nrw(j) + ibj=Nm(i,j) + toc(i,j)=zn(ibj) + do kk=1,ncw ! subtract off what the bit had received from the check + if( Mn(kk,ibj) .eq. j ) then + toc(i,j)=toc(i,j)-tov(kk,ibj) + endif + enddo + enddo + enddo + +! send messages from check nodes to variable nodes + do i=1,M + tanhtoc(1:7,i)=tanh(-toc(1:7,i)/2) + enddo + + do j=1,N + do i=1,ncw + ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j + Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j) + call platanh(-Tmn,y) +! y=atanh(-Tmn) + tov(i,j)=2*y + enddo + enddo + + enddo ! bp iterations + + do i=1,nosd + zn=zsave(:,i) + call osd174_91(zn,Keff,apmask,norder,message91,cw,nharderror,dminosd) + if(nharderror.gt.0) then + hdec=0 + where(llr .ge. 0) hdec=1 + nxor=ieor(hdec,cw) + dmin=sum(nxor*abs(llr)) + ntype=2 + return + endif + enddo + + ntype=0 + nharderror=-1 + dminosd=0.0 + + return +end subroutine decode174_91 diff --git a/lib/ft8/encode174_91.f90 b/lib/ft8/encode174_91.f90 index 0ffa4841..5bae7d56 100644 --- a/lib/ft8/encode174_91.f90 +++ b/lib/ft8/encode174_91.f90 @@ -2,57 +2,57 @@ subroutine encode174_91(message77,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 + 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 message77(77),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 + integer, parameter:: N=174, K=91, M=N-K + character*91 tmpchar + integer*1 codeword(N) + integer*1 gen(M,K) + integer*1 message77(77),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 + 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 ! Add 14-bit CRC to form 91-bit message+CRC14 -write(tmpchar,'(77i1)') message77 -tmpchar(78:80)='000' -i1MsgBytes=0 -read(tmpchar,'(10b8)') i1MsgBytes(1:10) -ncrc14 = crc14 (c_loc (i1MsgBytes), 12) -write(tmpchar(78:91),'(b14)') ncrc14 -read(tmpchar,'(91i1)') message + write(tmpchar,'(77i1)') message77 + tmpchar(78:80)='000' + i1MsgBytes=0 + read(tmpchar,'(10b8)') i1MsgBytes(1:10) + ncrc14 = crc14 (c_loc (i1MsgBytes), 12) + write(tmpchar(78:91),'(b14)') ncrc14 + read(tmpchar,'(91i1)') message -do i=1,M - nsum=0 - do j=1,K - nsum=nsum+message(j)*gen(i,j) - enddo - pchecks(i)=mod(nsum,2) -enddo + 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 + codeword(1:K)=message + codeword(K+1:N)=pchecks -return + return end subroutine encode174_91 diff --git a/lib/ft8/encode174_91_nocrc.f90 b/lib/ft8/encode174_91_nocrc.f90 new file mode 100644 index 00000000..371e8317 --- /dev/null +++ b/lib/ft8/encode174_91_nocrc.f90 @@ -0,0 +1,49 @@ +subroutine encode174_91_nocrc(message,codeword) +! +! Encode a 91-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 diff --git a/lib/ft8/extractmessage174.f90 b/lib/ft8/extractmessage174.f90 deleted file mode 100644 index 252547c4..00000000 --- a/lib/ft8/extractmessage174.f90 +++ /dev/null @@ -1,40 +0,0 @@ -subroutine extractmessage174(decoded,msgreceived,ncrcflag) - use iso_c_binding, only: c_loc,c_size_t - use crc - use packjt - - character*22 msgreceived - character*87 cbits - integer*1 decoded(87) - integer*1, target:: i1Dec8BitBytes(11) - integer*4 i4Dec6BitWords(12) - -! Write decoded bits into cbits: 75-bit message plus 12-bit CRC - write(cbits,1000) decoded -1000 format(87i1) - read(cbits,1001) i1Dec8BitBytes -1001 format(11b8) - read(cbits,1002) ncrc12 !Received CRC12 -1002 format(75x,b12) - - i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),transfer(128+64+32,0_1)) - i1Dec8BitBytes(11)=0 - icrc12=crc12(c_loc(i1Dec8BitBytes),11) !CRC12 computed from 75 msg bits - - if(ncrc12.eq.icrc12 .or. sum(decoded(57:87)).eq.0) then !### Kludge ### -! CRC12 checks out --- unpack 72-bit message - do ibyte=1,12 - itmp=0 - do ibit=1,6 - itmp=ishft(itmp,1)+iand(1_1,decoded((ibyte-1)*6+ibit)) - enddo - i4Dec6BitWords(ibyte)=itmp - enddo - call unpackmsg(i4Dec6BitWords,msgreceived) - ncrcflag=1 - else - msgreceived=' ' - ncrcflag=-1 - endif - return - end subroutine extractmessage174 diff --git a/lib/ft8/extractmessage174_91.f90 b/lib/ft8/extractmessage174_91.f90 deleted file mode 100644 index ecc14246..00000000 --- a/lib/ft8/extractmessage174_91.f90 +++ /dev/null @@ -1,40 +0,0 @@ -subroutine extractmessage174_91(decoded,msgreceived,ncrcflag) - use iso_c_binding, only: c_loc,c_size_t - use crc - use packjt - - character*22 msgreceived - character*91 cbits - integer*1 decoded(91) - integer*1, target:: i1Dec8BitBytes(12) - integer*4 i4Dec6BitWords(12) - -! Write decoded bits into cbits: 77-bit message plus 14-bit CRC - write(cbits,1000) decoded -1000 format(91i1) - read(cbits,1001) i1Dec8BitBytes -1001 format(12b8) - read(cbits,1002) ncrc14 !Received CRC12 -1002 format(77x,b14) - - i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),transfer(128+64+32+16+8,0_1)) - i1Dec8BitBytes(11:12)=0 - icrc14=crc14(c_loc(i1Dec8BitBytes),12) !CRC12 computed from 75 msg bits - - if(ncrc14.eq.icrc14 .or. sum(decoded(57:87)).eq.0) then !### Kludge ### -! CRC14 checks out --- unpack 72-bit message - do ibyte=1,12 - itmp=0 - do ibit=1,6 - itmp=ishft(itmp,1)+iand(1_1,decoded((ibyte-1)*6+ibit)) - enddo - i4Dec6BitWords(ibyte)=itmp - enddo - call unpackmsg(i4Dec6BitWords,msgreceived) - ncrcflag=1 - else - msgreceived=' ' - ncrcflag=-1 - endif - return - end subroutine extractmessage174_91 diff --git a/lib/ft8/filt8.f90 b/lib/ft8/filt8.f90 index aeacf2a7..6b39c043 100644 --- a/lib/ft8/filt8.f90 +++ b/lib/ft8/filt8.f90 @@ -9,7 +9,7 @@ subroutine filt8(f0,nslots,width,wave) equivalence (x,cx)
x=wave
- call four2a(x,NFFT,1,-1,0) !r2c
+ call four2a(cx,NFFT,1,-1,0) !r2c
df=12000.0/NFFT
fa=f0 - 0.5*6.25
fb=f0 + 7.5*6.25 + (nslots-1)*60.0
@@ -35,7 +35,7 @@ subroutine filt8(f0,nslots,width,wave) !###
if(nslots.ne.99) return
x=wave
- call four2a(x,NFFT,1,-1,0) !r2c
+ call four2a(cx,NFFT,1,-1,0) !r2c
do i=0,NH
s1(i)=real(cx(i))**2 + aimag(cx(i))**2
enddo
diff --git a/lib/ft8/foxfilt.f90 b/lib/ft8/foxfilt.f90 index d97923a8..6ad46a47 100644 --- a/lib/ft8/foxfilt.f90 +++ b/lib/ft8/foxfilt.f90 @@ -9,7 +9,7 @@ subroutine foxfilt(nslots,nfreq,width,wave) x(1:NWAVE)=wave
x(NWAVE+1:)=0.
- call four2a(x,NFFT,1,-1,0) !r2c
+ call four2a(cx,NFFT,1,-1,0) !r2c
df=48000.0/NFFT
fa=nfreq - 0.5*6.25
fb=nfreq + 7.5*6.25 + (nslots-1)*60.0
diff --git a/lib/ft8/ft8_testmsg.f90 b/lib/ft8/ft8_testmsg.f90 index 2a1bf8f9..253641d2 100644 --- a/lib/ft8/ft8_testmsg.f90 +++ b/lib/ft8/ft8_testmsg.f90 @@ -1,51 +1,51 @@ parameter (MAXTEST=75,NTEST=48) character*37 testmsg(MAXTEST) data testmsg(1:NTEST)/ & - "CQ K1ABC FN42", & - "K1ABC W9XYZ EN37", & - "W9XYZ K1ABC -11", & - "K1ABC W9XYZ R-09", & - "W9XYZ K1ABC RRR", & - "K1ABC W9XYZ 73", & - "K1ABC W9XYZ RR73", & - "CQ KH1/KH7Z", & - "K1ABC RR73; W9XYZ <KH1/KH7Z> -08", & - "CQ FD K1ABC FN42", & - "K1ABC W9XYZ 6A WI", & - "W9XYZ K1ABC R 2B EMA", & - "CQ TEST K1ABC/R FN42", & - "K1ABC/R W9XYZ EN37", & - "W9XYZ K1ABC/R R FN42", & - "K1ABC/R W9XYZ RR73", & - "CQ TEST K1ABC FN42", & - "K1ABC W9XYZ 579 WI", & - "W9XYZ K1ABC R 589 MA", & - "K1ABC KA0DEF 559 MO", & - "TU; KA0DEF K1ABC R 569 MA", & - "KA1ABC G3AAA 529 0013", & - "TU; G3AAA K1ABC R 559 MA", & - "CQ G4ABC/P IO91", & - "G4ABC/P PA9XYZ JO22", & - "PA9XYZ 590003 IO91NP", & - "G4ABC/P R 570007 JO22DB", & - "PA9XYZ G4ABC/P RR73", & - "CQ PJ4/K1ABC", & - "PJ4/K1ABC <W9XYZ>", & - "W9XYZ <PJ4/K1ABC> -11", & - "<PJ4/K1ABC> W9XYZ R-09", & - "<W9XYZ> PJ4/K1ABC RRR", & - "PJ4/K1ABC <W9XYZ> 73", & - "CQ W9XYZ EN37", & - "<W9XYZ> YW18FIFA", & - "<YW18FIFA> W9XYZ -11", & - "W9XYZ <YW18FIFA> R-09", & - "YW18FIFA <W9XYZ> RRR", & - "<W9XYZ> YW18FIFA 73", & - "TNX BOB 73 GL", & - "CQ YW18FIFA", & - "<YW18FIFA> KA1ABC", & - "KA1ABC <YW18FIFA> -11", & - "<YW18FIFA> KA1ABC R-17", & - "<KA1ABC> YW18FIFA RR73", & - "<YW18FIFA> KA1ABC 73", & - "123456789ABCDEF012"/ + "TNX BOB 73 GL", & ! 0.0 + "K1ABC RR73; W9XYZ <KH1/KH7Z> -08", & ! 0.1 + "PA9XYZ 590003 IO91NP", & ! 0.2 + "G4ABC/P R 570007 JO22DB", & ! 0.2 + "K1ABC W9XYZ 6A WI", & ! 0.3 + "W9XYZ K1ABC R 17B EMA", & ! 0.3 + "123456789ABCDEF012", & ! 0.5 + "CQ K1ABC FN42", & ! 1. + "K1ABC W9XYZ EN37", & ! 1. + "W9XYZ K1ABC -11", & ! 1. + "K1ABC W9XYZ R-09", & ! 1. + "W9XYZ K1ABC RRR", & ! 1. + "K1ABC W9XYZ 73", & ! 1. + "K1ABC W9XYZ RR73", & ! 1. + "CQ FD K1ABC FN42", & ! 1. + "CQ TEST K1ABC/R FN42", & ! 1. + "K1ABC/R W9XYZ EN37", & ! 1. + "W9XYZ K1ABC/R R FN42", & ! 1. + "K1ABC/R W9XYZ RR73", & ! 1. + "CQ TEST K1ABC FN42", & ! 1. + "W9XYZ <PJ4/K1ABC> -11", & ! 1. + "<PJ4/K1ABC> W9XYZ R-09", & ! 1. + "CQ W9XYZ EN37", & ! 1. + "<YW18FIFA> W9XYZ -11", & ! 1. + "W9XYZ <YW18FIFA> R-09", & ! 1. + "<YW18FIFA> KA1ABC", & ! 1. + "KA1ABC <YW18FIFA> -11", & ! 1. + "<YW18FIFA> KA1ABC R-17", & ! 1. + "<YW18FIFA> KA1ABC 73", & ! 1. + "CQ G4ABC/P IO91", & ! 2. + "G4ABC/P PA9XYZ JO22", & ! 2. + "PA9XYZ G4ABC/P RR73", & ! 2. + "K1ABC W9XYZ 579 WI", & ! 3. + "W9XYZ K1ABC R 589 MA", & ! 3. + "K1ABC KA0DEF 559 MO", & ! 3. + "TU; KA0DEF K1ABC R 569 MA", & ! 3. + "KA1ABC G3AAA 529 0013", & ! 3. + "TU; G3AAA K1ABC R 559 MA", & ! 3. + "CQ KH1/KH7Z", & ! 4. + "CQ PJ4/K1ABC", & ! 4. + "PJ4/K1ABC <W9XYZ>", & ! 4. + "<W9XYZ> PJ4/K1ABC RRR", & ! 4. + "PJ4/K1ABC <W9XYZ> 73", & ! 4. + "<W9XYZ> YW18FIFA", & ! 4. + "YW18FIFA <W9XYZ> RRR", & ! 4. + "<W9XYZ> YW18FIFA 73", & ! 4. + "CQ YW18FIFA", & ! 4. + "<KA1ABC> YW18FIFA RR73"/ diff --git a/lib/ft8/ft8apset.f90 b/lib/ft8/ft8apset.f90 index 56a18c4f..90f05b70 100644 --- a/lib/ft8/ft8apset.f90 +++ b/lib/ft8/ft8apset.f90 @@ -1,14 +1,18 @@ -subroutine ft8apset(mycall12,hiscall12,apsym) +subroutine ft8apset(mycall12,hiscall12,ncontest,apsym,aph10) use packjt77 character*77 c77 character*37 msg,msgchk character*12 mycall12,hiscall12,hiscall - integer apsym(58) + character*13 hc13 + character*10 c10 + integer apsym(58),aph10(10) logical nohiscall,unpk77_success apsym=0 apsym(1)=99 apsym(30)=99 + aph10=0 + aph10(1)=99 if(len(trim(mycall12)).lt.3) return @@ -17,23 +21,41 @@ subroutine ft8apset(mycall12,hiscall12,apsym) if(len(trim(hiscall)).lt.3) then hiscall=mycall12 ! use mycall for dummy hiscall - mycall won't be hashed. nohiscall=.true. + else + hc13=hiscall + n10=0 + n12=0 + n22=0 + call save_hash_call(hc13,n10,n12,n22) + write(c10,'(b10.10)') iand(n10,Z'3FF') + read(c10,'(10i1.1)',err=1) aph10 + aph10=2*aph10-1 endif ! Encode a dummy standard message: i3=1, 28 1 28 1 1 15 ! msg=trim(mycall12)//' '//trim(hiscall)//' RRR' + i3=0 + n3=0 call pack77(msg,i3,n3,c77) call unpack77(c77,1,msgchk,unpk77_success) + if(ncontest.eq.7.and. (i3.ne.1 .or. .not.unpk77_success)) return + if(ncontest.le.5.and. (i3.ne.1 .or. msg.ne.msgchk .or. .not.unpk77_success)) return - if(i3.ne.1 .or. (msg.ne.msgchk) .or. .not.unpk77_success) return - - read(c77,'(58i1)',err=1) apsym(1:58) + read(c77,'(58i1)',err=2) apsym(1:58) apsym=2*apsym-1 - if(nohiscall) apsym(30)=99 + if(nohiscall) then + apsym(30)=99 + aph10(1)=99 + endif return -1 apsym=0 +1 aph10=0 + aph10(1)=99 + return +2 apsym=0 apsym(1)=99 apsym(30)=99 return + end subroutine ft8apset diff --git a/lib/ft8/ft8b.f90 b/lib/ft8/ft8b.f90 index 0376311f..b92bde34 100644 --- a/lib/ft8/ft8b.f90 +++ b/lib/ft8/ft8b.f90 @@ -1,6 +1,7 @@ -subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & - napwid,lsubtract,nagain,ncontest,iaptype,mycall12,hiscall12, & - sync0,f1,xdt,xbase,apsym,nharderrors,dmin,nbadcrc,ipass,iera,msg37,xsnr) +subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,nzhsym,lapon, & + lapcqonly,napwid,lsubtract,nagain,ncontest,iaptype,mycall12,hiscall12, & + f1,xdt,xbase,apsym,aph10,nharderrors,dmin,nbadcrc,ipass, & + msg37,xsnr,itone) use crc use timer_module, only: timer @@ -13,12 +14,13 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & real a(5) real s8(0:7,NN) real s2(0:511) - real bmeta(174),bmetb(174),bmetc(174) - real llra(174),llrb(174),llrc(174),llrd(174) !Soft symbols + real bmeta(174),bmetb(174),bmetc(174),bmetd(174) + real llra(174),llrb(174),llrc(174),llrd(174),llrz(174) !Soft symbols real dd0(15*12000) - integer*1 message77(77),apmask(174),cw(174) - integer apsym(58) - integer mcq(29),mcqru(29),mcqfd(29),mcqtest(29) + real ss(9) + integer*1 message77(77),message91(91),apmask(174),cw(174) + integer apsym(58),aph10(10) + integer mcq(29),mcqru(29),mcqfd(29),mcqtest(29),mcqww(29) integer mrrr(19),m73(19),mrr73(19) integer itone(NN) integer icos7(0:6),ip(1) @@ -27,6 +29,7 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & integer ncontest,ncontest0 logical one(0:511,0:8) integer graymap(0:7) + integer iloc(1) complex cd0(0:3199) complex ctwk(32) complex csymb(32) @@ -37,6 +40,7 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & data mcqru/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,1,1,0,0/ data mcqfd/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,1,0/ data mcqtest/0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,1,0/ + data mcqww/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,1,1,1,1,0/ data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/ data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/ data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/ @@ -44,12 +48,12 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & data graymap/0,1,3,2,5,6,4,7/ save nappasses,naptypes,ncontest0,one - if(first.or.(ncontest.ne.ncontest0)) then mcq=2*mcq-1 mcqfd=2*mcqfd-1 mcqru=2*mcqru-1 mcqtest=2*mcqtest-1 + mcqww=2*mcqww-1 mrrr=2*mrrr-1 m73=2*m73-1 mrr73=2*mrr73-1 @@ -86,7 +90,7 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & ncontest0=ncontest endif - dxcall13=hiscall12 + dxcall13=hiscall12 ! initialize for use in packjt77 mycall13=mycall12 max_iterations=30 @@ -104,17 +108,15 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal smax=0.0 - do idt=i0-8,i0+8 !Search over +/- one quarter symbol + do idt=i0-10,i0+10 !Search over +/- one quarter symbol call sync8d(cd0,idt,ctwk,0,sync) if(sync.gt.smax) then smax=sync ibest=idt endif enddo - xdt2=ibest*dt2 !Improved estimate for DT ! Now peak up in frequency - i0=nint(xdt2*fs2) smax=0.0 do ifr=-5,5 !Search over +/- 2.5 Hz delf=ifr*0.5 @@ -124,7 +126,7 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & ctwk(i)=cmplx(cos(phi),sin(phi)) phi=mod(phi+dphi,twopi) enddo - call sync8d(cd0,i0,ctwk,1,sync) + call sync8d(cd0,ibest,ctwk,1,sync) if( sync .gt. smax ) then smax=sync delfbest=delf @@ -133,9 +135,22 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & a=0.0 a(1)=-delfbest call twkfreq1(cd0,NP2,fs2,a,cd0) - xdt=xdt2 f1=f1+delfbest !Improved estimate of DF - call sync8d(cd0,i0,ctwk,0,sync) + + call timer('ft8_down',0) + call ft8_downsample(dd0,.false.,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + smax=0.0 + do idt=-4,4 !Search over +/- one quarter symbol + call sync8d(cd0,ibest+idt,ctwk,0,sync) + ss(idt+5)=sync + enddo + smax=maxval(ss) + iloc=maxloc(ss) + ibest=iloc(1)-5+ibest + xdt=(ibest-1)*dt2 + sync=smax do k=1,NN i1=ibest+(k-1)*32 @@ -196,6 +211,14 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & if(i32+ib .gt.174) cycle if(nsym.eq.1) then bmeta(i32+ib)=bm + den=max(maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)), & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))) + if(den.gt.0.0) then + cm=bm/den + else ! erase it + cm=0.0 + endif + bmetd(i32+ib)=cm elseif(nsym.eq.2) then bmetb(i32+ib)=bm elseif(nsym.eq.3) then @@ -208,11 +231,13 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & call normalizebmet(bmeta,174) call normalizebmet(bmetb,174) call normalizebmet(bmetc,174) + call normalizebmet(bmetd,174) scalefac=2.83 llra=scalefac*bmeta llrb=scalefac*bmetb llrc=scalefac*bmetc + llrd=scalefac*bmetd apmag=maxval(abs(llra))*1.01 @@ -221,34 +246,36 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & ! 1 regular decoding, nsym=1 ! 2 regular decoding, nsym=2 ! 3 regular decoding, nsym=3 -! 4 ap pass 1, nsym=1 (for now?) -! 5 ap pass 2 -! 6 ap pass 3 -! 7 ap pass 4 +! 4 regular decoding, nsym=1, bit-by-bit normalized +! 5 ap pass 1, nsym=1 +! 6 ap pass 2 +! 7 ap pass 3 +! 8 ap pass 4 - if(lapon.or.ncontest.eq.6) then !Hounds always use AP + if(lapon.or.ncontest.eq.7) then !Hounds always use AP if(.not.lapcqonly) then - npasses=3+nappasses(nQSOProgress) + npasses=4+nappasses(nQSOProgress) else - npasses=4 + npasses=5 endif else - npasses=3 + npasses=4 endif - + if(nzhsym.lt.50) npasses=4 + do ipass=1,npasses - llrd=llra - if(ipass.eq.2) llrd=llrb - if(ipass.eq.3) llrd=llrc - if(ipass.le.3) then + llrz=llra + if(ipass.eq.2) llrz=llrb + if(ipass.eq.3) llrz=llrc + if(ipass.eq.4) llrz=llrd + if(ipass.le.4) then apmask=0 iaptype=0 endif - - if(ipass .gt. 3) then - llrd=llra + if(ipass .gt. 4) then + llrz=llra if(.not.lapcqonly) then - iaptype=naptypes(nQSOProgress,ipass-3) + iaptype=naptypes(nQSOProgress,ipass-4) else iaptype=1 endif @@ -258,129 +285,138 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & ! 2 : EU_VHF ! 3 : FIELD DAY ! 4 : RTTY -! 5 : FOX -! 6 : HOUND +! 5 : WW_DIGI +! 6 : FOX +! 7 : HOUND ! ! Conditions that cause us to bail out of AP decoding - if(ncontest.le.4 .and. iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid .and. abs(f1-nftx).gt.napwid) ) cycle - if(ncontest.eq.5) cycle ! No AP for Foxes - if(ncontest.eq.6.and.f1.gt.950.0) cycle ! Hounds use AP only for signals below 950 Hz + if(ncontest.le.5 .and. iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid .and. abs(f1-nftx).gt.napwid) ) cycle + if(ncontest.eq.6) cycle ! No AP for Foxes + if(ncontest.eq.7.and.f1.gt.950.0) cycle ! Hounds use AP only for signals below 950 Hz if(iaptype.ge.2 .and. apsym(1).gt.1) cycle ! No, or nonstandard, mycall + if(ncontest.eq.7 .and. iaptype.ge.2 .and. aph10(1).gt.1) cycle if(iaptype.ge.3 .and. apsym(30).gt.1) cycle ! No, or nonstandard, dxcall if(iaptype.eq.1) then ! CQ or CQ RU or CQ TEST or CQ FD apmask=0 apmask(1:29)=1 - if(ncontest.eq.0) llrd(1:29)=apmag*mcq(1:29) - if(ncontest.eq.1) llrd(1:29)=apmag*mcqtest(1:29) - if(ncontest.eq.2) llrd(1:29)=apmag*mcqtest(1:29) - if(ncontest.eq.3) llrd(1:29)=apmag*mcqfd(1:29) - if(ncontest.eq.4) llrd(1:29)=apmag*mcqru(1:29) - if(ncontest.eq.6) llrd(1:29)=apmag*mcq(1:29) + if(ncontest.eq.0) llrz(1:29)=apmag*mcq(1:29) + if(ncontest.eq.1) llrz(1:29)=apmag*mcqtest(1:29) + if(ncontest.eq.2) llrz(1:29)=apmag*mcqtest(1:29) + if(ncontest.eq.3) llrz(1:29)=apmag*mcqfd(1:29) + if(ncontest.eq.4) llrz(1:29)=apmag*mcqru(1:29) + if(ncontest.eq.5) llrz(1:29)=apmag*mcqww(1:29) + if(ncontest.eq.7) llrz(1:29)=apmag*mcq(1:29) apmask(75:77)=1 - llrd(75:76)=apmag*(-1) - llrd(77)=apmag*(+1) + llrz(75:76)=apmag*(-1) + llrz(77)=apmag*(+1) endif if(iaptype.eq.2) then ! MyCall,???,??? apmask=0 - if(ncontest.eq.0.or.ncontest.eq.1) then + if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.5) then apmask(1:29)=1 - llrd(1:29)=apmag*apsym(1:29) + llrz(1:29)=apmag*apsym(1:29) apmask(75:77)=1 - llrd(75:76)=apmag*(-1) - llrd(77)=apmag*(+1) + llrz(75:76)=apmag*(-1) + llrz(77)=apmag*(+1) else if(ncontest.eq.2) then apmask(1:28)=1 - llrd(1:28)=apmag*apsym(1:28) + llrz(1:28)=apmag*apsym(1:28) apmask(72:74)=1 - llrd(72)=apmag*(-1) - llrd(73)=apmag*(+1) - llrd(74)=apmag*(-1) + llrz(72)=apmag*(-1) + llrz(73)=apmag*(+1) + llrz(74)=apmag*(-1) apmask(75:77)=1 - llrd(75:77)=apmag*(-1) + llrz(75:77)=apmag*(-1) else if(ncontest.eq.3) then apmask(1:28)=1 - llrd(1:28)=apmag*apsym(1:28) + llrz(1:28)=apmag*apsym(1:28) apmask(75:77)=1 - llrd(75:77)=apmag*(-1) + llrz(75:77)=apmag*(-1) else if(ncontest.eq.4) then apmask(2:29)=1 - llrd(2:29)=apmag*apsym(1:28) + llrz(2:29)=apmag*apsym(1:28) apmask(75:77)=1 - llrd(75)=apmag*(-1) - llrd(76:77)=apmag*(+1) - else if(ncontest.eq.6) then ! ??? RR73; MyCall <???> ??? + llrz(75)=apmag*(-1) + llrz(76:77)=apmag*(+1) + else if(ncontest.eq.7) then ! ??? RR73; MyCall <Fox Call hash10> ??? apmask(29:56)=1 - llrd(29:56)=apmag*apsym(1:28) + llrz(29:56)=apmag*apsym(1:28) + apmask(57:66)=1 + llrz(57:66)=apmag*aph10(1:10) apmask(72:77)=1 - llrd(72:73)=apmag*(-1) - llrd(74)=apmag*(+1) - llrd(75:77)=apmag*(-1) + llrz(72:73)=apmag*(-1) + llrz(74)=apmag*(+1) + llrz(75:77)=apmag*(-1) endif endif if(iaptype.eq.3) then ! MyCall,DxCall,??? apmask=0 - if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2.or.ncontest.eq.6) then + if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2.or.ncontest.eq.5.or.ncontest.eq.7) then apmask(1:58)=1 - llrd(1:58)=apmag*apsym + llrz(1:58)=apmag*apsym apmask(75:77)=1 - llrd(75:76)=apmag*(-1) - llrd(77)=apmag*(+1) + llrz(75:76)=apmag*(-1) + llrz(77)=apmag*(+1) else if(ncontest.eq.3) then ! Field Day apmask(1:56)=1 - llrd(1:28)=apmag*apsym(1:28) - llrd(29:56)=apmag*apsym(30:57) + llrz(1:28)=apmag*apsym(1:28) + llrz(29:56)=apmag*apsym(30:57) apmask(72:74)=1 apmask(75:77)=1 - llrd(75:77)=apmag*(-1) - else if(ncontest.eq.4) then ! RTTY RU + llrz(75:77)=apmag*(-1) + else if(ncontest.eq.4) then apmask(2:57)=1 - llrd(2:29)=apmag*apsym(1:28) - llrd(30:57)=apmag*apsym(30:57) + llrz(2:29)=apmag*apsym(1:28) + llrz(30:57)=apmag*apsym(30:57) apmask(75:77)=1 - llrd(75)=apmag*(-1) - llrd(76:77)=apmag*(+1) + llrz(75)=apmag*(-1) + llrz(76:77)=apmag*(+1) endif endif - if(iaptype.eq.5.and.ncontest.eq.6) cycle !Hound + if(iaptype.eq.5.and.ncontest.eq.7) cycle !Hound if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then apmask=0 - if(ncontest.le.4 .or. (ncontest.eq.6.and.iaptype.eq.6)) then + if(ncontest.le.5 .or. (ncontest.eq.7.and.iaptype.eq.6)) then apmask(1:77)=1 ! mycall, hiscall, RRR|73|RR73 - llrd(1:58)=apmag*apsym - if(iaptype.eq.4) llrd(59:77)=apmag*mrrr - if(iaptype.eq.5) llrd(59:77)=apmag*m73 - if(iaptype.eq.6) llrd(59:77)=apmag*mrr73 - else if(ncontest.eq.6.and.iaptype.eq.4) then ! Hound listens for MyCall RR73;... + llrz(1:58)=apmag*apsym + if(iaptype.eq.4) llrz(59:77)=apmag*mrrr + if(iaptype.eq.5) llrz(59:77)=apmag*m73 + if(iaptype.eq.6) llrz(59:77)=apmag*mrr73 + else if(ncontest.eq.7.and.iaptype.eq.4) then ! Hound listens for MyCall RR73;... apmask(1:28)=1 - llrd(1:28)=apmag*apsym(1:28) + llrz(1:28)=apmag*apsym(1:28) + apmask(57:66)=1 + llrz(57:66)=apmag*aph10(1:10) apmask(72:77)=1 - llrd(72:73)=apmag*(-1) - llrd(74)=apmag*(1) - llrd(75:77)=apmag*(-1) + llrz(72:73)=apmag*(-1) + llrz(74)=apmag*(1) + llrz(75:77)=apmag*(-1) endif endif endif cw=0 - call timer('bpd174_91 ',0) - call bpdecode174_91(llrd,apmask,max_iterations,message77,cw,nharderrors, & - niterations) - call timer('bpd174_91 ',1) dmin=0.0 - if(ndepth.eq.3 .and. nharderrors.lt.0) then - ndeep=3 - if(abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid) then - ndeep=4 - endif - if(nagain) ndeep=5 - call timer('osd174_91 ',0) - call osd174_91(llrd,apmask,ndeep,message77,cw,nharderrors,dmin) - call timer('osd174_91 ',1) + norder=2 + maxosd=2 + if(ndepth.lt.3) maxosd=1 + if(abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid .or. ncontest.eq.7) then + maxosd=2 + endif + if(nagain) then + norder=3 + maxosd=1 endif + call timer('dec174_91 ',0) + Keff=91 + call decode174_91(llrz,Keff,maxosd,norder,apmask,message91,cw, & + ntype,nharderrors,dmin) + if(nharderrors.ge.0) message77=message91(1:77) + call timer('dec174_91 ',1) msg37=' ' if(nharderrors.lt.0 .or. nharderrors.gt.36) cycle @@ -388,16 +424,18 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & write(c77,'(77i1)') message77 read(c77(72:74),'(b3)') n3 read(c77(75:77),'(b3)') i3 - if(i3.gt.4 .or. (i3.eq.0.and.n3.gt.5)) then - cycle - endif + if(i3.gt.5 .or. (i3.eq.0.and.n3.gt.6)) cycle call unpack77(c77,1,msg37,unpk77_success) if(.not.unpk77_success) then cycle endif nbadcrc=0 ! If we get this far: valid codeword, valid (i3,n3), nonquirky message. call get_ft8_tones_from_77bits(message77,itone) - if(lsubtract) call subtractft8(dd0,itone,f1,xdt) + if(lsubtract) then + call timer('sub_ft8a',0) + call subtractft8(dd0,itone,f1,xdt,.false.) + call timer('sub_ft8a',1) + endif xsig=0.0 xnoi=0.0 do i=1,79 @@ -409,16 +447,19 @@ subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, & xsnr2=0.001 arg=xsig/xnoi-1.0 if(arg.gt.0.1) xsnr=arg - arg=xsig/xbase/2.6e6-1.0 + arg=xsig/xbase/3.0e6-1.0 if(arg.gt.0.1) xsnr2=arg xsnr=10.0*log10(xsnr)-27.0 xsnr2=10.0*log10(xsnr2)-27.0 if(.not.nagain) then xsnr=xsnr2 - endif - if(xsnr .lt. -24.0) xsnr=-24.0 - - return + endif + if(nsync.le.7 .and. xsnr.lt.-24.0) then !bail out, likely false decode + nbadcrc=1 + return + endif + if(xsnr .lt. -24.0) xsnr=-24.0 + return enddo return end subroutine ft8b diff --git a/lib/ft8/ft8code.f90 b/lib/ft8/ft8code.f90 index cbafd34b..8d5b5279 100644 --- a/lib/ft8/ft8code.f90 +++ b/lib/ft8/ft8code.f90 @@ -12,7 +12,8 @@ program ft8code character*9 comment character bad*1,msgtype*18 integer itone(NN) - integer*1 msgbits(77) + integer*1 msgbits(77),codeword(174) + logical short ! Get command-line argument(s) nargs=iargc() @@ -23,19 +24,22 @@ program ft8code print*,'bit and symbol ordering, and other details of the FT8 protocol.' print* print*,'Usage: ft8code [-c grid] "message" # Results for specified message' - print*,' ft8code -t # Examples of all message types' + print*,' ft8code -T # Examples of all message types' + print*,' ft8code -t # Short format examples' go to 999 endif call getarg(1,msg) !Message to be transmitted - if(len(trim(msg)).eq.2 .and. msg(1:2).eq.'-t') then + short=.false. + if(len(trim(msg)).eq.2 .and. (msg(1:2).eq.'-T' .or. msg(1:2).eq.'-t')) then nmsg=NTEST + short=msg(1:2).eq.'-t' else call fmtmsg(msg,iz) !To upper case; collapse multiple blanks nmsg=1 endif - write(*,1010) + if(.not.short) write(*,1010) 1010 format(4x,'Message',31x,'Decoded',29x,'Err i3.n3'/100('-')) do imsg=1,nmsg @@ -45,6 +49,7 @@ program ft8code i3=-1 n3=-1 call genft8(msg,i3,n3,msgsent,msgbits,itone) + call encode174_91(msgbits,codeword) msgtype="" if(i3.eq.0) then if(n3.eq.0) msgtype="Free text" @@ -58,26 +63,42 @@ program ft8code if(i3.eq.1) msgtype="Standard msg" if(i3.eq.2) msgtype="EU VHF Contest" if(i3.eq.3) msgtype="ARRL RTTY Roundup" - if(i3.eq.4) msgtype="Nonstandard calls" - if(i3.ge.5) msgtype="Undefined msg type" + if(i3.eq.4) msgtype="Nonstandard call" + if(i3.ge.5) msgtype="Undefined type" if(i3.ge.1) n3=-1 bad=" " comment=' ' if(msg.ne.msgsent) bad="*" - if(n3.ge.0) then - write(*,1020) imsg,msg,msgsent,bad,i3,n3,msgtype,comment -1020 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',i1,1x,a18,1x,a9) + if(short) then + if(n3.ge.0) then + write(*,1020) i3,n3,msg,bad,msgtype +1020 format(i1,'.',i1,2x,a37,1x,a1,1x,a18) + else + write(*,1022) i3,msg,bad,msgtype +1022 format(i1,'.',3x,a37,1x,a1,1x,a18) + endif else - write(*,1022) imsg,msg,msgsent,bad,i3,msgtype,comment -1022 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',1x,1x,a18,1x,a9) + if(n3.ge.0) then + write(*,1024) imsg,msg,msgsent,bad,i3,n3,msgtype,comment +1024 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',i1,1x,a18,1x,a9) + else + write(*,1026) imsg,msg,msgsent,bad,i3,msgtype,comment +1026 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',1x,1x,a18,1x,a9) + endif endif enddo if(nmsg.eq.1) then write(*,1030) msgbits -1030 format(/'Message bits: ',/77i1) +1030 format(/'Source-encoded message, 77 bits: ',/77i1) + write(*,1031) codeword(78:91) +1031 format(/'14-bit CRC: ',/14i1) + write(*,1032) codeword(92:174) +1032 format(/'83 Parity bits: ',/83i1) write(*,1034) itone -1034 format(/'Channel symbols (tones):'/79i1) +1034 format(/'Channel symbols (79 tones):'/ & + ' Sync ',14x,'Data',15x,'Sync',15x,'Data',15x,'Sync'/ & + 7i1,1x,29i1,1x,7i1,1x,29i1,1x,7i1) endif 999 end program ft8code diff --git a/lib/ft8/ft8sim.f90 b/lib/ft8/ft8sim.f90 index c5dd82bb..42931635 100644 --- a/lib/ft8/ft8sim.f90 +++ b/lib/ft8/ft8sim.f90 @@ -1,4 +1,4 @@ -program ft8sim +program ft8sim_gfsk ! Generate simulated "type 2" ft8 files ! Output is saved to a *.wav file. @@ -13,18 +13,21 @@ program ft8sim character c77*77 complex c0(0:NMAX-1) complex c(0:NMAX-1) + complex cwave(0:NWAVE-1) real wave(NMAX) + real xjunk(NWAVE) integer itone(NN) integer*1 msgbits(77) integer*2 iwave(NMAX) !Generated full-length waveform ! Get command-line argument(s) nargs=iargc() - if(nargs.ne.8) then - print*,'Usage: ft8sim "message" f0 DT fdop del width nfiles snr' - print*,'Examples: ft8sim "K1ABC W9XYZ EN37" 1500.0 0.0 0.1 1.0 0 10 -18' - print*,' ft8sim "WA9XYZ/R KA1ABC/R FN42" 1500.0 0.0 0.1 1.0 0 10 -18' + if(nargs.ne.7) then + print*,'Usage: ft8sim "message" f0 DT fdop del nfiles snr' + print*,'Examples: ft8sim "K1ABC W9XYZ EN37" 1500.0 0.0 0.1 1.0 10 -18' + print*,' ft8sim "WA9XYZ/R KA1ABC/R FN42" 1500.0 0.0 0.1 1.0 10 -18' print*,' ft8sim "K1ABC RR73; W9XYZ <KH1/KH7Z> -11" 300 0 0 0 25 1 -10' + print*,' ft8sim "<G4ABC/P> <PA9XYZ> R 570007 JO22DB" 1500 0 0 0 1 -10' go to 999 endif call getarg(1,msg37) !Message to be transmitted @@ -37,10 +40,8 @@ program ft8sim call getarg(5,arg) read(arg,*) delay !Watterson delay (ms) call getarg(6,arg) - read(arg,*) width !Filter transition width (Hz) - call getarg(7,arg) read(arg,*) nfiles !Number of files - call getarg(8,arg) + call getarg(7,arg) read(arg,*) snrdb !SNR_2500 nsig=1 @@ -57,6 +58,7 @@ program ft8sim baud=1.0/tt !Keying rate (baud) bw=8*baud !Occupied bandwidth (Hz) txt=NZ*dt !Transmission length (s) + bt=2.0 bandwidth_ratio=2500.0/(fs/2.0) sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) if(snrdb.gt.90.0) sig=1.0 @@ -67,9 +69,10 @@ program ft8sim n3=-1 call pack77(msg37,i3,n3,c77) call genft8(msg37,i3,n3,msgsent37,msgbits,itone) + call gen_ft8wave(itone,NN,NSPS,bt,fs,f0,cwave,xjunk,1,NWAVE) !Generate complex cwave write(*,*) - write(*,'(a23,a37,3x,a7,i1,a1,i1)') 'New Style FT8 Message: ',msgsent37,'i3.n3: ',i3,'.',n3 + write(*,'(a23,a37,3x,a7,i1,a1,i1)') 'Decoded message: ',msgsent37,'i3.n3: ',i3,'.',n3 write(*,1000) f0,xdt,txt,snrdb,bw 1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1, & ' BW:',f4.1) @@ -90,26 +93,15 @@ program ft8sim msg0=msg do ifile=1,nfiles - k=nint((xdt+0.5)/dt) - ia=max(1,k) - phi=0.0 - c0=0.0 - do j=1,NN !Generate complex waveform - dphi=twopi*(f0*dt+itone(j)/real(NSPS)) - do i=1,NSPS - if(k.ge.0 .and. k.lt.NMAX) c0(k)=cmplx(cos(phi),sin(phi)) - k=k+1 - phi=mod(phi+dphi,twopi) - enddo - enddo + c0=0. + c0(0:NWAVE-1)=cwave + c0=cshift(c0,-nint((xdt+0.5)/dt)) if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c0,NMAX,NWAVE,fs,delay,fspread) c=sig*c0 - ib=min(k,NMAX) - wave=real(c) - peak=maxval(abs(wave(ia:ib))) + wave=imag(c) + peak=maxval(abs(wave)) nslots=1 - if(width.gt.0.0) call filt8(f0,nslots,width,wave) if(snrdb.lt.90) then do i=1,NMAX !Add gaussian noise at specified SNR @@ -128,7 +120,6 @@ program ft8sim endif if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." iwave=nint(wave) - h=default_header(12000,NMAX) write(fname,1102) ifile 1102 format('000000_',i6.6,'.wav') @@ -138,4 +129,4 @@ program ft8sim write(*,1110) ifile,xdt,f0,snrdb,fname 1110 format(i4,f7.2,f8.2,f7.1,2x,a17) enddo -999 end program ft8sim +999 end program ft8sim_gfsk diff --git a/lib/ft8/ft8sim_gfsk.f90 b/lib/ft8/ft8sim_gfsk.f90 deleted file mode 100644 index 4cca67e4..00000000 --- a/lib/ft8/ft8sim_gfsk.f90 +++ /dev/null @@ -1,131 +0,0 @@ -program ft8sim_gfsk - -! Generate simulated "type 2" ft8 files -! Output is saved to a *.wav file. - - use wavhdr - use packjt77 - include 'ft8_params.f90' !Set various constants - parameter (NWAVE=NN*NSPS) - type(hdr) h !Header for .wav file - character arg*12,fname*17 - character msg37*37,msgsent37*37 - character c77*77 - complex c0(0:NMAX-1) - complex c(0:NMAX-1) - complex cwave(0:NWAVE-1) - real wave(NMAX) - real xjunk(NWAVE) - integer itone(NN) - integer*1 msgbits(77) - integer*2 iwave(NMAX) !Generated full-length waveform - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.7) then - print*,'Usage: ft8sim "message" f0 DT fdop del nfiles snr' - print*,'Examples: ft8sim "K1ABC W9XYZ EN37" 1500.0 0.0 0.1 1.0 10 -18' - print*,' ft8sim "WA9XYZ/R KA1ABC/R FN42" 1500.0 0.0 0.1 1.0 10 -18' - print*,' ft8sim "K1ABC RR73; W9XYZ <KH1/KH7Z> -11" 300 0 0 0 25 1 -10' - go to 999 - endif - call getarg(1,msg37) !Message to be transmitted - call getarg(2,arg) - read(arg,*) f0 !Frequency (only used for single-signal) - call getarg(3,arg) - read(arg,*) xdt !Time offset from nominal (s) - call getarg(4,arg) - read(arg,*) fspread !Watterson frequency spread (Hz) - call getarg(5,arg) - read(arg,*) delay !Watterson delay (ms) - call getarg(6,arg) - read(arg,*) nfiles !Number of files - call getarg(7,arg) - read(arg,*) snrdb !SNR_2500 - - nsig=1 - if(f0.lt.100.0) then - nsig=f0 - f0=1500 - endif - - nfiles=abs(nfiles) - twopi=8.0*atan(1.0) - fs=12000.0 !Sample rate (Hz) - dt=1.0/fs !Sample interval (s) - tt=NSPS*dt !Duration of symbols (s) - baud=1.0/tt !Keying rate (baud) - bw=8*baud !Occupied bandwidth (Hz) - txt=NZ*dt !Transmission length (s) - bt=2.0 - bandwidth_ratio=2500.0/(fs/2.0) - sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb) - if(snrdb.gt.90.0) sig=1.0 - txt=NN*NSPS/12000.0 - - ! Source-encode, then get itone() - i3=-1 - n3=-1 - call pack77(msg37,i3,n3,c77) - call genft8(msg37,i3,n3,msgsent37,msgbits,itone) - call gen_ft8wave(itone,NN,NSPS,bt,fs,f0,cwave,xjunk,1,NWAVE) !Generate complex cwave - - write(*,*) - write(*,'(a23,a37,3x,a7,i1,a1,i1)') 'New Style FT8 Message: ',msgsent37,'i3.n3: ',i3,'.',n3 - write(*,1000) f0,xdt,txt,snrdb,bw -1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1, & - ' BW:',f4.1) - write(*,*) - if(i3.eq.1) then - write(*,*) ' mycall hiscall hisgrid' - write(*,'(28i1,1x,i1,1x,28i1,1x,i1,1x,i1,1x,15i1,1x,3i1)') msgbits(1:77) - else - write(*,'(a14)') 'Message bits: ' - write(*,'(77i1)') msgbits - endif - write(*,*) - write(*,'(a17)') 'Channel symbols: ' - write(*,'(79i1)') itone - write(*,*) - - call sgran() - - msg0=msg - do ifile=1,nfiles - c0=0. - c0(0:NWAVE-1)=cwave - c0=cshift(c0,-nint((xdt+0.5)/dt)) - if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c0,NMAX,NWAVE,fs,delay,fspread) - c=sig*c0 - - wave=imag(c) - peak=maxval(abs(wave)) - nslots=1 - - if(snrdb.lt.90) then - do i=1,NMAX !Add gaussian noise at specified SNR - xnoise=gran() - wave(i)=wave(i) + xnoise - enddo - endif - - gain=100.0 - if(snrdb.lt.90.0) then - wave=gain*wave - else - datpk=maxval(abs(wave)) - fac=32766.9/datpk - wave=fac*wave - endif - if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." - iwave=nint(wave) - h=default_header(12000,NMAX) - write(fname,1102) ifile -1102 format('000000_',i6.6,'.wav') - open(10,file=fname,status='unknown',access='stream') - write(10) h,iwave !Save to *.wav file - close(10) - write(*,1110) ifile,xdt,f0,snrdb,fname -1110 format(i4,f7.2,f8.2,f7.1,2x,a17) - enddo -999 end program ft8sim_gfsk diff --git a/lib/ft8/gen_ft8wave.f90 b/lib/ft8/gen_ft8wave.f90 index 10edc994..02e7fdbd 100644 --- a/lib/ft8/gen_ft8wave.f90 +++ b/lib/ft8/gen_ft8wave.f90 @@ -2,15 +2,15 @@ subroutine gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) ! ! generate ft8 waveform using Gaussian-filtered frequency pulses. ! - - parameter(MAX_SECONDS=20) + use timer_module, only: timer + parameter(MAX_SECONDS=20,NTAB=65536) real wave(nwave) - complex cwave(nwave) + complex cwave(nwave),ctab(0:NTAB-1) real pulse(23040) real dphi(0:(nsym+2)*nsps-1) integer itone(nsym) data ibt0/0/ - save pulse,twopi,dt,hmod,ibt0 + save pulse,twopi,dt,hmod,ibt0,ctab ibt=nint(10*bt) if(ibt0.ne.ibt) then @@ -23,6 +23,10 @@ subroutine gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) pulse(i)=gfsk_pulse(bt,tt) enddo ibt0=nint(10*bt) + do i=0,NTAB-1 + phi=i*twopi/NTAB + ctab(i)=cmplx(cos(phi),sin(phi)) + enddo endif ! Compute the smoothed frequency waveform. @@ -40,19 +44,23 @@ subroutine gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) ! Calculate and insert the audio waveform phi=0.0 - dphi = dphi + twopi*f0*dt !Shift frequency up by f0 + dphi = dphi + twopi*f0*dt !Shift frequency up by f0 wave=0. - if (icmplx .ne. 0) cwave=0. ! avoid writing to memory we may not have access to + if(icmplx .ne. 0) cwave=0. !Avoid writing to memory we may not have access to + + call timer('gen_loop',0) k=0 - do j=nsps,nsps+nwave-1 !Don't include dummy symbols + do j=nsps,nsps+nwave-1 !Don't include dummy symbols k=k+1 if(icmplx.eq.0) then wave(k)=sin(phi) else - cwave(k)=cmplx(cos(phi),sin(phi)) + i=phi*float(NTAB)/twopi + cwave(k)=ctab(i) endif phi=mod(phi+dphi(j),twopi) enddo + call timer('gen_loop',1) ! Apply envelope shaping to the first and last symbols nramp=nint(nsps/8.0) diff --git a/lib/ft8/get_crc14.f90 b/lib/ft8/get_crc14.f90 new file mode 100644 index 00000000..63580897 --- /dev/null +++ b/lib/ft8/get_crc14.f90 @@ -0,0 +1,25 @@ +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 + integer*1 mc(len) + integer*1 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,len-15 + 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 + +end subroutine get_crc14 diff --git a/lib/ft8/get_spectrum_baseline.f90 b/lib/ft8/get_spectrum_baseline.f90 new file mode 100644 index 00000000..9cf4e637 --- /dev/null +++ b/lib/ft8/get_spectrum_baseline.f90 @@ -0,0 +1,43 @@ +subroutine get_spectrum_baseline(dd,nfa,nfb,sbase)
+
+ include 'ft8_params.f90'
+ parameter(NST=NFFT1/2,NF=93) !NF=NMAX/NST-1
+ real s(NH1,NF)
+ real savg(NH1)
+ real sbase(NH1)
+ real x(NFFT1)
+ real window(NFFT1)
+ complex cx(0:NH1)
+ real dd(NMAX)
+ equivalence (x,cx)
+ logical first
+ data first/.true./
+ save first,window
+
+ if(first) then
+ first=.false.
+ pi=4.0*atan(1.)
+ window=0.
+ call nuttal_window(window,NFFT1)
+ window=window/sum(window)*NSPS*2/300.0
+ endif
+
+! Compute symbol spectra, stepping by NSTEP steps.
+ savg=0.
+ df=12000.0/NFFT1
+ do j=1,NF
+ ia=(j-1)*NST + 1
+ ib=ia+NFFT1-1
+ if(ib.gt.NMAX) exit
+ x=dd(ia:ib)*window
+ call four2a(x,NFFT1,1,-1,0) !r2c FFT
+ s(1:NH1,j)=abs(cx(1:NH1))**2
+ savg=savg + s(1:NH1,j) !Average spectrum
+ enddo
+
+ if(nfa.lt.100) nfa=100
+ if(nfb.gt.4910) nfb=4910
+ call baseline(savg,nfa,nfb,sbase)
+
+return
+end subroutine get_spectrum_baseline
diff --git a/lib/ft8/ldpc_174_91_c_parity.f90 b/lib/ft8/ldpc_174_91_c_parity.f90 index 6210ee26..2309ad8e 100644 --- a/lib/ft8/ldpc_174_91_c_parity.f90 +++ b/lib/ft8/ldpc_174_91_c_parity.f90 @@ -1,88 +1,5 @@ -data Mn/ & - 1, 24, 66, & - 2, 5, 70, & - 3, 31, 65, & - 4, 49, 58, & - 6, 60, 67, & - 7, 32, 75, & - 8, 48, 82, & - 9, 35, 41, & - 10, 39, 62, & - 11, 14, 61, & - 12, 71, 74, & - 13, 23, 78, & - 15, 16, 79, & - 17, 54, 63, & - 18, 50, 57, & - 19, 30, 47, & - 20, 64, 80, & - 21, 28, 69, & - 22, 25, 43, & - 26, 34, 72, & - 27, 36, 37, & - 29, 40, 44, & - 33, 52, 53, & - 38, 55, 83, & - 42, 51, 59, & - 45, 76, 81, & - 46, 68, 77, & - 56, 67, 73, & - 1, 4, 5, & - 2, 47, 51, & - 3, 46, 82, & - 6, 24, 76, & - 7, 9, 16, & - 8, 10, 78, & - 11, 35, 55, & - 12, 38, 64, & - 13, 22, 37, & - 14, 15, 58, & - 17, 50, 53, & - 18, 29, 56, & - 19, 26, 57, & - 20, 39, 77, & - 21, 36, 63, & - 23, 54, 74, & - 25, 69, 73, & - 27, 33, 65, & - 28, 44, 79, & - 30, 43, 52, & - 31, 45, 61, & - 32, 48, 71, & - 34, 60, 62, & - 40, 41, 70, & - 42, 66, 68, & - 49, 75, 83, & - 59, 72, 80, & - 36, 64, 81, & - 1, 65, 74, & - 2, 8, 81, & - 3, 26, 79, & - 4, 22, 72, & - 5, 38, 50, & - 6, 9, 52, & - 7, 18, 77, & - 10, 28, 55, & - 11, 56, 59, & - 12, 67, 68, & - 13, 29, 47, & - 14, 39, 54, & - 15, 60, 70, & - 16, 37, 66, & - 17, 25, 82, & - 19, 21, 71, & - 20, 30, 31, & - 23, 75, 80, & - 24, 69, 75, & - 27, 32, 62, & - 33, 59, 76, & - 34, 53, 61, & - 35, 46, 47, & - 40, 43, 83, & - 41, 42, 63, & - 20, 44, 48, & +data Mn/ & 16, 45, 73, & - 42, 49, 57, & 25, 51, 62, & 33, 58, 78, & 1, 44, 45, & @@ -172,98 +89,182 @@ data Mn/ & 14, 66, 72, & 22, 60, 74, & 35, 39, 79, & - 1, 46, 64/ + 1, 46, 64, & + 1, 24, 66, & + 2, 5, 70, & + 3, 31, 65, & + 4, 49, 58, & + 1, 4, 5, & + 6, 60, 67, & + 7, 32, 75, & + 8, 48, 82, & + 9, 35, 41, & + 10, 39, 62, & + 11, 14, 61, & + 12, 71, 74, & + 13, 23, 78, & + 11, 35, 55, & + 15, 16, 79, & + 7, 9, 16, & + 17, 54, 63, & + 18, 50, 57, & + 19, 30, 47, & + 20, 64, 80, & + 21, 28, 69, & + 22, 25, 43, & + 13, 22, 37, & + 2, 47, 51, & + 23, 54, 74, & + 26, 34, 72, & + 27, 36, 37, & + 21, 36, 63, & + 29, 40, 44, & + 19, 26, 57, & + 3, 46, 82, & + 14, 15, 58, & + 33, 52, 53, & + 30, 43, 52, & + 6, 9, 52, & + 27, 33, 65, & + 25, 69, 73, & + 38, 55, 83, & + 20, 39, 77, & + 18, 29, 56, & + 32, 48, 71, & + 42, 51, 59, & + 28, 44, 79, & + 34, 60, 62, & + 31, 45, 61, & + 46, 68, 77, & + 6, 24, 76, & + 8, 10, 78, & + 40, 41, 70, & + 17, 50, 53, & + 42, 66, 68, & + 4, 22, 72, & + 36, 64, 81, & + 13, 29, 47, & + 2, 8, 81, & + 56, 67, 73, & + 5, 38, 50, & + 12, 38, 64, & + 59, 72, 80, & + 3, 26, 79, & + 45, 76, 81, & + 1, 65, 74, & + 7, 18, 77, & + 11, 56, 59, & + 14, 39, 54, & + 16, 37, 66, & + 10, 28, 55, & + 15, 60, 70, & + 17, 25, 82, & + 20, 30, 31, & + 12, 67, 68, & + 23, 75, 80, & + 27, 32, 62, & + 24, 69, 75, & + 19, 21, 71, & + 34, 53, 61, & + 35, 46, 47, & + 33, 59, 76, & + 40, 43, 83, & + 41, 42, 63, & + 49, 75, 83, & + 20, 44, 48, & + 42, 49, 57/ -data Nm/ & - 1, 29, 57, 87, 114, 142, 174, & - 2, 30, 58, 88, 115, 143, 0, & - 3, 31, 59, 89, 107, 144, 0, & - 4, 29, 60, 90, 116, 145, 0, & - 2, 29, 61, 91, 108, 146, 166, & - 5, 32, 62, 89, 115, 147, 0, & - 6, 33, 63, 88, 117, 148, 161, & - 7, 34, 58, 92, 118, 149, 0, & - 8, 33, 62, 93, 119, 150, 0, & - 9, 34, 64, 94, 120, 150, 170, & - 10, 35, 65, 95, 121, 151, 0, & - 11, 36, 66, 96, 122, 152, 0, & - 12, 37, 67, 91, 123, 153, 165, & - 10, 38, 68, 97, 124, 154, 171, & - 13, 38, 69, 98, 125, 142, 0, & - 13, 33, 70, 83, 116, 155, 0, & - 14, 39, 71, 99, 126, 156, 0, & - 15, 40, 63, 100, 120, 157, 164, & - 16, 41, 72, 94, 127, 158, 0, & - 17, 42, 73, 82, 128, 138, 147, & - 18, 43, 72, 91, 129, 154, 0, & - 19, 37, 60, 101, 119, 159, 172, & - 12, 44, 74, 102, 121, 160, 0, & - 1, 32, 75, 103, 130, 153, 0, & - 19, 45, 71, 85, 131, 157, 0, & - 20, 41, 59, 104, 128, 161, 166, & - 21, 46, 76, 105, 130, 141, 0, & - 18, 47, 64, 99, 122, 145, 0, & - 22, 40, 67, 106, 126, 162, 0, & - 16, 48, 73, 102, 118, 142, 156, & - 3, 49, 73, 103, 119, 146, 0, & - 6, 50, 76, 97, 114, 162, 0, & - 23, 46, 77, 86, 127, 163, 0, & - 20, 51, 78, 102, 129, 164, 0, & - 8, 35, 79, 90, 132, 141, 173, & - 21, 43, 56, 95, 133, 144, 0, & - 21, 37, 70, 96, 134, 147, 0, & - 24, 36, 61, 107, 135, 159, 0, & - 9, 42, 68, 108, 136, 152, 173, & - 22, 52, 80, 103, 129, 148, 163, & - 8, 52, 81, 104, 137, 160, 0, & - 25, 53, 81, 84, 118, 165, 0, & - 19, 48, 80, 97, 113, 166, 0, & - 22, 47, 82, 87, 112, 151, 0, & - 26, 49, 83, 87, 135, 140, 169, & - 27, 31, 79, 109, 134, 139, 174, & - 16, 30, 67, 79, 135, 167, 0, & - 7, 50, 82, 90, 133, 164, 0, & - 4, 54, 84, 106, 138, 150, 0, & - 15, 39, 61, 109, 124, 160, 0, & - 25, 30, 85, 110, 124, 144, 145, & - 23, 48, 62, 110, 123, 139, 0, & - 23, 39, 78, 101, 132, 138, 0, & - 14, 44, 68, 89, 116, 168, 0, & - 24, 35, 64, 111, 131, 153, 168, & - 28, 40, 65, 92, 137, 146, 0, & - 15, 41, 84, 105, 136, 151, 0, & - 4, 38, 86, 96, 131, 161, 0, & - 25, 55, 65, 77, 114, 152, 0, & - 5, 51, 69, 95, 126, 149, 172, & - 10, 49, 78, 88, 122, 158, 0, & - 9, 51, 76, 85, 137, 169, 0, & - 14, 43, 81, 98, 139, 170, 0, & - 17, 36, 56, 93, 127, 165, 174, & - 3, 46, 57, 106, 117, 154, 0, & - 1, 53, 70, 94, 132, 171, 0, & - 5, 28, 66, 112, 117, 170, 0, & - 27, 53, 66, 113, 133, 143, 169, & - 18, 45, 75, 93, 136, 149, 167, & - 2, 52, 69, 105, 140, 168, 0, & - 11, 50, 72, 111, 115, 155, 0, & - 20, 55, 60, 111, 112, 167, 171, & - 28, 45, 83, 109, 128, 163, 0, & - 11, 44, 57, 100, 110, 172, 0, & - 6, 54, 74, 75, 134, 140, 0, & - 26, 32, 77, 104, 120, 156, 0, & - 27, 42, 63, 99, 130, 159, 0, & - 12, 34, 86, 107, 113, 155, 0, & - 13, 47, 59, 92, 123, 173, 0, & - 17, 55, 74, 98, 141, 143, 157, & - 26, 56, 58, 101, 125, 162, 0, & - 7, 31, 71, 108, 121, 148, 0, & - 24, 54, 80, 100, 125, 158, 0/ +data Nm/ & + 4, 31, 59, 91, 92, 96, 153, & + 5, 32, 60, 93, 115, 146, 0, & + 6, 24, 61, 94, 122, 151, 0, & + 7, 33, 62, 95, 96, 143, 0, & + 8, 25, 63, 83, 93, 96, 148, & + 6, 32, 64, 97, 126, 138, 0, & + 5, 34, 65, 78, 98, 107, 154, & + 9, 35, 66, 99, 139, 146, 0, & + 10, 36, 67, 100, 107, 126, 0, & + 11, 37, 67, 87, 101, 139, 158, & + 12, 38, 68, 102, 105, 155, 0, & + 13, 39, 69, 103, 149, 162, 0, & + 8, 40, 70, 82, 104, 114, 145, & + 14, 41, 71, 88, 102, 123, 156, & + 15, 42, 59, 106, 123, 159, 0, & + 1, 33, 72, 106, 107, 157, 0, & + 16, 43, 73, 108, 141, 160, 0, & + 17, 37, 74, 81, 109, 131, 154, & + 11, 44, 75, 110, 121, 166, 0, & + 45, 55, 64, 111, 130, 161, 173, & + 8, 46, 71, 112, 119, 166, 0, & + 18, 36, 76, 89, 113, 114, 143, & + 19, 38, 77, 104, 116, 163, 0, & + 20, 47, 70, 92, 138, 165, 0, & + 2, 48, 74, 113, 128, 160, 0, & + 21, 45, 78, 83, 117, 121, 151, & + 22, 47, 58, 118, 127, 164, 0, & + 16, 39, 62, 112, 134, 158, 0, & + 23, 43, 79, 120, 131, 145, 0, & + 19, 35, 59, 73, 110, 125, 161, & + 20, 36, 63, 94, 136, 161, 0, & + 14, 31, 79, 98, 132, 164, 0, & + 3, 44, 80, 124, 127, 169, 0, & + 19, 46, 81, 117, 135, 167, 0, & + 7, 49, 58, 90, 100, 105, 168, & + 12, 50, 61, 118, 119, 144, 0, & + 13, 51, 64, 114, 118, 157, 0, & + 24, 52, 76, 129, 148, 149, 0, & + 25, 53, 69, 90, 101, 130, 156, & + 20, 46, 65, 80, 120, 140, 170, & + 21, 54, 77, 100, 140, 171, 0, & + 35, 82, 133, 142, 171, 174, 0, & + 14, 30, 83, 113, 125, 170, 0, & + 4, 29, 68, 120, 134, 173, 0, & + 1, 4, 52, 57, 86, 136, 152, & + 26, 51, 56, 91, 122, 137, 168, & + 52, 84, 110, 115, 145, 168, 0, & + 7, 50, 81, 99, 132, 173, 0, & + 23, 55, 67, 95, 172, 174, 0, & + 26, 41, 77, 109, 141, 148, 0, & + 2, 27, 41, 61, 62, 115, 133, & + 27, 40, 56, 124, 125, 126, 0, & + 18, 49, 55, 124, 141, 167, 0, & + 6, 33, 85, 108, 116, 156, 0, & + 28, 48, 70, 85, 105, 129, 158, & + 9, 54, 63, 131, 147, 155, 0, & + 22, 53, 68, 109, 121, 174, 0, & + 3, 13, 48, 78, 95, 123, 0, & + 31, 69, 133, 150, 155, 169, 0, & + 12, 43, 66, 89, 97, 135, 159, & + 5, 39, 75, 102, 136, 167, 0, & + 2, 54, 86, 101, 135, 164, 0, & + 15, 56, 87, 108, 119, 171, 0, & + 10, 44, 82, 91, 111, 144, 149, & + 23, 34, 71, 94, 127, 153, 0, & + 11, 49, 88, 92, 142, 157, 0, & + 29, 34, 87, 97, 147, 162, 0, & + 30, 50, 60, 86, 137, 142, 162, & + 10, 53, 66, 84, 112, 128, 165, & + 22, 57, 85, 93, 140, 159, 0, & + 28, 32, 72, 103, 132, 166, 0, & + 28, 29, 84, 88, 117, 143, 150, & + 1, 26, 45, 80, 128, 147, 0, & + 17, 27, 89, 103, 116, 153, 0, & + 51, 57, 98, 163, 165, 172, 0, & + 21, 37, 73, 138, 152, 169, 0, & + 16, 47, 76, 130, 137, 154, 0, & + 3, 24, 30, 72, 104, 139, 0, & + 9, 40, 90, 106, 134, 151, 0, & + 15, 58, 60, 74, 111, 150, 163, & + 18, 42, 79, 144, 146, 152, 0, & + 25, 38, 65, 99, 122, 160, 0, & + 17, 42, 75, 129, 170, 172, 0/ -data nrw/ & -7,6,6,6,7,6,7,6,6,7,6,6,7,7,6,6,6, & -7,6,7,6,7,6,6,6,7,6,6,6,7,6,6,6,6, & -7,6,6,6,7,7,6,6,6,6,7,7,6,6,6,6,7, & -6,6,6,7,6,6,6,6,7,6,6,6,7,6,6,6,7, & -7,6,6,7,6,6,6,6,6,6,6,7,6,6,6/ +data nrw/ & +7,6,6,6,7,6,7,6,6,7,6,6,7,7,6,6, & +6,7,6,7,6,7,6,6,6,7,6,6,6,7,6,6, & +6,6,7,6,6,6,7,7,6,6,6,6,7,7,6,6, & +6,6,7,6,6,6,7,6,6,6,6,7,6,6,6,7, & +6,6,6,7,7,6,6,7,6,6,6,6,6,6,6,7, & +6,6,6/ ncw=3 diff --git a/lib/ft8/ldpc_174_91_c_reordered_parity.f90 b/lib/ft8/ldpc_174_91_c_reordered_parity.f90 deleted file mode 100644 index 2309ad8e..00000000 --- a/lib/ft8/ldpc_174_91_c_reordered_parity.f90 +++ /dev/null @@ -1,270 +0,0 @@ -data Mn/ & - 16, 45, 73, & - 25, 51, 62, & - 33, 58, 78, & - 1, 44, 45, & - 2, 7, 61, & - 3, 6, 54, & - 4, 35, 48, & - 5, 13, 21, & - 8, 56, 79, & - 9, 64, 69, & - 10, 19, 66, & - 11, 36, 60, & - 12, 37, 58, & - 14, 32, 43, & - 15, 63, 80, & - 17, 28, 77, & - 18, 74, 83, & - 22, 53, 81, & - 23, 30, 34, & - 24, 31, 40, & - 26, 41, 76, & - 27, 57, 70, & - 29, 49, 65, & - 3, 38, 78, & - 5, 39, 82, & - 46, 50, 73, & - 51, 52, 74, & - 55, 71, 72, & - 44, 67, 72, & - 43, 68, 78, & - 1, 32, 59, & - 2, 6, 71, & - 4, 16, 54, & - 7, 65, 67, & - 8, 30, 42, & - 9, 22, 31, & - 10, 18, 76, & - 11, 23, 82, & - 12, 28, 61, & - 13, 52, 79, & - 14, 50, 51, & - 15, 81, 83, & - 17, 29, 60, & - 19, 33, 64, & - 20, 26, 73, & - 21, 34, 40, & - 24, 27, 77, & - 25, 55, 58, & - 35, 53, 66, & - 36, 48, 68, & - 37, 46, 75, & - 38, 45, 47, & - 39, 57, 69, & - 41, 56, 62, & - 20, 49, 53, & - 46, 52, 63, & - 45, 70, 75, & - 27, 35, 80, & - 1, 15, 30, & - 2, 68, 80, & - 3, 36, 51, & - 4, 28, 51, & - 5, 31, 56, & - 6, 20, 37, & - 7, 40, 82, & - 8, 60, 69, & - 9, 10, 49, & - 11, 44, 57, & - 12, 39, 59, & - 13, 24, 55, & - 14, 21, 65, & - 16, 71, 78, & - 17, 30, 76, & - 18, 25, 80, & - 19, 61, 83, & - 22, 38, 77, & - 23, 41, 50, & - 7, 26, 58, & - 29, 32, 81, & - 33, 40, 73, & - 18, 34, 48, & - 13, 42, 64, & - 5, 26, 43, & - 47, 69, 72, & - 54, 55, 70, & - 45, 62, 68, & - 10, 63, 67, & - 14, 66, 72, & - 22, 60, 74, & - 35, 39, 79, & - 1, 46, 64, & - 1, 24, 66, & - 2, 5, 70, & - 3, 31, 65, & - 4, 49, 58, & - 1, 4, 5, & - 6, 60, 67, & - 7, 32, 75, & - 8, 48, 82, & - 9, 35, 41, & - 10, 39, 62, & - 11, 14, 61, & - 12, 71, 74, & - 13, 23, 78, & - 11, 35, 55, & - 15, 16, 79, & - 7, 9, 16, & - 17, 54, 63, & - 18, 50, 57, & - 19, 30, 47, & - 20, 64, 80, & - 21, 28, 69, & - 22, 25, 43, & - 13, 22, 37, & - 2, 47, 51, & - 23, 54, 74, & - 26, 34, 72, & - 27, 36, 37, & - 21, 36, 63, & - 29, 40, 44, & - 19, 26, 57, & - 3, 46, 82, & - 14, 15, 58, & - 33, 52, 53, & - 30, 43, 52, & - 6, 9, 52, & - 27, 33, 65, & - 25, 69, 73, & - 38, 55, 83, & - 20, 39, 77, & - 18, 29, 56, & - 32, 48, 71, & - 42, 51, 59, & - 28, 44, 79, & - 34, 60, 62, & - 31, 45, 61, & - 46, 68, 77, & - 6, 24, 76, & - 8, 10, 78, & - 40, 41, 70, & - 17, 50, 53, & - 42, 66, 68, & - 4, 22, 72, & - 36, 64, 81, & - 13, 29, 47, & - 2, 8, 81, & - 56, 67, 73, & - 5, 38, 50, & - 12, 38, 64, & - 59, 72, 80, & - 3, 26, 79, & - 45, 76, 81, & - 1, 65, 74, & - 7, 18, 77, & - 11, 56, 59, & - 14, 39, 54, & - 16, 37, 66, & - 10, 28, 55, & - 15, 60, 70, & - 17, 25, 82, & - 20, 30, 31, & - 12, 67, 68, & - 23, 75, 80, & - 27, 32, 62, & - 24, 69, 75, & - 19, 21, 71, & - 34, 53, 61, & - 35, 46, 47, & - 33, 59, 76, & - 40, 43, 83, & - 41, 42, 63, & - 49, 75, 83, & - 20, 44, 48, & - 42, 49, 57/ - -data Nm/ & - 4, 31, 59, 91, 92, 96, 153, & - 5, 32, 60, 93, 115, 146, 0, & - 6, 24, 61, 94, 122, 151, 0, & - 7, 33, 62, 95, 96, 143, 0, & - 8, 25, 63, 83, 93, 96, 148, & - 6, 32, 64, 97, 126, 138, 0, & - 5, 34, 65, 78, 98, 107, 154, & - 9, 35, 66, 99, 139, 146, 0, & - 10, 36, 67, 100, 107, 126, 0, & - 11, 37, 67, 87, 101, 139, 158, & - 12, 38, 68, 102, 105, 155, 0, & - 13, 39, 69, 103, 149, 162, 0, & - 8, 40, 70, 82, 104, 114, 145, & - 14, 41, 71, 88, 102, 123, 156, & - 15, 42, 59, 106, 123, 159, 0, & - 1, 33, 72, 106, 107, 157, 0, & - 16, 43, 73, 108, 141, 160, 0, & - 17, 37, 74, 81, 109, 131, 154, & - 11, 44, 75, 110, 121, 166, 0, & - 45, 55, 64, 111, 130, 161, 173, & - 8, 46, 71, 112, 119, 166, 0, & - 18, 36, 76, 89, 113, 114, 143, & - 19, 38, 77, 104, 116, 163, 0, & - 20, 47, 70, 92, 138, 165, 0, & - 2, 48, 74, 113, 128, 160, 0, & - 21, 45, 78, 83, 117, 121, 151, & - 22, 47, 58, 118, 127, 164, 0, & - 16, 39, 62, 112, 134, 158, 0, & - 23, 43, 79, 120, 131, 145, 0, & - 19, 35, 59, 73, 110, 125, 161, & - 20, 36, 63, 94, 136, 161, 0, & - 14, 31, 79, 98, 132, 164, 0, & - 3, 44, 80, 124, 127, 169, 0, & - 19, 46, 81, 117, 135, 167, 0, & - 7, 49, 58, 90, 100, 105, 168, & - 12, 50, 61, 118, 119, 144, 0, & - 13, 51, 64, 114, 118, 157, 0, & - 24, 52, 76, 129, 148, 149, 0, & - 25, 53, 69, 90, 101, 130, 156, & - 20, 46, 65, 80, 120, 140, 170, & - 21, 54, 77, 100, 140, 171, 0, & - 35, 82, 133, 142, 171, 174, 0, & - 14, 30, 83, 113, 125, 170, 0, & - 4, 29, 68, 120, 134, 173, 0, & - 1, 4, 52, 57, 86, 136, 152, & - 26, 51, 56, 91, 122, 137, 168, & - 52, 84, 110, 115, 145, 168, 0, & - 7, 50, 81, 99, 132, 173, 0, & - 23, 55, 67, 95, 172, 174, 0, & - 26, 41, 77, 109, 141, 148, 0, & - 2, 27, 41, 61, 62, 115, 133, & - 27, 40, 56, 124, 125, 126, 0, & - 18, 49, 55, 124, 141, 167, 0, & - 6, 33, 85, 108, 116, 156, 0, & - 28, 48, 70, 85, 105, 129, 158, & - 9, 54, 63, 131, 147, 155, 0, & - 22, 53, 68, 109, 121, 174, 0, & - 3, 13, 48, 78, 95, 123, 0, & - 31, 69, 133, 150, 155, 169, 0, & - 12, 43, 66, 89, 97, 135, 159, & - 5, 39, 75, 102, 136, 167, 0, & - 2, 54, 86, 101, 135, 164, 0, & - 15, 56, 87, 108, 119, 171, 0, & - 10, 44, 82, 91, 111, 144, 149, & - 23, 34, 71, 94, 127, 153, 0, & - 11, 49, 88, 92, 142, 157, 0, & - 29, 34, 87, 97, 147, 162, 0, & - 30, 50, 60, 86, 137, 142, 162, & - 10, 53, 66, 84, 112, 128, 165, & - 22, 57, 85, 93, 140, 159, 0, & - 28, 32, 72, 103, 132, 166, 0, & - 28, 29, 84, 88, 117, 143, 150, & - 1, 26, 45, 80, 128, 147, 0, & - 17, 27, 89, 103, 116, 153, 0, & - 51, 57, 98, 163, 165, 172, 0, & - 21, 37, 73, 138, 152, 169, 0, & - 16, 47, 76, 130, 137, 154, 0, & - 3, 24, 30, 72, 104, 139, 0, & - 9, 40, 90, 106, 134, 151, 0, & - 15, 58, 60, 74, 111, 150, 163, & - 18, 42, 79, 144, 146, 152, 0, & - 25, 38, 65, 99, 122, 160, 0, & - 17, 42, 75, 129, 170, 172, 0/ - -data nrw/ & -7,6,6,6,7,6,7,6,6,7,6,6,7,7,6,6, & -6,7,6,7,6,7,6,6,6,7,6,6,6,7,6,6, & -6,6,7,6,6,6,7,7,6,6,6,6,7,7,6,6, & -6,6,7,6,6,6,7,6,6,6,6,7,6,6,6,7, & -6,6,6,7,7,6,6,7,6,6,6,6,6,6,6,7, & -6,6,6/ - -ncw=3 diff --git a/lib/ft8/ldpcsim174_91.f90 b/lib/ft8/ldpcsim174_91.f90 new file mode 100644 index 00000000..994b7837 --- /dev/null +++ b/lib/ft8/ldpcsim174_91.f90 @@ -0,0 +1,134 @@ +program ldpcsim174_91 +! End to end test of the (174,91)/crc14 encoder and decoder. + use packjt77 + + integer, parameter:: N=174, K=91, M=N-K + character*37 msg,msgsent,msgreceived + character*77 c77 + character*8 arg + character*6 grid + character*96 tmpchar + integer*1, allocatable :: codeword(:), decoded(:), message(:) + integer*1 msgbits(77) + integer*1 message77(77),message91(91) + integer*1 apmask(N), cw(N) + integer nerrtot(0:N),nerrdec(0:N) + logical unpk77_success + real*8, allocatable :: rxdata(:) + real, allocatable :: llr(:) + + nerrtot=0 + nerrdec=0 + + nargs=iargc() + if(nargs.ne.6) then + print*,'Usage: ldpcsim niter ndepth #trials s Keff nbposd' + print*,'eg: ldpcsim 10 2 1000 0.84 91 1' + print*,'niter: max BP iterations' + print*,'ndepth: OSD order' + print*,'s: noise sigma; if negative value is ignored and sigma is calculated from SNR.' + print*,'nbposd=0, no coupling. nbposd>0, maxsuper=nbposd; nbposd<0, no OSD' + return + endif + call getarg(1,arg) + read(arg,*) max_iterations + call getarg(2,arg) + read(arg,*) ndepth + call getarg(3,arg) + read(arg,*) ntrials + call getarg(4,arg) + 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 + 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) ) + + msg="K9ABC K1ABC FN20" + i3=0 + n3=1 + call pack77(msg,i3,n3,c77) !Pack into 12 6-bit bytes + call unpack77(c77,1,msgsent,unpk77_success) !Unpack to get msgsent + write(*,*) "message sent ",msgsent + + read(c77,'(77i1)') msgbits(1:77) + write(*,*) 'message' + write(*,'(a71,1x,a3,1x,a3)') c77(1:71),c77(72:74),c77(75:77) + + call init_random_seed() + + call encode174_91(msgbits,codeword) + write(*,*) 'crc14' + write(*,'(14i1)') codeword(78:91) + write(*,*) 'codeword' + write(*,'(22(8i1,1x))') codeword + + write(*,*) "Eb/N0 Es/N0 ngood nundetected sigma psymerr" + do idb = 10,-4,-1 + db=idb/2.0-1.0 + sigma=1/sqrt( 2*rate*(10**(db/10.0)) ) + ngood=0 + nue=0 + nsumerr=0 + + do itrial=1, ntrials +! Create a realization of a noisy received word + do i=1,N + rxdata(i) = 2.0*codeword(i)-1.0 + sigma*gran() + enddo + nerr=0 + do i=1,N + if( rxdata(i)*(2*codeword(i)-1.0) .lt. 0 ) nerr=nerr+1 + enddo + if(nerr.ge.1) nerrtot(nerr)=nerrtot(nerr)+1 + + rxav=sum(rxdata)/N + rx2av=sum(rxdata*rxdata)/N + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + if( s .lt. 0 ) then + ss=sigma + else + ss=s + endif + + llr=2.0*rxdata/(ss*ss) + nap=0 ! number of AP bits + llr(1:nap)=5*(2.0*msgbits(1:nap)-1.0) + apmask=0 + apmask(1:nap)=1 + call decode174_91(llr,Keff,nbposd,ndepth,apmask,message91,cw,ntype,nharderrors,dmin) +! If the decoder finds a valid codeword, nharderrors will be .ge. 0. + if( nharderrors.ge.0 ) then + nhw=count(cw.ne.codeword) + if(nhw.eq.0) then ! this is a good decode + ngood=ngood+1 + nerrdec(nerr)=nerrdec(nerr)+1 + else + nue=nue+1 + endif + endif + nsumerr=nsumerr+nerr + enddo + + esn0=db+10.0*log10(rate) + pberr=real(nsumerr)/(real(ntrials*N)) + write(*,"(f4.1,4x,f5.1,1x,i8,1x,i8,8x,f5.2,8x,e10.3)") db,esn0,ngood,nue,ss,pberr + + enddo + + open(unit=23,file='nerrhisto.dat',status='unknown') + do i=1,174 + write(23,'(i4,2x,i10,i10,f10.2)') i,nerrdec(i),nerrtot(i),real(nerrdec(i))/real(nerrtot(i)+1e-10) + enddo + close(23) + +end program ldpcsim174_91 diff --git a/lib/ft8/osd174_91.f90 b/lib/ft8/osd174_91.f90 index 958b0c9f..d9584f56 100644 --- a/lib/ft8/osd174_91.f90 +++ b/lib/ft8/osd174_91.f90 @@ -1,234 +1,269 @@ -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. -! -integer, parameter:: N=174, K=91, M=N-K -integer*1 apmask(N),apmaskr(N) -integer*1 gen(K,N) -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) -integer*1 r2pat(N-K) -integer indices(N),nxor(N) -integer*1 cw(N),ce(N),c0(N),hdec(N) -integer*1 decoded(K) -integer*1 message77(77) -integer indx(N) -real llr(N),rx(N),absrx(N) +! 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. +! +! If p1 (0.le.p1.le.14) is the number of CRC14 bits that are +! to be used for bad codeword detection, then the argument k should +! be set to 77+p1. +! +! Valid values for k are in the range [77,91]. +! + character*14 c14 + integer, parameter:: N=174 + integer*1 apmask(N),apmaskr(N) + integer*1, allocatable, save :: gen(:,:) + integer*1, allocatable :: genmrb(:,:),g2(:,:) + 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 -data first/.true./ -save first,gen + allocate( genmrb(k,N), g2(N,k) ) + allocate( temp(k), m0(k), me(k), mi(k), misub(k), e2sub(N-k), e2(N-k), ui(N-k) ) + allocate( r2pat(N-k), decoded(k) ) -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 - irow=(j-1)*4+jj - if( btest(istr,4-jj) ) gen(irow,K+i)=1 + 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 + do i=1,k + message91=0 + message91(i)=1 + if(i.le.77) then + m96=0 + m96(1:91)=message91 + call get_crc14(m96,96,ncrc14) + 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 - do irow=1,K - gen(irow,irow)=1 - enddo -first=.false. -endif -rx=llr -apmaskr=apmask + first=.false. + endif + + rx=llr + apmaskr=apmask ! Hard decisions on the received word. -hdec=0 -where(rx .ge. 0) hdec=1 + 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) + absrx=abs(rx) + call indexx(absrx,N,indx) ! Re-order the columns of the generator matrix in order of decreasing reliability. -do i=1,N - genmrb(1:K,i)=gen(1:K,indx(N+1-i)) - indices(i)=indx(N+1-i) -enddo + do i=1,N + genmrb(1:k,i)=gen(1:k,indx(N+1-i)) + indices(i)=indx(N+1-i) + enddo ! 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). -do id=1,K ! diagonal element indices - do icol=id,K+20 ! The 20 is ad hoc - beware - iflag=0 - if( genmrb(id,icol) .eq. 1 ) then - iflag=1 - if( icol .ne. id ) then ! reorder column - temp(1:K)=genmrb(1:K,id) - genmrb(1:K,id)=genmrb(1:K,icol) - genmrb(1:K,icol)=temp(1:K) - itmp=indices(id) - indices(id)=indices(icol) - indices(icol)=itmp - endif - do ii=1,K - if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then - genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) - endif +! received bits in positions 1:k in order of decreasing reliability (more or less). + do id=1,k ! diagonal element indices + do icol=id,k+20 ! The 20 is ad hoc - beware + iflag=0 + if( genmrb(id,icol) .eq. 1 ) then + iflag=1 + if( icol .ne. id ) then ! reorder column + temp(1:k)=genmrb(1:k,id) + genmrb(1:k,id)=genmrb(1:k,icol) + genmrb(1:k,icol)=temp(1:k) + itmp=indices(id) + indices(id)=indices(icol) + indices(icol)=itmp + endif + do ii=1,k + if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then + genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N)) + endif + enddo + exit + endif enddo - exit - endif - enddo -enddo + enddo -g2=transpose(genmrb) + g2=transpose(genmrb) -! 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. +! 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. Return the member of the list that has the smallest Euclidean -! distance to the received word. - -hdec=hdec(indices) ! hard decisions from received symbols -m0=hdec(1:K) ! zero'th order message -absrx=absrx(indices) -rx=rx(indices) -apmaskr=apmaskr(indices) +! distance to the received word. -call mrbencode91(m0,c0,g2,N,K) -nxor=ieor(c0,hdec) -nhardmin=sum(nxor) -dmin=sum(nxor*absrx) + hdec=hdec(indices) ! hard decisions from received symbols + m0=hdec(1:k) ! zero'th order message + absrx=absrx(indices) + rx=rx(indices) + apmaskr=apmaskr(indices) -cw=c0 -ntotal=0 -nrejected=0 + call mrbencode91(m0,c0,g2,N,k) + nxor=ieor(c0,hdec) + nhardmin=sum(nxor) + dmin=sum(nxor*absrx) -if(ndeep.eq.0) goto 998 ! norder=0 -if(ndeep.gt.5) ndeep=5 -if( ndeep.eq. 1) then - nord=1 + cw=c0 + ntotal=0 + nrejected=0 npre1=0 npre2=0 - nt=40 - ntheta=12 -elseif(ndeep.eq.2) then - nord=1 - npre1=1 - npre2=0 - nt=40 - ntheta=12 -elseif(ndeep.eq.3) then - nord=1 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=14 -elseif(ndeep.eq.4) then - nord=2 - npre1=1 - npre2=0 - nt=40 - ntheta=12 - ntau=19 -elseif(ndeep.eq.5) then - nord=2 - npre1=1 - npre2=1 - nt=40 - ntheta=12 - ntau=19 -endif -do iorder=1,nord - misub(1:K-iorder)=0 - misub(K-iorder+1:K)=1 - iflag=K-iorder+1 - do while(iflag .ge.0) - if(iorder.eq.nord .and. npre1.eq.0) then - iend=iflag - else - iend=1 - endif - do n1=iflag,iend,-1 - mi=misub - mi(n1)=1 - if(any(iand(apmaskr(1:K),mi).eq.1)) cycle - ntotal=ntotal+1 - me=ieor(m0,mi) - if(n1.eq.iflag) then - call mrbencode91(me,ce,g2,N,K) - e2sub=ieor(ce(K+1:N),hdec(K+1:N)) - e2=e2sub - nd1Kpt=sum(e2sub(1:nt))+1 - d1=sum(ieor(me(1:K),hdec(1:K))*absrx(1:K)) + if(ndeep.eq.0) goto 998 ! norder=0 + if(ndeep.gt.6) ndeep=6 + if( ndeep.eq. 1) then + nord=1 + npre1=0 + npre2=0 + nt=40 + ntheta=12 + elseif(ndeep.eq.2) then + nord=1 + npre1=1 + npre2=0 + nt=40 +! ntheta=12 + ntheta=10 + elseif(ndeep.eq.3) then + nord=1 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=14 + elseif(ndeep.eq.4) then + nord=2 + npre1=1 + npre2=1 + nt=40 + ntheta=12 + ntau=17 + 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 + misub(1:k-iorder)=0 + misub(k-iorder+1:k)=1 + iflag=k-iorder+1 + do while(iflag .ge.0) + if(iorder.eq.nord .and. npre1.eq.0) then + iend=iflag else - e2=ieor(e2sub,g2(K+1:N,n1)) - nd1Kpt=sum(e2(1:nt))+2 + iend=1 endif - if(nd1Kpt .le. ntheta) then - call mrbencode91(me,ce,g2,N,K) - nxor=ieor(ce,hdec) + d1=0. + do n1=iflag,iend,-1 + mi=misub + mi(n1)=1 + if(any(iand(apmaskr(1:k),mi).eq.1)) cycle + ntotal=ntotal+1 + me=ieor(m0,mi) if(n1.eq.iflag) then - dd=d1+sum(e2sub*absrx(K+1:N)) + call mrbencode91(me,ce,g2,N,k) + e2sub=ieor(ce(k+1:N),hdec(k+1:N)) + e2=e2sub + nd1kpt=sum(e2sub(1:nt))+1 + d1=sum(ieor(me(1:k),hdec(1:k))*absrx(1:k)) else - dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(K+1:N)) + e2=ieor(e2sub,g2(k+1:N,n1)) + nd1kpt=sum(e2(1:nt))+2 endif - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - nd1Kptbest=nd1Kpt + if(nd1kpt .le. ntheta) then + call mrbencode91(me,ce,g2,N,k) + nxor=ieor(ce,hdec) + if(n1.eq.iflag) then + dd=d1+sum(e2sub*absrx(k+1:N)) + else + dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(k+1:N)) + endif + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + nd1kptbest=nd1kpt + endif + else + nrejected=nrejected+1 endif - else - nrejected=nrejected+1 - endif - enddo + enddo ! Get the next test error pattern, iflag will go negative ! 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 -if(npre2.eq.1) then - reset=.true. - ntotal=0 - do i1=K,1,-1 - do i2=i1-1,1,-1 - ntotal=ntotal+1 - 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) + if(npre2.eq.1) then + reset=.true. + ntotal=0 + do i1=k,1,-1 + do i2=i1-1,1,-1 + ntotal=ntotal+1 + 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) + enddo enddo - enddo - ncount2=0 - ntotal2=0 - reset=.true. + ncount2=0 + ntotal2=0 + reset=.true. ! Now run through again and do the second pre-processing rule - misub(1:K-nord)=0 - misub(K-nord+1:K)=1 - iflag=K-nord+1 - do while(iflag .ge.0) - me=ieor(m0,misub) - call mrbencode91(me,ce,g2,N,K) - e2sub=ieor(ce(K+1:N),hdec(K+1:N)) - do i2=0,ntau - ntotal2=ntotal2+1 - ui=0 - if(i2.gt.0) ui(i2)=1 - r2pat=ieor(e2sub,ui) -778 continue + misub(1:k-nord)=0 + misub(k-nord+1:k)=1 + iflag=k-nord+1 + do while(iflag .ge.0) + me=ieor(m0,misub) + call mrbencode91(me,ce,g2,N,k) + e2sub=ieor(ce(k+1:N),hdec(k+1:N)) + do i2=0,ntau + ntotal2=ntotal2+1 + ui=0 + if(i2.gt.0) ui(i2)=1 + r2pat=ieor(e2sub,ui) +778 continue call fetchit91(reset,r2pat(1:ntau),ntau,in1,in2) if(in1.gt.0.and.in2.gt.0) then ncount2=ncount2+1 - mi=misub + mi=misub mi(in1)=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) - call mrbencode91(me,ce,g2,N,K) + call mrbencode91(me,ce,g2,N,k) nxor=ieor(ce,hdec) dd=sum(nxor*absrx) if( dd .lt. dmin ) then @@ -237,136 +272,138 @@ if(npre2.eq.1) then nhardmin=sum(nxor) endif goto 778 - endif + endif + enddo + call nextpat91(misub,k,nord,iflag) enddo - call nextpat91(misub,K,nord,iflag) - enddo -endif + endif 998 continue -! Re-order the codeword to [message bits][parity bits] format. -cw(indices)=cw -hdec(indices)=hdec -decoded=cw(1:K) -call chkcrc14a(decoded,nbadcrc) -message77=decoded(1:77) -if(nbadcrc.eq.1) nhardmin=-nhardmin +! Re-order the codeword to [message bits][parity bits] format. + cw(indices)=cw + hdec(indices)=hdec + message91=cw(1:91) + m96=0 + m96(1:77)=cw(1:77) + m96(83:96)=cw(78:91) + call get_crc14(m96,96,nbadcrc) + if(nbadcrc.ne.0) nhardmin=-nhardmin -return + return end subroutine osd174_91 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 - codeword=0 - do i=1,K - if( me(i) .eq. 1 ) then - codeword=ieor(codeword,g2(1:N,i)) - endif - enddo -return + codeword=0 + do i=1,K + if( me(i) .eq. 1 ) then + codeword=ieor(codeword,g2(1:N,i)) + endif + enddo + return end subroutine mrbencode91 subroutine nextpat91(mi,k,iorder,iflag) - integer*1 mi(k),ms(k) + integer*1 mi(k),ms(k) ! generate the next test error pattern - ind=-1 - do i=1,k-1 - if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i - enddo - if( ind .lt. 0 ) then ! no more patterns of this order - iflag=ind - return - endif - ms=0 - ms(1:ind-1)=mi(1:ind-1) - ms(ind)=1 - ms(ind+1)=0 - if( ind+1 .lt. k ) then - nz=iorder-sum(ms) - ms(k-nz+1:k)=1 - endif - mi=ms - do i=1,k ! iflag will point to the lowest-index 1 in mi - if(mi(i).eq.1) then - iflag=i - exit - endif - enddo - return + ind=-1 + do i=1,k-1 + if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i + enddo + if( ind .lt. 0 ) then ! no more patterns of this order + iflag=ind + return + endif + ms=0 + ms(1:ind-1)=mi(1:ind-1) + ms(ind)=1 + ms(ind+1)=0 + if( ind+1 .lt. k ) then + nz=iorder-sum(ms) + ms(k-nz+1:k)=1 + endif + mi=ms + do i=1,k ! iflag will point to the lowest-index 1 in mi + if(mi(i).eq.1) then + iflag=i + exit + endif + enddo + return end subroutine nextpat91 subroutine boxit91(reset,e2,ntau,npindex,i1,i2) - integer*1 e2(1:ntau) - integer indexes(5000,2),fp(0:525000),np(5000) - logical reset - common/boxes/indexes,fp,np + integer*1 e2(1:ntau) + integer indexes(5000,2),fp(0:525000),np(5000) + logical reset + common/boxes/indexes,fp,np + + if(reset) then + patterns=-1 + fp=-1 + np=-1 + sc=-1 + indexes=-1 + reset=.false. + endif - if(reset) then - patterns=-1 - fp=-1 - np=-1 - sc=-1 - indexes=-1 - reset=.false. - endif - - indexes(npindex,1)=i1 - indexes(npindex,2)=i2 - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo + indexes(npindex,1)=i1 + indexes(npindex,2)=i2 + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo - ip=fp(ipat) ! see what's currently stored in fp(ipat) - if(ip.eq.-1) then - fp(ipat)=npindex - else - do while (np(ip).ne.-1) - ip=np(ip) - enddo - np(ip)=npindex - endif - return + ip=fp(ipat) ! see what's currently stored in fp(ipat) + if(ip.eq.-1) then + fp(ipat)=npindex + else + do while (np(ip).ne.-1) + ip=np(ip) + enddo + np(ip)=npindex + endif + return end subroutine boxit91 subroutine fetchit91(reset,e2,ntau,i1,i2) - integer indexes(5000,2),fp(0:525000),np(5000) - integer lastpat - integer*1 e2(ntau) - logical reset - common/boxes/indexes,fp,np - save lastpat,inext + integer indexes(5000,2),fp(0:525000),np(5000) + integer lastpat + integer*1 e2(ntau) + logical reset + common/boxes/indexes,fp,np + save lastpat,inext - if(reset) then - lastpat=-1 - reset=.false. - endif + if(reset) then + lastpat=-1 + reset=.false. + endif - ipat=0 - do i=1,ntau - if(e2(i).eq.1) then - ipat=ipat+ishft(1,ntau-i) - endif - enddo - index=fp(ipat) + ipat=0 + do i=1,ntau + if(e2(i).eq.1) then + ipat=ipat+ishft(1,ntau-i) + endif + enddo + index=fp(ipat) - if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices - i1=indexes(index,1) - i2=indexes(index,2) - inext=np(index) - elseif(lastpat.eq.ipat .and. inext.gt.0) then - i1=indexes(inext,1) - i2=indexes(inext,2) - inext=np(inext) - else - i1=-1 - i2=-1 - inext=-1 - endif - lastpat=ipat - return + if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices + i1=indexes(index,1) + i2=indexes(index,2) + inext=np(index) + elseif(lastpat.eq.ipat .and. inext.gt.0) then + i1=indexes(inext,1) + i2=indexes(inext,2) + inext=np(inext) + else + i1=-1 + i2=-1 + inext=-1 + endif + lastpat=ipat + return end subroutine fetchit91 - + diff --git a/lib/ft8/subtractft8.f90 b/lib/ft8/subtractft8.f90 index ec0beea9..7c3b5908 100644 --- a/lib/ft8/subtractft8.f90 +++ b/lib/ft8/subtractft8.f90 @@ -1,4 +1,4 @@ -subroutine subtractft8(dd,itone,f0,dt) +subroutine subtractft8(dd0,itone,f0,dt,lrefinedt) ! Subtract an ft8 signal ! @@ -7,60 +7,98 @@ subroutine subtractft8(dd,itone,f0,dt) ! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ] ! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt} - use timer_module, only: timer - parameter (NMAX=15*12000,NFRAME=1920*79) - parameter (NFFT=NMAX,NFILT=1400) - real*4 dd(NMAX), window(-NFILT/2:NFILT/2), xjunk - complex cref,camp,cfilt,cw + parameter (NFFT=NMAX,NFILT=4000) + real dd(NMAX),dd0(NMAX) + real window(-NFILT/2:NFILT/2) + real x(NFFT+2) + real endcorrection(NFILT/2+1) + complex cx(0:NFFT/2) + complex cref,camp,cfilt,cw,z integer itone(79) - logical first + logical first,lrefinedt,ldt data first/.true./ - common/heap8/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX),xjunk(NFRAME) - save first - - nstart=dt*12000+1 - nsym=79 - nsps=1920 - fs=12000.0 - icmplx=1 - bt=2.0 - call gen_ft8wave(itone,nsym,nsps,bt,fs,f0,cref,xjunk,icmplx,NFRAME) - camp=0. - do i=1,nframe - id=nstart-1+i - if(id.ge.1.and.id.le.NMAX) camp(i)=dd(id)*conjg(cref(i)) - enddo + common/heap8/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX) + equivalence (x,cx) + save first,/heap8/,endcorrection - if(first) then -! Create and normalize the filter + if(first) then ! Create and normalize the filter pi=4.0*atan(1.0) fac=1.0/float(nfft) - sum=0.0 + sumw=0.0 do j=-NFILT/2,NFILT/2 window(j)=cos(pi*j/NFILT)**2 - sum=sum+window(j) + sumw=sumw+window(j) enddo cw=0. - cw(1:NFILT+1)=window/sum + cw(1:NFILT+1)=window/sumw cw=cshift(cw,NFILT/2+1) call four2a(cw,nfft,1,-1,1) cw=cw*fac first=.false. + do j=1,NFILT/2+1 + endcorrection(j)=1.0/(1.0-sum(window(j-1:NFILT/2))/sumw) + enddo endif - cfilt=0.0 - cfilt(1:nframe)=camp(1:nframe) - call four2a(cfilt,nfft,1,-1,1) - cfilt(1:nfft)=cfilt(1:nfft)*cw(1:nfft) - call four2a(cfilt,nfft,1,1,1) - -! Subtract the reconstructed signal - do i=1,nframe - j=nstart+i-1 - if(j.ge.1 .and. j.le.NMAX) dd(j)=dd(j)-2*REAL(cfilt(i)*cref(i)) - enddo +! Generate complex reference waveform cref + call gen_ft8wave(itone,79,1920,2.0,12000.0,f0,cref,xjunk,1,NFRAME) + ldt=lrefinedt + if(ldt) then !Are we refining DT ? + sqa=sqf(-90) + sqb=sqf(+90) + sq0=sqf(0) + call peakup(sqa,sq0,sqb,dx) + if(abs(dx).gt.1.0) return !No acceptable minimum: do not subtract + i2=nint(90.0*dx) !Best estimate of idt + ldt=.false. + sq0=sqf(i2) !Do the subtraction with idt=i2 + else + sq0=sqf(0) !Do the subtraction with idt=0 + endif + dd0=dd !Return dd0 with this signal subtracted return -end subroutine subtractft8 +contains + + real function sqf(idt) !Internal function: all variables accessible + nstart=dt*12000+1 + idt + camp=0. + dd=dd0 + do i=1,nframe + j=nstart-1+i + if(j.ge.1.and.j.le.NMAX) camp(i)=dd(j)*conjg(cref(i)) + enddo + + cfilt(1:nframe)=camp(1:nframe) + cfilt(nframe+1:)=0.0 + call four2a(cfilt,nfft,1,-1,1) + cfilt(1:nfft)=cfilt(1:nfft)*cw(1:nfft) + call four2a(cfilt,nfft,1,1,1) + cfilt(1:NFILT/2+1)=cfilt(1:NFILT/2+1)*endcorrection + cfilt(nframe:nframe-NFILT/2:-1)=cfilt(nframe:nframe-NFILT/2:-1)*endcorrection + x=0. + do i=1,nframe + j=nstart+i-1 + if(j.ge.1 .and. j.le.NMAX) then + z=cfilt(i)*cref(i) + dd(j)=dd(j)-2.0*real(z) !Subtract the reconstructed signal + x(i)=dd(j) + endif + enddo + sqq=0. + if(ldt) then + call four2a(cx,NFFT,1,-1,0) !Forward FFT, r2c + df=12000.0/NFFT + ia=(f0-1.5*6.25)/df + ib=(f0+8.5*6.25)/df + do i=ia,ib + sqq=sqq + real(cx(i))*real(cx(i)) + aimag(cx(i))*aimag(cx(i)) + enddo + endif + sqf=sqq + return + end function sqf + +end subroutine subtractft8 diff --git a/lib/ft8/sync8.f90 b/lib/ft8/sync8.f90 index 219c6ebf..5ea2254a 100644 --- a/lib/ft8/sync8.f90 +++ b/lib/ft8/sync8.f90 @@ -2,6 +2,7 @@ subroutine sync8(dd,nfa,nfb,syncmin,nfqso,maxcand,s,candidate, & ncand,sbase)
include 'ft8_params.f90'
+ parameter (MAXPRECAND=500)
! Search over +/- 2.5s relative to 0.5s TX start time.
parameter (JZ=62)
complex cx(0:NH1)
@@ -11,7 +12,7 @@ subroutine sync8(dd,nfa,nfb,syncmin,nfqso,maxcand,s,candidate, & real x(NFFT1)
real sync2d(NH1,-JZ:JZ)
real red(NH1)
- real candidate0(3,maxcand)
+ real candidate0(3,MAXPRECAND)
real candidate(3,maxcand)
real dd(NMAX)
integer jpeak(NH1)
@@ -37,7 +38,7 @@ subroutine sync8(dd,nfa,nfb,syncmin,nfqso,maxcand,s,candidate, & enddo
savg=savg + s(1:NH1,j) !Average spectrum
enddo
- call baseline(savg,nfa,nfb,sbase)
+ call get_spectrum_baseline(dd,nfa,nfb,sbase)
ia=max(1,nint(nfa/df))
ib=nint(nfb/df)
@@ -100,19 +101,18 @@ subroutine sync8(dd,nfa,nfb,syncmin,nfqso,maxcand,s,candidate, & base=red(ibase)
red=red/base
- do i=1,min(maxcand,iz)
+ do i=1,min(MAXPRECAND,iz)
n=ia + indx(iz+1-i) - 1
- if(red(n).lt.syncmin.or.isnan(red(n)).or.k.eq.maxcand) exit
+ if(red(n).lt.syncmin.or.isnan(red(n)).or.k.eq.MAXPRECAND) exit
k=k+1
candidate0(1,k)=n*df
- candidate0(2,k)=(jpeak(n)-1)*tstep
+ candidate0(2,k)=(jpeak(n)-0.5)*tstep
candidate0(3,k)=red(n)
enddo
ncand=k
-! Put nfqso at top of list, and save only the best of near-dupe freqs.
+! Save only the best of near-dupe freqs.
do i=1,ncand
- if(abs(candidate0(1,i)-nfqso).lt.10.0) candidate0(1,i)=-candidate0(1,i)
if(i.ge.2) then
do j=1,i-1
fdiff=abs(candidate0(1,i))-abs(candidate0(1,j))
@@ -123,25 +123,31 @@ subroutine sync8(dd,nfa,nfb,syncmin,nfqso,maxcand,s,candidate, & enddo
endif
enddo
-
fac=20.0/maxval(s)
s=fac*s
! Sort by sync
-! call indexx(candidate0(3,1:ncand),ncand,indx)
-! Sort by frequency
- call indexx(candidate0(1,1:ncand),ncand,indx)
+ call indexx(candidate0(3,1:ncand),ncand,indx)
+! Place candidates within 10 Hz of nfqso at the top of the list
k=1
-! do i=ncand,1,-1
do i=1,ncand
+ if( abs( candidate0(1,i)-nfqso ).le.10.0 .and. candidate0(3,i).ge.syncmin ) then
+ candidate(1:3,k)=candidate0(1:3,i)
+ candidate0(3,i)=0.0
+ k=k+1
+ endif
+ enddo
+
+ do i=ncand,1,-1
j=indx(i)
-! if( candidate0(3,j) .ge. syncmin .and. candidate0(2,j).ge.-1.5 ) then
if( candidate0(3,j) .ge. syncmin ) then
candidate(2:3,k)=candidate0(2:3,j)
candidate(1,k)=abs(candidate0(1,j))
k=k+1
+ if(k.gt.maxcand) exit
endif
enddo
ncand=k-1
+
return
end subroutine sync8
diff --git a/lib/ft8/sync8d.f90 b/lib/ft8/sync8d.f90 index 798f2831..556acead 100644 --- a/lib/ft8/sync8d.f90 +++ b/lib/ft8/sync8d.f90 @@ -12,20 +12,16 @@ subroutine sync8d(cd0,i0,ctwk,itwk,sync) integer icos7(0:6)
data icos7/3,1,4,0,6,5,2/
data first/.true./
- save first,twopi,fs2,dt2,taus,baud,csync
+ save first,twopi,csync
p(z1)=real(z1)**2 + aimag(z1)**2 !Statement function for power
! Set some constants and compute the csync array.
if( first ) then
twopi=8.0*atan(1.0)
- fs2=12000.0/NDOWN !Sample rate after downsampling
- dt2=1/fs2 !Corresponding sample interval
- taus=32*dt2 !Symbol duration
- baud=1.0/taus !Keying rate
do i=0,6
phi=0.0
- dphi=twopi*icos7(i)*baud*dt2
+ dphi=twopi*icos7(i)/32.0
do j=1,32
csync(i,j)=cmplx(cos(phi),sin(phi)) !Waveform for 7x7 Costas array
phi=mod(phi+dphi,twopi)
|
