From 992d4b4b8d3f3a630a2cf00d593ee4ce4dfa7ce8 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Thu, 9 Jan 2025 22:12:06 +0100 Subject: New upstream version 2.7.0~rc8+repack --- lib/ft8/bpdecode174_91.f90 | 234 ++++---- lib/ft8/chkcrc13a.f90 | 48 +- lib/ft8/chkcrc14a.f90 | 48 +- lib/ft8/chkdec.f90 | 322 +++++------ lib/ft8/decode174_91.f90 | 310 +++++------ lib/ft8/encode174.f90 | 100 ++-- lib/ft8/encode174_91.f90 | 116 ++-- lib/ft8/encode174_91_nocrc.f90 | 94 ++-- lib/ft8/ft8_a7.f90 | 756 +++++++++++++------------- lib/ft8/ft8_testmsg.f90 | 102 ++-- lib/ft8/ft8apset.f90 | 124 ++--- lib/ft8/ft8b.f90 | 1006 +++++++++++++++++------------------ lib/ft8/ft8c.f90 | 522 +++++++++--------- lib/ft8/ft8code.f90 | 210 ++++---- lib/ft8/ft8d.f90 | 126 ++--- lib/ft8/ft8q3.f90 | 218 ++++---- lib/ft8/ft8sim.f90 | 282 +++++----- lib/ft8/gen_ft8wave.f90 | 166 +++--- lib/ft8/genft8.f90 | 92 ++-- lib/ft8/genft8refsig.f90 | 46 +- lib/ft8/get_crc14.f90 | 50 +- lib/ft8/ldpc_174_87_params.f90 | 204 +++---- lib/ft8/ldpc_174_91_c_colorder.f90 | 22 +- lib/ft8/ldpc_174_91_c_generator.f90 | 172 +++--- lib/ft8/ldpc_174_91_c_parity.f90 | 540 +++++++++---------- lib/ft8/ldpcsim174_91.f90 | 538 +++++++++---------- lib/ft8/osd174_91.f90 | 818 ++++++++++++++-------------- lib/ft8/subtractft8.f90 | 212 ++++---- lib/ft8/test_ft8q3.f90 | 82 +-- 29 files changed, 3780 insertions(+), 3780 deletions(-) (limited to 'lib/ft8') diff --git a/lib/ft8/bpdecode174_91.f90 b/lib/ft8/bpdecode174_91.f90 index ae1cb9da..a7c6f95b 100755 --- a/lib/ft8/bpdecode174_91.f90 +++ b/lib/ft8/bpdecode174_91.f90 @@ -1,117 +1,117 @@ -subroutine bpdecode174_91(llr,apmask,maxiterations,message77,cw,nharderror,iter,ncheck) -! -! A log-domain belief propagation decoder for the (174,91) code. -! -use iso_c_binding, only: c_loc,c_size_t -use crc -integer, parameter:: N=174, K=91, M=N-K -integer*1 cw(N),apmask(N) -integer*1 decoded(K) -integer*1 message77(77) -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) -real llr(N) -real Tmn - -include "ldpc_174_91_c_parity.f90" - -decoded=0 -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 - -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 - -! 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 -! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied' - enddo -! write(*,*) 'number of unsatisfied parity checks ',ncheck - if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it - decoded=cw(1:K) - call chkcrc14a(decoded,nbadcrc) - nharderror=count( (2*cw-1)*llr .lt. 0.0 ) - if(nbadcrc.eq.0) then - message77=decoded(1:77) - 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 - - return - 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 -nharderror=-1 -return -end subroutine bpdecode174_91 +subroutine bpdecode174_91(llr,apmask,maxiterations,message77,cw,nharderror,iter,ncheck) +! +! A log-domain belief propagation decoder for the (174,91) code. +! +use iso_c_binding, only: c_loc,c_size_t +use crc +integer, parameter:: N=174, K=91, M=N-K +integer*1 cw(N),apmask(N) +integer*1 decoded(K) +integer*1 message77(77) +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) +real llr(N) +real Tmn + +include "ldpc_174_91_c_parity.f90" + +decoded=0 +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 + +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 + +! 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 +! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied' + enddo +! write(*,*) 'number of unsatisfied parity checks ',ncheck + if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it + decoded=cw(1:K) + call chkcrc14a(decoded,nbadcrc) + nharderror=count( (2*cw-1)*llr .lt. 0.0 ) + if(nbadcrc.eq.0) then + message77=decoded(1:77) + 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 + + return + 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 +nharderror=-1 +return +end subroutine bpdecode174_91 diff --git a/lib/ft8/chkcrc13a.f90 b/lib/ft8/chkcrc13a.f90 index e35a92a1..25e14584 100755 --- a/lib/ft8/chkcrc13a.f90 +++ b/lib/ft8/chkcrc13a.f90 @@ -1,24 +1,24 @@ -subroutine chkcrc13a(decoded,nbadcrc) - - use crc - integer*1 decoded(90) - integer*1, target:: i1Dec8BitBytes(12) - character*90 cbits - -! Write decoded bits into cbits: 77-bit message plus 13-bit CRC - write(cbits,1000) decoded -1000 format(90i1) - read(cbits,1001) i1Dec8BitBytes -1001 format(12b8) - read(cbits,1002) ncrc13 !Received CRC13 -1002 format(77x,b13) - - i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),transfer(128+64+32+16+8,0_1)) - i1Dec8BitBytes(11:12)=0 - icrc13=crc13(c_loc(i1Dec8BitBytes),12) !CRC13 computed from 77 msg bits - - nbadcrc=1 - if(ncrc13.eq.icrc13) nbadcrc=0 - - return -end subroutine chkcrc13a +subroutine chkcrc13a(decoded,nbadcrc) + + use crc + integer*1 decoded(90) + integer*1, target:: i1Dec8BitBytes(12) + character*90 cbits + +! Write decoded bits into cbits: 77-bit message plus 13-bit CRC + write(cbits,1000) decoded +1000 format(90i1) + read(cbits,1001) i1Dec8BitBytes +1001 format(12b8) + read(cbits,1002) ncrc13 !Received CRC13 +1002 format(77x,b13) + + i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),transfer(128+64+32+16+8,0_1)) + i1Dec8BitBytes(11:12)=0 + icrc13=crc13(c_loc(i1Dec8BitBytes),12) !CRC13 computed from 77 msg bits + + nbadcrc=1 + if(ncrc13.eq.icrc13) nbadcrc=0 + + return +end subroutine chkcrc13a diff --git a/lib/ft8/chkcrc14a.f90 b/lib/ft8/chkcrc14a.f90 index 75eac39f..9ecda9b2 100755 --- a/lib/ft8/chkcrc14a.f90 +++ b/lib/ft8/chkcrc14a.f90 @@ -1,24 +1,24 @@ -subroutine chkcrc14a(decoded,nbadcrc) - - use crc - integer*1 decoded(91) - integer*1, target:: i1Dec8BitBytes(12) - character*91 cbits - -! 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 CRC14 -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) !CRC14 computed from 77 msg bits - - nbadcrc=1 - if(ncrc14.eq.icrc14) nbadcrc=0 - - return -end subroutine chkcrc14a +subroutine chkcrc14a(decoded,nbadcrc) + + use crc + integer*1 decoded(91) + integer*1, target:: i1Dec8BitBytes(12) + character*91 cbits + +! 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 CRC14 +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) !CRC14 computed from 77 msg bits + + nbadcrc=1 + if(ncrc14.eq.icrc14) nbadcrc=0 + + return +end subroutine chkcrc14a diff --git a/lib/ft8/chkdec.f90 b/lib/ft8/chkdec.f90 index ddd9cf7f..7a5e7618 100755 --- a/lib/ft8/chkdec.f90 +++ b/lib/ft8/chkdec.f90 @@ -1,161 +1,161 @@ -program chkdec - - parameter(NMAX=100) - character*88 line - character*37 msg(NMAX),msg0,msg1 - character*2 c2(NMAX) - character*1 c1(NMAX) - character*1 only - integer nsnr(NMAX,0:1),nf(NMAX,0:1) - real dt(NMAX,0:1) - logical found,eof - -! These files are sorted by freq within each Rx sequence - open(10,file='all.wsjtx',status='old') - open(11,file='all.jtdx',status='old') - write(20,1030) -1030 format(' iseq B w j W W+ J E B w j W', & - ' W+ J E'/80('-')) - - nutc0=-1 - nbt=0 !Both - nwt=0 !WSJT-X only - njt=0 !JTDX only - net=0 !Either - n7t=0 !a7 - eof=.false. - - do iseq=1,9999 - j=0 - msg=' ' - nsnr=-99 - nf=-99 - dt=-99 - c1=' ' - c2=' ' - do i=1,NMAX - read(10,'(a88)',end=8) line !Read from the WSJT-X file - if(line(25:30).ne.'Rx FT8') cycle !Ignore any line not an FT8 decode - read(line(8:13),*) nutc - if(nutc0.lt.0) nutc0=nutc !First time only - if(nutc.ne.nutc0) then - backspace(10) - go to 10 !Finished WSJT-X for this sequence - endif - j=j+1 - if(j.eq.1) then - nf(j,0)=-1 - j=j+1 - endif - read(line,1001) nsnr(j,0),dt(j,0),nf(j,0),msg(j),c2(j) -1001 format(30x,i7,f5.1,i5,1x,a36,2x,a2) -! if(nutc.eq.180215 .and. c2(j).eq.'a7') print*,'aaa',j,nf(j,0),c2(j) - nutc0=nutc - enddo ! i - -8 eof=.true. -10 jz=j - do i=1,NMAX - read(11,'(a88)',end=20) line !Read from the JTDX file - if(line(31:31).ne.'~') cycle !Ignore any line not an FT8 decode - read(line(10:15),*) nutc - if(nutc.ne.nutc0) then - backspace(11) - go to 20 !Finished JTDX for this sequence - endif - msg1=line(33:58) - read(line(25:29),*) nf1 - found=.false. - do j=1,jz - if(msg(j).eq.msg1) then - read(line,1002) nsnr(j,1),dt(j,1),nf(j,1),c1(j) -1002 format(15x,i4,f5.1,i5,29x,a1) - found=.true. - exit - endif - i1=index(msg(j),'<') - if(i1.gt.0) then - i2=index(msg(j),'>') - msg0=msg(j)(1:i1-1)//msg(j)(i1+1:i2-1)//msg(j)(i2+1:) - if(msg0.eq.msg1) then - read(line,1002) nsnr(j,1),dt(j,1),nf(j,1),c1(j) - found=.true. - exit - endif - endif - enddo ! j - - if(.not.found) then !Insert this one as a new message - do j=1,jz - if(nf1.ge.nf(j,0) .and. nf1.lt.nf(j+1,0)) then - jj=j+1 - exit - endif - enddo - do j=jz+1,jj+1,-1 - nsnr(j,0)=nsnr(j-1,0) - dt(j,0)=dt(j-1,0) - nf(j,0)=nf(j-1,0) - msg(j)=msg(j-1) - c1(j)=c1(j-1) - c2(j)=c2(j-1) - enddo ! j - read(line,1004) nsnr(jj,1),dt(jj,1),nf(jj,1),msg(jj),c1(jj) -1004 format(15x,i4,f5.1,i5,3x,a26,a1) - c2(jj)=' ' - nsnr(jj,0)=-99 - dt(jj,0)=-99.0 - nf(jj,0)=-99 - jz=jz+1 - endif - enddo ! i - -20 nb=0 - nw=0 - nj=0 - ne=0 - n7=0 - do j=2,jz - write(line,1020) nutc0,j,nsnr(j,:),dt(j,:),nf(j,:),msg(j)(1:26), & - c2(j),c1(j) -1020 format(i6.6,i3,1x,2i4,1x,2f6.1,1x,2i5,1x,a26,1x,a2,1x,a1) - if(c2(j).eq.'a7') n7=n7+1 - only=' ' - if(line(12:14).eq.'-99') then - line(12:14)=' ' - only='j' - nj=nj+1 -! if(c2(j).eq.'a7') print*,'aaa ',trim(line) - endif - if(line(16:18).eq.'-99') then - line(16:18)=' ' - only='w' - nw=nw+1 - endif - if(line(12:14).ne.' ' .or. line(16:19).ne.' ') ne=ne+1 - if(line(12:14).ne.' ' .and. line(16:19).ne.' ') nb=nb+1 - if(line(21:25).eq.'-99.0') line(21:25)=' ' - if(line(27:31).eq.'-99.0') line(27:31)=' ' - if(line(35:37).eq.'-99') line(35:37)=' ' - if(line(40:42).eq.'-99') line(40:42)=' ' -! if(line(12:14).ne.' ') nw=nw+1 -! if(line(16:18).ne.' ') nj=nj+1 - write(*,'(a74,1x,a1)') line(1:74),only - enddo ! j - - nbt=nbt+nb - nwt=nwt+nw - n7t=n7t+n7 - njt=njt+nj - net=net+ne - nutc0=nutc - write(*,*) - - write(20,1031) iseq,nb,nw,nj,nb+nw-n7,nb+nw,nb+nj,ne,nbt,nwt,njt, & - nbt+nwt-n7t,nbt+nwt,nbt+njt,net -1031 format(i5,2x,7i4,2x,7i6) - if(eof) exit -! if(iseq.eq.2) exit - enddo ! iseq - -end program chkdec +program chkdec + + parameter(NMAX=100) + character*88 line + character*37 msg(NMAX),msg0,msg1 + character*2 c2(NMAX) + character*1 c1(NMAX) + character*1 only + integer nsnr(NMAX,0:1),nf(NMAX,0:1) + real dt(NMAX,0:1) + logical found,eof + +! These files are sorted by freq within each Rx sequence + open(10,file='all.wsjtx',status='old') + open(11,file='all.jtdx',status='old') + write(20,1030) +1030 format(' iseq B w j W W+ J E B w j W', & + ' W+ J E'/80('-')) + + nutc0=-1 + nbt=0 !Both + nwt=0 !WSJT-X only + njt=0 !JTDX only + net=0 !Either + n7t=0 !a7 + eof=.false. + + do iseq=1,9999 + j=0 + msg=' ' + nsnr=-99 + nf=-99 + dt=-99 + c1=' ' + c2=' ' + do i=1,NMAX + read(10,'(a88)',end=8) line !Read from the WSJT-X file + if(line(25:30).ne.'Rx FT8') cycle !Ignore any line not an FT8 decode + read(line(8:13),*) nutc + if(nutc0.lt.0) nutc0=nutc !First time only + if(nutc.ne.nutc0) then + backspace(10) + go to 10 !Finished WSJT-X for this sequence + endif + j=j+1 + if(j.eq.1) then + nf(j,0)=-1 + j=j+1 + endif + read(line,1001) nsnr(j,0),dt(j,0),nf(j,0),msg(j),c2(j) +1001 format(30x,i7,f5.1,i5,1x,a36,2x,a2) +! if(nutc.eq.180215 .and. c2(j).eq.'a7') print*,'aaa',j,nf(j,0),c2(j) + nutc0=nutc + enddo ! i + +8 eof=.true. +10 jz=j + do i=1,NMAX + read(11,'(a88)',end=20) line !Read from the JTDX file + if(line(31:31).ne.'~') cycle !Ignore any line not an FT8 decode + read(line(10:15),*) nutc + if(nutc.ne.nutc0) then + backspace(11) + go to 20 !Finished JTDX for this sequence + endif + msg1=line(33:58) + read(line(25:29),*) nf1 + found=.false. + do j=1,jz + if(msg(j).eq.msg1) then + read(line,1002) nsnr(j,1),dt(j,1),nf(j,1),c1(j) +1002 format(15x,i4,f5.1,i5,29x,a1) + found=.true. + exit + endif + i1=index(msg(j),'<') + if(i1.gt.0) then + i2=index(msg(j),'>') + msg0=msg(j)(1:i1-1)//msg(j)(i1+1:i2-1)//msg(j)(i2+1:) + if(msg0.eq.msg1) then + read(line,1002) nsnr(j,1),dt(j,1),nf(j,1),c1(j) + found=.true. + exit + endif + endif + enddo ! j + + if(.not.found) then !Insert this one as a new message + do j=1,jz + if(nf1.ge.nf(j,0) .and. nf1.lt.nf(j+1,0)) then + jj=j+1 + exit + endif + enddo + do j=jz+1,jj+1,-1 + nsnr(j,0)=nsnr(j-1,0) + dt(j,0)=dt(j-1,0) + nf(j,0)=nf(j-1,0) + msg(j)=msg(j-1) + c1(j)=c1(j-1) + c2(j)=c2(j-1) + enddo ! j + read(line,1004) nsnr(jj,1),dt(jj,1),nf(jj,1),msg(jj),c1(jj) +1004 format(15x,i4,f5.1,i5,3x,a26,a1) + c2(jj)=' ' + nsnr(jj,0)=-99 + dt(jj,0)=-99.0 + nf(jj,0)=-99 + jz=jz+1 + endif + enddo ! i + +20 nb=0 + nw=0 + nj=0 + ne=0 + n7=0 + do j=2,jz + write(line,1020) nutc0,j,nsnr(j,:),dt(j,:),nf(j,:),msg(j)(1:26), & + c2(j),c1(j) +1020 format(i6.6,i3,1x,2i4,1x,2f6.1,1x,2i5,1x,a26,1x,a2,1x,a1) + if(c2(j).eq.'a7') n7=n7+1 + only=' ' + if(line(12:14).eq.'-99') then + line(12:14)=' ' + only='j' + nj=nj+1 +! if(c2(j).eq.'a7') print*,'aaa ',trim(line) + endif + if(line(16:18).eq.'-99') then + line(16:18)=' ' + only='w' + nw=nw+1 + endif + if(line(12:14).ne.' ' .or. line(16:19).ne.' ') ne=ne+1 + if(line(12:14).ne.' ' .and. line(16:19).ne.' ') nb=nb+1 + if(line(21:25).eq.'-99.0') line(21:25)=' ' + if(line(27:31).eq.'-99.0') line(27:31)=' ' + if(line(35:37).eq.'-99') line(35:37)=' ' + if(line(40:42).eq.'-99') line(40:42)=' ' +! if(line(12:14).ne.' ') nw=nw+1 +! if(line(16:18).ne.' ') nj=nj+1 + write(*,'(a74,1x,a1)') line(1:74),only + enddo ! j + + nbt=nbt+nb + nwt=nwt+nw + n7t=n7t+n7 + njt=njt+nj + net=net+ne + nutc0=nutc + write(*,*) + + write(20,1031) iseq,nb,nw,nj,nb+nw-n7,nb+nw,nb+nj,ne,nbt,nwt,njt, & + nbt+nwt-n7t,nbt+nwt,nbt+njt,net +1031 format(i5,2x,7i4,2x,7i6) + if(eof) exit +! if(iseq.eq.2) exit + enddo ! iseq + +end program chkdec diff --git a/lib/ft8/decode174_91.f90 b/lib/ft8/decode174_91.f90 index a4d82c56..134864d9 100755 --- a/lib/ft8/decode174_91.f90 +++ b/lib/ft8/decode174_91.f90 @@ -1,155 +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 +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.f90 b/lib/ft8/encode174.f90 index 2a14614b..599f1064 100755 --- a/lib/ft8/encode174.f90 +++ b/lib/ft8/encode174.f90 @@ -1,50 +1,50 @@ -subroutine encode174(message,codeword) -! Encode an 87-bit message and return a 174-bit codeword. -! The generator matrix has dimensions (87,87). -! The code is a (174,87) regular ldpc code with column weight 3. -! The code was generated using the PEG algorithm. -! After creating the codeword, the columns are re-ordered according to -! "colorder" to make the codeword compatible with the parity-check matrix -! - -include "ldpc_174_87_params.f90" - -integer*1 codeword(N) -integer*1 gen(M,K) -integer*1 itmp(N) -integer*1 message(K) -integer*1 pchecks(M) -logical first -data first/.true./ - -save first,gen - -if( first ) then ! fill the generator matrix - gen=0 - do i=1,M - do j=1,11 - read(g(i)( (j-1)*2+1:(j-1)*2+2 ),"(Z2)") istr - do jj=1, 8 - icol=(j-1)*8+jj - if( icol .le. 87 ) then - if( btest(istr,8-jj) ) gen(i,icol)=1 - endif - 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 -itmp(1:M)=pchecks -itmp(M+1:N)=message(1:K) -codeword(colorder+1)=itmp(1:N) - -return -end subroutine encode174 +subroutine encode174(message,codeword) +! Encode an 87-bit message and return a 174-bit codeword. +! The generator matrix has dimensions (87,87). +! The code is a (174,87) regular ldpc code with column weight 3. +! The code was generated using the PEG algorithm. +! After creating the codeword, the columns are re-ordered according to +! "colorder" to make the codeword compatible with the parity-check matrix +! + +include "ldpc_174_87_params.f90" + +integer*1 codeword(N) +integer*1 gen(M,K) +integer*1 itmp(N) +integer*1 message(K) +integer*1 pchecks(M) +logical first +data first/.true./ + +save first,gen + +if( first ) then ! fill the generator matrix + gen=0 + do i=1,M + do j=1,11 + read(g(i)( (j-1)*2+1:(j-1)*2+2 ),"(Z2)") istr + do jj=1, 8 + icol=(j-1)*8+jj + if( icol .le. 87 ) then + if( btest(istr,8-jj) ) gen(i,icol)=1 + endif + 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 +itmp(1:M)=pchecks +itmp(M+1:N)=message(1:K) +codeword(colorder+1)=itmp(1:N) + +return +end subroutine encode174 diff --git a/lib/ft8/encode174_91.f90 b/lib/ft8/encode174_91.f90 index b94529dc..5bae7d56 100755 --- a/lib/ft8/encode174_91.f90 +++ b/lib/ft8/encode174_91.f90 @@ -1,58 +1,58 @@ -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 - - 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 - -! 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 - - 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 +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 + + 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 + +! 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 + + 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 diff --git a/lib/ft8/encode174_91_nocrc.f90 b/lib/ft8/encode174_91_nocrc.f90 index 1a05425e..82d1669d 100755 --- a/lib/ft8/encode174_91_nocrc.f90 +++ b/lib/ft8/encode174_91_nocrc.f90 @@ -1,47 +1,47 @@ -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 - integer*1 codeword(N) - integer*1 gen(M,K) - integer*1 message(K) - integer*1 pchecks(M) - 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 +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 + integer*1 codeword(N) + integer*1 gen(M,K) + integer*1 message(K) + integer*1 pchecks(M) + 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/ft8_a7.f90 b/lib/ft8/ft8_a7.f90 index a7af8c81..56217601 100755 --- a/lib/ft8/ft8_a7.f90 +++ b/lib/ft8/ft8_a7.f90 @@ -1,378 +1,378 @@ -module ft8_a7 - - parameter(MAXDEC=200) - -! For the following three arrays -! First index i=decode number in this sequence -! Second index j=0 or 1 for even or odd sequence -! Third index k=0 or 1 for previous or current tally for this j - real dt0(MAXDEC,0:1,0:1) !dt0(i,j,k) - real f0(MAXDEC,0:1,0:1) !f0(i,j,k) - character*37 msg0(MAXDEC,0:1,0:1) !msg0(i,j,k) - - integer itone_a7(79) - integer jseq !even=0, odd=1 - integer ndec(0:1,0:1) !ndec(j,k) - data ndec/4*0/,jseq/0/ - -contains - -subroutine ft8_a7_save(nutc,dt,f,msg) - - use packjt77 - character*37 msg,msg1 - character*13 w(19) - character*4 g4 - integer nw(19) - logical isgrid4 - -! Statement function: - isgrid4(g4)=(len_trim(g4).eq.4 .and. & - ichar(g4(1:1)).ge.ichar('A') .and. ichar(g4(1:1)).le.ichar('R') .and. & - ichar(g4(2:2)).ge.ichar('A') .and. ichar(g4(2:2)).le.ichar('R') .and. & - ichar(g4(3:3)).ge.ichar('0') .and. ichar(g4(3:3)).le.ichar('9') .and. & - ichar(g4(4:4)).ge.ichar('0') .and. ichar(g4(4:4)).le.ichar('9')) - - if(index(msg,'/').ge.1 .or. index(msg,'<').ge.1) go to 999 - call split77(msg,nwords,nw,w) !Parse msg into words - if(nwords.lt.1) go to 999 - if(w(1)(1:3).eq.'CQ_') go to 999 - j=mod(nutc/5,2) !j is 0 or 1 for odd/even sequence - jseq=j - -! Add this decode to current table for this sequence - ndec(j,1)=ndec(j,1)+1 !Number of decodes in this sequence - i=ndec(j,1) !i is index of a new table entry - if(i.gt.MAXDEC) return !Prevent table overflow (indexes start at 1) - - dt0(i,j,1)=dt !Save dt in table - f0(i,j,1)=f !Save f in table - msg0(i,j,1)=trim(w(1))//' '//trim(w(2)) !Save "call_1 call_2" - if(w(1)(1:3).eq.'CQ ' .and. nw(2).le.2) then - msg0(i,j,1)='CQ '//trim(w(2))//' '//trim(w(3)) !Save "CQ DX Call_2" - endif - msg1=msg0(i,j,1) !Message without grid - nn=len(trim(msg1)) !Message length without grid -! Include grid as part of message - if(isgrid4(w(nwords))) msg0(i,j,1)=trim(msg0(i,j,1))//' '//trim(w(nwords)) - -! If a transmission at this frequency with message fragment "call_1 call_2" -! was decoded in the previous sequence, flag it as "DO NOT USE" because -! we have already decoded and subtracted that station's next transmission. - - call split77(msg0(i,j,1),nwords,nw,w) !Parse msg into words - do i=1,ndec(j,0) - if(f0(i,j,0).le.-98.0) cycle - i2=index(msg0(i,j,0),' '//trim(w(2))) - if(abs(f-f0(i,j,0)).le.3.0 .and. i2.ge.3) then - f0(i,j,0)=-98.0 !Flag as "do not use" for a potential a7 decode - endif - enddo - -999 return -end subroutine ft8_a7_save - -subroutine ft8_a7d(dd0,newdat,call_1,call_2,grid4,xdt,f1,xbase,nharderrors,dmin, & - msg37,xsnr) - -! Examine the raw data in dd0() for possible "a7" decodes. - - use crc - use timer_module, only: timer - use packjt77 - include 'ft8_params.f90' - parameter(NP2=2812) - character*37 msg37,msg,msgsent,msgbest - character*12 call_1,call_2 - character*4 grid4 - real a(5) - real s8(0:7,NN) - real s2(0:511) - real dmm(206) - real bmeta(174),bmetb(174),bmetc(174),bmetd(174) - real llra(174),llrb(174),llrc(174),llrd(174) !Soft symbols - real dd0(15*12000) - real ss(9) - real rcw(174) - integer*1 cw(174) - integer*1 msgbits(77) - integer*1 nxor(174),hdec(174) - integer itone(NN) - integer icos7(0:6),ip(1) - logical one(0:511,0:8) - integer graymap(0:7) - integer iloc(1) - complex cd0(0:3199) - complex ctwk(32) - complex csymb(32) - complex cs(0:7,NN) - logical std_1,std_2 - logical first,newdat - data icos7/3,1,4,0,6,5,2/ !Sync array - data first/.true./ - data graymap/0,1,3,2,5,6,4,7/ - save one - - if(first) then - one=.false. - do i=0,511 - do j=0,8 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - first=.false. - endif - - call stdcall(call_1,std_1) - if(call_1(1:3).eq.'CQ ') std_1=.true. - call stdcall(call_2,std_2) - - fs2=12000.0/NDOWN - dt2=1.0/fs2 - twopi=8.0*atan(1.0) - delfbest=0. - ibest=0 - - call timer('ft8_down',0) - call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample - call timer('ft8_down',1) - - i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal - smax=0.0 - do idt=i0-10,i0+10 !Search over +/- one quarter symbol - call sync8d(cd0,idt,ctwk,0,sync) !NB: ctwk not used here - if(sync.gt.smax) then - smax=sync - ibest=idt - endif - enddo - -! Peak up in frequency - smax=0.0 - do ifr=-5,5 !Search over +/- 2.5 Hz - delf=ifr*0.5 - dphi=twopi*delf*dt2 - phi=0.0 - do i=1,32 - ctwk(i)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - enddo - call sync8d(cd0,ibest,ctwk,1,sync) - if( sync .gt. smax ) then - smax=sync - delfbest=delf - endif - enddo - a=0.0 - a(1)=-delfbest - call twkfreq1(cd0,NP2,fs2,a,cd0) - f1=f1+delfbest !Improved estimate of DF - - 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 - 0.5 - sync=smax - - do k=1,NN - i1=ibest+(k-1)*32 - csymb=cmplx(0.0,0.0) - if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) - call four2a(csymb,32,1,-1,1) - cs(0:7,k)=csymb(1:8)/1e3 - s8(0:7,k)=abs(csymb(1:8)) - enddo - -! sync quality check - is1=0 - is2=0 - is3=0 - do k=1,7 - ip=maxloc(s8(:,k)) - if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 - ip=maxloc(s8(:,k+36)) - if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 - ip=maxloc(s8(:,k+72)) - if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 - enddo -! hard sync sum - max is 21 - nsync=is1+is2+is3 -! if(nsync .le. 6) return ! bail out - - do nsym=1,3 - nt=2**(3*nsym) - do ihalf=1,2 - do k=1,29,nsym - if(ihalf.eq.1) ks=k+7 - if(ihalf.eq.2) ks=k+43 - amax=-1.0 - do i=0,nt-1 - i1=i/64 - i2=iand(i,63)/8 - i3=iand(i,7) - if(nsym.eq.1) then - s2(i)=abs(cs(graymap(i3),ks)) - elseif(nsym.eq.2) then - s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) - elseif(nsym.eq.3) then - s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) - else - print*,"Error - nsym must be 1, 2, or 3." - endif - enddo - i32=1+(k-1)*3+(ihalf-1)*87 - if(nsym.eq.1) ibmax=2 - if(nsym.eq.2) ibmax=5 - if(nsym.eq.3) ibmax=8 - do ib=0,ibmax - bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) - 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 - bmetc(i32+ib)=bm - endif - enddo - enddo - enddo - enddo - 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 - - MAXMSG=206 - pbest=0. - dmin=1.e30 - nharderrors=-1 - - do imsg=1,MAXMSG - msg=trim(call_1)//' '//trim(call_2) - i=imsg - if(call_1(1:3).eq.'CQ ' .and. i.ne.5) msg='QU1RK '//trim(call_2) - if(.not.std_1) then - if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' - else if(.not.std_2) then - if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' - endif - j0=len(trim(msg))+2 - if(i.eq.2) msg(j0:j0+2)='RRR' - if(i.eq.3) msg(j0:j0+3)='RR73' - if(i.eq.4) msg(j0:j0+1)='73' - if(i.eq.5) then - if(std_2) then - msg='CQ '//trim(call_2) - if(call_1(3:3).eq.'_') msg=trim(call_1)//' '//trim(call_2) - if(grid4.ne.'RR73') msg=trim(msg)//' '//grid4 - endif - if(.not.std_2) msg='CQ '//trim(call_2) - endif - if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 - if(i.ge.7) then - isnr = -50 + (i-7)/2 - if(iand(i,1).eq.1) then - write(msg(j0:j0+2),'(i3.2)') isnr - if(msg(j0:j0).eq.' ') msg(j0:j0)='+' - else - write(msg(j0:j0+3),'("R",i3.2)') isnr - if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' - endif - endif - - i3=-1 - n3=-1 - call genft8(msg,i3,n3,msgsent,msgbits,itone) !Source-encode this message - call encode174_91(msgbits,cw) !Get codeword for this message - rcw=2*cw-1 - pow=0.0 - do i=1,79 - pow=pow+s8(itone(i),i)**2 - enddo - - hdec=0 - where(llra.ge.0.0) hdec=1 - nxor=ieor(hdec,cw) - da=sum(nxor*abs(llra)) - - hdec=0 - where(llrb.ge.0.0) hdec=1 - nxor=ieor(hdec,cw) - dbb=sum(nxor*abs(llrb)) - - hdec=0 - where(llrc.ge.0.0) hdec=1 - nxor=ieor(hdec,cw) - dc=sum(nxor*abs(llrc)) - - hdec=0 - where(llrd.ge.0.0) hdec=1 - nxor=ieor(hdec,cw) - dd=sum(nxor*abs(llrd)) - - dm=min(da,dbb,dc,dd) - dmm(imsg)=dm - if(dm.lt.dmin) then - dmin=dm - msgbest=msgsent - pbest=pow - if(dm.eq.da) then - nharderrors=count((2*cw-1)*llra.lt.0.0) - else if(dm.eq.dbb) then - nharderrors=count((2*cw-1)*llrb.lt.0.0) - else if(dm.eq.dc) then - nharderrors=count((2*cw-1)*llrc.lt.0.0) - else if(dm.eq.dd) then - nharderrors=count((2*cw-1)*llrd.lt.0.0) - endif - endif - - enddo ! imsg - - iloc=minloc(dmm) - dmm(iloc(1))=1.e30 - iloc=minloc(dmm) - dmin2=dmm(iloc(1)) - xsnr=-24. - arg=pbest/xbase/3.0e6-1.0 - if(arg.gt.0.0) xsnr=max(-24.0,db(arg)-27.0) -! write(41,3041) nharderrors,dmin,dmin2,dmin2/dmin,xsnr,trim(msgbest) -!3041 format(i3,2f7.1,f7.2,f7.1,1x,a) - if(dmin.gt.100.0 .or. dmin2/dmin.lt.1.3) nharderrors=-1 - msg37=msgbest - if(msg37(1:3).eq.'CQ ' .and. std_2 .and. grid4.eq.' ') nharderrors=-1 - if(msg37(1:6).eq.'QU1RK ') nharderrors=-1 - - return -end subroutine ft8_a7d - -end module ft8_a7 +module ft8_a7 + + parameter(MAXDEC=200) + +! For the following three arrays +! First index i=decode number in this sequence +! Second index j=0 or 1 for even or odd sequence +! Third index k=0 or 1 for previous or current tally for this j + real dt0(MAXDEC,0:1,0:1) !dt0(i,j,k) + real f0(MAXDEC,0:1,0:1) !f0(i,j,k) + character*37 msg0(MAXDEC,0:1,0:1) !msg0(i,j,k) + + integer itone_a7(79) + integer jseq !even=0, odd=1 + integer ndec(0:1,0:1) !ndec(j,k) + data ndec/4*0/,jseq/0/ + +contains + +subroutine ft8_a7_save(nutc,dt,f,msg) + + use packjt77 + character*37 msg,msg1 + character*13 w(19) + character*4 g4 + integer nw(19) + logical isgrid4 + +! Statement function: + isgrid4(g4)=(len_trim(g4).eq.4 .and. & + ichar(g4(1:1)).ge.ichar('A') .and. ichar(g4(1:1)).le.ichar('R') .and. & + ichar(g4(2:2)).ge.ichar('A') .and. ichar(g4(2:2)).le.ichar('R') .and. & + ichar(g4(3:3)).ge.ichar('0') .and. ichar(g4(3:3)).le.ichar('9') .and. & + ichar(g4(4:4)).ge.ichar('0') .and. ichar(g4(4:4)).le.ichar('9')) + + if(index(msg,'/').ge.1 .or. index(msg,'<').ge.1) go to 999 + call split77(msg,nwords,nw,w) !Parse msg into words + if(nwords.lt.1) go to 999 + if(w(1)(1:3).eq.'CQ_') go to 999 + j=mod(nutc/5,2) !j is 0 or 1 for odd/even sequence + jseq=j + +! Add this decode to current table for this sequence + ndec(j,1)=ndec(j,1)+1 !Number of decodes in this sequence + i=ndec(j,1) !i is index of a new table entry + if(i.gt.MAXDEC) return !Prevent table overflow (indexes start at 1) + + dt0(i,j,1)=dt !Save dt in table + f0(i,j,1)=f !Save f in table + msg0(i,j,1)=trim(w(1))//' '//trim(w(2)) !Save "call_1 call_2" + if(w(1)(1:3).eq.'CQ ' .and. nw(2).le.2) then + msg0(i,j,1)='CQ '//trim(w(2))//' '//trim(w(3)) !Save "CQ DX Call_2" + endif + msg1=msg0(i,j,1) !Message without grid + nn=len(trim(msg1)) !Message length without grid +! Include grid as part of message + if(isgrid4(w(nwords))) msg0(i,j,1)=trim(msg0(i,j,1))//' '//trim(w(nwords)) + +! If a transmission at this frequency with message fragment "call_1 call_2" +! was decoded in the previous sequence, flag it as "DO NOT USE" because +! we have already decoded and subtracted that station's next transmission. + + call split77(msg0(i,j,1),nwords,nw,w) !Parse msg into words + do i=1,ndec(j,0) + if(f0(i,j,0).le.-98.0) cycle + i2=index(msg0(i,j,0),' '//trim(w(2))) + if(abs(f-f0(i,j,0)).le.3.0 .and. i2.ge.3) then + f0(i,j,0)=-98.0 !Flag as "do not use" for a potential a7 decode + endif + enddo + +999 return +end subroutine ft8_a7_save + +subroutine ft8_a7d(dd0,newdat,call_1,call_2,grid4,xdt,f1,xbase,nharderrors,dmin, & + msg37,xsnr) + +! Examine the raw data in dd0() for possible "a7" decodes. + + use crc + use timer_module, only: timer + use packjt77 + include 'ft8_params.f90' + parameter(NP2=2812) + character*37 msg37,msg,msgsent,msgbest + character*12 call_1,call_2 + character*4 grid4 + real a(5) + real s8(0:7,NN) + real s2(0:511) + real dmm(206) + real bmeta(174),bmetb(174),bmetc(174),bmetd(174) + real llra(174),llrb(174),llrc(174),llrd(174) !Soft symbols + real dd0(15*12000) + real ss(9) + real rcw(174) + integer*1 cw(174) + integer*1 msgbits(77) + integer*1 nxor(174),hdec(174) + integer itone(NN) + integer icos7(0:6),ip(1) + logical one(0:511,0:8) + integer graymap(0:7) + integer iloc(1) + complex cd0(0:3199) + complex ctwk(32) + complex csymb(32) + complex cs(0:7,NN) + logical std_1,std_2 + logical first,newdat + data icos7/3,1,4,0,6,5,2/ !Sync array + data first/.true./ + data graymap/0,1,3,2,5,6,4,7/ + save one + + if(first) then + one=.false. + do i=0,511 + do j=0,8 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + first=.false. + endif + + call stdcall(call_1,std_1) + if(call_1(1:3).eq.'CQ ') std_1=.true. + call stdcall(call_2,std_2) + + fs2=12000.0/NDOWN + dt2=1.0/fs2 + twopi=8.0*atan(1.0) + delfbest=0. + ibest=0 + + call timer('ft8_down',0) + call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal + smax=0.0 + do idt=i0-10,i0+10 !Search over +/- one quarter symbol + call sync8d(cd0,idt,ctwk,0,sync) !NB: ctwk not used here + if(sync.gt.smax) then + smax=sync + ibest=idt + endif + enddo + +! Peak up in frequency + smax=0.0 + do ifr=-5,5 !Search over +/- 2.5 Hz + delf=ifr*0.5 + dphi=twopi*delf*dt2 + phi=0.0 + do i=1,32 + ctwk(i)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + enddo + call sync8d(cd0,ibest,ctwk,1,sync) + if( sync .gt. smax ) then + smax=sync + delfbest=delf + endif + enddo + a=0.0 + a(1)=-delfbest + call twkfreq1(cd0,NP2,fs2,a,cd0) + f1=f1+delfbest !Improved estimate of DF + + 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 - 0.5 + sync=smax + + do k=1,NN + i1=ibest+(k-1)*32 + csymb=cmplx(0.0,0.0) + if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) + call four2a(csymb,32,1,-1,1) + cs(0:7,k)=csymb(1:8)/1e3 + s8(0:7,k)=abs(csymb(1:8)) + enddo + +! sync quality check + is1=0 + is2=0 + is3=0 + do k=1,7 + ip=maxloc(s8(:,k)) + if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s8(:,k+36)) + if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s8(:,k+72)) + if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 + enddo +! hard sync sum - max is 21 + nsync=is1+is2+is3 +! if(nsync .le. 6) return ! bail out + + do nsym=1,3 + nt=2**(3*nsym) + do ihalf=1,2 + do k=1,29,nsym + if(ihalf.eq.1) ks=k+7 + if(ihalf.eq.2) ks=k+43 + amax=-1.0 + do i=0,nt-1 + i1=i/64 + i2=iand(i,63)/8 + i3=iand(i,7) + if(nsym.eq.1) then + s2(i)=abs(cs(graymap(i3),ks)) + elseif(nsym.eq.2) then + s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) + elseif(nsym.eq.3) then + s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) + else + print*,"Error - nsym must be 1, 2, or 3." + endif + enddo + i32=1+(k-1)*3+(ihalf-1)*87 + if(nsym.eq.1) ibmax=2 + if(nsym.eq.2) ibmax=5 + if(nsym.eq.3) ibmax=8 + do ib=0,ibmax + bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) + 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 + bmetc(i32+ib)=bm + endif + enddo + enddo + enddo + enddo + 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 + + MAXMSG=206 + pbest=0. + dmin=1.e30 + nharderrors=-1 + + do imsg=1,MAXMSG + msg=trim(call_1)//' '//trim(call_2) + i=imsg + if(call_1(1:3).eq.'CQ ' .and. i.ne.5) msg='QU1RK '//trim(call_2) + if(.not.std_1) then + if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' + else if(.not.std_2) then + if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' + endif + j0=len(trim(msg))+2 + if(i.eq.2) msg(j0:j0+2)='RRR' + if(i.eq.3) msg(j0:j0+3)='RR73' + if(i.eq.4) msg(j0:j0+1)='73' + if(i.eq.5) then + if(std_2) then + msg='CQ '//trim(call_2) + if(call_1(3:3).eq.'_') msg=trim(call_1)//' '//trim(call_2) + if(grid4.ne.'RR73') msg=trim(msg)//' '//grid4 + endif + if(.not.std_2) msg='CQ '//trim(call_2) + endif + if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 + if(i.ge.7) then + isnr = -50 + (i-7)/2 + if(iand(i,1).eq.1) then + write(msg(j0:j0+2),'(i3.2)') isnr + if(msg(j0:j0).eq.' ') msg(j0:j0)='+' + else + write(msg(j0:j0+3),'("R",i3.2)') isnr + if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' + endif + endif + + i3=-1 + n3=-1 + call genft8(msg,i3,n3,msgsent,msgbits,itone) !Source-encode this message + call encode174_91(msgbits,cw) !Get codeword for this message + rcw=2*cw-1 + pow=0.0 + do i=1,79 + pow=pow+s8(itone(i),i)**2 + enddo + + hdec=0 + where(llra.ge.0.0) hdec=1 + nxor=ieor(hdec,cw) + da=sum(nxor*abs(llra)) + + hdec=0 + where(llrb.ge.0.0) hdec=1 + nxor=ieor(hdec,cw) + dbb=sum(nxor*abs(llrb)) + + hdec=0 + where(llrc.ge.0.0) hdec=1 + nxor=ieor(hdec,cw) + dc=sum(nxor*abs(llrc)) + + hdec=0 + where(llrd.ge.0.0) hdec=1 + nxor=ieor(hdec,cw) + dd=sum(nxor*abs(llrd)) + + dm=min(da,dbb,dc,dd) + dmm(imsg)=dm + if(dm.lt.dmin) then + dmin=dm + msgbest=msgsent + pbest=pow + if(dm.eq.da) then + nharderrors=count((2*cw-1)*llra.lt.0.0) + else if(dm.eq.dbb) then + nharderrors=count((2*cw-1)*llrb.lt.0.0) + else if(dm.eq.dc) then + nharderrors=count((2*cw-1)*llrc.lt.0.0) + else if(dm.eq.dd) then + nharderrors=count((2*cw-1)*llrd.lt.0.0) + endif + endif + + enddo ! imsg + + iloc=minloc(dmm) + dmm(iloc(1))=1.e30 + iloc=minloc(dmm) + dmin2=dmm(iloc(1)) + xsnr=-24. + arg=pbest/xbase/3.0e6-1.0 + if(arg.gt.0.0) xsnr=max(-24.0,db(arg)-27.0) +! write(41,3041) nharderrors,dmin,dmin2,dmin2/dmin,xsnr,trim(msgbest) +!3041 format(i3,2f7.1,f7.2,f7.1,1x,a) + if(dmin.gt.100.0 .or. dmin2/dmin.lt.1.3) nharderrors=-1 + msg37=msgbest + if(msg37(1:3).eq.'CQ ' .and. std_2 .and. grid4.eq.' ') nharderrors=-1 + if(msg37(1:6).eq.'QU1RK ') nharderrors=-1 + + return +end subroutine ft8_a7d + +end module ft8_a7 diff --git a/lib/ft8/ft8_testmsg.f90 b/lib/ft8/ft8_testmsg.f90 index 931df4f5..253641d2 100755 --- 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)/ & - "TNX BOB 73 GL", & ! 0.0 - "K1ABC RR73; W9XYZ -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 -11", & ! 1. - " W9XYZ R-09", & ! 1. - "CQ W9XYZ EN37", & ! 1. - " W9XYZ -11", & ! 1. - "W9XYZ R-09", & ! 1. - " KA1ABC", & ! 1. - "KA1ABC -11", & ! 1. - " KA1ABC R-17", & ! 1. - " 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 ", & ! 4. - " PJ4/K1ABC RRR", & ! 4. - "PJ4/K1ABC 73", & ! 4. - " YW18FIFA", & ! 4. - "YW18FIFA RRR", & ! 4. - " YW18FIFA 73", & ! 4. - "CQ YW18FIFA", & ! 4. - " YW18FIFA RR73"/ + parameter (MAXTEST=75,NTEST=48) + character*37 testmsg(MAXTEST) + data testmsg(1:NTEST)/ & + "TNX BOB 73 GL", & ! 0.0 + "K1ABC RR73; W9XYZ -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 -11", & ! 1. + " W9XYZ R-09", & ! 1. + "CQ W9XYZ EN37", & ! 1. + " W9XYZ -11", & ! 1. + "W9XYZ R-09", & ! 1. + " KA1ABC", & ! 1. + "KA1ABC -11", & ! 1. + " KA1ABC R-17", & ! 1. + " 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 ", & ! 4. + " PJ4/K1ABC RRR", & ! 4. + "PJ4/K1ABC 73", & ! 4. + " YW18FIFA", & ! 4. + "YW18FIFA RRR", & ! 4. + " YW18FIFA 73", & ! 4. + "CQ YW18FIFA", & ! 4. + " YW18FIFA RR73"/ diff --git a/lib/ft8/ft8apset.f90 b/lib/ft8/ft8apset.f90 index 64b22128..73a224ec 100755 --- a/lib/ft8/ft8apset.f90 +++ b/lib/ft8/ft8apset.f90 @@ -1,62 +1,62 @@ -subroutine ft8apset(mycall12,hiscall12,ncontest,apsym,aph10) - use packjt77 - character*77 c77 - character*37 msg,msgchk - character*12 mycall12,hiscall12,hiscall - character*13 hc13 - character*10 c10 - integer apsym(58),aph10(10) - logical nohiscall,unpk77_success,std - - apsym=0 - apsym(1)=99 - apsym(30)=99 - aph10=0 - aph10(1)=99 - if(len(trim(mycall12)).lt.3) return - - nohiscall=.false. - hiscall=hiscall12 - if(len(trim(hiscall)).lt.3) then - hiscall='KA1ABC' !Use a dummy hiscall - 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' - call stdcall(mycall12,std) - if(.not.std) 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 - - read(c77,'(58i1)',err=2) apsym(1:58) - apsym=2*apsym-1 - if(nohiscall) then - apsym(30)=99 - aph10(1)=99 - endif - return - -1 aph10=0 - aph10(1)=99 - return -2 apsym=0 - apsym(1)=99 - apsym(30)=99 - return - -end subroutine ft8apset +subroutine ft8apset(mycall12,hiscall12,ncontest,apsym,aph10) + use packjt77 + character*77 c77 + character*37 msg,msgchk + character*12 mycall12,hiscall12,hiscall + character*13 hc13 + character*10 c10 + integer apsym(58),aph10(10) + logical nohiscall,unpk77_success,std + + apsym=0 + apsym(1)=99 + apsym(30)=99 + aph10=0 + aph10(1)=99 + if(len(trim(mycall12)).lt.3) return + + nohiscall=.false. + hiscall=hiscall12 + if(len(trim(hiscall)).lt.3) then + hiscall='KA1ABC' !Use a dummy hiscall + 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' + call stdcall(mycall12,std) + if(.not.std) 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 + + read(c77,'(58i1)',err=2) apsym(1:58) + apsym=2*apsym-1 + if(nohiscall) then + apsym(30)=99 + aph10(1)=99 + endif + return + +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 75b17adf..30cd95c8 100755 --- a/lib/ft8/ft8b.f90 +++ b/lib/ft8/ft8b.f90 @@ -1,503 +1,503 @@ -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 - use packjt77 - include 'ft8_params.f90' - parameter(NP2=2812) - character*37 msg37 - character*12 mycall12,hiscall12 - character*77 c77 - real a(5) - real s8(0:7,NN) - real s2(0:511) - 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) - 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) - integer nappasses(0:5) !Number of decoding passes to use for each QSO state - integer naptypes(0:5,4) ! (nQSOProgress, decoding pass) maximum of 4 passes for now - 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) - complex cs(0:7,NN) - logical first,newdat,lsubtract,lapon,lapcqonly,nagain,unpk77_success - data icos7/3,1,4,0,6,5,2/ ! Flipped w.r.t. original FT8 sync array - data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/ - 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/ - data first/.true./ - 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 - nappasses(0)=2 - nappasses(1)=2 - nappasses(2)=2 - nappasses(3)=4 - nappasses(4)=4 - nappasses(5)=3 - -! iaptype -!------------------------ -! 1 CQ ??? ??? (29+3=32 ap bits) -! 2 MyCall ??? ??? (29+3=32 ap bits) -! 3 MyCall DxCall ??? (58+3=61 ap bits) -! 4 MyCall DxCall RRR (77 ap bits) -! 5 MyCall DxCall 73 (77 ap bits) -! 6 MyCall DxCall RR73 (77 ap bits) - - naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ) - naptypes(1,1:4)=(/2,3,0,0/) ! Tx1 - naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 - naptypes(3,1:4)=(/3,4,5,6/) ! Tx3 - naptypes(4,1:4)=(/3,4,5,6/) ! Tx4 - naptypes(5,1:4)=(/3,1,2,0/) ! Tx5 - - one=.false. - do i=0,511 - do j=0,8 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - first=.false. - ncontest0=ncontest - endif - - dxcall13=hiscall12 ! initialize for use in packjt77 - mycall13=mycall12 - - max_iterations=30 - nharderrors=-1 - fs2=12000.0/NDOWN - dt2=1.0/fs2 - twopi=8.0*atan(1.0) - delfbest=0. - ibest=0 - - call timer('ft8_down',0) - call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample - call timer('ft8_down',1) - - i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal - smax=0.0 - 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 - -! Now peak up in frequency - smax=0.0 - do ifr=-5,5 !Search over +/- 2.5 Hz - delf=ifr*0.5 - dphi=twopi*delf*dt2 - phi=0.0 - do i=1,32 - ctwk(i)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - enddo - call sync8d(cd0,ibest,ctwk,1,sync) - if( sync .gt. smax ) then - smax=sync - delfbest=delf - endif - enddo - a=0.0 - a(1)=-delfbest - call twkfreq1(cd0,NP2,fs2,a,cd0) - f1=f1+delfbest !Improved estimate of DF - - 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 - csymb=cmplx(0.0,0.0) - if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) - call four2a(csymb,32,1,-1,1) - cs(0:7,k)=csymb(1:8)/1e3 - s8(0:7,k)=abs(csymb(1:8)) - enddo - -! sync quality check - is1=0 - is2=0 - is3=0 - do k=1,7 - ip=maxloc(s8(:,k)) - if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 - ip=maxloc(s8(:,k+36)) - if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 - ip=maxloc(s8(:,k+72)) - if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 - enddo -! hard sync sum - max is 21 - nsync=is1+is2+is3 - if(nsync .le. 6) then ! bail out - nbadcrc=1 - return - endif - - do nsym=1,3 - nt=2**(3*nsym) - do ihalf=1,2 - do k=1,29,nsym - if(ihalf.eq.1) ks=k+7 - if(ihalf.eq.2) ks=k+43 - amax=-1.0 - do i=0,nt-1 - i1=i/64 - i2=iand(i,63)/8 - i3=iand(i,7) - if(nsym.eq.1) then - s2(i)=abs(cs(graymap(i3),ks)) - elseif(nsym.eq.2) then - s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) - elseif(nsym.eq.3) then - s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) - else - print*,"Error - nsym must be 1, 2, or 3." - endif - enddo - i32=1+(k-1)*3+(ihalf-1)*87 - if(nsym.eq.1) ibmax=2 - if(nsym.eq.2) ibmax=5 - if(nsym.eq.3) ibmax=8 - do ib=0,ibmax - bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) - 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 - bmetc(i32+ib)=bm - endif - enddo - enddo - enddo - enddo - 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 - -! pass # -!------------------------------ -! 1 regular decoding, nsym=1 -! 2 regular decoding, nsym=2 -! 3 regular decoding, nsym=3 -! 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.7) then !Hounds always use AP - if(.not.lapcqonly) then - npasses=4+nappasses(nQSOProgress) - else - npasses=5 - endif - else - npasses=4 - endif - if(nzhsym.lt.50) npasses=4 - - do ipass=1,npasses - 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. 4) then - llrz=llra - if(.not.lapcqonly) then - iaptype=naptypes(nQSOProgress,ipass-4) - else - iaptype=1 - endif - -! ncontest=0 : NONE -! 1 : NA_VHF -! 2 : EU_VHF -! 3 : FIELD DAY -! 4 : RTTY -! 5 : WW_DIGI -! 6 : FOX -! 7 : HOUND -! 8 : ARRL_DIGI -! -! Conditions that cause us to bail out of AP decoding - 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) 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) - if(ncontest.eq.8) llrz(1:29)=apmag*mcqtest(1:29) - apmask(75:77)=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.or.ncontest.eq.5.or.ncontest.eq.8) then - apmask(1:29)=1 - llrz(1:29)=apmag*apsym(1:29) - apmask(75:77)=1 - llrz(75:76)=apmag*(-1) - llrz(77)=apmag*(+1) - else if(ncontest.eq.2) then - apmask(1:28)=1 - llrz(1:28)=apmag*apsym(1:28) - apmask(72:74)=1 - llrz(72)=apmag*(-1) - llrz(73)=apmag*(+1) - llrz(74)=apmag*(-1) - apmask(75:77)=1 - llrz(75:77)=apmag*(-1) - else if(ncontest.eq.3) then - apmask(1:28)=1 - llrz(1:28)=apmag*apsym(1:28) - apmask(75:77)=1 - llrz(75:77)=apmag*(-1) - else if(ncontest.eq.4) then - apmask(2:29)=1 - llrz(2:29)=apmag*apsym(1:28) - apmask(75:77)=1 - llrz(75)=apmag*(-1) - llrz(76:77)=apmag*(+1) - else if(ncontest.eq.7) then ! ??? RR73; MyCall ??? - apmask(29:56)=1 - llrz(29:56)=apmag*apsym(1:28) - apmask(57:66)=1 - llrz(57:66)=apmag*aph10(1:10) - apmask(72:77)=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.5.or.ncontest.eq.7.or.ncontest.eq.8) then - apmask(1:58)=1 - llrz(1:58)=apmag*apsym - apmask(75:77)=1 - llrz(75:76)=apmag*(-1) - llrz(77)=apmag*(+1) - else if(ncontest.eq.3) then ! Field Day - apmask(1:56)=1 - llrz(1:28)=apmag*apsym(1:28) - llrz(29:56)=apmag*apsym(30:57) - apmask(72:74)=1 - apmask(75:77)=1 - llrz(75:77)=apmag*(-1) - else if(ncontest.eq.4) then - apmask(2:57)=1 - llrz(2:29)=apmag*apsym(1:28) - llrz(30:57)=apmag*apsym(30:57) - apmask(75:77)=1 - llrz(75)=apmag*(-1) - llrz(76:77)=apmag*(+1) - endif - endif - - 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.5 .or. (ncontest.eq.7.and.iaptype.eq.6) .or. ncontest.eq.8) then - apmask(1:77)=1 ! mycall, hiscall, RRR|73|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 - llrz(1:28)=apmag*apsym(1:28) - apmask(57:66)=1 - llrz(57:66)=apmag*aph10(1:10) - apmask(72:77)=1 - llrz(72:73)=apmag*(-1) - llrz(74)=apmag*(1) - llrz(75:77)=apmag*(-1) - endif - endif - endif - - cw=0 - dmin=0.0 - norder=2 - maxosd=2 - if(ndepth.eq.1) maxosd=-1 ! BP only - if(ndepth.eq.2) maxosd=0 ! uncoupled BP+OSD - if(ndepth.eq.3 .and. & - (abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid .or. ncontest.eq.7)) then - maxosd=2 - 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=' ' - nbadcrc=1 - if(nharderrors.lt.0 .or. nharderrors.gt.36) cycle - if(count(cw.eq.0).eq.174) cycle !Reject the all-zero codeword - write(c77,'(77i1)') message77 - read(c77(72:74),'(b3)') n3 - read(c77(75:77),'(b3)') i3 - if(i3.gt.5 .or. (i3.eq.0.and.n3.gt.6)) cycle - if(i3.eq.0 .and. n3.eq.2) cycle - call unpack77(c77,1,msg37,unpk77_success) - if(.not.unpk77_success) cycle - nbadcrc=0 ! If we get this far: valid codeword, valid (i3,n3), nonquirky message. - call get_ft8_tones_from_77bits(message77,itone) - 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 - xsig=xsig+s8(itone(i),i)**2 - ios=mod(itone(i)+4,7) - xnoi=xnoi+s8(ios,i)**2 - enddo - xsnr=0.001 - xsnr2=0.001 - arg=xsig/xnoi-1.0 - if(arg.gt.0.1) xsnr=arg - 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(nsync.le.10 .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 - -subroutine normalizebmet(bmet,n) - real bmet(n) - - bmetav=sum(bmet)/real(n) - bmet2av=sum(bmet*bmet)/real(n) - var=bmet2av-bmetav*bmetav - if( var .gt. 0.0 ) then - bmetsig=sqrt(var) - else - bmetsig=sqrt(bmet2av) - endif - bmet=bmet/bmetsig - return -end subroutine normalizebmet - - -function bessi0(x) -! From Numerical Recipes - real bessi0,x - double precision p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9,y - save p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9 - data p1,p2,p3,p4,p5,p6,p7/1.0d0,3.5156229d0,3.0899424d0,1.2067492d0, & - 0.2659732d0,0.360768d-1,0.45813d-2/ - data q1,q2,q3,q4,q5,q6,q7,q8,q9/0.39894228d0,0.1328592d-1, & - 0.225319d-2,-0.157565d-2,0.916281d-2,-0.2057706d-1, & - 0.2635537d-1,-0.1647633d-1,0.392377d-2/ - - if (abs(x).lt.3.75) then - y=(x/3.75)**2 - bessi0=p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7))))) - else - ax=abs(x) - y=3.75/ax - bessi0=(exp(ax)/sqrt(ax))*(q1+y*(q2+y*(q3+y*(q4 & - +y*(q5+y*(q6+y*(q7+y*(q8+y*q9)))))))) - endif - return -end function bessi0 +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 + use packjt77 + include 'ft8_params.f90' + parameter(NP2=2812) + character*37 msg37 + character*12 mycall12,hiscall12 + character*77 c77 + real a(5) + real s8(0:7,NN) + real s2(0:511) + 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) + 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) + integer nappasses(0:5) !Number of decoding passes to use for each QSO state + integer naptypes(0:5,4) ! (nQSOProgress, decoding pass) maximum of 4 passes for now + 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) + complex cs(0:7,NN) + logical first,newdat,lsubtract,lapon,lapcqonly,nagain,unpk77_success + data icos7/3,1,4,0,6,5,2/ ! Flipped w.r.t. original FT8 sync array + data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/ + 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/ + data first/.true./ + 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 + nappasses(0)=2 + nappasses(1)=2 + nappasses(2)=2 + nappasses(3)=4 + nappasses(4)=4 + nappasses(5)=3 + +! iaptype +!------------------------ +! 1 CQ ??? ??? (29+3=32 ap bits) +! 2 MyCall ??? ??? (29+3=32 ap bits) +! 3 MyCall DxCall ??? (58+3=61 ap bits) +! 4 MyCall DxCall RRR (77 ap bits) +! 5 MyCall DxCall 73 (77 ap bits) +! 6 MyCall DxCall RR73 (77 ap bits) + + naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ) + naptypes(1,1:4)=(/2,3,0,0/) ! Tx1 + naptypes(2,1:4)=(/2,3,0,0/) ! Tx2 + naptypes(3,1:4)=(/3,4,5,6/) ! Tx3 + naptypes(4,1:4)=(/3,4,5,6/) ! Tx4 + naptypes(5,1:4)=(/3,1,2,0/) ! Tx5 + + one=.false. + do i=0,511 + do j=0,8 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + first=.false. + ncontest0=ncontest + endif + + dxcall13=hiscall12 ! initialize for use in packjt77 + mycall13=mycall12 + + max_iterations=30 + nharderrors=-1 + fs2=12000.0/NDOWN + dt2=1.0/fs2 + twopi=8.0*atan(1.0) + delfbest=0. + ibest=0 + + call timer('ft8_down',0) + call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal + smax=0.0 + 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 + +! Now peak up in frequency + smax=0.0 + do ifr=-5,5 !Search over +/- 2.5 Hz + delf=ifr*0.5 + dphi=twopi*delf*dt2 + phi=0.0 + do i=1,32 + ctwk(i)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + enddo + call sync8d(cd0,ibest,ctwk,1,sync) + if( sync .gt. smax ) then + smax=sync + delfbest=delf + endif + enddo + a=0.0 + a(1)=-delfbest + call twkfreq1(cd0,NP2,fs2,a,cd0) + f1=f1+delfbest !Improved estimate of DF + + 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 + csymb=cmplx(0.0,0.0) + if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) + call four2a(csymb,32,1,-1,1) + cs(0:7,k)=csymb(1:8)/1e3 + s8(0:7,k)=abs(csymb(1:8)) + enddo + +! sync quality check + is1=0 + is2=0 + is3=0 + do k=1,7 + ip=maxloc(s8(:,k)) + if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s8(:,k+36)) + if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s8(:,k+72)) + if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 + enddo +! hard sync sum - max is 21 + nsync=is1+is2+is3 + if(nsync .le. 6) then ! bail out + nbadcrc=1 + return + endif + + do nsym=1,3 + nt=2**(3*nsym) + do ihalf=1,2 + do k=1,29,nsym + if(ihalf.eq.1) ks=k+7 + if(ihalf.eq.2) ks=k+43 + amax=-1.0 + do i=0,nt-1 + i1=i/64 + i2=iand(i,63)/8 + i3=iand(i,7) + if(nsym.eq.1) then + s2(i)=abs(cs(graymap(i3),ks)) + elseif(nsym.eq.2) then + s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) + elseif(nsym.eq.3) then + s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) + else + print*,"Error - nsym must be 1, 2, or 3." + endif + enddo + i32=1+(k-1)*3+(ihalf-1)*87 + if(nsym.eq.1) ibmax=2 + if(nsym.eq.2) ibmax=5 + if(nsym.eq.3) ibmax=8 + do ib=0,ibmax + bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) + 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 + bmetc(i32+ib)=bm + endif + enddo + enddo + enddo + enddo + 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 + +! pass # +!------------------------------ +! 1 regular decoding, nsym=1 +! 2 regular decoding, nsym=2 +! 3 regular decoding, nsym=3 +! 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.7) then !Hounds always use AP + if(.not.lapcqonly) then + npasses=4+nappasses(nQSOProgress) + else + npasses=5 + endif + else + npasses=4 + endif + if(nzhsym.lt.50) npasses=4 + + do ipass=1,npasses + 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. 4) then + llrz=llra + if(.not.lapcqonly) then + iaptype=naptypes(nQSOProgress,ipass-4) + else + iaptype=1 + endif + +! ncontest=0 : NONE +! 1 : NA_VHF +! 2 : EU_VHF +! 3 : FIELD DAY +! 4 : RTTY +! 5 : WW_DIGI +! 6 : FOX +! 7 : HOUND +! 8 : ARRL_DIGI +! +! Conditions that cause us to bail out of AP decoding + 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) 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) + if(ncontest.eq.8) llrz(1:29)=apmag*mcqtest(1:29) + apmask(75:77)=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.or.ncontest.eq.5.or.ncontest.eq.8) then + apmask(1:29)=1 + llrz(1:29)=apmag*apsym(1:29) + apmask(75:77)=1 + llrz(75:76)=apmag*(-1) + llrz(77)=apmag*(+1) + else if(ncontest.eq.2) then + apmask(1:28)=1 + llrz(1:28)=apmag*apsym(1:28) + apmask(72:74)=1 + llrz(72)=apmag*(-1) + llrz(73)=apmag*(+1) + llrz(74)=apmag*(-1) + apmask(75:77)=1 + llrz(75:77)=apmag*(-1) + else if(ncontest.eq.3) then + apmask(1:28)=1 + llrz(1:28)=apmag*apsym(1:28) + apmask(75:77)=1 + llrz(75:77)=apmag*(-1) + else if(ncontest.eq.4) then + apmask(2:29)=1 + llrz(2:29)=apmag*apsym(1:28) + apmask(75:77)=1 + llrz(75)=apmag*(-1) + llrz(76:77)=apmag*(+1) + else if(ncontest.eq.7) then ! ??? RR73; MyCall ??? + apmask(29:56)=1 + llrz(29:56)=apmag*apsym(1:28) + apmask(57:66)=1 + llrz(57:66)=apmag*aph10(1:10) + apmask(72:77)=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.5.or.ncontest.eq.7.or.ncontest.eq.8) then + apmask(1:58)=1 + llrz(1:58)=apmag*apsym + apmask(75:77)=1 + llrz(75:76)=apmag*(-1) + llrz(77)=apmag*(+1) + else if(ncontest.eq.3) then ! Field Day + apmask(1:56)=1 + llrz(1:28)=apmag*apsym(1:28) + llrz(29:56)=apmag*apsym(30:57) + apmask(72:74)=1 + apmask(75:77)=1 + llrz(75:77)=apmag*(-1) + else if(ncontest.eq.4) then + apmask(2:57)=1 + llrz(2:29)=apmag*apsym(1:28) + llrz(30:57)=apmag*apsym(30:57) + apmask(75:77)=1 + llrz(75)=apmag*(-1) + llrz(76:77)=apmag*(+1) + endif + endif + + 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.5 .or. (ncontest.eq.7.and.iaptype.eq.6) .or. ncontest.eq.8) then + apmask(1:77)=1 ! mycall, hiscall, RRR|73|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 + llrz(1:28)=apmag*apsym(1:28) + apmask(57:66)=1 + llrz(57:66)=apmag*aph10(1:10) + apmask(72:77)=1 + llrz(72:73)=apmag*(-1) + llrz(74)=apmag*(1) + llrz(75:77)=apmag*(-1) + endif + endif + endif + + cw=0 + dmin=0.0 + norder=2 + maxosd=2 + if(ndepth.eq.1) maxosd=-1 ! BP only + if(ndepth.eq.2) maxosd=0 ! uncoupled BP+OSD + if(ndepth.eq.3 .and. & + (abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid .or. ncontest.eq.7)) then + maxosd=2 + 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=' ' + nbadcrc=1 + if(nharderrors.lt.0 .or. nharderrors.gt.36) cycle + if(count(cw.eq.0).eq.174) cycle !Reject the all-zero codeword + write(c77,'(77i1)') message77 + read(c77(72:74),'(b3)') n3 + read(c77(75:77),'(b3)') i3 + if(i3.gt.5 .or. (i3.eq.0.and.n3.gt.6)) cycle + if(i3.eq.0 .and. n3.eq.2) cycle + call unpack77(c77,1,msg37,unpk77_success) + if(.not.unpk77_success) cycle + nbadcrc=0 ! If we get this far: valid codeword, valid (i3,n3), nonquirky message. + call get_ft8_tones_from_77bits(message77,itone) + 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 + xsig=xsig+s8(itone(i),i)**2 + ios=mod(itone(i)+4,7) + xnoi=xnoi+s8(ios,i)**2 + enddo + xsnr=0.001 + xsnr2=0.001 + arg=xsig/xnoi-1.0 + if(arg.gt.0.1) xsnr=arg + 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(nsync.le.10 .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 + +subroutine normalizebmet(bmet,n) + real bmet(n) + + bmetav=sum(bmet)/real(n) + bmet2av=sum(bmet*bmet)/real(n) + var=bmet2av-bmetav*bmetav + if( var .gt. 0.0 ) then + bmetsig=sqrt(var) + else + bmetsig=sqrt(bmet2av) + endif + bmet=bmet/bmetsig + return +end subroutine normalizebmet + + +function bessi0(x) +! From Numerical Recipes + real bessi0,x + double precision p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9,y + save p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9 + data p1,p2,p3,p4,p5,p6,p7/1.0d0,3.5156229d0,3.0899424d0,1.2067492d0, & + 0.2659732d0,0.360768d-1,0.45813d-2/ + data q1,q2,q3,q4,q5,q6,q7,q8,q9/0.39894228d0,0.1328592d-1, & + 0.225319d-2,-0.157565d-2,0.916281d-2,-0.2057706d-1, & + 0.2635537d-1,-0.1647633d-1,0.392377d-2/ + + if (abs(x).lt.3.75) then + y=(x/3.75)**2 + bessi0=p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7))))) + else + ax=abs(x) + y=3.75/ax + bessi0=(exp(ax)/sqrt(ax))*(q1+y*(q2+y*(q3+y*(q4 & + +y*(q5+y*(q6+y*(q7+y*(q8+y*q9)))))))) + endif + return +end function bessi0 diff --git a/lib/ft8/ft8c.f90 b/lib/ft8/ft8c.f90 index 87dc76ac..a7d1ccb9 100755 --- a/lib/ft8/ft8c.f90 +++ b/lib/ft8/ft8c.f90 @@ -1,261 +1,261 @@ -subroutine ft8c(dd0,newdat,call_1,call_2,grid4,xdt,f1,nharderrors,dmin, & - msg37,xsnr) - - use crc - use timer_module, only: timer - use packjt77 - include 'ft8_params.f90' - parameter(NP2=2812) - character*37 msg37,msg,msgsent,msgbest - character*12 call_1,call_2 - character*4 grid4 - real a(5) - real s8(0:7,NN) - real s2(0:511) - real bmeta(174),bmetb(174),bmetc(174),bmetd(174) - real llra(174),llrb(174),llrc(174),llrd(174),llrbest(174) !Soft symbols - real dd0(15*12000) - real ss(9) - real rcw(174) - integer*1 cw(174) - integer*1 msgbits(77) - integer*1 nxor(174),hdec(174) - integer itone(NN) - integer icos7(0:6),ip(1) - logical one(0:511,0:8) - integer graymap(0:7) - integer iloc(1) - complex cd0(0:3199) - complex ctwk(32) - complex csymb(32) - complex cs(0:7,NN) - logical std_1,std_2 - logical first,newdat - data icos7/3,1,4,0,6,5,2/ ! Flipped w.r.t. original FT8 sync array - data first/.true./ - data graymap/0,1,3,2,5,6,4,7/ - save one - - if(first) then - one=.false. - do i=0,511 - do j=0,8 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - first=.false. - endif - - call stdcall(call_1,std_1) - if(call_1(1:3).eq.'CQ ') std_1=.true. - call stdcall(call_2,std_2) - - nharderrors=-1 - fs2=12000.0/NDOWN - dt2=1.0/fs2 - twopi=8.0*atan(1.0) - delfbest=0. - ibest=0 - - call timer('ft8_down',0) - call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample - call timer('ft8_down',1) - - i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal - smax=0.0 - 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 - -! Now peak up in frequency - smax=0.0 - do ifr=-5,5 !Search over +/- 2.5 Hz - delf=ifr*0.5 - dphi=twopi*delf*dt2 - phi=0.0 - do i=1,32 - ctwk(i)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - enddo - call sync8d(cd0,ibest,ctwk,1,sync) - if( sync .gt. smax ) then - smax=sync - delfbest=delf - endif - enddo - a=0.0 - a(1)=-delfbest - call twkfreq1(cd0,NP2,fs2,a,cd0) - f1=f1+delfbest !Improved estimate of DF - - 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 - 0.5 - sync=smax - - do k=1,NN - i1=ibest+(k-1)*32 - csymb=cmplx(0.0,0.0) - if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) - call four2a(csymb,32,1,-1,1) - cs(0:7,k)=csymb(1:8)/1e3 - s8(0:7,k)=abs(csymb(1:8)) - enddo - -! sync quality check - is1=0 - is2=0 - is3=0 - do k=1,7 - ip=maxloc(s8(:,k)) - if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 - ip=maxloc(s8(:,k+36)) - if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 - ip=maxloc(s8(:,k+72)) - if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 - enddo -! hard sync sum - max is 21 - nsync=is1+is2+is3 -! if(nsync .le. 6) return ! bail out - - do nsym=1,3 - nt=2**(3*nsym) - do ihalf=1,2 - do k=1,29,nsym - if(ihalf.eq.1) ks=k+7 - if(ihalf.eq.2) ks=k+43 - amax=-1.0 - do i=0,nt-1 - i1=i/64 - i2=iand(i,63)/8 - i3=iand(i,7) - if(nsym.eq.1) then - s2(i)=abs(cs(graymap(i3),ks)) - elseif(nsym.eq.2) then - s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) - elseif(nsym.eq.3) then - s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) - else - print*,"Error - nsym must be 1, 2, or 3." - endif - enddo - i32=1+(k-1)*3+(ihalf-1)*87 - if(nsym.eq.1) ibmax=2 - if(nsym.eq.2) ibmax=5 - if(nsym.eq.3) ibmax=8 - do ib=0,ibmax - bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) - 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 - bmetc(i32+ib)=bm - endif - enddo - enddo - enddo - enddo - 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 - - MAXMSG=206 - pbest=0. - do imsg=1,MAXMSG - msg=trim(call_1)//' '//trim(call_2) - i=imsg - if(call_1(1:3).eq.'CQ ' .and. i.ne.5) msg='QQ0XYZ '//trim(call_2) - if(.not.std_1) then - if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' - else if(.not.std_2) then - if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' - endif - j0=len(trim(msg))+2 - if(i.eq.2) msg(j0:j0+2)='RRR' - if(i.eq.3) msg(j0:j0+3)='RR73' - if(i.eq.4) msg(j0:j0+1)='73' - if(i.eq.5) then - if(std_2) then - msg='CQ '//trim(call_2) - if(call_1(3:3).eq.'_') msg=trim(call_1)//' '//trim(call_2) - if(grid4.ne.'RR73') msg=trim(msg)//' '//grid4 - endif - if(.not.std_2) msg='CQ '//trim(call_2) - endif - if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 - if(i.ge.7) then - isnr = -50 + (i-7)/2 - if(iand(i,1).eq.1) then - write(msg(j0:j0+2),'(i3.2)') isnr - if(msg(j0:j0).eq.' ') msg(j0:j0)='+' - else - write(msg(j0:j0+3),'("R",i3.2)') isnr - if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' - endif - endif - -! Source-encode, then get codeword - i3=-1 - n3=-1 - call genft8(msg,i3,n3,msgsent,msgbits,itone) - call encode174_91(msgbits,cw) - rcw=2*cw-1 - pa=sum(llra*rcw) - pb=sum(llrb*rcw) - pc=sum(llrc*rcw) - pd=sum(llrd*rcw) - - if(pa.gt.pbest) then - pbest=pa - msgbest=msgsent - llrbest=llra - nharderrors=count((2*cw-1)*llra.lt.0.0) - hdec=0 - where(llra.ge.0.0) hdec=1 - nxor=ieor(hdec,cw) - dmin=sum(nxor*abs(llra)) - endif - enddo ! imsg - -! write(*,4001) pbest,nharderrors,dmin,trim(msgbest) -!4001 format('$$$',f7.1,i4,f7.1,2x,a) - msg37=msgbest - - return -end subroutine ft8c +subroutine ft8c(dd0,newdat,call_1,call_2,grid4,xdt,f1,nharderrors,dmin, & + msg37,xsnr) + + use crc + use timer_module, only: timer + use packjt77 + include 'ft8_params.f90' + parameter(NP2=2812) + character*37 msg37,msg,msgsent,msgbest + character*12 call_1,call_2 + character*4 grid4 + real a(5) + real s8(0:7,NN) + real s2(0:511) + real bmeta(174),bmetb(174),bmetc(174),bmetd(174) + real llra(174),llrb(174),llrc(174),llrd(174),llrbest(174) !Soft symbols + real dd0(15*12000) + real ss(9) + real rcw(174) + integer*1 cw(174) + integer*1 msgbits(77) + integer*1 nxor(174),hdec(174) + integer itone(NN) + integer icos7(0:6),ip(1) + logical one(0:511,0:8) + integer graymap(0:7) + integer iloc(1) + complex cd0(0:3199) + complex ctwk(32) + complex csymb(32) + complex cs(0:7,NN) + logical std_1,std_2 + logical first,newdat + data icos7/3,1,4,0,6,5,2/ ! Flipped w.r.t. original FT8 sync array + data first/.true./ + data graymap/0,1,3,2,5,6,4,7/ + save one + + if(first) then + one=.false. + do i=0,511 + do j=0,8 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + first=.false. + endif + + call stdcall(call_1,std_1) + if(call_1(1:3).eq.'CQ ') std_1=.true. + call stdcall(call_2,std_2) + + nharderrors=-1 + fs2=12000.0/NDOWN + dt2=1.0/fs2 + twopi=8.0*atan(1.0) + delfbest=0. + ibest=0 + + call timer('ft8_down',0) + call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample + call timer('ft8_down',1) + + i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal + smax=0.0 + 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 + +! Now peak up in frequency + smax=0.0 + do ifr=-5,5 !Search over +/- 2.5 Hz + delf=ifr*0.5 + dphi=twopi*delf*dt2 + phi=0.0 + do i=1,32 + ctwk(i)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + enddo + call sync8d(cd0,ibest,ctwk,1,sync) + if( sync .gt. smax ) then + smax=sync + delfbest=delf + endif + enddo + a=0.0 + a(1)=-delfbest + call twkfreq1(cd0,NP2,fs2,a,cd0) + f1=f1+delfbest !Improved estimate of DF + + 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 - 0.5 + sync=smax + + do k=1,NN + i1=ibest+(k-1)*32 + csymb=cmplx(0.0,0.0) + if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31) + call four2a(csymb,32,1,-1,1) + cs(0:7,k)=csymb(1:8)/1e3 + s8(0:7,k)=abs(csymb(1:8)) + enddo + +! sync quality check + is1=0 + is2=0 + is3=0 + do k=1,7 + ip=maxloc(s8(:,k)) + if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1 + ip=maxloc(s8(:,k+36)) + if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1 + ip=maxloc(s8(:,k+72)) + if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1 + enddo +! hard sync sum - max is 21 + nsync=is1+is2+is3 +! if(nsync .le. 6) return ! bail out + + do nsym=1,3 + nt=2**(3*nsym) + do ihalf=1,2 + do k=1,29,nsym + if(ihalf.eq.1) ks=k+7 + if(ihalf.eq.2) ks=k+43 + amax=-1.0 + do i=0,nt-1 + i1=i/64 + i2=iand(i,63)/8 + i3=iand(i,7) + if(nsym.eq.1) then + s2(i)=abs(cs(graymap(i3),ks)) + elseif(nsym.eq.2) then + s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) + elseif(nsym.eq.3) then + s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) + else + print*,"Error - nsym must be 1, 2, or 3." + endif + enddo + i32=1+(k-1)*3+(ihalf-1)*87 + if(nsym.eq.1) ibmax=2 + if(nsym.eq.2) ibmax=5 + if(nsym.eq.3) ibmax=8 + do ib=0,ibmax + bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) + 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 + bmetc(i32+ib)=bm + endif + enddo + enddo + enddo + enddo + 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 + + MAXMSG=206 + pbest=0. + do imsg=1,MAXMSG + msg=trim(call_1)//' '//trim(call_2) + i=imsg + if(call_1(1:3).eq.'CQ ' .and. i.ne.5) msg='QQ0XYZ '//trim(call_2) + if(.not.std_1) then + if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' + else if(.not.std_2) then + if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' + endif + j0=len(trim(msg))+2 + if(i.eq.2) msg(j0:j0+2)='RRR' + if(i.eq.3) msg(j0:j0+3)='RR73' + if(i.eq.4) msg(j0:j0+1)='73' + if(i.eq.5) then + if(std_2) then + msg='CQ '//trim(call_2) + if(call_1(3:3).eq.'_') msg=trim(call_1)//' '//trim(call_2) + if(grid4.ne.'RR73') msg=trim(msg)//' '//grid4 + endif + if(.not.std_2) msg='CQ '//trim(call_2) + endif + if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 + if(i.ge.7) then + isnr = -50 + (i-7)/2 + if(iand(i,1).eq.1) then + write(msg(j0:j0+2),'(i3.2)') isnr + if(msg(j0:j0).eq.' ') msg(j0:j0)='+' + else + write(msg(j0:j0+3),'("R",i3.2)') isnr + if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' + endif + endif + +! Source-encode, then get codeword + i3=-1 + n3=-1 + call genft8(msg,i3,n3,msgsent,msgbits,itone) + call encode174_91(msgbits,cw) + rcw=2*cw-1 + pa=sum(llra*rcw) + pb=sum(llrb*rcw) + pc=sum(llrc*rcw) + pd=sum(llrd*rcw) + + if(pa.gt.pbest) then + pbest=pa + msgbest=msgsent + llrbest=llra + nharderrors=count((2*cw-1)*llra.lt.0.0) + hdec=0 + where(llra.ge.0.0) hdec=1 + nxor=ieor(hdec,cw) + dmin=sum(nxor*abs(llra)) + endif + enddo ! imsg + +! write(*,4001) pbest,nharderrors,dmin,trim(msgbest) +!4001 format('$$$',f7.1,i4,f7.1,2x,a) + msg37=msgbest + + return +end subroutine ft8c diff --git a/lib/ft8/ft8code.f90 b/lib/ft8/ft8code.f90 index 45b0b6a6..53371ff4 100755 --- a/lib/ft8/ft8code.f90 +++ b/lib/ft8/ft8code.f90 @@ -1,105 +1,105 @@ -program ft8code - -! Provides examples of message packing, LDPC(174,91) encoding, bit and -! symbol ordering, and other details of the FT8 protocol. - - use packjt77 - include 'ft8_params.f90' !Set various constants - include 'ft8_testmsg.f90' - parameter (NWAVE=NN*NSPS) - - character*37 msg,msgsent - character*9 comment - character bad*1,msgtype*18 - integer itone(NN) - integer*1 msgbits(77),codeword(174) - logical short - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.1 .and. nargs.ne.3) then - print* - print*,'Program ft8code: Provides examples of message packing, ', & - 'LDPC(174,91) encoding,' - print*,'bit and symbol ordering, and other details of the FT8 protocol.' - print* - print*,'Usage: ft8code "message" # Results for specified message' - 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 - 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 - - if(.not.short) write(*,1010) -1010 format(4x,'Message',31x,'Decoded',29x,'Err i3.n3'/100('-')) - - do imsg=1,nmsg - if(nmsg.gt.1) msg=testmsg(imsg) - -! Generate msgsent, msgbits, and itone - 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" - if(n3.eq.1) msgtype="DXpedition mode" - if(n3.eq.2) msgtype="EU VHF Contest" - if(n3.eq.3) msgtype="ARRL Field Day" - if(n3.eq.4) msgtype="ARRL Field Day" - if(n3.eq.5) msgtype="Telemetry" - if(n3.ge.6) msgtype="Undefined type" - endif - 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 call" - if(i3.eq.5) msgtype="EU VHF Contest" - if(i3.ge.6) msgtype="Undefined type" - if(i3.ge.1) n3=-1 - bad=" " - comment=' ' - if(msg.ne.msgsent) bad="*" - 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 - 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(/'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 (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 +program ft8code + +! Provides examples of message packing, LDPC(174,91) encoding, bit and +! symbol ordering, and other details of the FT8 protocol. + + use packjt77 + include 'ft8_params.f90' !Set various constants + include 'ft8_testmsg.f90' + parameter (NWAVE=NN*NSPS) + + character*37 msg,msgsent + character*9 comment + character bad*1,msgtype*18 + integer itone(NN) + integer*1 msgbits(77),codeword(174) + logical short + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.1 .and. nargs.ne.3) then + print* + print*,'Program ft8code: Provides examples of message packing, ', & + 'LDPC(174,91) encoding,' + print*,'bit and symbol ordering, and other details of the FT8 protocol.' + print* + print*,'Usage: ft8code "message" # Results for specified message' + 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 + 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 + + if(.not.short) write(*,1010) +1010 format(4x,'Message',31x,'Decoded',29x,'Err i3.n3'/100('-')) + + do imsg=1,nmsg + if(nmsg.gt.1) msg=testmsg(imsg) + +! Generate msgsent, msgbits, and itone + 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" + if(n3.eq.1) msgtype="DXpedition mode" + if(n3.eq.2) msgtype="EU VHF Contest" + if(n3.eq.3) msgtype="ARRL Field Day" + if(n3.eq.4) msgtype="ARRL Field Day" + if(n3.eq.5) msgtype="Telemetry" + if(n3.ge.6) msgtype="Undefined type" + endif + 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 call" + if(i3.eq.5) msgtype="EU VHF Contest" + if(i3.ge.6) msgtype="Undefined type" + if(i3.ge.1) n3=-1 + bad=" " + comment=' ' + if(msg.ne.msgsent) bad="*" + 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 + 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(/'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 (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/ft8d.f90 b/lib/ft8/ft8d.f90 index 28af93d1..4d107135 100755 --- a/lib/ft8/ft8d.f90 +++ b/lib/ft8/ft8d.f90 @@ -1,63 +1,63 @@ -program ft8d - -! Decode FT8 data read from *.wav files. - - include 'ft8_params.f90' - character*12 arg - character infile*80,datetime*13,message*22 - real s(NH1,NHSYM) - real candidate(3,100) - integer ihdr(11) - integer*2 iwave(NMAX) !Generated full-length waveform - real dd(NMAX) - - nargs=iargc() - if(nargs.lt.3) then - print*,'Usage: ft8d MaxIt Norder file1 [file2 ...]' - print*,'Example ft8d 40 2 *.wav' - go to 999 - endif - call getarg(1,arg) - read(arg,*) max_iterations - call getarg(2,arg) - read(arg,*) norder - nfiles=nargs-2 - - twopi=8.0*atan(1.0) - fs=12000.0 !Sample rate - dt=1.0/fs !Sample interval (s) - tt=NSPS*dt !Duration of "itone" symbols (s) - ts=2*NSPS*dt !Duration of OQPSK symbols (s) - baud=1.0/tt !Keying rate (baud) - txt=NZ*dt !Transmission length (s) - nfa=100.0 - nfb=3000.0 - nfqso=1500.0 - - do ifile=1,nfiles - call getarg(ifile+2,infile) - open(10,file=infile,status='old',access='stream') - read(10,end=999) ihdr,iwave - close(10) - j2=index(infile,'.wav') - read(infile(j2-6:j2-1),*) nutc - datetime=infile(j2-13:j2-1) - call sync8(iwave,NMAX,nfa,nfb,nfqso,s,candidate,ncand) - syncmin=2.0 - dd=iwave - do icand=1,ncand - sync=candidate(3,icand) - if( sync.lt.syncmin) cycle - f1=candidate(1,icand) - xdt=candidate(2,icand) - nsnr=min(99,nint(10.0*log10(sync)-25.5)) - call ft8b(dd,nfqso,f1,xdt,nharderrors,dmin,nbadcrc,message,xsnr) - nsnr=xsnr - xdt=xdt-0.6 - write(*,1110) datetime,0,nsnr,xdt,f1,message,nharderrors,dmin -1110 format(a13,2i4,f6.2,f7.1,' ~ ',a22,i6,f7.1) - enddo - enddo ! ifile loop - -999 end program ft8d - +program ft8d + +! Decode FT8 data read from *.wav files. + + include 'ft8_params.f90' + character*12 arg + character infile*80,datetime*13,message*22 + real s(NH1,NHSYM) + real candidate(3,100) + integer ihdr(11) + integer*2 iwave(NMAX) !Generated full-length waveform + real dd(NMAX) + + nargs=iargc() + if(nargs.lt.3) then + print*,'Usage: ft8d MaxIt Norder file1 [file2 ...]' + print*,'Example ft8d 40 2 *.wav' + go to 999 + endif + call getarg(1,arg) + read(arg,*) max_iterations + call getarg(2,arg) + read(arg,*) norder + nfiles=nargs-2 + + twopi=8.0*atan(1.0) + fs=12000.0 !Sample rate + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + ts=2*NSPS*dt !Duration of OQPSK symbols (s) + baud=1.0/tt !Keying rate (baud) + txt=NZ*dt !Transmission length (s) + nfa=100.0 + nfb=3000.0 + nfqso=1500.0 + + do ifile=1,nfiles + call getarg(ifile+2,infile) + open(10,file=infile,status='old',access='stream') + read(10,end=999) ihdr,iwave + close(10) + j2=index(infile,'.wav') + read(infile(j2-6:j2-1),*) nutc + datetime=infile(j2-13:j2-1) + call sync8(iwave,NMAX,nfa,nfb,nfqso,s,candidate,ncand) + syncmin=2.0 + dd=iwave + do icand=1,ncand + sync=candidate(3,icand) + if( sync.lt.syncmin) cycle + f1=candidate(1,icand) + xdt=candidate(2,icand) + nsnr=min(99,nint(10.0*log10(sync)-25.5)) + call ft8b(dd,nfqso,f1,xdt,nharderrors,dmin,nbadcrc,message,xsnr) + nsnr=xsnr + xdt=xdt-0.6 + write(*,1110) datetime,0,nsnr,xdt,f1,message,nharderrors,dmin +1110 format(a13,2i4,f6.2,f7.1,' ~ ',a22,i6,f7.1) + enddo + enddo ! ifile loop + +999 end program ft8d + diff --git a/lib/ft8/ft8q3.f90 b/lib/ft8/ft8q3.f90 index 74f8a763..122e49c9 100755 --- a/lib/ft8/ft8q3.f90 +++ b/lib/ft8/ft8q3.f90 @@ -1,109 +1,109 @@ -subroutine ft8q3(cd,xdt,f0,call_1,call_2,grid4,msgbest,snr) - -! Get q3-style decodes for FT8. - - use packjt77 - parameter(NN=79,NSPS=32) - parameter(NWAVE=NN*NSPS) !2528 - parameter(NZ=3200,NLAGS=NZ-NWAVE) - character*12 call_1,call_2 - character*4 grid4 - character*37 msg,msgbest,msgsent - character c77*77 - complex cwave(0:NWAVE-1) - complex cd(0:NZ-1) - complex z - real xjunk(NWAVE) - real ccf(0:NLAGS-1) - real ccfmsg(206) - integer itone(NN) - integer*1 msgbits(77) - logical std_1,std_2 - - if(xdt.eq.-99.0) return !Silence compiler warning - call stdcall(call_1,std_1) - call stdcall(call_2,std_2) - - fs=200.0 !Sample rate (Hz) - dt=1.0/fs !Sample interval (s) - bt=2.0 - ccfbest=0. - lagbest=-1 - - do imsg=1,206 - msg=trim(call_1)//' '//trim(call_2) - i=imsg - if(.not.std_1) then - if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' - else if(.not.std_2) then - if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) - if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' - endif - j0=len(trim(msg))+2 - if(i.eq.2) msg(j0:j0+2)='RRR' - if(i.eq.3) msg(j0:j0+3)='RR73' - if(i.eq.4) msg(j0:j0+1)='73' - if(i.eq.5) then - if(std_2) msg='CQ '//trim(call_2)//' '//grid4 - if(.not.std_2) msg='CQ '//trim(call_2) - endif - if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 - if(i.ge.7 .and. i.le.206) then - isnr = -50 + (i-7)/2 - if(iand(i,1).eq.1) then - write(msg(j0:j0+2),'(i3.2)') isnr - if(msg(j0:j0).eq.' ') msg(j0:j0)='+' - else - write(msg(j0:j0+3),'("R",i3.2)') isnr - if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' - endif - endif - -! Source-encode, then get itone() - i3=-1 - n3=-1 - call pack77(msg,i3,n3,c77) - call genft8(msg,i3,n3,msgsent,msgbits,itone) -! Generate complex cwave - call gen_ft8wave(itone,NN,NSPS,bt,fs,f0,cwave,xjunk,1,NWAVE) - - lagmax=-1 - ccfmax=0. - nsum=32*2 - do lag=0,nlags-1 - z=0. - s=0. - do i=0,NWAVE-1 - z=z + cd(i+lag)*conjg(cwave(i)) - if(mod(i,nsum).eq.nsum-1 .or. i.eq.NWAVE-1) then - s=s + abs(z) - z=0. - endif - enddo - ccf(lag)=s - if(ccf(lag).gt.ccfmax) then - ccfmax=ccf(lag) - lagmax=lag - endif - enddo ! lag - ccfmsg(imsg)=ccfmax - if(ccfmax.gt.ccfbest) then - ccfbest=ccfmax - lagbest=lagmax - msgbest=msg - endif - enddo ! imsg - - call pctile(ccfmsg,207,50,base) - call pctile(ccfmsg,207,67,sigma) - sigma=sigma-base - ccfmsg=(ccfmsg-base)/sigma -! do imsg=1,207 -! write(44,3044) imsg,ccfmsg(imsg) -!3044 format(i5,f10.3) -! enddo - snr=maxval(ccfmsg) - - return -end subroutine ft8q3 +subroutine ft8q3(cd,xdt,f0,call_1,call_2,grid4,msgbest,snr) + +! Get q3-style decodes for FT8. + + use packjt77 + parameter(NN=79,NSPS=32) + parameter(NWAVE=NN*NSPS) !2528 + parameter(NZ=3200,NLAGS=NZ-NWAVE) + character*12 call_1,call_2 + character*4 grid4 + character*37 msg,msgbest,msgsent + character c77*77 + complex cwave(0:NWAVE-1) + complex cd(0:NZ-1) + complex z + real xjunk(NWAVE) + real ccf(0:NLAGS-1) + real ccfmsg(206) + integer itone(NN) + integer*1 msgbits(77) + logical std_1,std_2 + + if(xdt.eq.-99.0) return !Silence compiler warning + call stdcall(call_1,std_1) + call stdcall(call_2,std_2) + + fs=200.0 !Sample rate (Hz) + dt=1.0/fs !Sample interval (s) + bt=2.0 + ccfbest=0. + lagbest=-1 + + do imsg=1,206 + msg=trim(call_1)//' '//trim(call_2) + i=imsg + if(.not.std_1) then + if(i.eq.1 .or. i.ge.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.2 .and. i.le.4) msg=trim(call_1)//' <'//trim(call_2)//'>' + else if(.not.std_2) then + if(i.le.4 .or. i.eq.6) msg='<'//trim(call_1)//'> '//trim(call_2) + if(i.ge.7) msg=trim(call_1)//' <'//trim(call_2)//'>' + endif + j0=len(trim(msg))+2 + if(i.eq.2) msg(j0:j0+2)='RRR' + if(i.eq.3) msg(j0:j0+3)='RR73' + if(i.eq.4) msg(j0:j0+1)='73' + if(i.eq.5) then + if(std_2) msg='CQ '//trim(call_2)//' '//grid4 + if(.not.std_2) msg='CQ '//trim(call_2) + endif + if(i.eq.6 .and. std_2) msg(j0:j0+3)=grid4 + if(i.ge.7 .and. i.le.206) then + isnr = -50 + (i-7)/2 + if(iand(i,1).eq.1) then + write(msg(j0:j0+2),'(i3.2)') isnr + if(msg(j0:j0).eq.' ') msg(j0:j0)='+' + else + write(msg(j0:j0+3),'("R",i3.2)') isnr + if(msg(j0+1:j0+1).eq.' ') msg(j0+1:j0+1)='+' + endif + endif + +! Source-encode, then get itone() + i3=-1 + n3=-1 + call pack77(msg,i3,n3,c77) + call genft8(msg,i3,n3,msgsent,msgbits,itone) +! Generate complex cwave + call gen_ft8wave(itone,NN,NSPS,bt,fs,f0,cwave,xjunk,1,NWAVE) + + lagmax=-1 + ccfmax=0. + nsum=32*2 + do lag=0,nlags-1 + z=0. + s=0. + do i=0,NWAVE-1 + z=z + cd(i+lag)*conjg(cwave(i)) + if(mod(i,nsum).eq.nsum-1 .or. i.eq.NWAVE-1) then + s=s + abs(z) + z=0. + endif + enddo + ccf(lag)=s + if(ccf(lag).gt.ccfmax) then + ccfmax=ccf(lag) + lagmax=lag + endif + enddo ! lag + ccfmsg(imsg)=ccfmax + if(ccfmax.gt.ccfbest) then + ccfbest=ccfmax + lagbest=lagmax + msgbest=msg + endif + enddo ! imsg + + call pctile(ccfmsg,207,50,base) + call pctile(ccfmsg,207,67,sigma) + sigma=sigma-base + ccfmsg=(ccfmsg-base)/sigma +! do imsg=1,207 +! write(44,3044) imsg,ccfmsg(imsg) +!3044 format(i5,f10.3) +! enddo + snr=maxval(ccfmsg) + + return +end subroutine ft8q3 diff --git a/lib/ft8/ft8sim.f90 b/lib/ft8/ft8sim.f90 index 693542be..5943bd08 100755 --- a/lib/ft8/ft8sim.f90 +++ b/lib/ft8/ft8sim.f90 @@ -1,141 +1,141 @@ -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 -11" 300 0 0 0 25 1 -10' - print*,' ft8sim " R 570007 JO22DB" 1500 0 0 0 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)') '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) - 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() - - 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 - - psig=0. - pnoise=0. - if(snrdb.lt.90) then - do i=1,NMAX !Add gaussian noise at specified SNR - xnoise=gran() - if(i.ge.6001 .and. i.le.157692) then - psig=psig + wave(i)*wave(i) !Signal power - pnoise=pnoise + xnoise*xnoise !Noise power in signal interval - endif - wave(i)=wave(i) + xnoise - enddo - endif - -! Noise power in signal interval and 2500 Hz bandwidth: - pnoise=bandwidth_ratio*pnoise - snr_2500=db(psig/pnoise) !SNR in 2500 Hz bandwidth - - 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,snr_2500 -1110 format(i4,f7.2,f8.2,f7.1,2x,a17,f8.2) - enddo -999 end program ft8sim_gfsk +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 -11" 300 0 0 0 25 1 -10' + print*,' ft8sim " R 570007 JO22DB" 1500 0 0 0 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)') '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) + 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() + + 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 + + psig=0. + pnoise=0. + if(snrdb.lt.90) then + do i=1,NMAX !Add gaussian noise at specified SNR + xnoise=gran() + if(i.ge.6001 .and. i.le.157692) then + psig=psig + wave(i)*wave(i) !Signal power + pnoise=pnoise + xnoise*xnoise !Noise power in signal interval + endif + wave(i)=wave(i) + xnoise + enddo + endif + +! Noise power in signal interval and 2500 Hz bandwidth: + pnoise=bandwidth_ratio*pnoise + snr_2500=db(psig/pnoise) !SNR in 2500 Hz bandwidth + + 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,snr_2500 +1110 format(i4,f7.2,f8.2,f7.1,2x,a17,f8.2) + enddo +999 end program ft8sim_gfsk diff --git a/lib/ft8/gen_ft8wave.f90 b/lib/ft8/gen_ft8wave.f90 index 1d395520..c7be0915 100755 --- a/lib/ft8/gen_ft8wave.f90 +++ b/lib/ft8/gen_ft8wave.f90 @@ -1,83 +1,83 @@ -subroutine gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) -! -! generate ft8 waveform using Gaussian-filtered frequency pulses. -! - use timer_module, only: timer - parameter(MAX_SECONDS=20,NTAB=65536) - real wave(nwave) - complex cwave(nwave),ctab(0:NTAB-1) - real pulse(23040) - real dphi(0:(nsym+2)*nsps-1) - integer itone(nsym) - data fchk0/0.0/ - save pulse,twopi,dt,hmod,fchk0,ctab - - ibt=nint(10*bt) - fchk=nsym+nsps+bt+fsample - if(fchk.ne.fchk0) then - twopi=8.0*atan(1.0) - dt=1.0/fsample - hmod=1.0 -! Compute the frequency-smoothing pulse - do i=1,3*nsps - tt=(i-1.5*nsps)/real(nsps) - pulse(i)=gfsk_pulse(bt,tt) - enddo - do i=0,NTAB-1 - phi=i*twopi/NTAB - ctab(i)=cmplx(cos(phi),sin(phi)) - enddo - fchk0=fchk - endif - -! Compute the smoothed frequency waveform. -! Length = (nsym+2)*nsps samples, first and last symbols extended - dphi_peak=twopi*hmod/real(nsps) - dphi=0.0 - do j=1,nsym - ib=(j-1)*nsps - ie=ib+3*nsps-1 - dphi(ib:ie) = dphi(ib:ie) + dphi_peak*pulse(1:3*nsps)*itone(j) - enddo -! Add dummy symbols at beginning and end with tone values equal to 1st and last symbol, respectively - dphi(0:2*nsps-1)=dphi(0:2*nsps-1)+dphi_peak*itone(1)*pulse(nsps+1:3*nsps) - dphi(nsym*nsps:(nsym+2)*nsps-1)=dphi(nsym*nsps:(nsym+2)*nsps-1)+dphi_peak*itone(nsym)*pulse(1:2*nsps) - -! Calculate and insert the audio waveform - phi=0.0 - dphi = dphi + twopi*f0*dt !Shift frequency up by f0 - if(icmplx .eq. 0) wave=0. - 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 - k=k+1 - if(icmplx.eq.0) then - wave(k)=sin(phi) - else - 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) - if(icmplx.eq.0) then - wave(1:nramp)=wave(1:nramp) * & - (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - k1=nsym*nsps-nramp+1 - wave(k1:k1+nramp-1)=wave(k1:k1+nramp-1) * & - (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - else - cwave(1:nramp)=cwave(1:nramp) * & - (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - k1=nsym*nsps-nramp+1 - cwave(k1:k1+nramp-1)=cwave(k1:k1+nramp-1) * & - (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 - endif - - return -end subroutine gen_ft8wave +subroutine gen_ft8wave(itone,nsym,nsps,bt,fsample,f0,cwave,wave,icmplx,nwave) +! +! generate ft8 waveform using Gaussian-filtered frequency pulses. +! + use timer_module, only: timer + parameter(MAX_SECONDS=20,NTAB=65536) + real wave(nwave) + complex cwave(nwave),ctab(0:NTAB-1) + real pulse(23040) + real dphi(0:(nsym+2)*nsps-1) + integer itone(nsym) + data fchk0/0.0/ + save pulse,twopi,dt,hmod,fchk0,ctab + + ibt=nint(10*bt) + fchk=nsym+nsps+bt+fsample + if(fchk.ne.fchk0) then + twopi=8.0*atan(1.0) + dt=1.0/fsample + hmod=1.0 +! Compute the frequency-smoothing pulse + do i=1,3*nsps + tt=(i-1.5*nsps)/real(nsps) + pulse(i)=gfsk_pulse(bt,tt) + enddo + do i=0,NTAB-1 + phi=i*twopi/NTAB + ctab(i)=cmplx(cos(phi),sin(phi)) + enddo + fchk0=fchk + endif + +! Compute the smoothed frequency waveform. +! Length = (nsym+2)*nsps samples, first and last symbols extended + dphi_peak=twopi*hmod/real(nsps) + dphi=0.0 + do j=1,nsym + ib=(j-1)*nsps + ie=ib+3*nsps-1 + dphi(ib:ie) = dphi(ib:ie) + dphi_peak*pulse(1:3*nsps)*itone(j) + enddo +! Add dummy symbols at beginning and end with tone values equal to 1st and last symbol, respectively + dphi(0:2*nsps-1)=dphi(0:2*nsps-1)+dphi_peak*itone(1)*pulse(nsps+1:3*nsps) + dphi(nsym*nsps:(nsym+2)*nsps-1)=dphi(nsym*nsps:(nsym+2)*nsps-1)+dphi_peak*itone(nsym)*pulse(1:2*nsps) + +! Calculate and insert the audio waveform + phi=0.0 + dphi = dphi + twopi*f0*dt !Shift frequency up by f0 + if(icmplx .eq. 0) wave=0. + 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 + k=k+1 + if(icmplx.eq.0) then + wave(k)=sin(phi) + else + 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) + if(icmplx.eq.0) then + wave(1:nramp)=wave(1:nramp) * & + (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + k1=nsym*nsps-nramp+1 + wave(k1:k1+nramp-1)=wave(k1:k1+nramp-1) * & + (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + else + cwave(1:nramp)=cwave(1:nramp) * & + (1.0-cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + k1=nsym*nsps-nramp+1 + cwave(k1:k1+nramp-1)=cwave(k1:k1+nramp-1) * & + (1.0+cos(twopi*(/(i,i=0,nramp-1)/)/(2.0*nramp)))/2.0 + endif + + return +end subroutine gen_ft8wave diff --git a/lib/ft8/genft8.f90 b/lib/ft8/genft8.f90 index 9a926d50..a03c3e58 100755 --- a/lib/ft8/genft8.f90 +++ b/lib/ft8/genft8.f90 @@ -1,46 +1,46 @@ -subroutine genft8(msg,i3,n3,msgsent,msgbits,itone) - -! Encode an FT8 message, producing array itone(). - - use packjt77 - include 'ft8_params.f90' - character msg*37,msgsent*37 - character*77 c77 - integer*1 msgbits(77),codeword(174) - integer itone(79) - integer icos7(0:6) - integer graymap(0:7) - logical unpk77_success - data icos7/3,1,4,0,6,5,2/ !Costas 7x7 tone pattern - data graymap/0,1,3,2,5,6,4,7/ - - i3=-1 - n3=-1 - call pack77(msg,i3,n3,c77) - call unpack77(c77,0,msgsent,unpk77_success) - read(c77,'(77i1)',err=1) msgbits - if(unpk77_success) go to 2 -1 msgbits=0 - itone=0 - msgsent='*** bad message *** ' - go to 900 - -entry get_ft8_tones_from_77bits(msgbits,itone) - -2 call encode174_91(msgbits,codeword) !Encode the test message - -! Message structure: S7 D29 S7 D29 S7 - itone(1:7)=icos7 - itone(36+1:36+7)=icos7 - itone(NN-6:NN)=icos7 - k=7 - do j=1,ND - i=3*j -2 - k=k+1 - if(j.eq.30) k=k+7 - indx=codeword(i)*4 + codeword(i+1)*2 + codeword(i+2) - itone(k)=graymap(indx) - enddo - -900 return -end subroutine genft8 +subroutine genft8(msg,i3,n3,msgsent,msgbits,itone) + +! Encode an FT8 message, producing array itone(). + + use packjt77 + include 'ft8_params.f90' + character msg*37,msgsent*37 + character*77 c77 + integer*1 msgbits(77),codeword(174) + integer itone(79) + integer icos7(0:6) + integer graymap(0:7) + logical unpk77_success + data icos7/3,1,4,0,6,5,2/ !Costas 7x7 tone pattern + data graymap/0,1,3,2,5,6,4,7/ + + i3=-1 + n3=-1 + call pack77(msg,i3,n3,c77) + call unpack77(c77,0,msgsent,unpk77_success) + read(c77,'(77i1)',err=1) msgbits + if(unpk77_success) go to 2 +1 msgbits=0 + itone=0 + msgsent='*** bad message *** ' + go to 900 + +entry get_ft8_tones_from_77bits(msgbits,itone) + +2 call encode174_91(msgbits,codeword) !Encode the test message + +! Message structure: S7 D29 S7 D29 S7 + itone(1:7)=icos7 + itone(36+1:36+7)=icos7 + itone(NN-6:NN)=icos7 + k=7 + do j=1,ND + i=3*j -2 + k=k+1 + if(j.eq.30) k=k+7 + indx=codeword(i)*4 + codeword(i+1)*2 + codeword(i+2) + itone(k)=graymap(indx) + enddo + +900 return +end subroutine genft8 diff --git a/lib/ft8/genft8refsig.f90 b/lib/ft8/genft8refsig.f90 index 2951165c..cd1468c1 100755 --- a/lib/ft8/genft8refsig.f90 +++ b/lib/ft8/genft8refsig.f90 @@ -1,23 +1,23 @@ -subroutine genft8refsig(itone,cref,f0) - complex cref(79*1920) - integer itone(79) -! real*8 twopi,phi,dphi,dt,xnsps - real twopi,phi,dphi,dt,xnsps - data twopi/0.d0/ - save twopi - if( twopi .lt. 0.1 ) twopi=8.d0*atan(1.d0) - - xnsps=1920.d0 - dt=1.d0/12000.d0 - phi=0.d0 - k=1 - do i=1,79 - dphi=twopi*(f0*dt+itone(i)/xnsps) - do is=1,1920 - cref(k)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi,twopi) - k=k+1 - enddo - enddo - return -end subroutine genft8refsig +subroutine genft8refsig(itone,cref,f0) + complex cref(79*1920) + integer itone(79) +! real*8 twopi,phi,dphi,dt,xnsps + real twopi,phi,dphi,dt,xnsps + data twopi/0.d0/ + save twopi + if( twopi .lt. 0.1 ) twopi=8.d0*atan(1.d0) + + xnsps=1920.d0 + dt=1.d0/12000.d0 + phi=0.d0 + k=1 + do i=1,79 + dphi=twopi*(f0*dt+itone(i)/xnsps) + do is=1,1920 + cref(k)=cmplx(cos(phi),sin(phi)) + phi=mod(phi+dphi,twopi) + k=k+1 + enddo + enddo + return +end subroutine genft8refsig diff --git a/lib/ft8/get_crc14.f90 b/lib/ft8/get_crc14.f90 index 8124082f..63580897 100755 --- a/lib/ft8/get_crc14.f90 +++ b/lib/ft8/get_crc14.f90 @@ -1,25 +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 +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/ldpc_174_87_params.f90 b/lib/ft8/ldpc_174_87_params.f90 index 4e20ad0a..35af9b81 100755 --- a/lib/ft8/ldpc_174_87_params.f90 +++ b/lib/ft8/ldpc_174_87_params.f90 @@ -1,102 +1,102 @@ -integer, parameter:: N=174, K=87, M=N-K -character*22 g(87) -integer colorder(N) -data g/ & !parity generator matrix for (174,87) code -"23bba830e23b6b6f50982e", & -"1f8e55da218c5df3309052", & -"ca7b3217cd92bd59a5ae20", & -"56f78313537d0f4382964e", & -"29c29dba9c545e267762fe", & -"6be396b5e2e819e373340c", & -"293548a138858328af4210", & -"cb6c6afcdc28bb3f7c6e86", & -"3f2a86f5c5bd225c961150", & -"849dd2d63673481860f62c", & -"56cdaec6e7ae14b43feeee", & -"04ef5cfa3766ba778f45a4", & -"c525ae4bd4f627320a3974", & -"fe37802941d66dde02b99c", & -"41fd9520b2e4abeb2f989c", & -"40907b01280f03c0323946", & -"7fb36c24085a34d8c1dbc4", & -"40fc3e44bb7d2bb2756e44", & -"d38ab0a1d2e52a8ec3bc76", & -"3d0f929ef3949bd84d4734", & -"45d3814f504064f80549ae", & -"f14dbf263825d0bd04b05e", & -"f08a91fb2e1f78290619a8", & -"7a8dec79a51e8ac5388022", & -"ca4186dd44c3121565cf5c", & -"db714f8f64e8ac7af1a76e", & -"8d0274de71e7c1a8055eb0", & -"51f81573dd4049b082de14", & -"d037db825175d851f3af00", & -"d8f937f31822e57c562370", & -"1bf1490607c54032660ede", & -"1616d78018d0b4745ca0f2", & -"a9fa8e50bcb032c85e3304", & -"83f640f1a48a8ebc0443ea", & -"eca9afa0f6b01d92305edc", & -"3776af54ccfbae916afde6", & -"6abb212d9739dfc02580f2", & -"05209a0abb530b9e7e34b0", & -"612f63acc025b6ab476f7c", & -"0af7723161ec223080be86", & -"a8fc906976c35669e79ce0", & -"45b7ab6242b77474d9f11a", & -"b274db8abd3c6f396ea356", & -"9059dfa2bb20ef7ef73ad4", & -"3d188ea477f6fa41317a4e", & -"8d9071b7e7a6a2eed6965e", & -"a377253773ea678367c3f6", & -"ecbd7c73b9cd34c3720c8a", & -"b6537f417e61d1a7085336", & -"6c280d2a0523d9c4bc5946", & -"d36d662a69ae24b74dcbd8", & -"d747bfc5fd65ef70fbd9bc", & -"a9fa2eefa6f8796a355772", & -"cc9da55fe046d0cb3a770c", & -"f6ad4824b87c80ebfce466", & -"cc6de59755420925f90ed2", & -"164cc861bdd803c547f2ac", & -"c0fc3ec4fb7d2bb2756644", & -"0dbd816fba1543f721dc72", & -"a0c0033a52ab6299802fd2", & -"bf4f56e073271f6ab4bf80", & -"57da6d13cb96a7689b2790", & -"81cfc6f18c35b1e1f17114", & -"481a2a0df8a23583f82d6c", & -"1ac4672b549cd6dba79bcc", & -"c87af9a5d5206abca532a8", & -"97d4169cb33e7435718d90", & -"a6573f3dc8b16c9d19f746", & -"2c4142bf42b01e71076acc", & -"081c29a10d468ccdbcecb6", & -"5b0f7742bca86b8012609a", & -"012dee2198eba82b19a1da", & -"f1627701a2d692fd9449e6", & -"35ad3fb0faeb5f1b0c30dc", & -"b1ca4ea2e3d173bad4379c", & -"37d8e0af9258b9e8c5f9b2", & -"cd921fdf59e882683763f6", & -"6114e08483043fd3f38a8a", & -"2e547dd7a05f6597aac516", & -"95e45ecd0135aca9d6e6ae", & -"b33ec97be83ce413f9acc8", & -"c8b5dffc335095dcdcaf2a", & -"3dd01a59d86310743ec752", & -"14cd0f642fc0c5fe3a65ca", & -"3a0a1dfd7eee29c2e827e0", & -"8abdb889efbe39a510a118", & -"3f231f212055371cf3e2a2"/ -data colorder/ & - 0, 1, 2, 3, 30, 4, 5, 6, 7, 8, 9, 10, 11, 32, 12, 40, 13, 14, 15, 16,& - 17, 18, 37, 45, 29, 19, 20, 21, 41, 22, 42, 31, 33, 34, 44, 35, 47, 51, 50, 43,& - 36, 52, 63, 46, 25, 55, 27, 24, 23, 53, 39, 49, 59, 38, 48, 61, 60, 57, 28, 62,& - 56, 58, 65, 66, 26, 70, 64, 69, 68, 67, 74, 71, 54, 76, 72, 75, 78, 77, 80, 79,& - 73, 83, 84, 81, 82, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,& - 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,& - 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,& - 140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,& - 160,161,162,163,164,165,166,167,168,169,170,171,172,173/ - +integer, parameter:: N=174, K=87, M=N-K +character*22 g(87) +integer colorder(N) +data g/ & !parity generator matrix for (174,87) code +"23bba830e23b6b6f50982e", & +"1f8e55da218c5df3309052", & +"ca7b3217cd92bd59a5ae20", & +"56f78313537d0f4382964e", & +"29c29dba9c545e267762fe", & +"6be396b5e2e819e373340c", & +"293548a138858328af4210", & +"cb6c6afcdc28bb3f7c6e86", & +"3f2a86f5c5bd225c961150", & +"849dd2d63673481860f62c", & +"56cdaec6e7ae14b43feeee", & +"04ef5cfa3766ba778f45a4", & +"c525ae4bd4f627320a3974", & +"fe37802941d66dde02b99c", & +"41fd9520b2e4abeb2f989c", & +"40907b01280f03c0323946", & +"7fb36c24085a34d8c1dbc4", & +"40fc3e44bb7d2bb2756e44", & +"d38ab0a1d2e52a8ec3bc76", & +"3d0f929ef3949bd84d4734", & +"45d3814f504064f80549ae", & +"f14dbf263825d0bd04b05e", & +"f08a91fb2e1f78290619a8", & +"7a8dec79a51e8ac5388022", & +"ca4186dd44c3121565cf5c", & +"db714f8f64e8ac7af1a76e", & +"8d0274de71e7c1a8055eb0", & +"51f81573dd4049b082de14", & +"d037db825175d851f3af00", & +"d8f937f31822e57c562370", & +"1bf1490607c54032660ede", & +"1616d78018d0b4745ca0f2", & +"a9fa8e50bcb032c85e3304", & +"83f640f1a48a8ebc0443ea", & +"eca9afa0f6b01d92305edc", & +"3776af54ccfbae916afde6", & +"6abb212d9739dfc02580f2", & +"05209a0abb530b9e7e34b0", & +"612f63acc025b6ab476f7c", & +"0af7723161ec223080be86", & +"a8fc906976c35669e79ce0", & +"45b7ab6242b77474d9f11a", & +"b274db8abd3c6f396ea356", & +"9059dfa2bb20ef7ef73ad4", & +"3d188ea477f6fa41317a4e", & +"8d9071b7e7a6a2eed6965e", & +"a377253773ea678367c3f6", & +"ecbd7c73b9cd34c3720c8a", & +"b6537f417e61d1a7085336", & +"6c280d2a0523d9c4bc5946", & +"d36d662a69ae24b74dcbd8", & +"d747bfc5fd65ef70fbd9bc", & +"a9fa2eefa6f8796a355772", & +"cc9da55fe046d0cb3a770c", & +"f6ad4824b87c80ebfce466", & +"cc6de59755420925f90ed2", & +"164cc861bdd803c547f2ac", & +"c0fc3ec4fb7d2bb2756644", & +"0dbd816fba1543f721dc72", & +"a0c0033a52ab6299802fd2", & +"bf4f56e073271f6ab4bf80", & +"57da6d13cb96a7689b2790", & +"81cfc6f18c35b1e1f17114", & +"481a2a0df8a23583f82d6c", & +"1ac4672b549cd6dba79bcc", & +"c87af9a5d5206abca532a8", & +"97d4169cb33e7435718d90", & +"a6573f3dc8b16c9d19f746", & +"2c4142bf42b01e71076acc", & +"081c29a10d468ccdbcecb6", & +"5b0f7742bca86b8012609a", & +"012dee2198eba82b19a1da", & +"f1627701a2d692fd9449e6", & +"35ad3fb0faeb5f1b0c30dc", & +"b1ca4ea2e3d173bad4379c", & +"37d8e0af9258b9e8c5f9b2", & +"cd921fdf59e882683763f6", & +"6114e08483043fd3f38a8a", & +"2e547dd7a05f6597aac516", & +"95e45ecd0135aca9d6e6ae", & +"b33ec97be83ce413f9acc8", & +"c8b5dffc335095dcdcaf2a", & +"3dd01a59d86310743ec752", & +"14cd0f642fc0c5fe3a65ca", & +"3a0a1dfd7eee29c2e827e0", & +"8abdb889efbe39a510a118", & +"3f231f212055371cf3e2a2"/ +data colorder/ & + 0, 1, 2, 3, 30, 4, 5, 6, 7, 8, 9, 10, 11, 32, 12, 40, 13, 14, 15, 16,& + 17, 18, 37, 45, 29, 19, 20, 21, 41, 22, 42, 31, 33, 34, 44, 35, 47, 51, 50, 43,& + 36, 52, 63, 46, 25, 55, 27, 24, 23, 53, 39, 49, 59, 38, 48, 61, 60, 57, 28, 62,& + 56, 58, 65, 66, 26, 70, 64, 69, 68, 67, 74, 71, 54, 76, 72, 75, 78, 77, 80, 79,& + 73, 83, 84, 81, 82, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,& + 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,& + 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,& + 140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,& + 160,161,162,163,164,165,166,167,168,169,170,171,172,173/ + diff --git a/lib/ft8/ldpc_174_91_c_colorder.f90 b/lib/ft8/ldpc_174_91_c_colorder.f90 index 91380187..a83de09d 100755 --- a/lib/ft8/ldpc_174_91_c_colorder.f90 +++ b/lib/ft8/ldpc_174_91_c_colorder.f90 @@ -1,11 +1,11 @@ -data colorder/ & - 0, 1, 2, 3, 28, 4, 5, 6, 7, 8, 9, 10, 11, 34, 12, 32, 13, 14, 15, 16, & - 17, 18, 36, 29, 43, 19, 20, 42, 21, 40, 30, 37, 22, 47, 61, 45, 44, 23, 41, 39, & - 49, 24, 46, 50, 48, 26, 31, 33, 51, 38, 52, 59, 55, 66, 57, 27, 60, 35, 54, 58, & - 25, 56, 62, 64, 67, 69, 63, 68, 70, 72, 65, 73, 75, 74, 71, 77, 78, 76, 79, 80, & - 53, 81, 83, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, & -100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119, & -120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139, & -140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, & -160,161,162,163,164,165,166,167,168,169,170,171,172,173/ - +data colorder/ & + 0, 1, 2, 3, 28, 4, 5, 6, 7, 8, 9, 10, 11, 34, 12, 32, 13, 14, 15, 16, & + 17, 18, 36, 29, 43, 19, 20, 42, 21, 40, 30, 37, 22, 47, 61, 45, 44, 23, 41, 39, & + 49, 24, 46, 50, 48, 26, 31, 33, 51, 38, 52, 59, 55, 66, 57, 27, 60, 35, 54, 58, & + 25, 56, 62, 64, 67, 69, 63, 68, 70, 72, 65, 73, 75, 74, 71, 77, 78, 76, 79, 80, & + 53, 81, 83, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, & +100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119, & +120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139, & +140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, & +160,161,162,163,164,165,166,167,168,169,170,171,172,173/ + diff --git a/lib/ft8/ldpc_174_91_c_generator.f90 b/lib/ft8/ldpc_174_91_c_generator.f90 index d513422f..675bae57 100755 --- a/lib/ft8/ldpc_174_91_c_generator.f90 +++ b/lib/ft8/ldpc_174_91_c_generator.f90 @@ -1,86 +1,86 @@ -character*23 g(83) - -data g/ & - "8329ce11bf31eaf509f27fc", & - "761c264e25c259335493132", & - "dc265902fb277c6410a1bdc", & - "1b3f417858cd2dd33ec7f62", & - "09fda4fee04195fd034783a", & - "077cccc11b8873ed5c3d48a", & - "29b62afe3ca036f4fe1a9da", & - "6054faf5f35d96d3b0c8c3e", & - "e20798e4310eed27884ae90", & - "775c9c08e80e26ddae56318", & - "b0b811028c2bf997213487c", & - "18a0c9231fc60adf5c5ea32", & - "76471e8302a0721e01b12b8", & - "ffbccb80ca8341fafb47b2e", & - "66a72a158f9325a2bf67170", & - "c4243689fe85b1c51363a18", & - "0dff739414d1a1b34b1c270", & - "15b48830636c8b99894972e", & - "29a89c0d3de81d665489b0e", & - "4f126f37fa51cbe61bd6b94", & - "99c47239d0d97d3c84e0940", & - "1919b75119765621bb4f1e8", & - "09db12d731faee0b86df6b8", & - "488fc33df43fbdeea4eafb4", & - "827423ee40b675f756eb5fe", & - "abe197c484cb74757144a9a", & - "2b500e4bc0ec5a6d2bdbdd0", & - "c474aa53d70218761669360", & - "8eba1a13db3390bd6718cec", & - "753844673a27782cc42012e", & - "06ff83a145c37035a5c1268", & - "3b37417858cc2dd33ec3f62", & - "9a4a5a28ee17ca9c324842c", & - "bc29f465309c977e89610a4", & - "2663ae6ddf8b5ce2bb29488", & - "46f231efe457034c1814418", & - "3fb2ce85abe9b0c72e06fbe", & - "de87481f282c153971a0a2e", & - "fcd7ccf23c69fa99bba1412", & - "f0261447e9490ca8e474cec", & - "4410115818196f95cdd7012", & - "088fc31df4bfbde2a4eafb4", & - "b8fef1b6307729fb0a078c0", & - "5afea7acccb77bbc9d99a90", & - "49a7016ac653f65ecdc9076", & - "1944d085be4e7da8d6cc7d0", & - "251f62adc4032f0ee714002", & - "56471f8702a0721e00b12b8", & - "2b8e4923f2dd51e2d537fa0", & - "6b550a40a66f4755de95c26", & - "a18ad28d4e27fe92a4f6c84", & - "10c2e586388cb82a3d80758", & - "ef34a41817ee02133db2eb0", & - "7e9c0c54325a9c15836e000", & - "3693e572d1fde4cdf079e86", & - "bfb2cec5abe1b0c72e07fbe", & - "7ee18230c583cccc57d4b08", & - "a066cb2fedafc9f52664126", & - "bb23725abc47cc5f4cc4cd2", & - "ded9dba3bee40c59b5609b4", & - "d9a7016ac653e6decdc9036", & - "9ad46aed5f707f280ab5fc4", & - "e5921c77822587316d7d3c2", & - "4f14da8242a8b86dca73352", & - "8b8b507ad467d4441df770e", & - "22831c9cf1169467ad04b68", & - "213b838fe2ae54c38ee7180", & - "5d926b6dd71f085181a4e12", & - "66ab79d4b29ee6e69509e56", & - "958148682d748a38dd68baa", & - "b8ce020cf069c32a723ab14", & - "f4331d6d461607e95752746", & - "6da23ba424b9596133cf9c8", & - "a636bcbc7b30c5fbeae67fe", & - "5cb0d86a07df654a9089a20", & - "f11f106848780fc9ecdd80a", & - "1fbb5364fb8d2c9d730d5ba", & - "fcb86bc70a50c9d02a5d034", & - "a534433029eac15f322e34c", & - "c989d9c7c3d3b8c55d75130", & - "7bb38b2f0186d46643ae962", & - "2644ebadeb44b9467d1f42c", & - "608cc857594bfbb55d69600"/ +character*23 g(83) + +data g/ & + "8329ce11bf31eaf509f27fc", & + "761c264e25c259335493132", & + "dc265902fb277c6410a1bdc", & + "1b3f417858cd2dd33ec7f62", & + "09fda4fee04195fd034783a", & + "077cccc11b8873ed5c3d48a", & + "29b62afe3ca036f4fe1a9da", & + "6054faf5f35d96d3b0c8c3e", & + "e20798e4310eed27884ae90", & + "775c9c08e80e26ddae56318", & + "b0b811028c2bf997213487c", & + "18a0c9231fc60adf5c5ea32", & + "76471e8302a0721e01b12b8", & + "ffbccb80ca8341fafb47b2e", & + "66a72a158f9325a2bf67170", & + "c4243689fe85b1c51363a18", & + "0dff739414d1a1b34b1c270", & + "15b48830636c8b99894972e", & + "29a89c0d3de81d665489b0e", & + "4f126f37fa51cbe61bd6b94", & + "99c47239d0d97d3c84e0940", & + "1919b75119765621bb4f1e8", & + "09db12d731faee0b86df6b8", & + "488fc33df43fbdeea4eafb4", & + "827423ee40b675f756eb5fe", & + "abe197c484cb74757144a9a", & + "2b500e4bc0ec5a6d2bdbdd0", & + "c474aa53d70218761669360", & + "8eba1a13db3390bd6718cec", & + "753844673a27782cc42012e", & + "06ff83a145c37035a5c1268", & + "3b37417858cc2dd33ec3f62", & + "9a4a5a28ee17ca9c324842c", & + "bc29f465309c977e89610a4", & + "2663ae6ddf8b5ce2bb29488", & + "46f231efe457034c1814418", & + "3fb2ce85abe9b0c72e06fbe", & + "de87481f282c153971a0a2e", & + "fcd7ccf23c69fa99bba1412", & + "f0261447e9490ca8e474cec", & + "4410115818196f95cdd7012", & + "088fc31df4bfbde2a4eafb4", & + "b8fef1b6307729fb0a078c0", & + "5afea7acccb77bbc9d99a90", & + "49a7016ac653f65ecdc9076", & + "1944d085be4e7da8d6cc7d0", & + "251f62adc4032f0ee714002", & + "56471f8702a0721e00b12b8", & + "2b8e4923f2dd51e2d537fa0", & + "6b550a40a66f4755de95c26", & + "a18ad28d4e27fe92a4f6c84", & + "10c2e586388cb82a3d80758", & + "ef34a41817ee02133db2eb0", & + "7e9c0c54325a9c15836e000", & + "3693e572d1fde4cdf079e86", & + "bfb2cec5abe1b0c72e07fbe", & + "7ee18230c583cccc57d4b08", & + "a066cb2fedafc9f52664126", & + "bb23725abc47cc5f4cc4cd2", & + "ded9dba3bee40c59b5609b4", & + "d9a7016ac653e6decdc9036", & + "9ad46aed5f707f280ab5fc4", & + "e5921c77822587316d7d3c2", & + "4f14da8242a8b86dca73352", & + "8b8b507ad467d4441df770e", & + "22831c9cf1169467ad04b68", & + "213b838fe2ae54c38ee7180", & + "5d926b6dd71f085181a4e12", & + "66ab79d4b29ee6e69509e56", & + "958148682d748a38dd68baa", & + "b8ce020cf069c32a723ab14", & + "f4331d6d461607e95752746", & + "6da23ba424b9596133cf9c8", & + "a636bcbc7b30c5fbeae67fe", & + "5cb0d86a07df654a9089a20", & + "f11f106848780fc9ecdd80a", & + "1fbb5364fb8d2c9d730d5ba", & + "fcb86bc70a50c9d02a5d034", & + "a534433029eac15f322e34c", & + "c989d9c7c3d3b8c55d75130", & + "7bb38b2f0186d46643ae962", & + "2644ebadeb44b9467d1f42c", & + "608cc857594bfbb55d69600"/ diff --git a/lib/ft8/ldpc_174_91_c_parity.f90 b/lib/ft8/ldpc_174_91_c_parity.f90 index 135c9de9..2309ad8e 100755 --- a/lib/ft8/ldpc_174_91_c_parity.f90 +++ b/lib/ft8/ldpc_174_91_c_parity.f90 @@ -1,270 +1,270 @@ -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 +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 index ae16fa43..4e30859a 100755 --- a/lib/ft8/ldpcsim174_91.f90 +++ b/lib/ft8/ldpcsim174_91.f90 @@ -1,269 +1,269 @@ -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, NN=58 - character*37 msg,msgsent - character*77 c77 - character*8 arg - integer*1, allocatable :: codeword(:), decoded(:), message(:) - integer*1 msgbits(77) - integer*1 message91(91) - integer*1 apmask(N), cw(N) - integer lmax(1) - integer modtype, itone(79), itonecw(58), graymap(0:7) - integer nerrtot(0:N),nerrdec(0:N) - integer channeltype - logical unpk77_success - logical one(0:511,0:8) - real*8, allocatable :: rxdata(:) - real llr(174),llra(174),llrb(174),llrc(174),llrd(174) - real bmeta(174),bmetb(174),bmetc(174),bmetd(174) - complex cs(0:7,NN) - real s2(0:511) - data graymap/0,1,3,2,5,6,4,7/ - - nerrtot=0 - nerrdec=0 - -! - - nargs=iargc() - if(nargs.ne.7) then - print*,'Usage: ldpcsim maxosd norder #trials s Keff modtype channel' - print*,'eg: ldpcsim 10 2 1000 0.84 91 1 0' - print*,' maxosd<0: do bp only' - print*,' maxosd=0: do bp and then call osd once with channel llrs' - print*,' maxosd>1: do bp and then call osd maxosd times with saved bp outputs' - print*,' norder : osd decoding depth' - print*,' s : BPSK only, noise sigma, if s<0 value is ignored and sigma is calculated from SNR.' - print*,' Keff : Keff must be in the range [77,91]; Keff-77 is the # of bits to use as CRC.' - print*,' modtype : 0, coherent BPSK; 1 noncoherent 8FSK' - print*,' channel : 0, AWGN; 1, block Rayleigh (Rayleigh only works with 8FSK!)' - return - endif - call getarg(1,arg) - read(arg,*) maxosd - call getarg(2,arg) - read(arg,*) norder - 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,*) modtype - call getarg(7,arg) - read(arg,*) channeltype - -! scale Eb/No for a (174,91) code - rate=real(K)/real(N) - - write(*,*) "rate: ",rate - - allocate ( codeword(N), decoded(K), message(K) ) - allocate ( rxdata(N) ) - - one=.false. - do i=0,511 - do j=0,8 - if(iand(i,2**j).ne.0) one(i,j)=.true. - enddo - enddo - - 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() - - iq=1 - if(modtype.gt.0) then ! MFSK - get tones - i3=-1 - n3=-1 - call genft8(msg,i3,n3,msgsent,msgbits,itone) - write(*,*) 'message tones' - write(*,'(79(i1,1x))') itone - itonecw(1:29)=itone(8:36) - itonecw(30:58)=itone(44:72) - iq=3 ! bits per symbol - endif - call encode174_91(msgbits,codeword) - write(*,*) 'crc14' - write(*,'(14i1)') codeword(78:91) - write(*,*) 'codeword' - write(*,'(22(8i1,1x))') codeword - write(*,*) 'Eb/N0 Es/N0 SNR2500 ngood nundetected sigma psymerr pbiterr' - do idb = 20,-4,-1 - nsymerr=0 - nbiterr=0 - db=idb/2.0-1.0 - sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) - ngood=0 - nue=0 - nsumerr=0 - do itrial=1, ntrials -! Create a realization of a noisy received word - if(modtype.eq.0) then - 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) - else -! noncoherent MFSK - do i=1,58 - do j=0,7 - if(j.eq.itonecw(i)) then - if(channeltype.eq.0) then - A=1.0 - elseif(channeltype.eq.1) then - xI=gran()**2 + gran()**2 - A=sqrt(xI/2) - endif - cs(j,i)= A + sigma*gran() + cmplx(0,1)*sigma*gran() - elseif(j.ne.itonecw(i)) then - cs(j,i)= sigma*gran() + cmplx(0,1)*sigma*gran() - endif - enddo - lmax=maxloc(abs(cs(:,i))) - if(lmax(1)-1.ne.itonecw(i) ) nsymerr=nsymerr+1 - enddo - do nsym=1,3 - nt=2**(3*nsym) - do ks=1,58,nsym - amax=-1.0 - do i=0,nt-1 - i1=i/64 - i2=iand(i,63)/8 - i3=iand(i,7) - if(nsym.eq.1) then - s2(i)=abs(cs(graymap(i3),ks)) - elseif(nsym.eq.2) then - s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) - elseif(nsym.eq.3) then - if(ks.ne.58) then - s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) - else - s2(i)=abs(cs(graymap(i1),ks)) - endif - else - print*,"Error - nsym must be 1, 2, or 3." - endif - enddo - - i32=1+(ks-1)*3 - if(nsym.eq.1) ibmax=2 - if(nsym.eq.2) ibmax=5 - if(nsym.eq.3) ibmax=8 - do ib=0,ibmax - bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & - maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) - 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 - bmetc(i32+ib)=bm - endif - enddo - enddo - enddo - 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 - - llr=llrc - endif - - do i=1, 174 - if(llr(i)*(codeword(i)-0.5).lt.0) nbiterr=nbiterr+1 - enddo - - 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,maxosd,norder,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(iq*rate) ! iq=3 bits per symbol for 8FSK - snr2500=esn0-10.0*log10(2500/6.25) -! pberr=real(nsumerr)/(real(ntrials*N)) - psymerr=real(nsymerr)/(ntrials*174.0/iq) - pbiterr=real(nbiterr)/(ntrials*174.0) - write(*,"(f4.1,4x,f5.1,4x,f5.1,1x,i8,1x,i8,8x,f5.2,8x,e10.3,8x,e10.3)") db,esn0,snr2500,ngood,nue,ss,psymerr,pbiterr - - 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 - -subroutine normalizebmet(bmet,n) - real bmet(n) - - bmetav=sum(bmet)/real(n) - bmet2av=sum(bmet*bmet)/real(n) - var=bmet2av-bmetav*bmetav - if( var .gt. 0.0 ) then - bmetsig=sqrt(var) - else - bmetsig=sqrt(bmet2av) - endif - bmet=bmet/bmetsig - return -end subroutine normalizebmet +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, NN=58 + character*37 msg,msgsent + character*77 c77 + character*8 arg + integer*1, allocatable :: codeword(:), decoded(:), message(:) + integer*1 msgbits(77) + integer*1 message91(91) + integer*1 apmask(N), cw(N) + integer lmax(1) + integer modtype, itone(79), itonecw(58), graymap(0:7) + integer nerrtot(0:N),nerrdec(0:N) + integer channeltype + logical unpk77_success + logical one(0:511,0:8) + real*8, allocatable :: rxdata(:) + real llr(174),llra(174),llrb(174),llrc(174),llrd(174) + real bmeta(174),bmetb(174),bmetc(174),bmetd(174) + complex cs(0:7,NN) + real s2(0:511) + data graymap/0,1,3,2,5,6,4,7/ + + nerrtot=0 + nerrdec=0 + +! + + nargs=iargc() + if(nargs.ne.7) then + print*,'Usage: ldpcsim maxosd norder #trials s Keff modtype channel' + print*,'eg: ldpcsim 10 2 1000 0.84 91 1 0' + print*,' maxosd<0: do bp only' + print*,' maxosd=0: do bp and then call osd once with channel llrs' + print*,' maxosd>1: do bp and then call osd maxosd times with saved bp outputs' + print*,' norder : osd decoding depth' + print*,' s : BPSK only, noise sigma, if s<0 value is ignored and sigma is calculated from SNR.' + print*,' Keff : Keff must be in the range [77,91]; Keff-77 is the # of bits to use as CRC.' + print*,' modtype : 0, coherent BPSK; 1 noncoherent 8FSK' + print*,' channel : 0, AWGN; 1, block Rayleigh (Rayleigh only works with 8FSK!)' + return + endif + call getarg(1,arg) + read(arg,*) maxosd + call getarg(2,arg) + read(arg,*) norder + 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,*) modtype + call getarg(7,arg) + read(arg,*) channeltype + +! scale Eb/No for a (174,91) code + rate=real(K)/real(N) + + write(*,*) "rate: ",rate + + allocate ( codeword(N), decoded(K), message(K) ) + allocate ( rxdata(N) ) + + one=.false. + do i=0,511 + do j=0,8 + if(iand(i,2**j).ne.0) one(i,j)=.true. + enddo + enddo + + 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() + + iq=1 + if(modtype.gt.0) then ! MFSK - get tones + i3=-1 + n3=-1 + call genft8(msg,i3,n3,msgsent,msgbits,itone) + write(*,*) 'message tones' + write(*,'(79(i1,1x))') itone + itonecw(1:29)=itone(8:36) + itonecw(30:58)=itone(44:72) + iq=3 ! bits per symbol + endif + call encode174_91(msgbits,codeword) + write(*,*) 'crc14' + write(*,'(14i1)') codeword(78:91) + write(*,*) 'codeword' + write(*,'(22(8i1,1x))') codeword + write(*,*) 'Eb/N0 Es/N0 SNR2500 ngood nundetected sigma psymerr pbiterr' + do idb = 20,-4,-1 + nsymerr=0 + nbiterr=0 + db=idb/2.0-1.0 + sigma=1/sqrt( 2*rate*iq*(10**(db/10.0)) ) + ngood=0 + nue=0 + nsumerr=0 + do itrial=1, ntrials +! Create a realization of a noisy received word + if(modtype.eq.0) then + 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) + else +! noncoherent MFSK + do i=1,58 + do j=0,7 + if(j.eq.itonecw(i)) then + if(channeltype.eq.0) then + A=1.0 + elseif(channeltype.eq.1) then + xI=gran()**2 + gran()**2 + A=sqrt(xI/2) + endif + cs(j,i)= A + sigma*gran() + cmplx(0,1)*sigma*gran() + elseif(j.ne.itonecw(i)) then + cs(j,i)= sigma*gran() + cmplx(0,1)*sigma*gran() + endif + enddo + lmax=maxloc(abs(cs(:,i))) + if(lmax(1)-1.ne.itonecw(i) ) nsymerr=nsymerr+1 + enddo + do nsym=1,3 + nt=2**(3*nsym) + do ks=1,58,nsym + amax=-1.0 + do i=0,nt-1 + i1=i/64 + i2=iand(i,63)/8 + i3=iand(i,7) + if(nsym.eq.1) then + s2(i)=abs(cs(graymap(i3),ks)) + elseif(nsym.eq.2) then + s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1)) + elseif(nsym.eq.3) then + if(ks.ne.58) then + s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2)) + else + s2(i)=abs(cs(graymap(i1),ks)) + endif + else + print*,"Error - nsym must be 1, 2, or 3." + endif + enddo + + i32=1+(ks-1)*3 + if(nsym.eq.1) ibmax=2 + if(nsym.eq.2) ibmax=5 + if(nsym.eq.3) ibmax=8 + do ib=0,ibmax + bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - & + maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib)) + 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 + bmetc(i32+ib)=bm + endif + enddo + enddo + enddo + 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 + + llr=llrc + endif + + do i=1, 174 + if(llr(i)*(codeword(i)-0.5).lt.0) nbiterr=nbiterr+1 + enddo + + 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,maxosd,norder,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(iq*rate) ! iq=3 bits per symbol for 8FSK + snr2500=esn0-10.0*log10(2500/6.25) +! pberr=real(nsumerr)/(real(ntrials*N)) + psymerr=real(nsymerr)/(ntrials*174.0/iq) + pbiterr=real(nbiterr)/(ntrials*174.0) + write(*,"(f4.1,4x,f5.1,4x,f5.1,1x,i8,1x,i8,8x,f5.2,8x,e10.3,8x,e10.3)") db,esn0,snr2500,ngood,nue,ss,psymerr,pbiterr + + 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 + +subroutine normalizebmet(bmet,n) + real bmet(n) + + bmetav=sum(bmet)/real(n) + bmet2av=sum(bmet*bmet)/real(n) + var=bmet2av-bmetav*bmetav + if( var .gt. 0.0 ) then + bmetsig=sqrt(var) + else + bmetsig=sqrt(bmet2av) + endif + bmet=bmet/bmetsig + return +end subroutine normalizebmet diff --git a/lib/ft8/osd174_91.f90 b/lib/ft8/osd174_91.f90 index ca99fd62..89677ebe 100755 --- a/lib/ft8/osd174_91.f90 +++ b/lib/ft8/osd174_91.f90 @@ -1,409 +1,409 @@ -subroutine osd174_91(llr,k,apmask,ndeep,message91,cw,nhardmin,dmin) -! -! An ordered-statistics decoder for the (174,91) code. -! Message payload is 77 bits. Any or all of a 14-bit CRC can be -! used for detecting incorrect codewords. The remaining CRC bits are -! cascaded with the LDPC code for the purpose of improving the -! distance spectrum of the code. -! -! 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) - - logical first,reset - data first/.true./ - save first - - 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 -! -! 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 - - first=.false. - endif - - rx=llr - apmaskr=apmask - -! Hard decisions on the received word. - hdec=0 - where(rx .ge. 0) hdec=1 - -! Use magnitude of received symbols as a measure of reliability. - absrx=abs(rx) - call indexx(absrx,N,indx) - -! 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 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 - enddo - exit - endif - enddo - enddo - - 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. -! 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) - - call mrbencode91(m0,c0,g2,N,k) - nxor=ieor(c0,hdec) - nhardmin=sum(nxor) - dmin=sum(nxor*absrx) - - cw=c0 - ntotal=0 - nrejected=0 - npre1=0 - npre2=0 - - 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 - else !ndeep=6 - 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 - iend=1 - endif - 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 - 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 - e2=ieor(e2sub,g2(k+1:N,n1)) - nd1kpt=sum(e2(1:nt))+2 - endif - 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 - 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) - 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) - enddo - enddo - - 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 - call fetchit91(reset,r2pat(1:ntau),ntau,in1,in2) - if(in1.gt.0.and.in2.gt.0) then - ncount2=ncount2+1 - 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 - me=ieor(m0,mi) - call mrbencode91(me,ce,g2,N,k) - nxor=ieor(ce,hdec) - dd=sum(nxor*absrx) - if( dd .lt. dmin ) then - dmin=dd - cw=ce - nhardmin=sum(nxor) - endif - goto 778 - endif - enddo - call nextpat91(misub,k,nord,iflag) - enddo - endif - -998 continue -! 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 -end subroutine osd174_91 - -subroutine mrbencode91(me,codeword,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 -end subroutine mrbencode91 - -subroutine nextpat91(mi,k,iorder,iflag) - 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 -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 - - 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 - - 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 - - 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) - - 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 - +subroutine osd174_91(llr,k,apmask,ndeep,message91,cw,nhardmin,dmin) +! +! An ordered-statistics decoder for the (174,91) code. +! Message payload is 77 bits. Any or all of a 14-bit CRC can be +! used for detecting incorrect codewords. The remaining CRC bits are +! cascaded with the LDPC code for the purpose of improving the +! distance spectrum of the code. +! +! 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) + + logical first,reset + data first/.true./ + save first + + 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 +! +! 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 + + first=.false. + endif + + rx=llr + apmaskr=apmask + +! Hard decisions on the received word. + hdec=0 + where(rx .ge. 0) hdec=1 + +! Use magnitude of received symbols as a measure of reliability. + absrx=abs(rx) + call indexx(absrx,N,indx) + +! 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 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 + enddo + exit + endif + enddo + enddo + + 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. +! 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) + + call mrbencode91(m0,c0,g2,N,k) + nxor=ieor(c0,hdec) + nhardmin=sum(nxor) + dmin=sum(nxor*absrx) + + cw=c0 + ntotal=0 + nrejected=0 + npre1=0 + npre2=0 + + 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 + else !ndeep=6 + 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 + iend=1 + endif + 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 + 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 + e2=ieor(e2sub,g2(k+1:N,n1)) + nd1kpt=sum(e2(1:nt))+2 + endif + 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 + 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) + 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) + enddo + enddo + + 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 + call fetchit91(reset,r2pat(1:ntau),ntau,in1,in2) + if(in1.gt.0.and.in2.gt.0) then + ncount2=ncount2+1 + 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 + me=ieor(m0,mi) + call mrbencode91(me,ce,g2,N,k) + nxor=ieor(ce,hdec) + dd=sum(nxor*absrx) + if( dd .lt. dmin ) then + dmin=dd + cw=ce + nhardmin=sum(nxor) + endif + goto 778 + endif + enddo + call nextpat91(misub,k,nord,iflag) + enddo + endif + +998 continue +! 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 +end subroutine osd174_91 + +subroutine mrbencode91(me,codeword,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 +end subroutine mrbencode91 + +subroutine nextpat91(mi,k,iorder,iflag) + 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 +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 + + 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 + + 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 + + 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) + + 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 137d8616..40657e7e 100755 --- a/lib/ft8/subtractft8.f90 +++ b/lib/ft8/subtractft8.f90 @@ -1,106 +1,106 @@ -subroutine subtractft8(dd0,itone,f0,dt,lrefinedt) - -! Subtract an ft8 signal -! -! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t)) -! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) ) -! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ] -! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt} - - parameter (NMAX=15*12000,NFRAME=1920*79) - 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,lrefinedt,ldt - data first/.true./ - 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 - pi=4.0*atan(1.0) - fac=1.0/float(nfft) - sumw=0.0 - do j=-NFILT/2,NFILT/2 - window(j)=cos(pi*j/NFILT)**2 - sumw=sumw+window(j) - enddo - cw=0. - 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 - -! 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 -! write(44,3044) nint(f0),dt-0.5,1.e-8*sum(dd*dd) -!3044 format(i4,f7.2,f10.6) - return - -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 +subroutine subtractft8(dd0,itone,f0,dt,lrefinedt) + +! Subtract an ft8 signal +! +! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t)) +! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) ) +! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ] +! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt} + + parameter (NMAX=15*12000,NFRAME=1920*79) + 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,lrefinedt,ldt + data first/.true./ + 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 + pi=4.0*atan(1.0) + fac=1.0/float(nfft) + sumw=0.0 + do j=-NFILT/2,NFILT/2 + window(j)=cos(pi*j/NFILT)**2 + sumw=sumw+window(j) + enddo + cw=0. + 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 + +! 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 +! write(44,3044) nint(f0),dt-0.5,1.e-8*sum(dd*dd) +!3044 format(i4,f7.2,f10.6) + return + +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/test_ft8q3.f90 b/lib/ft8/test_ft8q3.f90 index 00871e61..4a3802c3 100755 --- a/lib/ft8/test_ft8q3.f90 +++ b/lib/ft8/test_ft8q3.f90 @@ -1,41 +1,41 @@ -program test_ft8q3 - -! Test q3-style decodes for FT8. - - use packjt77 - parameter(NN=79,NSPS=32) - parameter(NWAVE=NN*NSPS) !2528 - parameter(NZ=3200,NLAGS=NZ-NWAVE) - character arg*12 - character*37 msg - character*12 call_1,call_2 - character*4 grid4 - complex cd(0:NZ-1) - -! Get command-line argument(s) - nargs=iargc() - if(nargs.ne.4 .and. nargs.ne.5) then - print*,'Usage: ft8q3 DT f0 call_1 call_2 [grid4]' - go to 999 - endif - call getarg(1,arg) - read(arg,*) xdt !Time offset from nominal (s) - call getarg(2,arg) - read(arg,*) f0 !Frequency (Hz) - call getarg(3,call_1) !First callsign - call getarg(4,call_2) !Second callsign - grid4=' ' - if(nargs.eq.5) call getarg(5,grid4) !Locator for call_2 - - do i=0,NZ-1 - read(40,3040) cd(i) -3040 format(17x,2f10.3) - enddo - - call sec0(0,t) - call ft8q3(cd,xdt,f0,call_1,call_2,grid4,msg,snr) - call sec0(1,t) - write(*,1100) t,snr,trim(msg) -1100 format('Time:',f6.2,' S/N:',f6.1,' msg: ',a) - -999 end program test_ft8q3 +program test_ft8q3 + +! Test q3-style decodes for FT8. + + use packjt77 + parameter(NN=79,NSPS=32) + parameter(NWAVE=NN*NSPS) !2528 + parameter(NZ=3200,NLAGS=NZ-NWAVE) + character arg*12 + character*37 msg + character*12 call_1,call_2 + character*4 grid4 + complex cd(0:NZ-1) + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.4 .and. nargs.ne.5) then + print*,'Usage: ft8q3 DT f0 call_1 call_2 [grid4]' + go to 999 + endif + call getarg(1,arg) + read(arg,*) xdt !Time offset from nominal (s) + call getarg(2,arg) + read(arg,*) f0 !Frequency (Hz) + call getarg(3,call_1) !First callsign + call getarg(4,call_2) !Second callsign + grid4=' ' + if(nargs.eq.5) call getarg(5,grid4) !Locator for call_2 + + do i=0,NZ-1 + read(40,3040) cd(i) +3040 format(17x,2f10.3) + enddo + + call sec0(0,t) + call ft8q3(cd,xdt,f0,call_1,call_2,grid4,msg,snr) + call sec0(1,t) + write(*,1100) t,snr,trim(msg) +1100 format('Time:',f6.2,' S/N:',f6.1,' msg: ',a) + +999 end program test_ft8q3 -- cgit v1.2.3